Enlightenment CVS committal

Author  : dj2
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src/lib


Modified Files:
        ewl_callback.c ewl_callback.h ewl_misc.c ewl_widget.c 
        ewl_widget.h 


Log Message:
- add a entry to the end of the callback queue for custom callbacks
- change the widget destroy procedures. Ewl_Widget dosen't have a destroy
  callback now, instead of freeing in the garbage collecter we destroy the
  widget data then free. Makes the system work better when destroying
  widgets.

===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_callback.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -3 -r1.20 -r1.21
--- ewl_callback.c      11 Jul 2006 22:04:33 -0000      1.20
+++ ewl_callback.c      13 Jul 2006 00:20:29 -0000      1.21
@@ -17,6 +17,8 @@
 static int ewl_callback_compare(void *key1, void *key2);
 static Ewl_Callback *ewl_callback_register(Ewl_Callback * cb);
 static void ewl_callback_unregister(Ewl_Callback * cb);
+static Ewl_Callback *ewl_callback_get(Ewl_Widget *w, unsigned int type, 
+                                               unsigned int idx);
 
 static void ewl_callback_rm(Ewl_Widget *w, unsigned int t, 
                                                unsigned int pos);
@@ -98,8 +100,7 @@
 
        found = ecore_hash_get(cb_registration, cb);
        if (!found) {
-               found = NEW(Ewl_Callback, 1);
-               memcpy(found, cb, sizeof(Ewl_Callback));
+               found = cb; 
                found->id = ++callback_id;
                ecore_hash_set(cb_registration, found, found);
        }
@@ -247,6 +248,35 @@
        DRETURN_INT(cb->id, DLEVEL_STABLE);
 }
 
