elementary: rely on Efl.Ui.Widget to do more of property binding for MVVM in Efl...
authorCedric BAIL <cedric.bail@free.fr>
Tue, 12 Feb 2019 19:55:50 +0000 (11:55 -0800)
committerJunsuChoi <jsuya.choi@samsung.com>
Fri, 15 Mar 2019 04:23:19 +0000 (13:23 +0900)
Reviewed-by: Vitor Sousa da Silva <vitorsousa@expertisesolutions.com.br>
Differential Revision: https://phab.enlightenment.org/D7943

Change-Id: I40296ad06a11711cc914fbd178ead1ed93b6c3da

src/lib/elementary/efl_ui_layout.c
src/lib/elementary/efl_ui_layout_base.eo
src/lib/elementary/elm_widget_layout.h

index c57154a..7fb5c44 100644 (file)
@@ -922,6 +922,7 @@ _efl_ui_layout_base_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Layout_Data *sd)
    Edje_Signal_Data *esd;
    Evas_Object *child;
    Eina_List *l;
+   Efl_Model *model;
 
    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
 
@@ -957,12 +958,11 @@ _efl_ui_layout_base_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Layout_Data *sd)
         free(esd);
      }
 
-   if(sd->connect.model)
+   model = efl_ui_view_model_get(obj);
+   if(model)
      {
-         efl_event_callback_del(sd->connect.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
+         efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
                                 _efl_model_properties_changed_cb, sd);
-         efl_unref(sd->connect.model);
-         sd->connect.model = NULL;
      }
 
    eina_hash_free(sd->connect.properties);
