summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarry Lira <larry@expertisesolutions.com.br>2018-11-29 15:11:51 -0200
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2018-11-30 16:56:47 -0200
commit6b0c85cb0da92e1e00d867e115ffe2827e2e3853 (patch)
tree537467990ce39d4917d285f5f7dc40e90c590dff
parent0398b8f19c2adcf206ec298ded8ce4dd1681a501 (diff)
Efl.Ui.List.View: fixed MVVM life-cycle
Fix bugs on Views and Model related with null items and proper ownership and life-cycle of components. Configure default theme for default factory on finalize.
-rw-r--r--src/examples/elementary/efl_ui_list_view_example_1.c5
-rw-r--r--src/examples/elementary/efl_ui_list_view_example_2.c2
-rw-r--r--src/examples/elementary/efl_ui_list_view_example_3.c16
-rw-r--r--src/lib/ecore/efl_model_container.c6
-rw-r--r--src/lib/ecore/efl_model_item.c9
-rw-r--r--src/lib/elementary/efl_ui_layout.c16
-rw-r--r--src/lib/elementary/efl_ui_layout_factory.c59
-rw-r--r--src/lib/elementary/efl_ui_list_view.c73
-rw-r--r--src/lib/elementary/efl_ui_list_view_precise_layouter.c47
-rw-r--r--src/lib/elementary/efl_ui_list_view_seg_array.c9
10 files changed, 118 insertions, 124 deletions
diff --git a/src/examples/elementary/efl_ui_list_view_example_1.c b/src/examples/elementary/efl_ui_list_view_example_1.c
index f0a6adcfb8..dc300264aa 100644
--- a/src/examples/elementary/efl_ui_list_view_example_1.c
+++ b/src/examples/elementary/efl_ui_list_view_example_1.c
@@ -22,7 +22,7 @@ const char *styles[] = {
22char edj_path[PATH_MAX]; 22char edj_path[PATH_MAX];
23 23
24static void 24static void
25_realized_cb(void *data, const Efl_Event *event) 25_realized_cb(void *data EINA_UNUSED, const Efl_Event *event)
26{ 26{
27 Efl_Ui_List_View_Item_Event *ie = event->info; 27 Efl_Ui_List_View_Item_Event *ie = event->info;
28 if (!ie->layout) return; 28 if (!ie->layout) return;
@@ -69,7 +69,7 @@ _make_model(Evas_Object *win)
69} 69}
70 70
71EAPI_MAIN int 71EAPI_MAIN int
72elm_main(int argc, char **argv) 72elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
73{ 73{
74 Efl_Ui_Factory *factory; 74 Efl_Ui_Factory *factory;
75 Evas_Object *win, *li; 75 Evas_Object *win, *li;
@@ -110,7 +110,6 @@ elm_main(int argc, char **argv)
110 evas_object_show(win); 110 evas_object_show(win);
111 111
112 elm_run(); 112 elm_run();
113 efl_unref(model);
114 113
115 return 0; 114 return 0;
116} 115}
diff --git a/src/examples/elementary/efl_ui_list_view_example_2.c b/src/examples/elementary/efl_ui_list_view_example_2.c
index c624cade19..ca56f37d33 100644
--- a/src/examples/elementary/efl_ui_list_view_example_2.c
+++ b/src/examples/elementary/efl_ui_list_view_example_2.c
@@ -15,7 +15,7 @@
15#define EFL_MODEL_TEST_FILENAME_PATH "/tmp" 15#define EFL_MODEL_TEST_FILENAME_PATH "/tmp"
16 16
17EAPI_MAIN int 17EAPI_MAIN int
18elm_main(int argc, char **argv) 18elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
19{ 19{
20 Efl_Ui_Layout_Factory *factory; 20 Efl_Ui_Layout_Factory *factory;
21 Efl_Ui_Image_Factory *imgf; 21 Efl_Ui_Image_Factory *imgf;
diff --git a/src/examples/elementary/efl_ui_list_view_example_3.c b/src/examples/elementary/efl_ui_list_view_example_3.c
index 46d5ca5813..eaf5dc975a 100644
--- a/src/examples/elementary/efl_ui_list_view_example_3.c
+++ b/src/examples/elementary/efl_ui_list_view_example_3.c
@@ -66,7 +66,7 @@ _focused(void *data, const Efl_Event *event)
66} 66}
67 67
68static void 68static void
69_bt_add_clicked(void *data, Evas_Object *obj, void *event_info) 69_bt_add_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
70{ 70{
71 Priv_Data *priv = (Priv_Data*)data; 71 Priv_Data *priv = (Priv_Data*)data;
72 Eina_Value vtext, value; 72 Eina_Value vtext, value;
@@ -90,7 +90,7 @@ _bt_add_clicked(void *data, Evas_Object *obj, void *event_info)
90} 90}
91 91
92static void 92static void
93_bt_del_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) 93_bt_del_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
94{ 94{
95 Priv_Data *priv = (Priv_Data*)data; 95 Priv_Data *priv = (Priv_Data*)data;
96 Eo *child = NULL; 96 Eo *child = NULL;
@@ -110,35 +110,35 @@ _bt_del_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
110} 110}
111 111
112static void 112static void
113_bt_none_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) 113_bt_none_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
114{ 114{
115 Evas_Object *li = data; 115 Evas_Object *li = data;
116 efl_ui_list_view_select_mode_set(li, ELM_OBJECT_SELECT_MODE_NONE); 116 efl_ui_list_view_select_mode_set(li, ELM_OBJECT_SELECT_MODE_NONE);
117} 117}
118 118
119static void 119static void
120_bt_donly_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) 120_bt_donly_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
121{ 121{
122 Evas_Object *li = data; 122 Evas_Object *li = data;
123 efl_ui_list_view_select_mode_set(li, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); 123 efl_ui_list_view_select_mode_set(li, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
124} 124}
125 125
126static void 126static void
127_bt_default_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) 127_bt_default_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
128{ 128{
129 Evas_Object *li = data; 129 Evas_Object *li = data;
130 efl_ui_list_view_select_mode_set(li, ELM_OBJECT_SELECT_MODE_DEFAULT); 130 efl_ui_list_view_select_mode_set(li, ELM_OBJECT_SELECT_MODE_DEFAULT);
131} 131}
132 132
133static void 133static void
134_bt_set_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) 134_bt_set_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
135{ 135{
136 Priv_Data *priv = data; 136 Priv_Data *priv = data;
137 efl_ui_view_model_set(priv->list2, priv->model); 137 efl_ui_view_model_set(priv->list2, priv->model);
138} 138}
139 139
140static void 140static void
141_bt_unset_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) 141_bt_unset_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
142{ 142{
143 Evas_Object *li = data; 143 Evas_Object *li = data;
144 efl_ui_view_model_set(li, NULL); 144 efl_ui_view_model_set(li, NULL);
@@ -201,7 +201,7 @@ _make_model()
201} 201}
202 202
203EAPI_MAIN int 203EAPI_MAIN int
204elm_main(int argc, char **argv) 204elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
205{ 205{
206 Priv_Data *priv; 206 Priv_Data *priv;
207 Evas_Object *win, *bx, *vbx, *bt; 207 Evas_Object *win, *bx, *vbx, *bt;
diff --git a/src/lib/ecore/efl_model_container.c b/src/lib/ecore/efl_model_container.c
index 5449ae4307..ce5dc493aa 100644
--- a/src/lib/ecore/efl_model_container.c
+++ b/src/lib/ecore/efl_model_container.c
@@ -84,12 +84,8 @@ _efl_model_container_efl_object_destructor(Eo *obj,
84{ 84{
85 Eina_Stringshare *key; 85 Eina_Stringshare *key;
86 Eina_Iterator *it; 86 Eina_Iterator *it;
87 Efl_Model *child;
88 87
89 EINA_LIST_FREE(sd->childrens, child) 88 eina_list_free(sd->childrens);
90 {
91 if (child) efl_parent_set(child, NULL);
92 }
93 89
94 it = eina_hash_iterator_key_new(sd->properties); 90 it = eina_hash_iterator_key_new(sd->properties);
95 EINA_ITERATOR_FOREACH(it, key) 91 EINA_ITERATOR_FOREACH(it, key)
diff --git a/src/lib/ecore/efl_model_item.c b/src/lib/ecore/efl_model_item.c
index 104125a705..13f60292c9 100644
--- a/src/lib/ecore/efl_model_item.c
+++ b/src/lib/ecore/efl_model_item.c
@@ -44,14 +44,7 @@ _efl_model_item_efl_object_constructor(Eo *obj, Efl_Model_Item_Data *sd)
44static void 44static void
45_efl_model_item_efl_object_destructor(Eo *obj, Efl_Model_Item_Data *sd) 45_efl_model_item_efl_object_destructor(Eo *obj, Efl_Model_Item_Data *sd)
46{ 46{
47 Efl_Model *child; 47 eina_list_free(sd->childrens);
48
49 EINA_LIST_FREE(sd->childrens, child)
50 {
51 if (child)
52 efl_parent_set(child, NULL);
53 }
54
55 eina_hash_foreach(sd->properties, _stringshared_keys_free, NULL); 48 eina_hash_foreach(sd->properties, _stringshared_keys_free, NULL);
56 eina_hash_free(sd->properties); 49 eina_hash_free(sd->properties);
57 50
diff --git a/src/lib/elementary/efl_ui_layout.c b/src/lib/elementary/efl_ui_layout.c
index 0e42c88d21..c14bebac3d 100644
--- a/src/lib/elementary/efl_ui_layout.c
+++ b/src/lib/elementary/efl_ui_layout.c
@@ -2103,9 +2103,8 @@ _efl_ui_layout_connect_hash(Efl_Ui_Layout_Data *pd)
2103{ 2103{
2104 if (pd->connect.properties) return ; 2104 if (pd->connect.properties) return ;
2105 2105
2106 // FIXME: fix destruction function definition 2106 pd->connect.properties = eina_hash_stringshared_new(EINA_FREE_CB(free)); // Hash of property targeting a part
2107 pd->connect.properties = eina_hash_stringshared_new(NULL); // Hash of property targeting a part 2107 pd->connect.signals = eina_hash_stringshared_new(EINA_FREE_CB(free)); // Hash of property triggering a signal
2108 pd->connect.signals = eina_hash_stringshared_new(NULL); // Hash of property triggering a signal
2109 pd->connect.factories = eina_hash_stringshared_new(EINA_FREE_CB(efl_unref)); // Hash of property triggering a content creation 2108 pd->connect.factories = eina_hash_stringshared_new(EINA_FREE_CB(efl_unref)); // Hash of property triggering a content creation
2110} 2109}
2111 2110
@@ -2116,13 +2115,16 @@ _efl_ui_layout_efl_ui_view_model_set(Eo *obj, Efl_Ui_Layout_Data *pd, Efl_Model
2116 Eina_Hash_Tuple *tuple; 2115 Eina_Hash_Tuple *tuple;
2117 Eina_Iterator *it; 2116 Eina_Iterator *it;
2118 2117
2119 efl_replace(&pd->connect.model, model); 2118 if (pd->connect.model && pd->connect.model != model)
2119 efl_event_callback_del(pd->connect.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
2120 _efl_model_properties_changed_cb, pd);
2121
2122 if (!efl_replace(&pd->connect.model, model))
2123 return;
2120 2124
2121 if (model) 2125 if (model)
2122 { 2126 efl_event_callback_add(pd->connect.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
2123 efl_event_callback_add(pd->connect.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
2124 _efl_model_properties_changed_cb, pd); 2127 _efl_model_properties_changed_cb, pd);
2125 }
2126 2128
2127 _efl_ui_layout_connect_hash(pd); 2129 _efl_ui_layout_connect_hash(pd);
2128 2130
diff --git a/src/lib/elementary/efl_ui_layout_factory.c b/src/lib/elementary/efl_ui_layout_factory.c
index 43d0a0f35d..cbd8139064 100644
--- a/src/lib/elementary/efl_ui_layout_factory.c
+++ b/src/lib/elementary/efl_ui_layout_factory.c
@@ -10,7 +10,6 @@
10 10
11typedef struct _Efl_Ui_Layout_Factory_Data 11typedef struct _Efl_Ui_Layout_Factory_Data
12{ 12{
13 Eina_Array *layouts;
14 Eina_Hash *connects; 13 Eina_Hash *connects;
15 Eina_Hash *factory_connects; 14 Eina_Hash *factory_connects;
16 Eina_Stringshare *klass; 15 Eina_Stringshare *klass;
@@ -46,12 +45,8 @@ _efl_ui_layout_factory_efl_object_constructor(Eo *obj, Efl_Ui_Layout_Factory_Dat
46{ 45{
47 obj = efl_constructor(efl_super(obj, MY_CLASS)); 46 obj = efl_constructor(efl_super(obj, MY_CLASS));
48 47
49 pd->klass = NULL;
50 pd->group = NULL;
51 pd->style = NULL;
52 pd->layouts = eina_array_new(8);
53 pd->connects = eina_hash_stringshared_new(EINA_FREE_CB(eina_stringshare_del)); 48 pd->connects = eina_hash_stringshared_new(EINA_FREE_CB(eina_stringshare_del));
54 pd->factory_connects = eina_hash_stringshared_new(EINA_FREE_CB(efl_del)); 49 pd->factory_connects = eina_hash_stringshared_new(EINA_FREE_CB(efl_unref));
55 50
56 return obj; 51 return obj;
57} 52}
@@ -59,18 +54,10 @@ _efl_ui_layout_factory_efl_object_constructor(Eo *obj, Efl_Ui_Layout_Factory_Dat
59EOLIAN static void 54EOLIAN static void
60_efl_ui_layout_factory_efl_object_destructor(Eo *obj, Efl_Ui_Layout_Factory_Data *pd) 55_efl_ui_layout_factory_efl_object_destructor(Eo *obj, Efl_Ui_Layout_Factory_Data *pd)
61{ 56{
62 Eina_Array_Iterator iterator;
63 Eo *layout;
64 unsigned int i;
65
66 eina_stringshare_del(pd->klass); 57 eina_stringshare_del(pd->klass);
67 eina_stringshare_del(pd->group); 58 eina_stringshare_del(pd->group);
68 eina_stringshare_del(pd->style); 59 eina_stringshare_del(pd->style);
69 60
70 EINA_ARRAY_ITER_NEXT(pd->layouts, i, layout, iterator)
71 efl_parent_set(layout, NULL);
72
73 eina_array_free(pd->layouts);
74 eina_hash_free(pd->connects); 61 eina_hash_free(pd->connects);
75 eina_hash_free(pd->factory_connects); 62 eina_hash_free(pd->factory_connects);
76 63
@@ -83,25 +70,16 @@ _efl_ui_layout_factory_efl_ui_factory_create(Eo *obj EINA_UNUSED, Efl_Ui_Layout_
83{ 70{
84 Efl_Gfx_Entity *layout; 71 Efl_Gfx_Entity *layout;
85 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL); 72 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
86/*
87 if (eina_array_count(pd->layouts))
88 {
89 layout = eina_array_pop(pd->layouts);
90 efl_parent_set(layout, parent);
91 efl_ui_view_model_set(layout, model);
92 }
93 else */
94 {
95 layout = efl_add(EFL_UI_LAYOUT_CLASS, parent,
96 efl_ui_view_model_set(efl_added, model),
97 efl_ui_layout_theme_set(efl_added, pd->klass, pd->group, pd->style));
98 73
99 eina_hash_foreach(pd->connects, _model_connect, layout); 74 layout = efl_add(EFL_UI_LAYOUT_CLASS, parent,
100 eina_hash_foreach(pd->factory_connects, _factory_model_connect, layout); 75 efl_ui_view_model_set(efl_added, model),
76 efl_ui_layout_theme_set(efl_added, pd->klass, pd->group, pd->style));
101 77
102 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0); 78 eina_hash_foreach(pd->connects, _model_connect, layout);
103 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL); 79 eina_hash_foreach(pd->factory_connects, _factory_model_connect, layout);
104 } 80
81 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, 0);
82 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
105 83
106 return layout; 84 return layout;
107} 85}
@@ -118,6 +96,7 @@ _efl_ui_layout_factory_efl_ui_factory_model_connect(Eo *obj EINA_UNUSED, Efl_Ui_
118 , const char *name, Efl_Ui_Factory *factory) 96 , const char *name, Efl_Ui_Factory *factory)
119{ 97{
120 Eina_Stringshare *ss_name; 98 Eina_Stringshare *ss_name;
99 Efl_Ui_Factory *f_old;
121 ss_name = eina_stringshare_add(name); 100 ss_name = eina_stringshare_add(name);
122 101
123 if (factory == NULL) 102 if (factory == NULL)
@@ -126,24 +105,36 @@ _efl_ui_layout_factory_efl_ui_factory_model_connect(Eo *obj EINA_UNUSED, Efl_Ui_
126 return; 105 return;
127 } 106 }
128 107
129 eina_stringshare_del(eina_hash_set(pd->factory_connects, ss_name, factory)); 108 f_old = eina_hash_set(pd->factory_connects, ss_name, efl_ref(factory));
109 if (f_old)
110 {
111 efl_unref(f_old);
112 eina_stringshare_del(ss_name);
113 }
130} 114}
131 115
132EOLIAN static void 116EOLIAN static void
133_efl_ui_layout_factory_efl_ui_model_connect_connect(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Factory_Data *pd 117_efl_ui_layout_factory_efl_ui_model_connect_connect(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Factory_Data *pd
134 , const char *name, const char *property) 118 , const char *name, const char *property)
135{ 119{
136 Eina_Stringshare *ss_name, *ss_prop; 120 Eina_Stringshare *ss_name, *ss_prop, *ss_old;
137 ss_name = eina_stringshare_add(name); 121 ss_name = eina_stringshare_add(name);
138 122
139 if (property == NULL) 123 if (property == NULL)
140 { 124 {
141 eina_hash_del(pd->connects, ss_name, NULL); 125 eina_hash_del(pd->connects, ss_name, NULL);
126 eina_stringshare_del(ss_name);
142 return; 127 return;
143 } 128 }
144 129
145 ss_prop = eina_stringshare_add(property); 130 ss_prop = eina_stringshare_add(property);
146 eina_stringshare_del(eina_hash_set(pd->connects, ss_name, ss_prop)); 131 ss_old = eina_hash_set(pd->connects, ss_name, ss_prop);
132 if (ss_old)
133 {
134 eina_stringshare_del(ss_old);
135 eina_stringshare_del(ss_name);
136 }
137
147} 138}
148 139
149EOLIAN static void 140EOLIAN static void
diff --git a/src/lib/elementary/efl_ui_list_view.c b/src/lib/elementary/efl_ui_list_view.c
index 94e9fdbf94..5a9a764947 100644
--- a/src/lib/elementary/efl_ui_list_view.c
+++ b/src/lib/elementary/efl_ui_list_view.c
@@ -620,7 +620,9 @@ _efl_ui_list_view_efl_canvas_group_group_add(Eo *obj, Efl_Ui_List_View_Data *pd)
620EOLIAN static void 620EOLIAN static void
621_efl_ui_list_view_efl_canvas_group_group_del(Eo *obj, Efl_Ui_List_View_Data *pd) 621_efl_ui_list_view_efl_canvas_group_group_del(Eo *obj, Efl_Ui_List_View_Data *pd)
622{ 622{
623 ELM_SAFE_FREE(pd->pan_obj, evas_object_del); 623 efl_ui_list_view_relayout_model_set(pd->relayout, NULL);
624
625 ELM_SAFE_FREE(pd->pan_obj, efl_del);
624 efl_canvas_group_del(efl_super(obj, MY_CLASS)); 626 efl_canvas_group_del(efl_super(obj, MY_CLASS));
625} 627}
626 628
@@ -637,15 +639,16 @@ _efl_ui_list_view_efl_ui_widget_focus_manager_focus_manager_create(Eo *obj EINA_
637EOLIAN static Eo * 639EOLIAN static Eo *
638_efl_ui_list_view_efl_object_finalize(Eo *obj, Efl_Ui_List_View_Data *pd) 640_efl_ui_list_view_efl_object_finalize(Eo *obj, Efl_Ui_List_View_Data *pd)
639{ 641{
640
641 if (!pd->factory) 642 if (!pd->factory)
642 pd->factory = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, obj); 643 {
644 pd->factory = efl_new(EFL_UI_LAYOUT_FACTORY_CLASS);
645 efl_ui_layout_factory_theme_config(pd->factory, "list_item", NULL, "default");
646 }
643 647
644 if(!pd->relayout) 648 if(!pd->relayout)
645 { 649 {
646 pd->relayout = efl_add(EFL_UI_LIST_VIEW_PRECISE_LAYOUTER_CLASS, obj); 650 pd->relayout = efl_new(EFL_UI_LIST_VIEW_PRECISE_LAYOUTER_CLASS);
647 if (pd->model) 651 efl_ui_list_view_relayout_model_set(pd->relayout, pd->model);
648 efl_ui_list_view_relayout_model_set(pd->relayout, pd->model);
649 } 652 }
650 return obj; 653 return obj;
651} 654}
@@ -659,7 +662,7 @@ _efl_ui_list_view_efl_object_constructor(Eo *obj, Efl_Ui_List_View_Data *pd)
659 evas_object_smart_callbacks_descriptions_set(obj, _smart_callbacks); 662 evas_object_smart_callbacks_descriptions_set(obj, _smart_callbacks);
660 efl_access_object_role_set(obj, EFL_ACCESS_ROLE_LIST); 663 efl_access_object_role_set(obj, EFL_ACCESS_ROLE_LIST);
661 664
662 pd->seg_array = efl_add(EFL_UI_LIST_VIEW_SEG_ARRAY_CLASS, obj, efl_ui_list_view_seg_array_setup(efl_added, 32)); 665 pd->seg_array = efl_new(EFL_UI_LIST_VIEW_SEG_ARRAY_CLASS, efl_ui_list_view_seg_array_setup(efl_added, 32));
663 666
664 efl_event_callback_add(obj, EFL_UI_FOCUS_MANAGER_EVENT_FOCUS_CHANGED, _list_element_focused, NULL); 667 efl_event_callback_add(obj, EFL_UI_FOCUS_MANAGER_EVENT_FOCUS_CHANGED, _list_element_focused, NULL);
665 668
@@ -678,45 +681,37 @@ _efl_ui_list_view_efl_object_constructor(Eo *obj, Efl_Ui_List_View_Data *pd)
678EOLIAN static void 681EOLIAN static void
679_efl_ui_list_view_efl_object_destructor(Eo *obj, Efl_Ui_List_View_Data *pd) 682_efl_ui_list_view_efl_object_destructor(Eo *obj, Efl_Ui_List_View_Data *pd)
680{ 683{
681 efl_ui_list_view_relayout_model_set(pd->relayout, NULL); 684 efl_event_callback_del(obj, EFL_UI_FOCUS_MANAGER_EVENT_FOCUS_CHANGED,
682 685 _list_element_focused, NULL);
683 efl_unref(pd->model);
684 eina_stringshare_del(pd->style);
685 686
686 _efl_ui_list_view_edje_object_detach(obj); 687 _efl_ui_list_view_edje_object_detach(obj);
687 688
688 ELM_SAFE_FREE(pd->pan_obj, evas_object_del); 689 efl_replace(&pd->model, NULL);
689 efl_canvas_group_del(efl_super(obj, MY_CLASS)); 690 efl_replace(&pd->relayout, NULL);
691 efl_replace(&pd->factory, NULL);
692
693 efl_ui_list_view_seg_array_flush(pd->seg_array);
694 efl_unref(pd->seg_array);
690 695
696 eina_stringshare_del(pd->style);
691 efl_destructor(efl_super(obj, MY_CLASS)); 697 efl_destructor(efl_super(obj, MY_CLASS));
692} 698}
693 699
694EOLIAN static void 700EOLIAN static void
695_efl_ui_list_view_layout_factory_set(Eo *obj EINA_UNUSED, Efl_Ui_List_View_Data *pd, Efl_Ui_Factory *factory) 701_efl_ui_list_view_layout_factory_set(Eo *obj EINA_UNUSED, Efl_Ui_List_View_Data *pd, Efl_Ui_Factory *factory)
696{ 702{
697 if (pd->factory) 703 efl_replace(&pd->factory, factory);
698 efl_unref(pd->factory);
699
700 pd->factory = factory;
701 efl_ref(pd->factory);
702} 704}
703 705
704EOLIAN static void 706EOLIAN static void
705_efl_ui_list_view_efl_ui_view_model_set(Eo *obj EINA_UNUSED, Efl_Ui_List_View_Data *pd, Efl_Model *model) 707_efl_ui_list_view_efl_ui_view_model_set(Eo *obj EINA_UNUSED, Efl_Ui_List_View_Data *pd, Efl_Model *model)
706{ 708{
707 if (pd->model == model) 709 if (!efl_replace(&pd->model, model))
708 return; 710 return;
709 711
710 if (pd->model) 712 efl_ui_list_view_seg_array_flush(pd->seg_array);
711 {
712 if (pd->relayout)
713 efl_ui_list_view_relayout_model_set(pd->relayout, NULL);
714 efl_ui_list_view_seg_array_flush(pd->seg_array);
715 }
716
717 efl_replace(&pd->model, model);
718 713
719 if (pd->model && pd->relayout) 714 if (pd->relayout)
720 efl_ui_list_view_relayout_model_set(pd->relayout, pd->model); 715 efl_ui_list_view_relayout_model_set(pd->relayout, pd->model);
721 716
722 evas_object_smart_changed(pd->obj); 717 evas_object_smart_changed(pd->obj);
@@ -815,7 +810,7 @@ _efl_ui_list_view_item_select_set(Efl_Ui_List_View_Layout_Item *item, Eina_Bool
815 if (_efl_model_properties_has(item->children, sprop)) 810 if (_efl_model_properties_has(item->children, sprop))
816 { 811 {
817 Eina_Value v; 812 Eina_Value v;
818 eina_value_setup(&v, EINA_VALUE_TYPE_UCHAR); 813 eina_value_setup(&v, EINA_VALUE_TYPE_BOOL);
819 eina_value_set(&v, selected); 814 eina_value_set(&v, selected);
820 efl_model_property_set(item->children, sprop, &v); 815 efl_model_property_set(item->children, sprop, &v);
821 eina_value_flush(&v); 816 eina_value_flush(&v);
@@ -826,8 +821,7 @@ _efl_ui_list_view_item_select_set(Efl_Ui_List_View_Layout_Item *item, Eina_Bool
826static void 821static void
827_efl_ui_list_view_relayout_set(Eo *obj EINA_UNUSED, Efl_Ui_List_View_Data *pd EINA_UNUSED, Efl_Ui_List_View_Relayout *object) 822_efl_ui_list_view_relayout_set(Eo *obj EINA_UNUSED, Efl_Ui_List_View_Data *pd EINA_UNUSED, Efl_Ui_List_View_Relayout *object)
828{ 823{
829 efl_replace(&pd->relayout, object); 824 if (efl_replace(&pd->relayout, object) && pd->model && pd->relayout)
830 if (pd->model && pd->relayout)
831 efl_ui_list_view_relayout_model_set(pd->relayout, pd->model); 825 efl_ui_list_view_relayout_model_set(pd->relayout, pd->model);
832} 826}
833 827
@@ -912,9 +906,13 @@ EOLIAN static Efl_Ui_List_View_Layout_Item *
912_efl_ui_list_view_efl_ui_list_view_model_realize(Eo *obj, Efl_Ui_List_View_Data *pd, Efl_Ui_List_View_Layout_Item *item) 906_efl_ui_list_view_efl_ui_list_view_model_realize(Eo *obj, Efl_Ui_List_View_Data *pd, Efl_Ui_List_View_Layout_Item *item)
913{ 907{
914 Efl_Ui_List_View_Item_Event evt; 908 Efl_Ui_List_View_Item_Event evt;
915 EINA_SAFETY_ON_NULL_RETURN_VAL(item->children, item); 909 EINA_SAFETY_ON_NULL_RETURN_VAL(item, NULL);
910
911 if (!item->children)
912 return item;
916 913
917 item->layout = efl_ui_factory_create(pd->factory, item->children, obj); 914 item->layout = efl_ui_factory_create(pd->factory, item->children, obj);
915 EINA_SAFETY_ON_NULL_RETURN_VAL(item->layout, NULL);
918 evas_object_smart_member_add(item->layout, pd->pan_obj); 916 evas_object_smart_member_add(item->layout, pd->pan_obj);
919 evas_object_event_callback_add(item->layout, EVAS_CALLBACK_MOUSE_UP, _on_item_mouse_up, item); 917 evas_object_event_callback_add(item->layout, EVAS_CALLBACK_MOUSE_UP, _on_item_mouse_up, item);
920 918
@@ -938,13 +936,16 @@ EOLIAN static void
938_efl_ui_list_view_efl_ui_list_view_model_unrealize(Eo *obj, Efl_Ui_List_View_Data *pd, Efl_Ui_List_View_Layout_Item *item) 936_efl_ui_list_view_efl_ui_list_view_model_unrealize(Eo *obj, Efl_Ui_List_View_Data *pd, Efl_Ui_List_View_Layout_Item *item)
939{ 937{
940 Efl_Ui_List_View_Item_Event evt; 938 Efl_Ui_List_View_Item_Event evt;
941 EINA_SAFETY_ON_NULL_RETURN(item->layout); 939 EINA_SAFETY_ON_NULL_RETURN(item);
940
941 if (!item->layout)
942 return;
942 943
943 evas_object_event_callback_del_full(item->layout, EVAS_CALLBACK_MOUSE_UP, _on_item_mouse_up, item); 944 evas_object_event_callback_del_full(item->layout, EVAS_CALLBACK_MOUSE_UP, _on_item_mouse_up, item);
944 if (elm_object_focus_allow_get(item->layout)) 945 if (elm_object_focus_allow_get(item->layout))
945 { 946 {
946 if (elm_object_focus_get(item->layout)) 947 if (efl_ui_focus_object_focus_get(item->layout))
947 elm_object_focus_set(item->layout, EINA_FALSE); 948 efl_ui_focus_object_focus_set(item->layout, EINA_FALSE);
948 efl_ui_focus_manager_calc_unregister(obj, item->layout); 949 efl_ui_focus_manager_calc_unregister(obj, item->layout);
949 } 950 }
950 evas_object_hide(item->layout); 951 evas_object_hide(item->layout);
@@ -955,8 +956,8 @@ _efl_ui_list_view_efl_ui_list_view_model_unrealize(Eo *obj, Efl_Ui_List_View_Dat
955 evt.index = efl_ui_list_view_item_index_get(item); 956 evt.index = efl_ui_list_view_item_index_get(item);
956 efl_event_callback_call(obj, EFL_UI_LIST_VIEW_EVENT_ITEM_UNREALIZED, &evt); 957 efl_event_callback_call(obj, EFL_UI_LIST_VIEW_EVENT_ITEM_UNREALIZED, &evt);
957 958
958 evas_object_smart_member_del(item->layout);
959 efl_ui_factory_release(pd->factory, item->layout); 959 efl_ui_factory_release(pd->factory, item->layout);
960 evas_object_smart_member_del(item->layout);
960 item->layout = NULL; 961 item->layout = NULL;
961} 962}
962 963
diff --git a/src/lib/elementary/efl_ui_list_view_precise_layouter.c b/src/lib/elementary/efl_ui_list_view_precise_layouter.c
index 3beac4d468..9b6ba9f0ad 100644
--- a/src/lib/elementary/efl_ui_list_view_precise_layouter.c
+++ b/src/lib/elementary/efl_ui_list_view_precise_layouter.c
@@ -325,14 +325,15 @@ _initilize(Eo *obj EINA_UNUSED, Efl_Ui_List_View_Precise_Layouter_Data *pd, Efl_
325 if(pd->initialized) 325 if(pd->initialized)
326 return EINA_TRUE; 326 return EINA_TRUE;
327 327
328 if(!pd->model || !pd->count_total) 328 efl_replace(&pd->modeler, modeler);
329
330 if(!pd->model || !pd->modeler)
329 return EINA_FALSE; 331 return EINA_FALSE;
330 332
331 pd->recalc = EINA_TRUE; 333 pd->recalc = EINA_TRUE;
332 pd->initialized = EINA_TRUE; 334 pd->initialized = EINA_TRUE;
333 335
334 pd->modeler = modeler; 336 efl_replace(&pd->seg_array, seg_array);
335 pd->seg_array = seg_array;
336 337
337 efl_ui_list_view_model_load_range_set(pd->modeler, 0, pd->count_total); // load all 338 efl_ui_list_view_model_load_range_set(pd->modeler, 0, pd->count_total); // load all
338 efl_event_callback_add(pd->model, EFL_MODEL_EVENT_CHILD_ADDED, _child_added_cb, pd); 339 efl_event_callback_add(pd->model, EFL_MODEL_EVENT_CHILD_ADDED, _child_added_cb, pd);
@@ -351,27 +352,36 @@ _finalize(Eo *obj EINA_UNUSED, Efl_Ui_List_View_Precise_Layouter_Data *pd)
351 Efl_Ui_List_View_Seg_Array_Node* node; 352 Efl_Ui_List_View_Seg_Array_Node* node;
352 int i = 0; 353 int i = 0;
353 354
354 evas_object_event_callback_del_full(pd->modeler, EVAS_CALLBACK_RESIZE, _on_modeler_resize, pd); 355 if (pd->model)
355 efl_event_callback_del(pd->model, EFL_MODEL_EVENT_CHILD_ADDED, _child_added_cb, pd);
356 efl_event_callback_del(pd->model, EFL_MODEL_EVENT_CHILD_REMOVED, _child_removed_cb, pd);
357 pd->count_total = 0;
358
359 Eina_Accessor *nodes = efl_ui_list_view_seg_array_node_accessor_get(pd->seg_array);
360 EINA_ACCESSOR_FOREACH(nodes, i, node)
361 { 356 {
362 _node_unrealize(pd, node); 357 efl_event_callback_del(pd->model, EFL_MODEL_EVENT_CHILD_ADDED, _child_added_cb, pd);
363 free(node->layout_data); 358 efl_event_callback_del(pd->model, EFL_MODEL_EVENT_CHILD_REMOVED, _child_removed_cb, pd);
359 pd->count_total = 0;
364 } 360 }
365 361
366 eina_accessor_free(nodes); 362 if (pd->seg_array)
363 {
364 Eina_Accessor *nodes = efl_ui_list_view_seg_array_node_accessor_get(pd->seg_array);
365 EINA_ACCESSOR_FOREACH(nodes, i, node)
366 {
367 _node_unrealize(pd, node);
368 free(node->layout_data);
369 }
370
371 eina_accessor_free(nodes);
372 }
367 373
368 pd->min.w = 0; 374 pd->min.w = 0;
369 pd->min.h = 0; 375 pd->min.h = 0;
370 376
371 efl_ui_list_view_model_min_size_set(pd->modeler, pd->min); 377 if (pd->modeler)
378 {
379 evas_object_event_callback_del_full(pd->modeler, EVAS_CALLBACK_RESIZE, _on_modeler_resize, pd);
380 efl_ui_list_view_model_min_size_set(pd->modeler, pd->min);
381 }
372 382
373 pd->seg_array = NULL; 383 efl_replace(&pd->seg_array, NULL);
374 pd->modeler = NULL; 384 efl_replace(&pd->modeler, NULL);
375 385
376 pd->initialized = EINA_FALSE; 386 pd->initialized = EINA_FALSE;
377 pd->recalc = EINA_TRUE; 387 pd->recalc = EINA_TRUE;
@@ -567,7 +577,8 @@ _efl_ui_list_view_precise_layouter_efl_ui_list_view_relayout_elements_get(const
567 } 577 }
568 } 578 }
569 579
570 return elements_order; 580 eina_accessor_free(nodes);
581 return elements_order;
571} 582}
572 583
573EOLIAN static void 584EOLIAN static void
@@ -682,7 +693,7 @@ _efl_ui_list_view_precise_layouter_efl_ui_list_view_relayout_layout_do
682 (Eo *obj EINA_UNUSED, Efl_Ui_List_View_Precise_Layouter_Data *pd 693 (Eo *obj EINA_UNUSED, Efl_Ui_List_View_Precise_Layouter_Data *pd
683 , Efl_Ui_List_View_Model *modeler, int first, Efl_Ui_List_View_Seg_Array *seg_array) 694 , Efl_Ui_List_View_Model *modeler, int first, Efl_Ui_List_View_Seg_Array *seg_array)
684{ 695{
685 if (!_initilize(obj, pd, modeler, seg_array)) 696 if (!_initilize(obj, pd, modeler, seg_array) || !pd->seg_array)
686 return; 697 return;
687 698
688 pd->first = first; 699 pd->first = first;
diff --git a/src/lib/elementary/efl_ui_list_view_seg_array.c b/src/lib/elementary/efl_ui_list_view_seg_array.c
index bf379a6a07..8c6c0ed154 100644
--- a/src/lib/elementary/efl_ui_list_view_seg_array.c
+++ b/src/lib/elementary/efl_ui_list_view_seg_array.c
@@ -56,7 +56,6 @@ static Eina_Rbtree_Direction _rbtree_compare(Efl_Ui_List_View_Seg_Array_Node con
56 return EINA_RBTREE_RIGHT; 56 return EINA_RBTREE_RIGHT;
57} 57}
58 58
59
60static void 59static void
61_free_node(Efl_Ui_List_View_Seg_Array_Node* node, void* data EINA_UNUSED) 60_free_node(Efl_Ui_List_View_Seg_Array_Node* node, void* data EINA_UNUSED)
62{ 61{
@@ -64,8 +63,10 @@ _free_node(Efl_Ui_List_View_Seg_Array_Node* node, void* data EINA_UNUSED)
64 63
65 while (i < node->length) 64 while (i < node->length)
66 { 65 {
67 free(node->pointers[i]); 66 Efl_Ui_List_View_Layout_Item* item = node->pointers[i];
68 ++i; 67 efl_unref(item->children);
68 free(item);
69 ++i;
69 } 70 }
70 71
71 free(node); 72 free(node);
@@ -98,7 +99,7 @@ _efl_ui_list_view_seg_array_flush(Eo* obj EINA_UNUSED, Efl_Ui_List_View_Seg_Arra
98static Efl_Ui_List_View_Layout_Item* _create_item_partial(Efl_Model* model) 99static Efl_Ui_List_View_Layout_Item* _create_item_partial(Efl_Model* model)
99{ 100{
100 Efl_Ui_List_View_Layout_Item* item = calloc(1, sizeof(Efl_Ui_List_View_Layout_Item)); 101 Efl_Ui_List_View_Layout_Item* item = calloc(1, sizeof(Efl_Ui_List_View_Layout_Item));
101 item->children = model; 102 item->children = efl_ref(model);
102 return item; 103 return item;
103} 104}
104 105