X-Git-Url: http://git.code-monkey.de/?p=ruby-edje.git;a=blobdiff_plain;f=src%2Frb_edje.c;h=50ba39b4369a613393ada20ff00e67098f65019e;hp=c85e594bed7d4e3fe3375023a99dbb66c63fb237;hb=251fa1fd3a3b4949b4919bf377a9b73e23f0cf0e;hpb=fc473416558a8d1cbccdabfe9ab5fae2a1e987fa diff --git a/src/rb_edje.c b/src/rb_edje.c index c85e594..50ba39b 100644 --- a/src/rb_edje.c +++ b/src/rb_edje.c @@ -1,5 +1,5 @@ /* - * $Id: rb_edje.c 48 2004-07-31 13:46:07Z tilman $ + * $Id: rb_edje.c 66 2004-08-12 19:37:52Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -21,19 +21,14 @@ #include #include -#include -#include +#include +#include #define __RB_EDJE_C +#include "rb_edje.h" #include "rb_edje_main.h" #include "rb_part.h" -typedef struct { - Evas_Object *real; - VALUE parts; - VALUE callbacks; -} RbEdje; - VALUE cEdje; static void c_mark (RbEdje *e) @@ -42,30 +37,40 @@ static void c_mark (RbEdje *e) rb_gc_mark (e->parts); rb_gc_mark (e->callbacks); + + if (!NIL_P (e->on_text_changed_cb)) + rb_gc_mark (e->on_text_changed_cb); } static void c_free (RbEdje *e) { - c_evas_object_free (&e->real); + c_evas_object_free (&e->real, false); 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]; - RbEdje *edje; + RbEdje *edje = NULL; CHECK_CLASS (evas, cEvas); - GET_OBJ (evas, Evas *, e); + GET_OBJ (evas, RbEvas, e); edje_init (); self = Data_Make_Struct (klass, RbEdje, c_mark, c_free, edje); - edje->real = edje_object_add (*e); + edje->real.real = edje_object_add (e->real); edje->parts = rb_hash_new (); edje->callbacks = rb_ary_new (); + edje->on_text_changed_cb = Qnil; argv[0] = evas; rb_obj_call_init (self, 1, argv); @@ -73,24 +78,43 @@ 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); - edje_object_freeze (e->real); + edje_object_freeze (e->real.real); return Qnil; } +/* + * call-seq: + * edje.thaw => nil + * + * Thaws edje. + */ static VALUE c_thaw (VALUE self) { GET_OBJ (self, RbEdje, e); - edje_object_thaw (e->real); + edje_object_thaw (e->real.real); 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); @@ -98,35 +122,56 @@ static VALUE c_load (VALUE self, VALUE eet, VALUE group) Check_Type (eet, T_STRING); Check_Type (group, T_STRING); - if (!edje_object_file_set (e->real, StringValuePtr (eet), + if (!edje_object_file_set (e->real.real, StringValuePtr (eet), StringValuePtr (group))) rb_raise (rb_eException, "Cannot load eet"); 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; GET_OBJ (self, RbEdje, e); - edje_object_size_min_get (e->real, &w, &h); + 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 edje. + */ 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, &w, &h); + 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 edje has a part called part, + * else returns false. + */ static VALUE c_part_exists_get (VALUE self, VALUE name) { int r; @@ -135,21 +180,30 @@ static VALUE c_part_exists_get (VALUE self, VALUE name) Check_Type (name, T_STRING); - r = edje_object_part_exists (e->real, StringValuePtr (name)); + r = edje_object_part_exists (e->real.real, StringValuePtr (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; GET_OBJ (self, RbEdje, e); - Check_Type (name, T_STRING); - if (!edje_object_part_exists (e->real, StringValuePtr (name))) + if (!edje_object_part_exists (e->real.real, StringValuePtr (name))) { + rb_raise (rb_eException, "Unknown part name"); return Qnil; + } if (NIL_P (part = rb_hash_aref (e->parts, name))) { part = TO_PART (self, name); @@ -159,13 +213,33 @@ static VALUE c_part_get (VALUE self, VALUE name) return part; } -static void on_text_changed (void *data, Evas_Object *e, - const char *part) +static void on_text_changed (void *data, Evas_Object *eo, + const char *part_name) { - rb_funcall ((VALUE) data, rb_intern ("call"), 1, - rb_str_new2 (part)); + VALUE self = (VALUE) data, part, name; + + GET_OBJ (self, RbEdje, e); + + name = rb_str_new2 (part_name); + + 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 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); @@ -173,32 +247,51 @@ static VALUE c_on_text_changed (VALUE self) if (!rb_block_given_p ()) return Qnil; - edje_object_text_change_cb_set (e->real, on_text_changed, - (void *) rb_block_proc ()); + e->on_text_changed_cb = rb_block_proc (); + + edje_object_text_change_cb_set (e->real.real, on_text_changed, + (void *) 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, 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)); } +/* + * call-seq: + * edje.on_signal(signal, source) { |signal, source| block } => nil + * + * Registers a callback that will get called when signal + * is emitted by source. + * The block is passed two strings, signal and source, which identify + * the emission. + */ static VALUE c_on_signal (VALUE self, VALUE signal, VALUE src) { VALUE cb; @@ -214,45 +307,70 @@ static VALUE c_on_signal (VALUE self, VALUE signal, VALUE src) cb = rb_block_proc (); rb_ary_push (e->callbacks, cb); - edje_object_signal_callback_add (e->real, StringValuePtr (signal), + edje_object_signal_callback_add (e->real.real, + StringValuePtr (signal), StringValuePtr (src), 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); - return edje_object_play_get (e->real) ? Qtrue : Qfalse; + 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); CHECK_BOOL(val); - edje_object_play_set (e->real, val == Qtrue); + edje_object_play_set (e->real.real, val == Qtrue); 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); - return edje_object_animation_get (e->real) ? Qtrue : Qfalse; + 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); CHECK_BOOL(val); - edje_object_animation_set (e->real, val == Qtrue); + edje_object_animation_set (e->real.real, val == Qtrue); return Qnil; }