2 * $Id: rb_smart.c 380 2006-05-21 14:54:58Z 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;
67 SMART_CB (clip_unset);
68 SMART_CB_OBJ (stack_above);
69 SMART_CB_OBJ (stack_below);
70 SMART_CB_OBJ (clip_set);
71 SMART_CB_COORD (move);
72 SMART_CB_COORD (resize);
74 static void on_layer_set (Evas_Object *o, int layer)
76 SMART_CB_BODY (layer_set);
78 rb_funcall (self, id, 1, FIX2INT (layer));
81 static void on_color_set (Evas_Object *o, int r, int g, int b, int a)
83 SMART_CB_BODY (color_set);
85 rb_funcall (self, id, 4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
89 static VALUE c_inherited (VALUE klass, VALUE child)
91 rb_const_set (child, id_smart_object, Qnil);
96 static VALUE c_init (VALUE self, VALUE evas)
98 VALUE klass, smart, name;
99 Evas_Smart **s = NULL;
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 smart = rb_const_get (klass, id_smart_object);
110 Data_Get_Struct (smart, Evas_Smart *, s);
112 name = rb_class_path (klass);
114 smart = Data_Make_Struct (rb_cObject, Evas_Smart *, NULL, NULL, s);
116 *s = evas_smart_new (StringValuePtr (name),
117 NULL, on_delete, on_layer_set,
118 on_raise, on_lower, on_stack_above,
119 on_stack_below, on_move, on_resize,
120 on_show, on_hide, on_color_set,
121 on_clip_set, on_clip_unset, NULL);
123 rb_mod_remove_const(klass, ID2SYM (id_smart_object));
124 rb_const_set (klass, id_smart_object, smart);
127 s2->real = evas_object_smart_add (e->real, *s);
129 rb_call_super (1, &evas);
134 static VALUE c_add_member (VALUE self, VALUE member)
136 GET_OBJ (self, RbEvasObject, e);
137 GET_OBJ (member, RbEvasObject, e2);
139 /* weird order of arguments */
140 evas_object_smart_member_add (e2->real, e->real);
145 void Init_Smart (void)
147 VALUE c = rb_define_class_under (mEvas, "Smart", cEvasObject);
149 rb_define_singleton_method (c, "inherited", c_inherited, 1);
150 rb_define_method (c, "initialize", c_init, 1);
151 rb_define_method (c, "add_member", c_add_member, 1);
153 id_smart_object = rb_intern ("SMART_OBJECT");