/*
- * $Id: rb_edje.c 66 2004-08-12 19:37:52Z tilman $
+ * $Id: rb_edje.c 139 2004-10-30 09:41:17Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#include "rb_edje.h"
#include "rb_edje_main.h"
#include "rb_part.h"
+#include "rb_messages.h"
VALUE cEdje;
/*
* 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;
edje_object_signal_callback_add (e->real.real,
StringValuePtr (signal),
- StringValuePtr (src), on_signal,
- (void *) cb);
+ ssrc, on_signal, (void *) cb);
return Qnil;
}
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)
+{
+ VALUE m;
+ Edje_Message_Type type;
+ int id;
+
+ GET_OBJ (self, RbEdje, e);
+
+ CHECK_CLASS (msg, cMsg);
+
+ type = NUM2INT (rb_iv_get (msg, "@type"));
+ id = NUM2INT (rb_iv_get (msg, "@id"));
+ m = rb_funcall (msg, rb_intern ("serialize"), 0, NULL);
+
+ edje_object_message_send (e->real.real, type, id, (void *) m);
+
+ return Qnil;
+}
+
void Init_Edje (void)
{
cEdje = rb_define_class_under (mEdje, "Edje", cEvasObject);
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);
+ rb_define_method (cEdje, "send_message", c_send_message, 1);
}