We now use real structs to wrap objects.
[ruby-ecore.git] / src / ecore_evas / rb_software_x11.c
1 /*
2  * $Id: rb_software_x11.c 50 2004-08-01 10:18:39Z tilman $
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 #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 window;
35 } RbEcoreEvasSoftwareX11;
36
37 static void c_mark (RbEcoreEvasSoftwareX11 *ee)
38 {
39         c_ecore_evas_mark (&ee->ee);
40
41         if (!NIL_P (ee->window))
42                 rb_gc_mark (ee->window);
43 }
44
45 static void c_free (RbEcoreEvasSoftwareX11 *ee)
46 {
47         c_ecore_evas_free (&ee->ee, false);
48
49         free (ee);
50 }
51
52 static VALUE c_new (int argc, VALUE *argv, VALUE klass)
53 {
54         VALUE self, disp, parent, geom[4];
55         RbEcoreEvasSoftwareX11 *ee = NULL;
56         char *cdisp = NULL;
57         int i, igeom[4] = {0, 0, 0, 0};
58
59         self = Data_Make_Struct (klass, RbEcoreEvasSoftwareX11,
60                                  c_mark, c_free, ee);
61
62         rb_scan_args (argc, argv, "06", &disp, &parent,
63                       &geom[0], &geom[1], &geom[2], &geom[3]);
64
65         if (!NIL_P (disp)) {
66                 Check_Type (disp, T_STRING);
67                 cdisp = StringValuePtr (disp);
68         }
69
70         for (i = 0; i < 4; i++)
71                 if (!NIL_P (geom[i])) {
72                         Check_Type (geom[i], T_FIXNUM);
73                         igeom[i] = FIX2INT (geom[i]);
74                 }
75
76         ecore_init ();
77         ecore_evas_init ();
78
79         ee->ee.real = ecore_evas_software_x11_new (cdisp, 0,
80                                                    igeom[0], igeom[1],
81                                                    igeom[2], igeom[3]);
82         ee->window = Qnil;
83
84         rb_obj_call_init (self, 0, NULL);
85
86         return self;
87 }
88
89 static VALUE c_window_get (VALUE self)
90 {
91         Ecore_X_Window w;
92
93         GET_OBJ (self, RbEcoreEvasSoftwareX11, ee);
94
95         if (NIL_P (ee->window)) {
96                 w = ecore_evas_software_x11_window_get (ee->ee.real);
97                 ee->window = TO_ECORE_X_WINDOW (self, w);
98         }
99
100         return ee->window;
101 }
102
103 void Init_SoftwareX11 (void)
104 {
105         VALUE c;
106
107         rb_require ("ecore_x");
108
109         c = rb_define_class_under (mEvas, "SoftwareX11", cEcoreEvas);
110
111         rb_define_singleton_method (c, "new", c_new, -1);
112         rb_define_method (c, "window", c_window_get, 0);
113 }