+/*
+ * call-seq:
+ * edje.get_size_min => array
+ *
+ * Returns an array that contains the minimum size
+ * of <i>edje</i>.
+ */
+static VALUE c_get_size_min (VALUE self)
+{
+ int w = 0, h = 0;
+
+ GET_OBJ (self, RbEdje, e);
+
+ edje_object_size_min_get (e->real.real, &w, &h);
+
+ return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
+}
+
+/*
+ * call-seq:
+ * edje.get_size_max => array
+ *
+ * Returns an array that contains the maximum size
+ * of <i>edje</i>.
+ */
+static VALUE c_get_size_max (VALUE self)
+{
+ int w = 0, h = 0;
+
+ GET_OBJ (self, RbEdje, e);
+
+ edje_object_size_max_get (e->real.real, &w, &h);
+
+ return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
+}
+
+/*
+ * call-seq:
+ * edje.part_exists?(part) => true or false
+ *
+ * Returns true if <i>edje</i> has a part called <i>part</i>,
+ * else returns false.
+ */
+static VALUE c_part_exists_get (VALUE self, VALUE name)
+{
+ int r;
+
+ GET_OBJ (self, RbEdje, e);
+
+ Check_Type (name, T_STRING);
+
+ r = edje_object_part_exists (e->real.real, StringValuePtr (name));
+
+ return r ? Qtrue : Qfalse;
+}
+
+/*
+ * call-seq:
+ * edje.part(part_name) => part
+ *
+ * Returns the <code>Edje::Part</code> object that corresponds to
+ * <i>part_name</i>. If there's no part with that name in <i>edje</i>,
+ * an exception is raised.
+ */
+static VALUE c_part_get (VALUE self, VALUE name)
+{
+ VALUE part;
+ const char *cname = StringValuePtr (name);
+
+ GET_OBJ (self, RbEdje, e);
+
+ if (!edje_object_part_exists (e->real.real, cname)) {
+ rb_raise (rb_eException, "Unknown part name - %s", cname);
+ return Qnil;
+ }
+
+ if (NIL_P (e->parts))
+ e->parts = rb_hash_new ();
+
+ if (NIL_P (part = rb_hash_aref (e->parts, name))) {
+ part = TO_PART (self, name);
+ rb_hash_aset (e->parts, name, part);
+ }
+
+ return part;
+}
+
+static void on_text_changed (void *data, Evas_Object *eo,
+ const char *part_name)
+{
+ VALUE self = (VALUE) data, part, name;
+
+ GET_OBJ (self, RbEdje, e);
+
+ name = rb_str_new2 (part_name);
+
+ if (NIL_P (e->parts))
+ e->parts = rb_hash_new ();
+
+ if (NIL_P (part = rb_hash_aref (e->parts, name))) {
+ part = TO_PART (self, name);
+ rb_hash_aset (e->parts, name, part);
+ }
+
+ rb_funcall (e->on_text_changed_cb,
+ rb_intern ("call"), 1, part);
+}
+
+/*
+ * call-seq:
+ * edje.on_text_changed { |part_obj| block }
+ *
+ * Registers a callback that will get called when the text
+ * of any part is changed in <i>edje</i>.
+ * The block is passed the <code>Edje::Part</code> object
+ * of which the text changed.
+ */
+static VALUE c_on_text_changed (VALUE self)
+{
+ GET_OBJ (self, RbEdje, e);
+
+ if (!rb_block_given_p ())
+ return Qnil;
+
+ e->on_text_changed_cb = rb_block_proc ();
+
+ edje_object_text_change_cb_set (e->real.real, on_text_changed,
+ (void *) self);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * edje.emit_signal(signal, source) => nil
+ *
+ * Emits a signal to <i>edje</i>.
+ *
+ * edje.emit_signal("signal_foo", "part_bar") #=> nil
+ */
+static VALUE c_emit_signal (VALUE self, VALUE signal, VALUE source)
+{
+ GET_OBJ (self, RbEdje, e);
+
+ Check_Type (signal, T_STRING);
+ Check_Type (source, T_STRING);
+
+ edje_object_signal_emit (e->real.real, StringValuePtr (signal),
+ StringValuePtr (source));
+
+ return Qnil;
+}
+
+static void on_signal (void *data, Evas_Object *o,
+ const char *signal, const char *src)
+{
+ rb_funcall ((VALUE) data, rb_intern ("call"), 2,
+ rb_str_new2 (signal), rb_str_new2 (src));
+}
+
+/*
+ * call-seq:
+ * edje.on_signal(signal [, source]) { |signal, source| block } => nil
+ *
+ * Registers a callback that will get called when <i>signal</i>
+ * is emitted by <i>source</i>.
+ * If source is nil, "*" will be used instead.
+ * The block is passed two strings, signal and source, which identify
+ * the emission.
+ */
+static VALUE c_on_signal (int argc, VALUE *argv, VALUE self)
+{
+ VALUE signal, src, cb;
+ char *ssrc = "*";
+
+ GET_OBJ (self, RbEdje, e);
+
+ rb_scan_args (argc, argv, "11", &signal, &src);
+
+ Check_Type (signal, T_STRING);
+
+ if (!NIL_P (src)) {
+ Check_Type (src, T_STRING);
+ ssrc = StringValuePtr (src);
+ }
+
+ if (!rb_block_given_p ())
+ return Qnil;
+
+ cb = rb_block_proc ();
+
+ if (NIL_P (e->callbacks))
+ e->callbacks = rb_ary_new ();
+
+ rb_ary_push (e->callbacks, cb);
+
+ edje_object_signal_callback_add (e->real.real,
+ StringValuePtr (signal),
+ ssrc, on_signal, (void *) cb);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * edje.play? => true or false
+ *
+ * Returns true if <i>edje</i> is in play mode, else returns false.
+ */
+static VALUE c_play_get (VALUE self)
+{
+ GET_OBJ (self, RbEdje, e);
+
+ return edje_object_play_get (e->real.real) ? Qtrue : Qfalse;
+}
+
+/*
+ * call-seq:
+ * edje.play(true or false)
+ *
+ * Sets <i>edje</i> to play resp. pause mode.
+ */
+static VALUE c_play_set (VALUE self, VALUE val)
+{
+ GET_OBJ (self, RbEdje, e);
+
+ CHECK_BOOL(val);
+
+ edje_object_play_set (e->real.real, val == Qtrue);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * edje.animation? => true or false
+ *
+ * Returns the animation state of <i>edje</i>.
+ */
+static VALUE c_animation_get (VALUE self)
+{
+ GET_OBJ (self, RbEdje, e);
+
+ return edje_object_animation_get (e->real.real) ? Qtrue : Qfalse;
+}
+
+/*
+ * call-seq:
+ * edje.animation(true or false)
+ *
+ * Sets the animation state of <i>edje</i>.
+ */
+static VALUE c_animation_set (VALUE self, VALUE val)
+{
+ GET_OBJ (self, RbEdje, e);
+
+ CHECK_BOOL(val);
+
+ edje_object_animation_set (e->real.real, val == Qtrue);
+
+ return Qnil;
+}
+
+static VALUE c_data_get (VALUE self, VALUE key)
+{
+ const char *s;
+
+ GET_OBJ (self, RbEdje, e);
+
+ Check_Type (key, T_STRING);
+
+ s = edje_object_data_get (e->real.real, StringValuePtr (key));
+
+ return s ? rb_str_new2 (s) : Qnil;
+}
+
+static VALUE c_send_message (VALUE self, VALUE msg)
+{
+ Edje_Message_String s;
+ Edje_Message_Int i;
+ Edje_Message_Float f;
+ Edje_Message_Type type;
+ void *data;
+ VALUE v, tmp;
+
+ GET_OBJ (self, RbEdje, e);
+
+ CHECK_CLASS (msg, cMsg);
+
+ v = rb_iv_get (msg, "@value");
+
+ if (NIL_P (v)) {
+ rb_raise (eEdjeError, "value must not be nil");
+ return Qnil;
+ }
+
+ if (!NIL_P (tmp = rb_check_string_type (v))) {
+ type = EDJE_MESSAGE_STRING;
+ s.str = StringValuePtr (tmp);
+ data = &s;
+ } else if (rb_obj_is_kind_of (v, rb_cFixnum)) {
+ type = EDJE_MESSAGE_INT;
+ i.val = FIX2INT (v);
+ data = &i;
+ } else if (rb_obj_is_kind_of (v, rb_cFloat)) {
+ type = EDJE_MESSAGE_FLOAT;
+ f.val = NUM2DBL (v);
+ data = &v;
+ /* } else if (!NIL_P (tmp = rb_check_array_type (v))) { */
+ } else {
+ rb_raise (eEdjeError, "unsupported value");
+ }
+
+ edje_object_message_send (e->real.real, type,
+ NUM2INT (rb_iv_get (msg, "@id")), data);
+
+ return Qnil;
+}
+
+static VALUE c_msg_init (int argc, VALUE *argv, VALUE self)
+{
+ VALUE val;
+
+ rb_scan_args (argc, argv, "01", &val);
+
+ rb_iv_set (self, "@id", UINT2NUM (0));
+ rb_iv_set (self, "@value", val);
+
+ return self;
+}
+