/*
- * $Id: rb_ecore_evas.c 30 2004-07-10 14:05:30Z tilman $
+ * $Id: rb_ecore_evas.c 40 2004-07-25 13:14:34Z tilman $
*
* Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
*
#include <Ecore_Evas.h>
#include <rb_evas.h>
+#include "../ecore/rb_ecore.h"
#include "rb_ecore_evas_main.h"
#include "rb_ecore_evas.h"
-#define GET_OBJ(obj, type, o) \
- type **(o) = NULL; \
+#define CALLBACK_ADD_HANDLER(name) \
+ static void on_##name (Ecore_Evas *ee) \
+ { \
+ VALUE self = rb_hash_aref (objects, INT2NUM ((long) ee)); \
+ VALUE hash = rb_hash_aref (callbacks, self); \
\
- Data_Get_Struct ((obj), type *, (o)); \
+ rb_funcall (rb_hash_aref (hash, rb_str_new2 (#name)), \
+ rb_intern ("call"), 0); \
+ } \
\
- if (!*(o)) { \
- rb_raise (rb_eException, \
- "%s destroyed already", \
- rb_obj_classname ((obj))); \
- return Qnil; \
- }
-
-#define CHECK_BOOL(val) \
- if (TYPE ((val)) != T_TRUE && TYPE ((val)) != T_FALSE) { \
- rb_raise (rb_eTypeError, \
- "wrong argument type %s (expected true or false)", \
- rb_obj_classname ((val))); \
- return Qnil; \
- }
-
-#define INSPECT(obj, type) \
- char buf[128]; \
+ static VALUE c_on_##name (VALUE self) \
+ { \
+ VALUE hash; \
+\
+ GET_OBJ (self, Ecore_Evas *, ee); \
+\
+ if (!rb_block_given_p ()) \
+ return Qnil; \
\
- GET_OBJ (obj, type, o); \
+ if (NIL_P ((hash = rb_hash_aref (callbacks, self)))) { \
+ hash = rb_hash_new (); \
\
- snprintf (buf, sizeof (buf), \
- "#<%s:%p ptr=%p>", rb_obj_classname ((obj)), \
- (void *) obj, *o); \
+ rb_global_variable (&hash); \
+ rb_hash_aset (callbacks, self, hash); \
+ } \
\
- return rb_str_new2 (buf);
+ rb_hash_aset (hash, rb_str_new2 (#name), rb_block_proc ()); \
+\
+ ecore_evas_callback_##name##_set (*ee, on_##name); \
+\
+ return Qnil; \
+ }
-static VALUE evases;
+#define CALLBACK_ADD(mod, name) \
+ rb_define_method ((mod), "on_"#name, c_on_##name, 0);
+
+static VALUE evases, callbacks, objects;
/* called by the child classes */
void c_ecore_evas_free (Ecore_Evas **ee)
{
- if (*ee)
+ if (*ee) {
+ rb_hash_aset (objects, INT2NUM ((long) *ee), Qnil);
ecore_evas_free (*ee);
+ }
rb_hash_aset (evases, INT2NUM ((long) ee), Qnil);
free (ee);
}
+static VALUE c_initialize (int argc, VALUE *argv, VALUE self)
+{
+ Ecore_Evas **ee = NULL;
+
+ Data_Get_Struct (self, Ecore_Evas *, ee);
+
+ rb_hash_aset (objects, INT2NUM ((long) *ee), self);
+
+ return Qnil;
+}
+
static VALUE c_inspect (VALUE self)
{
- INSPECT (self, Ecore_Evas);
+ INSPECT (self, Ecore_Evas *);
}
static VALUE c_show (VALUE self)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
ecore_evas_show (*ee);
static VALUE c_hide (VALUE self)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
ecore_evas_hide (*ee);
static VALUE c_visible_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
return ecore_evas_visibility_get (*ee) ? Qtrue : Qfalse;
}
static VALUE c_raise (VALUE self)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
ecore_evas_raise (*ee);
static VALUE c_lower (VALUE self)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
ecore_evas_lower (*ee);
static VALUE c_layer_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
return INT2FIX (ecore_evas_layer_get (*ee));
}
static VALUE c_layer_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
Check_Type (val, T_FIXNUM);
return Qnil;
}
-static VALUE c_evas (VALUE self)
+static VALUE c_evas_get (VALUE self)
{
VALUE evas;
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
if (NIL_P (evas = rb_hash_aref (evases, INT2NUM ((long) (ee))))) {
evas = TO_EVAS (self, ecore_evas_get (*ee));
return evas;
}
+static VALUE c_geometry_get (VALUE self)
+{
+ int x = 0, y = 0, w = 0, h = 0;
+
+ GET_OBJ (self, Ecore_Evas *, ee);
+
+ ecore_evas_geometry_get (*ee, &x, &y, &w, &h);
+
+ return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
+ INT2FIX (w), INT2FIX (h));
+}
+
static VALUE c_get_size_min (VALUE self)
{
int w = 0, h = 0;
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
ecore_evas_size_min_get (*ee, &w, &h);
static VALUE c_set_size_min (VALUE self, VALUE w, VALUE h)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
Check_Type (w, T_FIXNUM);
Check_Type (h, T_FIXNUM);
{
int w = 0, h = 0;
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
ecore_evas_size_max_get (*ee, &w, &h);
static VALUE c_set_size_max (VALUE self, VALUE w, VALUE h)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
Check_Type (w, T_FIXNUM);
Check_Type (h, T_FIXNUM);
static VALUE c_move (VALUE self, VALUE x, VALUE y)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
Check_Type (x, T_FIXNUM);
Check_Type (y, T_FIXNUM);
static VALUE c_resize (VALUE self, VALUE w, VALUE h)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
Check_Type (w, T_FIXNUM);
Check_Type (h, T_FIXNUM);
{
const char *tmp;
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
if (!(tmp = ecore_evas_title_get (*ee)))
return Qnil;
static VALUE c_title_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
Check_Type (val, T_STRING);
static VALUE c_borderless_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
return ecore_evas_borderless_get (*ee) ? Qtrue : Qfalse;
}
static VALUE c_borderless_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
CHECK_BOOL (val);
static VALUE c_shaped_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
return ecore_evas_shaped_get (*ee) ? Qtrue : Qfalse;
}
static VALUE c_shaped_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
CHECK_BOOL (val);
static VALUE c_sticky_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
return ecore_evas_sticky_get (*ee) ? Qtrue : Qfalse;
}
static VALUE c_sticky_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
CHECK_BOOL (val);
static VALUE c_rotation_get (VALUE self)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
return INT2FIX (ecore_evas_rotation_get (*ee));
}
static VALUE c_rotation_set (VALUE self, VALUE val)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
Check_Type (val, T_FIXNUM);
return Qnil;
}
+/* FIXME: this is unsafe! */
static VALUE c_delete (VALUE self)
{
- GET_OBJ (self, Ecore_Evas, ee);
+ GET_OBJ (self, Ecore_Evas *, ee);
/* reap our children */
rb_gc_start ();
ecore_evas_free (*ee);
+ rb_hash_aset (objects, INT2NUM ((long) *ee), Qnil);
*ee = NULL;
return Qnil;
}
+CALLBACK_ADD_HANDLER (resize);
+CALLBACK_ADD_HANDLER (move);
+CALLBACK_ADD_HANDLER (show);
+CALLBACK_ADD_HANDLER (hide);
+CALLBACK_ADD_HANDLER (delete_request);
+CALLBACK_ADD_HANDLER (destroy);
+CALLBACK_ADD_HANDLER (focus_in);
+CALLBACK_ADD_HANDLER (focus_out);
+CALLBACK_ADD_HANDLER (mouse_in);
+CALLBACK_ADD_HANDLER (mouse_out);
+CALLBACK_ADD_HANDLER (pre_render);
+CALLBACK_ADD_HANDLER (post_render);
+
void Init_EcoreEvas (void)
{
cEcoreEvas = rb_define_class_under (mEvas, "EcoreEvas", rb_cObject);
rb_define_private_method (rb_singleton_class (cEcoreEvas),
"new", NULL, 0);
+ rb_define_method (cEcoreEvas, "initialize", c_initialize, -1);
rb_define_method (cEcoreEvas, "inspect", c_inspect, 0);
rb_define_method (cEcoreEvas, "delete", c_delete, 0);
rb_define_method (cEcoreEvas, "show", c_show, 0);
rb_define_method (cEcoreEvas, "lower", c_lower, 0);
rb_define_method (cEcoreEvas, "layer", c_layer_get, 0);
rb_define_method (cEcoreEvas, "layer=", c_layer_set, 1);
- rb_define_method (cEcoreEvas, "evas", c_evas, 0);
+ rb_define_method (cEcoreEvas, "evas", c_evas_get, 0);
+ rb_define_method (cEcoreEvas, "geometry", c_geometry_get, 0);
rb_define_method (cEcoreEvas, "get_size_min", c_get_size_min, 0);
rb_define_method (cEcoreEvas, "set_size_min", c_set_size_min, 2);
rb_define_method (cEcoreEvas, "get_size_max", c_get_size_max, 0);
rb_define_method (cEcoreEvas, "rotation", c_rotation_get, 0);
rb_define_method (cEcoreEvas, "rotation=", c_rotation_set, 1);
+ CALLBACK_ADD (cEcoreEvas, resize);
+ CALLBACK_ADD (cEcoreEvas, move);
+ CALLBACK_ADD (cEcoreEvas, show);
+ CALLBACK_ADD (cEcoreEvas, hide);
+ CALLBACK_ADD (cEcoreEvas, delete_request);
+ CALLBACK_ADD (cEcoreEvas, destroy);
+ CALLBACK_ADD (cEcoreEvas, focus_in);
+ CALLBACK_ADD (cEcoreEvas, focus_out);
+ CALLBACK_ADD (cEcoreEvas, mouse_in);
+ CALLBACK_ADD (cEcoreEvas, mouse_out);
+ CALLBACK_ADD (cEcoreEvas, pre_render);
+ CALLBACK_ADD (cEcoreEvas, post_render);
+
evases = rb_hash_new ();
rb_global_variable (&evases);
+
+ objects = rb_hash_new ();
+ rb_global_variable (&objects);
+
+ callbacks = rb_hash_new ();
+ rb_global_variable (&callbacks);
}