/*
- * $Id: rb_ecore.c 361 2006-02-13 22:37:49Z tilman $
+ * $Id: rb_ecore.c 365 2006-02-14 21:50:47Z tilman $
*
* Copyright (C) 2004 ruby-ecore team (see AUTHORS)
*
return rb_float_new (ecore_time_get ());
}
-static VALUE m_new_event_type (VALUE self, VALUE klass)
-{
- VALUE num;
-
- num = INT2NUM (ecore_event_type_new());
- rb_hash_aset (event_classes, num, klass);
-
- return num;
-}
-
-static void free_ruby_event (void *data, void *event)
-{
- /* do nothing */
-}
-
-static VALUE m_add_event (VALUE self, VALUE type, VALUE event)
-{
- Check_Type (type, T_FIXNUM);
-
- ecore_event_add (FIX2INT (type), (void *) event, free_ruby_event, NULL);
-
- return Qnil;
-}
-
#if 0
static VALUE c_ev_exe_exit_init (VALUE self, VALUE event)
{
rb_define_module_function (mEcore, "main_loop_quit",
m_main_loop_quit, 0);
rb_define_module_function (mEcore, "time", m_time_get, 0);
- rb_define_module_function (mEcore, "new_event_type",
- m_new_event_type, 1);
- rb_define_module_function (mEcore, "add_event", m_add_event, 2);
Init_Timer ();
Init_Animator ();
Init_FdHandler ();
/* SIGNAL_HUP */
- ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_HUP,
+ ADD_EVENT (mEcore, ECORE_EVENT_SIGNAL_HUP,
"SignalHup", c);
- rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
/* SIGNAL_POWER */
- ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_POWER,
+ ADD_EVENT (mEcore, ECORE_EVENT_SIGNAL_POWER,
"SignalPower", c);
- rb_define_private_method (c, "initialize", c_ev_generic_init, 1);
#if 0
/* EXE_EXIT */
- ADD_EVENT (mEcore, ECORE_EVENT_, EXE_EXIT, "ExeExit", c);
+ ADD_EVENT (mEcore, ECORE_EVENT_EXE_EXIT, "ExeExit", c);
rb_define_private_method (c, "initialize", c_ev_exe_exit_init, 1);
#endif
/* SIGNAL_USER */
- ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_USER,
+ ADD_EVENT (mEcore, ECORE_EVENT_SIGNAL_USER,
"SignalUser", c);
rb_define_private_method (c, "initialize", c_ev_sig_user_init, 1);
/* SIGNAL_EXIT */
- ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_EXIT,
+ ADD_EVENT (mEcore, ECORE_EVENT_SIGNAL_EXIT,
"SignalExit", c);
rb_define_private_method (c, "initialize", c_ev_sig_exit_init, 1);
/* SIGNAL_REALTIME */
- ADD_EVENT (mEcore, ECORE_EVENT_, SIGNAL_REALTIME,
+ ADD_EVENT (mEcore, ECORE_EVENT_SIGNAL_REALTIME,
"SignalRealtime", c);
rb_define_private_method (c, "initialize", c_ev_sig_rt_init, 1);
}
/*
- * $Id: rb_event_handler.c 364 2006-02-14 19:06:43Z tilman $
+ * $Id: rb_event_handler.c 365 2006-02-14 21:50:47Z tilman $
*
* Copyright (C) 2004 ruby-ecore team (see AUTHORS)
*
typedef struct {
Ecore_Event_Handler *real;
+ int type;
VALUE callback;
bool deleted;
} RbEventHandler;
static int on_ecore_event (void *data, int type, void *event);
+static VALUE c_ev_raise (VALUE klass, VALUE event);
VALUE event_classes, cEcoreEvent;
static VALUE handlers;
Data_Get_Struct (self, RbEventHandler, h);
- t = NUM2INT (type);
+ if (rb_obj_is_kind_of (type, rb_cModule) != Qtrue)
+ rb_raise (rb_eArgError, "invalid argument");
+ t = NUM2INT (rb_const_get (type, rb_intern ("TYPE")));
if (t <= ECORE_EVENT_NONE)
rb_raise (rb_eStandardError, "invalid type");
- rb_iv_set (self, "@type", type);
-
+ h->type = t;
h->callback = rb_block_proc ();
h->deleted = false;
h->real = ecore_event_handler_add (t, on_ecore_event, NULL);
{
RbEventHandler *h = NULL;
VALUE handler, klass, obj, tmp, res;
- int handler_type, len, ret = 1, i;
+ int len, ret = 1, i;
/* instantiate the event object
* first, find the class we're gonna use
for (i = 0; i < len; i++) {
handler = rb_ary_entry (handlers, i);
- handler_type = NUM2INT (rb_iv_get (handler, "@type"));
+ Data_Get_Struct (handler, RbEventHandler, h);
- if (handler_type == type) {
- Data_Get_Struct (handler, RbEventHandler, h);
+ if (h->type == type) {
res = rb_funcall (h->callback, rb_intern ("call"), 1, obj);
/* if the block returned false, don't call the other
return ret;
}
-VALUE c_ev_generic_init (VALUE self, VALUE event)
+VALUE c_ev_inherited (VALUE klass, VALUE child)
{
- /* dummy */
- return self;
+ VALUE t;
+
+ t = INT2FIX (ecore_event_type_new ());
+ rb_hash_aset (event_classes, t, child);
+
+ rb_define_const (child, "TYPE", t);
+ rb_define_singleton_method (child, "raise", c_ev_raise, 1);
+
+ return Qnil;
+}
+
+VALUE c_ev_inherited_noop (VALUE klass, VALUE child)
+{
+ return Qnil;
+}
+
+static void free_ruby_event (void *data, void *event)
+{
+ /* do nothing */
+}
+
+static VALUE c_ev_raise (VALUE klass, VALUE event)
+{
+ VALUE t;
+
+ t = rb_const_get (klass, rb_intern ("TYPE"));
+ ecore_event_add (FIX2INT (t), (void *) event, free_ruby_event, NULL);
+
+ return Qnil;
}
void Init_EventHandler (void)
/* define a base event class */
cEcoreEvent = rb_define_class_under (mEcore, "Event", rb_cObject);
- rb_define_private_method (rb_singleton_class (cEcoreEvent),
- "new", NULL, 0);
+ rb_define_singleton_method (cEcoreEvent, "inherited", c_ev_inherited, 1);
}
/*
- * $Id: rb_event_handler.h 343 2005-05-07 20:22:56Z tilman $
+ * $Id: rb_event_handler.h 365 2006-02-14 21:50:47Z tilman $
*
* Copyright (C) 2004 ruby-ecore team (see AUTHORS)
*
#ifndef __RB_EVENT_HANDLER_H
#define __RB_EVENT_HANDLER_H
-#define ADD_EVENT(mod, prefix, constname, clsname, obj) \
- rb_define_const ((mod), #constname, \
- INT2FIX (prefix##constname)); \
+#define ADD_EVENT(mod, constname, clsname, obj) \
+ rb_define_singleton_method (cEcoreEvent, "inherited", \
+ c_ev_inherited_noop, 1); \
\
(obj) = rb_define_class_under ((mod), (clsname), cEcoreEvent); \
rb_define_private_method (rb_singleton_class ((obj)), \
"new", NULL, 0); \
\
- rb_hash_aset (event_classes, INT2FIX (prefix##constname), (obj));
+ rb_define_const ((obj), "TYPE", INT2FIX (constname)); \
+ rb_hash_aset (event_classes, INT2FIX (constname), (obj)); \
+ rb_define_singleton_method (cEcoreEvent, "inherited", c_ev_inherited, 1);
void Init_EventHandler (void);
-VALUE c_ev_generic_init (VALUE self, VALUE event);
+VALUE c_ev_inherited (VALUE klass, VALUE child);
+VALUE c_ev_inherited_noop (VALUE klass, VALUE child);
#ifndef __RB_EVENT_HANDLER_C
extern VALUE event_classes, cEcoreEvent;
/*
- * $Id: rb_server.c 362 2006-02-13 22:46:35Z tilman $
+ * $Id: rb_server.c 365 2006-02-14 21:50:47Z tilman $
*
* Copyright (C) 2005 ruby-ecore team (see AUTHORS)
*
rb_define_alias (c, "<<", "write");
rb_define_method (c, "delete", c_delete, 0);
- ADD_EVENT (m, ECORE_CON_EVENT_, SERVER_ADD, "ServerAdd", c);
+ ADD_EVENT (m, ECORE_CON_EVENT_SERVER_ADD, "ServerAdd", c);
rb_define_private_method (c, "initialize",
c_ev_server_add_init, 1);
- ADD_EVENT (m, ECORE_CON_EVENT_, SERVER_DATA, "ServerData", c);
+ ADD_EVENT (m, ECORE_CON_EVENT_SERVER_DATA, "ServerData", c);
rb_define_private_method (c, "initialize",
c_ev_server_data_init, 1);
- ADD_EVENT (m, ECORE_CON_EVENT_, SERVER_DEL, "ServerDel", c);
+ ADD_EVENT (m, ECORE_CON_EVENT_SERVER_DEL, "ServerDel", c);
rb_define_private_method (c, "initialize",
c_ev_server_del_init, 1);
}
/*
- * $Id: rb_ecore_x.c 101 2004-08-27 23:56:26Z tilman $
+ * $Id: rb_ecore_x.c 365 2006-02-14 21:50:47Z tilman $
*
* Copyright (C) 2004 ruby-ecore team (see AUTHORS)
*
DEF_CONST (c, ECORE_X_MODIFIER_, WIN);
/* events */
- ADD_EVENT (mX, ECORE_X_EVENT_, KEY_DOWN, "KeyDown", c);
+ ADD_EVENT (mX, ECORE_X_EVENT_KEY_DOWN, "KeyDown", c);
rb_define_private_method (c, "initialize",
c_ev_key_down_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, KEY_UP, "KeyUp", c);
+ ADD_EVENT (mX, ECORE_X_EVENT_KEY_UP, "KeyUp", c);
rb_define_private_method (c, "initialize",
c_ev_key_down_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_BUTTON_DOWN,
+ ADD_EVENT (mX, ECORE_X_EVENT_MOUSE_BUTTON_DOWN,
"MouseButtonDown", c);
rb_define_private_method (c, "initialize",
c_ev_mouse_button_down_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_BUTTON_UP,
+ ADD_EVENT (mX, ECORE_X_EVENT_MOUSE_BUTTON_UP,
"MouseButtonUp", c);
rb_define_private_method (c, "initialize",
c_ev_mouse_button_up_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_MOVE, "MouseMove", c);
+ ADD_EVENT (mX, ECORE_X_EVENT_MOUSE_MOVE, "MouseMove", c);
rb_define_private_method (c, "initialize",
c_ev_mouse_move_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_IN, "MouseIn", c);
+ ADD_EVENT (mX, ECORE_X_EVENT_MOUSE_IN, "MouseIn", c);
rb_define_private_method (c, "initialize",
c_ev_mouse_in_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, MOUSE_OUT, "MouseOut", c);
+ ADD_EVENT (mX, ECORE_X_EVENT_MOUSE_OUT, "MouseOut", c);
rb_define_private_method (c, "initialize",
c_ev_mouse_in_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_IN,
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_FOCUS_IN,
"WindowFocusIn", c);
rb_define_private_method (c, "initialize",
c_ev_win_focus_change_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_FOCUS_OUT,
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_FOCUS_OUT,
"WindowFocusOut", c);
rb_define_private_method (c, "initialize",
c_ev_win_focus_change_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DELETE_REQUEST,
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_DELETE_REQUEST,
"WindowDeleteRequest", c);
rb_define_private_method (c, "initialize",
c_ev_win_delete_request_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE_REQUEST,
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_CONFIGURE_REQUEST,
"WindowConfigureRequest", c);
rb_define_private_method (c, "initialize",
c_ev_win_configure_request_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CONFIGURE,
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_CONFIGURE,
"WindowConfigure", c);
rb_define_private_method (c, "initialize",
c_ev_win_configure_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_RESIZE_REQUEST,
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_RESIZE_REQUEST,
"WindowResizeRequest", c);
rb_define_private_method (c, "initialize",
c_ev_win_resize_request_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DAMAGE, "WindowDamage", c);
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_DAMAGE, "WindowDamage", c);
rb_define_private_method (c, "initialize",
c_ev_win_damage_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_VISIBILITY_CHANGE,
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_VISIBILITY_CHANGE,
"WindowVisibilityChange", c);
rb_define_private_method (c, "initialize",
c_ev_win_visibility_change_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_CREATE, "WindowCreate", c);
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_CREATE, "WindowCreate", c);
rb_define_private_method (c, "initialize",
c_ev_win_create_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_DESTROY, "WindowDestroy", c);
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_DESTROY, "WindowDestroy", c);
rb_define_private_method (c, "initialize",
c_ev_win_delete_request_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW, "WindowShow", c);
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_SHOW, "WindowShow", c);
rb_define_private_method (c, "initialize",
c_ev_win_delete_request_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_HIDE, "WindowHide", c);
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_HIDE, "WindowHide", c);
rb_define_private_method (c, "initialize",
c_ev_win_delete_request_init, 1);
- ADD_EVENT (mX, ECORE_X_EVENT_, WINDOW_SHOW_REQUEST,
+ ADD_EVENT (mX, ECORE_X_EVENT_WINDOW_SHOW_REQUEST,
"WindowShowRequest", c);
rb_define_private_method (c, "initialize",
c_ev_win_show_request_init, 1);