X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Frb_edje.c;h=02ff4ea2f254abec8e9e88531bc5fe6e8a98c5b7;hb=7003b6f4e489403e126d372ce017996147b35491;hp=57509cfc37044e2e0bff0b69e831017bd64556f3;hpb=3a9c35673bdd0dc885f7474865be23d6d0061789;p=ruby-edje.git
diff --git a/src/rb_edje.c b/src/rb_edje.c
index 57509cf..02ff4ea 100644
--- a/src/rb_edje.c
+++ b/src/rb_edje.c
@@ -1,5 +1,5 @@
/*
- * $Id: rb_edje.c 51 2004-08-01 10:19:02Z tilman $
+ * $Id: rb_edje.c 328 2005-04-28 07:44:46Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
@@ -28,6 +28,7 @@
#include "rb_edje.h"
#include "rb_edje_main.h"
#include "rb_part.h"
+#include "rb_messages.h"
VALUE cEdje;
@@ -35,8 +36,11 @@ static void c_mark (RbEdje *e)
{
c_evas_object_mark (&e->real);
- rb_gc_mark (e->parts);
- rb_gc_mark (e->callbacks);
+ if (!NIL_P (e->parts))
+ rb_gc_mark (e->parts);
+
+ if (!NIL_P (e->callbacks))
+ rb_gc_mark (e->callbacks);
if (!NIL_P (e->on_text_changed_cb))
rb_gc_mark (e->on_text_changed_cb);
@@ -45,10 +49,17 @@ static void c_mark (RbEdje *e)
static void c_free (RbEdje *e)
{
c_evas_object_free (&e->real, false);
+ free (e);
edje_shutdown ();
}
+/*
+ * call-seq:
+ * Edje::Edje.new(evas) => edje
+ *
+ * Creates an Edje::Edje object.
+ */
static VALUE c_new (VALUE klass, VALUE evas)
{
VALUE self, argv[1];
@@ -62,8 +73,8 @@ static VALUE c_new (VALUE klass, VALUE evas)
self = Data_Make_Struct (klass, RbEdje, c_mark, c_free, edje);
edje->real.real = edje_object_add (e->real);
- edje->parts = rb_hash_new ();
- edje->callbacks = rb_ary_new ();
+ edje->parts = Qnil;
+ edje->callbacks = Qnil;
edje->on_text_changed_cb = Qnil;
argv[0] = evas;
@@ -72,6 +83,12 @@ static VALUE c_new (VALUE klass, VALUE evas)
return self;
}
+/*
+ * call-seq:
+ * edje.freeze => nil
+ *
+ * Freezes edje.
+ */
static VALUE c_freeze (VALUE self)
{
GET_OBJ (self, RbEdje, e);
@@ -81,6 +98,12 @@ static VALUE c_freeze (VALUE self)
return Qnil;
}
+/*
+ * call-seq:
+ * edje.thaw => nil
+ *
+ * Thaws edje.
+ */
static VALUE c_thaw (VALUE self)
{
GET_OBJ (self, RbEdje, e);
@@ -90,6 +113,13 @@ static VALUE c_thaw (VALUE self)
return Qnil;
}
+/*
+ * call-seq:
+ * edje.load(eet, group) => nil
+ *
+ * Loads eet into edje. group is the
+ * name of the group to be displayed.
+ */
static VALUE c_load (VALUE self, VALUE eet, VALUE group)
{
GET_OBJ (self, RbEdje, e);
@@ -104,6 +134,13 @@ static VALUE c_load (VALUE self, VALUE eet, VALUE group)
return Qnil;
}
+/*
+ * call-seq:
+ * edje.get_size_min => array
+ *
+ * Returns an array that contains the minimum size
+ * of edje.
+ */
static VALUE c_get_size_min (VALUE self)
{
int w = 0, h = 0;
@@ -115,6 +152,13 @@ static VALUE c_get_size_min (VALUE self)
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 edje.
+ */
static VALUE c_get_size_max (VALUE self)
{
int w = 0, h = 0;
@@ -126,6 +170,13 @@ static VALUE c_get_size_max (VALUE self)
return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
}
+/*
+ * call-seq:
+ * edje.part_exists?(part) => true or false
+ *
+ * Returns true if edje has a part called part,
+ * else returns false.
+ */
static VALUE c_part_exists_get (VALUE self, VALUE name)
{
int r;
@@ -139,15 +190,28 @@ static VALUE c_part_exists_get (VALUE self, VALUE name)
return r ? Qtrue : Qfalse;
}
+/*
+ * call-seq:
+ * edje.part(part_name) => part
+ *
+ * Returns the Edje::Part
object that corresponds to
+ * part_name. If there's no part with that name in edje,
+ * 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);
- Check_Type (name, T_STRING);
- if (!edje_object_part_exists (e->real.real, StringValuePtr (name)))
+ 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);
@@ -166,6 +230,9 @@ static void on_text_changed (void *data, Evas_Object *eo,
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);
@@ -175,6 +242,15 @@ static void on_text_changed (void *data, Evas_Object *eo,
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 edje.
+ * The block is passed the Edje::Part
object
+ * of which the text changed.
+ */
static VALUE c_on_text_changed (VALUE self)
{
GET_OBJ (self, RbEdje, e);
@@ -190,49 +266,83 @@ static VALUE c_on_text_changed (VALUE self)
return Qnil;
}
-static VALUE c_emit_signal (VALUE self, VALUE emission, VALUE source)
+/*
+ * call-seq:
+ * edje.emit_signal(signal, source) => nil
+ *
+ * Emits a signal to edje.
+ *
+ * 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 (emission, T_STRING);
+ Check_Type (signal, T_STRING);
Check_Type (source, T_STRING);
- edje_object_signal_emit (e->real.real, StringValuePtr (emission),
+ edje_object_signal_emit (e->real.real, StringValuePtr (signal),
StringValuePtr (source));
return Qnil;
}
static void on_signal (void *data, Evas_Object *o,
- const char *emission, const char *src)
+ const char *signal, const char *src)
{
rb_funcall ((VALUE) data, rb_intern ("call"), 2,
- rb_str_new2 (emission), rb_str_new2 (src));
+ rb_str_new2 (signal), rb_str_new2 (src));
}
-static VALUE c_on_signal (VALUE self, VALUE signal, VALUE src)
+/*
+ * call-seq:
+ * edje.on_signal(signal [, source]) { |signal, source| block } => nil
+ *
+ * Registers a callback that will get called when signal
+ * is emitted by source.
+ * 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 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;
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),
- StringValuePtr (src), on_signal,
- (void *) cb);
+ ssrc, on_signal, (void *) cb);
return Qnil;
}
+/*
+ * call-seq:
+ * edje.play? => true or false
+ *
+ * Returns true if edje is in play mode, else returns false.
+ */
static VALUE c_play_get (VALUE self)
{
GET_OBJ (self, RbEdje, e);
@@ -240,6 +350,12 @@ static VALUE c_play_get (VALUE self)
return edje_object_play_get (e->real.real) ? Qtrue : Qfalse;
}
+/*
+ * call-seq:
+ * edje.play(true or false)
+ *
+ * Sets edje to play resp. pause mode.
+ */
static VALUE c_play_set (VALUE self, VALUE val)
{
GET_OBJ (self, RbEdje, e);
@@ -251,6 +367,12 @@ static VALUE c_play_set (VALUE self, VALUE val)
return Qnil;
}
+/*
+ * call-seq:
+ * edje.animation? => true or false
+ *
+ * Returns the animation state of edje.
+ */
static VALUE c_animation_get (VALUE self)
{
GET_OBJ (self, RbEdje, e);
@@ -258,6 +380,12 @@ static VALUE c_animation_get (VALUE self)
return edje_object_animation_get (e->real.real) ? Qtrue : Qfalse;
}
+/*
+ * call-seq:
+ * edje.animation(true or false)
+ *
+ * Sets the animation state of edje.
+ */
static VALUE c_animation_set (VALUE self, VALUE val)
{
GET_OBJ (self, RbEdje, e);
@@ -269,6 +397,38 @@ 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;
+}
+
+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);
@@ -283,9 +443,11 @@ 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);
+ rb_define_method (cEdje, "send_message", c_send_message, 1);
}