X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Frb_smart.c;fp=src%2Frb_smart.c;h=4abce295972d66d648d7681efbda24956c7f7777;hb=ff457c57c3ac469622c2fcd6bf9e66a55c1df678;hp=b9379e0d90dc95916a736ded4e1b91a1ecd7f97e;hpb=ab841e74c1011d7fdc2e793aae70578957a5bcc6;p=ruby-evas.git diff --git a/src/rb_smart.c b/src/rb_smart.c index b9379e0..4abce29 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 354 2006-02-10 18:14:08Z 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); \ @@ -98,20 +84,25 @@ static void on_color_set (Evas_Object *o, int r, int g, int b, int a) INT2FIX (a)); } +static VALUE c_alloc (VALUE klass) +{ + Evas_Smart **smart = NULL; + + return Data_Make_Struct (klass, Evas_Smart *, NULL, free, smart); +} + /* * 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_init (VALUE self, VALUE name) { - VALUE self; - Evas_Smart **smart; + GET_OBJ (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, @@ -119,16 +110,9 @@ static VALUE c_new (VALUE klass, VALUE name) on_show, on_hide, on_color_set, on_clip_set, on_clip_unset, NULL); - rb_obj_call_init (self, 0, NULL); - return self; } -static void c_object_free (RbEvasObject *e) -{ - c_evas_object_free (e, true); -} - /* * call-seq: * smart.new_object(class, evas) => smart_obj @@ -137,23 +121,20 @@ static void c_object_free (RbEvasObject *e) */ static VALUE c_new_object (VALUE self, VALUE klass, VALUE evas) { - VALUE obj, argv[1]; - RbEvasObject *smart; + VALUE obj; CHECK_CLASS (evas, cEvas); GET_OBJ (evas, RbEvas, e); GET_OBJ (self, Evas_Smart *, s); - obj = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark, - c_object_free, smart); - smart->real = evas_object_smart_add (e->real, *s); + obj = rb_obj_alloc (klass); - evas_object_data_set (smart->real, RUBY_EVAS_SMART_OBJECT_KEY, - (void *) obj); + GET_OBJ (obj, RbEvasObject, smart); + + smart->real = evas_object_smart_add (e->real, *s); - argv[0] = evas; - rb_obj_call_init (obj, 1, argv); + rb_obj_call_init (obj, 1, &evas); return obj; } @@ -162,6 +143,7 @@ void Init_Smart (void) { VALUE c = rb_define_class_under (mEvas, "Smart", rb_cObject); - rb_define_singleton_method (c, "new", c_new, 1); + rb_define_alloc_func (c, c_alloc); + rb_define_method (c, "initialize", c_init, 1); rb_define_method (c, "new_object", c_new_object, 2); }