This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit 5ddeecebddd01a1bbd8124cfe283174e66053542
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Oct 31 12:21:12 2026 -0600

    elementary: a box or a table forgets a child another container takes
    
    Efl.Ui.Box and Efl.Ui.Table keep their own list of children and were
    never told when one of them was taken: packed into another box, set
    as another widget's content, or added as another widget's sub-object.
    The child still counted, was still iterated and was still laid out by
    its old container, over the new one. They now override
    widget_sub_object_del, which EFL calls on the old parent in every one
    of those cases, and release the child there, with one content,removed.
    Unpacking goes through the same path, so a child is never released
    twice.
    
    They also drop a child when it is invalidated rather than when it is
    freed: a child deleted while something still holds a reference, as a
    language binding's wrapper does, no longer lingers in the container.
    
    Efl.Ui.Radio_Box takes a radio out of its group when it loses it, and
    registers a radio only once it is packed, so a refused pack leaves the
    radio in the group it was in. A radio that was its group's fallback no
    longer stays the group's selection after it leaves.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_box.c              |  85 ++++++--
 src/lib/elementary/efl_ui_box.eo             |   1 +
 src/lib/elementary/efl_ui_radio_box.c        |  50 ++---
 src/lib/elementary/efl_ui_radio_box.eo       |   1 +
 src/lib/elementary/efl_ui_radio_group_impl.c |   4 +
 src/lib/elementary/efl_ui_table.c            | 103 +++++----
 src/lib/elementary/efl_ui_table.eo           |   1 +
 src/lib/elementary/efl_ui_table_private.h    |   1 +
 src/tests/elementary/efl_ui_test_box.c       | 315 +++++++++++++++++++++++++++
 src/tests/elementary/efl_ui_test_table.c     | 220 +++++++++++++++++++
 10 files changed, 696 insertions(+), 85 deletions(-)

diff --git a/src/lib/elementary/efl_ui_box.c b/src/lib/elementary/efl_ui_box.c
index 34cc5a79f0..7b0dcb6870 100644
--- a/src/lib/elementary/efl_ui_box.c
+++ b/src/lib/elementary/efl_ui_box.c
@@ -19,17 +19,6 @@ _on_child_size_changed(void *data, const Efl_Event *event EINA_UNUSED)
    efl_pack_layout_request(box);
 }
 
-static void
-_on_child_del(void *data, const Efl_Event *event)
-{
-   Eo *box = data;
-   EFL_UI_BOX_DATA_GET(box, sd);
-
-   sd->children = eina_list_remove(sd->children, event->object);
-
-   efl_pack_layout_request(box);
-}
-
 static void
 _on_child_hints_changed(void *data, const Efl_Event *event EINA_UNUSED)
 {
@@ -37,10 +26,12 @@ _on_child_hints_changed(void *data, const Efl_Event *event EINA_UNUSED)
    efl_pack_layout_request(box);
 }
 
+static void _on_child_invalidate(void *data, const Efl_Event *event);
+
 EFL_CALLBACKS_ARRAY_DEFINE(efl_ui_box_callbacks,
   { EFL_GFX_ENTITY_EVENT_SIZE_CHANGED, _on_child_size_changed },
   { EFL_GFX_ENTITY_EVENT_HINTS_CHANGED, _on_child_hints_changed },
-  { EFL_EVENT_DEL, _on_child_del }
+  { EFL_EVENT_INVALIDATE, _on_child_invalidate }
 );
 
 static inline Eina_Bool
@@ -69,6 +60,36 @@ _efl_ui_box_child_register(Eo *obj, Efl_Ui_Box_Data *pd, Efl_Gfx_Entity *subobj)
    return EINA_TRUE;
 }
 
