summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-07-11 10:56:51 -0700
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-17 21:57:52 +0200
commitc0e7b1343c6407b040b2d137a675f91ff7574b8d (patch)
treea0e54762d827d4fb91e7f60ec081dd48cd12ddb1
parent2d481d859354205465db2ba3df07d2bcfcbd7979 (diff)
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.c86
-rw-r--r--src/lib/elementary/efl_ui_layout_base.eo2
-rw-r--r--src/lib/elementary/elm_widget_layout.h2
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)
2225 pd->connect.factories = eina_hash_stringshared_new(EINA_FREE_CB(_efl_ui_layout_factory_free)); // Hash of property triggering a content creation 2225 pd->connect.factories = eina_hash_stringshared_new(EINA_FREE_CB(_efl_ui_layout_factory_free)); // Hash of property triggering a content creation
2226} 2226}
2227 2227
2228EOLIAN static void 2228
2229_efl_ui_layout_base_efl_ui_view_model_set(Eo *obj, Efl_Ui_Layout_Data *pd, Efl_Model *model) 2229static void
2230_efl_ui_layout_base_model_unregister(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Data *pd,
2231 Efl_Model *model)
2232{
2233 if (!model) return ;
2234 if (!pd->model_bound) return ;
2235
2236 efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
2237 _efl_model_properties_changed_cb, pd);
2238
2239 pd->model_bound = EINA_FALSE;
2240}
2241
2242static void
2243_efl_ui_layout_base_model_register(Eo *obj, Efl_Ui_Layout_Data *pd,
2244 Efl_Model *model)
2230{ 2245{
2231 Eina_Stringshare *key; 2246 Eina_Stringshare *key;
2232 Eina_Hash_Tuple *tuple; 2247 Eina_Hash_Tuple *tuple;
2233 Eina_Iterator *it; 2248 Eina_Iterator *it;
2234 Efl_Model *setted;
2235 2249
2236 setted = efl_ui_view_model_get(obj); 2250 if (!model) return ;
2237 if (setted) 2251 if (pd->model_bound) return;
2238 efl_event_callback_del(setted, EFL_MODEL_EVENT_PROPERTIES_CHANGED, 2252 pd->model_bound = EINA_TRUE;
2239 _efl_model_properties_changed_cb, pd);
2240 2253
2241 efl_ui_view_model_set(efl_super(obj, EFL_UI_LAYOUT_BASE_CLASS), model); 2254 efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
2242 2255 _efl_model_properties_changed_cb, pd);
2243 if (model)
2244 efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
2245 _efl_model_properties_changed_cb, pd);
2246 2256
2247 _efl_ui_layout_connect_hash(pd); 2257 _efl_ui_layout_connect_hash(pd);
2248 2258
@@ -2279,6 +2289,31 @@ _efl_ui_layout_base_efl_ui_view_model_set(Eo *obj, Efl_Ui_Layout_Data *pd, Efl_M
2279 _efl_ui_layout_view_model_update(pd); 2289 _efl_ui_layout_view_model_update(pd);
2280} 2290}
2281 2291
2292static void
2293_efl_ui_layout_base_model_update(void *data, const Efl_Event *event)
2294{
2295 Efl_Ui_Layout_Data *pd = data;
2296 Efl_Model_Changed_Event *ev = event->info;
2297
2298 _efl_ui_layout_base_model_unregister(event->object, pd, ev->previous);
2299 _efl_ui_layout_base_model_register(event->object, pd, ev->current);
2300}
2301
2302static void
2303_efl_ui_layout_base_model_watch(Eo *obj, Efl_Ui_Layout_Data *pd)
2304{
2305 Efl_Model *model;
2306
2307 if (pd->model_watch) return ;
2308 pd->model_watch = EINA_TRUE;
2309
2310 efl_event_callback_add(obj, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
2311 _efl_ui_layout_base_model_update, pd);
2312 model = efl_ui_view_model_get(obj);
2313 if (!model) return ;
2314 _efl_ui_layout_base_model_register(obj, pd, model);
2315}
2316
2282EOLIAN static Eina_Error 2317EOLIAN static Eina_Error
2283_efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Data *pd, const char *key, const char *property) 2318_efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Data *pd, const char *key, const char *property)
2284{ 2319{
@@ -2298,6 +2333,9 @@ _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Da
2298 if (!_elm_layout_part_aliasing_eval(obj, &key, EINA_TRUE)) 2333 if (!_elm_layout_part_aliasing_eval(obj, &key, EINA_TRUE))
2299 return EFL_PROPERTY_ERROR_INVALID_KEY; 2334 return EFL_PROPERTY_ERROR_INVALID_KEY;
2300 2335
2336 // Check if there is a model and register it
2337 _efl_ui_layout_base_model_watch(obj, pd);
2338
2301 _efl_ui_layout_connect_hash(pd); 2339 _efl_ui_layout_connect_hash(pd);
2302 2340
2303 sprop = eina_stringshare_add(property); 2341 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
2354 if (!_elm_layout_part_aliasing_eval(obj, &key, EINA_TRUE)) 2392 if (!_elm_layout_part_aliasing_eval(obj, &key, EINA_TRUE))
2355 return; 2393 return;
2356 2394
2395 // Check if there is a model and register it
2396 _efl_ui_layout_base_model_watch(obj, pd);
2397
2357 if (!pd->connect.factories) 2398 if (!pd->connect.factories)
2358 pd->connect.factories = eina_hash_stringshared_new(EINA_FREE_CB(_efl_ui_layout_factory_free)); 2399 pd->connect.factories = eina_hash_stringshared_new(EINA_FREE_CB(_efl_ui_layout_factory_free));
2359 2400
@@ -2421,6 +2462,27 @@ _efl_ui_layout_base_efl_object_finalize(Eo *obj, Efl_Ui_Layout_Data *pd EINA_UNU
2421 return eo; 2462 return eo;
2422} 2463}
2423 2464
2465static void
2466_efl_ui_layout_base_efl_object_invalidate(Eo *obj, Efl_Ui_Layout_Data *pd)
2467{
2468 if (pd->model_watch)
2469 {
2470 Efl_Model *model;
2471
2472 pd->model_watch = EINA_FALSE;
2473 efl_event_callback_del(obj, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
2474 _efl_ui_layout_base_model_update, pd);
2475
2476 model = efl_ui_view_model_get(obj);
2477 if (!model)
2478 {
2479 _efl_ui_layout_base_model_unregister(obj, pd, model);
2480 }
2481 }
2482
2483 efl_invalidate(efl_super(obj, EFL_UI_LAYOUT_BASE_CLASS));
2484}
2485
2424EOLIAN static void 2486EOLIAN static void
2425_efl_ui_layout_base_efl_layout_signal_message_send(Eo *obj, Efl_Ui_Layout_Data *pd EINA_UNUSED, int id, const Eina_Value msg) 2487_efl_ui_layout_base_efl_layout_signal_message_send(Eo *obj, Efl_Ui_Layout_Data *pd EINA_UNUSED, int id, const Eina_Value msg)
2426{ 2488{
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,
60 class.constructor; 60 class.constructor;
61 Efl.Object.constructor; 61 Efl.Object.constructor;
62 Efl.Object.finalize; 62 Efl.Object.finalize;
63 Efl.Object.invalidate;
63 Efl.Canvas.Group.group_calculate; 64 Efl.Canvas.Group.group_calculate;
64 Efl.Layout.Calc.calc_freeze; 65 Efl.Layout.Calc.calc_freeze;
65 Efl.Layout.Calc.calc_thaw; 66 Efl.Layout.Calc.calc_thaw;
@@ -86,7 +87,6 @@ abstract Efl.Ui.Layout_Base extends Efl.Ui.Widget implements Efl.Container,
86 Efl.Part.part_get; 87 Efl.Part.part_get;
87 Efl.Ui.Property_Bind.property_bind; 88 Efl.Ui.Property_Bind.property_bind;
88 Efl.Ui.Factory_Bind.factory_bind; 89 Efl.Ui.Factory_Bind.factory_bind;
89 Efl.Ui.View.model { set; }
90 } 90 }
91 events { 91 events {
92 theme,changed: void; [[Called when theme changed]] 92 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
71 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. */ 71 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. */
72 Eina_Bool file_set : 1; /**< This flag indicates if Efl.Ui.Layout source is set from a file*/ 72 Eina_Bool file_set : 1; /**< This flag indicates if Efl.Ui.Layout source is set from a file*/
73 Eina_Bool automatic_orientation_apply : 1; 73 Eina_Bool automatic_orientation_apply : 1;
74 Eina_Bool model_bound : 1; /**< Set to true once we are watching over a model*/
75 Eina_Bool model_watch : 1; /**< Set to true once we do watch for model change*/
74} Efl_Ui_Layout_Data; 76} Efl_Ui_Layout_Data;
75 77
76/** 78/**