summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-07-10 17:56:20 -0700
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-17 21:57:50 +0200
commita68e18a903ffb0fa14d1b5ebeb3efc3a8db95812 (patch)
tree250140a47d6a2297081625d02d1b985bbead781c
parent4d071ff1cbc020ecbb833e97e577ecee07274efa (diff)
elementary: Efl.Ui.Image now rely on event to update model binding.
Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D9289
-rw-r--r--src/lib/elementary/efl_ui_image.c70
-rw-r--r--src/lib/elementary/efl_ui_image.eo2
-rw-r--r--src/lib/elementary/efl_ui_widget_image.h1
3 files changed, 47 insertions, 26 deletions
diff --git a/src/lib/elementary/efl_ui_image.c b/src/lib/elementary/efl_ui_image.c
index 02dd574378..dea9ec1b00 100644
--- a/src/lib/elementary/efl_ui_image.c
+++ b/src/lib/elementary/efl_ui_image.c
@@ -53,6 +53,7 @@ void _efl_ui_image_sizing_eval(Evas_Object *obj);
53static void _efl_ui_image_model_properties_changed_cb(void *data, const Efl_Event *event); 53static void _efl_ui_image_model_properties_changed_cb(void *data, const Efl_Event *event);
54static void _on_size_hints_changed(void *data, const Efl_Event *e); 54static void _on_size_hints_changed(void *data, const Efl_Event *e);
55static Eina_Bool _efl_ui_image_download(Eo *obj, Efl_Ui_Image_Data *sd, const char *url); 55static Eina_Bool _efl_ui_image_download(Eo *obj, Efl_Ui_Image_Data *sd, const char *url);
56static void _update_viewmodel(Eo *obj, Efl_Ui_Image_Data *pd);
56 57
57static const Elm_Action key_actions[] = { 58static const Elm_Action key_actions[] = {
58 {"activate", _key_action_activate}, 59 {"activate", _key_action_activate},
@@ -848,6 +849,21 @@ _on_size_hints_changed(void *data EINA_UNUSED, const Efl_Event *ev)
848 _efl_ui_image_sizing_eval(ev->object); 849 _efl_ui_image_sizing_eval(ev->object);
849} 850}
850 851
852static void
853_efl_ui_image_model_changed(void *data, const Efl_Event *event)
854{
855 Efl_Model_Changed_Event *ev = event->info;
856
857 if (ev->previous)
858 efl_event_callback_del(ev->previous, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
859 _efl_ui_image_model_properties_changed_cb, event->object);
860 if (ev->current)
861 efl_event_callback_add(ev->current, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
862 _efl_ui_image_model_properties_changed_cb, event->object);
863
864 _update_viewmodel(event->object, data);
865}
866
851EOLIAN static Eo * 867EOLIAN static Eo *
852_efl_ui_image_efl_object_constructor(Eo *obj, Efl_Ui_Image_Data *pd) 868_efl_ui_image_efl_object_constructor(Eo *obj, Efl_Ui_Image_Data *pd)
853{ 869{
@@ -861,6 +877,22 @@ _efl_ui_image_efl_object_constructor(Eo *obj, Efl_Ui_Image_Data *pd)
861 return obj; 877 return obj;
862} 878}
863 879
880EOLIAN static void
881_efl_ui_image_efl_object_invalidate(Eo *obj, Efl_Ui_Image_Data *pd EINA_UNUSED)
882{
883 Efl_Model *model;
884
885 if (pd->property_watch)
886 efl_event_callback_del(obj, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
887 _efl_ui_image_model_changed, pd);
888
889 model = efl_ui_view_model_get(obj);
890 if (model)
891 efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
892 _efl_ui_image_model_properties_changed_cb, obj);
893 efl_invalidate(efl_super(obj, EFL_UI_IMAGE_CLASS));
894}
895
864static const Eina_Slice remote_uri[] = { 896static const Eina_Slice remote_uri[] = {
865 EINA_SLICE_STR_LITERAL("http://"), 897 EINA_SLICE_STR_LITERAL("http://"),
866 EINA_SLICE_STR_LITERAL("https://"), 898 EINA_SLICE_STR_LITERAL("https://"),
@@ -1829,6 +1861,15 @@ _update_viewmodel(Eo *obj, Efl_Ui_Image_Data *pd)
1829 char *key = NULL; 1861 char *key = NULL;
1830 Efl_Model *model; 1862 Efl_Model *model;
1831 1863
1864 if (!pd->property.file) return ;
1865
1866 if (!pd->property_watch)
1867 {
1868 efl_event_callback_add(obj, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
1869 _efl_ui_image_model_changed, pd);
1870 pd->property_watch = EINA_TRUE;
1871 }
1872
1832 model = efl_ui_view_model_get(obj); 1873 model = efl_ui_view_model_get(obj);
1833 if (!model) return ; 1874 if (!model) return ;
1834 1875
@@ -1903,35 +1944,14 @@ _efl_ui_image_model_properties_changed_cb(void *data, const Efl_Event *event)
1903 if (refresh) _update_viewmodel(obj, pd); 1944 if (refresh) _update_viewmodel(obj, pd);
1904} 1945}
1905 1946
1906EOLIAN static void
1907_efl_ui_image_efl_ui_view_model_set(Eo *obj, Efl_Ui_Image_Data *pd, Efl_Model *model)
1908{
1909 Efl_Model *setted;
1910
1911 setted = efl_ui_view_model_get(obj);
1912 if (setted)
1913 {
1914 efl_event_callback_del(setted, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
1915 _efl_ui_image_model_properties_changed_cb, obj);
1916 }
1917
1918 efl_ui_view_model_set(efl_super(obj, EFL_UI_IMAGE_CLASS), model);
1919
1920 setted = efl_ui_view_model_get(obj);
1921 if (setted)
1922 {
1923 efl_event_callback_add(setted, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
1924 _efl_ui_image_model_properties_changed_cb, obj);
1925 }
1926
1927 _update_viewmodel(obj, pd);
1928}
1929
1930EOLIAN static Eina_Error 1947EOLIAN static Eina_Error
1931_efl_ui_image_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Image_Data *pd, const char *key, const char *property) 1948_efl_ui_image_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Image_Data *pd, const char *key, const char *property)
1932{ 1949{
1933 Eina_Stringshare *sk; 1950 Eina_Stringshare *sk;
1934 1951
1952 if (efl_ui_property_bind(efl_super(obj, EFL_UI_IMAGE_CLASS), key, property) == 0)
1953 return 0;
1954
1935 if (strcmp(key, "filename") == 0) 1955 if (strcmp(key, "filename") == 0)
1936 { 1956 {
1937 pd->property.icon = EINA_FALSE; 1957 pd->property.icon = EINA_FALSE;
@@ -1949,7 +1969,7 @@ _efl_ui_image_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Image_Data *pd,
1949 } 1969 }
1950 else 1970 else
1951 { 1971 {
1952 return efl_ui_property_bind(efl_super(obj, EFL_UI_IMAGE_CLASS), key, property); 1972 return EFL_PROPERTY_ERROR_INVALID_KEY;
1953 } 1973 }
1954 1974
1955 _update_viewmodel(obj, pd); 1975 _update_viewmodel(obj, pd);
diff --git a/src/lib/elementary/efl_ui_image.eo b/src/lib/elementary/efl_ui_image.eo
index d6db562358..728a6c4cb0 100644
--- a/src/lib/elementary/efl_ui_image.eo
+++ b/src/lib/elementary/efl_ui_image.eo
@@ -89,6 +89,7 @@ class @beta Efl.Ui.Image extends Efl.Ui.Widget implements Efl.Ui.Clickable, Efl.
89 } 89 }
90 implements { 90 implements {
91 Efl.Object.constructor; 91 Efl.Object.constructor;
92 Efl.Object.invalidate;
92 Efl.File.load; 93 Efl.File.load;
93 Efl.File.unload; 94 Efl.File.unload;
94 Efl.Gfx.Color.color { set; } 95 Efl.Gfx.Color.color { set; }
@@ -118,7 +119,6 @@ class @beta Efl.Ui.Image extends Efl.Ui.Widget implements Efl.Ui.Clickable, Efl.
118 Efl.Canvas.Group.group_member_add; 119 Efl.Canvas.Group.group_member_add;
119 Efl.Ui.Draggable.drag_target { get; set; } 120 Efl.Ui.Draggable.drag_target { get; set; }
120 Efl.Ui.Property_Bind.property_bind; 121 Efl.Ui.Property_Bind.property_bind;
121 Efl.Ui.View.model { set; }
122 Efl.Ui.Widget.theme_apply; 122 Efl.Ui.Widget.theme_apply;
123 Efl.Ui.Widget.widget_input_event_handler; 123 Efl.Ui.Widget.widget_input_event_handler;
124 Efl.Access.Component.extents { get; } 124 Efl.Access.Component.extents { get; }
diff --git a/src/lib/elementary/efl_ui_widget_image.h b/src/lib/elementary/efl_ui_widget_image.h
index c140c9b7c5..661cca94f2 100644
--- a/src/lib/elementary/efl_ui_widget_image.h
+++ b/src/lib/elementary/efl_ui_widget_image.h
@@ -103,6 +103,7 @@ struct _Efl_Ui_Image_Data
103 Eina_Bool scale_up : 1; 103 Eina_Bool scale_up : 1;
104 Eina_Bool scale_down : 1; 104 Eina_Bool scale_down : 1;
105 Eina_Bool legacy_align : 1; 105 Eina_Bool legacy_align : 1;
106 Eina_Bool property_watch : 1;
106}; 107};
107 108
108/** 109/**