2d7e3c0d7b4f666218a8329c669ae22cccfc7b91
[ruby-ecore.git] / src / ecore_x / rb_window.c
1 /*
2  * $Id: rb_window.c 39 2004-07-25 13:13:57Z 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_X.h>
25
26 #include "rb_ecore_x.h"
27
28 static VALUE cWindow, parents;
29
30 static void c_mark (Ecore_X_Window *w)
31 {
32         VALUE parent;
33
34         parent = rb_hash_aref (parents, INT2NUM ((long) (w)));
35         if (parent != Qnil)
36                 rb_gc_mark (parent);
37 }
38
39 static void c_free (Ecore_X_Window *w)
40 {
41         rb_hash_aset (parents, INT2NUM ((long) w), Qnil);
42
43         free (w);
44 }
45
46 VALUE TO_ECORE_X_WINDOW (VALUE parent, Ecore_X_Window w)
47 {
48         VALUE self;
49         Ecore_X_Window *my_w = NULL;
50
51         if (NIL_P (parent) || !w)
52                 return Qnil;
53
54         self = Data_Make_Struct (cWindow, Ecore_X_Window,
55                                  c_mark, c_free, my_w);
56         *my_w = w;
57
58         rb_hash_aset (parents, INT2NUM ((long) my_w), parent);
59
60         rb_obj_call_init (self, 0, NULL);
61
62         return self;
63 }
64
65 void Init_Window (void)
66 {
67         cWindow = rb_define_class_under (mX, "Window", rb_cObject);
68
69         /* not publically instantiable yet */
70         rb_define_private_method (rb_singleton_class (cWindow),
71                                   "new", NULL, 0);
72
73         parents = rb_hash_new ();
74         rb_global_variable (&parents);
75 }