2 * $Id: rb_edje.c 24 2004-06-26 22:59:56Z 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_object.h>
27 #include "rb_edje_main.h"
29 #define GET_OBJ(obj, type, o, desc) \
32 Data_Get_Struct ((obj), type *, (o)); \
35 rb_raise (rb_eException, desc " destroyed already"); \
39 #define CHECK_BOOL(val) \
40 if (TYPE ((val)) != T_TRUE && TYPE ((val)) != T_FALSE) { \
41 rb_raise (rb_eTypeError, \
42 "wrong argument type %s (expected true or false)", \
43 rb_obj_classname ((val))); \
47 static VALUE c_new (VALUE klass, VALUE evas)
52 if (!rb_obj_is_kind_of (evas, cEvas)) {
53 rb_raise (rb_eTypeError,
54 "wrong argument type %s (expected Evas)",
55 rb_obj_classname (evas));
59 GET_OBJ (evas, Evas, e, "Evas");
61 self = Data_Make_Struct (klass, Evas_Object *, c_evas_object_mark,
62 c_evas_object_free, edje);
63 *edje = edje_object_add (*e);
66 rb_obj_call_init (self, 1, argv);
71 static VALUE c_load (VALUE self, VALUE eet, VALUE group)
73 GET_OBJ (self, Evas_Object, e, "Edje");
75 Check_Type (eet, T_STRING);
76 Check_Type (group, T_STRING);
78 if (!edje_object_file_set (*e, StringValuePtr (eet),
79 StringValuePtr (group)))
80 rb_raise (rb_eException, "Cannot load eet");
85 static VALUE c_get_size_min (VALUE self)
89 GET_OBJ (self, Evas_Object, e, "Edje");
91 edje_object_size_min_get (*e, &w, &h);
93 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
96 static VALUE c_get_size_max (VALUE self)
100 GET_OBJ (self, Evas_Object, e, "Edje");
102 edje_object_size_max_get (*e, &w, &h);
104 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
107 static VALUE c_part_exists_get (VALUE self, VALUE part)
111 GET_OBJ (self, Evas_Object, e, "Edje");
113 Check_Type (part, T_STRING);
115 r = edje_object_part_exists (*e, StringValuePtr (part));
117 return r ? Qtrue : Qfalse;
120 static VALUE c_part_swallow (VALUE self, VALUE part, VALUE target)
122 GET_OBJ (self, Evas_Object, e, "Edje");
124 Check_Type (part, T_STRING);
126 if (!rb_obj_is_kind_of (target, cEvasObject)) {
127 rb_raise (rb_eTypeError,
128 "wrong argument type %s (expected EvasObject)",
129 rb_obj_classname (target));
133 GET_OBJ (target, Evas_Object, target2, "EvasObject");
135 edje_object_part_swallow (*e, StringValuePtr (part), *target2);
140 static VALUE c_part_unswallow (VALUE self, VALUE target)
142 GET_OBJ (self, Evas_Object, e, "Edje");
144 if (!rb_obj_is_kind_of (target, cEvasObject)) {
145 rb_raise (rb_eTypeError,
146 "wrong argument type %s (expected EvasObject)",
147 rb_obj_classname (target));
151 GET_OBJ (target, Evas_Object, target2, "EvasObject");
153 edje_object_part_unswallow (*e, *target2);
158 static VALUE c_get_part_swallow (VALUE self, VALUE part)
163 GET_OBJ (self, Evas_Object, e, "Edje");
165 Check_Type (part, T_STRING);
167 if (!(o = edje_object_part_swallow_get (*e, StringValuePtr (part))))
170 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
171 rb_raise (rb_eException, "EvasObject Ruby object key missing");
178 static VALUE c_get_part_text (VALUE self, VALUE part)
182 GET_OBJ (self, Evas_Object, e, "Edje");
184 Check_Type (part, T_STRING);
186 if (!(s = edje_object_part_text_get (*e, StringValuePtr (part))))
189 return rb_str_new2 (s);
192 static VALUE c_set_part_text (VALUE self, VALUE part, VALUE text)
194 GET_OBJ (self, Evas_Object, e, "Edje");
196 Check_Type (part, T_STRING);
197 Check_Type (text, T_STRING);
199 edje_object_part_text_set (*e, StringValuePtr (part),
200 StringValuePtr (text));
205 static void on_text_changed (void *data, Evas_Object *e,
208 rb_funcall ((VALUE) data, rb_intern ("call"), 1,
212 static VALUE c_on_text_changed (VALUE self)
214 GET_OBJ (self, Evas_Object, e, "Edje");
216 if (!rb_block_given_p ())
219 edje_object_text_change_cb_set (*e, on_text_changed,
220 (void *) rb_block_proc ());
225 static VALUE c_signal_emit (VALUE self, VALUE emission, VALUE source)
227 GET_OBJ (self, Evas_Object, e, "Edje");
229 Check_Type (emission, T_STRING);
230 Check_Type (source, T_STRING);
232 edje_object_signal_emit (*e, StringValuePtr (emission),
233 StringValuePtr (source));
238 static void on_signal (void *data, Evas_Object *o,
239 const char *emission, const char *src) {
240 rb_funcall ((VALUE) data, rb_intern ("call"), 1,
241 rb_str_new2 (emission), rb_str_new2 (src));
244 static VALUE c_on_signal (VALUE self, VALUE signal, VALUE src)
246 GET_OBJ (self, Evas_Object, e, "Edje");
248 Check_Type (signal, T_STRING);
249 Check_Type (src, T_STRING);
251 if (!rb_block_given_p ())
254 edje_object_signal_callback_add (*e, StringValuePtr (signal),
255 StringValuePtr (src), on_signal,
256 (void *) rb_block_proc ());
261 static VALUE c_play_get (VALUE self)
263 GET_OBJ (self, Evas_Object, e, "Edje");
265 return edje_object_play_get (*e) ? Qtrue : Qfalse;
268 static VALUE c_play_set (VALUE self, VALUE val)
270 GET_OBJ (self, Evas_Object, e, "Edje");
274 edje_object_play_set (*e, val == Qtrue ? 1 : 0);
279 static VALUE c_animation_get (VALUE self)
281 GET_OBJ (self, Evas_Object, e, "Edje");
283 return edje_object_animation_get (*e) ? Qtrue : Qfalse;
286 static VALUE c_animation_set (VALUE self, VALUE val)
288 GET_OBJ (self, Evas_Object, e, "Edje");
292 edje_object_animation_set (*e, val == Qtrue ? 1 : 0);
297 void Init_Edje (void)
299 VALUE cEdje = rb_define_class_under (mEdje, "Edje", cEvasObject);
301 rb_define_singleton_method (cEdje, "new", c_new, 1);
302 rb_define_method (cEdje, "load", c_load, 2);
303 rb_define_method (cEdje, "get_size_min", c_get_size_min, 0);
304 rb_define_method (cEdje, "get_size_max", c_get_size_max, 0);
305 rb_define_method (cEdje, "part_exists?", c_part_exists_get, 1);
306 rb_define_method (cEdje, "part_swallow", c_part_swallow, 2);
307 rb_define_method (cEdje, "part_unswallow", c_part_unswallow, 1);
308 rb_define_method (cEdje, "get_part_swallow", c_get_part_swallow, 1);
309 rb_define_method (cEdje, "get_part_text", c_get_part_text, 1);
310 rb_define_method (cEdje, "set_part_text", c_set_part_text, 2);
311 rb_define_method (cEdje, "on_text_changed", c_on_text_changed, 0);
312 rb_define_method (cEdje, "signal_emit", c_signal_emit, 1);
313 rb_define_method (cEdje, "on_signal", c_on_signal, 2);
314 rb_define_method (cEdje, "play?", c_play_get, 0);
315 rb_define_method (cEdje, "play=", c_play_set, 1);
316 rb_define_method (cEdje, "animation?", c_animation_get, 0);
317 rb_define_method (cEdje, "animation=", c_animation_set, 1);