summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-07-10 17:54:46 -0700
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-17 21:57:49 +0200
commit4d071ff1cbc020ecbb833e97e577ecee07274efa (patch)
tree102d624473c722bcb0f3b24c52f8c9ad53369722
parent65b4782682318055db57697064349ef8e4983064 (diff)
efl: implement notification for when the model is changed on a widget.
Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D9288
-rw-r--r--src/lib/efl/interfaces/efl_ui_view.eo9
-rw-r--r--src/lib/elementary/efl_ui_widget.c91
-rw-r--r--src/lib/elementary/elm_widget.h1
3 files changed, 70 insertions, 31 deletions
diff --git a/src/lib/efl/interfaces/efl_ui_view.eo b/src/lib/efl/interfaces/efl_ui_view.eo
index 33919d5c96..56026a0ed2 100644
--- a/src/lib/efl/interfaces/efl_ui_view.eo
+++ b/src/lib/efl/interfaces/efl_ui_view.eo
@@ -1,3 +1,9 @@
1struct @beta Efl.Model_Changed_Event {
2 [[Every time the model is changed on the object.]]
3 current: Efl.Model; [[The newly set model.]]
4 previous: Efl.Model; [[The previously set model.]]
5}
6
1interface @beta Efl.Ui.View 7interface @beta Efl.Ui.View
2{ 8{
3 [[Efl UI view interface]] 9 [[Efl UI view interface]]
@@ -10,4 +16,7 @@ interface @beta Efl.Ui.View
10 } 16 }
11 } 17 }
12 } 18 }
19 events {
20 model,changed: Efl.Model_Changed_Event; [[Event dispatched when a new model is set.]]
21 }
13} 22}
diff --git a/src/lib/elementary/efl_ui_widget.c b/src/lib/elementary/efl_ui_widget.c
index f6ddf3270f..f7749d9a66 100644
--- a/src/lib/elementary/efl_ui_widget.c
+++ b/src/lib/elementary/efl_ui_widget.c
@@ -5775,6 +5775,47 @@ _efl_ui_view_property_bind_changed(void *data, const Efl_Event *event)
5775 } 5775 }
5776} 5776}
5777 5777
5778static void
5779_efl_ui_widget_model_update(Efl_Ui_Widget_Data *pd)
5780{
5781 Efl_Ui_Property_Bound *property;
5782 Eina_Iterator *it;
5783
5784 it = eina_hash_iterator_data_new(pd->properties.model_lookup);
5785 EINA_ITERATOR_FOREACH(it, property)
5786 _efl_ui_property_bind_get(pd, property);
5787}
5788
5789static void
5790_efl_ui_widget_model_register(Eo *obj, Efl_Ui_Widget_Data *pd)
5791{
5792 if (pd->properties.registered) return ;
5793 if (pd->properties.model_lookup)
5794 {
5795 if (!pd->properties.model) return ;
5796
5797 efl_event_callback_add(pd->properties.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
5798 _efl_ui_model_property_bind_changed, pd);
5799 efl_event_callback_add(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED,
5800 _efl_ui_view_property_bind_changed, pd);
5801 pd->properties.registered = EINA_TRUE;
5802 }
5803}
5804
5805static void
5806_efl_ui_widget_model_unregister(Eo *obj, Efl_Ui_Widget_Data *pd)
5807{
5808 if (pd->properties.registered)
5809 {
5810 // Remove any existing handler that might exist for any reason
5811 efl_event_callback_del(pd->properties.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
5812 _efl_ui_model_property_bind_changed, pd);
5813 efl_event_callback_del(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED,
5814 _efl_ui_view_property_bind_changed, pd);
5815
5816 pd->properties.registered = EINA_FALSE;
5817 }
5818}
5778static Eina_Error 5819static Eina_Error
5779_efl_ui_widget_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Widget_Data *pd, 5820_efl_ui_widget_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Widget_Data *pd,
5780 const char *key, const char *property) 5821 const char *key, const char *property)
@@ -5788,14 +5829,8 @@ _efl_ui_widget_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Widget_Data *p
5788 { 5829 {
5789 pd->properties.model_lookup = eina_hash_stringshared_new(_efl_ui_property_bind_free); 5830 pd->properties.model_lookup = eina_hash_stringshared_new(_efl_ui_property_bind_free);
5790 pd->properties.view_lookup = eina_hash_stringshared_new(NULL); 5831 pd->properties.view_lookup = eina_hash_stringshared_new(NULL);
5791 if (pd->properties.model)
5792 {
5793 efl_event_callback_add(pd->properties.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
5794 _efl_ui_model_property_bind_changed, pd);
5795 efl_event_callback_add(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED,
5796 _efl_ui_view_property_bind_changed, pd);
5797 }
5798 } 5832 }
5833 _efl_ui_widget_model_register(obj, pd);
5799 5834
5800 prop = calloc(1, sizeof (Efl_Ui_Property_Bound)); 5835 prop = calloc(1, sizeof (Efl_Ui_Property_Bound));
5801 if (!prop) return ENOMEM; 5836 if (!prop) return ENOMEM;
@@ -5817,25 +5852,24 @@ _efl_ui_widget_efl_ui_view_model_set(Eo *obj,
5817 Efl_Ui_Widget_Data *pd, 5852 Efl_Ui_Widget_Data *pd,
5818 Efl_Model *model) 5853 Efl_Model *model)
5819{ 5854{
5820 if (pd->properties.model) 5855 Efl_Model_Changed_Event ev;
5821 { 5856
5822 // Remove any existing handler that might exist for any reason 5857 ev.current = efl_ref(model);
5823 efl_event_callback_del(pd->properties.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, 5858 ev.previous = efl_ref(pd->properties.model);
5824 _efl_ui_model_property_bind_changed, pd); 5859
5825 efl_event_callback_del(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED, 5860 _efl_ui_widget_model_unregister(obj, pd);
5826 _efl_ui_view_property_bind_changed, pd);
5827 }
5828 5861
5829 efl_replace(&pd->properties.model, model); 5862 efl_replace(&pd->properties.model, model);
5830 5863
5831 if (pd->properties.model && pd->properties.model_lookup) 5864 // Set the properties handler just in case
5832 { 5865 _efl_ui_widget_model_register(obj, pd);
5833 // Set the properties handler just in case 5866
5834 efl_event_callback_add(pd->properties.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, 5867 efl_event_callback_call(obj, EFL_UI_VIEW_EVENT_MODEL_CHANGED, &ev);
5835 _efl_ui_model_property_bind_changed, pd); 5868
5836 efl_event_callback_add(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED, 5869 if (pd->properties.model) _efl_ui_widget_model_update(pd);
5837 _efl_ui_view_property_bind_changed, pd); 5870
5838 } 5871 efl_unref(ev.current);
5872 efl_unref(ev.previous);
5839} 5873}
5840 5874
5841static Efl_Model * 5875static Efl_Model *
@@ -5849,14 +5883,9 @@ _efl_ui_widget_efl_object_invalidate(Eo *obj, Efl_Ui_Widget_Data *pd)
5849{ 5883{
5850 efl_invalidate(efl_super(obj, EFL_UI_WIDGET_CLASS)); 5884 efl_invalidate(efl_super(obj, EFL_UI_WIDGET_CLASS));
5851 5885
5852 if (pd->properties.model) 5886 _efl_ui_widget_model_unregister(obj, pd);
5853 { 5887 efl_replace(&pd->properties.model, NULL);
5854 efl_event_callback_del(pd->properties.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, 5888
5855 _efl_ui_model_property_bind_changed, pd);
5856 efl_event_callback_del(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED,
5857 _efl_ui_view_property_bind_changed, pd);
5858 efl_replace(&pd->properties.model, NULL);
5859 }
5860 if (pd->properties.view_lookup) eina_hash_free(pd->properties.view_lookup); 5889 if (pd->properties.view_lookup) eina_hash_free(pd->properties.view_lookup);
5861 pd->properties.view_lookup = NULL; 5890 pd->properties.view_lookup = NULL;
5862 if (pd->properties.model_lookup) eina_hash_free(pd->properties.model_lookup); 5891 if (pd->properties.model_lookup) eina_hash_free(pd->properties.model_lookup);
diff --git a/src/lib/elementary/elm_widget.h b/src/lib/elementary/elm_widget.h
index fec163dc44..f9fe403388 100644
--- a/src/lib/elementary/elm_widget.h
+++ b/src/lib/elementary/elm_widget.h
@@ -388,6 +388,7 @@ typedef struct _Elm_Widget_Smart_Data
388 Efl_Model *model; 388 Efl_Model *model;
389 Eina_Hash *model_lookup; 389 Eina_Hash *model_lookup;
390 Eina_Hash *view_lookup; 390 Eina_Hash *view_lookup;
391 Eina_Bool registered : 1;
391 } properties; 392 } properties;
392 Eina_Bool scroll_x_locked : 1; 393 Eina_Bool scroll_x_locked : 1;
393 Eina_Bool scroll_y_locked : 1; 394 Eina_Bool scroll_y_locked : 1;