Initial commit.
[ruby-ecore.git] / src / ecore_evas / rb_ecore_evas.c
1 /*
2  * $Id$
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, ee) \
30         Ecore_Evas **(ee) = NULL; \
31 \
32         Data_Get_Struct ((obj), Ecore_Evas *, (ee)); \
33 \
34         if (!*(ee)) { \
35                 rb_raise (rb_eException, "EcoreEvas destroyed already"); \
36                 return Qnil; \
37         }
38
39 /* called by the child classes */
40 void c_ecore_evas_free (Ecore_Evas **ee)
41 {
42         if (*ee)
43                 ecore_evas_free (*ee);
44
45         free (ee);
46 }
47
48 #if 0
49 static VALUE c_init (int argc, VALUE argv, VALUE self)
50 {
51         rb_iv_set (self, "@title", rb_str_new2 (""));
52         rb_iv_set (self, "@name", rb_str_new2 (""));
53         rb_iv_set (self, "@class", rb_str_new2 (""));
54         rb_iv_set (self, "@name", rb_str_new2 (""));
55
56         return self;
57 }
58 #endif
59
60 static VALUE c_show (VALUE self)
61 {
62         GET_OBJ (self, ee);
63
64         ecore_evas_show (*ee);
65
66         return Qnil;
67 }
68
69 static VALUE c_hide (VALUE self)
70 {
71         GET_OBJ (self, ee);
72
73         ecore_evas_hide (*ee);
74
75         return Qnil;
76 }
77
78 static VALUE c_is_visible (VALUE self)
79 {
80         GET_OBJ (self, ee);
81
82         return ecore_evas_visibility_get (*ee) ? Qtrue : Qfalse;
83 }
84
85 static VALUE c_evas (VALUE self)
86 {
87         GET_OBJ (self, ee);
88
89         return TO_EVAS (self, ecore_evas_get (*ee));
90 }
91
92 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
93 {
94         GET_OBJ (self, ee);
95
96         Check_Type (w, T_FIXNUM);
97         Check_Type (h, T_FIXNUM);
98
99         ecore_evas_resize (*ee, FIX2INT (w), FIX2INT (h));
100
101         return Qnil;
102 }
103
104 static VALUE c_title_get (VALUE self)
105 {
106         const char *tmp;
107
108         GET_OBJ (self, ee);
109
110         if (!(tmp = ecore_evas_title_get (*ee)))
111                 return Qnil;
112         else
113                 return rb_str_new2 (tmp);
114 }
115
116 static VALUE c_title_set (VALUE self, VALUE val)
117 {
118         GET_OBJ (self, ee);
119
120         Check_Type (val, T_STRING);
121
122         ecore_evas_title_set (*ee, STR2CSTR (val));
123
124         return Qnil;
125 }
126
127 static VALUE c_borderless_get (VALUE self)
128 {
129         GET_OBJ (self, ee);
130
131         return ecore_evas_borderless_get (*ee) ? Qtrue : Qfalse;
132 }
133
134 static VALUE c_borderless_set (VALUE self, VALUE val)
135 {
136         GET_OBJ (self, ee);
137
138         /* make sure we're passed a boolean */
139         if (TYPE (val) != T_TRUE && TYPE (val) != T_FALSE) {
140                 rb_raise (rb_eTypeError,
141                           "wrong argument type %s (expected true or false)",
142                           rb_obj_classname (val));
143                 return Qnil;
144         }
145
146         ecore_evas_borderless_set (*ee, val == Qtrue ? 1 : 0);
147
148         return Qnil;
149 }
150
151 static VALUE c_delete (VALUE self)
152 {
153         GET_OBJ (self, ee);
154
155         /* reap our children */
156         rb_gc_start ();
157
158         ecore_evas_free (*ee);
159         *ee = NULL;
160
161         return Qnil;
162 }
163
164 void Init_EcoreEvas (void)
165 {
166         cEcoreEvas = rb_define_class_under (mEvas, "EcoreEvas", rb_cObject);
167
168         rb_define_private_method (rb_singleton_class (cEcoreEvas),
169                                   "new", NULL, 0);
170         /*rb_define_method (cEcoreEvas, "initialize", c_init, -1);*/
171         rb_define_method (cEcoreEvas, "delete", c_delete, 0);
172         rb_define_method (cEcoreEvas, "show", c_show, 0);
173         rb_define_method (cEcoreEvas, "hide", c_hide, 0);
174         rb_define_method (cEcoreEvas, "visible?", c_is_visible, 0);
175         rb_define_method (cEcoreEvas, "evas", c_evas, 0);
176         rb_define_method (cEcoreEvas, "resize", c_resize, 2);
177         rb_define_method (cEcoreEvas, "title", c_title_get, 0);
178         rb_define_method (cEcoreEvas, "title=", c_title_set, 1);
179         rb_define_method (cEcoreEvas, "borderless", c_borderless_get, 0);
180         rb_define_method (cEcoreEvas, "borderless=", c_borderless_set, 1);
181 }
182