+static Ewl_Callback *
+ewl_callback_get(Ewl_Widget *w, unsigned int t, unsigned int i)
+{
+       Ewl_Callback *cb = NULL;
+       Ewl_Callback_Custom *ccb = NULL;
+       Ewl_Callback_Chain *chain = NULL;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR_RET("w", w, NULL);
+       DCHECK_TYPE_RET("w", w, EWL_WIDGET_TYPE, NULL);
+
+       chain = &(w->callbacks[EWL_CALLBACK_INDEX(t)]);
+
+       if (chain->mask & EWL_CALLBACK_TYPE_DIRECT)
+               cb = EWL_CALLBACK(chain->list);
+
+       else if (chain->list) 
+               cb = chain->list[i];
+
+       if (t >= EWL_CALLBACK_MAX)
+               ccb = EWL_CALLBACK_CUSTOM(cb);
+
+       /* make sure the event id's match (if this is a custom callback */
+       if (ccb && (ccb->event_id != t))
+               cb = NULL;
+
+       DRETURN_PTR(cb, DLEVEL_STABLE);
+}
+
 /**
  * @return Returns a new callback identifier
  * @brief Creates and returns a new callback identifier
@@ -259,6 +289,40 @@
        DRETURN_INT(++callback_type_count, DLEVEL_STABLE);
 }
 
+static int
+ewl_callback_position_insert(Ewl_Widget *w, unsigned int type, 
+                               Ewl_Callback_Function func, 
+                               unsigned int pos, void *user_data)
+{
+       int ret;
+       Ewl_Callback *cb, *found;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+       DCHECK_PARAM_PTR_RET("w", w, 0);
+       DCHECK_PARAM_PTR_RET("func", func, 0);
+       DCHECK_TYPE_RET("w", w, EWL_WIDGET_TYPE, 0);
+
+       if (type < EWL_CALLBACK_MAX)
+       {
+               cb = NEW(Ewl_Callback, 1);
+       }
+       else
+       {
+               cb = NEW(Ewl_Callback_Custom, 1);
+               EWL_CALLBACK_CUSTOM(cb)->event_id = type;
+       }
+
+       cb->func = func;
+       cb->user_data = user_data;
+
+       found = ewl_callback_register(cb);
+       if (cb != found) FREE(cb);
+
+       ret = ewl_callback_insert(w, type, found, pos);
+
+       DRETURN_INT(ret, DLEVEL_STABLE);
+}
+
 /**
  * @param w: the widget to attach the callback
  * @param t: the type of the callback that is being attached
@@ -275,8 +339,6 @@
 ewl_callback_append(Ewl_Widget *w, unsigned int t,
                    Ewl_Callback_Function f, void *user_data)
 {
-       Ewl_Callback cb;
-       Ewl_Callback *found;
        int ret;
 
        DENTER_FUNCTION(DLEVEL_STABLE);
@@ -284,13 +346,8 @@
        DCHECK_PARAM_PTR_RET("f", f, 0);
        DCHECK_TYPE_RET("w", w, EWL_WIDGET_TYPE, 0);
 
-       cb.func = f;
-       cb.user_data = user_data;
-       cb.references = 0;
-       cb.id = 0;
-
-       found = ewl_callback_register(&cb);
-       ret = ewl_callback_insert(w, t, found, EWL_CALLBACK_LEN(w, t));
+       ret = ewl_callback_position_insert(w, t, f, 
+                               EWL_CALLBACK_LEN(w, t), user_data);
 
        DRETURN_INT(ret, DLEVEL_STABLE);
 }
@@ -310,8 +367,6 @@
 ewl_callback_prepend(Ewl_Widget *w, unsigned int t,
                     Ewl_Callback_Function f, void *user_data)
 {
-       Ewl_Callback cb;
-       Ewl_Callback *found;
        int ret;
 
        DENTER_FUNCTION(DLEVEL_STABLE);
@@ -319,14 +374,8 @@
        DCHECK_PARAM_PTR_RET("f", f, 0);
        DCHECK_TYPE_RET("w", w, EWL_WIDGET_TYPE, 0);
 
-       cb.func = f;
-       cb.user_data = user_data;
-       cb.references = 0;
-       cb.id = 0;
-
-       found = ewl_callback_register(&cb);
-       ret = ewl_callback_insert(w, t, found, 0);
-
+       ret = ewl_callback_position_insert(w, t, f, 0, user_data);
+                       
        DRETURN_INT(ret, DLEVEL_STABLE);
 }
 
@@ -348,8 +397,6 @@
                          Ewl_Callback_Function f, void *user_data,
                          Ewl_Callback_Function after, void *after_data)
 {
-       Ewl_Callback cb;
-       Ewl_Callback *found;
        Ewl_Callback *search;
        int ret, pos = 0;
 
@@ -358,26 +405,21 @@
        DCHECK_PARAM_PTR_RET("f", f, 0);
        DCHECK_TYPE_RET("w", w, EWL_WIDGET_TYPE, 0);
 
-       cb.func = f;
-       cb.user_data = user_data;
-       cb.references = 0;
-       cb.id = 0;
-
-       found = ewl_callback_register(&cb);
-
        /*
-        * Step 1 position past the callback we want to insert after.
+        * position past the callback we want to insert after.
         */
        for (pos = 0; pos < EWL_CALLBACK_LEN(w, t); pos++)
        {
-               search = EWL_CALLBACK_GET(w, t, pos);
-               if ((search->func == after) && (search->user_data == 
after_data))
+               search = ewl_callback_get(w, t, pos);
+               if (search && (search->func == after) && 
+                               (search->user_data == after_data))
                {
                        pos ++;
                        break;
                }
        }
-       ret = ewl_callback_insert(w, t, found, pos);
+
+       ret = ewl_callback_position_insert(w, t, f, pos, user_data);
 
        DRETURN_INT(ret, DLEVEL_STABLE);
 }
