API tweaks.
[ruby-esmart.git] / src / esmart_container / rb_esmart_container.c
1 /*
2  * $Id: rb_esmart_container.c 56 2004-08-10 13:28:01Z tilman $
3  *
4  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <ruby.h>
22
23 #include <Esmart/Esmart_Container.h>
24 #include <evas/rb_evas.h>
25 #include <evas/rb_evas_object.h>
26
27 #include "../rb_esmart.h"
28
29 static void c_free (RbEvasObject *e)
30 {
31         c_evas_object_free (e, true);
32 }
33
34 static VALUE c_new (VALUE klass, VALUE evas)
35 {
36         VALUE self, argv[1];
37         RbEvasObject *cont;
38
39         CHECK_CLASS (evas, cEvas);
40         GET_OBJ (evas, RbEvas, e);
41
42         self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark,
43                                  c_free, cont);
44         cont->real = esmart_container_new (e->real);
45
46         argv[0] = evas;
47         rb_obj_call_init (self, 1, argv);
48
49         return self;
50 }
51
52 static VALUE c_append_element (VALUE self, VALUE element)
53 {
54         GET_OBJ (self, RbEvasObject, e);
55
56         CHECK_CLASS (element, cEvasObject);
57         GET_OBJ (element, Evas_Object *, o);
58
59         esmart_container_element_append (e->real, *o);
60
61         return Qnil;
62 }
63
64 static VALUE c_prepend_element (VALUE self, VALUE element)
65 {
66         GET_OBJ (self, RbEvasObject, e);
67
68         CHECK_CLASS (element, cEvasObject);
69         GET_OBJ (element, Evas_Object *, o);
70
71         esmart_container_element_prepend (e->real, *o);
72
73         return Qnil;
74 }
75
76 static VALUE c_remove_element (VALUE self, VALUE element)
77 {
78         GET_OBJ (self, RbEvasObject, e);
79
80         CHECK_CLASS (element, cEvasObject);
81         GET_OBJ (element, Evas_Object *, o);
82
83         esmart_container_element_remove (e->real, *o);
84
85         return Qnil;
86 }
87
88 static VALUE c_direction_get (VALUE self)
89 {
90         GET_OBJ (self, RbEvasObject, e);
91
92         return INT2FIX (esmart_container_direction_get (e->real));
93 }
94
95 static VALUE c_direction_set (VALUE self, VALUE val)
96 {
97         GET_OBJ (self, RbEvasObject, e);
98
99         Check_Type (val, T_FIXNUM);
100
101         esmart_container_direction_set (e->real, FIX2INT (val));
102
103         return Qnil;
104 }
105
106 static VALUE c_spacing_get (VALUE self)
107 {
108         GET_OBJ (self, RbEvasObject, e);
109
110         return INT2FIX (esmart_container_spacing_get (e->real));
111 }
112
113 static VALUE c_spacing_set (VALUE self, VALUE val)
114 {
115         GET_OBJ (self, RbEvasObject, e);
116
117         Check_Type (val, T_FIXNUM);
118
119         esmart_container_spacing_set (e->real, FIX2INT (val));
120
121         return Qnil;
122 }
123
124 static VALUE c_fill_policy_get (VALUE self)
125 {
126         GET_OBJ (self, RbEvasObject, e);
127
128         return INT2FIX (esmart_container_fill_policy_get (e->real));
129 }
130
131 static VALUE c_fill_policy_set (VALUE self, VALUE val)
132 {
133         GET_OBJ (self, RbEvasObject, e);
134
135         Check_Type (val, T_FIXNUM);
136
137         esmart_container_fill_policy_set (e->real, FIX2INT (val));
138
139         return Qnil;
140 }
141
142 static VALUE c_get_padding (VALUE self)
143 {
144         double l = 0, r = 0, t = 0, b = 0;
145
146         GET_OBJ (self, RbEvasObject, e);
147
148         esmart_container_padding_get (e->real, &l, &r, &t, &b);
149
150         return rb_ary_new3 (4, rb_float_new (l), rb_float_new (r),
151                             rb_float_new (t), rb_float_new (b));
152 }
153
154 static VALUE c_set_padding (VALUE self, VALUE l, VALUE r,
155                             VALUE t, VALUE b)
156 {
157         GET_OBJ (self, RbEvasObject, e);
158
159         Check_Type (l, T_FLOAT);
160         Check_Type (r, T_FLOAT);
161         Check_Type (t, T_FLOAT);
162         Check_Type (b, T_FLOAT);
163
164         esmart_container_padding_set (e->real, NUM2DBL (l), NUM2DBL (r),
165                                       NUM2DBL (t), NUM2DBL (b));
166
167         return Qnil;
168 }
169
170 static VALUE c_scroll (VALUE self, VALUE val)
171 {
172         GET_OBJ (self, RbEvasObject, e);
173
174         Check_Type (val, T_FIXNUM);
175
176         esmart_container_scroll (e->real, FIX2INT (val));
177
178         return Qnil;
179 }
180
181 void Init_esmart_container (void)
182 {
183         VALUE c;
184
185         rb_require ("esmart");
186
187         c = rb_define_class_under (mEsmart, "Container", cEvasObject);
188
189         rb_define_singleton_method (c, "new", c_new, 1);
190         rb_define_method (c, "direction", c_direction_get, 0);
191         rb_define_method (c, "direction=", c_direction_set, 1);
192         rb_define_method (c, "spacing", c_spacing_get, 0);
193         rb_define_method (c, "spacing=", c_spacing_set, 1);
194         rb_define_method (c, "fill_policy", c_fill_policy_get, 0);
195         rb_define_method (c, "fill_policy=", c_fill_policy_set, 1);
196         rb_define_method (c, "get_padding", c_get_padding, 0);
197         rb_define_method (c, "set_padding", c_set_padding, 4);
198         rb_define_method (c, "append_element", c_append_element, 1);
199         rb_define_method (c, "prepend_element", c_prepend_element, 1);
200         rb_define_method (c, "remove_element", c_remove_element, 1);
201         rb_define_method (c, "scroll", c_scroll, 1);
202
203         rb_define_const (c, "HORIZONTAL",
204                          INT2FIX (CONTAINER_DIRECTION_HORIZONTAL));
205         rb_define_const (c, "VERTICAL",
206                          INT2FIX (CONTAINER_DIRECTION_VERTICAL));
207
208         rb_define_const (c, "NONE",
209                          INT2FIX (CONTAINER_FILL_POLICY_NONE));
210         rb_define_const (c, "KEEP_ASPECT",
211                          INT2FIX (CONTAINER_FILL_POLICY_KEEP_ASPECT));
212         rb_define_const (c, "FILL_X",
213                          INT2FIX (CONTAINER_FILL_POLICY_FILL_X));
214         rb_define_const (c, "FILL_Y",
215                          INT2FIX (CONTAINER_FILL_POLICY_FILL_Y));
216         rb_define_const (c, "HOMOGENOUS",
217                          INT2FIX (CONTAINER_FILL_POLICY_HOMOGENOUS));
218 }