@@ -1411,6 +1411,7 @@ _efl_ui_layout_text_generic_set(Eo *obj, Efl_Ui_Layout_Data *sd, const char *par
 
    Efl_Ui_Layout_Sub_Object_Data *sub_d = NULL;
    Eina_List *l;
+   Efl_Model *model;
 
    EINA_LIST_FOREACH(sd->subs, l, sub_d)
      {
@@ -1475,7 +1476,8 @@ _efl_ui_layout_text_generic_set(Eo *obj, Efl_Ui_Layout_Data *sd, const char *par
      sub_d->obj = _elm_access_edje_object_part_object_register
          (obj, elm_layout_edje_get(obj), part);
 
-   if (sd->connect.model && !sd->connect.updating)
+   model = efl_ui_view_model_get(obj);
+   if (model && !sd->connect.updating)
      {
         char *property = eina_hash_find(sd->connect.properties, sub_d->part);
 
@@ -1486,7 +1488,7 @@ _efl_ui_layout_text_generic_set(Eo *obj, Efl_Ui_Layout_Data *sd, const char *par
              eina_value_setup(&v, EINA_VALUE_TYPE_STRING);
              eina_value_set(&v, text);
 
-             efl_model_property_set(sd->connect.model, property, &v);
+             efl_model_property_set(model, property, &v);
           }
      }
 
@@ -2181,8 +2183,10 @@ _efl_ui_layout_view_model_property_update(Efl_Ui_Layout_Data *pd, const char *pa
 {
    Eina_Value *v = NULL;
    char *value = NULL;
+   Efl_Model *model;
 
-   v = efl_model_property_get(pd->connect.model, fetch);
+   model = efl_ui_view_model_get(pd->obj);
+   v = efl_model_property_get(model, fetch);
    if (!v) return;
 
    if (eina_value_type_get(v) != EINA_VALUE_TYPE_ERROR)
@@ -2202,10 +2206,12 @@ _efl_ui_layout_view_model_signal_update(Efl_Ui_Layout_Data *pd, const char *sign
    Eina_Value *v = NULL;
    Eina_Strbuf *buf;
    char *value = NULL;
+   Efl_Model *model;
    Eina_Bool eval = EINA_FALSE;
    Eina_Bool is_bool = EINA_FALSE;
 
-   v = efl_model_property_get(pd->connect.model, fetch);
+   model = efl_ui_view_model_get(pd->obj);
+   v = efl_model_property_get(model, fetch);
    if (!v) return;
 
    if (eina_value_type_get(v) == EINA_VALUE_TYPE_ERROR)
@@ -2315,6 +2321,7 @@ _efl_ui_layout_view_model_content_update(Efl_Ui_Layout_Data *pd, Efl_Ui_Layout_F
 {
    Efl_Ui_Layout_Factory_Request *request = calloc(1, sizeof (Efl_Ui_Layout_Factory_Request));
    Eina_Future *f;
+   Efl_Model *model;
 
    if (!request) return ;
 
@@ -2325,7 +2332,8 @@ _efl_ui_layout_view_model_content_update(Efl_Ui_Layout_Data *pd, Efl_Ui_Layout_F
    request->factory = efl_ref(tracking->factory);
    request->tracking = tracking;
 
-   f = efl_ui_view_factory_create_with_event(tracking->factory, pd->connect.model, pd->obj);
+   model = efl_ui_view_model_get(pd->obj);
+   f = efl_ui_view_factory_create_with_event(tracking->factory, model, pd->obj);
    f = efl_future_then(pd->obj, f,
                        .success = _content_created,
                        .success_type = EINA_VALUE_TYPE_OBJECT,
@@ -2339,7 +2347,7 @@ _efl_ui_layout_view_model_update(Efl_Ui_Layout_Data *pd)
    Eina_Hash_Tuple *tuple;
    Eina_Iterator *it;
 
-   if (!pd->connect.model) return ;
+   if (!efl_ui_view_model_get(pd->obj)) return ;
 
    it = eina_hash_iterator_tuple_new(pd->connect.properties);
    EINA_ITERATOR_FOREACH(it, tuple)
@@ -2417,17 +2425,18 @@ _efl_ui_layout_base_efl_ui_view_model_set(Eo *obj, Efl_Ui_Layout_Data *pd, Efl_M
    Eina_Stringshare *key;
    Eina_Hash_Tuple *tuple;
    Eina_Iterator *it;
+   Efl_Model *setted;
 
-   if (pd->connect.model && pd->connect.model != model)
-     efl_event_callback_del(pd->connect.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
-                               _efl_model_properties_changed_cb, pd);
+   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 (!efl_replace(&pd->connect.model, model))
-     return;
+   efl_ui_view_model_set(efl_super(obj, EFL_UI_LAYOUT_BASE_CLASS), model);
 
    if (model)
-     efl_event_callback_add(pd->connect.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);
 
@@ -2464,20 +2473,21 @@ _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);
 }
 
-EOLIAN static Efl_Model *
-_efl_ui_layout_base_efl_ui_view_model_get(const Eo *obj EINA_UNUSED, Efl_Ui_Layout_Data *pd)
-{
-   return pd->connect.model;
-}
-
 EOLIAN static Eina_Error
-_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)
+_efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Data *pd, const char *key, const char *property)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(key, EFL_PROPERTY_ERROR_INVALID_KEY);
    Eina_Stringshare *sprop;
    Eina_Hash *hash = NULL;
    char *data = NULL;
+   Efl_Model *model;
+   Eina_Error r;
+
+   // First try binding with property on the Widget
+   r = efl_ui_property_bind(efl_super(obj, EFL_UI_LAYOUT_BASE_CLASS), key, property);
+   if (!r) return r;
 
+   // Before trying to bind on the part of this object.
    if (!_elm_layout_part_aliasing_eval(obj, &key, EINA_TRUE))
      return EFL_PROPERTY_ERROR_INVALID_KEY;
 
@@ -2507,7 +2517,8 @@ _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj EINA_UNUSED, Efl_
      }
 
    // Update display right away if possible
-   if (pd->connect.model)
+   model = efl_ui_view_model_get(obj);
+   if (model)
      {
         if (hash == pd->connect.signals)
           _efl_ui_layout_view_model_signal_update(pd, data, sprop);
index ca956d8..eb392b7 100644 (file)
@@ -2,7 +2,7 @@ import efl_ui;
 import efl_orientation;
 
 abstract @beta Efl.Ui.Layout_Base extends Efl.Ui.Widget implements Efl.Container,
-                     Efl.Ui.View, Efl.Ui.Property_Bind, Efl.Ui.Factory_Bind,
+                     Efl.Ui.Factory_Bind,
                      Efl.Layout.Calc, Efl.Layout.Signal,
                      Efl.Layout.Group
 {
@@ -85,9 +85,10 @@ abstract @beta Efl.Ui.Layout_Base extends Efl.Ui.Widget implements Efl.Container
       Efl.Container.content_count;
       Efl.Container.content_iterate;
       Efl.Part.part_get;
-      Efl.Ui.View.model { get; set; }
       Efl.Ui.Property_Bind.property_bind;
       Efl.Ui.Factory_Bind.factory_bind;
+      Efl.Ui.View.model { set; }
+
       //TIZEN_ONLY(20161212): apply screen_reader_changed callback
       // TIZEN_ONLY(20170516): connect to at-spi dbus based on org.a11y.Status.IsEnabled property
       Efl.Ui.Widget.screen_reader;
index 827398f..4fda71c 100644 (file)
@@ -58,7 +58,6 @@ typedef struct _Elm_Layout_Smart_Data
       Eina_Hash         *properties; /**< The list of properties connected to layout parts. */
       Eina_Hash         *signals; /**< The list of signals connected. */
       Eina_Hash         *factories; /**< The hash with parts connected to factories. */
-      Efl_Model         *model; /**< The model */
 
       Eina_Bool          updating : 1;
    } connect;