+/*
+ * $Id: rb_window.c 39 2004-07-25 13:13:57Z tilman $
+ *
+ * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <ruby.h>
+
+#include <Ecore.h>
+#include <Ecore_X.h>
+
+#include "rb_ecore_x.h"
+
+static VALUE cWindow, parents;
+
+static void c_mark (Ecore_X_Window *w)
+{
+ VALUE parent;
+
+ parent = rb_hash_aref (parents, INT2NUM ((long) (w)));
+ if (parent != Qnil)
+ rb_gc_mark (parent);
+}
+
+static void c_free (Ecore_X_Window *w)
+{
+ rb_hash_aset (parents, INT2NUM ((long) w), Qnil);
+
+ free (w);
+}
+
+VALUE TO_ECORE_X_WINDOW (VALUE parent, Ecore_X_Window w)
+{
+ VALUE self;
+ Ecore_X_Window *my_w = NULL;
+
+ if (NIL_P (parent) || !w)
+ return Qnil;
+
+ self = Data_Make_Struct (cWindow, Ecore_X_Window,
+ c_mark, c_free, my_w);
+ *my_w = w;
+
+ rb_hash_aset (parents, INT2NUM ((long) my_w), parent);
+
+ rb_obj_call_init (self, 0, NULL);
+
+ return self;
+}
+
+void Init_Window (void)
+{
+ cWindow = rb_define_class_under (mX, "Window", rb_cObject);
+
+ /* not publically instantiable yet */
+ rb_define_private_method (rb_singleton_class (cWindow),
+ "new", NULL, 0);
+
+ parents = rb_hash_new ();
+ rb_global_variable (&parents);
+}