/*
- * $Id: rb_evas_object_events.c 302 2005-03-22 17:41:35Z tilman $
+ * $Id: rb_evas_object_events.c 306 2005-03-23 17:29:37Z tilman $
*
* Copyright (C) 2005 Tilman Sauerbeck (tilman at code-monkey de)
*
VALUE argv[1] = {(VALUE) event}, klass, cb, ev, s; \
\
s = rb_str_new2 (#name); \
- klass = rb_hash_aref (event_classes, s); \
- ev = rb_class_new_instance (1, argv, klass); \
+\
cb = rb_hash_aref (e->callbacks, s); \
\
- rb_funcall (cb, rb_intern ("call"), 1, ev); \
+ klass = rb_hash_aref (event_classes, s); \
+ if (!NIL_P (klass)) { \
+ ev = rb_class_new_instance (1, argv, klass); \
+ rb_funcall (cb, rb_intern ("call"), 1, ev); \
+ } else \
+ rb_funcall (cb, rb_intern ("call"), 0); \
}
#define CALLBACK_HANDLER_METHOD(name, callback) \
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);
+#define CALLBACK_REGISTER2(name) \
+ rb_define_method (cEvasObject, "on_"#name, c_on_##name, 0);
+
static VALUE event_classes, cPos;
+static VALUE c_ev_mouse_in_init (VALUE self, VALUE ev)
+{
+ VALUE argv[4];
+ Evas_Event_Mouse_In *e = (Evas_Event_Mouse_In *) ev;
+
+ argv[0] = INT2FIX ((int) e->output.x);
+ argv[1] = INT2FIX ((int) e->output.y);
+ argv[2] = INT2FIX ((int) e->canvas.x);
+ argv[3] = INT2FIX ((int) e->canvas.y);
+
+ rb_iv_set (self, "@position",
+ rb_class_new_instance (4, argv, cPos));
+ rb_iv_set (self, "@buttons", INT2FIX (e->buttons));
+
+ return self;
+}
+
+static VALUE c_ev_mouse_out_init (VALUE self, VALUE ev)
+{
+ VALUE argv[4];
+ Evas_Event_Mouse_Out *e = (Evas_Event_Mouse_Out *) ev;
+
+ argv[0] = INT2FIX ((int) e->output.x);
+ argv[1] = INT2FIX ((int) e->output.y);
+ argv[2] = INT2FIX ((int) e->canvas.x);
+ argv[3] = INT2FIX ((int) e->canvas.y);
+
+ rb_iv_set (self, "@position",
+ rb_class_new_instance (4, argv, cPos));
+ rb_iv_set (self, "@buttons", INT2FIX (e->buttons));
+
+ return self;
+}
+
static VALUE c_ev_mouse_down_init (VALUE self, VALUE ev)
{
VALUE argv[4];
return self;
}
+static VALUE c_ev_mouse_wheel_init (VALUE self, VALUE ev)
+{
+ VALUE argv[4];
+ Evas_Event_Mouse_Wheel *e = (Evas_Event_Mouse_Wheel *) ev;
+
+ argv[0] = INT2FIX ((int) e->output.x);
+ argv[1] = INT2FIX ((int) e->output.y);
+ argv[2] = INT2FIX ((int) e->canvas.x);
+ argv[3] = INT2FIX ((int) e->canvas.y);
+
+ rb_iv_set (self, "@position",
+ rb_class_new_instance (4, argv, cPos));
+ rb_iv_set (self, "@direction", INT2FIX (e->direction));
+ rb_iv_set (self, "@z", INT2FIX (e->z));
+
+ return self;
+}
+
+static VALUE c_ev_key_down_init (VALUE self, VALUE ev)
+{
+ Evas_Event_Key_Down *e = (Evas_Event_Key_Down *) ev;
+
+ rb_iv_set (self, "@keyname", rb_str_new2 (e->keyname));
+ rb_iv_set (self, "@key", rb_str_new2 (e->key));
+ rb_iv_set (self, "@string", rb_str_new2 (e->string));
+ rb_iv_set (self, "@compose", rb_str_new2 (e->compose));
+
+ return self;
+}
+
+static VALUE c_ev_key_up_init (VALUE self, VALUE ev)
+{
+ Evas_Event_Key_Up *e = (Evas_Event_Key_Up *) ev;
+
+ rb_iv_set (self, "@keyname", rb_str_new2 (e->keyname));
+ rb_iv_set (self, "@key", rb_str_new2 (e->key));
+ rb_iv_set (self, "@string", rb_str_new2 (e->string));
+ rb_iv_set (self, "@compose", rb_str_new2 (e->compose));
+
+ 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);
+
+static VALUE c_on_mouse_in (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (mouse_in, MOUSE_IN);
+}
+
+static VALUE c_on_mouse_out (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (mouse_out, MOUSE_OUT);
+}
static VALUE c_on_mouse_down (VALUE self)
{
CALLBACK_HANDLER_METHOD (mouse_move, MOUSE_MOVE);
}
-static VALUE c_ev_init (VALUE self)
+static VALUE c_on_mouse_wheel (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (mouse_wheel, MOUSE_WHEEL);
+}
+
+static VALUE c_on_key_down (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (key_down, KEY_DOWN);
+}
+
+static VALUE c_on_key_up (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (key_up, KEY_UP);
+}
+
+static VALUE c_on_focus_in (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (focus_in, FOCUS_IN);
+}
+
+static VALUE c_on_focus_out (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (focus_out, FOCUS_OUT);
+}
+
+static VALUE c_on_show (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (show, SHOW);
+}
+
+static VALUE c_on_hide (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (hide, HIDE);
+}
+
+static VALUE c_on_move (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (move, MOVE);
+}
+
+static VALUE c_on_resize (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (resize, RESIZE);
+}
+
+static VALUE c_on_restack (VALUE self)
+{
+ CALLBACK_HANDLER_METHOD (restack, RESTACK);
+}
+
+static VALUE c_ev_init (VALUE argc, VALUE argv, VALUE self)
{
return self;
}
cEvent = rb_define_class_under (mEvas, "EvasObjectEvent", rb_cObject);
rb_define_private_method (rb_singleton_class (cEvent), "new", NULL, 0);
- rb_define_private_method (cEvent, "initialize", c_ev_init, 0);
+ rb_define_private_method (cEvent, "initialize", c_ev_init, -1);
cPos = rb_define_class_under (cEvent, "Position", rb_cObject);
rb_define_private_method (rb_singleton_class (cPos), "new", NULL, 0);
rb_define_attr (cPos, "canvas_x", 1, 0);
rb_define_attr (cPos, "canvas_y", 1, 0);
+ CALLBACK_REGISTER (mouse_in, "MouseInEvent");
+ rb_define_attr (c, "buttons", 1, 0);
+ rb_define_attr (c, "position", 1, 0);
+
+ CALLBACK_REGISTER (mouse_out, "MouseOutEvent");
+ rb_define_attr (c, "buttons", 1, 0);
+ rb_define_attr (c, "position", 1, 0);
+
CALLBACK_REGISTER (mouse_down, "MouseDownEvent");
rb_define_attr (c, "button", 1, 0);
+ rb_define_attr (c, "position", 1, 0);
CALLBACK_REGISTER (mouse_up, "MouseUpEvent");
rb_define_attr (c, "button", 1, 0);
+ rb_define_attr (c, "position", 1, 0);
CALLBACK_REGISTER (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");
+ 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");
+ 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");
+ 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_REGISTER2 (focus_in);
+ CALLBACK_REGISTER2 (focus_out);
+ CALLBACK_REGISTER2 (show);
+ CALLBACK_REGISTER2 (hide);
+ CALLBACK_REGISTER2 (move);
+ CALLBACK_REGISTER2 (resize);
+ CALLBACK_REGISTER2 (restack);
}