X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Frb_smart.c;h=32a729d868519b9ef9bcc439a011e29cf0872685;hb=afead3a417018aa09e32bf16a026b3deec0b29dc;hp=4abce295972d66d648d7681efbda24956c7f7777;hpb=ff457c57c3ac469622c2fcd6bf9e66a55c1df678;p=ruby-evas.git diff --git a/src/rb_smart.c b/src/rb_smart.c index 4abce29..32a729d 100644 --- a/src/rb_smart.c +++ b/src/rb_smart.c @@ -1,5 +1,5 @@ /* - * $Id: rb_smart.c 354 2006-02-10 18:14:08Z tilman $ + * $Id: rb_smart.c 381 2006-05-21 14:56:15Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -57,25 +57,16 @@ rb_funcall (self, id, 2, INT2FIX ((int) a), INT2FIX ((int) b)); \ } +static ID id_smart_object; + SMART_CB (delete); -SMART_CB (raise); -SMART_CB (lower); SMART_CB (show); SMART_CB (hide); SMART_CB (clip_unset); -SMART_CB_OBJ (stack_above); -SMART_CB_OBJ (stack_below); SMART_CB_OBJ (clip_set); SMART_CB_COORD (move); SMART_CB_COORD (resize); -static void on_layer_set (Evas_Object *o, int layer) -{ - SMART_CB_BODY (layer_set); - - rb_funcall (self, id, 1, FIX2INT (layer)); -} - static void on_color_set (Evas_Object *o, int r, int g, int b, int a) { SMART_CB_BODY (color_set); @@ -84,66 +75,69 @@ static void on_color_set (Evas_Object *o, int r, int g, int b, int a) INT2FIX (a)); } -static VALUE c_alloc (VALUE klass) +static VALUE c_inherited (VALUE klass, VALUE child) { - Evas_Smart **smart = NULL; + rb_const_set (child, id_smart_object, Qnil); - return Data_Make_Struct (klass, Evas_Smart *, NULL, free, smart); + return Qnil; } -/* - * call-seq: - * Evas::Smart.new(name) => smart - * - * Creates a Evas::Smart object with the given name. - */ -static VALUE c_init (VALUE self, VALUE name) +static VALUE c_init (VALUE self, VALUE evas) { - GET_OBJ (self, Evas_Smart *, smart); + VALUE klass, smart, name; + Evas_Smart **s = NULL; - Check_Type (name, T_STRING); + CHECK_CLASS (evas, cEvas); + GET_OBJ (evas, RbEvas, e); + GET_OBJ (self, RbEvasObject, s2); - *smart = evas_smart_new (StringValuePtr (name), - NULL, on_delete, on_layer_set, - on_raise, on_lower, on_stack_above, - on_stack_below, on_move, on_resize, - on_show, on_hide, on_color_set, - on_clip_set, on_clip_unset, NULL); + klass = rb_obj_class (self); - return self; -} + /* check whether the smart object has been created already */ + smart = rb_const_get (klass, id_smart_object); + if (!NIL_P (smart)) + Data_Get_Struct (smart, Evas_Smart *, s); + else { + name = rb_class_path (klass); -/* - * call-seq: - * smart.new_object(class, evas) => smart_obj - * - * Creates a Evas::EvasObject from smart. - */ -static VALUE c_new_object (VALUE self, VALUE klass, VALUE evas) -{ - VALUE obj; + smart = Data_Make_Struct (rb_cObject, Evas_Smart *, NULL, NULL, s); - CHECK_CLASS (evas, cEvas); - GET_OBJ (evas, RbEvas, e); + *s = evas_smart_new (StringValuePtr (name), + NULL, on_delete, NULL, + NULL, NULL, NULL, NULL, + on_move, on_resize, + on_show, on_hide, on_color_set, + on_clip_set, on_clip_unset, NULL); - GET_OBJ (self, Evas_Smart *, s); + rb_mod_remove_const(klass, ID2SYM (id_smart_object)); + rb_const_set (klass, id_smart_object, smart); + } + + s2->real = evas_object_smart_add (e->real, *s); - obj = rb_obj_alloc (klass); + rb_call_super (1, &evas); - GET_OBJ (obj, RbEvasObject, smart); + return self; +} - smart->real = evas_object_smart_add (e->real, *s); +static VALUE c_add_member (VALUE self, VALUE member) +{ + GET_OBJ (self, RbEvasObject, e); + GET_OBJ (member, RbEvasObject, e2); - rb_obj_call_init (obj, 1, &evas); + /* weird order of arguments */ + evas_object_smart_member_add (e2->real, e->real); - return obj; + return Qnil; } void Init_Smart (void) { - VALUE c = rb_define_class_under (mEvas, "Smart", rb_cObject); + VALUE c = rb_define_class_under (mEvas, "Smart", cEvasObject); - rb_define_alloc_func (c, c_alloc); + rb_define_singleton_method (c, "inherited", c_inherited, 1); rb_define_method (c, "initialize", c_init, 1); - rb_define_method (c, "new_object", c_new_object, 2); + rb_define_method (c, "add_member", c_add_member, 1); + + id_smart_object = rb_intern ("SMART_OBJECT"); }