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