2 * $Id: rb_window.c 81 2004-08-21 09:43:23Z tilman $
4 * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
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
27 #include "../ecore/rb_ecore.h"
28 #include "rb_ecore_x.h"
29 #include "rb_window.h"
33 static void c_mark (RbWindow *w)
35 if (!NIL_P (w->parent))
36 rb_gc_mark (w->parent);
39 static void c_free (RbWindow *w)
42 ecore_x_window_del (w->real);
47 VALUE TO_ECORE_X_WINDOW (VALUE parent, Ecore_X_Window w)
50 RbWindow *window = NULL;
52 self = Data_Make_Struct (cWindow, RbWindow, c_mark, free, window);
55 window->parent = parent;
57 rb_obj_call_init (self, 0, NULL);
62 static VALUE c_new (int argc, VALUE *argv, VALUE klass)
64 VALUE self, parent, geom[4];
65 RbWindow *window = NULL, *p = NULL;
66 int i, igeom[4] = {0, 0, 0, 0};
67 Ecore_X_Window pwin = 0;
69 self = Data_Make_Struct (cWindow, RbWindow, c_mark, c_free, window);
71 rb_scan_args (argc, argv, "05",
72 &parent, &geom[0], &geom[1], &geom[2], &geom[3]);
74 if (!NIL_P (parent)) {
75 CHECK_CLASS (parent, cWindow);
76 Data_Get_Struct (parent, RbWindow, p);
80 for (i = 0; i < 4; i++)
81 if (!NIL_P (geom[i])) {
82 Check_Type (geom[i], T_FIXNUM);
83 igeom[i] = FIX2INT (geom[i]);
86 window->real = ecore_x_window_new (pwin, igeom[0], igeom[1],
88 window->parent = parent;
90 rb_obj_call_init (self, 0, NULL);
95 static VALUE c_equal_value (VALUE self, VALUE other)
97 GET_OBJ (self, RbWindow, w1);
99 CHECK_CLASS (other, cWindow);
100 GET_OBJ (other, RbWindow, w2);
102 return w1->real == w2->real ? Qtrue : Qfalse;
105 static VALUE c_show (VALUE self)
107 GET_OBJ (self, RbWindow, win);
109 ecore_x_window_show (win->real);
114 static VALUE c_hide (VALUE self)
116 GET_OBJ (self, RbWindow, win);
118 ecore_x_window_hide (win->real);
123 static VALUE c_visible_get (VALUE self)
125 GET_OBJ (self, RbWindow, win);
127 return ecore_x_window_visible_get (win->real) ? Qtrue : Qfalse;
130 static VALUE c_delete (VALUE self)
132 GET_OBJ (self, RbWindow, win);
135 ecore_x_window_del (win->real);
142 static VALUE c_raise (VALUE self)
144 GET_OBJ (self, RbWindow, win);
146 ecore_x_window_raise (win->real);
151 static VALUE c_lower (VALUE self)
153 GET_OBJ (self, RbWindow, win);
155 ecore_x_window_lower (win->real);
160 static VALUE c_reparent (VALUE self, VALUE other, VALUE x, VALUE y)
162 GET_OBJ (self, RbWindow, win);
164 CHECK_CLASS (other, cWindow);
165 GET_OBJ (other, RbWindow, o);
167 Check_Type (x, T_FIXNUM);
168 Check_Type (y, T_FIXNUM);
170 ecore_x_window_reparent (win->real, o->real,
171 FIX2INT (x), FIX2INT (y));
176 static VALUE c_move (VALUE self, VALUE x, VALUE y)
178 GET_OBJ (self, RbWindow, win);
180 Check_Type (x, T_FIXNUM);
181 Check_Type (y, T_FIXNUM);
183 ecore_x_window_move (win->real, FIX2INT (x), FIX2INT (y));
188 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
190 GET_OBJ (self, RbWindow, win);
192 Check_Type (w, T_FIXNUM);
193 Check_Type (h, T_FIXNUM);
195 ecore_x_window_move (win->real, FIX2INT (w), FIX2INT (h));
200 static VALUE c_size_get (VALUE self)
204 GET_OBJ (self, RbWindow, win);
206 ecore_x_window_size_get (win->real, &w, &h);
208 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
211 static VALUE c_geometry_get (VALUE self)
213 int x = 0, y = 0, w = 0, h = 0;
215 GET_OBJ (self, RbWindow, win);
217 ecore_x_window_geometry_get (win->real, &x, &y, &w, &h);
219 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
220 INT2FIX (w), INT2FIX (h));
223 static VALUE c_border_size_get (VALUE self)
225 GET_OBJ (self, RbWindow, win);
227 return INT2FIX (ecore_x_window_border_size_get (win->real));
230 static VALUE c_depth_get (VALUE self)
232 GET_OBJ (self, RbWindow, win);
234 return INT2FIX (ecore_x_window_depth_get (win->real));
237 static VALUE c_parent_get (VALUE self)
239 GET_OBJ (self, RbWindow, win);
241 return TO_ECORE_X_WINDOW (Qnil,
242 ecore_x_window_parent_get (win->real));
245 static VALUE c_title_get (VALUE self)
247 GET_OBJ (self, RbWindow, win);
249 return rb_str_new2 (ecore_x_window_prop_title_get (win->real));
252 static VALUE c_title_set (VALUE self, VALUE val)
254 GET_OBJ (self, RbWindow, win);
256 Check_Type (val, T_STRING);
258 ecore_x_window_prop_title_set (win->real, StringValuePtr (val));
263 static VALUE c_set_event_mask (VALUE self, VALUE val)
265 GET_OBJ (self, RbWindow, win);
267 Check_Type (val, T_FIXNUM);
269 ecore_x_event_mask_set (win->real, FIX2INT (val));
274 static VALUE c_unset_event_mask (VALUE self, VALUE val)
276 GET_OBJ (self, RbWindow, win);
278 Check_Type (val, T_FIXNUM);
280 ecore_x_event_mask_unset (win->real, FIX2INT (val));
285 static VALUE c_set_protocol (VALUE self, VALUE proto, VALUE on)
287 GET_OBJ (self, RbWindow, win);
289 Check_Type (proto, T_FIXNUM);
292 ecore_x_window_prop_protocol_set (win->real, FIX2INT (proto),
298 void Init_Window (void)
300 cWindow = rb_define_class_under (mX, "Window", rb_cObject);
302 rb_define_singleton_method (cWindow, "new", c_new, -1);
303 rb_define_method (cWindow, "==", c_equal_value, 1);
304 rb_define_method (cWindow, "show", c_show, 0);
305 rb_define_method (cWindow, "hide", c_hide, 0);
306 rb_define_method (cWindow, "visible?", c_visible_get, 0);
307 rb_define_method (cWindow, "delete", c_delete, 0);
308 rb_define_method (cWindow, "raise", c_raise, 0);
309 rb_define_method (cWindow, "lower", c_lower, 0);
310 rb_define_method (cWindow, "reparent", c_reparent, 3);
311 rb_define_method (cWindow, "move", c_move, 2);
312 rb_define_method (cWindow, "resize", c_resize, 2);
313 rb_define_method (cWindow, "size", c_size_get, 0);
314 rb_define_method (cWindow, "geometry", c_geometry_get, 0);
315 rb_define_method (cWindow, "border_size", c_border_size_get, 0);
316 rb_define_method (cWindow, "depth", c_depth_get, 0);
317 rb_define_method (cWindow, "parent", c_parent_get, 0);
318 rb_define_method (cWindow, "title", c_title_get, 0);
319 rb_define_method (cWindow, "title=", c_title_set, 1);
320 rb_define_method (cWindow, "set_event_mask", c_set_event_mask, 1);
321 rb_define_method (cWindow, "unset_event_mask",
322 c_unset_event_mask, 1);
323 rb_define_method (cWindow, "set_protocol", c_set_protocol, 2);