+/* The box lets go of a child: no longer a member, clipped, or listened to.
+   This is shared by the box unpacking the child and by another container
+   taking it, which the box hears of as the widget parent losing it. */
+static void
+_efl_ui_box_child_release(Eo *obj, Efl_Gfx_Entity *subobj)
+{
+   efl_canvas_group_member_remove(obj, subobj);
+   efl_canvas_object_clipper_set(subobj, NULL);
+   efl_key_data_set(subobj, "_elm_leaveme", NULL);
+   efl_event_callback_array_del(subobj, efl_ui_box_callbacks(), obj);
+   if (efl_invalidating_get(obj) || efl_invalidated_get(obj)) return;
+
+   efl_pack_layout_request(obj);
+   efl_event_callback_call(obj, EFL_CONTAINER_EVENT_CONTENT_REMOVED, subobj);
+}
+
+/* A child deleted while something else still references it is gone from the
+   box now, not at the last unref. */
+static void
+_on_child_invalidate(void *data, const Efl_Event *event)
+{
+   Eo *box = data;
+   EFL_UI_BOX_DATA_GET(box, sd);
+   Eina_List *found = eina_list_data_find_list(sd->children, event->object);
+
+   if (!found) return;
+   sd->children = eina_list_remove_list(sd->children, found);
+   _efl_ui_box_child_release(box, event->object);
+}
+
 static inline Eina_Bool
 _efl_ui_box_child_unregister(Eo *obj, Efl_Ui_Box_Data *pd EINA_UNUSED, Efl_Gfx_Entity *subobj)
 {
@@ -81,23 +102,36 @@ _efl_ui_box_child_unregister(Eo *obj, Efl_Ui_Box_Data *pd EINA_UNUSED, Efl_Gfx_E
    if (!subobj)
      return EINA_FALSE;
 
+   /* Moving the child to the top widget makes the box hear of it through
+      widget_sub_object_del, which releases it already. */
    if (!efl_ui_widget_internal_get(obj))
      {
         if (!_elm_widget_sub_object_redirect_to_top(obj, subobj))
           return EINA_FALSE;
      }
 
-   efl_canvas_group_member_remove(obj, subobj);
-   efl_canvas_object_clipper_set(subobj, NULL);
-   efl_key_data_set(subobj, "_elm_leaveme", NULL);
-   efl_pack_layout_request(obj);
-
-   efl_event_callback_array_del(subobj, efl_ui_box_callbacks(), obj);
-   efl_event_callback_call(obj, EFL_CONTAINER_EVENT_CONTENT_REMOVED, subobj);
+   if (efl_canvas_object_render_parent_get(subobj) == obj)
+     _efl_ui_box_child_release(obj, subobj);
 
    return EINA_TRUE;
 }
 
+/* A child that another container takes is no longer ours, whatever it
+   was told. */
+EOLIAN static Eina_Bool
+_efl_ui_box_efl_ui_widget_widget_sub_object_del(Eo *obj, Efl_Ui_Box_Data *pd, Efl_Gfx_Entity *sobj)
+{
+   Eina_Bool ok = efl_ui_widget_sub_object_del(efl_super(obj, MY_CLASS), sobj);
+   Eina_List *found = ok ? eina_list_data_find_list(pd->children, sobj) : NULL;
+
+   if (found)
+     {
+        pd->children = eina_list_remove_list(pd->children, found);
+        _efl_ui_box_child_release(obj, sobj);
+     }
+   return ok;
+}
+
 static void
 _efl_ui_box_size_hints_changed_cb(void *data EINA_UNUSED, const Efl_Event *ev)
 {
@@ -230,8 +264,12 @@ EOLIAN static Eina_Bool
 _efl_ui_box_efl_pack_pack_clear(Eo *obj, Efl_Ui_Box_Data *pd)
 {
    Eo *child;
-   EINA_LIST_FREE(pd->children, child)
+
+   /* Each child leaves the list before it is deleted, as deleting it makes
+      the box hear of it through widget_sub_object_del. */
+   while ((child = eina_list_data_get(pd->children)))
      {
+        pd->children = eina_list_remove_list(pd->children, pd->children);
         efl_event_callback_array_del(child, efl_ui_box_callbacks(), obj);
         efl_del(child);
      }
@@ -247,8 +285,11 @@ _efl_ui_box_efl_pack_unpack_all(Eo *obj, Efl_Ui_Box_Data *pd)
    Eo *child;
    Eina_Bool ret = EINA_TRUE;
 
-   EINA_LIST_FREE(pd->children, child)
-     ret &= _efl_ui_box_child_unregister(obj, pd, child);
+   while ((child = eina_list_data_get(pd->children)))
+     {
+        pd->children = eina_list_remove_list(pd->children, pd->children);
+        ret &= _efl_ui_box_child_unregister(obj, pd, child);
+     }
 
    return ret;
 }
diff --git a/src/lib/elementary/efl_ui_box.eo b/src/lib/elementary/efl_ui_box.eo
index 9d004af05d..64b87d916c 100644
--- a/src/lib/elementary/efl_ui_box.eo
+++ b/src/lib/elementary/efl_ui_box.eo
@@ -43,6 +43,7 @@ class Efl.Ui.Box extends Efl.Ui.Widget implements Efl.Pack_Linear, Efl.Pack_Layo
       Efl.Canvas.Group.group_calculate;
       Efl.Gfx.Entity.position { set; }
       Efl.Gfx.Entity.size { set; }
+      Efl.Ui.Widget.widget_sub_object_del;
       Efl.Container.content_iterate;
       Efl.Container.content_count;
       Efl.Ui.Focus.Object.setup_order_non_recursive;
diff --git a/src/lib/elementary/efl_ui_radio_box.c b/src/lib/elementary/efl_ui_radio_box.c
index 84f6733926..59251cd854 100644
--- a/src/lib/elementary/efl_ui_radio_box.c
+++ b/src/lib/elementary/efl_ui_radio_box.c
@@ -11,33 +11,19 @@ typedef struct {
    Efl_Ui_Radio_Group *group;
 } Efl_Ui_Radio_Box_Data;
 
-static inline Eina_Bool
-register_safe_in_group_begin(Eo *subobj, Efl_Ui_Radio_Box_Data *pd, Eina_Bool is_radio)
-{
-   if (pd->in_pack) return EINA_TRUE;
-   if (is_radio)
-     efl_ui_radio_group_register(pd->group, subobj);
-   pd->in_pack = EINA_TRUE;
-
-   return EINA_TRUE;
-}
-
-static inline Eina_Bool
-register_safe_group_end(Eo *subobj, Efl_Ui_Radio_Box_Data *pd, Eina_Bool is_radio, Eina_Bool result)
-{
-   if (is_radio && (!result))
-     efl_ui_radio_group_unregister(pd->group, subobj);
-   pd->in_pack = EINA_FALSE;
-
-   return result;
-}
-
+/* The radio joins the group once the box holds it. Packing it takes it from
+   its former parent, and a radio box learns of that as its radio leaves, so
+   the radio is out of the group it came from by the time it joins this one.
+   A pack that calls another pack registers only in the outermost one. */
 #define REGISTER_SAFE(f) \
-  Eina_Bool result, is_radio = efl_isa(subobj, EFL_UI_RADIO_CLASS); \
-  if (!register_safe_in_group_begin(subobj, pd, is_radio)) \
-    return EINA_FALSE; \
-  result = f ; \
-  return register_safe_group_end(subobj, pd, is_radio, result);
+  Eina_Bool result, is_radio; \
+  if (pd->in_pack) return f; \
+  is_radio = efl_isa(subobj, EFL_UI_RADIO_CLASS); \
+  pd->in_pack = EINA_TRUE; \
+  result = f; \
+  pd->in_pack = EINA_FALSE; \
+  if (result && is_radio) efl_ui_radio_group_register(pd->group, subobj); \
+  return result;
 
 static void
 unpack_from_logical(Eo *obj, Efl_Ui_Radio_Box_Data *pd)
@@ -49,6 +35,18 @@ unpack_from_logical(Eo *obj, Efl_Ui_Radio_Box_Data *pd)
      }
 }
 
