yakov pushed a commit to branch master.

http://git.enlightenment.org/tools/erigo.git/commit/?id=190a938ff9d43c095e4f15c0d044d7b4b94a20b0

commit 190a938ff9d43c095e4f15c0d044d7b4b94a20b0
Author: Yakov Goldberg <yako...@samsung.com>
Date:   Thu Oct 29 11:05:57 2015 +0200

    Refactoring eo deletetion for widgets
    
    In order do delete widget's eo, call manager_widget_del()
    it will delete Eo, and call callbacks to delete all child's Eo objects
---
 src/bin/gui/editor.c | 122 ++++++++++++++++++++++++---------------------------
 1 file changed, 58 insertions(+), 64 deletions(-)

diff --git a/src/bin/gui/editor.c b/src/bin/gui/editor.c
index 71256a1..1e46fa0 100644
--- a/src/bin/gui/editor.c
+++ b/src/bin/gui/editor.c
@@ -482,58 +482,6 @@ _editor_wdg_selected_set(const Gui_Widget *wdg)
      }
 }
 
-/* Second parameter is used to indicate if the wdg has to be deleted */
-static void
-_iter_widget_delete(Gui_Widget *wdg)
-{
-   const Eina_List *children = NULL, *l, *l2;
-   Eid *wid;
-   Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(_active_context_get());
-
-   children = wdg_children_list_get(wdg);
-   EINA_LIST_FOREACH_SAFE(children, l, l2, wid)
-     {
-        Gui_Widget *w = wdg_get(wid);
-        if (w) _iter_widget_delete(w);
-     }
-
-   /* If widget is Win, look for its frame and unset content, but don't delete 
frame. */
-   Eo *optional_win = NULL;
-   /* Each time we iterate over widgets in order to delete them, we set 
window's frame invisible.
-    * DUring creation it will be visible again. Frame deleted only when 
project is closed. */
-   if (IS_MAIN(wdg))
-     {
-        Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
-        if (wi)
-          {
-             if (!IS_WIN(wdg))
-               {
-                  Eo *o = session_eo_get(session, wdg);
-                  eo_do(o, optional_win = eo_key_data_get("__editor_win"));
-               }
-             Eo *fr = main_wdg_info_frame_get(wi);
-             if (fr)
-               {
-                  /* Inlined image is created right on a evas and not 
connected to it's win.
-                   * So when win is deleted, image stays.
-                   * During next creation of Eo for wdg new image will be 
created and the old one will be unter it.
-                   * Anyhow, let's hide it.
-                   * It will be deleted together with it's evas*/
-                  Eo *win_inlined_image = elm_object_content_get(fr);
-                  eo_do(win_inlined_image, efl_gfx_visible_set(EINA_FALSE));
-                  eo_do(fr, efl_gfx_visible_set(EINA_FALSE));
-               }
-          }
-     }
-   manager_widget_delete(session, wdg, NULL);
-
-   /* Delete window's optinal win. */
-   if (optional_win)
-     {
-        eo_del(optional_win);
-     }
-}
-
 static void
 _key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event_info EINA_UNUSED)
 {
@@ -2482,12 +2430,57 @@ _dragdone_post_cb(Eina_Bool accept)
 }
 
 static Eina_Bool