@@ -416,7 +458,7 @@
 ewl_callback_call_with_event_data(Ewl_Widget *w, unsigned int t,
                                  void *ev_data)
 {
-       Ewl_Callback *cb, *oldcb;
+       Ewl_Callback *cb;
        Ewl_Widget *parent, *top = NULL;
 
        DENTER_FUNCTION(DLEVEL_STABLE);
@@ -464,12 +506,23 @@
        EWL_CALLBACK_POS(w, t) = 0;
        while (EWL_CALLBACK_POS(w, t) < EWL_CALLBACK_LEN(w, t))
        {
-               oldcb = cb = EWL_CALLBACK_GET(w, t, EWL_CALLBACK_POS(w, t));
+               Ewl_Callback *newcb = NULL;
+
+               cb = ewl_callback_get(w, t, EWL_CALLBACK_POS(w, t));
+
+               /* keep going if there is no callback at this spot. This can
+                * happen with hte custom array */
+               if (!cb)
+               {
+                       EWL_CALLBACK_POS(w, t)++;
+                       continue;
+               }
+
                if (cb->func)
                        cb->func(w, ev_data, cb->user_data);
-               cb = EWL_CALLBACK_GET(w, t, EWL_CALLBACK_POS(w, t));
 
-               if (cb == oldcb)
+               newcb = ewl_callback_get(w, t, EWL_CALLBACK_POS(w, t));
+               if (cb == newcb)
                        EWL_CALLBACK_POS(w, t)++;
        }
 
@@ -527,8 +580,8 @@
 
        for (i = 0; i < EWL_CALLBACK_LEN(w, t); i++)
        {
-               cb = EWL_CALLBACK_GET(w, t, i);
-               if (cb->id == cb_id) {
+               cb = ewl_callback_get(w, t, i);
+               if (cb && (cb->id == cb_id)) {
                        ewl_callback_rm(w, t, i);
                        break;
                }
@@ -586,8 +639,8 @@
 
        for (i = 0; i < EWL_CALLBACK_LEN(w, t); i++)
        {
-               cb = EWL_CALLBACK_GET(w, t, i);
-               if (cb->func == f) {
+               cb = ewl_callback_get(w, t, i);
+               if (cb && (cb->func == f)) {
                        ewl_callback_rm(w, t, i);
                        break;
                }
@@ -623,8 +676,8 @@
 
        for (i = 0; i < EWL_CALLBACK_LEN(w, t); i++)
        {
-               cb = EWL_CALLBACK_GET(w, t, i);
-               if ((cb->func == f) && (cb->user_data == d)) {
+               cb = ewl_callback_get(w, t, i);
+               if (cb && (cb->func == f) && (cb->user_data == d)) {
                        ewl_callback_rm(w, t, i);
                        break;
                }
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_callback.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- ewl_callback.h      11 Jul 2006 22:04:33 -0000      1.11
+++ ewl_callback.h      13 Jul 2006 00:20:29 -0000      1.12
@@ -39,6 +39,24 @@
        int             id; /**< id number of this callback */
 };
 
+
+/**
+ * The custom callbacks for extended events
+ */
+typedef struct Ewl_Callback_Custom Ewl_Callback_Custom;
+
+/**
+ * @def EWL_CALLBACK_CUSTOM(cb)
+ * Typecasts a pointer to an Ewl_Callback_Custom pointer.
+ */
+#define EWL_CALLBACK_CUSTOM(cb) ((Ewl_Callback_Custom *)cb)
+
+struct Ewl_Callback_Custom
+{
+       Ewl_Callback cb;
+       unsigned int event_id;
+};
+
 /**
  * @def EWL_CALLBACK_NOTIFY_MASK
  * The value to binary AND with the callback pointer to check the notifiers.
@@ -46,70 +64,70 @@
 #define EWL_CALLBACK_NOTIFY_MASK (0x3)
 
 /**
+ * @def EWL_CALLBACK_INDEX(t)
+ * Retrieves the actual array index for t
+ */
+#define EWL_CALLBACK_INDEX(t) ((t < EWL_CALLBACK_MAX) ? t : EWL_CALLBACK_MAX)
+
+/**
  * @def EWL_CALLBACK_LIST(w, t)
  * Retrives the callback list from a widget for a certain event type.
  */
-#define EWL_CALLBACK_LIST(w, t) (w->callbacks[t].list)
+#define EWL_CALLBACK_LIST(w, t) (w->callbacks[EWL_CALLBACK_INDEX(t)].list)
 
 /**
  * @def EWL_CALLBACK_FLAGS(w, t)
  * Retrives the callback flags from a widget for a certain event type.
  */
-#define EWL_CALLBACK_FLAGS(w, t) (w->callbacks[t].mask)
+#define EWL_CALLBACK_FLAGS(w, t) (w->callbacks[EWL_CALLBACK_INDEX(t)].mask)
 
 /**
  * @def EWL_CALLBACK_LEN(w, t)
  * Retrives the length from a widget for a certain event type.
  */
-#define EWL_CALLBACK_LEN(w, t) (w->callbacks[t].len)
+#define EWL_CALLBACK_LEN(w, t) (w->callbacks[EWL_CALLBACK_INDEX(t)].len)
 
 /**
  * @def EWL_CALLBACK_POS(w, t)
  * Retrives the current callback position from a widget for an event type.
  */
-#define EWL_CALLBACK_POS(w, t) w->callbacks[t].index
-
-/**
- * @def EWL_CALLBACK_GET(w, t, i)
- * Retrives the callback struct at the given position
- */
-#define EWL_CALLBACK_GET(w, t, i) \
-       ((w->callbacks[t].mask & EWL_CALLBACK_TYPE_DIRECT) ? 
w->callbacks[t].list : (w->callbacks[t].list ? w->callbacks[t].list[i] : NULL))
+#define EWL_CALLBACK_POS(w, t) w->callbacks[EWL_CALLBACK_INDEX(t)].index
 
 /**
  * @def EWL_CALLBACK_FLAG_INTERCEPT(w, t)
  * Sets the callback intercept flag from a widget for a certain event type.
  */
 #define EWL_CALLBACK_FLAG_INTERCEPT(w, t) \
-               w->callbacks[t].mask |= EWL_CALLBACK_NOTIFY_INTERCEPT
+               w->callbacks[EWL_CALLBACK_INDEX(t)].mask |= 
EWL_CALLBACK_NOTIFY_INTERCEPT
 
 /**
  * @def EWL_CALLBACK_FLAG_NOINTERCEPT(w, t)
  * Clears the callback intercept flag from a widget for a certain event type.
  */
 #define EWL_CALLBACK_FLAG_NOINTERCEPT(w, t) \
-               w->callbacks[t].mask = w->callbacks[t].mask & 
~EWL_CALLBACK_NOTIFY_INTERCEPT
+               w->callbacks[EWL_CALLBACK_INDEX(t)].mask = \
+                       w->callbacks[EWL_CALLBACK_INDEX(t)].mask & 
~EWL_CALLBACK_NOTIFY_INTERCEPT
 
 /**
  * @def EWL_CALLBACK_FLAG_NOTIFY(w, t)
  * Sets the callback notify flag from a widget for a certain event type.
  */
 #define EWL_CALLBACK_FLAG_NOTIFY(w, t) \
-               w->callbacks[t].mask |= EWL_CALLBACK_NOTIFY_NOTIFY
+               w->callbacks[EWL_CALLBACK_INDEX(t)].mask |= 
EWL_CALLBACK_NOTIFY_NOTIFY
 
 /**
  * @def EWL_CALLBACK_SET_DIRECT(w, t)
  * Sets the callback direct flag for a centain event type
  */
 #define EWL_CALLBACK_SET_DIRECT(w, t) \
-               w->callbacks[t].mask |= EWL_CALLBACK_TYPE_DIRECT
+               w->callbacks[EWL_CALLBACK_INDEX(t)].mask |= 
EWL_CALLBACK_TYPE_DIRECT
 
 /**
  * @def EWL_CALLBACK_SET_NODIRECT(w, t)
  * Clears the callback direct flag from a widget for a certain event type
  */
 #define EWL_CALLBACK_SET_NODIRECT(w, t) \
-               w->callbacks[t].mask &= ~EWL_CALLBACK_TYPE_DIRECT
+               w->callbacks[EWL_CALLBACK_INDEX(t)].mask &= 
~EWL_CALLBACK_TYPE_DIRECT
 
 
 int             ewl_callbacks_init(void);
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_misc.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -3 -r1.62 -r1.63
--- ewl_misc.c  12 Jul 2006 11:13:16 -0000      1.62
+++ ewl_misc.c  13 Jul 2006 00:20:29 -0000      1.63
@@ -1048,7 +1048,7 @@
        
                ewl_callback_call(w, EWL_CALLBACK_DESTROY);
                ewl_callback_del_type(w, EWL_CALLBACK_DESTROY);
-               FREE(w);
+               ewl_widget_free(w);
                cleanup++;
        }
 
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_widget.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -3 -r1.89 -r1.90
--- ewl_widget.c        7 Jul 2006 20:27:38 -0000       1.89
+++ ewl_widget.c        13 Jul 2006 00:20:29 -0000      1.90
@@ -92,8 +92,6 @@
                                NULL);
        ewl_callback_append(w, EWL_CALLBACK_CONFIGURE, ewl_widget_configure_cb,
                                NULL);
-       ewl_callback_append(w, EWL_CALLBACK_DESTROY, ewl_widget_destroy_cb,
-                               NULL);
        ewl_callback_append(w, EWL_CALLBACK_REPARENT, ewl_widget_reparent_cb,
                                NULL);
        ewl_callback_append(w, EWL_CALLBACK_WIDGET_ENABLE, ewl_widget_enable_cb,
@@ -439,7 +437,7 @@
         * We delete these now so that we can't possibly get any callbacks 
before the 
         * idler kicks in
         */
-       for (i = 0; i < EWL_CALLBACK_MAX; i++)
+       for (i = 0; i < (EWL_CALLBACK_MAX + 1); i++)
        {
                if (i == EWL_CALLBACK_DESTROY) continue;
                ewl_callback_del_type(w, i);
@@ -2024,16 +2022,11 @@
 /**
  * @internal
  * @param w: The widget to work with
- * @param ev_data: UNUSED
- * @param data: UNUSED
  * @return Returns no value
- * @brief Perform the series of operations common to every widget when
- * they are destroyed. This should ALWAYS be the the last callback
- * in the chain.
+ * @brief Free all the widget data
  */
 void
-ewl_widget_destroy_cb(Ewl_Widget *w, void *ev_data __UNUSED__,
-                       void *data __UNUSED__)
+ewl_widget_free(Ewl_Widget *w)
 {
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("w", w);
@@ -2091,7 +2084,9 @@
                ecore_hash_destroy(w->data);
                w->data = NULL;
        }
-
+       
+       FREE(w);
+       
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 
===================================================================
RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_widget.h,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -3 -r1.43 -r1.44
--- ewl_widget.h        25 May 2006 18:27:18 -0000      1.43
+++ ewl_widget.h        13 Jul 2006 00:20:29 -0000      1.44
@@ -127,7 +127,8 @@
        Ewl_Object       object; /**< Inherit the base Object class */
        Ewl_Widget      *parent; /**< The parent widget, actually a container */
 
-       Ewl_Callback_Chain callbacks[EWL_CALLBACK_MAX]; /**< Callback chain 
array */
+       Ewl_Callback_Chain callbacks[EWL_CALLBACK_MAX + 1]; 
+                                               /**< Callback chain array */
        Ewl_Attach_List *attach;       /**< List of attachments on the widget */
 
        Evas_Object     *smart_object; /**< Smart Object for the layer stuff */
@@ -149,6 +150,7 @@
 };
 
 int             ewl_widget_init(Ewl_Widget * w);
+void           ewl_widget_free(Ewl_Widget *w);
 
 void            ewl_widget_name_set(Ewl_Widget * w, const char *name);
 const char *    ewl_widget_name_get(Ewl_Widget * w);
@@ -248,7 +250,6 @@
 void ewl_widget_realize_cb(Ewl_Widget *w, void *ev_data, void *user_data);
 void ewl_widget_unrealize_cb(Ewl_Widget *w, void *ev_data, void *user_data);
 void ewl_widget_configure_cb(Ewl_Widget *w, void *ev_data, void *user_data);
-void ewl_widget_destroy_cb(Ewl_Widget *w, void *ev_data, void *user_data);
 void ewl_widget_reparent_cb(Ewl_Widget *w, void *ev_data, void *user_data);
 void ewl_widget_enable_cb(Ewl_Widget *w, void *ev_data, void *user_data);
 void ewl_widget_disable_cb(Ewl_Widget *w, void *ev_data, void *user_data);




-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to