2 * $Id: rb_edje.c 48 2004-07-31 13:46:07Z 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>
28 #include "rb_edje_main.h"
39 static void c_mark (RbEdje *e)
41 c_evas_object_mark (&e->real);
43 rb_gc_mark (e->parts);
44 rb_gc_mark (e->callbacks);
47 static void c_free (RbEdje *e)
49 c_evas_object_free (&e->real);
54 static VALUE c_new (VALUE klass, VALUE evas)
59 CHECK_CLASS (evas, cEvas);
60 GET_OBJ (evas, Evas *, e);
64 self = Data_Make_Struct (klass, RbEdje, c_mark, c_free, edje);
66 edje->real = edje_object_add (*e);
67 edje->parts = rb_hash_new ();
68 edje->callbacks = rb_ary_new ();
71 rb_obj_call_init (self, 1, argv);
76 static VALUE c_freeze (VALUE self)
78 GET_OBJ (self, RbEdje, e);
80 edje_object_freeze (e->real);
85 static VALUE c_thaw (VALUE self)
87 GET_OBJ (self, RbEdje, e);
89 edje_object_thaw (e->real);
94 static VALUE c_load (VALUE self, VALUE eet, VALUE group)
96 GET_OBJ (self, RbEdje, e);
98 Check_Type (eet, T_STRING);
99 Check_Type (group, T_STRING);
101 if (!edje_object_file_set (e->real, StringValuePtr (eet),
102 StringValuePtr (group)))
103 rb_raise (rb_eException, "Cannot load eet");
108 static VALUE c_get_size_min (VALUE self)
112 GET_OBJ (self, RbEdje, e);
114 edje_object_size_min_get (e->real, &w, &h);
116 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
119 static VALUE c_get_size_max (VALUE self)
123 GET_OBJ (self, RbEdje, e);
125 edje_object_size_max_get (e->real, &w, &h);
127 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
130 static VALUE c_part_exists_get (VALUE self, VALUE name)
134 GET_OBJ (self, RbEdje, e);
136 Check_Type (name, T_STRING);
138 r = edje_object_part_exists (e->real, StringValuePtr (name));
140 return r ? Qtrue : Qfalse;
143 static VALUE c_part_get (VALUE self, VALUE name)
147 GET_OBJ (self, RbEdje, e);
149 Check_Type (name, T_STRING);
151 if (!edje_object_part_exists (e->real, StringValuePtr (name)))
154 if (NIL_P (part = rb_hash_aref (e->parts, name))) {
155 part = TO_PART (self, name);
156 rb_hash_aset (e->parts, name, part);
162 static void on_text_changed (void *data, Evas_Object *e,
165 rb_funcall ((VALUE) data, rb_intern ("call"), 1,
169 static VALUE c_on_text_changed (VALUE self)
171 GET_OBJ (self, RbEdje, e);
173 if (!rb_block_given_p ())
176 edje_object_text_change_cb_set (e->real, on_text_changed,
177 (void *) rb_block_proc ());
182 static VALUE c_emit_signal (VALUE self, VALUE emission, VALUE source)
184 GET_OBJ (self, RbEdje, e);
186 Check_Type (emission, T_STRING);
187 Check_Type (source, T_STRING);
189 edje_object_signal_emit (e->real, StringValuePtr (emission),
190 StringValuePtr (source));
195 static void on_signal (void *data, Evas_Object *o,
196 const char *emission, const char *src)
198 rb_funcall ((VALUE) data, rb_intern ("call"), 2,
199 rb_str_new2 (emission), rb_str_new2 (src));
202 static VALUE c_on_signal (VALUE self, VALUE signal, VALUE src)
206 GET_OBJ (self, RbEdje, e);
208 Check_Type (signal, T_STRING);
209 Check_Type (src, T_STRING);
211 if (!rb_block_given_p ())
214 cb = rb_block_proc ();
215 rb_ary_push (e->callbacks, cb);
217 edje_object_signal_callback_add (e->real, StringValuePtr (signal),
218 StringValuePtr (src), on_signal,
224 static VALUE c_play_get (VALUE self)
226 GET_OBJ (self, RbEdje, e);
228 return edje_object_play_get (e->real) ? Qtrue : Qfalse;
231 static VALUE c_play_set (VALUE self, VALUE val)
233 GET_OBJ (self, RbEdje, e);
237 edje_object_play_set (e->real, val == Qtrue);
242 static VALUE c_animation_get (VALUE self)
244 GET_OBJ (self, RbEdje, e);
246 return edje_object_animation_get (e->real) ? Qtrue : Qfalse;
249 static VALUE c_animation_set (VALUE self, VALUE val)
251 GET_OBJ (self, RbEdje, e);
255 edje_object_animation_set (e->real, val == Qtrue);
260 void Init_Edje (void)
262 cEdje = rb_define_class_under (mEdje, "Edje", cEvasObject);
264 rb_define_singleton_method (cEdje, "new", c_new, 1);
265 rb_define_method (cEdje, "freeze", c_freeze, 0);
266 rb_define_method (cEdje, "thaw", c_thaw, 0);
267 rb_define_method (cEdje, "load", c_load, 2);
268 rb_define_method (cEdje, "get_size_min", c_get_size_min, 0);
269 rb_define_method (cEdje, "get_size_max", c_get_size_max, 0);
270 rb_define_method (cEdje, "part_exists?", c_part_exists_get, 1);
271 rb_define_method (cEdje, "part", c_part_get, 1);
272 rb_define_method (cEdje, "on_text_changed", c_on_text_changed, 0);
273 rb_define_method (cEdje, "emit_signal", c_emit_signal, 2);
274 rb_define_method (cEdje, "on_signal", c_on_signal, 2);
275 rb_define_method (cEdje, "play?", c_play_get, 0);
276 rb_define_method (cEdje, "play=", c_play_set, 1);
277 rb_define_method (cEdje, "animation?", c_animation_get, 0);
278 rb_define_method (cEdje, "animation=", c_animation_set, 1);