From ee7deb06e7acec3a4c8989981603ad047647ce47 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Tue, 21 Feb 2006 21:20:35 +0000 Subject: [PATCH] Finalize Evas::Smart API. You'll now have to inherit from Evas::Smart and define SMART_NAME in your class to get a smart object. --- src/rb_smart.c | 79 +++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/src/rb_smart.c b/src/rb_smart.c index 4abce29..ba7bd30 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 374 2006-02-21 21:20:35Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -57,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); @@ -84,66 +86,57 @@ 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); - - Check_Type (name, T_STRING); - - *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); - - return self; -} - -/* - * 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; + 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 = rb_obj_alloc (klass); + /* 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); - GET_OBJ (obj, RbEvasObject, smart); + smart = Data_Make_Struct (rb_cObject, Evas_Smart *, NULL, NULL, s); - smart->real = evas_object_smart_add (e->real, *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_obj_call_init (obj, 1, &evas); + rb_mod_remove_const(klass, ID2SYM (id_smart_object)); + rb_const_set (klass, id_smart_object, smart); + } - return obj; + s2->real = evas_object_smart_add (e->real, *s); + + rb_call_super (1, &evas); + + return self; } 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); + + id_smart_object = rb_intern ("SMART_OBJECT"); } -- 2.30.2