diff options
author | Cedric BAIL <cedric.bail@free.fr> | 2019-07-11 10:56:51 -0700 |
---|---|---|
committer | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2019-07-17 21:57:52 +0200 |
commit | c0e7b1343c6407b040b2d137a675f91ff7574b8d (patch) | |
tree | a0e54762d827d4fb91e7f60ec081dd48cd12ddb1 | |
parent | 2d481d859354205465db2ba3df07d2bcfcbd7979 (diff) | |
download | efl-c0e7b1343c6407b040b2d137a675f91ff7574b8d.tar.gz |
elementary: Efl.Ui.Layout now rely on model change event to track the model.
This means that this will work nicely with model provider too.
Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de>
Differential Revision: https://phab.enlightenment.org/D9291
-rw-r--r-- | src/lib/elementary/efl_ui_layout.c | 86 | ||||
-rw-r--r-- | src/lib/elementary/efl_ui_layout_base.eo | 2 | ||||
-rw-r--r-- | src/lib/elementary/elm_widget_layout.h | 2 |
3 files changed, 77 insertions, 13 deletions
diff --git a/src/lib/elementary/efl_ui_layout.c b/src/lib/elementary/efl_ui_layout.c index 5547ae94bf..1390fc774f 100644 --- a/src/lib/elementary/efl_ui_layout.c +++ b/src/lib/elementary/efl_ui_layout.c @@ -2225,24 +2225,34 @@ _efl_ui_layout_connect_hash(Efl_Ui_Layout_Data *pd) pd->connect.factories = eina_hash_stringshared_new(EINA_FREE_CB(_efl_ui_layout_factory_free)); // Hash of property triggering a content creation } -EOLIAN static void -_efl_ui_layout_base_efl_ui_view_model_set(Eo *obj, Efl_Ui_Layout_Data *pd, Efl_Model *model) + +static void +_efl_ui_layout_base_model_unregister(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Data *pd, + Efl_Model *model) +{ + if (!model) return ; + if (!pd->model_bound) return ; + + efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, + _efl_model_properties_changed_cb, pd); + + pd->model_bound = EINA_FALSE; +} + +static void +_efl_ui_layout_base_model_register(Eo *obj, Efl_Ui_Layout_Data *pd, + Efl_Model *model) { Eina_Stringshare *key; Eina_Hash_Tuple *tuple; Eina_Iterator *it; - Efl_Model *setted; - setted = efl_ui_view_model_get(obj); - if (setted) - efl_event_callback_del(setted, EFL_MODEL_EVENT_PROPERTIES_CHANGED, - _efl_model_properties_changed_cb, pd); + if (!model) return ; + if (pd->model_bound) return; + pd->model_bound = EINA_TRUE; - efl_ui_view_model_set(efl_super(obj, EFL_UI_LAYOUT_BASE_CLASS), model); - - if (model) - efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, - _efl_model_properties_changed_cb, pd); + efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, + _efl_model_properties_changed_cb, pd); _efl_ui_layout_connect_hash(pd); @@ -2279,6 +2289,31 @@ _efl_ui_layout_base_efl_ui_view_model_set(Eo *obj, Efl_Ui_Layout_Data *pd, Efl_M _efl_ui_layout_view_model_update(pd); } +static void +_efl_ui_layout_base_model_update(void *data, const Efl_Event *event) +{ + Efl_Ui_Layout_Data *pd = data; + Efl_Model_Changed_Event *ev = event->info; + + _efl_ui_layout_base_model_unregister(event->object, pd, ev->previous); + _efl_ui_layout_base_model_register(event->object, pd, ev->current); +} + +static void +_efl_ui_layout_base_model_watch(Eo *obj, Efl_Ui_Layout_Data *pd) +{ + Efl_Model *model; + + if (pd->model_watch) return ; + pd->model_watch = EINA_TRUE; + + efl_event_callback_add(obj, EFL_UI_VIEW_EVENT_MODEL_CHANGED, + _efl_ui_layout_base_model_update, pd); + model = efl_ui_view_model_get(obj); + if (!model) return ; + _efl_ui_layout_base_model_register(obj, pd, model); +} + EOLIAN static Eina_Error _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Data *pd, const char *key, const char *property) { @@ -2298,6 +2333,9 @@ _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Da if (!_elm_layout_part_aliasing_eval(obj, &key, EINA_TRUE)) return EFL_PROPERTY_ERROR_INVALID_KEY; + // Check if there is a model and register it + _efl_ui_layout_base_model_watch(obj, pd); + _efl_ui_layout_connect_hash(pd); sprop = eina_stringshare_add(property); @@ -2354,6 +2392,9 @@ _efl_ui_layout_base_efl_ui_factory_bind_factory_bind(Eo *obj EINA_UNUSED, Efl_Ui if (!_elm_layout_part_aliasing_eval(obj, &key, EINA_TRUE)) return; + // Check if there is a model and register it + _efl_ui_layout_base_model_watch(obj, pd); + if (!pd->connect.factories) pd->connect.factories = eina_hash_stringshared_new(EINA_FREE_CB(_efl_ui_layout_factory_free)); @@ -2421,6 +2462,27 @@ _efl_ui_layout_base_efl_object_finalize(Eo *obj, Efl_Ui_Layout_Data *pd EINA_UNU return eo; } +static void +_efl_ui_layout_base_efl_object_invalidate(Eo *obj, Efl_Ui_Layout_Data *pd) +{ + if (pd->model_watch) + { + Efl_Model *model; + + pd->model_watch = EINA_FALSE; + efl_event_callback_del(obj, EFL_UI_VIEW_EVENT_MODEL_CHANGED, + _efl_ui_layout_base_model_update, pd); + + model = efl_ui_view_model_get(obj); + if (!model) + { + _efl_ui_layout_base_model_unregister(obj, pd, model); + } + } + + efl_invalidate(efl_super(obj, EFL_UI_LAYOUT_BASE_CLASS)); +} + EOLIAN static void _efl_ui_layout_base_efl_layout_signal_message_send(Eo *obj, Efl_Ui_Layout_Data *pd EINA_UNUSED, int id, const Eina_Value msg) { diff --git a/src/lib/elementary/efl_ui_layout_base.eo b/src/lib/elementary/efl_ui_layout_base.eo index 54a646c1bb..1266dcef85 100644 --- a/src/lib/elementary/efl_ui_layout_base.eo +++ b/src/lib/elementary/efl_ui_layout_base.eo @@ -60,6 +60,7 @@ abstract Efl.Ui.Layout_Base extends Efl.Ui.Widget implements Efl.Container, class.constructor; Efl.Object.constructor; Efl.Object.finalize; + Efl.Object.invalidate; Efl.Canvas.Group.group_calculate; Efl.Layout.Calc.calc_freeze; Efl.Layout.Calc.calc_thaw; @@ -86,7 +87,6 @@ abstract Efl.Ui.Layout_Base extends Efl.Ui.Widget implements Efl.Container, Efl.Part.part_get; Efl.Ui.Property_Bind.property_bind; Efl.Ui.Factory_Bind.factory_bind; - Efl.Ui.View.model { set; } } events { theme,changed: void; [[Called when theme changed]] diff --git a/src/lib/elementary/elm_widget_layout.h b/src/lib/elementary/elm_widget_layout.h index 4fda71cdba..d8de1d4bde 100644 --- a/src/lib/elementary/elm_widget_layout.h +++ b/src/lib/elementary/elm_widget_layout.h @@ -71,6 +71,8 @@ typedef struct _Elm_Layout_Smart_Data Eina_Bool destructed_is : 1; /**< This flag indicates if Efl.Ui.Layout destructor was called. This is needed to avoid unnecessary calculation of subobject deletion during layout object's deletion. */ Eina_Bool file_set : 1; /**< This flag indicates if Efl.Ui.Layout source is set from a file*/ Eina_Bool automatic_orientation_apply : 1; + Eina_Bool model_bound : 1; /**< Set to true once we are watching over a model*/ + Eina_Bool model_watch : 1; /**< Set to true once we do watch for model change*/ } Efl_Ui_Layout_Data; /** |