2 * $Id: rb_esmart_container.c 36 2004-07-25 10:45:47Z 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>
25 #include <rb_evas_object.h>
27 #include "../rb_esmart.h"
29 static VALUE c_new (VALUE klass, VALUE evas)
34 CHECK_CLASS (evas, cEvas);
35 GET_OBJ (evas, Evas *, e);
37 self = Data_Make_Struct (klass, Evas_Object *, c_evas_object_mark,
38 c_evas_object_free, cont);
39 *cont = esmart_container_new (*e);
42 rb_obj_call_init (self, 1, argv);
47 static VALUE c_element_append (VALUE self, VALUE element)
49 GET_OBJ (self, Evas_Object *, e);
51 CHECK_CLASS (element, cEvasObject);
52 GET_OBJ (element, Evas_Object *, o);
54 esmart_container_element_append (*e, *o);
59 static VALUE c_element_prepend (VALUE self, VALUE element)
61 GET_OBJ (self, Evas_Object *, e);
63 CHECK_CLASS (element, cEvasObject);
64 GET_OBJ (element, Evas_Object *, o);
66 esmart_container_element_prepend (*e, *o);
71 static VALUE c_element_remove (VALUE self, VALUE element)
73 GET_OBJ (self, Evas_Object *, e);
75 CHECK_CLASS (element, cEvasObject);
76 GET_OBJ (element, Evas_Object *, o);
78 esmart_container_element_remove (*e, *o);
83 static VALUE c_direction_get (VALUE self)
85 GET_OBJ (self, Evas_Object *, e);
87 return INT2FIX (esmart_container_direction_get (*e));
90 static VALUE c_direction_set (VALUE self, VALUE val)
92 GET_OBJ (self, Evas_Object *, e);
94 Check_Type (val, T_FIXNUM);
96 esmart_container_direction_set (*e, FIX2INT (val));
101 static VALUE c_spacing_get (VALUE self)
103 GET_OBJ (self, Evas_Object *, e);
105 return INT2FIX (esmart_container_spacing_get (*e));
108 static VALUE c_spacing_set (VALUE self, VALUE val)
110 GET_OBJ (self, Evas_Object *, e);
112 Check_Type (val, T_FIXNUM);
114 esmart_container_spacing_set (*e, FIX2INT (val));
119 static VALUE c_fill_policy_get (VALUE self)
121 GET_OBJ (self, Evas_Object *, e);
123 return INT2FIX (esmart_container_fill_policy_get (*e));
126 static VALUE c_fill_policy_set (VALUE self, VALUE val)
128 GET_OBJ (self, Evas_Object *, e);
130 Check_Type (val, T_FIXNUM);
132 esmart_container_fill_policy_set (*e, FIX2INT (val));
137 static VALUE c_get_padding (VALUE self)
139 double l = 0, r = 0, t = 0, b = 0;
141 GET_OBJ (self, Evas_Object *, e);
143 esmart_container_padding_get (*e, &l, &r, &t, &b);
145 return rb_ary_new3 (4, rb_float_new (l), rb_float_new (r),
146 rb_float_new (t), rb_float_new (b));
149 static VALUE c_set_padding (VALUE self, VALUE l, VALUE r,
152 GET_OBJ (self, Evas_Object *, e);
154 Check_Type (l, T_FLOAT);
155 Check_Type (r, T_FLOAT);
156 Check_Type (t, T_FLOAT);
157 Check_Type (b, T_FLOAT);
159 esmart_container_padding_set (*e, NUM2DBL (l), NUM2DBL (r),
160 NUM2DBL (t), NUM2DBL (b));
165 static VALUE c_scroll (VALUE self, VALUE val)
167 GET_OBJ (self, Evas_Object *, e);
169 Check_Type (val, T_FIXNUM);
171 esmart_container_scroll (*e, FIX2INT (val));
176 void Init_esmart_container (void)
180 rb_require ("esmart");
182 c = rb_define_class_under (mEsmart, "Container", cEvasObject);
184 rb_define_singleton_method (c, "new", c_new, 1);
185 rb_define_method (c, "direction", c_direction_get, 0);
186 rb_define_method (c, "direction=", c_direction_set, 1);
187 rb_define_method (c, "spacing", c_spacing_get, 0);
188 rb_define_method (c, "spacing=", c_spacing_set, 1);
189 rb_define_method (c, "fill_policy", c_fill_policy_get, 0);
190 rb_define_method (c, "fill_policy=", c_fill_policy_set, 1);
191 rb_define_method (c, "get_padding", c_get_padding, 0);
192 rb_define_method (c, "set_padding", c_set_padding, 4);
193 rb_define_method (c, "element_append", c_element_append, 1);
194 rb_define_method (c, "element_prepend", c_element_prepend, 1);
195 rb_define_method (c, "element_remove", c_element_remove, 1);
196 rb_define_method (c, "scroll", c_scroll, 1);
198 rb_define_const (c, "HORIZONTAL",
199 INT2FIX (CONTAINER_DIRECTION_HORIZONTAL));
200 rb_define_const (c, "VERTICAL",
201 INT2FIX (CONTAINER_DIRECTION_VERTICAL));
203 rb_define_const (c, "NONE",
204 INT2FIX (CONTAINER_FILL_POLICY_NONE));
205 rb_define_const (c, "KEEP_ASPECT",
206 INT2FIX (CONTAINER_FILL_POLICY_KEEP_ASPECT));
207 rb_define_const (c, "FILL_X",
208 INT2FIX (CONTAINER_FILL_POLICY_FILL_X));
209 rb_define_const (c, "FILL_Y",
210 INT2FIX (CONTAINER_FILL_POLICY_FILL_Y));
211 rb_define_const (c, "HOMOGENOUS",
212 INT2FIX (CONTAINER_FILL_POLICY_HOMOGENOUS));