/*
- * $Id: rb_window.c 39 2004-07-25 13:13:57Z tilman $
+ * $Id: rb_window.c 81 2004-08-21 09:43:23Z tilman $
*
- * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
+ * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include <Ecore.h>
#include <Ecore_X.h>
+#define __RB_WINDOW_C
+#include "../ecore/rb_ecore.h"
#include "rb_ecore_x.h"
+#include "rb_window.h"
-static VALUE cWindow, parents;
+VALUE cWindow;
-static void c_mark (Ecore_X_Window *w)
+static void c_mark (RbWindow *w)
{
- VALUE parent;
-
- parent = rb_hash_aref (parents, INT2NUM ((long) (w)));
- if (parent != Qnil)
- rb_gc_mark (parent);
+ if (!NIL_P (w->parent))
+ rb_gc_mark (w->parent);
}
-static void c_free (Ecore_X_Window *w)
+static void c_free (RbWindow *w)
{
- rb_hash_aset (parents, INT2NUM ((long) w), Qnil);
+ if (w->real)
+ ecore_x_window_del (w->real);
free (w);
}
VALUE TO_ECORE_X_WINDOW (VALUE parent, Ecore_X_Window w)
{
VALUE self;
- Ecore_X_Window *my_w = NULL;
+ RbWindow *window = NULL;
+
+ self = Data_Make_Struct (cWindow, RbWindow, c_mark, free, window);
+
+ window->real = w;
+ window->parent = parent;
+
+ rb_obj_call_init (self, 0, NULL);
- if (NIL_P (parent) || !w)
- return Qnil;
+ return self;
+}
- self = Data_Make_Struct (cWindow, Ecore_X_Window,
- c_mark, c_free, my_w);
- *my_w = w;
+static VALUE c_new (int argc, VALUE *argv, VALUE klass)
+{
+ VALUE self, parent, geom[4];
+ RbWindow *window = NULL, *p = NULL;
+ int i, igeom[4] = {0, 0, 0, 0};
+ Ecore_X_Window pwin = 0;
- rb_hash_aset (parents, INT2NUM ((long) my_w), parent);
+ self = Data_Make_Struct (cWindow, RbWindow, c_mark, c_free, window);
+
+ rb_scan_args (argc, argv, "05",
+ &parent, &geom[0], &geom[1], &geom[2], &geom[3]);
+
+ if (!NIL_P (parent)) {
+ CHECK_CLASS (parent, cWindow);
+ Data_Get_Struct (parent, RbWindow, p);
+ pwin = p->real;
+ }
+
+ for (i = 0; i < 4; i++)
+ if (!NIL_P (geom[i])) {
+ Check_Type (geom[i], T_FIXNUM);
+ igeom[i] = FIX2INT (geom[i]);
+ }
+
+ window->real = ecore_x_window_new (pwin, igeom[0], igeom[1],
+ igeom[2], igeom[3]);
+ window->parent = parent;
rb_obj_call_init (self, 0, NULL);
return self;
}
+static VALUE c_equal_value (VALUE self, VALUE other)
+{
+ GET_OBJ (self, RbWindow, w1);
+
+ CHECK_CLASS (other, cWindow);
+ GET_OBJ (other, RbWindow, w2);
+
+ return w1->real == w2->real ? Qtrue : Qfalse;
+}
+
+static VALUE c_show (VALUE self)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ ecore_x_window_show (win->real);
+
+ return Qnil;
+}
+
+static VALUE c_hide (VALUE self)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ ecore_x_window_hide (win->real);
+
+ return Qnil;
+}
+
+static VALUE c_visible_get (VALUE self)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ return ecore_x_window_visible_get (win->real) ? Qtrue : Qfalse;
+}
+
+static VALUE c_delete (VALUE self)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ if (win->real) {
+ ecore_x_window_del (win->real);
+ win->real = 0;
+ }
+
+ return Qnil;
+}
+
+static VALUE c_raise (VALUE self)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ ecore_x_window_raise (win->real);
+
+ return Qnil;
+}
+
+static VALUE c_lower (VALUE self)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ ecore_x_window_lower (win->real);
+
+ return Qnil;
+}
+
+static VALUE c_reparent (VALUE self, VALUE other, VALUE x, VALUE y)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ CHECK_CLASS (other, cWindow);
+ GET_OBJ (other, RbWindow, o);
+
+ Check_Type (x, T_FIXNUM);
+ Check_Type (y, T_FIXNUM);
+
+ ecore_x_window_reparent (win->real, o->real,
+ FIX2INT (x), FIX2INT (y));
+
+ return Qnil;
+}
+
+static VALUE c_move (VALUE self, VALUE x, VALUE y)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ Check_Type (x, T_FIXNUM);
+ Check_Type (y, T_FIXNUM);
+
+ ecore_x_window_move (win->real, FIX2INT (x), FIX2INT (y));
+
+ return Qnil;
+}
+
+static VALUE c_resize (VALUE self, VALUE w, VALUE h)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ Check_Type (w, T_FIXNUM);
+ Check_Type (h, T_FIXNUM);
+
+ ecore_x_window_move (win->real, FIX2INT (w), FIX2INT (h));
+
+ return Qnil;
+}
+
+static VALUE c_size_get (VALUE self)
+{
+ int w = 0, h = 0;
+
+ GET_OBJ (self, RbWindow, win);
+
+ ecore_x_window_size_get (win->real, &w, &h);
+
+ return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
+}
+
+static VALUE c_geometry_get (VALUE self)
+{
+ int x = 0, y = 0, w = 0, h = 0;
+
+ GET_OBJ (self, RbWindow, win);
+
+ ecore_x_window_geometry_get (win->real, &x, &y, &w, &h);
+
+ return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
+ INT2FIX (w), INT2FIX (h));
+}
+
+static VALUE c_border_size_get (VALUE self)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ return INT2FIX (ecore_x_window_border_size_get (win->real));
+}
+
+static VALUE c_depth_get (VALUE self)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ return INT2FIX (ecore_x_window_depth_get (win->real));
+}
+
+static VALUE c_parent_get (VALUE self)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ return TO_ECORE_X_WINDOW (Qnil,
+ ecore_x_window_parent_get (win->real));
+}
+
+static VALUE c_title_get (VALUE self)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ return rb_str_new2 (ecore_x_window_prop_title_get (win->real));
+}
+
+static VALUE c_title_set (VALUE self, VALUE val)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ Check_Type (val, T_STRING);
+
+ ecore_x_window_prop_title_set (win->real, StringValuePtr (val));
+
+ return Qnil;
+}
+
+static VALUE c_set_event_mask (VALUE self, VALUE val)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ Check_Type (val, T_FIXNUM);
+
+ ecore_x_event_mask_set (win->real, FIX2INT (val));
+
+ return Qnil;
+}
+
+static VALUE c_unset_event_mask (VALUE self, VALUE val)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ Check_Type (val, T_FIXNUM);
+
+ ecore_x_event_mask_unset (win->real, FIX2INT (val));
+
+ return Qnil;
+}
+
+static VALUE c_set_protocol (VALUE self, VALUE proto, VALUE on)
+{
+ GET_OBJ (self, RbWindow, win);
+
+ Check_Type (proto, T_FIXNUM);
+ CHECK_BOOL (on);
+
+ ecore_x_window_prop_protocol_set (win->real, FIX2INT (proto),
+ on == Qtrue);
+
+ return Qnil;
+}
+
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);
+ rb_define_singleton_method (cWindow, "new", c_new, -1);
+ rb_define_method (cWindow, "==", c_equal_value, 1);
+ rb_define_method (cWindow, "show", c_show, 0);
+ rb_define_method (cWindow, "hide", c_hide, 0);
+ rb_define_method (cWindow, "visible?", c_visible_get, 0);
+ rb_define_method (cWindow, "delete", c_delete, 0);
+ rb_define_method (cWindow, "raise", c_raise, 0);
+ rb_define_method (cWindow, "lower", c_lower, 0);
+ rb_define_method (cWindow, "reparent", c_reparent, 3);
+ rb_define_method (cWindow, "move", c_move, 2);
+ rb_define_method (cWindow, "resize", c_resize, 2);
+ rb_define_method (cWindow, "size", c_size_get, 0);
+ rb_define_method (cWindow, "geometry", c_geometry_get, 0);
+ rb_define_method (cWindow, "border_size", c_border_size_get, 0);
+ rb_define_method (cWindow, "depth", c_depth_get, 0);
+ rb_define_method (cWindow, "parent", c_parent_get, 0);
+ rb_define_method (cWindow, "title", c_title_get, 0);
+ rb_define_method (cWindow, "title=", c_title_set, 1);
+ rb_define_method (cWindow, "set_event_mask", c_set_event_mask, 1);
+ rb_define_method (cWindow, "unset_event_mask",
+ c_unset_event_mask, 1);
+ rb_define_method (cWindow, "set_protocol", c_set_protocol, 2);
}