Reworked on_ecore_event().
[ruby-ecore.git] / src / ecore / rb_event_handler.c
index 12e2739b1740392de2d1a8c81f9a47e93caf7941..a360ef70cac34cb42447fcb5f831adb6930ac68a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_event_handler.c 358 2006-02-12 15:42:28Z tilman $
+ * $Id: rb_event_handler.c 364 2006-02-14 19:06:43Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
@@ -117,7 +117,7 @@ static VALUE c_delete (VALUE self)
                        h->real = NULL;
                        h->deleted = true;
 
-                       return Qnil;
+                       break;
                }
 
                rb_ary_push (handlers, el);
@@ -129,23 +129,20 @@ static VALUE c_delete (VALUE self)
 static int on_ecore_event (void *data, int type, void *event)
 {
        RbEventHandler *h = NULL;
-       VALUE handler, klass, obj, argv[1], res;
-       int handler_type, len, i;
-       bool called = false;
+       VALUE handler, klass, obj, tmp, res;
+       int handler_type, len, ret = 1, i;
 
        /* instantiate the event object
         * first, find the class we're gonna use
         */
-       if (NIL_P (klass = rb_hash_aref (event_classes, INT2NUM (type)))) {
+       klass = rb_hash_aref (event_classes, INT2NUM (type));
+       if (NIL_P (klass))
                rb_raise (rb_eException, "Cannot find event class "
                                         "for event %i\n", type);
-               return 0;
-       }
 
        /* now create and init the object */
-       obj = rb_obj_alloc (klass);
-       argv[0] = (VALUE) event;
-       rb_obj_call_init (obj, 1, argv);
+       tmp = (VALUE) event;
+       obj = rb_class_new_instance (1, &tmp, klass);
 
        len = RARRAY (handlers)->len;
 
@@ -156,21 +153,18 @@ static int on_ecore_event (void *data, int type, void *event)
                if (handler_type == type) {
                        Data_Get_Struct (handler, RbEventHandler, h);
                        res = rb_funcall (h->callback, rb_intern ("call"), 1, obj);
-                       called = true;
 
                        /* if the block returned false, don't call the other
                         * event handlers
                         */
-                       if (res == Qfalse)
+                       if (res == Qfalse) {
+                               ret = 0;
                                break;
+                       }
                }
        }
 
-       if (type == ECORE_EVENT_SIGNAL_EXIT && !called)
-               ecore_main_loop_quit ();
-
-       /* call other event handlers, too */
-       return 1;
+       return ret;
 }
 
 VALUE c_ev_generic_init (VALUE self, VALUE event)