+/* A radio another container takes leaves the group with the box. */
+EOLIAN static Eina_Bool
+_efl_ui_radio_box_efl_ui_widget_widget_sub_object_del(Eo *obj, Efl_Ui_Radio_Box_Data *pd, Efl_Gfx_Entity *sobj)
+{
+   Eina_Bool held = efl_isa(sobj, EFL_UI_RADIO_CLASS) &&
+     (efl_pack_index_get(obj, sobj) >= 0);
+   Eina_Bool ok = efl_ui_widget_sub_object_del(efl_super(obj, MY_CLASS), sobj);
+
+   if (ok && held) efl_ui_radio_group_unregister(pd->group, sobj);
+   return ok;
+}
+
 EOLIAN static Eina_Bool
 _efl_ui_radio_box_efl_pack_pack_clear(Eo *obj, Efl_Ui_Radio_Box_Data *pd)
 {
diff --git a/src/lib/elementary/efl_ui_radio_box.eo b/src/lib/elementary/efl_ui_radio_box.eo
index 86b05af74a..a29e0e7f07 100644
--- a/src/lib/elementary/efl_ui_radio_box.eo
+++ b/src/lib/elementary/efl_ui_radio_box.eo
@@ -20,5 +20,6 @@ class Efl.Ui.Radio_Box extends Efl.Ui.Box composites Efl.Ui.Radio_Group
       Efl.Pack_Linear.pack_at;
       Efl.Pack_Linear.pack_unpack_at;
       Efl.Object.constructor;
+      Efl.Ui.Widget.widget_sub_object_del;
    }
 }
