2 * $Id: rb_edje.c 47 2004-07-26 13:24:50Z 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"
32 static VALUE part_hashes;
34 static void c_free (Evas_Object **e)
36 c_evas_object_free (e);
38 rb_hash_aset (part_hashes, INT2NUM ((long) e), Qnil);
43 static VALUE c_new (VALUE klass, VALUE evas)
48 CHECK_CLASS (evas, cEvas);
49 GET_OBJ (evas, Evas *, e);
53 self = Data_Make_Struct (klass, Evas_Object *, c_evas_object_mark,
55 *edje = edje_object_add (*e);
58 rb_obj_call_init (self, 1, argv);
63 static VALUE c_load (VALUE self, VALUE eet, VALUE group)
65 GET_OBJ (self, Evas_Object *, e);
67 Check_Type (eet, T_STRING);
68 Check_Type (group, T_STRING);
70 if (!edje_object_file_set (*e, StringValuePtr (eet),
71 StringValuePtr (group)))
72 rb_raise (rb_eException, "Cannot load eet");
77 static VALUE c_get_size_min (VALUE self)
81 GET_OBJ (self, Evas_Object *, e);
83 edje_object_size_min_get (*e, &w, &h);
85 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
88 static VALUE c_get_size_max (VALUE self)
92 GET_OBJ (self, Evas_Object *, e);
94 edje_object_size_max_get (*e, &w, &h);
96 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
99 static VALUE c_part_exists_get (VALUE self, VALUE name)
103 GET_OBJ (self, Evas_Object *, e);
105 Check_Type (name, T_STRING);
107 r = edje_object_part_exists (*e, StringValuePtr (name));
109 return r ? Qtrue : Qfalse;
112 static VALUE c_part_get (VALUE self, VALUE name)
116 GET_OBJ (self, Evas_Object *, e);
118 Check_Type (name, T_STRING);
120 if (!edje_object_part_exists (*e, StringValuePtr (name)))
123 parts = rb_hash_aref (part_hashes, INT2NUM ((long) (e)));
125 parts = rb_hash_new ();
126 rb_hash_aset (part_hashes, INT2NUM ((long) e), parts);
129 if (NIL_P (part = rb_hash_aref (parts, name))) {
130 part = TO_PART (self, name);
131 rb_hash_aset (parts, name, part);
137 static void on_text_changed (void *data, Evas_Object *e,
140 rb_funcall ((VALUE) data, rb_intern ("call"), 1,
144 static VALUE c_on_text_changed (VALUE self)
146 GET_OBJ (self, Evas_Object *, e);
148 if (!rb_block_given_p ())
151 edje_object_text_change_cb_set (*e, on_text_changed,
152 (void *) rb_block_proc ());
157 static VALUE c_signal_emit (VALUE self, VALUE emission, VALUE source)
159 GET_OBJ (self, Evas_Object *, e);
161 Check_Type (emission, T_STRING);
162 Check_Type (source, T_STRING);
164 edje_object_signal_emit (*e, StringValuePtr (emission),
165 StringValuePtr (source));
170 static void on_signal (void *data, Evas_Object *o,
171 const char *emission, const char *src)
173 rb_funcall ((VALUE) data, rb_intern ("call"), 1,
174 rb_str_new2 (emission), rb_str_new2 (src));
177 static VALUE c_on_signal (VALUE self, VALUE signal, VALUE src)
179 GET_OBJ (self, Evas_Object *, e);
181 Check_Type (signal, T_STRING);
182 Check_Type (src, T_STRING);
184 if (!rb_block_given_p ())
187 edje_object_signal_callback_add (*e, StringValuePtr (signal),
188 StringValuePtr (src), on_signal,
189 (void *) rb_block_proc ());
194 static VALUE c_play_get (VALUE self)
196 GET_OBJ (self, Evas_Object *, e);
198 return edje_object_play_get (*e) ? Qtrue : Qfalse;
201 static VALUE c_play_set (VALUE self, VALUE val)
203 GET_OBJ (self, Evas_Object *, e);
207 edje_object_play_set (*e, val == Qtrue);
212 static VALUE c_animation_get (VALUE self)
214 GET_OBJ (self, Evas_Object *, e);
216 return edje_object_animation_get (*e) ? Qtrue : Qfalse;
219 static VALUE c_animation_set (VALUE self, VALUE val)
221 GET_OBJ (self, Evas_Object *, e);
225 edje_object_animation_set (*e, val == Qtrue);
230 void Init_Edje (void)
232 cEdje = rb_define_class_under (mEdje, "Edje", cEvasObject);
234 rb_define_singleton_method (cEdje, "new", c_new, 1);
235 rb_define_method (cEdje, "load", c_load, 2);
236 rb_define_method (cEdje, "get_size_min", c_get_size_min, 0);
237 rb_define_method (cEdje, "get_size_max", c_get_size_max, 0);
238 rb_define_method (cEdje, "part_exists?", c_part_exists_get, 1);
239 rb_define_method (cEdje, "part", c_part_get, 1);
240 rb_define_method (cEdje, "on_text_changed", c_on_text_changed, 0);
241 rb_define_method (cEdje, "signal_emit", c_signal_emit, 1);
242 rb_define_method (cEdje, "on_signal", c_on_signal, 2);
243 rb_define_method (cEdje, "play?", c_play_get, 0);
244 rb_define_method (cEdje, "play=", c_play_set, 1);
245 rb_define_method (cEdje, "animation?", c_animation_get, 0);
246 rb_define_method (cEdje, "animation=", c_animation_set, 1);
248 part_hashes = rb_hash_new ();
249 rb_global_variable (&part_hashes);