summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-02-12 11:55:50 -0800
committerCedric BAIL <cedric.bail@free.fr>2019-03-08 14:31:03 -0800
commit4e1c26d04714acf60f8b29d0c65ba09a9b94f727 (patch)
tree116ebadf3506c135442116253d155aad7edf197d
parente7afae9a8b7ca3fc3c65b1e4d541eb6f1788bfe5 (diff)
elementary: rely on Efl.Ui.Widget to do more of property binding for MVVM in Efl.Ui.Layout.
Reviewed-by: Vitor Sousa da Silva <vitorsousa@expertisesolutions.com.br> Differential Revision: https://phab.enlightenment.org/D7943
-rw-r--r--src/lib/elementary/efl_ui_layout.c61
-rw-r--r--src/lib/elementary/efl_ui_layout_base.eo4
-rw-r--r--src/lib/elementary/elm_widget_layout.h1
3 files changed, 38 insertions, 28 deletions
diff --git a/src/lib/elementary/efl_ui_layout.c b/src/lib/elementary/efl_ui_layout.c
index 67c9a59de4..cdb945e203 100644
--- a/src/lib/elementary/efl_ui_layout.c
+++ b/src/lib/elementary/efl_ui_layout.c
@@ -758,6 +758,7 @@ _efl_ui_layout_base_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Layout_Data *sd)
758 Edje_Signal_Data *esd; 758 Edje_Signal_Data *esd;
759 Evas_Object *child; 759 Evas_Object *child;
760 Eina_List *l; 760 Eina_List *l;
761 Efl_Model *model;
761 762
762 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); 763 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
763 764
@@ -782,12 +783,11 @@ _efl_ui_layout_base_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Layout_Data *sd)
782 free(esd); 783 free(esd);
783 } 784 }
784 785
785 if(sd->connect.model) 786 model = efl_ui_view_model_get(obj);
787 if(model)
786 { 788 {
787 efl_event_callback_del(sd->connect.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, 789 efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
788 _efl_model_properties_changed_cb, sd); 790 _efl_model_properties_changed_cb, sd);
789 efl_unref(sd->connect.model);
790 sd->connect.model = NULL;
791 } 791 }
792 792
793 eina_hash_free(sd->connect.properties); 793 eina_hash_free(sd->connect.properties);
@@ -1236,6 +1236,7 @@ _efl_ui_layout_text_generic_set(Eo *obj, Efl_Ui_Layout_Data *sd, const char *par
1236 1236
1237 Efl_Ui_Layout_Sub_Object_Data *sub_d = NULL; 1237 Efl_Ui_Layout_Sub_Object_Data *sub_d = NULL;
1238 Eina_List *l; 1238 Eina_List *l;
1239 Efl_Model *model;
1239 1240
1240 EINA_LIST_FOREACH(sd->subs, l, sub_d) 1241 EINA_LIST_FOREACH(sd->subs, l, sub_d)
1241 { 1242 {
@@ -1292,7 +1293,8 @@ _efl_ui_layout_text_generic_set(Eo *obj, Efl_Ui_Layout_Data *sd, const char *par
1292 sub_d->obj = _elm_access_edje_object_part_object_register 1293 sub_d->obj = _elm_access_edje_object_part_object_register
1293 (obj, elm_layout_edje_get(obj), part); 1294 (obj, elm_layout_edje_get(obj), part);
1294 1295
1295 if (sd->connect.model && !sd->connect.updating) 1296 model = efl_ui_view_model_get(obj);
1297 if (model && !sd->connect.updating)
1296 { 1298 {
1297 char *property = eina_hash_find(sd->connect.properties, sub_d->part); 1299 char *property = eina_hash_find(sd->connect.properties, sub_d->part);
1298 1300
@@ -1303,7 +1305,7 @@ _efl_ui_layout_text_generic_set(Eo *obj, Efl_Ui_Layout_Data *sd, const char *par
1303 eina_value_setup(&v, EINA_VALUE_TYPE_STRING); 1305 eina_value_setup(&v, EINA_VALUE_TYPE_STRING);
1304 eina_value_set(&v, text); 1306 eina_value_set(&v, text);
1305 1307
1306 efl_model_property_set(sd->connect.model, property, &v); 1308 efl_model_property_set(model, property, &v);
1307 } 1309 }
1308 } 1310 }
1309 1311
@@ -1978,8 +1980,10 @@ _efl_ui_layout_view_model_property_update(Efl_Ui_Layout_Data *pd, const char *pa
1978{ 1980{
1979 Eina_Value *v = NULL; 1981 Eina_Value *v = NULL;
1980 char *value = NULL; 1982 char *value = NULL;
1983 Efl_Model *model;
1981 1984
1982 v = efl_model_property_get(pd->connect.model, fetch); 1985 model = efl_ui_view_model_get(pd->obj);
1986 v = efl_model_property_get(model, fetch);
1983 if (!v) return; 1987 if (!v) return;
1984 1988
1985 if (eina_value_type_get(v) != EINA_VALUE_TYPE_ERROR) 1989 if (eina_value_type_get(v) != EINA_VALUE_TYPE_ERROR)
@@ -1999,10 +2003,12 @@ _efl_ui_layout_view_model_signal_update(Efl_Ui_Layout_Data *pd, const char *sign
1999 Eina_Value *v = NULL; 2003 Eina_Value *v = NULL;
2000 Eina_Strbuf *buf; 2004 Eina_Strbuf *buf;
2001 char *value = NULL; 2005 char *value = NULL;
2006 Efl_Model *model;
2002 Eina_Bool eval = EINA_FALSE; 2007 Eina_Bool eval = EINA_FALSE;
2003 Eina_Bool is_bool = EINA_FALSE; 2008 Eina_Bool is_bool = EINA_FALSE;
2004 2009
2005 v = efl_model_property_get(pd->connect.model, fetch); 2010 model = efl_ui_view_model_get(pd->obj);
2011 v = efl_model_property_get(model, fetch);
2006 if (!v) return; 2012 if (!v) return;
2007 2013
2008 if (eina_value_type_get(v) == EINA_VALUE_TYPE_ERROR) 2014 if (eina_value_type_get(v) == EINA_VALUE_TYPE_ERROR)
@@ -2112,6 +2118,7 @@ _efl_ui_layout_view_model_content_update(Efl_Ui_Layout_Data *pd, Efl_Ui_Layout_F
2112{ 2118{
2113 Efl_Ui_Layout_Factory_Request *request = calloc(1, sizeof (Efl_Ui_Layout_Factory_Request)); 2119 Efl_Ui_Layout_Factory_Request *request = calloc(1, sizeof (Efl_Ui_Layout_Factory_Request));
2114 Eina_Future *f; 2120 Eina_Future *f;
2121 Efl_Model *model;
2115 2122
2116 if (!request) return ; 2123 if (!request) return ;
2117 2124
@@ -2122,7 +2129,8 @@ _efl_ui_layout_view_model_content_update(Efl_Ui_Layout_Data *pd, Efl_Ui_Layout_F
2122 request->factory = efl_ref(tracking->factory); 2129 request->factory = efl_ref(tracking->factory);
2123 request->tracking = tracking; 2130 request->tracking = tracking;
2124 2131
2125 f = efl_ui_view_factory_create_with_event(tracking->factory, pd->connect.model, pd->obj); 2132 model = efl_ui_view_model_get(pd->obj);
2133 f = efl_ui_view_factory_create_with_event(tracking->factory, model, pd->obj);
2126 f = efl_future_then(pd->obj, f, 2134 f = efl_future_then(pd->obj, f,
2127 .success = _content_created, 2135 .success = _content_created,
2128 .success_type = EINA_VALUE_TYPE_OBJECT, 2136 .success_type = EINA_VALUE_TYPE_OBJECT,
@@ -2136,7 +2144,7 @@ _efl_ui_layout_view_model_update(Efl_Ui_Layout_Data *pd)
2136 Eina_Hash_Tuple *tuple; 2144 Eina_Hash_Tuple *tuple;
2137 Eina_Iterator *it; 2145 Eina_Iterator *it;
2138 2146
2139 if (!pd->connect.model) return ; 2147 if (!efl_ui_view_model_get(pd->obj)) return ;
2140 2148
2141 it = eina_hash_iterator_tuple_new(pd->connect.properties); 2149 it = eina_hash_iterator_tuple_new(pd->connect.properties);
2142 EINA_ITERATOR_FOREACH(it, tuple) 2150 EINA_ITERATOR_FOREACH(it, tuple)
@@ -2214,17 +2222,18 @@ _efl_ui_layout_base_efl_ui_view_model_set(Eo *obj, Efl_Ui_Layout_Data *pd, Efl_M
2214 Eina_Stringshare *key; 2222 Eina_Stringshare *key;
2215 Eina_Hash_Tuple *tuple; 2223 Eina_Hash_Tuple *tuple;
2216 Eina_Iterator *it; 2224 Eina_Iterator *it;
2225 Efl_Model *setted;
2217 2226
2218 if (pd->connect.model && pd->connect.model != model) 2227 setted = efl_ui_view_model_get(obj);
2219 efl_event_callback_del(pd->connect.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, 2228 if (setted)
2220 _efl_model_properties_changed_cb, pd); 2229 efl_event_callback_del(setted, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
2230 _efl_model_properties_changed_cb, pd);
2221 2231
2222 if (!efl_replace(&pd->connect.model, model)) 2232 efl_ui_view_model_set(efl_super(obj, EFL_UI_LAYOUT_BASE_CLASS), model);
2223 return;
2224 2233
2225 if (model) 2234 if (model)
2226 efl_event_callback_add(pd->connect.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, 2235 efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
2227 _efl_model_properties_changed_cb, pd); 2236 _efl_model_properties_changed_cb, pd);
2228 2237
2229 _efl_ui_layout_connect_hash(pd); 2238 _efl_ui_layout_connect_hash(pd);
2230 2239
@@ -2261,20 +2270,21 @@ _efl_ui_layout_base_efl_ui_view_model_set(Eo *obj, Efl_Ui_Layout_Data *pd, Efl_M
2261 _efl_ui_layout_view_model_update(pd); 2270 _efl_ui_layout_view_model_update(pd);
2262} 2271}
2263 2272
2264EOLIAN static Efl_Model *
2265_efl_ui_layout_base_efl_ui_view_model_get(const Eo *obj EINA_UNUSED, Efl_Ui_Layout_Data *pd)
2266{
2267 return pd->connect.model;
2268}
2269
2270EOLIAN static Eina_Error 2273EOLIAN static Eina_Error
2271_efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Data *pd, const char *key, const char *property) 2274_efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Data *pd, const char *key, const char *property)
2272{ 2275{
2273 EINA_SAFETY_ON_NULL_RETURN_VAL(key, EFL_PROPERTY_ERROR_INVALID_KEY); 2276 EINA_SAFETY_ON_NULL_RETURN_VAL(key, EFL_PROPERTY_ERROR_INVALID_KEY);
2274 Eina_Stringshare *sprop; 2277 Eina_Stringshare *sprop;
2275 Eina_Hash *hash = NULL; 2278 Eina_Hash *hash = NULL;
2276 char *data = NULL; 2279 char *data = NULL;
2280 Efl_Model *model;
2281 Eina_Error r;
2282
2283 // First try binding with property on the Widget
2284 r = efl_ui_property_bind(efl_super(obj, EFL_UI_LAYOUT_BASE_CLASS), key, property);
2285 if (!r) return r;
2277 2286
2287 // Before trying to bind on the part of this object.
2278 if (!_elm_layout_part_aliasing_eval(obj, &key, EINA_TRUE)) 2288 if (!_elm_layout_part_aliasing_eval(obj, &key, EINA_TRUE))
2279 return EFL_PROPERTY_ERROR_INVALID_KEY; 2289 return EFL_PROPERTY_ERROR_INVALID_KEY;
2280 2290
@@ -2304,7 +2314,8 @@ _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj EINA_UNUSED, Efl_
2304 } 2314 }
2305 2315
2306 // Update display right away if possible 2316 // Update display right away if possible
2307 if (pd->connect.model) 2317 model = efl_ui_view_model_get(obj);
2318 if (model)
2308 { 2319 {
2309 if (hash == pd->connect.signals) 2320 if (hash == pd->connect.signals)
2310 _efl_ui_layout_view_model_signal_update(pd, data, sprop); 2321 _efl_ui_layout_view_model_signal_update(pd, data, sprop);
diff --git a/src/lib/elementary/efl_ui_layout_base.eo b/src/lib/elementary/efl_ui_layout_base.eo
index 31cf7034cd..102a253688 100644
--- a/src/lib/elementary/efl_ui_layout_base.eo
+++ b/src/lib/elementary/efl_ui_layout_base.eo
@@ -2,7 +2,7 @@ import efl_ui;
2import efl_orientation; 2import efl_orientation;
3 3
4abstract @beta Efl.Ui.Layout_Base extends Efl.Ui.Widget implements Efl.Container, 4abstract @beta Efl.Ui.Layout_Base extends Efl.Ui.Widget implements Efl.Container,
5 Efl.Ui.View, Efl.Ui.Property_Bind, Efl.Ui.Factory_Bind, 5 Efl.Ui.Factory_Bind,
6 Efl.Layout.Calc, Efl.Layout.Signal, 6 Efl.Layout.Calc, Efl.Layout.Signal,
7 Efl.Layout.Group 7 Efl.Layout.Group
8{ 8{
@@ -85,9 +85,9 @@ abstract @beta Efl.Ui.Layout_Base extends Efl.Ui.Widget implements Efl.Container
85 Efl.Container.content_count; 85 Efl.Container.content_count;
86 Efl.Container.content_iterate; 86 Efl.Container.content_iterate;
87 Efl.Part.part_get; 87 Efl.Part.part_get;
88 Efl.Ui.View.model { get; set; }
89 Efl.Ui.Property_Bind.property_bind; 88 Efl.Ui.Property_Bind.property_bind;
90 Efl.Ui.Factory_Bind.factory_bind; 89 Efl.Ui.Factory_Bind.factory_bind;
90 Efl.Ui.View.model { set; }
91 } 91 }
92 events { 92 events {
93 theme,changed: void; [[Called when theme changed]] 93 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 827398fec6..4fda71cdba 100644
--- a/src/lib/elementary/elm_widget_layout.h
+++ b/src/lib/elementary/elm_widget_layout.h
@@ -58,7 +58,6 @@ typedef struct _Elm_Layout_Smart_Data
58 Eina_Hash *properties; /**< The list of properties connected to layout parts. */ 58 Eina_Hash *properties; /**< The list of properties connected to layout parts. */
59 Eina_Hash *signals; /**< The list of signals connected. */ 59 Eina_Hash *signals; /**< The list of signals connected. */
60 Eina_Hash *factories; /**< The hash with parts connected to factories. */ 60 Eina_Hash *factories; /**< The hash with parts connected to factories. */
61 Efl_Model *model; /**< The model */
62 61
63 Eina_Bool updating : 1; 62 Eina_Bool updating : 1;
64 } connect; 63 } connect;