Removed RCS-style IDs.
[ruby-ecore.git] / src / ecore_x / rb_window.c
1 /*
2  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include <ruby.h>
20
21 #include <Ecore.h>
22 #include <Ecore_X.h>
23
24 #define __RB_WINDOW_C
25 #include "../ecore/rb_ecore.h"
26 #include "rb_ecore_x.h"
27 #include "rb_window.h"
28 #include "rb_cursor.h"
29
30 static VALUE cWindow;
31
32 static void c_mark (RbWindow *w)
33 {
34         if (!NIL_P (w->parent))
35                 rb_gc_mark (w->parent);
36 }
37
38 static void c_free (RbWindow *w)
39 {
40         if (w->real)
41                 ecore_x_window_del (w->real);
42
43         free (w);
44 }
45
46 VALUE TO_ECORE_X_WINDOW (VALUE parent, Ecore_X_Window w)
47 {
48         VALUE self;
49         RbWindow *window = NULL;
50
51         self = Data_Make_Struct (cWindow, RbWindow, c_mark, free, window);
52
53         window->real = w;
54         window->parent = parent;
55
56         rb_obj_call_init (self, 0, NULL);
57
58         return self;
59 }
60
61 static VALUE c_alloc (VALUE klass)
62 {
63         RbWindow *window = NULL;
64
65         return Data_Make_Struct (cWindow, RbWindow, c_mark, c_free, window);
66 }
67
68 static VALUE c_init (int argc, VALUE *argv, VALUE self)
69 {
70         VALUE parent, geom[4];
71         RbWindow *p = NULL;
72         int i, igeom[4] = {0, 0, 0, 0};
73         Ecore_X_Window pwin = 0;
74
75         GET_OBJ (self, RbWindow, win);
76
77         rb_scan_args (argc, argv, "05",
78                       &parent, &geom[0], &geom[1], &geom[2], &geom[3]);
79
80         if (!NIL_P (parent)) {
81                 CHECK_CLASS (parent, cWindow);
82                 Data_Get_Struct (parent, RbWindow, p);
83                 pwin = p->real;
84         }
85
86         for (i = 0; i < 4; i++)
87                 if (!NIL_P (geom[i])) {
88                         Check_Type (geom[i], T_FIXNUM);
89                         igeom[i] = FIX2INT (geom[i]);
90                 }
91
92         win->real = ecore_x_window_new (pwin, igeom[0], igeom[1],
93                                         igeom[2], igeom[3]);
94         win->parent = parent;
95
96         rb_iv_set (self, "@cursor", Qnil);
97
98         return self;
99 }
100
101 static VALUE c_inspect (VALUE self)
102 {
103         char buf[128];
104
105         GET_OBJ (self, RbWindow, win);
106
107         snprintf (buf, sizeof (buf),
108                   "#<%s:%p id=%u>", rb_obj_classname (self),
109                   (void *) self, win->real);
110
111         return rb_str_new2 (buf);
112 }
113
114 static VALUE c_equal_value (VALUE self, VALUE other)
115 {
116         GET_OBJ (self, RbWindow, w1);
117
118         CHECK_CLASS (other, cWindow);
119         GET_OBJ (other, RbWindow, w2);
120
121         return w1->real == w2->real ? Qtrue : Qfalse;
122 }
123
124 static VALUE c_configure (int argc, VALUE *argv, VALUE self)
125 {
126         VALUE mask, geom[4], border, sibling, stackm;
127         RbWindow *sibwin = NULL;
128         int i;
129
130         GET_OBJ (self, RbWindow, win);
131
132         rb_scan_args (argc, argv, "17", &mask,
133                       &geom[0], &geom[1], &geom[2], &geom[3],
134                       &border, &sibling, &stackm);
135
136         Check_Type (mask, T_FIXNUM);
137
138         for (i = 0; i < 4; i++)
139                 if (!NIL_P (geom[i]))
140                         Check_Type (geom[i], T_FIXNUM);
141
142         if (!NIL_P (border))
143                 Check_Type (border, T_FIXNUM);
144
145         if (!NIL_P (sibling)) {
146                 CHECK_CLASS (sibling, cWindow);
147                 Data_Get_Struct (sibling, RbWindow, sibwin);
148         }
149
150         if (!NIL_P (stackm))
151                 Check_Type (stackm, T_FIXNUM);
152
153         ecore_x_window_configure (win->real, FIX2INT (mask),
154                                   NIL_P (geom[0]) ? 0 : FIX2INT (geom[0]),
155                                   NIL_P (geom[1]) ? 0 : FIX2INT (geom[1]),
156                                   NIL_P (geom[2]) ? 0 : FIX2INT (geom[2]),
157                                   NIL_P (geom[3]) ? 0 : FIX2INT (geom[3]),
158                                   NIL_P (border) ? 0 : FIX2INT (border),
159                                   sibwin ? sibwin->real : 0,
160                                   NIL_P (stackm) ? 0 : FIX2INT (stackm));
161
162         return Qnil;
163 }
164
165 static VALUE c_show (VALUE self)
166 {
167         GET_OBJ (self, RbWindow, win);
168
169         ecore_x_window_show (win->real);
170
171         return Qnil;
172 }
173
174 static VALUE c_hide (VALUE self)
175 {
176         GET_OBJ (self, RbWindow, win);
177
178         ecore_x_window_hide (win->real);
179
180         return Qnil;
181 }
182
183 static VALUE c_visible_get (VALUE self)
184 {
185         GET_OBJ (self, RbWindow, win);
186
187         return ecore_x_window_visible_get (win->real) ? Qtrue : Qfalse;
188 }
189
190 static VALUE c_delete (VALUE self)
191 {
192         GET_OBJ (self, RbWindow, win);
193
194         ecore_x_window_del (win->real);
195
196         return Qnil;
197 }
198
199 static VALUE c_send_delete_request (VALUE self)
200 {
201         GET_OBJ (self, RbWindow, win);
202
203         ecore_x_window_delete_request_send (win->real);
204
205         return Qnil;
206 }
207
208 static VALUE c_raise (VALUE self)
209 {
210         GET_OBJ (self, RbWindow, win);
211
212         ecore_x_window_raise (win->real);
213
214         return Qnil;
215 }
216
217 static VALUE c_lower (VALUE self)
218 {
219         GET_OBJ (self, RbWindow, win);
220
221         ecore_x_window_lower (win->real);
222
223         return Qnil;
224 }
225
226 static VALUE c_reparent (VALUE self, VALUE other, VALUE x, VALUE y)
227 {
228         GET_OBJ (self, RbWindow, win);
229
230         CHECK_CLASS (other, cWindow);
231         GET_OBJ (other, RbWindow, o);
232
233         Check_Type (x, T_FIXNUM);
234         Check_Type (y, T_FIXNUM);
235
236         ecore_x_window_reparent (win->real, o->real,
237                                  FIX2INT (x), FIX2INT (y));
238
239         return Qnil;
240 }
241
242 static VALUE c_focus (VALUE self)
243 {
244         GET_OBJ (self, RbWindow, win);
245
246         ecore_x_window_focus (win->real);
247
248         return Qnil;
249 }
250
251 static VALUE c_move (VALUE self, VALUE x, VALUE y)
252 {
253         GET_OBJ (self, RbWindow, win);
254
255         Check_Type (x, T_FIXNUM);
256         Check_Type (y, T_FIXNUM);
257
258         ecore_x_window_move (win->real, FIX2INT (x), FIX2INT (y));
259
260         return Qnil;
261 }
262
263 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
264 {
265         GET_OBJ (self, RbWindow, win);
266
267         Check_Type (w, T_FIXNUM);
268         Check_Type (h, T_FIXNUM);
269
270         ecore_x_window_resize (win->real, FIX2INT (w), FIX2INT (h));
271
272         return Qnil;
273 }
274
275 static VALUE c_size_get (VALUE self)
276 {
277         int w = 0, h = 0;
278
279         GET_OBJ (self, RbWindow, win);
280
281         ecore_x_window_size_get (win->real, &w, &h);
282
283         return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
284 }
285
286 static VALUE c_geometry_get (VALUE self)
287 {
288         int x = 0, y = 0, w = 0, h = 0;
289
290         GET_OBJ (self, RbWindow, win);
291
292         ecore_x_window_geometry_get (win->real, &x, &y, &w, &h);
293
294         return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
295                             INT2FIX (w), INT2FIX (h));
296 }
297
298 static VALUE c_border_width_get (VALUE self)
299 {
300         GET_OBJ (self, RbWindow, win);
301
302         return INT2FIX (ecore_x_window_border_width_get (win->real));
303 }
304
305 static VALUE c_border_width_set (VALUE self, VALUE val)
306 {
307         GET_OBJ (self, RbWindow, win);
308
309         Check_Type (val, T_FIXNUM);
310
311         ecore_x_window_border_width_set (win->real, FIX2INT (val));
312
313         return Qnil;
314 }
315
316 static VALUE c_depth_get (VALUE self)
317 {
318         GET_OBJ (self, RbWindow, win);
319
320         return INT2FIX (ecore_x_window_depth_get (win->real));
321 }
322
323 static VALUE c_parent_get (VALUE self)
324 {
325         GET_OBJ (self, RbWindow, win);
326
327         return TO_ECORE_X_WINDOW (Qnil,
328                                   ecore_x_window_parent_get (win->real));
329 }
330
331 #if 0
332 static VALUE c_title_get (VALUE self)
333 {
334         char *s;
335
336         GET_OBJ (self, RbWindow, win);
337
338         s = ecore_x_window_prop_title_get (win->real);
339
340         return s ? rb_str_new2 (s) : Qnil;
341 }
342
343 static VALUE c_title_set (VALUE self, VALUE val)
344 {
345         GET_OBJ (self, RbWindow, win);
346
347         Check_Type (val, T_STRING);
348
349         ecore_x_window_prop_title_set (win->real, StringValuePtr (val));
350
351         return Qnil;
352 }
353 #endif
354
355 static VALUE c_set_event_mask (VALUE self, VALUE val)
356 {
357         GET_OBJ (self, RbWindow, win);
358
359         Check_Type (val, T_FIXNUM);
360
361         ecore_x_event_mask_set (win->real, FIX2INT (val));
362
363         return Qnil;
364 }
365
366 static VALUE c_unset_event_mask (VALUE self, VALUE val)
367 {
368         GET_OBJ (self, RbWindow, win);
369
370         Check_Type (val, T_FIXNUM);
371
372         ecore_x_event_mask_unset (win->real, FIX2INT (val));
373
374         return Qnil;
375 }
376
377 #if 0
378 static VALUE c_set_protocol (VALUE self, VALUE proto, VALUE on)
379 {
380         GET_OBJ (self, RbWindow, win);
381
382         Check_Type (proto, T_FIXNUM);
383         CHECK_BOOL (on);
384
385         ecore_x_window_prop_protocol_set (win->real, FIX2INT (proto),
386                                           on == Qtrue);
387
388         return Qnil;
389 }
390 #endif
391
392 static VALUE c_get_protocol (VALUE self, VALUE proto)
393 {
394         int s;
395
396         GET_OBJ (self, RbWindow, win);
397
398         s = ecore_x_window_prop_protocol_isset (win->real, FIX2INT (proto));
399
400         return s ? Qtrue : Qfalse;
401 }
402
403 #if 0
404 static VALUE c_sticky_get (VALUE self)
405 {
406         int s;
407
408         GET_OBJ (self, RbWindow, win);
409
410         s = ecore_x_window_prop_state_isset (win->real,
411                                              ECORE_X_WINDOW_STATE_STICKY);
412
413         return s ? Qtrue : Qfalse;
414 }
415
416 static VALUE c_sticky_set (VALUE self, VALUE val)
417 {
418         GET_OBJ (self, RbWindow, win);
419
420         CHECK_BOOL (val);
421
422         ecore_x_window_prop_sticky_set (win->real, val == Qtrue);
423
424         return Qnil;
425 }
426
427 static VALUE c_borderless_get (VALUE self)
428 {
429         int s;
430
431         GET_OBJ (self, RbWindow, win);
432
433         s = ecore_x_window_prop_borderless_get (win->real);
434
435         return s ? Qtrue : Qfalse;
436 }
437
438 static VALUE c_borderless_set (VALUE self, VALUE val)
439 {
440         GET_OBJ (self, RbWindow, win);
441
442         CHECK_BOOL (val);
443
444         ecore_x_window_prop_borderless_set (win->real, val == Qtrue);
445
446         return Qnil;
447 }
448 #endif
449
450 static VALUE c_cursor_set (VALUE self, VALUE val)
451 {
452         GET_OBJ (self, RbWindow, win);
453
454         CHECK_CLASS (val, cCursor);
455         GET_OBJ (val, RbCursor, c);
456
457         ecore_x_window_cursor_set (win->real, c->real);
458         rb_iv_set (self, "@cursor", val);
459
460         return Qnil;
461 }
462
463 static VALUE c_manage (VALUE self)
464 {
465         GET_OBJ (self, RbWindow, win);
466
467         ecore_x_window_manage (win->real);
468
469         return Qnil;
470 }
471
472 static VALUE c_manage_container (VALUE self)
473 {
474         GET_OBJ (self, RbWindow, win);
475
476         ecore_x_window_container_manage (win->real);
477
478         return Qnil;
479 }
480
481 static VALUE c_manage_client (VALUE self)
482 {
483         GET_OBJ (self, RbWindow, win);
484
485         ecore_x_window_client_manage (win->real);
486
487         return Qnil;
488 }
489
490 static VALUE c_sniff (VALUE self)
491 {
492         GET_OBJ (self, RbWindow, win);
493
494         ecore_x_window_sniff (win->real);
495
496         return Qnil;
497 }
498
499 static VALUE c_sniff_client (VALUE self)
500 {
501         GET_OBJ (self, RbWindow, win);
502
503         ecore_x_window_client_sniff (win->real);
504
505         return Qnil;
506 }
507
508 void Init_Window (void)
509 {
510         cWindow = rb_define_class_under (mX, "Window", rb_cObject);
511
512         rb_define_alloc_func (cWindow, c_alloc);
513         rb_define_method (cWindow, "initialize", c_init, -1);
514         rb_define_method (cWindow, "inspect", c_inspect, 0);
515         rb_define_method (cWindow, "eql?", c_equal_value, 1);
516         rb_define_method (cWindow, "==", c_equal_value, 1);
517         rb_define_method (cWindow, "===", c_equal_value, 1);
518         rb_define_method (cWindow, "configure", c_configure, -1);
519         rb_define_method (cWindow, "show", c_show, 0);
520         rb_define_method (cWindow, "hide", c_hide, 0);
521         rb_define_method (cWindow, "visible?", c_visible_get, 0);
522         rb_define_method (cWindow, "delete", c_delete, 0);
523         rb_define_method (cWindow, "send_delete_request",
524                           c_send_delete_request, 0);
525         rb_define_method (cWindow, "raise", c_raise, 0);
526         rb_define_method (cWindow, "lower", c_lower, 0);
527         rb_define_method (cWindow, "reparent", c_reparent, 3);
528         rb_define_method (cWindow, "focus", c_focus, 0);
529         rb_define_method (cWindow, "move", c_move, 2);
530         rb_define_method (cWindow, "resize", c_resize, 2);
531         rb_define_method (cWindow, "size", c_size_get, 0);
532         rb_define_method (cWindow, "geometry", c_geometry_get, 0);
533         rb_define_method (cWindow, "border_width", c_border_width_get, 0);
534         rb_define_method (cWindow, "border_width=", c_border_width_set, 1);
535         rb_define_method (cWindow, "depth", c_depth_get, 0);
536         rb_define_method (cWindow, "parent", c_parent_get, 0);
537 #if 0
538         rb_define_method (cWindow, "title", c_title_get, 0);
539         rb_define_method (cWindow, "title=", c_title_set, 1);
540 #endif
541         rb_define_method (cWindow, "set_event_mask", c_set_event_mask, 1);
542         rb_define_method (cWindow, "unset_event_mask",
543                           c_unset_event_mask, 1);
544 #if 0
545         rb_define_method (cWindow, "set_protocol", c_set_protocol, 2);
546 #endif
547         rb_define_method (cWindow, "get_protocol", c_get_protocol, 1);
548 #if 0
549         rb_define_method (cWindow, "sticky?", c_sticky_get, 0);
550         rb_define_method (cWindow, "sticky=", c_sticky_set, 1);
551         rb_define_method (cWindow, "borderless?", c_borderless_get, 0);
552         rb_define_method (cWindow, "borderless=", c_borderless_set, 1);
553 #endif
554         rb_define_method (cWindow, "cursor=", c_cursor_set, 1);
555         rb_define_method (cWindow, "manage", c_manage, 0);
556         rb_define_method (cWindow, "manage_container", c_manage_container, 0);
557         rb_define_method (cWindow, "manage_client", c_manage_client, 0);
558         rb_define_method (cWindow, "sniff", c_sniff, 0);
559         rb_define_method (cWindow, "sniff_client", c_sniff_client, 0);
560
561         rb_define_attr (cWindow, "cursor", 1, 0);
562 }