/*
- * $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); \
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,
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
*/
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;
}
{
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);
}