+_wdg_eo_del(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc 
EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+   Gui_Widget *wdg = data;
+   /*FIXME: move this from here*/
+   objtree_item_remove(wdg);
+
+   DnD_Main_Obj_Info *di = wdg_data_get(wdg, EDITOR_DND_DATA);
+   if (di)
+     {
+        free(di);
+        wdg_data_set(wdg, EDITOR_DND_DATA, NULL);
+     }
+
+   drop_target_wdg_del((Gui_Widget *) wdg, NULL);
+   return EINA_TRUE;
+}
+
+static Eina_Bool
+_main_wdg_eo_del(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description 
*desc EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+   Gui_Widget *wdg = data;
+   /* If widget is Win, look for its frame and unset content, but don't delete 
frame. */
+
+   /* Each time we iterate over widgets in order to delete them, we set 
window's frame invisible.
+    * During creation it will be visible again. Frame is deleted only when 
project is closed. */
+   Main_Wdg_Info *wi = wdg_data_get(wdg, MAIN_WDG_INFO);
+   if (wi)
+     {
+        /* Inlined image is created right on a evas and not connected to it's 
win.
+         * So when win is deleted, image stays.
+         * During next creation of Eo for wdg new image will be created and 
the old one      will be unter it.
+         * Anyhow, let's hide it.
+         * It will be deleted together with it's evas*/
+        Eo *fr = main_wdg_info_frame_get(wi);
+        if (fr)
+          {
+             eo_do(fr, elm_obj_container_content_unset(NULL));
+             eo_do(fr, efl_gfx_visible_set(EINA_FALSE));
+          }
+     }
+   return EINA_TRUE;
+}
+
+static Eina_Bool
 _widget_add(Gui_Session *session, const Gui_Widget *wdg, void *data 
EINA_UNUSED)
 {
    if (!IS_MAIN(wdg))
      {
         Eo *o = _ffi_eo_add(session, wdg, NULL);
         if (!o) return EINA_FALSE;
+        eo_do(o, eo_event_callback_add(EO_BASE_EVENT_DEL, _wdg_eo_del, wdg));
         /* Add specific callbacks, related to UI. */
         evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN, _key_down, 
wdg_context_get(wdg));
         eo_do(o, eo_event_callback_add(EVAS_OBJECT_EVENT_RESIZE, _wdg_resize, 
NULL));
@@ -2536,12 +2529,15 @@ _widget_add(Gui_Session *session, const Gui_Widget 
*wdg, void *data EINA_UNUSED)
           {
              Eo *o = _ffi_eo_add(session, wdg, win);
              if (!o) return EINA_FALSE;
-             //eo_do(win, elm_obj_win_resize_object_add(o));
              eo_do(o, eo_key_data_set("__editor_win", win));
+             eo_do(o, eo_event_callback_add(EO_BASE_EVENT_DEL, 
_main_wdg_eo_del, wdg));
+             eo_do(o, eo_event_callback_add(EO_BASE_EVENT_DEL, _wdg_eo_del, 
wdg));
           }
         else
           {
              session_eo_set(session, wdg, win);
+             eo_do(win, eo_event_callback_add(EO_BASE_EVENT_DEL, _wdg_eo_del, 
wdg));
+             eo_do(win, eo_event_callback_add(EO_BASE_EVENT_DEL, 
_main_wdg_eo_del, wdg));
           }
 
         Eo *iwin = elm_win_inlined_image_object_get(win);
@@ -2652,19 +2648,15 @@ _widget_add(Gui_Session *session, const Gui_Widget 
*wdg, void *data EINA_UNUSED)
 static Eina_Bool
 _widget_del(Gui_Session *session, const Gui_Widget *wdg, void *data 
EINA_UNUSED)
 {
-   Eo *o = session_eo_get(session, wdg);
-   objtree_item_remove(wdg);
-   session_wdg_existence_set(session, wdg, EINA_FALSE);
+   Eo *o = session_eo_get(session, wdg), *del_obj;
+   del_obj = o;
 
-   DnD_Main_Obj_Info *di = wdg_data_get(wdg, EDITOR_DND_DATA);
-   if (di)
+   if (IS_MAIN(wdg) && !IS_WIN(wdg))
      {
-        free(di);
-        wdg_data_set(wdg, EDITOR_DND_DATA, NULL);
+        eo_do(o, del_obj = eo_key_data_get("__editor_win"));
      }
 
-   drop_target_wdg_del((Gui_Widget *) wdg, NULL);
-   eo_del(o);
+   eo_del(del_obj);
    return EINA_TRUE;
 }
 
@@ -2682,7 +2674,8 @@ _editor_layout_clear(const Gui_Context *ctx)
    EINA_LIST_FOREACH_SAFE(list, itr, itr2, wdg_id)
      {
         Gui_Widget *wdg = wdg_get(wdg_id);
-        if (wdg) _iter_widget_delete(wdg);
+        Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(_active_context_get());
+        manager_widget_delete(session, wdg, NULL);
      }
    return EINA_TRUE;
 }
@@ -2692,7 +2685,8 @@ static Eina_Bool
 _editor_widget_clear(Gui_Widget *wdg)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(wdg, EINA_FALSE);
-   _iter_widget_delete(wdg);
+   Gui_Session *session = (Gui_Session *) 
gui_context_editor_session_get(_active_context_get());
+   manager_widget_delete(session, wdg, NULL);
    return EINA_TRUE;
 }
 

-- 


Reply via email to