summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>2015-07-26 21:10:14 +0200
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2015-07-26 21:10:14 +0200
commit3f2e54eeabe0378f2f893bdc6fba545bea5585d1 (patch)
tree05407c76a7259dca84df500759e0494066520e21
parent9ecb6f73524c1b3849f8487becf7b21726bf7af4 (diff)
elm_items_display: Moved selection behaviour into the display
-rw-r--r--src/lib/items/elm_items_display.c76
-rw-r--r--src/lib/items/elm_items_display.eo12
-rw-r--r--src/lib/items/elm_items_list.c77
-rw-r--r--src/lib/items/elm_items_priv.h2
4 files changed, 89 insertions, 78 deletions
diff --git a/src/lib/items/elm_items_display.c b/src/lib/items/elm_items_display.c
index ee87490..994b051 100644
--- a/src/lib/items/elm_items_display.c
+++ b/src/lib/items/elm_items_display.c
@@ -369,16 +369,60 @@ _elm_items_display_item_search_xywh(Eo *obj EINA_UNUSED, Elm_Items_Display_Data
369 } 369 }
370 return items; 370 return items;
371} 371}
372
373
372//================================== 374//==================================
373// Selection tracking 375// Selection tracking
374//================================== 376//==================================
375 377
378EOLIAN static void
379_elm_items_display_selection_mode_set(Eo *obj EINA_UNUSED, Elm_Items_Display_Data *pd, Elm_Items_Selection_Mode mode)
380{
381 pd->mode = mode;
382}
383
384EOLIAN static Elm_Items_Selection_Mode
385_elm_items_display_selection_mode_get(Eo *obj EINA_UNUSED, Elm_Items_Display_Data *pd)
386{
387 return pd->mode;
388}
389
376static Eina_Bool 390static Eina_Bool
377_selected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED) 391_selected(void *data, Eo *obj, const Eo_Event_Description2 *desc EINA_UNUSED, void *event EINA_UNUSED)
378{ 392{
379 Elm_Items_Display_Data *pd; 393 Elm_Items_Display_Data *pd;
380 394
381 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS); 395 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS);
396
397 //a select mode change is keeping the list up to date for itself
398 if (pd->select_mode_change) return EO_CALLBACK_CONTINUE;
399
400 //mark that we are keeping track of the list
401 pd->select_mode_change = EINA_TRUE;
402 switch(pd->mode)
403 {
404 //we dont do something if it is touchmode
405 case ELM_ITEMS_SELECTION_MODE_MULTISELECT_CRTL:
406 //if ctrl mode is set just select
407 if (evas_key_modifier_is_set(evas_key_modifier_get(evas_object_evas_get(obj)), "Control"))
408 break;
409 case ELM_ITEMS_SELECTION_MODE_SINGLESELECT:
410 if (eina_list_count(pd->selected) > 0)
411 {
412 Elm_Items_Item *it;
413
414 EINA_LIST_FREE(pd->selected, it)
415 {
416 eo_do(it, elm_items_item_selected_set(EINA_FALSE));
417 }
418
419 pd->selected = NULL;
420 }
421 break;
422 case ELM_ITEMS_SELECTION_MODE_MULTISELECT_TOUCH:
423 break;
424 }
425 pd->select_mode_change = EINA_FALSE;
382 pd->selected = eina_list_append(pd->selected, obj); 426 pd->selected = eina_list_append(pd->selected, obj);
383 return EO_CALLBACK_CONTINUE; 427 return EO_CALLBACK_CONTINUE;
384} 428}
@@ -389,6 +433,36 @@ _unselected(void *data, Eo *obj, const Eo_Event_Description2 *desc EINA_UNUSED,
389 Elm_Items_Display_Data *pd; 433 Elm_Items_Display_Data *pd;
390 434
391 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS); 435 pd = eo_data_scope_get(data, ELM_ITEMS_DISPLAY_CLASS);
436
437 //a select mode change is keeping the list up to date for itself
438 if (pd->select_mode_change) return EO_CALLBACK_CONTINUE;
439
440 //mark that we are keeping track of the list
441 pd->select_mode_change = EINA_TRUE;
442 switch(pd->mode)
443 {
444 case ELM_ITEMS_SELECTION_MODE_MULTISELECT_CRTL:
445 //if ctrl key is not pressed unselect all the
446 if (!evas_key_modifier_is_set(evas_key_modifier_get(evas_object_evas_get(obj)), "Control"))
447 {
448 Elm_Items_Item *it;
449
450 EINA_LIST_FREE(pd->selected, it)
451 eo_do(it, elm_items_item_selected_set(EINA_FALSE));
452
453 pd->selected = NULL;
454 //reselect this item
455 eo_do(obj, elm_items_item_selected_set(EINA_TRUE));
456 pd->selected = eina_list_append(pd->selected, obj);
457 pd->select_mode_change = EINA_FALSE;
458 return EO_CALLBACK_CONTINUE;
459 }
460 case ELM_ITEMS_SELECTION_MODE_SINGLESELECT:
461 break;
462 case ELM_ITEMS_SELECTION_MODE_MULTISELECT_TOUCH:
463 break;
464 }
465 pd->select_mode_change = EINA_FALSE;
392 pd->selected = eina_list_remove(pd->selected, obj); 466 pd->selected = eina_list_remove(pd->selected, obj);
393 return EO_CALLBACK_CONTINUE; 467 return EO_CALLBACK_CONTINUE;
394} 468}
diff --git a/src/lib/items/elm_items_display.eo b/src/lib/items/elm_items_display.eo
index a0d0ff2..0677e0f 100644
--- a/src/lib/items/elm_items_display.eo
+++ b/src/lib/items/elm_items_display.eo
@@ -13,6 +13,12 @@ struct Elm.Items.Rect {
13 h : int; 13 h : int;
14} 14}
15 15
16enum Elm.Items.Selection_Mode {
17 singleselect = 0,
18 multiselect_crtl,
19 multiselect_touch
20}
21
16abstract Elm.Items.Display (Elm.Scroller) { 22abstract Elm.Items.Display (Elm.Scroller) {
17 [[Abstraction for widgets which wants to place Elm.Items.Item´s]] 23 [[Abstraction for widgets which wants to place Elm.Items.Item´s]]
18 methods { 24 methods {
@@ -44,7 +50,11 @@ abstract Elm.Items.Display (Elm.Scroller) {
44 search : const(char)*; 50 search : const(char)*;
45 } 51 }
46 } 52 }
47 53 @property selection_mode {
54 values {
55 mode : Elm.Items.Selection_Mode;
56 }
57 }
48 @property selected { 58 @property selected {
49 get { 59 get {
50 60
diff --git a/src/lib/items/elm_items_list.c b/src/lib/items/elm_items_list.c
index 1aed339..48783f3 100644
--- a/src/lib/items/elm_items_list.c
+++ b/src/lib/items/elm_items_list.c
@@ -125,91 +125,17 @@ _elm_items_list_evas_object_smart_add(Eo *obj, Elm_Items_List_Data *pd EINA_UNUS
125} 125}
126 126
127static Eina_Bool 127static Eina_Bool
128_selected(void *data, Eo *obj, const Eo_Event_Description *desc EINA_UNUSED, void *event EINA_UNUSED) 128_add(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event)
129{
130 Elm_Items_List_Data *pd;
131 Elm_Items_Item *sel;
132 const Evas_Modifier *mods;
133 Eina_List *selection;
134
135 pd = eo_data_scope_get(data, ELM_ITEMS_LIST_CLASS);
136 eo_do(data, selection = elm_items_display_selected_get());
137
138 mods = evas_key_modifier_get(evas_object_evas_get(obj));
139
140 if (!evas_key_modifier_is_set(mods, "Control"))
141 {
142 Eina_List *selected;
143
144 selected = eina_list_clone(selection);
145 //stop unselecting work
146 pd->unselect_barrier = EINA_TRUE;
147 EINA_LIST_FREE(selected, sel)
148 {
149 if (sel == obj) continue;
150 eo_do(sel, elm_items_item_selected_set(EINA_FALSE));
151 }
152 //restart unselecting work
153 pd->unselect_barrier = EINA_FALSE;
154 }
155 return EO_CALLBACK_CONTINUE;
156}
157
158static Eina_Bool
159_unselected(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event EINA_UNUSED)
160{
161 Elm_Items_List_Data *pd;
162 const Evas_Modifier *mods;
163 Eina_List *selection;
164
165 pd = eo_data_scope_get(data, ELM_ITEMS_LIST_CLASS);
166 eo_do(data, selection = elm_items_display_selected_get());
167 if (pd->unselect_barrier) return EO_CALLBACK_CONTINUE;
168
169 mods = evas_key_modifier_get(evas_object_evas_get(data));
170
171 if (!evas_key_modifier_is_set(mods, "Control"))
172 {
173 if (eina_list_count(selection) > 1)
174 eo_do(obj, elm_items_item_selected_set(EINA_TRUE));
175
176 }
177 return EO_CALLBACK_CONTINUE;
178}
179
180static Eina_Bool
181_add(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event)
182{ 129{
183 Eo *good; 130 Eo *good;
184 131
185 eo_do(event, good = efl_tree_base_carry_get()); 132 eo_do(event, good = efl_tree_base_carry_get());
186 //subscribe to item events
187 eo_do(good, eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_SELECTED, _selected, data);
188 eo_event_callback_add(ELM_ITEMS_ITEM_EVENT_UNSELECTED, _unselected, data);
189 );
190 133
191 //set hints 134 //set hints
192 evas_object_size_hint_min_set(good, 1, HACKY_HEIGHT); 135 evas_object_size_hint_min_set(good, 1, HACKY_HEIGHT);
193 evas_object_size_hint_align_set(good, EVAS_HINT_FILL, 1.0); 136 evas_object_size_hint_align_set(good, EVAS_HINT_FILL, 1.0);
194 evas_object_size_hint_weight_set(good, EVAS_HINT_EXPAND, 0.0); 137 evas_object_size_hint_weight_set(good, EVAS_HINT_EXPAND, 0.0);
195 138
196 //show the item
197 evas_object_show(good);
198
199 return EO_CALLBACK_CONTINUE;
200}
201
202static Eina_Bool
203_del(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event)
204{
205 Eo *good;
206
207 eo_do(event, good = efl_tree_base_carry_get());
208
209 eo_do(good, eo_event_callback_del(ELM_ITEMS_ITEM_EVENT_SELECTED, _selected, data);
210 eo_event_callback_del(ELM_ITEMS_ITEM_EVENT_UNSELECTED, _unselected, data);
211 );
212
213 return EO_CALLBACK_CONTINUE; 139 return EO_CALLBACK_CONTINUE;
214} 140}
215 141
@@ -232,7 +158,6 @@ _elm_items_list_eo_base_constructor(Eo *obj, Elm_Items_List_Data *pd)
232 //monitor changes on the tree 158 //monitor changes on the tree
233 eo_do(pd->root, 159 eo_do(pd->root,
234 eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_ADD_DIRECT, _add, obj); 160 eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_ADD_DIRECT, _add, obj);
235 eo_event_callback_add(EFL_TREE_BASE_EVENT_CHILDREN_DEL_DIRECT, _del, obj);
236 ); 161 );
237 return eo; 162 return eo;
238} 163}
diff --git a/src/lib/items/elm_items_priv.h b/src/lib/items/elm_items_priv.h
index 9c03709..d427016 100644
--- a/src/lib/items/elm_items_priv.h
+++ b/src/lib/items/elm_items_priv.h
@@ -48,6 +48,8 @@ typedef struct {
48 Eina_List *realitems; //< the list of really available items 48 Eina_List *realitems; //< the list of really available items
49 Eo *pan; 49 Eo *pan;
50 Ecore_Idler *realitems_idler; 50 Ecore_Idler *realitems_idler;
51 Elm_Items_Selection_Mode mode;
52 Eina_Bool select_mode_change; //< set if the selection_mode going on right now
51} Elm_Items_Display_Data; 53} Elm_Items_Display_Data;
52 54
53#endif \ No newline at end of file 55#endif \ No newline at end of file