efl_ui: add a internal flag to mark widgets internal

when a widget is marked internal, widgets can use that to behave in
certain ways. Box for example uses this to not alter the widget_parent
property anymore. Which is usefull for when boxes are used internally.

Reviewed-by: Cedric BAIL <cedric.bail@free.fr>
Differential Revision: https://phab.enlightenment.org/D8736
This commit is contained in:
Marcel Hollerbach 2019-04-26 14:16:30 +02:00
parent b376391078
commit 4f0ce2c58c
5 changed files with 54 additions and 3 deletions

View File

@ -52,8 +52,11 @@ _efl_ui_box_child_register(Eo *obj, Efl_Ui_Box_Data *pd, Efl_Gfx_Entity *subobj)
return EINA_FALSE;
}
if (!efl_ui_widget_sub_object_add(obj, subobj))
return EINA_FALSE;
if (!efl_ui_widget_internal_get(obj))
{
if (!efl_ui_widget_sub_object_add(obj, subobj))
return EINA_FALSE;
}
efl_key_data_set(subobj, "_elm_leaveme", obj);
efl_canvas_group_member_add(obj, subobj);
@ -74,9 +77,16 @@ _efl_ui_box_child_unregister(Eo *obj, Efl_Ui_Box_Data *pd EINA_UNUSED, Efl_Gfx_E
ERR("subobj %p %s is not part of this widget", subobj, efl_class_name_get(subobj) );
return EINA_FALSE;
}
if (!subobj || !_elm_widget_sub_object_redirect_to_top(obj, subobj))
if (!subobj)
return EINA_FALSE;
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);

View File

@ -5850,6 +5850,24 @@ _efl_ui_widget_efl_object_invalidate(Eo *obj, Efl_Ui_Widget_Data *pd)
#include "efl_ui_widget_part_bg.eo.c"
EAPI void
efl_ui_widget_internal_set(Eo *obj, Eina_Bool b)
{
ELM_WIDGET_DATA_GET(obj, pd);
EINA_SAFETY_ON_NULL_RETURN(pd);
pd->internal = b;
}
EAPI Eina_Bool
efl_ui_widget_internal_get(Eo *obj)
{
ELM_WIDGET_DATA_GET(obj, pd);
EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
return pd->internal;
}
/* Efl.Part Bg end */

View File

@ -1022,4 +1022,13 @@ void legacy_object_focus_handle(Efl_Ui_Focus_Object *object);
void _efl_ui_focus_event_redirector(Efl_Ui_Focus_Object *obj, Efl_Ui_Focus_Object *goal);
/**
* With this flag you can indicate that this widget is used internally.
* Indicating that a widget is internal, can be used by the implementing widget, that the parent property of the added sub-object should not be adjusted or altered.
* There is no direct promise that any widget behaves like the above, every case should be handchecked.
*/
void efl_ui_widget_internal_set(Eo *obj, Eina_Bool internal);
Eina_Bool efl_ui_widget_internal_get(Eo *obj);
#endif

View File

@ -410,6 +410,7 @@ typedef struct _Elm_Widget_Smart_Data
Eina_Bool on_destroy: 1; /**< This is true when the widget is on destruction(general widget destructor). */
Eina_Bool provider_lookup : 1; /**< This is true when efl_provider_find is currently walking the tree */
Eina_Bool has_shadow : 1;
Eina_Bool internal : 1;
} Elm_Widget_Smart_Data;
typedef Elm_Widget_Smart_Data Efl_Ui_Widget_Data;

View File

@ -5,6 +5,7 @@
#include <Efl_Ui.h>
#include <Elementary.h>
#include "elm_suite.h"
#include "elm_priv.h"
#define COORD_EQ(a, b) (!!(abs(a - b) < 2))
#define GEOMETRY_EQ(a, b) (COORD_EQ(a.x, b.x) && COORD_EQ(a.y, b.y) && \
@ -551,6 +552,17 @@ EFL_START_TEST (efl_ui_box_properties)
}
EFL_END_TEST
EFL_START_TEST (efl_ui_box_internal)
{
Efl_Ui_Widget *w = efl_add(EFL_UI_BUTTON_CLASS, win);
efl_ui_widget_internal_set(layout, EINA_TRUE);
ck_assert_ptr_eq(efl_ui_widget_parent_get(w), win);
efl_pack(layout, w);
ck_assert_ptr_eq(efl_ui_widget_parent_get(w), win);
}
EFL_END_TEST
void efl_ui_test_box(TCase *tc)
{
tcase_add_checked_fixture(tc, layout_setup, layout_teardown);
@ -560,4 +572,5 @@ void efl_ui_test_box(TCase *tc)
tcase_add_test(tc, efl_ui_box_size);
tcase_add_test(tc, efl_ui_box_pack_unpack);
tcase_add_test(tc, efl_ui_box_properties);
tcase_add_test(tc, efl_ui_box_internal);
}