Macro tweaks.
[ruby-ecore.git] / src / ecore_evas / rb_software_x11.c
1 /*
2  * $Id: rb_software_x11.c 40 2004-07-25 13:14:34Z 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
23 #include <Ecore.h>
24 #include <Ecore_Evas.h>
25
26 #include "../ecore/rb_ecore.h"
27 #include "../ecore_x/rb_window.h"
28 #include "rb_ecore_evas_main.h"
29 #include "rb_ecore_evas.h"
30
31 static VALUE windows;
32
33 static VALUE c_new (int argc, VALUE *argv, VALUE klass)
34 {
35         VALUE self, disp, parent, geom[4];
36         Ecore_Evas **ee = NULL;
37         char *cdisp = NULL;
38         int i, igeom[4] = {0, 0, 0, 0};
39
40         self = Data_Make_Struct (klass, Ecore_Evas *,
41                                  NULL, c_ecore_evas_free, ee);
42
43         rb_scan_args (argc, argv, "06", &disp, &parent,
44                       &geom[0], &geom[1], &geom[2], &geom[3]);
45
46         if (!NIL_P (disp)) {
47                 Check_Type (disp, T_STRING);
48                 cdisp = StringValuePtr (disp);
49         }
50
51         for (i = 0; i < 4; i++)
52                 if (!NIL_P (geom[i])) {
53                         Check_Type (geom[i], T_FIXNUM);
54                         igeom[i] = NUM2INT (geom[i]);
55                 }
56
57         ecore_init ();
58         ecore_evas_init ();
59
60         *ee = ecore_evas_software_x11_new (cdisp, 0,
61                                            igeom[0], igeom[1],
62                                            igeom[2], igeom[3]);
63
64         rb_obj_call_init (self, 0, NULL);
65
66         return self;
67 }
68
69 static VALUE c_window_get (VALUE self)
70 {
71         VALUE o;
72         Ecore_X_Window w;
73
74         GET_OBJ (self, Ecore_Evas *, ee);
75
76         if (NIL_P (o = rb_hash_aref (windows, INT2NUM ((long) (ee))))) {
77                 w = ecore_evas_software_x11_window_get (*ee);
78                 o = TO_ECORE_X_WINDOW (self, w);
79                 rb_hash_aset (windows, INT2NUM ((long) ee), o);
80         }
81
82         return o;
83 }
84
85 void Init_SoftwareX11 (void)
86 {
87         VALUE c;
88
89         rb_require ("ecore_x");
90
91         c = rb_define_class_under (mEvas, "SoftwareX11", cEcoreEvas);
92
93         rb_define_singleton_method (c, "new", c_new, -1);
94         rb_define_method (c, "window", c_window_get, 0);
95
96         windows = rb_hash_new ();
97         rb_global_variable (&windows);
98 }