Class instantiation fixes.
[ruby-evas.git] / src / rb_smart.c
index b9379e0d90dc95916a736ded4e1b91a1ecd7f97e..4abce295972d66d648d7681efbda24956c7f7777 100644 (file)
@@ -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)
  *
 #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);
 }