2 * $Id: rb_edje.c 21 2004-06-25 17:41:17Z 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))); \
49 static VALUE c_new (VALUE klass, VALUE evas)
54 GET_OBJ (evas, Evas, e, "Evas");
56 self = Data_Make_Struct (klass, Evas_Object *, c_evas_object_mark,
57 c_evas_object_free, edje);
58 *edje = edje_object_add (*e);
61 rb_obj_call_init (self, 1, argv);
66 static VALUE c_load (VALUE self, VALUE eet, VALUE group)
68 GET_OBJ (self, Evas_Object, e, "Edje");
70 Check_Type (eet, T_STRING);
71 Check_Type (group, T_STRING);
73 if (!edje_object_file_set (*e, StringValuePtr (eet),
74 StringValuePtr (group)))
75 rb_raise (rb_eException, "Cannot load eet");
80 static VALUE c_get_size_min (VALUE self)
84 GET_OBJ (self, Evas_Object, e, "Edje");
86 edje_object_size_min_get (*e, &w, &h);
88 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
91 static VALUE c_get_size_max (VALUE self)
95 GET_OBJ (self, Evas_Object, e, "Edje");
97 edje_object_size_max_get (*e, &w, &h);
99 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
102 static VALUE c_part_exists_get (VALUE self, VALUE part)
106 GET_OBJ (self, Evas_Object, e, "Edje");
108 Check_Type (part, T_STRING);
110 r = edje_object_part_exists (*e, StringValuePtr (part));
112 return r ? Qtrue : Qfalse;
115 static VALUE c_part_swallow (VALUE self, VALUE part, VALUE target)
117 GET_OBJ (self, Evas_Object, e, "Edje");
119 Check_Type (part, T_STRING);
121 if (!rb_obj_is_kind_of (target, cEvasObject)) {
122 rb_raise (rb_eTypeError,
123 "wrong argument type %s (expected EvasObject)",
124 rb_obj_classname (target));
128 GET_OBJ (target, Evas_Object, target2, "EvasObject");
130 edje_object_part_swallow (*e, StringValuePtr (part), *target2);
135 static VALUE c_part_unswallow (VALUE self, VALUE target)
137 GET_OBJ (self, Evas_Object, e, "Edje");
139 if (!rb_obj_is_kind_of (target, cEvasObject)) {
140 rb_raise (rb_eTypeError,
141 "wrong argument type %s (expected EvasObject)",
142 rb_obj_classname (target));
146 GET_OBJ (target, Evas_Object, target2, "EvasObject");
148 edje_object_part_unswallow (*e, *target2);
153 static VALUE c_get_part_swallow (VALUE self, VALUE part)
158 GET_OBJ (self, Evas_Object, e, "Edje");
160 Check_Type (part, T_STRING);
162 if (!(o = edje_object_part_swallow_get (*e, StringValuePtr (part))))
165 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
166 rb_raise (rb_eException, "EvasObject Ruby object key missing");
173 static VALUE c_get_part_text (VALUE self, VALUE part)
177 GET_OBJ (self, Evas_Object, e, "Edje");
179 Check_Type (part, T_STRING);
181 if (!(s = edje_object_part_text_get (*e, StringValuePtr (part))))
184 return rb_str_new2 (s);
187 static VALUE c_set_part_text (VALUE self, VALUE part, VALUE text)
189 GET_OBJ (self, Evas_Object, e, "Edje");
191 Check_Type (part, T_STRING);
192 Check_Type (text, T_STRING);
194 edje_object_part_text_set (*e, StringValuePtr (part),
195 StringValuePtr (text));
200 static void on_text_changed (void *data, Evas_Object *e,
203 rb_funcall ((VALUE) data, rb_intern ("call"), 1,
207 static VALUE c_on_text_changed (VALUE self)
209 GET_OBJ (self, Evas_Object, e, "Edje");
211 if (!rb_block_given_p ())
214 edje_object_text_change_cb_set (*e, on_text_changed,
215 (void *) rb_block_proc ());
220 static VALUE c_signal_emit (VALUE self, VALUE emission, VALUE source)
222 GET_OBJ (self, Evas_Object, e, "Edje");
224 Check_Type (emission, T_STRING);
225 Check_Type (source, T_STRING);
227 edje_object_signal_emit (*e, StringValuePtr (emission),
228 StringValuePtr (source));
233 static void on_signal (void *data, Evas_Object *o,
234 const char *emission, const char *src) {
235 rb_funcall ((VALUE) data, rb_intern ("call"), 1,
236 rb_str_new2 (emission), rb_str_new2 (src));
239 static VALUE c_on_signal (VALUE self, VALUE signal, VALUE src)
241 GET_OBJ (self, Evas_Object, e, "Edje");
243 Check_Type (signal, T_STRING);
244 Check_Type (src, T_STRING);
246 if (!rb_block_given_p ())
249 edje_object_signal_callback_add (*e, StringValuePtr (signal),
250 StringValuePtr (src), on_signal,
251 (void *) rb_block_proc ());
256 static VALUE c_play_get (VALUE self)
258 GET_OBJ (self, Evas_Object, e, "Edje");
260 return edje_object_play_get (*e) ? Qtrue : Qfalse;
263 static VALUE c_play_set (VALUE self, VALUE val)
265 GET_OBJ (self, Evas_Object, e, "Edje");
269 edje_object_play_set (*e, val == Qtrue ? 1 : 0);
274 static VALUE c_animation_get (VALUE self)
276 GET_OBJ (self, Evas_Object, e, "Edje");
278 return edje_object_animation_get (*e) ? Qtrue : Qfalse;
281 static VALUE c_animation_set (VALUE self, VALUE val)
283 GET_OBJ (self, Evas_Object, e, "Edje");
287 edje_object_animation_set (*e, val == Qtrue ? 1 : 0);
292 void Init_Edje (void)
294 cEdje = rb_define_class_under (mEdje, "Edje", cEvasObject);
296 rb_define_singleton_method (cEdje, "new", c_new, 1);
297 rb_define_method (cEdje, "load", c_load, 2);
298 rb_define_method (cEdje, "get_size_min", c_get_size_min, 0);
299 rb_define_method (cEdje, "get_size_max", c_get_size_max, 0);
300 rb_define_method (cEdje, "part_exists?", c_part_exists_get, 1);
301 rb_define_method (cEdje, "part_swallow", c_part_swallow, 2);
302 rb_define_method (cEdje, "part_unswallow", c_part_unswallow, 1);
303 rb_define_method (cEdje, "get_part_swallow", c_get_part_swallow, 1);
304 rb_define_method (cEdje, "get_part_text", c_get_part_text, 1);
305 rb_define_method (cEdje, "set_part_text", c_set_part_text, 2);
306 rb_define_method (cEdje, "on_text_changed", c_on_text_changed, 0);
307 rb_define_method (cEdje, "signal_emit", c_signal_emit, 1);
308 rb_define_method (cEdje, "on_signal", c_on_signal, 2);
309 rb_define_method (cEdje, "play?", c_play_get, 0);
310 rb_define_method (cEdje, "play=", c_play_set, 1);
311 rb_define_method (cEdje, "animation?", c_animation_get, 0);
312 rb_define_method (cEdje, "animation=", c_animation_set, 1);