2 * $Id: rb_edje.c 37 2004-07-25 11:19:48Z 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) \
32 Data_Get_Struct ((obj), type, (o)); \
35 rb_raise (rb_eException, \
36 "%s destroyed already", \
37 rb_obj_classname ((obj))); \
41 #define CHECK_BOOL(val) \
42 if (TYPE ((val)) != T_TRUE && TYPE ((val)) != T_FALSE) { \
43 rb_raise (rb_eTypeError, \
44 "wrong argument type %s (expected true or false)", \
45 rb_obj_classname ((val))); \
49 #define CHECK_CLASS(val, klass) \
50 if (!rb_obj_is_kind_of ((val), (klass))) { \
51 rb_raise (rb_eTypeError, \
52 "wrong argument type %s (expected %s)", \
53 rb_obj_classname ((val)), \
54 rb_class2name ((klass))); \
58 static void c_free (Evas_Object **e)
60 c_evas_object_free (e);
65 static VALUE c_new (VALUE klass, VALUE evas)
70 CHECK_CLASS (evas, cEvas);
71 GET_OBJ (evas, Evas *, e);
75 self = Data_Make_Struct (klass, Evas_Object *, c_evas_object_mark,
77 *edje = edje_object_add (*e);
80 rb_obj_call_init (self, 1, argv);
85 static VALUE c_load (VALUE self, VALUE eet, VALUE group)
87 GET_OBJ (self, Evas_Object *, e);
89 Check_Type (eet, T_STRING);
90 Check_Type (group, T_STRING);
92 if (!edje_object_file_set (*e, StringValuePtr (eet),
93 StringValuePtr (group)))
94 rb_raise (rb_eException, "Cannot load eet");
99 static VALUE c_get_size_min (VALUE self)
103 GET_OBJ (self, Evas_Object *, e);
105 edje_object_size_min_get (*e, &w, &h);
107 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
110 static VALUE c_get_size_max (VALUE self)
114 GET_OBJ (self, Evas_Object *, e);
116 edje_object_size_max_get (*e, &w, &h);
118 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
121 static VALUE c_part_exists_get (VALUE self, VALUE part)
125 GET_OBJ (self, Evas_Object *, e);
127 Check_Type (part, T_STRING);
129 r = edje_object_part_exists (*e, StringValuePtr (part));
131 return r ? Qtrue : Qfalse;
134 static VALUE c_part_swallow (VALUE self, VALUE part, VALUE target)
136 GET_OBJ (self, Evas_Object *, e);
138 Check_Type (part, T_STRING);
140 CHECK_CLASS (target, cEvasObject);
141 GET_OBJ (target, Evas_Object *, target2);
143 edje_object_part_swallow (*e, StringValuePtr (part), *target2);
148 static VALUE c_part_unswallow (VALUE self, VALUE target)
150 GET_OBJ (self, Evas_Object *, e);
152 CHECK_CLASS (target, cEvasObject);
153 GET_OBJ (target, Evas_Object *, target2);
155 edje_object_part_unswallow (*e, *target2);
160 static VALUE c_get_part_swallow (VALUE self, VALUE part)
165 GET_OBJ (self, Evas_Object *, e);
167 Check_Type (part, T_STRING);
169 if (!(o = edje_object_part_swallow_get (*e, StringValuePtr (part))))
172 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
173 rb_raise (rb_eException, "EvasObject Ruby object key missing");
180 static VALUE c_get_part_text (VALUE self, VALUE part)
184 GET_OBJ (self, Evas_Object *, e);
186 Check_Type (part, T_STRING);
188 if (!(s = edje_object_part_text_get (*e, StringValuePtr (part))))
191 return rb_str_new2 (s);
194 static VALUE c_set_part_text (VALUE self, VALUE part, VALUE text)
196 GET_OBJ (self, Evas_Object *, e);
198 Check_Type (part, T_STRING);
199 Check_Type (text, T_STRING);
201 edje_object_part_text_set (*e, StringValuePtr (part),
202 StringValuePtr (text));
207 static void on_text_changed (void *data, Evas_Object *e,
210 rb_funcall ((VALUE) data, rb_intern ("call"), 1,
214 static VALUE c_on_text_changed (VALUE self)
216 GET_OBJ (self, Evas_Object *, e);
218 if (!rb_block_given_p ())
221 edje_object_text_change_cb_set (*e, on_text_changed,
222 (void *) rb_block_proc ());
227 static VALUE c_signal_emit (VALUE self, VALUE emission, VALUE source)
229 GET_OBJ (self, Evas_Object *, e);
231 Check_Type (emission, T_STRING);
232 Check_Type (source, T_STRING);
234 edje_object_signal_emit (*e, StringValuePtr (emission),
235 StringValuePtr (source));
240 static void on_signal (void *data, Evas_Object *o,
241 const char *emission, const char *src) {
242 rb_funcall ((VALUE) data, rb_intern ("call"), 1,
243 rb_str_new2 (emission), rb_str_new2 (src));
246 static VALUE c_on_signal (VALUE self, VALUE signal, VALUE src)
248 GET_OBJ (self, Evas_Object *, e);
250 Check_Type (signal, T_STRING);
251 Check_Type (src, T_STRING);
253 if (!rb_block_given_p ())
256 edje_object_signal_callback_add (*e, StringValuePtr (signal),
257 StringValuePtr (src), on_signal,
258 (void *) rb_block_proc ());
263 static VALUE c_play_get (VALUE self)
265 GET_OBJ (self, Evas_Object *, e);
267 return edje_object_play_get (*e) ? Qtrue : Qfalse;
270 static VALUE c_play_set (VALUE self, VALUE val)
272 GET_OBJ (self, Evas_Object *, e);
276 edje_object_play_set (*e, val == Qtrue ? 1 : 0);
281 static VALUE c_animation_get (VALUE self)
283 GET_OBJ (self, Evas_Object *, e);
285 return edje_object_animation_get (*e) ? Qtrue : Qfalse;
288 static VALUE c_animation_set (VALUE self, VALUE val)
290 GET_OBJ (self, Evas_Object *, e);
294 edje_object_animation_set (*e, val == Qtrue ? 1 : 0);
299 void Init_Edje (void)
301 VALUE c = rb_define_class_under (mEdje, "Edje", cEvasObject);
303 rb_define_singleton_method (c, "new", c_new, 1);
304 rb_define_method (c, "load", c_load, 2);
305 rb_define_method (c, "get_size_min", c_get_size_min, 0);
306 rb_define_method (c, "get_size_max", c_get_size_max, 0);
307 rb_define_method (c, "part_exists?", c_part_exists_get, 1);
308 rb_define_method (c, "part_swallow", c_part_swallow, 2);
309 rb_define_method (c, "part_unswallow", c_part_unswallow, 1);
310 rb_define_method (c, "get_part_swallow", c_get_part_swallow, 1);
311 rb_define_method (c, "get_part_text", c_get_part_text, 1);
312 rb_define_method (c, "set_part_text", c_set_part_text, 2);
313 rb_define_method (c, "on_text_changed", c_on_text_changed, 0);
314 rb_define_method (c, "signal_emit", c_signal_emit, 1);
315 rb_define_method (c, "on_signal", c_on_signal, 2);
316 rb_define_method (c, "play?", c_play_get, 0);
317 rb_define_method (c, "play=", c_play_set, 1);
318 rb_define_method (c, "animation?", c_animation_get, 0);
319 rb_define_method (c, "animation=", c_animation_set, 1);