2 * $Id: rb_part.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>
27 #include "rb_edje_main.h"
32 static inline char *GET_NAME (VALUE o)
38 id = rb_intern ("@name");
40 name = rb_ivar_get (o, id);
42 return StringValuePtr (name);
45 static inline VALUE GET_EDJE (VALUE o)
50 id = rb_intern ("@edje");
52 return rb_ivar_get (o, id);
55 static void c_mark (VALUE *self)
57 rb_gc_mark (GET_EDJE (*self));
60 static void c_free (VALUE *self)
67 VALUE TO_PART (VALUE edje, VALUE name)
71 CHECK_CLASS (edje, cEdje);
72 Check_Type (name, T_STRING);
76 /* we only use Data_Make_Struct to be able to specify
77 * mark and sweep hooks
79 self = Data_Make_Struct (cPart, VALUE, c_mark, c_free, self2);
82 rb_iv_set (self, "@edje", edje);
83 rb_iv_set (self, "@name", rb_str_dup (name));
85 rb_obj_call_init (self, 0, NULL);
90 static VALUE c_get_geometry (VALUE self)
92 int x = 0, y = 0, w = 0, h = 0;
94 GET_OBJ (GET_EDJE (self), Evas_Object *, e);
96 edje_object_part_geometry_get (*e, GET_NAME (self),
102 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
103 INT2FIX (y), INT2FIX (h));
106 static VALUE c_swallow (VALUE self, VALUE target)
108 GET_OBJ (GET_EDJE (self), Evas_Object *, e);
110 CHECK_CLASS (target, cEvasObject);
111 GET_OBJ (target, Evas_Object *, target2);
113 edje_object_part_swallow (*e, GET_NAME (self), *target2);
118 static VALUE c_unswallow (VALUE self)
122 GET_OBJ (GET_EDJE (self), Evas_Object *, e);
124 if (!(o = edje_object_part_swallow_get (*e, GET_NAME (self)))) {
125 rb_raise (rb_eException, "Part didn't swallow an EvasObject");
129 edje_object_part_unswallow (*e, o);
134 static VALUE c_swallowed_object_get (VALUE self)
139 GET_OBJ (GET_EDJE (self), Evas_Object *, e);
141 if (!(o = edje_object_part_swallow_get (*e, GET_NAME (self))))
144 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
145 rb_raise (rb_eException, "EvasObject Ruby object key missing");
152 static VALUE c_text_get (VALUE self)
156 GET_OBJ (GET_EDJE (self), Evas_Object *, e);
158 if (!(s = edje_object_part_text_get (*e, GET_NAME (self))))
161 return rb_str_new2 (s);
164 static VALUE c_text_set (VALUE self, VALUE text)
166 GET_OBJ (GET_EDJE (self), Evas_Object *, e);
168 Check_Type (text, T_STRING);
170 edje_object_part_text_set (*e, GET_NAME (self),
171 StringValuePtr (text));
176 static VALUE c_get_drag_value (VALUE self)
178 double dx = 0, dy = 0;
180 GET_OBJ (GET_EDJE (self), Evas_Object *, e);
182 edje_object_part_drag_value_get (*e, GET_NAME (self), &dx, &dy);
184 return rb_ary_new3 (2, rb_float_new (dx), rb_float_new (dy));
187 static VALUE c_set_drag_value (VALUE self, VALUE dx, VALUE dy)
189 GET_OBJ (GET_EDJE (self), Evas_Object *, e);
192 Check_Type (dx, T_FLOAT);
195 Check_Type (dy, T_FLOAT);
197 edje_object_part_drag_value_set (*e, GET_NAME (self),
198 NUM2DBL (dx), NUM2DBL (dy));
203 void Init_Part (void)
205 cPart = rb_define_class_under (mEdje, "Part", rb_cObject);
207 rb_define_attr (cPart, "edje", 1, 0);
208 rb_define_attr (cPart, "name", 1, 0);
210 /* not publically instantiable yet */
211 rb_define_private_method (rb_singleton_class (cPart),
213 rb_define_method (cPart, "get_geometry", c_get_geometry, 0);
214 rb_define_method (cPart, "swallow", c_swallow, 1);
215 rb_define_method (cPart, "unswallow", c_unswallow, 1);
216 rb_define_method (cPart, "swallowed_object",
217 c_swallowed_object_get, 0);
218 rb_define_method (cPart, "text", c_text_get, 0);
219 rb_define_method (cPart, "text=", c_text_set, 1);
220 rb_define_method (cPart, "get_drag_value", c_get_drag_value, 2);
221 rb_define_method (cPart, "set_drag_value", c_set_drag_value, 2);