diff --git a/src/lib/elementary/efl_ui_radio_group_impl.c b/src/lib/elementary/efl_ui_radio_group_impl.c
index 1f9e9a4e8d..4e32efa2ec 100644
--- a/src/lib/elementary/efl_ui_radio_group_impl.c
+++ b/src/lib/elementary/efl_ui_radio_group_impl.c
@@ -165,6 +165,10 @@ _efl_ui_radio_group_impl_efl_ui_radio_group_register(Eo *obj, Efl_Ui_Radio_Group
 EOLIAN static void
 _efl_ui_radio_group_impl_efl_ui_radio_group_unregister(Eo *obj, Efl_Ui_Radio_Group_Impl_Data *pd, Efl_Ui_Radio *radio)
 {
+   /* A radio that leaves cannot be what the group falls back to, or
+      deselecting it would select it again. */
+   if (pd->fallback_object == radio)
+     pd->fallback_object = NULL;
    if (pd->selected == radio)
      efl_ui_selectable_selected_set(pd->selected, EINA_FALSE);
 
diff --git a/src/lib/elementary/efl_ui_table.c b/src/lib/elementary/efl_ui_table.c
index 12b8342c1e..1f6e7e9271 100644
--- a/src/lib/elementary/efl_ui_table.c
+++ b/src/lib/elementary/efl_ui_table.c
@@ -48,38 +48,12 @@ _on_child_hints_changed(void *data, const Efl_Event *event EINA_UNUSED)
    efl_pack_layout_request(table);
 }
 
-static void
-_on_child_del(void *data, const Efl_Event *event)
-{
-   Eo *table = data;
-   Table_Item *gi;
-   EFL_UI_TABLE_DATA_GET(table, pd);
-
-   gi = _efl_ui_table_item_date_get(table, pd, event->object);
-   if (!gi) return;
-
-   if ((gi->col == pd->last_col) && (gi->row == pd->last_row))
-     pd->linear_recalc = EINA_TRUE;
-
-   if (gi->col + gi->col_span >= pd->cols)
-     pd->cols_recalc = EINA_TRUE;
-   if (gi->row + gi->row_span >= pd->rows)
-     pd->rows_recalc = EINA_TRUE;
-
-   pd->items = (Table_Item *)
-         eina_inlist_remove(EINA_INLIST_GET(pd->items), EINA_INLIST_GET(gi));
-   free(gi);
-
-   pd->count--;
-   efl_key_data_set(event->object, TABLE_ITEM_KEY, NULL);
-
-   efl_pack_layout_request(table);
-}
+static void _on_child_invalidate(void *data, const Efl_Event *event);
 
 EFL_CALLBACKS_ARRAY_DEFINE(efl_ui_table_callbacks,
   { EFL_GFX_ENTITY_EVENT_SIZE_CHANGED, _on_child_size_changed },
   { EFL_GFX_ENTITY_EVENT_HINTS_CHANGED, _on_child_hints_changed },
-  { EFL_EVENT_DEL, _on_child_del }
+  { EFL_EVENT_INVALIDATE, _on_child_invalidate }
 );
 
 static void
@@ -259,6 +233,7 @@ _efl_ui_table_efl_object_invalidate(Eo *obj, Efl_Ui_Table_Data *pd)
    EINA_INLIST_FREE(EINA_INLIST_GET(pd->items), gi)
      {
         efl_event_callback_array_del(gi->object, efl_ui_table_callbacks(), obj);
+        efl_key_data_set(gi->object, TABLE_ITEM_KEY, NULL);
 
         pd->items = (Table_Item *)
             eina_inlist_remove(EINA_INLIST_GET(pd->items), EINA_INLIST_GET(gi));
@@ -355,6 +330,7 @@ _pack_at(Eo *obj, Efl_Ui_Table_Data *pd, Efl_Gfx_Entity *subobj, int col, int ro
    gi->col_span = colspan;
    gi->row_span = rowspan;
    gi->object = subobj;
+   gi->table = obj;
    pd->count++;
    pd->items = (Table_Item *)
        eina_inlist_append(EINA_INLIST_GET(pd->items), EINA_INLIST_GET(gi));
@@ -509,21 +485,20 @@ _efl_ui_table_efl_pack_table_table_content_get(Eo *obj EINA_UNUSED, Efl_Ui_Table
    return NULL;
 }
 
-static Eina_Bool
-_item_remove(Efl_Ui_Table *obj, Efl_Ui_Table_Data *pd, Table_Item *gi)
+/* The table lets go of an item: no longer a member, clipped, or listened
+   to. This is shared by the table unpacking the child and by another
+   container taking it, which the table hears of as the widget parent
+   losing it. */
+static void
+_item_release(Efl_Ui_Table *obj, Efl_Ui_Table_Data *pd, Table_Item *gi)
 {
    Efl_Gfx_Entity *subobj = gi->object;
 
-   if (!subobj || !_elm_widget_sub_object_redirect_to_top(obj, subobj))
-     return EINA_FALSE;
-
    efl_canvas_object_clipper_set(subobj, NULL);
    efl_key_data_set(subobj, "_elm_leaveme", NULL);
    efl_key_data_set(subobj, TABLE_ITEM_KEY, NULL);
    efl_event_callback_array_del(subobj, efl_ui_table_callbacks(), obj);
-
    efl_canvas_group_member_remove(obj, subobj);
-   efl_event_callback_call(obj, EFL_CONTAINER_EVENT_CONTENT_REMOVED, subobj);
 
    if ((gi->col == pd->last_col) && (gi->row == pd->last_row))
      pd->linear_recalc = EINA_TRUE;
@@ -538,11 +513,61 @@ _item_remove(Efl_Ui_Table *obj, Efl_Ui_Table_Data *pd, Table_Item *gi)
    free(gi);
 
    pd->count--;
+   if (efl_invalidating_get(obj) || efl_invalidated_get(obj)) return;
+
    efl_pack_layout_request(obj);
+   efl_event_callback_call(obj, EFL_CONTAINER_EVENT_CONTENT_REMOVED, subobj);
+}
+
+/* The item of a child this table holds, found through the child. */
+static Table_Item *
+_item_owned(Efl_Ui_Table *obj, Efl_Gfx_Entity *subobj)
+{
+   Table_Item *gi = efl_key_data_get(subobj, TABLE_ITEM_KEY);
+
+   return (gi && (gi->table == obj)) ? gi : NULL;
+}
+
+static Eina_Bool
+_item_remove(Efl_Ui_Table *obj, Efl_Ui_Table_Data *pd, Table_Item *gi)
+{
+   Efl_Gfx_Entity *subobj = gi->object;
+
+   if (!subobj || !_elm_widget_sub_object_redirect_to_top(obj, subobj))
+     return EINA_FALSE;
+
+   /* Moving the child to the top widget makes the table hear of it through
+      widget_sub_object_del, which releases it already. */
+   gi = _item_owned(obj, subobj);
+   if (gi) _item_release(obj, pd, gi);
 
    return EINA_TRUE;
 }
 
+/* A child deleted while something else still references it is gone from the
+   table now, not at the last unref. */
+static void
+_on_child_invalidate(void *data, const Efl_Event *event)
+{
+   Eo *table = data;
+   EFL_UI_TABLE_DATA_GET(table, pd);
+   Table_Item *gi = _item_owned(table, event->object);
+
+   if (gi) _item_release(table, pd, gi);
+}
+
+/* A child that another container takes is no longer ours, whatever it
+   was told. */
+EOLIAN static Eina_Bool
+_efl_ui_table_efl_ui_widget_widget_sub_object_del(Eo *obj, Efl_Ui_Table_Data *pd, Efl_Gfx_Entity *sobj)
+{
+   Eina_Bool ok = efl_ui_widget_sub_object_del(efl_super(obj, MY_CLASS), sobj);
+   Table_Item *gi = ok ? _item_owned(obj, sobj) : NULL;
+
+   if (gi) _item_release(obj, pd, gi);
+   return ok;
+}
+
 EOLIAN static Eina_Bool
 _efl_ui_table_efl_pack_unpack(Eo *obj, Efl_Ui_Table_Data *pd, Efl_Gfx_Entity *subobj)
 {
@@ -559,12 +584,16 @@ _efl_ui_table_efl_pack_pack_clear(Eo *obj, Efl_Ui_Table_Data *pd)
 
    EINA_INLIST_FREE(EINA_INLIST_GET(pd->items), gi)
      {
-        efl_event_callback_array_del(gi->object, efl_ui_table_callbacks(), obj);
-        efl_del(gi->object);
+        Efl_Gfx_Entity *subobj = gi->object;
 
+        /* The item is gone before the child is deleted, as deleting it
+           makes the table hear of it through widget_sub_object_del. */
         pd->items = (Table_Item *)
             eina_inlist_remove(EINA_INLIST_GET(pd->items), EINA_INLIST_GET(gi));
         free(gi);
+        efl_key_data_set(subobj, TABLE_ITEM_KEY, NULL);
+        efl_event_callback_array_del(subobj, efl_ui_table_callbacks(), obj);
+        efl_del(subobj);
      }
 
    pd->linear_recalc = EINA_TRUE;
diff --git a/src/lib/elementary/efl_ui_table.eo b/src/lib/elementary/efl_ui_table.eo
index c72a3a0a19..cc579e5ec5 100644
--- a/src/lib/elementary/efl_ui_table.eo
+++ b/src/lib/elementary/efl_ui_table.eo
@@ -37,6 +37,7 @@ class Efl.Ui.Table extends Efl.Ui.Widget implements Efl.Pack_Table, Efl.Pack_Lay
       Efl.Canvas.Group.group_calculate;
       Efl.Gfx.Entity.position { set; }
       Efl.Gfx.Entity.size { set; }
+      Efl.Ui.Widget.widget_sub_object_del;
       Efl.Container.content_iterate;
       Efl.Container.content_count;
       Efl.Ui.Layout_Orientable.orientation { get; set; }
diff --git a/src/lib/elementary/efl_ui_table_private.h b/src/lib/elementary/efl_ui_table_private.h
index 5b24e046fb..dc3f290133 100644
--- a/src/lib/elementary/efl_ui_table_private.h
+++ b/src/lib/elementary/efl_ui_table_private.h
@@ -23,6 +23,7 @@ struct _Table_Item
    EINA_INLIST;
 
    Efl_Gfx_Entity *object;
+   Eo *table; // the table holding it
    int col_span, row_span;
    int col, row;
 };
diff --git a/src/tests/elementary/efl_ui_test_box.c b/src/tests/elementary/efl_ui_test_box.c
index eb5f18f143..0d393b7aec 100644
--- a/src/tests/elementary/efl_ui_test_box.c
+++ b/src/tests/elementary/efl_ui_test_box.c
@@ -580,6 +580,311 @@ EFL_START_TEST (efl_ui_box_focus_order)
 }
 EFL_END_TEST
 
+static int
+_iterated(Eo *container, Eo *wanted)
+{
+   Eina_Iterator *it = efl_content_iterate(container);
+   Eo *child;
+   int n = 0;
+
+   EINA_ITERATOR_FOREACH(it, child)
+     {
+        if (child == wanted) n++;
+     }
+   eina_iterator_free(it);
+   return n;
+}
+
+static void
+_removed_cb(void *data, const Efl_Event *ev EINA_UNUSED)
+{
+   (*(int *)data)++;
+}
+
+static Eo *
+_mover(Eo *parent)
+{
+   Eo *m = efl_add(EFL_UI_BUTTON_CLASS, parent);
+
+   efl_gfx_hint_size_min_set(m, EINA_SIZE2D(20, 20));
+   return m;
+}
+
+static void
+_calculate(Eo *container, int x, int y)
+{
+   efl_gfx_entity_geometry_set(container, EINA_RECT(x, y, 100, 100));
+   efl_canvas_group_calculate(container);
+}
+
+typedef enum
+{
+   TAKEN_BY_BOX,
+   TAKEN_AS_CONTENT,
+   TAKEN_AS_SUB_OBJECT
+} Taker_Kind;
+
+/* What takes the child from the box: another box, a frame as its content,
+   or a widget adopting it as a sub object. */
+static Eo *
+_taker_add(Taker_Kind kind)
+{
+   switch (kind)
+     {
+      case TAKEN_BY_BOX: return efl_add(EFL_UI_BOX_CLASS, win);
+      case TAKEN_AS_CONTENT: return efl_add(EFL_UI_FRAME_CLASS, win);
+      default: return efl_add(EFL_UI_LAYOUT_CLASS, win);
+     }
+}
+
+static void
+_taken_by(Taker_Kind kind, Eo *taker, Eo *child)
+{
+   switch (kind)
+     {
+      case TAKEN_BY_BOX:
+         ck_assert(efl_pack_end(taker, child));
+         break;
+      case TAKEN_AS_CONTENT:
+         ck_assert(efl_content_set(taker, child));
+         break;
+      default:
+         ck_assert(efl_ui_widget_sub_object_add(taker, child));
+         break;
+     }
+}
+
+static void
+_box_child_taken(Taker_Kind kind)
+{
+   Eo *first = _mover(win), *moved = _mover(win), *last = _mover(win);
+   Eo *taker;
+   int removed = 0;
+
+   taker = _taker_add(kind);
+
+   ck_assert(efl_pack_end(layout, first));
+   ck_assert(efl_pack_end(layout, moved));
+   ck_assert(efl_pack_end(layout, last));
+   efl_event_callback_add(layout, EFL_CONTAINER_EVENT_CONTENT_REMOVED, _removed_cb, &removed);
+   _calculate(layout, 0, 0);
+
+   _taken_by(kind, taker, moved);
+   _calculate(taker, 300, 300);
+   _calculate(layout, 0, 0);
+
+   ck_assert_int_eq(efl_content_count(layout), 2);
+   ck_assert_int_eq(_iterated(layout, moved), 0);
+   ck_assert_int_eq(_iterated(layout, first), 1);
+   ck_assert_int_eq(_iterated(layout, last), 1);
+   ck_assert_ptr_eq(efl_pack_content_get(layout, 1), last);
+   ck_assert_int_eq(efl_pack_index_get(layout, moved), -1);
+   ck_assert_int_eq(removed, 1);
+   ck_assert_ptr_ne(efl_canvas_object_render_parent_get(moved), layout);
+   /* a plain widget parent places nothing: the old box must not either */
+   if (kind == TAKEN_AS_SUB_OBJECT) efl_gfx_entity_position_set(moved, EINA_POSITION2D(300, 300));
+   _calculate(layout, 0, 0);
+   ck_assert_int_ge(efl_gfx_entity_position_get(moved).x, 300);
+   ck_assert_int_ge(efl_gfx_entity_position_get(moved).y, 300);
+
+   /* deleting the old box leaves what it lost alone */
+   efl_del(layout);
+   layout = NULL;
+   ck_assert_int_eq(removed, 1);
+   ck_assert(!efl_invalidated_get(moved));
+   ck_assert(efl_invalidated_get(first));
+   ck_assert(efl_invalidated_get(last));
+   _calculate(taker, 300, 300);
+   ck_assert_int_ge(efl_gfx_entity_position_get(moved).x, 300);
+
+   /* and the new container is the one to delete it */
+   efl_del(taker);
+   ck_assert(efl_invalidated_get(moved));
+}
+
+EFL_START_TEST (efl_ui_box_child_taken_by_another_box)
+{
+   _box_child_taken(TAKEN_BY_BOX);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_box_child_taken_as_content)
+{
+   _box_child_taken(TAKEN_AS_CONTENT);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_box_child_taken_as_sub_object)
+{
+   _box_child_taken(TAKEN_AS_SUB_OBJECT);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_box_child_deleted_after_being_taken)
+{
+   Eo *moved = _mover(win);
+   Eo *other = efl_add(EFL_UI_BOX_CLASS, win);
+
+   ck_assert(efl_pack_end(layout, moved));
+   ck_assert(efl_pack_end(other, moved));
+   efl_del(moved);
+   _calculate(layout, 0, 0);
+   _calculate(other, 100, 100);
+   ck_assert_int_eq(efl_content_count(layout), 0);
+   ck_assert_int_eq(efl_content_count(other), 0);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_box_child_deleted_but_referenced)
+{
+   Eo *kept = _mover(win), *dead = _mover(win);
+
+   ck_assert(efl_pack_end(layout, kept));
+   ck_assert(efl_pack_end(layout, dead));
+   efl_ref(dead);
+   efl_del(dead);
+   ck_assert_int_eq(efl_content_count(layout), 1);
+   ck_assert_int_eq(_iterated(layout, dead), 0);
+   ck_assert_ptr_eq(efl_pack_content_get(layout, 0), kept);
+   efl_unref(dead);
+}
+EFL_END_TEST
+
+/* A radio another container takes leaves the group of the radio box. */
+EFL_START_TEST (efl_ui_box_radio_taken_leaves_the_group)
+{
+   Eo *radios = efl_add(EFL_UI_RADIO_BOX_CLASS, win);
+   Eo *other = efl_add(EFL_UI_RADIO_BOX_CLASS, win);
+   Eo *r1 = efl_add(EFL_UI_RADIO_CLASS, win, efl_ui_radio_state_value_set(efl_added, 1));
+   Eo *r2 = efl_add(EFL_UI_RADIO_CLASS, win, efl_ui_radio_state_value_set(efl_added, 2));
+
+   ck_assert(efl_pack_end(radios, r1));
+   ck_assert(efl_pack_end(radios, r2));
+   efl_ui_selectable_selected_set(r1, EINA_TRUE);
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radios), 1);
+
+   /* taken by another box with its own group: it joins that one */
+   ck_assert(efl_pack_end(other, r1));
+   ck_assert_int_eq(efl_content_count(radios), 1);
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radios), -1);
+   efl_ui_selectable_selected_set(r2, EINA_TRUE);
+   ck_assert(!efl_ui_selectable_selected_get(r1));
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radios), 2);
+   efl_ui_selectable_selected_set(r1, EINA_TRUE);
+   ck_assert(efl_ui_selectable_selected_get(r2));
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radios), 2);
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(other), 1);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_box_radio_taken_by_a_frame_leaves_the_group)
+{
+   Eo *radios = efl_add(EFL_UI_RADIO_BOX_CLASS, win);
+   Eo *frame = efl_add(EFL_UI_FRAME_CLASS, win);
+   Eo *r1 = efl_add(EFL_UI_RADIO_CLASS, win, efl_ui_radio_state_value_set(efl_added, 1));
+   Eo *r2 = efl_add(EFL_UI_RADIO_CLASS, win, efl_ui_radio_state_value_set(efl_added, 2));
+
+   ck_assert(efl_pack_end(radios, r1));
+   ck_assert(efl_pack_end(radios, r2));
+   efl_ui_selectable_selected_set(r1, EINA_TRUE);
+
+   ck_assert(efl_content_set(frame, r1));
+   ck_assert_int_eq(efl_content_count(radios), 1);
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radios), -1);
+   efl_ui_selectable_selected_set(r2, EINA_TRUE);
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radios), 2);
+   efl_ui_selectable_selected_set(r1, EINA_TRUE);
+   ck_assert(efl_ui_selectable_selected_get(r2));
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radios), 2);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_box_radio_failed_pack_keeps_the_group)
+{
+   Eo *a = efl_add(EFL_UI_RADIO_BOX_CLASS, win);
+   Eo *b = efl_add(EFL_UI_RADIO_BOX_CLASS, win);
+   Eo *r1 = efl_add(EFL_UI_RADIO_CLASS, win, efl_ui_radio_state_value_set(efl_added, 1));
+   Eo *r2 = efl_add(EFL_UI_RADIO_CLASS, win, efl_ui_radio_state_value_set(efl_added, 2));
+   Eo *stranger = _mover(win);
+
+   ck_assert(efl_pack_end(a, r1));
+   ck_assert(efl_pack_end(a, r2));
+
+   /* the anchor is not a child of b: nothing happens */
+   EXPECT_ERROR_START;
+   ck_assert(!efl_pack_before(b, r1, stranger));
+   EXPECT_ERROR_END;
+   ck_assert_int_eq(efl_content_count(a), 2);
+   efl_ui_selectable_selected_set(r1, EINA_TRUE);
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(a), 1);
+   efl_ui_selectable_selected_set(r2, EINA_TRUE);
+   ck_assert(!efl_ui_selectable_selected_get(r1));
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(a), 2);
+
+   /* packing it again where it is stays in the group */
+   EXPECT_ERROR_START;
+   ck_assert(!efl_pack_end(a, r1));
+   EXPECT_ERROR_END;
+   efl_ui_selectable_selected_set(r1, EINA_TRUE);
+   ck_assert(!efl_ui_selectable_selected_get(r2));
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(a), 1);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_box_radio_fallback_taken_leaves_the_group)
+{
+   Eo *a = efl_add(EFL_UI_RADIO_BOX_CLASS, win);
+   Eo *b = efl_add(EFL_UI_RADIO_BOX_CLASS, win);
+   Eo *r1 = efl_add(EFL_UI_RADIO_CLASS, win, efl_ui_radio_state_value_set(efl_added, 1));
+   Eo *r2 = efl_add(EFL_UI_RADIO_CLASS, win, efl_ui_radio_state_value_set(efl_added, 2));
+
+   ck_assert(efl_pack_end(a, r1));
+   ck_assert(efl_pack_end(a, r2));
+   efl_ui_selectable_fallback_selection_set(a, r1);
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(a), 1);
+
+   ck_assert(efl_pack_end(b, r1));
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(a), -1);
+   ck_assert_ptr_eq(efl_ui_selectable_fallback_selection_get(a), NULL);
+   efl_ui_selectable_selected_set(r2, EINA_TRUE);
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(a), 2);
+   efl_ui_selectable_selected_set(r2, EINA_FALSE);
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(a), -1);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_box_unpack_and_pack_back)
+{
+   Eo *a = _mover(win), *b = _mover(win);
+   int removed = 0;
+
+   ck_assert(efl_pack_end(layout, a));
+   ck_assert(efl_pack_end(layout, b));
+   efl_event_callback_add(layout, EFL_CONTAINER_EVENT_CONTENT_REMOVED, _removed_cb, &removed);
+
+   ck_assert(efl_pack_unpack(layout, a));
+   ck_assert_int_eq(removed, 1);
+   ck_assert_int_eq(efl_content_count(layout), 1);
+   ck_assert_int_eq(_iterated(layout, a), 0);
+   ck_assert(efl_pack_begin(layout, a));
+   ck_assert_int_eq(efl_content_count(layout), 2);
+   ck_assert_ptr_eq(efl_pack_content_get(layout, 0), a);
+
+   ck_assert(efl_pack_unpack_all(layout));
+   ck_assert_int_eq(removed, 3);
+   ck_assert_int_eq(efl_content_count(layout), 0);
+   ck_assert(!efl_invalidated_get(a));
+   ck_assert(!efl_invalidated_get(b));
+   ck_assert(efl_pack_end(layout, a));
+   ck_assert(efl_pack_end(layout, b));
+
+   ck_assert(efl_pack_clear(layout));
+   ck_assert_int_eq(efl_content_count(layout), 0);
+   ck_assert(efl_invalidated_get(a));
+   ck_assert(efl_invalidated_get(b));
+}
+EFL_END_TEST
+
 void efl_ui_test_box(TCase *tc)
 {
    tcase_add_checked_fixture(tc, layout_setup, NULL);
@@ -591,4 +896,14 @@ void efl_ui_test_box(TCase *tc)
    tcase_add_test(tc, efl_ui_box_properties);
    tcase_add_test(tc, efl_ui_box_internal);
    tcase_add_test(tc, efl_ui_box_focus_order);
+   tcase_add_test(tc, efl_ui_box_child_taken_by_another_box);
+   tcase_add_test(tc, efl_ui_box_child_taken_as_content);
+   tcase_add_test(tc, efl_ui_box_child_taken_as_sub_object);
+   tcase_add_test(tc, efl_ui_box_child_deleted_after_being_taken);
+   tcase_add_test(tc, efl_ui_box_child_deleted_but_referenced);
+   tcase_add_test(tc, efl_ui_box_radio_taken_leaves_the_group);
+   tcase_add_test(tc, efl_ui_box_radio_taken_by_a_frame_leaves_the_group);
+   tcase_add_test(tc, efl_ui_box_radio_failed_pack_keeps_the_group);
+   tcase_add_test(tc, efl_ui_box_radio_fallback_taken_leaves_the_group);
+   tcase_add_test(tc, efl_ui_box_unpack_and_pack_back);
 }
