2 * $Id: rb_smart.c 68 2004-08-16 15:42:19Z 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 RUBY_EVAS_SMART_OBJECT_KEY "__RB_EVAS_OBJECT_SMART_OBJECT"
31 #define GET_EVAS_OBJECT(obj, o) \
34 obj = (VALUE) evas_object_data_get (o, \
35 RUBY_EVAS_SMART_OBJECT_KEY); \
37 rb_raise (rb_eException, \
38 "EvasObject Ruby object key missing"); \
42 #define SMART_CB_BODY(name) \
45 GET_EVAS_OBJECT (self, o); \
48 id = rb_intern ("on_"#name); \
50 if (!rb_respond_to (self, id)) \
53 #define SMART_CB(name) \
54 static void on_##name (Evas_Object *o) \
56 SMART_CB_BODY (name); \
57 rb_funcall (self, id, 0); \
60 #define SMART_CB_OBJ(name) \
61 static void on_##name (Evas_Object *o, Evas_Object *other) \
63 SMART_CB_BODY (name); \
64 rb_funcall (self, id, 1, TO_EVAS_OBJECT (other)); \
67 #define SMART_CB_COORD(name) \
68 static void on_##name (Evas_Object *o, Evas_Coord a, Evas_Coord b) \
70 SMART_CB_BODY (name); \
71 rb_funcall (self, id, 2, INT2FIX ((int) a), INT2FIX ((int) b)); \
79 SMART_CB (clip_unset);
80 SMART_CB_OBJ (stack_above);
81 SMART_CB_OBJ (stack_below);
82 SMART_CB_OBJ (clip_set);
83 SMART_CB_COORD (move);
84 SMART_CB_COORD (resize);
86 static void on_layer_set (Evas_Object *o, int layer)
88 SMART_CB_BODY (layer_set);
90 rb_funcall (self, id, 1, FIX2INT (layer));
93 static void on_color_set (Evas_Object *o, int r, int g, int b, int a)
95 SMART_CB_BODY (color_set);
97 rb_funcall (self, id, 4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
103 * Evas::Smart.new(name) => smart
105 * Creates a Evas::Smart object with the given name.
107 static VALUE c_new (VALUE klass, VALUE name)
112 Check_Type (name, T_STRING);
114 self = Data_Make_Struct (klass, Evas_Smart *, NULL, free, smart);
115 *smart = evas_smart_new (StringValuePtr (name),
116 NULL, on_delete, on_layer_set,
117 on_raise, on_lower, on_stack_above,
118 on_stack_below, on_move, on_resize,
119 on_show, on_hide, on_color_set,
120 on_clip_set, on_clip_unset, NULL);
122 rb_obj_call_init (self, 0, NULL);
127 static void c_object_free (RbEvasObject *e)
129 c_evas_object_free (e, true);
134 * smart.new_object(class, evas) => smart_obj
136 * Creates a Evas::EvasObject from <i>smart</i>.
138 static VALUE c_new_object (VALUE self, VALUE klass, VALUE evas)
143 CHECK_CLASS (evas, cEvas);
144 GET_OBJ (evas, RbEvas, e);
146 GET_OBJ (self, Evas_Smart *, s);
148 obj = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark,
149 c_object_free, smart);
150 smart->real = evas_object_smart_add (e->real, *s);
152 evas_object_data_set (smart->real, RUBY_EVAS_SMART_OBJECT_KEY,
156 rb_obj_call_init (obj, 1, argv);
161 void Init_Smart (void)
163 VALUE c = rb_define_class_under (mEvas, "Smart", rb_cObject);
165 rb_define_singleton_method (c, "new", c_new, 1);
166 rb_define_method (c, "new_object", c_new_object, 2);