Enlightenment CVS committal

Author  : rbdpngn
Project : e17
Module  : libs/ewl

Dir     : e17/libs/ewl/src


Modified Files:
        ewl_container.c ewl_enums.h ewl_misc.c ewl_misc.h 
        ewl_radiobutton.c ewl_widget.c 


Log Message:
A rudimentary GC for freeing widgets. This needs more extensive testing, but
appears to work well on the basic widgets.

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_container.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -3 -r1.42 -r1.43
--- ewl_container.c     22 Sep 2003 06:09:24 -0000      1.42
+++ ewl_container.c     24 Sep 2003 07:12:25 -0000      1.43
@@ -216,6 +216,15 @@
        DCHECK_PARAM_PTR("child", child);
 
        /*
+        * First remove reference to the parent if necessary.
+        */
+       if (EWL_CONTAINER(child->parent) == pc)
+               ewl_widget_set_parent(child, NULL);
+
+       if (!pc->children)
+               DRETURN(DLEVEL_STABLE);
+
+       /*
         * Traverse the list to the child.
         */
        temp = ewd_list_goto(pc->children, child);
@@ -232,8 +241,6 @@
        ewd_list_remove(pc->children);
        if (pc->child_remove && VISIBLE(child))
                pc->child_remove(pc, child);
-
-       ewl_widget_set_parent(child, NULL);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_enums.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -3 -r1.37 -r1.38
--- ewl_enums.h 22 Sep 2003 06:09:24 -0000      1.37
+++ ewl_enums.h 24 Sep 2003 07:12:25 -0000      1.38
@@ -139,6 +139,7 @@
        EWL_FLAGS_RECURSIVE = 0x8,
        EWL_FLAGS_CSCHEDULED = 0x10,
        EWL_FLAGS_RSCHEDULED = 0x20,
+       EWL_FLAGS_DSCHEDULED = 0x40,
 };
 
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_misc.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -3 -r1.36 -r1.37
--- ewl_misc.c  5 Sep 2003 22:20:26 -0000       1.36
+++ ewl_misc.c  24 Sep 2003 07:12:25 -0000      1.37
@@ -7,6 +7,7 @@
 extern Ewd_List *ewl_embed_list;
 static Ewd_List *configure_list = NULL;
 static Ewd_List *realize_list = NULL;
+static Ewd_List *destroy_list = NULL;
 
 void            __ewl_init_parse_options(int argc, char **argv);
 void            __ewl_parse_option_array(int argc, char **argv);
@@ -44,6 +45,7 @@
 
        configure_list = ewd_list_new();
        realize_list = ewd_list_new();
+       destroy_list = ewd_list_new();
        __ewl_init_parse_options(argc, argv);
 
        ecore_init();
@@ -121,6 +123,12 @@
                exit(-1);
        }
 
+       /*
+        * Clean out the unused widgets first, to avoid them being drawn or
+        * unnecessary work done from configuration.
+        */
+       ewl_garbage_collect();
+
        if (ewd_list_is_empty(ewl_embed_list))
                DRETURN_INT(TRUE, DLEVEL_STABLE);
 
@@ -439,6 +447,30 @@
        }
 
        ewd_list_append(realize_list, w);
