2 * $Id: rb_smart.c 381 2006-05-21 14:56:15Z tilman $
4 * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "rb_evas_main.h"
27 #include "rb_evas_object.h"
29 #define SMART_CB_BODY(name) \
30 VALUE self = TO_EVAS_OBJECT (o); \
34 id = rb_intern ("on_"#name); \
36 if (!rb_respond_to (self, id)) \
39 #define SMART_CB(name) \
40 static void on_##name (Evas_Object *o) \
42 SMART_CB_BODY (name); \
43 rb_funcall (self, id, 0); \
46 #define SMART_CB_OBJ(name) \
47 static void on_##name (Evas_Object *o, Evas_Object *other) \
49 SMART_CB_BODY (name); \
50 rb_funcall (self, id, 1, TO_EVAS_OBJECT (other)); \
53 #define SMART_CB_COORD(name) \
54 static void on_##name (Evas_Object *o, Evas_Coord a, Evas_Coord b) \
56 SMART_CB_BODY (name); \
57 rb_funcall (self, id, 2, INT2FIX ((int) a), INT2FIX ((int) b)); \
60 static ID id_smart_object;
65 SMART_CB (clip_unset);
66 SMART_CB_OBJ (clip_set);
67 SMART_CB_COORD (move);
68 SMART_CB_COORD (resize);
70 static void on_color_set (Evas_Object *o, int r, int g, int b, int a)
72 SMART_CB_BODY (color_set);
74 rb_funcall (self, id, 4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
78 static VALUE c_inherited (VALUE klass, VALUE child)
80 rb_const_set (child, id_smart_object, Qnil);
85 static VALUE c_init (VALUE self, VALUE evas)
87 VALUE klass, smart, name;
88 Evas_Smart **s = NULL;
90 CHECK_CLASS (evas, cEvas);
91 GET_OBJ (evas, RbEvas, e);
92 GET_OBJ (self, RbEvasObject, s2);
94 klass = rb_obj_class (self);
96 /* check whether the smart object has been created already */
97 smart = rb_const_get (klass, id_smart_object);
99 Data_Get_Struct (smart, Evas_Smart *, s);
101 name = rb_class_path (klass);
103 smart = Data_Make_Struct (rb_cObject, Evas_Smart *, NULL, NULL, s);
105 *s = evas_smart_new (StringValuePtr (name),
106 NULL, on_delete, NULL,
107 NULL, NULL, NULL, NULL,
109 on_show, on_hide, on_color_set,
110 on_clip_set, on_clip_unset, NULL);
112 rb_mod_remove_const(klass, ID2SYM (id_smart_object));
113 rb_const_set (klass, id_smart_object, smart);
116 s2->real = evas_object_smart_add (e->real, *s);
118 rb_call_super (1, &evas);
123 static VALUE c_add_member (VALUE self, VALUE member)
125 GET_OBJ (self, RbEvasObject, e);
126 GET_OBJ (member, RbEvasObject, e2);
128 /* weird order of arguments */
129 evas_object_smart_member_add (e2->real, e->real);
134 void Init_Smart (void)
136 VALUE c = rb_define_class_under (mEvas, "Smart", cEvasObject);
138 rb_define_singleton_method (c, "inherited", c_inherited, 1);
139 rb_define_method (c, "initialize", c_init, 1);
140 rb_define_method (c, "add_member", c_add_member, 1);
142 id_smart_object = rb_intern ("SMART_OBJECT");