diff --git a/src/tests/elementary/efl_ui_test_table.c b/src/tests/elementary/efl_ui_test_table.c
index 83fe2dbb27..e2fdb1fb50 100644
--- a/src/tests/elementary/efl_ui_test_table.c
+++ b/src/tests/elementary/efl_ui_test_table.c
@@ -537,6 +537,219 @@ EFL_START_TEST (efl_ui_table_properties)
 }
 EFL_END_TEST
 
+static int
+_iterated(Eo *container, Eo *wanted)
+{
+   Eina_Iterator *it = efl_content_iterate(container);
+   Eo *child;
+   int n = 0;
+
+   EINA_ITERATOR_FOREACH(it, child)
+     {
+        if (child == wanted) n++;
+     }
+   eina_iterator_free(it);
+   return n;
+}
+
+static void
+_removed_cb(void *data, const Efl_Event *ev EINA_UNUSED)
+{
+   (*(int *)data)++;
+}
+
+static Eo *
+_mover(Eo *parent)
+{
+   Eo *m = efl_add(EFL_UI_BUTTON_CLASS, parent);
+
+   efl_gfx_hint_size_min_set(m, EINA_SIZE2D(20, 20));
+   return m;
+}
+
+static void
+_calculate(Eo *container, int x, int y)
+{
+   efl_gfx_entity_geometry_set(container, EINA_RECT(x, y, 100, 100));
+   efl_canvas_group_calculate(container);
+}
+
+typedef enum
+{
+   TAKEN_BY_BOX,
+   TAKEN_AS_CONTENT,
+   TAKEN_AS_SUB_OBJECT
+} Taker_Kind;
+
+static Eo *
+_taker_add(Taker_Kind kind)
+{
+   switch (kind)
+     {
+      case TAKEN_BY_BOX: return efl_add(EFL_UI_BOX_CLASS, win);
+      case TAKEN_AS_CONTENT: return efl_add(EFL_UI_FRAME_CLASS, win);
+      default: return efl_add(EFL_UI_LAYOUT_CLASS, win);
+     }
+}
+
+static void
+_taken_by(Taker_Kind kind, Eo *taker, Eo *child)
+{
+   switch (kind)
+     {
+      case TAKEN_BY_BOX:
+         ck_assert(efl_pack_end(taker, child));
+         break;
+      case TAKEN_AS_CONTENT:
+         ck_assert(efl_content_set(taker, child));
+         break;
+      default:
+         ck_assert(efl_ui_widget_sub_object_add(taker, child));
+         break;
+     }
+}
+
+static void
+_table_child_taken(Taker_Kind kind)
+{
+   Eo *first = _mover(win), *moved = _mover(win), *last = _mover(win);
+   Eo *taker;
+   Eo *found;
+   int removed = 0;
+
+   taker = _taker_add(kind);
+
+   ck_assert(efl_pack_table(layout, first, 0, 0, 1, 1));
+   ck_assert(efl_pack_table(layout, moved, 1, 0, 1, 1));
+   ck_assert(efl_pack_table(layout, last, 0, 1, 1, 1));
+   efl_event_callback_add(layout, EFL_CONTAINER_EVENT_CONTENT_REMOVED, _removed_cb, &removed);
+   _calculate(layout, 0, 0);
+
+   _taken_by(kind, taker, moved);
+   _calculate(taker, 300, 300);
+   _calculate(layout, 0, 0);
+
+   ck_assert_int_eq(efl_content_count(layout), 2);
+   ck_assert_int_eq(_iterated(layout, moved), 0);
+   ck_assert_int_eq(_iterated(layout, first), 1);
+   ck_assert_int_eq(_iterated(layout, last), 1);
+   found = efl_pack_table_content_get(layout, 1, 0);
+   ck_assert_ptr_eq(found, NULL);
+   ck_assert_int_eq(removed, 1);
+   /* a plain widget parent places nothing: the old table must not either */
+   if (kind == TAKEN_AS_SUB_OBJECT) efl_gfx_entity_position_set(moved, EINA_POSITION2D(300, 300));
+   _calculate(layout, 0, 0);
+   ck_assert_int_ge(efl_gfx_entity_position_get(moved).x, 300);
+   ck_assert_int_ge(efl_gfx_entity_position_get(moved).y, 300);
+
+   efl_del(layout);
+   layout = NULL;
+   ck_assert_int_eq(removed, 1);
+   ck_assert(!efl_invalidated_get(moved));
+   ck_assert(efl_invalidated_get(first));
+   ck_assert(efl_invalidated_get(last));
+   _calculate(taker, 300, 300);
+   ck_assert_int_ge(efl_gfx_entity_position_get(moved).x, 300);
+
+   efl_del(taker);
+   ck_assert(efl_invalidated_get(moved));
+}
+
+EFL_START_TEST (efl_ui_table_child_taken_by_a_box)
+{
+   _table_child_taken(TAKEN_BY_BOX);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_table_child_taken_as_content)
+{
+   _table_child_taken(TAKEN_AS_CONTENT);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_table_child_taken_as_sub_object)
+{
+   _table_child_taken(TAKEN_AS_SUB_OBJECT);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_table_child_deleted_after_being_taken)
+{
+   Eo *moved = _mover(win);
+   Eo *other = efl_add(EFL_UI_BOX_CLASS, win);
+
+   ck_assert(efl_pack_table(layout, moved, 0, 0, 1, 1));
+   ck_assert(efl_pack_end(other, moved));
+   efl_del(moved);
+   _calculate(layout, 0, 0);
+   _calculate(other, 100, 100);
+   ck_assert_int_eq(efl_content_count(layout), 0);
+   ck_assert_int_eq(efl_content_count(other), 0);
+}
+EFL_END_TEST
+
+/* A table does not take what another table holds, and says so. */
+EFL_START_TEST (efl_ui_table_child_of_another_table_is_refused)
+{
+   Eo *moved = _mover(win);
+   Eo *other = efl_add(EFL_UI_TABLE_CLASS, win);
+
+   ck_assert(efl_pack_table(layout, moved, 0, 0, 1, 1));
+   EXPECT_ERROR_START;
+   ck_assert(!efl_pack_table(other, moved, 0, 0, 1, 1));
+   EXPECT_ERROR_END;
+   ck_assert_int_eq(efl_content_count(layout), 1);
+   ck_assert_int_eq(efl_content_count(other), 0);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_table_child_deleted_but_referenced)
+{
+   Eo *kept = _mover(win), *dead = _mover(win);
+
+   ck_assert(efl_pack_table(layout, kept, 0, 0, 1, 1));
+   ck_assert(efl_pack_table(layout, dead, 1, 0, 1, 1));
+   efl_ref(dead);
+   efl_del(dead);
+   ck_assert_int_eq(efl_content_count(layout), 1);
+   ck_assert_int_eq(_iterated(layout, dead), 0);
+   ck_assert_ptr_eq(efl_pack_table_content_get(layout, 1, 0), NULL);
+   efl_unref(dead);
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_table_unpack_and_pack_back)
+{
+   Eo *a = _mover(win), *b = _mover(win);
+   int removed = 0;
+
+   ck_assert(efl_pack_table(layout, a, 0, 0, 1, 1));
+   ck_assert(efl_pack_table(layout, b, 1, 0, 1, 1));
+   efl_event_callback_add(layout, EFL_CONTAINER_EVENT_CONTENT_REMOVED, _removed_cb, &removed);
+
+   ck_assert(efl_pack_unpack(layout, a));
+   ck_assert_int_eq(removed, 1);
+   ck_assert_int_eq(efl_content_count(layout), 1);
+   ck_assert_int_eq(_iterated(layout, a), 0);
+   ck_assert(efl_pack_table(layout, a, 0, 0, 1, 1));
+   ck_assert_int_eq(efl_content_count(layout), 2);
+   ck_assert_ptr_eq(efl_pack_table_content_get(layout, 0, 0), a);
+
+   ck_assert(efl_pack_unpack_all(layout));
+   ck_assert_int_eq(removed, 3);
+   ck_assert_int_eq(efl_content_count(layout), 0);
+   ck_assert(!efl_invalidated_get(a));
+   ck_assert(!efl_invalidated_get(b));
+   ck_assert(efl_pack_table(layout, a, 0, 0, 1, 1));
+   ck_assert(efl_pack_table(layout, b, 1, 0, 1, 1));
+
+   ck_assert(efl_pack_clear(layout));
+   ck_assert_int_eq(efl_content_count(layout), 0);
+   ck_assert(efl_invalidated_get(a));
+   ck_assert(efl_invalidated_get(b));
+}
+EFL_END_TEST
+
 void efl_ui_test_table(TCase *tc)
 {
    tcase_add_checked_fixture(tc, layout_setup, NULL);
@@ -547,4 +760,11 @@ void efl_ui_test_table(TCase *tc)
    tcase_add_test(tc, efl_ui_table_layout_update_matrix);
    tcase_add_test(tc, efl_ui_table_pack_table);
    tcase_add_test(tc, efl_ui_table_properties);
+   tcase_add_test(tc, efl_ui_table_child_taken_by_a_box);
+   tcase_add_test(tc, efl_ui_table_child_taken_as_content);
+   tcase_add_test(tc, efl_ui_table_child_taken_as_sub_object);
+   tcase_add_test(tc, efl_ui_table_child_deleted_after_being_taken);
+   tcase_add_test(tc, efl_ui_table_child_of_another_table_is_refused);
+   tcase_add_test(tc, efl_ui_table_child_deleted_but_referenced);
+   tcase_add_test(tc, efl_ui_table_unpack_and_pack_back);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to