2 * $Id: rb_esmart_container.c 70 2004-08-16 15:43:51Z 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"
29 static void c_free (RbEvasObject *e)
31 c_evas_object_free (e, true);
34 static VALUE c_new (VALUE klass, VALUE evas)
39 CHECK_CLASS (evas, cEvas);
40 GET_OBJ (evas, RbEvas, e);
42 self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark,
44 cont->real = esmart_container_new (e->real);
47 rb_obj_call_init (self, 1, argv);
52 static VALUE c_append_element (VALUE self, VALUE element)
54 GET_OBJ (self, RbEvasObject, e);
56 CHECK_CLASS (element, cEvasObject);
57 GET_OBJ (element, RbEvasObject, o);
59 esmart_container_element_append (e->real, o->real);
64 static VALUE c_prepend_element (VALUE self, VALUE element)
66 GET_OBJ (self, RbEvasObject, e);
68 CHECK_CLASS (element, cEvasObject);
69 GET_OBJ (element, RbEvasObject, o);
71 esmart_container_element_prepend (e->real, o->real);
76 static VALUE c_remove_element (VALUE self, VALUE element)
78 GET_OBJ (self, RbEvasObject, e);
80 CHECK_CLASS (element, cEvasObject);
81 GET_OBJ (element, RbEvasObject, o);
83 esmart_container_element_remove (e->real, o->real);
88 static VALUE c_elements_get (VALUE self)
93 GET_OBJ (self, RbEvasObject, e);
95 list = esmart_container_elements_get (e->real);
98 for (l = list; l; l = l->next)
99 rb_ary_push (ary, TO_EVAS_OBJECT (l->data));
104 static VALUE c_direction_get (VALUE self)
106 GET_OBJ (self, RbEvasObject, e);
108 return INT2FIX (esmart_container_direction_get (e->real));
111 static VALUE c_direction_set (VALUE self, VALUE val)
113 GET_OBJ (self, RbEvasObject, e);
115 Check_Type (val, T_FIXNUM);
117 esmart_container_direction_set (e->real, FIX2INT (val));
122 static VALUE c_spacing_get (VALUE self)
124 GET_OBJ (self, RbEvasObject, e);
126 return INT2FIX (esmart_container_spacing_get (e->real));
129 static VALUE c_spacing_set (VALUE self, VALUE val)
131 GET_OBJ (self, RbEvasObject, e);
133 Check_Type (val, T_FIXNUM);
135 esmart_container_spacing_set (e->real, FIX2INT (val));
140 static VALUE c_fill_policy_get (VALUE self)
142 GET_OBJ (self, RbEvasObject, e);
144 return INT2FIX (esmart_container_fill_policy_get (e->real));
147 static VALUE c_fill_policy_set (VALUE self, VALUE val)
149 GET_OBJ (self, RbEvasObject, e);
151 Check_Type (val, T_FIXNUM);
153 esmart_container_fill_policy_set (e->real, FIX2INT (val));
158 static VALUE c_get_padding (VALUE self)
160 double l = 0, r = 0, t = 0, b = 0;
162 GET_OBJ (self, RbEvasObject, e);
164 esmart_container_padding_get (e->real, &l, &r, &t, &b);
166 return rb_ary_new3 (4, rb_float_new (l), rb_float_new (r),
167 rb_float_new (t), rb_float_new (b));
170 static VALUE c_set_padding (VALUE self, VALUE l, VALUE r,
173 GET_OBJ (self, RbEvasObject, e);
175 Check_Type (l, T_FLOAT);
176 Check_Type (r, T_FLOAT);
177 Check_Type (t, T_FLOAT);
178 Check_Type (b, T_FLOAT);
180 esmart_container_padding_set (e->real, NUM2DBL (l), NUM2DBL (r),
181 NUM2DBL (t), NUM2DBL (b));
186 static VALUE c_scroll (VALUE self, VALUE val)
188 GET_OBJ (self, RbEvasObject, e);
190 Check_Type (val, T_FIXNUM);
192 esmart_container_scroll (e->real, FIX2INT (val));
197 void Init_esmart_container (void)
201 rb_require ("esmart");
203 c = rb_define_class_under (mEsmart, "Container", cEvasObject);
205 rb_define_singleton_method (c, "new", c_new, 1);
206 rb_define_method (c, "direction", c_direction_get, 0);
207 rb_define_method (c, "direction=", c_direction_set, 1);
208 rb_define_method (c, "spacing", c_spacing_get, 0);
209 rb_define_method (c, "spacing=", c_spacing_set, 1);
210 rb_define_method (c, "fill_policy", c_fill_policy_get, 0);
211 rb_define_method (c, "fill_policy=", c_fill_policy_set, 1);
212 rb_define_method (c, "get_padding", c_get_padding, 0);
213 rb_define_method (c, "set_padding", c_set_padding, 4);
214 rb_define_method (c, "append_element", c_append_element, 1);
215 rb_define_method (c, "prepend_element", c_prepend_element, 1);
216 rb_define_method (c, "remove_element", c_remove_element, 1);
217 rb_define_method (c, "elements", c_elements_get, 0);
218 rb_define_method (c, "scroll", c_scroll, 1);
220 rb_define_const (c, "HORIZONTAL",
221 INT2FIX (CONTAINER_DIRECTION_HORIZONTAL));
222 rb_define_const (c, "VERTICAL",
223 INT2FIX (CONTAINER_DIRECTION_VERTICAL));
225 rb_define_const (c, "NONE",
226 INT2FIX (CONTAINER_FILL_POLICY_NONE));
227 rb_define_const (c, "KEEP_ASPECT",
228 INT2FIX (CONTAINER_FILL_POLICY_KEEP_ASPECT));
229 rb_define_const (c, "FILL_X",
230 INT2FIX (CONTAINER_FILL_POLICY_FILL_X));
231 rb_define_const (c, "FILL_Y",
232 INT2FIX (CONTAINER_FILL_POLICY_FILL_Y));
233 rb_define_const (c, "HOMOGENOUS",
234 INT2FIX (CONTAINER_FILL_POLICY_HOMOGENOUS));