/*
- * $Id: rb_evas_object_events.c 315 2005-04-07 18:27:26Z tilman $
+ * $Id: rb_evas_object_events.c 370 2006-02-15 18:14:53Z tilman $
*
* Copyright (C) 2005 Tilman Sauerbeck (tilman at code-monkey de)
*
static void on_##name (void *data, Evas *evas, \
Evas_Object *evas_obj, void *event) \
{ \
- RbEvasObject *e = (RbEvasObject *) data; \
- VALUE argv[1] = {(VALUE) event}, klass, cb, ev, s; \
+ VALUE tmp = (VALUE) event, klass, cb = (VALUE) data, ev; \
\
- s = rb_str_new2 (#name); \
-\
- cb = rb_hash_aref (e->callbacks, s); \
-\
- klass = rb_hash_aref (event_classes, s); \
+ klass = rb_hash_aref (event_classes, INT2FIX (EVAS_CALLBACK_##name)); \
if (!NIL_P (klass)) { \
- ev = rb_class_new_instance (1, argv, klass); \
+ ev = rb_class_new_instance (1, &tmp, klass); \
rb_funcall (cb, rb_intern ("call"), 1, ev); \
} else \
rb_funcall (cb, rb_intern ("call"), 0); \
}
-#define CALLBACK_HANDLER_METHOD(name, callback) \
+#define CALLBACK_HANDLER_METHOD(callback) \
+ VALUE cb; \
GET_OBJ (self, RbEvasObject, e); \
\
if (!rb_block_given_p ()) \
return Qnil; \
+\
+ cb = rb_block_proc (); \
\
if (NIL_P (e->callbacks)) \
- e->callbacks = rb_hash_new (); \
+ e->callbacks = rb_ary_new (); \
+\
+ rb_ary_push (e->callbacks, cb); \
\
- rb_hash_aset (e->callbacks, rb_str_new2 (#name), \
- rb_block_proc ()); \
evas_object_event_callback_add (e->real, EVAS_CALLBACK_##callback, \
- on_##name, e); \
+ on_##callback, (void *) cb); \
\
return Qnil;
-#define CALLBACK_REGISTER(name, clsname) \
+#define CALLBACK_REGISTER(name, callback, clsname) \
rb_define_method (cEvasObject, "on_"#name, c_on_##name, 0); \
\
c = rb_define_class_under (mEvas, (clsname), cEvent); \
rb_define_private_method (rb_singleton_class (c), "new", NULL, 0); \
rb_define_private_method (c, "initialize", c_ev_##name##_init, 1); \
\
- rb_hash_aset (event_classes, rb_str_new2 (#name), c);
+ rb_hash_aset (event_classes, INT2FIX (EVAS_CALLBACK_##callback), c);
#define CALLBACK_REGISTER2(name) \
rb_define_method (cEvasObject, "on_"#name, c_on_##name, 0);
return self;
}
-CALLBACK_HANDLER_FUNC (mouse_in);
-CALLBACK_HANDLER_FUNC (mouse_out);
-CALLBACK_HANDLER_FUNC (mouse_down);
-CALLBACK_HANDLER_FUNC (mouse_up);
-CALLBACK_HANDLER_FUNC (mouse_move);
-CALLBACK_HANDLER_FUNC (mouse_wheel);
-CALLBACK_HANDLER_FUNC (key_down);
-CALLBACK_HANDLER_FUNC (key_up);
-CALLBACK_HANDLER_FUNC (focus_in);
-CALLBACK_HANDLER_FUNC (focus_out);
-CALLBACK_HANDLER_FUNC (show);
-CALLBACK_HANDLER_FUNC (hide);
-CALLBACK_HANDLER_FUNC (move);
-CALLBACK_HANDLER_FUNC (resize);
-CALLBACK_HANDLER_FUNC (restack);
+CALLBACK_HANDLER_FUNC (MOUSE_IN);
+CALLBACK_HANDLER_FUNC (MOUSE_OUT);
+CALLBACK_HANDLER_FUNC (MOUSE_DOWN);
+CALLBACK_HANDLER_FUNC (MOUSE_UP);
+CALLBACK_HANDLER_FUNC (MOUSE_MOVE);
+CALLBACK_HANDLER_FUNC (MOUSE_WHEEL);
+CALLBACK_HANDLER_FUNC (KEY_DOWN);
+CALLBACK_HANDLER_FUNC (KEY_UP);
+CALLBACK_HANDLER_FUNC (FOCUS_IN);
+CALLBACK_HANDLER_FUNC (FOCUS_OUT);
+CALLBACK_HANDLER_FUNC (SHOW);
+CALLBACK_HANDLER_FUNC (HIDE);
+CALLBACK_HANDLER_FUNC (MOVE);
+CALLBACK_HANDLER_FUNC (RESIZE);
+CALLBACK_HANDLER_FUNC (RESTACK);
static VALUE c_on_mouse_in (VALUE self)
{
- CALLBACK_HANDLER_METHOD (mouse_in, MOUSE_IN);
+ CALLBACK_HANDLER_METHOD (MOUSE_IN);
}
static VALUE c_on_mouse_out (VALUE self)
{
- CALLBACK_HANDLER_METHOD (mouse_out, MOUSE_OUT);
+ CALLBACK_HANDLER_METHOD (MOUSE_OUT);
}
static VALUE c_on_mouse_down (VALUE self)
{
- CALLBACK_HANDLER_METHOD (mouse_down, MOUSE_DOWN);
+ CALLBACK_HANDLER_METHOD (MOUSE_DOWN);
}
static VALUE c_on_mouse_up (VALUE self)
{
- CALLBACK_HANDLER_METHOD (mouse_up, MOUSE_UP);
+ CALLBACK_HANDLER_METHOD (MOUSE_UP);
}
static VALUE c_on_mouse_move (VALUE self)
{
- CALLBACK_HANDLER_METHOD (mouse_move, MOUSE_MOVE);
+ CALLBACK_HANDLER_METHOD (MOUSE_MOVE);
}
static VALUE c_on_mouse_wheel (VALUE self)
{
- CALLBACK_HANDLER_METHOD (mouse_wheel, MOUSE_WHEEL);
+ CALLBACK_HANDLER_METHOD (MOUSE_WHEEL);
}
static VALUE c_on_key_down (VALUE self)
{
- CALLBACK_HANDLER_METHOD (key_down, KEY_DOWN);
+ CALLBACK_HANDLER_METHOD (KEY_DOWN);
}
static VALUE c_on_key_up (VALUE self)
{
- CALLBACK_HANDLER_METHOD (key_up, KEY_UP);
+ CALLBACK_HANDLER_METHOD (KEY_UP);
}
static VALUE c_on_focus_in (VALUE self)
{
- CALLBACK_HANDLER_METHOD (focus_in, FOCUS_IN);
+ CALLBACK_HANDLER_METHOD (FOCUS_IN);
}
static VALUE c_on_focus_out (VALUE self)
{
- CALLBACK_HANDLER_METHOD (focus_out, FOCUS_OUT);
+ CALLBACK_HANDLER_METHOD (FOCUS_OUT);
}
static VALUE c_on_show (VALUE self)
{
- CALLBACK_HANDLER_METHOD (show, SHOW);
+ CALLBACK_HANDLER_METHOD (SHOW);
}
static VALUE c_on_hide (VALUE self)
{
- CALLBACK_HANDLER_METHOD (hide, HIDE);
+ CALLBACK_HANDLER_METHOD (HIDE);
}
static VALUE c_on_move (VALUE self)
{
- CALLBACK_HANDLER_METHOD (move, MOVE);
+ CALLBACK_HANDLER_METHOD (MOVE);
}
static VALUE c_on_resize (VALUE self)
{
- CALLBACK_HANDLER_METHOD (resize, RESIZE);
+ CALLBACK_HANDLER_METHOD (RESIZE);
}
static VALUE c_on_restack (VALUE self)
{
- CALLBACK_HANDLER_METHOD (restack, RESTACK);
+ CALLBACK_HANDLER_METHOD (RESTACK);
}
static VALUE c_ev_init (VALUE argc, VALUE argv, VALUE self)
rb_define_attr (cPos, "canvas_x", 1, 0);
rb_define_attr (cPos, "canvas_y", 1, 0);
- CALLBACK_REGISTER (mouse_in, "MouseInEvent");
+ CALLBACK_REGISTER (mouse_in, MOUSE_IN, "MouseInEvent");
rb_define_attr (c, "buttons", 1, 0);
rb_define_attr (c, "position", 1, 0);
- CALLBACK_REGISTER (mouse_out, "MouseOutEvent");
+ CALLBACK_REGISTER (mouse_out, MOUSE_OUT, "MouseOutEvent");
rb_define_attr (c, "buttons", 1, 0);
rb_define_attr (c, "position", 1, 0);
- CALLBACK_REGISTER (mouse_down, "MouseDownEvent");
+ CALLBACK_REGISTER (mouse_down, MOUSE_DOWN, "MouseDownEvent");
rb_define_attr (c, "button", 1, 0);
rb_define_attr (c, "position", 1, 0);
- CALLBACK_REGISTER (mouse_up, "MouseUpEvent");
+ CALLBACK_REGISTER (mouse_up, MOUSE_UP, "MouseUpEvent");
rb_define_attr (c, "button", 1, 0);
rb_define_attr (c, "position", 1, 0);
- CALLBACK_REGISTER (mouse_move, "MouseMoveEvent");
+ CALLBACK_REGISTER (mouse_move, MOUSE_MOVE, "MouseMoveEvent");
rb_define_attr (c, "current", 1, 0);
rb_define_attr (c, "previous", 1, 0);
rb_define_attr (c, "buttons", 1, 0);
- CALLBACK_REGISTER (mouse_wheel, "MouseWheelEvent");
+ CALLBACK_REGISTER (mouse_wheel, MOUSE_WHEEL, "MouseWheelEvent");
rb_define_attr (c, "direction", 1, 0);
rb_define_attr (c, "z", 1, 0);
rb_define_attr (c, "position", 1, 0);
- CALLBACK_REGISTER (key_down, "KeyDownEvent");
+ CALLBACK_REGISTER (key_down, KEY_DOWN, "KeyDownEvent");
rb_define_attr (c, "keyname", 1, 0);
rb_define_attr (c, "key", 1, 0);
rb_define_attr (c, "string", 1, 0);
rb_define_attr (c, "compose", 1, 0);
- CALLBACK_REGISTER (key_up, "KeyUpEvent");
+ CALLBACK_REGISTER (key_up, KEY_UP, "KeyUpEvent");
rb_define_attr (c, "keyname", 1, 0);
rb_define_attr (c, "key", 1, 0);
rb_define_attr (c, "string", 1, 0);