2 * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "rb_evas_main.h"
25 #include "rb_evas_object.h"
27 #define SMART_CB_BODY(name) \
28 VALUE self = TO_EVAS_OBJECT (o); \
32 id = rb_intern ("smart_"#name); \
34 if (!rb_respond_to (self, id)) \
37 #define SMART_CB(name) \
38 static void smart_##name (Evas_Object *o) \
40 SMART_CB_BODY (name); \
41 rb_funcall (self, id, 0); \
44 #define SMART_CB_OBJ(name) \
45 static void smart_##name (Evas_Object *o, Evas_Object *other) \
47 SMART_CB_BODY (name); \
48 rb_funcall (self, id, 1, TO_EVAS_OBJECT (other)); \
51 #define SMART_CB_COORD(name) \
52 static void smart_##name (Evas_Object *o, Evas_Coord a, Evas_Coord b) \
54 SMART_CB_BODY (name); \
55 rb_funcall (self, id, 2, INT2FIX ((int) a), INT2FIX ((int) b)); \
59 Evas_Smart_Class smart_class;
65 static ID id_smart_data;
70 SMART_CB (clip_unset);
71 SMART_CB_OBJ (clip_set);
72 SMART_CB_COORD (move);
73 SMART_CB_COORD (resize);
75 static void smart_color_set (Evas_Object *o, int r, int g, int b, int a)
77 SMART_CB_BODY (color_set);
79 rb_funcall (self, id, 4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
83 static VALUE c_inherited (VALUE klass, VALUE child)
85 rb_const_set (child, id_smart_data, Qnil);
91 c_data_mark (SmartData *sd)
93 rb_gc_mark (sd->name);
96 static VALUE c_init (VALUE self, VALUE evas)
101 CHECK_CLASS (evas, cEvas);
102 GET_OBJ (evas, RbEvas, e);
103 GET_OBJ (self, RbEvasObject, s2);
105 klass = rb_obj_class (self);
107 /* check whether the smart object has been created already */
108 data = rb_const_get (klass, id_smart_data);
110 Data_Get_Struct (data, SmartData, sd);
112 data = Data_Make_Struct (rb_cObject, SmartData,
113 c_data_mark, NULL, sd);
115 sd->name = rb_class_path (klass);
117 sd->smart_class.name = StringValuePtr (sd->name);
118 sd->smart_class.version = EVAS_SMART_CLASS_VERSION;
120 sd->smart_class.add = NULL;
121 sd->smart_class.del = smart_delete;
122 sd->smart_class.move = smart_move;
123 sd->smart_class.resize = smart_resize;
124 sd->smart_class.show = smart_show;
125 sd->smart_class.hide = smart_hide;
126 sd->smart_class.color_set = smart_color_set;
127 sd->smart_class.clip_set = smart_clip_set;
128 sd->smart_class.clip_unset = smart_clip_unset;
130 sd->smart = evas_smart_class_new (&sd->smart_class);
132 rb_mod_remove_const (klass, ID2SYM (id_smart_data));
133 rb_const_set (klass, id_smart_data, data);
136 s2->real = evas_object_smart_add (e->real, sd->smart);
138 rb_call_super (1, &evas);
143 static VALUE c_add_member (VALUE self, VALUE member)
145 GET_OBJ (self, RbEvasObject, e);
146 GET_OBJ (member, RbEvasObject, e2);
148 /* weird order of arguments */
149 evas_object_smart_member_add (e2->real, e->real);
154 void Init_Smart (void)
156 VALUE c = rb_define_class_under (mEvas, "Smart", cEvasObject);
158 rb_define_singleton_method (c, "inherited", c_inherited, 1);
159 rb_define_method (c, "initialize", c_init, 1);
160 rb_define_method (c, "add_member", c_add_member, 1);
162 id_smart_data = rb_intern ("SMART_DATA");