X-Git-Url: http://git.code-monkey.de/?p=ruby-edje.git;a=blobdiff_plain;f=src%2Frb_edje.c;h=f47fbd801fac392680c44f776394ef5bcf323102;hp=d6f60f29e5fa73198f50eed7eca88ceb7e47e5f9;hb=79794506e25681ff820cf8504ec1c622ee9ab77b;hpb=6c2cc2ece3ed1e6f4446983a608763c47be0d74c diff --git a/src/rb_edje.c b/src/rb_edje.c index d6f60f2..f47fbd8 100644 --- a/src/rb_edje.c +++ b/src/rb_edje.c @@ -1,5 +1,5 @@ /* - * $Id: rb_edje.c 19 2004-06-22 20:40:05Z tilman $ + * $Id: rb_edje.c 31 2004-07-10 14:06:07Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -26,13 +26,15 @@ #include "rb_edje_main.h" -#define GET_OBJ(obj, type, o, desc) \ +#define GET_OBJ(obj, type, o) \ type **(o) = NULL; \ \ Data_Get_Struct ((obj), type *, (o)); \ \ if (!*(o)) { \ - rb_raise (rb_eException, desc " destroyed already"); \ + rb_raise (rb_eException, \ + "%s destroyed already", \ + rb_obj_classname ((obj))); \ return Qnil; \ } @@ -44,17 +46,34 @@ return Qnil; \ } -VALUE cEdje; +#define CHECK_CLASS(val, klass) \ + if (!rb_obj_is_kind_of ((val), (klass))) { \ + rb_raise (rb_eTypeError, \ + "wrong argument type %s (expected %s)", \ + rb_obj_classname ((val)), \ + rb_obj_classname ((klass))); \ + return Qnil; \ + } + +static void c_free (Evas_Object **e) +{ + c_evas_object_free (e); + + edje_shutdown (); +} static VALUE c_new (VALUE klass, VALUE evas) { VALUE self, argv[1]; Evas_Object **edje; - GET_OBJ (evas, Evas, e, "Evas"); + CHECK_CLASS (evas, cEvas); + GET_OBJ (evas, Evas, e); + + edje_init (); self = Data_Make_Struct (klass, Evas_Object *, c_evas_object_mark, - c_evas_object_free, edje); + c_free, edje); *edje = edje_object_add (*e); argv[0] = evas; @@ -65,7 +84,7 @@ static VALUE c_new (VALUE klass, VALUE evas) static VALUE c_load (VALUE self, VALUE eet, VALUE group) { - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); Check_Type (eet, T_STRING); Check_Type (group, T_STRING); @@ -81,7 +100,7 @@ static VALUE c_get_size_min (VALUE self) { int w = 0, h = 0; - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); edje_object_size_min_get (*e, &w, &h); @@ -92,7 +111,7 @@ static VALUE c_get_size_max (VALUE self) { int w = 0, h = 0; - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); edje_object_size_max_get (*e, &w, &h); @@ -103,7 +122,7 @@ static VALUE c_part_exists_get (VALUE self, VALUE part) { int r; - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); Check_Type (part, T_STRING); @@ -114,18 +133,12 @@ static VALUE c_part_exists_get (VALUE self, VALUE part) static VALUE c_part_swallow (VALUE self, VALUE part, VALUE target) { - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); Check_Type (part, T_STRING); - if (!rb_obj_is_kind_of (target, cEvasObject)) { - rb_raise (rb_eTypeError, - "wrong argument type %s (expected EvasObject)", - rb_obj_classname (target)); - return Qnil; - } - - GET_OBJ (target, Evas_Object, target2, "EvasObject"); + CHECK_CLASS (target, cEvasObject); + GET_OBJ (target, Evas_Object, target2); edje_object_part_swallow (*e, StringValuePtr (part), *target2); @@ -134,16 +147,10 @@ static VALUE c_part_swallow (VALUE self, VALUE part, VALUE target) static VALUE c_part_unswallow (VALUE self, VALUE target) { - GET_OBJ (self, Evas_Object, e, "Edje"); - - if (!rb_obj_is_kind_of (target, cEvasObject)) { - rb_raise (rb_eTypeError, - "wrong argument type %s (expected EvasObject)", - rb_obj_classname (target)); - return Qnil; - } + GET_OBJ (self, Evas_Object, e); - GET_OBJ (target, Evas_Object, target2, "EvasObject"); + CHECK_CLASS (target, cEvasObject); + GET_OBJ (target, Evas_Object, target2); edje_object_part_unswallow (*e, *target2); @@ -155,7 +162,7 @@ static VALUE c_get_part_swallow (VALUE self, VALUE part) Evas_Object *o; void *obj; - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); Check_Type (part, T_STRING); @@ -174,7 +181,7 @@ static VALUE c_get_part_text (VALUE self, VALUE part) { const char *s; - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); Check_Type (part, T_STRING); @@ -186,7 +193,7 @@ static VALUE c_get_part_text (VALUE self, VALUE part) static VALUE c_set_part_text (VALUE self, VALUE part, VALUE text) { - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); Check_Type (part, T_STRING); Check_Type (text, T_STRING); @@ -206,7 +213,7 @@ static void on_text_changed (void *data, Evas_Object *e, static VALUE c_on_text_changed (VALUE self) { - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); if (!rb_block_given_p ()) return Qnil; @@ -219,7 +226,7 @@ static VALUE c_on_text_changed (VALUE self) static VALUE c_signal_emit (VALUE self, VALUE emission, VALUE source) { - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); Check_Type (emission, T_STRING); Check_Type (source, T_STRING); @@ -230,16 +237,39 @@ static VALUE c_signal_emit (VALUE self, VALUE emission, VALUE source) return Qnil; } +static void on_signal (void *data, Evas_Object *o, + const char *emission, const char *src) { + rb_funcall ((VALUE) data, rb_intern ("call"), 1, + rb_str_new2 (emission), rb_str_new2 (src)); +} + +static VALUE c_on_signal (VALUE self, VALUE signal, VALUE src) +{ + GET_OBJ (self, Evas_Object, e); + + Check_Type (signal, T_STRING); + Check_Type (src, T_STRING); + + if (!rb_block_given_p ()) + return Qnil; + + edje_object_signal_callback_add (*e, StringValuePtr (signal), + StringValuePtr (src), on_signal, + (void *) rb_block_proc ()); + + return Qnil; +} + static VALUE c_play_get (VALUE self) { - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); return edje_object_play_get (*e) ? Qtrue : Qfalse; } static VALUE c_play_set (VALUE self, VALUE val) { - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); CHECK_BOOL(val); @@ -250,14 +280,14 @@ static VALUE c_play_set (VALUE self, VALUE val) static VALUE c_animation_get (VALUE self) { - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); return edje_object_animation_get (*e) ? Qtrue : Qfalse; } static VALUE c_animation_set (VALUE self, VALUE val) { - GET_OBJ (self, Evas_Object, e, "Edje"); + GET_OBJ (self, Evas_Object, e); CHECK_BOOL(val); @@ -268,7 +298,7 @@ static VALUE c_animation_set (VALUE self, VALUE val) void Init_Edje (void) { - cEdje = rb_define_class_under (mEdje, "Edje", cEvasObject); + VALUE cEdje = rb_define_class_under (mEdje, "Edje", cEvasObject); rb_define_singleton_method (cEdje, "new", c_new, 1); rb_define_method (cEdje, "load", c_load, 2); @@ -282,9 +312,9 @@ void Init_Edje (void) rb_define_method (cEdje, "set_part_text", c_set_part_text, 2); rb_define_method (cEdje, "on_text_changed", c_on_text_changed, 0); rb_define_method (cEdje, "signal_emit", c_signal_emit, 1); + rb_define_method (cEdje, "on_signal", c_on_signal, 2); 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); } -