+}
+
+void ewl_destroy_request(Ewl_Widget *w)
+{
+       if (w->flags & EWL_FLAGS_DSCHEDULED)
+               DRETURN(DLEVEL_STABLE);
+
+       w->flags |= EWL_FLAGS_DSCHEDULED;
+       ewd_list_append(destroy_list, w);
+}
+
+void ewl_garbage_collect()
+{
+       Ewl_Widget *w;
+
+       DENTER_FUNCTION(DLEVEL_STABLE);
+
+       while ((w = ewd_list_remove_first(destroy_list))) {
+               ewl_callback_call(w, EWL_CALLBACK_DESTROY);
+               ewl_callback_del_type(w, EWL_CALLBACK_DESTROY);
+               FREE(w);
+       }
+
+       DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
 
 int __ewl_ecore_exit(void *data, int type, void *event)
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_misc.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -3 -r1.16 -r1.17
--- ewl_misc.h  5 Sep 2003 22:20:26 -0000       1.16
+++ ewl_misc.h  24 Sep 2003 07:12:25 -0000      1.17
@@ -21,5 +21,7 @@
 void            ewl_configure_request(Ewl_Widget * w);
 void            ewl_configure_cancel_request(Ewl_Widget *w);
 void            ewl_realize_request(Ewl_Widget *w);
+void           ewl_destroy_request(Ewl_Widget *w);
+void           ewl_garbage_collect();
 
 #endif                         /* __EWL_MISC_H__ */
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_radiobutton.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -3 -r1.26 -r1.27
--- ewl_radiobutton.c   5 Sep 2003 03:07:04 -0000       1.26
+++ ewl_radiobutton.c   24 Sep 2003 07:12:25 -0000      1.27
@@ -153,8 +153,10 @@
        ewd_list_goto(rb->chain, w);
        ewd_list_remove(rb->chain);
 
-       if (ewd_list_is_empty(rb->chain))
+       if (ewd_list_is_empty(rb->chain)) {
                ewd_list_destroy(rb->chain);
+               rb->chain = NULL;
+       }
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ewl/src/ewl_widget.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -3 -r1.70 -r1.71
--- ewl_widget.c        22 Sep 2003 06:09:24 -0000      1.70
+++ ewl_widget.c        24 Sep 2003 07:12:25 -0000      1.71
@@ -235,6 +235,9 @@
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("w", w);
 
+       if (w->flags & EWL_FLAGS_DSCHEDULED)
+               DRETURN(DLEVEL_STABLE);
+
        if (last_selected == w)
                last_selected = NULL;
 
@@ -247,11 +250,7 @@
        if (dnd_widget == w)
                dnd_widget = NULL;
 
-       ewl_callback_call(w, EWL_CALLBACK_DESTROY);
-
-       ewl_callback_del_type(w, EWL_CALLBACK_DESTROY);
-
-       FREE(w);
+       ewl_destroy_request(w);
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }
@@ -480,37 +479,31 @@
  */
 void ewl_widget_set_parent(Ewl_Widget * w, Ewl_Widget * p)
 {
+       Ewl_Container *op;
+
        DENTER_FUNCTION(DLEVEL_STABLE);
        DCHECK_PARAM_PTR("w", w);
 
+       op = EWL_CONTAINER(w->parent);
+       w->parent = p;
+
        /*
         * A widget cannot be the child of multiple widgets, so remove it
         * from a previous parent before adding to this parent.
         */
-       if (w->parent) {
-               ewl_container_remove_child(EWL_CONTAINER(w->parent), w);
-       }
-       else if (p) {
-               /*
-                * Append a destroy callback to the child to remove it from the
-                * container.
-                */
-               ewl_callback_prepend(w, EWL_CALLBACK_DESTROY,
-                               __ewl_widget_child_destroy, NULL);
-       }
-       else {
-               /*
-                * Remove the callback from the child for removing it from the
-                * container upon destruction.
-                */
-               ewl_callback_del(w, EWL_CALLBACK_DESTROY,
+       if (op) {
+               ewl_container_remove_child(op, w);
+               if (!p)
+                       ewl_callback_del(w, EWL_CALLBACK_DESTROY,
                                 __ewl_widget_child_destroy);
        }
 
-       w->parent = p;
-
-       if (p)
+       if (p) {
+               if (!op)
+                       ewl_callback_prepend(w, EWL_CALLBACK_DESTROY,
+                                       __ewl_widget_child_destroy, NULL);
                ewl_callback_call(w, EWL_CALLBACK_REPARENT);
+       }
 
        DLEAVE_FUNCTION(DLEVEL_STABLE);
 }




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to