X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Frb_smart.c;h=030909523b1de41889df82fd3d6152dc213d6e19;hb=5ec95b786c1f48b1e4d6816c3a144d22e8432471;hp=b9379e0d90dc95916a736ded4e1b91a1ecd7f97e;hpb=7389b77f481a867dd769c5ee08eb75329184ae04;p=ruby-evas.git diff --git a/src/rb_smart.c b/src/rb_smart.c index b9379e0..0309095 100644 --- a/src/rb_smart.c +++ b/src/rb_smart.c @@ -1,5 +1,5 @@ /* - * $Id: rb_smart.c 68 2004-08-16 15:42:19Z tilman $ + * $Id: rb_smart.c 380 2006-05-21 14:54:58Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -26,23 +26,9 @@ #include "rb_evas.h" #include "rb_evas_object.h" -#define RUBY_EVAS_SMART_OBJECT_KEY "__RB_EVAS_OBJECT_SMART_OBJECT" - -#define GET_EVAS_OBJECT(obj, o) \ - VALUE (obj); \ -\ - obj = (VALUE) evas_object_data_get (o, \ - RUBY_EVAS_SMART_OBJECT_KEY); \ - if (!obj) { \ - rb_raise (rb_eException, \ - "EvasObject Ruby object key missing"); \ - return; \ - } - #define SMART_CB_BODY(name) \ + VALUE self = TO_EVAS_OBJECT (o); \ static ID id; \ -\ - GET_EVAS_OBJECT (self, o); \ \ if (!id) \ id = rb_intern ("on_"#name); \ @@ -71,6 +57,8 @@ 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); @@ -98,70 +86,69 @@ static void on_color_set (Evas_Object *o, int r, int g, int b, int a) INT2FIX (a)); } -/* - * call-seq: - * Evas::Smart.new(name) => smart - * - * Creates a Evas::Smart object with the given name. - */ -static VALUE c_new (VALUE klass, VALUE name) +static VALUE c_inherited (VALUE klass, VALUE child) { - VALUE self; - Evas_Smart **smart; - - Check_Type (name, T_STRING); - - self = Data_Make_Struct (klass, Evas_Smart *, NULL, free, smart); - *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); - - rb_obj_call_init (self, 0, NULL); - - return self; -} + rb_const_set (child, id_smart_object, Qnil); -static void c_object_free (RbEvasObject *e) -{ - c_evas_object_free (e, true); + return Qnil; } -/* - * 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) +static VALUE c_init (VALUE self, VALUE evas) { - VALUE obj, argv[1]; - RbEvasObject *smart; + VALUE klass, smart, name; + Evas_Smart **s = NULL; CHECK_CLASS (evas, cEvas); GET_OBJ (evas, RbEvas, e); + GET_OBJ (self, RbEvasObject, s2); - GET_OBJ (self, Evas_Smart *, s); + klass = rb_obj_class (self); - obj = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark, - c_object_free, smart); - smart->real = evas_object_smart_add (e->real, *s); + /* 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); + + smart = Data_Make_Struct (rb_cObject, Evas_Smart *, NULL, NULL, s); + + *s = 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); + + rb_mod_remove_const(klass, ID2SYM (id_smart_object)); + rb_const_set (klass, id_smart_object, smart); + } - evas_object_data_set (smart->real, RUBY_EVAS_SMART_OBJECT_KEY, - (void *) obj); + s2->real = evas_object_smart_add (e->real, *s); - argv[0] = evas; - rb_obj_call_init (obj, 1, argv); + rb_call_super (1, &evas); - return obj; + return self; +} + +static VALUE c_add_member (VALUE self, VALUE member) +{ + GET_OBJ (self, RbEvasObject, e); + GET_OBJ (member, RbEvasObject, e2); + + /* weird order of arguments */ + evas_object_smart_member_add (e2->real, e->real); + + 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_singleton_method (c, "inherited", c_inherited, 1); + rb_define_method (c, "initialize", c_init, 1); + rb_define_method (c, "add_member", c_add_member, 1); - rb_define_singleton_method (c, "new", c_new, 1); - rb_define_method (c, "new_object", c_new_object, 2); + id_smart_object = rb_intern ("SMART_OBJECT"); }