2 * $Id: rb_esmart_container.c 317 2005-04-25 21:48:10Z 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
23 #include <Esmart/Esmart_Container.h>
24 #include <evas/rb_evas.h>
25 #include <evas/rb_evas_object.h>
27 #include "../rb_esmart.h"
34 static void c_mark (RbContainer *e)
36 c_evas_object_mark (&e->real);
38 rb_gc_mark (e->elements);
41 static void c_free (RbContainer *e)
43 c_evas_object_free (&e->real, false);
48 static VALUE c_new (VALUE klass, VALUE evas)
53 CHECK_CLASS (evas, cEvas);
54 GET_OBJ (evas, RbEvas, e);
56 self = Data_Make_Struct (klass, RbContainer, c_mark,
58 cont->real.real = esmart_container_new (e->real);
61 rb_obj_call_init (self, 1, argv);
63 cont->elements = rb_ary_new ();
68 static VALUE c_append_element (VALUE self, VALUE element)
70 GET_OBJ (self, RbContainer, e);
72 CHECK_CLASS (element, cEvasObject);
73 GET_OBJ (element, RbEvasObject, o);
75 esmart_container_element_append (e->real.real, o->real);
76 rb_ary_push (e->elements, element);
81 static VALUE c_prepend_element (VALUE self, VALUE element)
83 GET_OBJ (self, RbContainer, e);
85 CHECK_CLASS (element, cEvasObject);
86 GET_OBJ (element, RbEvasObject, o);
88 esmart_container_element_prepend (e->real.real, o->real);
89 rb_ary_unshift (e->elements, element);
94 static VALUE c_remove_element (VALUE self, VALUE element)
96 GET_OBJ (self, RbContainer, e);
98 CHECK_CLASS (element, cEvasObject);
99 GET_OBJ (element, RbEvasObject, o);
101 esmart_container_element_remove (e->real.real, o->real);
102 rb_ary_delete (e->elements, element);
107 static VALUE c_elements_get (VALUE self)
111 GET_OBJ (self, RbContainer, e);
113 ary = rb_ary_dup (e->elements);
119 static VALUE c_elements_length_get (VALUE self)
123 GET_OBJ (self, RbContainer, e);
125 l = esmart_container_elements_length_get (e->real.real);
127 return rb_float_new (l);
130 static VALUE c_elements_orig_length_get (VALUE self)
134 GET_OBJ (self, RbContainer, e);
136 l = esmart_container_elements_orig_length_get (e->real.real);
138 return rb_float_new (l);
141 static VALUE c_direction_get (VALUE self)
143 GET_OBJ (self, RbContainer, e);
145 return INT2FIX (esmart_container_direction_get (e->real.real));
148 static VALUE c_direction_set (VALUE self, VALUE val)
150 GET_OBJ (self, RbContainer, e);
152 Check_Type (val, T_FIXNUM);
154 esmart_container_direction_set (e->real.real, FIX2INT (val));
159 static VALUE c_spacing_get (VALUE self)
161 GET_OBJ (self, RbContainer, e);
163 return INT2FIX (esmart_container_spacing_get (e->real.real));
166 static VALUE c_spacing_set (VALUE self, VALUE val)
168 GET_OBJ (self, RbContainer, e);
170 Check_Type (val, T_FIXNUM);
172 esmart_container_spacing_set (e->real.real, FIX2INT (val));
177 static VALUE c_fill_policy_get (VALUE self)
179 GET_OBJ (self, RbContainer, e);
181 return INT2FIX (esmart_container_fill_policy_get (e->real.real));
184 static VALUE c_fill_policy_set (VALUE self, VALUE val)
186 GET_OBJ (self, RbContainer, e);
188 Check_Type (val, T_FIXNUM);
190 esmart_container_fill_policy_set (e->real.real, FIX2INT (val));
195 static VALUE c_alignment_get (VALUE self)
197 GET_OBJ (self, RbContainer, e);
199 return INT2FIX (esmart_container_alignment_get (e->real.real));
202 static VALUE c_alignment_set (VALUE self, VALUE val)
204 GET_OBJ (self, RbContainer, e);
206 Check_Type (val, T_FIXNUM);
208 esmart_container_alignment_set (e->real.real, FIX2INT (val));
214 static VALUE c_get_padding (VALUE self)
216 double l = 0, r = 0, t = 0, b = 0;
218 GET_OBJ (self, RbContainer, e);
220 esmart_container_padding_get (e->real.real, &l, &r, &t, &b);
222 return rb_ary_new3 (4, rb_float_new (l), rb_float_new (r),
223 rb_float_new (t), rb_float_new (b));
226 static VALUE c_set_padding (VALUE self, VALUE l, VALUE r,
229 GET_OBJ (self, RbContainer, e);
231 Check_Type (l, T_FLOAT);
232 Check_Type (r, T_FLOAT);
233 Check_Type (t, T_FLOAT);
234 Check_Type (b, T_FLOAT);
236 esmart_container_padding_set (e->real.real, NUM2DBL (l), NUM2DBL (r),
237 NUM2DBL (t), NUM2DBL (b));
242 static VALUE c_scroll (VALUE self, VALUE val)
244 GET_OBJ (self, RbContainer, e);
246 Check_Type (val, T_FIXNUM);
248 esmart_container_scroll (e->real.real, FIX2INT (val));
253 static VALUE c_scroll_percent_get (VALUE self)
257 GET_OBJ (self, RbContainer, e);
259 val = esmart_container_scroll_percent_get (e->real.real);
261 return rb_float_new (val);
264 static VALUE c_scroll_percent_set (VALUE self, VALUE val)
266 GET_OBJ (self, RbContainer, e);
268 Check_Type (val, T_FLOAT);
270 esmart_container_scroll_percent_set (e->real.real, NUM2DBL (val));
275 void Init_esmart_container (void)
279 rb_require ("esmart");
281 c = rb_define_class_under (mEsmart, "Container", cEvasObject);
283 rb_define_singleton_method (c, "new", c_new, 1);
284 rb_define_method (c, "direction", c_direction_get, 0);
285 rb_define_method (c, "direction=", c_direction_set, 1);
286 rb_define_method (c, "spacing", c_spacing_get, 0);
287 rb_define_method (c, "spacing=", c_spacing_set, 1);
288 rb_define_method (c, "fill_policy", c_fill_policy_get, 0);
289 rb_define_method (c, "fill_policy=", c_fill_policy_set, 1);
290 rb_define_method (c, "alignment", c_alignment_get, 0);
291 rb_define_method (c, "alignment=", c_alignment_set, 1);
292 rb_define_method (c, "get_padding", c_get_padding, 0);
293 rb_define_method (c, "set_padding", c_set_padding, 4);
294 rb_define_method (c, "append_element", c_append_element, 1);
295 rb_define_method (c, "prepend_element", c_prepend_element, 1);
296 rb_define_method (c, "remove_element", c_remove_element, 1);
297 rb_define_method (c, "elements", c_elements_get, 0);
298 rb_define_method (c, "elements_length", c_elements_length_get, 0);
299 rb_define_method (c, "elements_orig_length",
300 c_elements_orig_length_get, 0);
301 rb_define_method (c, "scroll", c_scroll, 1);
302 rb_define_method (c, "scroll_percent", c_scroll_percent_get, 0);
303 rb_define_method (c, "scroll_percent=", c_scroll_percent_set, 1);
305 rb_define_const (c, "HORIZONTAL",
306 INT2FIX (CONTAINER_DIRECTION_HORIZONTAL));
307 rb_define_const (c, "VERTICAL",
308 INT2FIX (CONTAINER_DIRECTION_VERTICAL));
310 rb_define_const (c, "NONE",
311 INT2FIX (CONTAINER_FILL_POLICY_NONE));
312 rb_define_const (c, "KEEP_ASPECT",
313 INT2FIX (CONTAINER_FILL_POLICY_KEEP_ASPECT));
314 rb_define_const (c, "FILL_X",
315 INT2FIX (CONTAINER_FILL_POLICY_FILL_X));
316 rb_define_const (c, "FILL_Y",
317 INT2FIX (CONTAINER_FILL_POLICY_FILL_Y));
318 rb_define_const (c, "HOMOGENOUS",
319 INT2FIX (CONTAINER_FILL_POLICY_HOMOGENOUS));
321 rb_define_const (c, "CENTER",
322 INT2FIX (CONTAINER_ALIGN_CENTER));
323 rb_define_const (c, "LEFT",
324 INT2FIX (CONTAINER_ALIGN_LEFT));
325 rb_define_const (c, "RIGHT",
326 INT2FIX (CONTAINER_ALIGN_RIGHT));
327 rb_define_const (c, "BOTTOM",
328 INT2FIX (CONTAINER_ALIGN_BOTTOM));
329 rb_define_const (c, "TOP",
330 INT2FIX (CONTAINER_ALIGN_TOP));