Make use of Ecore::X::Window in Ecore::Evas::SoftwareX11.
[ruby-ecore.git] / src / ecore_evas / rb_software_x11.c
1 /*
2  * $Id: rb_software_x11.c 82 2004-08-21 09:45:08Z 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 #include <stdbool.h>
23
24 #include <Ecore.h>
25 #include <Ecore_Evas.h>
26
27 #include "../ecore/rb_ecore.h"
28 #include "../ecore_x/rb_window.h"
29 #include "rb_ecore_evas_main.h"
30 #include "rb_ecore_evas.h"
31
32 typedef struct {
33         RbEcoreEvas ee;
34         VALUE parent_window;
35         VALUE window;
36 } RbEcoreEvasSoftwareX11;
37
38 static void c_mark (RbEcoreEvasSoftwareX11 *ee)
39 {
40         c_ecore_evas_mark (&ee->ee);
41
42         if (!NIL_P (ee->parent_window))
43                 rb_gc_mark (ee->parent_window);
44
45         if (!NIL_P (ee->window))
46                 rb_gc_mark (ee->window);
47 }
48
49 static void c_free (RbEcoreEvasSoftwareX11 *ee)
50 {
51         c_ecore_evas_free (&ee->ee, false);
52
53         free (ee);
54 }
55
56 /*
57  * call-seq:
58  *  Ecore::Evas::SoftwareX11.new([display, parent, x, y, w, h]) => swx11
59  *
60  * Creates an Ecore::Evas::SoftwareX11 object.
61  */
62 static VALUE c_new (int argc, VALUE *argv, VALUE klass)
63 {
64         VALUE self, disp, parent, geom[4];
65         RbEcoreEvasSoftwareX11 *ee = NULL;
66         RbWindow *win = NULL;
67         char *cdisp = NULL;
68         int i, igeom[4] = {0, 0, 0, 0};
69
70         self = Data_Make_Struct (klass, RbEcoreEvasSoftwareX11,
71                                  c_mark, c_free, ee);
72
73         rb_scan_args (argc, argv, "06", &disp, &parent,
74                       &geom[0], &geom[1], &geom[2], &geom[3]);
75
76         if (!NIL_P (disp)) {
77                 Check_Type (disp, T_STRING);
78                 cdisp = StringValuePtr (disp);
79         }
80
81         if (!NIL_P (parent)) {
82                 CHECK_CLASS (parent, cWindow);
83                 Data_Get_Struct (parent, RbWindow, win);
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         ecore_init ();
93         ecore_evas_init ();
94
95         ee->ee.real = ecore_evas_software_x11_new (cdisp,
96                                                    win ? win->real : 0,
97                                                    igeom[0], igeom[1],
98                                                    igeom[2], igeom[3]);
99         ee->parent_window = parent;
100         ee->window = Qnil;
101
102         rb_obj_call_init (self, 0, NULL);
103
104         return self;
105 }
106
107 /*
108  * call-seq:
109  *  swx11.window => window
110  *
111  * Returns the <code>Ecore::X::Window</code> object for <i>swx11</i>.
112  */
113 static VALUE c_window_get (VALUE self)
114 {
115         Ecore_X_Window w;
116
117         GET_OBJ (self, RbEcoreEvasSoftwareX11, ee);
118
119         if (NIL_P (ee->window)) {
120                 w = ecore_evas_software_x11_window_get (ee->ee.real);
121                 ee->window = TO_ECORE_X_WINDOW (self, w);
122         }
123
124         return ee->window;
125 }
126
127 void Init_SoftwareX11 (void)
128 {
129         VALUE c;
130
131         rb_require ("ecore_x");
132
133         c = rb_define_class_under (mEvas, "SoftwareX11", cEcoreEvas);
134
135         rb_define_singleton_method (c, "new", c_new, -1);
136         rb_define_method (c, "window", c_window_get, 0);
137 }