summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-04-18 13:37:28 -0700
committerCedric BAIL <cedric.bail@free.fr>2019-04-26 11:32:55 -0700
commit78563a395e1d9140eb6a67e7e7f9aff34af10e4b (patch)
tree9a7c0fdfac188d202b9e33f03c546f0111dff4b0 /src/lib/ecore
parent13b230029df72120191bbd837b065e2610a3c3ed (diff)
ecore: properly handle CHILD_ADDED and CHILD_REMOVED from source for Efl.CompositeModel
Before this patch we were directly sending this event on the Efl.CompositeModel, but they actually might contain an Efl.Model in the event child field. That Efl.Model wouldn't have been converted before to an Efl.CompositeModel exposing incoherence from the user of the object point of view. This patch fix that behavior. Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D8661
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/efl_composite_model.c92
1 files changed, 64 insertions, 28 deletions
diff --git a/src/lib/ecore/efl_composite_model.c b/src/lib/ecore/efl_composite_model.c
index 7ef607edd2..4a7e11413e 100644
--- a/src/lib/ecore/efl_composite_model.c
+++ b/src/lib/ecore/efl_composite_model.c
@@ -45,21 +45,18 @@ _children_indexed_key(const Efl_Composite_Model_Data *node,
45 return node->index - *key; 45 return node->index - *key;
46} 46}
47 47
48static void 48static Efl_Model *
49_efl_composite_model_efl_object_destructor(Eo *obj, Efl_Composite_Model_Data *pd) 49_efl_composite_lookup(const Efl_Class *self, Eo *parent, Efl_Model *view, unsigned int index)
50{ 50{
51 if (pd->source) 51 EFL_COMPOSITE_LOOKUP_RETURN(remember, parent, view, "_efl.composite_model");
52 {
53 efl_event_callback_forwarder_del(pd->source, EFL_MODEL_EVENT_CHILD_ADDED, obj);
54 efl_event_callback_forwarder_del(pd->source, EFL_MODEL_EVENT_CHILD_REMOVED, obj);
55 efl_event_callback_forwarder_del(pd->source, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, obj);
56 efl_event_callback_forwarder_del(pd->source, EFL_MODEL_EVENT_PROPERTIES_CHANGED, obj);
57 52
58 efl_unref(pd->source); 53 remember = efl_add_ref(self, parent,
59 pd->source = NULL; 54 efl_ui_view_model_set(efl_added, view),
60 } 55 efl_composite_model_index_set(efl_added, index),
56 efl_loop_model_volatile_make(efl_added));
57 if (!remember) return NULL;
61 58
62 efl_destructor(efl_super(obj, EFL_COMPOSITE_MODEL_CLASS)); 59 EFL_COMPOSITE_REMEMBER_RETURN(remember, view);
63} 60}
64 61
65static void 62static void
@@ -156,6 +153,44 @@ _efl_composite_model_index_get(const Eo *obj, Efl_Composite_Model_Data *pd)
156} 153}
157 154
158static void 155static void
156_efl_composite_model_child_added(void *data, const Efl_Event *event)
157{
158 Efl_Composite_Model_Data *pd = data;
159 Efl_Model_Children_Event *ev = event->info;
160 Efl_Model_Children_Event cev = { 0 };
161
162 cev.index = ev->index;
163 if (ev->child)
164 cev.child = _efl_composite_lookup(efl_class_get(pd->self),
165 pd->self, ev->child, ev->index);
166
167 efl_event_callback_call(pd->self, EFL_MODEL_EVENT_CHILD_ADDED, &cev);
168
169 efl_unref(cev.child);
170}
171
172static void
173_efl_composite_model_child_removed(void *data, const Efl_Event *event)
174{
175 Efl_Composite_Model_Data *pd = data;
176 Efl_Model_Children_Event *ev = event->info;
177 Efl_Model_Children_Event cev = { 0 };
178
179 cev.index = ev->index;
180 if (ev->child)
181 cev.child = _efl_composite_lookup(efl_class_get(pd->self),
182 pd->self, ev->child, ev->index);
183
184 efl_event_callback_call(pd->self, EFL_MODEL_EVENT_CHILD_REMOVED, &cev);
185
186 efl_unref(cev.child);
187}
188
189EFL_CALLBACKS_ARRAY_DEFINE(composite_callbacks,
190 { EFL_MODEL_EVENT_CHILD_ADDED, _efl_composite_model_child_added },
191 { EFL_MODEL_EVENT_CHILD_REMOVED, _efl_composite_model_child_removed });
192
193static void
159_efl_composite_model_efl_ui_view_model_set(Eo *obj EINA_UNUSED, Efl_Composite_Model_Data *pd, Efl_Model *model) 194_efl_composite_model_efl_ui_view_model_set(Eo *obj EINA_UNUSED, Efl_Composite_Model_Data *pd, Efl_Model *model)
160{ 195{
161 Eina_Iterator *properties; 196 Eina_Iterator *properties;
@@ -168,8 +203,7 @@ _efl_composite_model_efl_ui_view_model_set(Eo *obj EINA_UNUSED, Efl_Composite_Mo
168 } 203 }
169 pd->source = efl_ref(model); 204 pd->source = efl_ref(model);
170 205
171 efl_event_callback_forwarder_priority_add(model, EFL_MODEL_EVENT_CHILD_ADDED, EFL_CALLBACK_PRIORITY_BEFORE, obj); 206 efl_event_callback_array_add(model, composite_callbacks(), pd);
172 efl_event_callback_forwarder_priority_add(model, EFL_MODEL_EVENT_CHILD_REMOVED, EFL_CALLBACK_PRIORITY_BEFORE, obj);
173 efl_event_callback_forwarder_priority_add(model, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, EFL_CALLBACK_PRIORITY_BEFORE, obj); 207 efl_event_callback_forwarder_priority_add(model, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, EFL_CALLBACK_PRIORITY_BEFORE, obj);
174 efl_event_callback_forwarder_priority_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, EFL_CALLBACK_PRIORITY_BEFORE, obj); 208 efl_event_callback_forwarder_priority_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, EFL_CALLBACK_PRIORITY_BEFORE, obj);
175 209
@@ -252,20 +286,6 @@ struct _Efl_Composite_Model_Slice_Request
252 unsigned int dummy_need; 286 unsigned int dummy_need;
253}; 287};
254 288
255static Efl_Model *
256_efl_composite_lookup(const Efl_Class *self, Eo *parent, Efl_Model *view, unsigned int index)
257{
258 EFL_COMPOSITE_LOOKUP_RETURN(remember, parent, view, "_efl.composite_model");
259
260 remember = efl_add_ref(self, parent,
261 efl_ui_view_model_set(efl_added, view),
262 efl_composite_model_index_set(efl_added, index),
263 efl_loop_model_volatile_make(efl_added));
264 if (!remember) return NULL;
265
266 EFL_COMPOSITE_REMEMBER_RETURN(remember, view);
267}
268
269static Eina_Value 289static Eina_Value
270_efl_composite_model_then(Eo *o EINA_UNUSED, void *data, const Eina_Value v) 290_efl_composite_model_then(Eo *o EINA_UNUSED, void *data, const Eina_Value v)
271{ 291{
@@ -401,4 +421,20 @@ _efl_composite_model_efl_model_child_del(Eo *obj EINA_UNUSED,
401 efl_model_child_del(pd->source, child); 421 efl_model_child_del(pd->source, child);
402} 422}
403 423
424static void
425_efl_composite_model_efl_object_destructor(Eo *obj, Efl_Composite_Model_Data *pd)
426{
427 if (pd->source)
428 {
429 efl_event_callback_array_del(pd->source, composite_callbacks(), pd);
430 efl_event_callback_forwarder_del(pd->source, EFL_MODEL_EVENT_CHILDREN_COUNT_CHANGED, obj);
431 efl_event_callback_forwarder_del(pd->source, EFL_MODEL_EVENT_PROPERTIES_CHANGED, obj);
432
433 efl_unref(pd->source);
434 pd->source = NULL;
435 }
436
437 efl_destructor(efl_super(obj, EFL_COMPOSITE_MODEL_CLASS));
438}
439
404#include "efl_composite_model.eo.c" 440#include "efl_composite_model.eo.c"