Added wrappers for more functions.
[ruby-ecore.git] / src / ecore_evas / rb_ecore_evas.c
1 /*
2  * $Id: rb_ecore_evas.c 18 2004-06-22 20:32:57Z 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 <Ecore_Evas.h>
24 #include <rb_evas.h>
25
26 #include "rb_ecore_evas_main.h"
27 #include "rb_ecore_evas.h"
28
29 #define GET_OBJ(obj, type, o, desc) \
30         type **(o) = NULL; \
31 \
32         Data_Get_Struct ((obj), type *, (o)); \
33 \
34         if (!*(o)) { \
35                 rb_raise (rb_eException, desc " destroyed already"); \
36                 return Qnil; \
37         }
38
39 #define CHECK_BOOL(val) \
40         if (TYPE ((val)) != T_TRUE && TYPE ((val)) != T_FALSE) { \
41                 rb_raise (rb_eTypeError, \
42                           "wrong argument type %s (expected true or false)", \
43                           rb_obj_classname ((val))); \
44                 return Qnil; \
45         }
46
47 /* called by the child classes */
48 void c_ecore_evas_free (Ecore_Evas **ee)
49 {
50         if (*ee)
51                 ecore_evas_free (*ee);
52
53         free (ee);
54 }
55
56 static VALUE c_inspect (VALUE self)
57 {
58         char buf[128];
59
60         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
61
62         snprintf (buf, sizeof (buf), "#<EcoreEvas:%p ptr=%p>",
63                   (void *) self, *ee);
64
65         return rb_str_new2 (buf);
66 }
67
68 static VALUE c_show (VALUE self)
69 {
70         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
71
72         ecore_evas_show (*ee);
73
74         return Qnil;
75 }
76
77 static VALUE c_hide (VALUE self)
78 {
79         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
80
81         ecore_evas_hide (*ee);
82
83         return Qnil;
84 }
85
86 static VALUE c_visible_get (VALUE self)
87 {
88         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
89
90         return ecore_evas_visibility_get (*ee) ? Qtrue : Qfalse;
91 }
92
93 static VALUE c_evas (VALUE self)
94 {
95         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
96
97         return TO_EVAS (self, ecore_evas_get (*ee));
98 }
99
100 static VALUE c_get_size_min (VALUE self)
101 {
102         int w = 0, h = 0;
103
104         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
105
106         ecore_evas_size_min_get (*ee, &w, &h);
107
108         return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
109 }
110
111 static VALUE c_set_size_min (VALUE self, VALUE w, VALUE h)
112 {
113         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
114
115         Check_Type (w, T_FIXNUM);
116         Check_Type (h, T_FIXNUM);
117
118         ecore_evas_size_min_set (*ee, FIX2INT (w), FIX2INT (h));
119
120         return Qnil;
121 }
122
123 static VALUE c_get_size_max (VALUE self)
124 {
125         int w = 0, h = 0;
126
127         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
128
129         ecore_evas_size_max_get (*ee, &w, &h);
130
131         return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
132 }
133
134 static VALUE c_set_size_max (VALUE self, VALUE w, VALUE h)
135 {
136         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
137
138         Check_Type (w, T_FIXNUM);
139         Check_Type (h, T_FIXNUM);
140
141         ecore_evas_size_max_set (*ee, FIX2INT (w), FIX2INT (h));
142
143         return Qnil;
144 }
145
146 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
147 {
148         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
149
150         Check_Type (w, T_FIXNUM);
151         Check_Type (h, T_FIXNUM);
152
153         ecore_evas_resize (*ee, FIX2INT (w), FIX2INT (h));
154
155         return Qnil;
156 }
157
158 static VALUE c_title_get (VALUE self)
159 {
160         const char *tmp;
161
162         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
163
164         if (!(tmp = ecore_evas_title_get (*ee)))
165                 return Qnil;
166         else
167                 return rb_str_new2 (tmp);
168 }
169
170 static VALUE c_title_set (VALUE self, VALUE val)
171 {
172         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
173
174         Check_Type (val, T_STRING);
175
176         ecore_evas_title_set (*ee, StringValuePtr (val));
177
178         return Qnil;
179 }
180
181 static VALUE c_borderless_get (VALUE self)
182 {
183         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
184
185         return ecore_evas_borderless_get (*ee) ? Qtrue : Qfalse;
186 }
187
188 static VALUE c_borderless_set (VALUE self, VALUE val)
189 {
190         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
191
192         CHECK_BOOL (val);
193
194         ecore_evas_borderless_set (*ee, val == Qtrue ? 1 : 0);
195
196         return Qnil;
197 }
198
199 static VALUE c_delete (VALUE self)
200 {
201         GET_OBJ (self, Ecore_Evas, ee, "EcoreEvas");
202
203         /* reap our children */
204         rb_gc_start ();
205
206         ecore_evas_free (*ee);
207         *ee = NULL;
208
209         return Qnil;
210 }
211
212 void Init_EcoreEvas (void)
213 {
214         cEcoreEvas = rb_define_class_under (mEvas, "EcoreEvas", rb_cObject);
215
216         rb_define_private_method (rb_singleton_class (cEcoreEvas),
217                                   "new", NULL, 0);
218         rb_define_method (cEcoreEvas, "inspect", c_inspect, 0);
219         rb_define_method (cEcoreEvas, "delete", c_delete, 0);
220         rb_define_method (cEcoreEvas, "show", c_show, 0);
221         rb_define_method (cEcoreEvas, "hide", c_hide, 0);
222         rb_define_method (cEcoreEvas, "visible?", c_visible_get, 0);
223         rb_define_method (cEcoreEvas, "evas", c_evas, 0);
224         rb_define_method (cEcoreEvas, "get_size_min", c_get_size_min, 0);
225         rb_define_method (cEcoreEvas, "set_size_min", c_set_size_min, 2);
226         rb_define_method (cEcoreEvas, "get_size_max", c_get_size_max, 0);
227         rb_define_method (cEcoreEvas, "set_size_max", c_set_size_max, 2);
228         rb_define_method (cEcoreEvas, "resize", c_resize, 2);
229         rb_define_method (cEcoreEvas, "title", c_title_get, 0);
230         rb_define_method (cEcoreEvas, "title=", c_title_set, 1);
231         rb_define_method (cEcoreEvas, "borderless", c_borderless_get, 0);
232         rb_define_method (cEcoreEvas, "borderless=", c_borderless_set, 1);
233 }