Implemented Edje#data.
[ruby-edje.git] / src / rb_edje.c
index 50ba39b4369a613393ada20ff00e67098f65019e..711df113b0d1a4bf259242d1d1dd55477f2ff7b1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_edje.c 66 2004-08-12 19:37:52Z tilman $
+ * $Id: rb_edje.c 129 2004-10-22 17:03:35Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
@@ -285,21 +285,29 @@ static void on_signal (void *data, Evas_Object *o,
 
 /*
  * call-seq:
- *  edje.on_signal(signal, source) { |signal, source| block } => nil
+ *  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 (VALUE self, VALUE signal, VALUE src)
+static VALUE c_on_signal (int argc, VALUE *argv, VALUE self)
 {
-       VALUE cb;
+       VALUE signal, src, cb;
+       char *ssrc = "*";
 
        GET_OBJ (self, RbEdje, e);
 
+       rb_scan_args (argc, argv, "11", &signal, &src);
+
        Check_Type (signal, T_STRING);
-       Check_Type (src, T_STRING);
+
+       if (!NIL_P (src)) {
+               Check_Type (src, T_STRING);
+               ssrc = StringValuePtr (src);
+       }
 
        if (!rb_block_given_p ())
                return Qnil;
@@ -309,8 +317,7 @@ static VALUE c_on_signal (VALUE self, VALUE signal, VALUE src)
 
        edje_object_signal_callback_add (e->real.real,
                                         StringValuePtr (signal),
-                                        StringValuePtr (src), on_signal,
-                                        (void *) cb);
+                                        ssrc, on_signal, (void *) cb);
 
        return Qnil;
 }
@@ -375,6 +382,19 @@ static VALUE c_animation_set (VALUE self, VALUE val)
        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;
+}
+
 void Init_Edje (void)
 {
        cEdje = rb_define_class_under (mEdje, "Edje", cEvasObject);
@@ -389,9 +409,10 @@ void Init_Edje (void)
        rb_define_method (cEdje, "part", c_part_get, 1);
        rb_define_method (cEdje, "on_text_changed", c_on_text_changed, 0);
        rb_define_method (cEdje, "emit_signal", c_emit_signal, 2);
-       rb_define_method (cEdje, "on_signal", c_on_signal, 2);
+       rb_define_method (cEdje, "on_signal", c_on_signal, -1);
        rb_define_method (cEdje, "play?", c_play_get, 0);
        rb_define_method (cEdje, "play=", c_play_set, 1);
        rb_define_method (cEdje, "animation?", c_animation_get, 0);
        rb_define_method (cEdje, "animation=", c_animation_set, 1);
+       rb_define_method (cEdje, "data", c_data_get, 1);
 }