2 * $Id: rb_part.c 51 2004-08-01 10:19:02Z 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_edje_main.h"
30 static inline char *GET_NAME (VALUE o)
36 id = rb_intern ("@name");
38 name = rb_ivar_get (o, id);
40 return StringValuePtr (name);
43 static inline VALUE GET_EDJE (VALUE o)
48 id = rb_intern ("@edje");
50 return rb_ivar_get (o, id);
53 VALUE TO_PART (VALUE edje, VALUE name)
57 CHECK_CLASS (edje, cEdje);
58 Check_Type (name, T_STRING);
60 self = rb_obj_alloc (cPart);
62 rb_iv_set (self, "@edje", edje);
63 rb_iv_set (self, "@name", rb_str_dup (name));
65 rb_obj_call_init (self, 0, NULL);
70 static VALUE c_get_geometry (VALUE self)
72 int x = 0, y = 0, w = 0, h = 0;
74 GET_OBJ (GET_EDJE (self), RbEdje, e);
76 edje_object_part_geometry_get (e->real.real, GET_NAME (self),
82 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
83 INT2FIX (y), INT2FIX (h));
86 static VALUE c_swallow (VALUE self, VALUE target)
88 GET_OBJ (GET_EDJE (self), RbEdje, e);
90 CHECK_CLASS (target, cEvasObject);
91 GET_OBJ (target, RbEvasObject, t);
93 edje_object_part_swallow (e->real.real, GET_NAME (self), t->real);
98 static VALUE c_unswallow (VALUE self)
102 GET_OBJ (GET_EDJE (self), RbEdje, e);
104 o = edje_object_part_swallow_get (e->real.real, GET_NAME (self));
106 rb_raise (rb_eException, "Part didn't swallow an EvasObject");
110 edje_object_part_unswallow (e->real.real, o);
115 static VALUE c_swallowed_object_get (VALUE self)
120 GET_OBJ (GET_EDJE (self), RbEdje, e);
122 o = edje_object_part_swallow_get (e->real.real, GET_NAME (self));
126 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
127 rb_raise (rb_eException, "EvasObject Ruby object key missing");
134 static VALUE c_text_get (VALUE self)
138 GET_OBJ (GET_EDJE (self), RbEdje, e);
140 s = edje_object_part_text_get (e->real.real, GET_NAME (self));
142 return s ? rb_str_new2 (s) : Qnil;
145 static VALUE c_text_set (VALUE self, VALUE text)
147 GET_OBJ (GET_EDJE (self), RbEdje, e);
149 Check_Type (text, T_STRING);
151 edje_object_part_text_set (e->real.real, GET_NAME (self),
152 StringValuePtr (text));
157 static VALUE c_get_drag_value (VALUE self)
159 double dx = 0, dy = 0;
161 GET_OBJ (GET_EDJE (self), RbEdje, e);
163 edje_object_part_drag_value_get (e->real.real, GET_NAME (self), &dx, &dy);
165 return rb_ary_new3 (2, rb_float_new (dx), rb_float_new (dy));
168 static VALUE c_set_drag_value (VALUE self, VALUE dx, VALUE dy)
170 GET_OBJ (GET_EDJE (self), RbEdje, e);
173 Check_Type (dx, T_FLOAT);
176 Check_Type (dy, T_FLOAT);
178 edje_object_part_drag_value_set (e->real.real, GET_NAME (self),
179 NUM2DBL (dx), NUM2DBL (dy));
184 void Init_Part (void)
186 cPart = rb_define_class_under (mEdje, "Part", rb_cObject);
188 rb_define_attr (cPart, "edje", 1, 0);
189 rb_define_attr (cPart, "name", 1, 0);
191 /* not publically instantiable yet */
192 rb_define_private_method (rb_singleton_class (cPart),
194 rb_define_method (cPart, "get_geometry", c_get_geometry, 0);
195 rb_define_method (cPart, "swallow", c_swallow, 1);
196 rb_define_method (cPart, "unswallow", c_unswallow, 1);
197 rb_define_method (cPart, "swallowed_object",
198 c_swallowed_object_get, 0);
199 rb_define_method (cPart, "text", c_text_get, 0);
200 rb_define_method (cPart, "text=", c_text_set, 1);
201 rb_define_method (cPart, "get_drag_value", c_get_drag_value, 2);
202 rb_define_method (cPart, "set_drag_value", c_set_drag_value, 2);