1 #include <Elementary.h>
3 #include "els_scroller.h"
7 typedef struct _Widget_Data Widget_Data;
8 typedef struct _Elm_List_Item Elm_List_Item;
12 Evas_Object *scr, *box, *self;
13 Eina_List *items, *selected, *to_delete;
14 Elm_Object_Item *last_selected_item;
17 Evas_Coord minw[2], minh[2];
18 Elm_Object_Select_Mode select_mode;
24 } history[SWIPE_MOVES];
25 Eina_Bool scr_minw : 1;
26 Eina_Bool scr_minh : 1;
28 Eina_Bool fix_pending : 1;
29 Eina_Bool on_hold : 1;
31 Eina_Bool longpressed : 1;
32 Eina_Bool wasselected : 1;
41 Evas_Object *icon, *end;
43 Ecore_Timer *long_timer;
44 Ecore_Timer *swipe_timer;
45 Eina_Bool deleted : 1;
47 Eina_Bool is_even : 1;
48 Eina_Bool is_separator : 1;
50 Eina_Bool selected : 1;
51 Eina_Bool highlighted : 1;
52 Eina_Bool dummy_icon : 1;
53 Eina_Bool dummy_end : 1;
56 static const char *widtype = NULL;
57 static void _del_hook(Evas_Object *obj);
58 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
59 static void _theme_hook(Evas_Object *obj);
60 static void _sizing_eval(Evas_Object *obj);
61 static void _disable_hook(Evas_Object *obj);
62 static void _on_focus_hook(void *data, Evas_Object *obj);
63 static void _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source);
64 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
65 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
66 static void _fix_items(Evas_Object *obj);
67 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
68 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
69 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
70 static void _edge_left(void *data, Evas_Object *scr, void *event_info);
71 static void _edge_right(void *data, Evas_Object *scr, void *event_info);
72 static void _edge_top(void *data, Evas_Object *scr, void *event_info);
73 static void _edge_bottom(void *data, Evas_Object *scr, void *event_info);
74 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
75 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
76 static Eina_Bool _item_single_select_up(Widget_Data *wd);
77 static Eina_Bool _item_single_select_down(Widget_Data *wd);
78 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
79 Evas_Callback_Type type, void *event_info);
80 static Eina_Bool _deselect_all_items(Widget_Data *wd);
82 static const char SIG_ACTIVATED[] = "activated";
83 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
84 static const char SIG_SELECTED[] = "selected";
85 static const char SIG_UNSELECTED[] = "unselected";
86 static const char SIG_LONGPRESSED[] = "longpressed";
87 static const char SIG_EDGE_TOP[] = "edge,top";
88 static const char SIG_EDGE_BOTTOM[] = "edge,bottom";
89 static const char SIG_EDGE_LEFT[] = "edge,left";
90 static const char SIG_EDGE_RIGHT[] = "edge,right";
92 static const Evas_Smart_Cb_Description _signals[] = {
94 {SIG_CLICKED_DOUBLE, ""},
97 {SIG_LONGPRESSED, ""},
99 {SIG_EDGE_BOTTOM, ""},
101 {SIG_EDGE_RIGHT, ""},
105 #define ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ...) \
106 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, __VA_ARGS__); \
107 if (((Elm_List_Item *)it)->deleted) \
109 ERR("ERROR: "#it" has been DELETED.\n"); \
110 return __VA_ARGS__; \
114 _elm_list_item_free(Elm_List_Item *it)
116 evas_object_event_callback_del_full
117 (VIEW(it), EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, it);
118 evas_object_event_callback_del_full
119 (VIEW(it), EVAS_CALLBACK_MOUSE_UP, _mouse_up, it);
120 evas_object_event_callback_del_full
121 (VIEW(it), EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, it);
124 evas_object_event_callback_del_full
125 (it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
126 _changed_size_hints, WIDGET(it));
129 evas_object_event_callback_del_full
130 (it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
131 _changed_size_hints, WIDGET(it));
133 eina_stringshare_del(it->label);
135 if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
136 it->swipe_timer = NULL;
137 if (it->long_timer) ecore_timer_del(it->long_timer);
138 it->long_timer = NULL;
139 if (it->icon) evas_object_del(it->icon);
140 if (it->end) evas_object_del(it->end);
144 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
146 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
147 Evas_Event_Key_Down *ev = event_info;
148 Widget_Data *wd = elm_widget_data_get(obj);
149 if (!wd) return EINA_FALSE;
150 if (!wd->items) return EINA_FALSE;
151 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
152 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
154 Elm_List_Item *it = NULL;
157 Evas_Coord step_x = 0;
158 Evas_Coord step_y = 0;
161 Evas_Coord page_x = 0;
162 Evas_Coord page_y = 0;
164 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
165 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
166 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
167 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
169 /* TODO: fix logic for horizontal mode */
170 if ((!strcmp(ev->keyname, "Left")) ||
171 ((!strcmp(ev->keyname, "KP_Left")) && !ev->string))
174 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
175 (_item_multi_select_up(wd)))
176 || (_item_single_select_up(wd))))
178 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
184 else if ((!strcmp(ev->keyname, "Right")) ||
185 ((!strcmp(ev->keyname, "KP_Right")) && !ev->string))
188 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
189 (_item_multi_select_down(wd)))
190 || (_item_single_select_down(wd))))
192 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
198 else if ((!strcmp(ev->keyname, "Up")) ||
199 ((!strcmp(ev->keyname, "KP_Up")) && !ev->string))
202 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
203 (_item_multi_select_up(wd)))
204 || (_item_single_select_up(wd))))
206 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
212 else if ((!strcmp(ev->keyname, "Down")) ||
213 ((!strcmp(ev->keyname, "KP_Down")) && !ev->string))
216 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
217 (_item_multi_select_down(wd)))
218 || (_item_single_select_down(wd))))
220 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
226 else if ((!strcmp(ev->keyname, "Home")) ||
227 ((!strcmp(ev->keyname, "KP_Home")) && !ev->string))
229 it = eina_list_data_get(wd->items);
230 elm_list_item_bring_in((Elm_Object_Item *)it);
231 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
234 else if ((!strcmp(ev->keyname, "End")) ||
235 ((!strcmp(ev->keyname, "KP_End")) && !ev->string))
237 it = eina_list_data_get(eina_list_last(wd->items));
238 elm_list_item_bring_in((Elm_Object_Item *)it);
239 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
242 else if ((!strcmp(ev->keyname, "Prior")) ||
243 ((!strcmp(ev->keyname, "KP_Prior")) && !ev->string))
248 x -= -(page_x * v_w) / 100;
255 y -= -(page_y * v_h) / 100;
260 else if ((!strcmp(ev->keyname, "Next")) ||
261 ((!strcmp(ev->keyname, "KP_Next")) && !ev->string))
266 x += -(page_x * v_w) / 100;
273 y += -(page_y * v_h) / 100;
278 else if (((!strcmp(ev->keyname, "Return")) ||
279 (!strcmp(ev->keyname, "KP_Enter")) ||
280 (!strcmp(ev->keyname, "space")))
281 && (!wd->multi) && (wd->selected))
283 it = (Elm_List_Item *) elm_list_selected_item_get(obj);
284 evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it);
286 else if (!strcmp(ev->keyname, "Escape"))
288 if (!_deselect_all_items(wd)) return EINA_FALSE;
289 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
292 else return EINA_FALSE;
294 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
295 elm_smart_scroller_child_pos_set(wd->scr, x, y);
300 _translate_hook(Evas_Object *obj)
302 evas_object_smart_callback_call(obj, "language,changed", NULL);
306 _deselect_all_items(Widget_Data *wd)
308 if (!wd->selected) return EINA_FALSE;
310 elm_list_item_selected_set((Elm_Object_Item *) wd->selected->data,
317 _item_multi_select_up(Widget_Data *wd)
319 if (!wd->selected) return EINA_FALSE;
320 if (!wd->multi) return EINA_FALSE;
322 Elm_Object_Item *prev = elm_list_item_prev(wd->last_selected_item);
323 if (!prev) return EINA_TRUE;
325 if (elm_list_item_selected_get(prev))
327 elm_list_item_selected_set(wd->last_selected_item, EINA_FALSE);
328 wd->last_selected_item = prev;
329 elm_list_item_show(wd->last_selected_item);
333 elm_list_item_selected_set(prev, EINA_TRUE);
334 elm_list_item_show(prev);
340 _item_multi_select_down(Widget_Data *wd)
342 if (!wd->selected) return EINA_FALSE;
343 if (!wd->multi) return EINA_FALSE;
345 Elm_Object_Item *next = elm_list_item_next(wd->last_selected_item);
346 if (!next) return EINA_TRUE;
348 if (elm_list_item_selected_get(next))
350 elm_list_item_selected_set(wd->last_selected_item, EINA_FALSE);
351 wd->last_selected_item = next;
352 elm_list_item_show(wd->last_selected_item);
356 elm_list_item_selected_set(next, EINA_TRUE);
357 elm_list_item_show(next);
363 _item_single_select_up(Widget_Data *wd)
365 Elm_Object_Item *prev;
367 if (!wd->selected) prev = eina_list_data_get(eina_list_last(wd->items));
368 else prev = elm_list_item_prev(wd->last_selected_item);
369 if (!prev) return EINA_FALSE;
371 _deselect_all_items(wd);
373 elm_list_item_selected_set(prev, EINA_TRUE);
374 elm_list_item_show(prev);
379 _item_single_select_down(Widget_Data *wd)
381 Elm_Object_Item *next;
383 if (!wd->selected) next = eina_list_data_get(wd->items);
384 else next = elm_list_item_next(wd->last_selected_item);
385 if (!next) return EINA_FALSE;
387 _deselect_all_items(wd);
389 elm_list_item_selected_set(next, EINA_TRUE);
390 elm_list_item_show(next);
395 _elm_list_process_deletions(Widget_Data *wd)
399 wd->walking++; // avoid nested deletion and also _sub_del() fix_items
401 EINA_LIST_FREE(wd->to_delete, it)
403 wd->items = eina_list_remove_list(wd->items, it->node);
404 _elm_list_item_free(it);
405 elm_widget_item_free(it);
412 _elm_list_walk(Widget_Data *wd)
416 ERR("ERROR: walking was negative. fixed!\n");
423 _elm_list_unwalk(Widget_Data *wd)
428 ERR("ERROR: walking became negative. fixed!\n");
436 _elm_list_process_deletions(wd);
440 wd->fix_pending = EINA_FALSE;
441 _fix_items(wd->self);
442 _sizing_eval(wd->self);
447 _del_pre_hook(Evas_Object *obj)
449 Widget_Data *wd = elm_widget_data_get(obj);
453 evas_object_smart_callback_del(obj, "sub-object-del", _sub_del);
457 EINA_LIST_FOREACH(wd->items, l, it)
460 evas_object_event_callback_del(it->icon,
461 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
462 _changed_size_hints);
464 evas_object_event_callback_del(it->end,
465 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
466 _changed_size_hints);
469 evas_object_event_callback_del(wd->scr,
470 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
471 _changed_size_hints);
472 evas_object_event_callback_del(wd->box,
473 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
474 _changed_size_hints);
478 _del_hook(Evas_Object *obj)
480 Widget_Data *wd = elm_widget_data_get(obj);
486 ERR("ERROR: list deleted while walking.\n");
489 EINA_LIST_FOREACH(wd->items, n, it) elm_widget_item_pre_notify_del(it);
490 _elm_list_unwalk(wd);
492 ERR("ERROR: leaking nodes!\n");
494 EINA_LIST_FREE(wd->items, it)
496 _elm_list_item_free(it);
497 elm_widget_item_free(it);
499 eina_list_free(wd->selected);
504 _show_region_hook(void *data, Evas_Object *obj)
506 Widget_Data *wd = elm_widget_data_get(data);
507 Evas_Coord x, y, w, h;
509 elm_widget_show_region_get(obj, &x, &y, &w, &h);
510 elm_smart_scroller_child_region_set(wd->scr, x, y, w, h);
514 _disable_hook(Evas_Object *obj)
516 Widget_Data *wd = elm_widget_data_get(obj);
518 if (elm_widget_disabled_get(obj))
520 _signal_emit_hook(obj, "elm,state,disabled", "elm");
521 elm_widget_scroll_freeze_push(obj);
522 elm_widget_scroll_hold_push(obj);
523 /* FIXME: if we get to have a way to only un-highlight items
524 * in the future, keeping them selected... */
525 _deselect_all_items(wd);
529 _signal_emit_hook(obj, "elm,state,enabled", "elm");
530 elm_widget_scroll_freeze_pop(obj);
531 elm_widget_scroll_hold_pop(obj);
536 _sizing_eval(Evas_Object *obj)
539 Widget_Data *wd = elm_widget_data_get(obj);
541 Evas_Coord vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
544 evas_object_size_hint_min_get(wd->box, &minw, &minh);
545 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
546 evas_object_size_hint_weight_get(wd->box, &xw, &yw);
547 if (!wd->scr) return;
548 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
551 if ((minw > 0) && (vw < minw)) vw = minw;
552 else if ((maxw > 0) && (vw > maxw)) vw = maxw;
554 else if (minw > 0) vw = minw;
557 if ((minh > 0) && (vh < minh)) vh = minh;
558 else if ((maxh > 0) && (vh > maxh)) vh = maxh;
560 else if (minh > 0) vh = minh;
561 evas_object_resize(wd->box, vw, vh);
564 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
566 if (wd->scr_minw) w = vmw + minw;
567 if (wd->scr_minh) h = vmh + minh;
569 evas_object_size_hint_max_get(obj, &maxw, &maxh);
570 if ((maxw > 0) && (w > maxw))
572 if ((maxh > 0) && (h > maxh))
575 evas_object_size_hint_min_set(obj, w, h);
579 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
581 Widget_Data *wd = elm_widget_data_get(obj);
582 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
587 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
589 Widget_Data *wd = elm_widget_data_get(obj);
590 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
591 emission, source, func_cb, data);
595 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
597 Widget_Data *wd = elm_widget_data_get(obj);
598 edje_object_signal_callback_del_full(
599 elm_smart_scroller_edje_object_get(wd->scr),
600 emission, source, func_cb, data);
604 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
606 Widget_Data *wd = elm_widget_data_get(obj);
612 elm_smart_scroller_mirrored_set(wd->scr, rtl);
614 EINA_LIST_FOREACH(wd->items, n, it)
615 edje_object_mirrored_set(VIEW(it), rtl);
619 _theme_hook(Evas_Object *obj)
621 Widget_Data *wd = elm_widget_data_get(obj);
626 _elm_widget_mirrored_reload(obj);
627 _mirrored_set(obj, elm_widget_mirrored_get(obj));
634 elm_smart_scroller_object_theme_set(obj, wd->scr, "list", "base",
635 elm_widget_style_get(obj));
636 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
637 edj = elm_smart_scroller_edje_object_get(wd->scr);
638 str = edje_object_data_get(edj, "focus_highlight");
639 if ((str) && (!strcmp(str, "on")))
640 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
642 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
643 elm_object_style_set(wd->scr, elm_widget_style_get(obj));
645 EINA_LIST_FOREACH(wd->items, n, it)
647 edje_object_scale_set(VIEW(it), elm_widget_scale_get(obj) * _elm_config->scale);
655 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
657 Widget_Data *wd = elm_widget_data_get(obj);
659 if (elm_widget_focus_get(obj))
661 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
662 evas_object_focus_set(wd->self, EINA_TRUE);
664 if ((wd->selected) && (!wd->last_selected_item))
665 wd->last_selected_item = eina_list_data_get(wd->selected);
669 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
670 evas_object_focus_set(wd->self, EINA_FALSE);
675 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
677 Widget_Data *wd = elm_widget_data_get(data);
684 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
686 Widget_Data *wd = elm_widget_data_get(obj);
687 Evas_Object *sub = event_info;
693 if ((sub == wd->box) || (sub == wd->scr)) return;
695 EINA_LIST_FOREACH(wd->items, l, it)
697 if ((sub == it->icon) || (sub == it->end))
699 if (it->icon == sub) it->icon = NULL;
700 if (it->end == sub) it->end = NULL;
701 evas_object_event_callback_del_full
702 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints,
710 wd->fix_pending = EINA_TRUE;
717 _item_highlight(Elm_List_Item *it)
719 Evas_Object *obj = WIDGET(it);
720 Widget_Data *wd = elm_widget_data_get(obj);
721 const char *selectraise;
724 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
725 if ((it->highlighted) || (it->base.disabled) ||
726 (wd->select_mode == ELM_OBJECT_SELECT_MODE_NONE)) return;
728 evas_object_ref(obj);
731 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
732 selectraise = edje_object_data_get(VIEW(it), "selectraise");
733 if ((selectraise) && (!strcmp(selectraise, "on")))
734 evas_object_raise(VIEW(it));
735 it->highlighted = EINA_TRUE;
737 _elm_list_unwalk(wd);
738 evas_object_unref(obj);
742 _item_select(Elm_List_Item *it)
744 Evas_Object *obj = WIDGET(it);
745 Widget_Data *wd = elm_widget_data_get(obj);
748 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
749 if (it->base.disabled || (wd->select_mode == ELM_OBJECT_SELECT_MODE_NONE)) return;
752 if (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) goto call;
755 it->selected = EINA_TRUE;
756 wd->selected = eina_list_append(wd->selected, it);
759 evas_object_ref(obj);
762 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
763 evas_object_smart_callback_call(obj, SIG_SELECTED, it);
764 it->wd->last_selected_item = (Elm_Object_Item *)it;
766 _elm_list_unwalk(wd);
767 evas_object_unref(obj);
771 _item_unselect(Elm_List_Item *it)
773 Evas_Object *obj = WIDGET(it);
774 Widget_Data *wd = elm_widget_data_get(obj);
775 const char *stacking, *selectraise;
778 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
779 if (!it->highlighted) return;
781 evas_object_ref(obj);
784 edje_object_signal_emit(VIEW(it), "elm,state,unselected", "elm");
785 stacking = edje_object_data_get(VIEW(it), "stacking");
786 selectraise = edje_object_data_get(VIEW(it), "selectraise");
787 if ((selectraise) && (!strcmp(selectraise, "on")))
789 if ((stacking) && (!strcmp(stacking, "below")))
790 evas_object_lower(VIEW(it));
792 it->highlighted = EINA_FALSE;
795 it->selected = EINA_FALSE;
796 wd->selected = eina_list_remove(wd->selected, it);
797 evas_object_smart_callback_call(WIDGET(it), SIG_UNSELECTED, it);
800 _elm_list_unwalk(wd);
801 evas_object_unref(obj);
805 _swipe_cancel(void *data)
807 Elm_List_Item *it = data;
808 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
810 if (!wd) return ECORE_CALLBACK_CANCEL;
811 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
812 wd->swipe = EINA_FALSE;
814 return ECORE_CALLBACK_RENEW;
818 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
820 Elm_List_Item *it = data;
821 Evas_Object *obj2 = WIDGET(it);
822 Widget_Data *wd = elm_widget_data_get(obj2);
823 Evas_Event_Mouse_Move *ev = event_info;
826 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
828 evas_object_ref(obj2);
831 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
835 wd->on_hold = EINA_TRUE;
838 ecore_timer_del(it->long_timer);
839 it->long_timer = NULL;
841 if (!wd->wasselected)
844 if (wd->movements == SWIPE_MOVES) wd->swipe = EINA_TRUE;
847 wd->history[wd->movements].x = ev->cur.canvas.x;
848 wd->history[wd->movements].y = ev->cur.canvas.y;
849 if (abs((wd->history[wd->movements].x - wd->history[0].x)) > 40)
850 wd->swipe = EINA_TRUE;
856 _elm_list_unwalk(wd);
857 evas_object_unref(obj2);
861 _edge_left(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
863 Evas_Object *obj = data;
864 evas_object_smart_callback_call(obj, SIG_EDGE_LEFT, NULL);
868 _edge_right(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
870 Evas_Object *obj = data;
871 evas_object_smart_callback_call(obj, SIG_EDGE_RIGHT, NULL);
875 _edge_top(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
877 Evas_Object *obj = data;
878 evas_object_smart_callback_call(obj, SIG_EDGE_TOP, NULL);
882 _edge_bottom(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
884 Evas_Object *obj = data;
885 evas_object_smart_callback_call(obj, SIG_EDGE_BOTTOM, NULL);
889 _long_press(void *data)
891 Elm_List_Item *it = data;
892 Evas_Object *obj = WIDGET(it);
893 Widget_Data *wd = elm_widget_data_get(obj);
897 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
898 it->long_timer = NULL;
899 if (it->base.disabled) goto end;
901 wd->longpressed = EINA_TRUE;
902 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
905 return ECORE_CALLBACK_CANCEL;
909 _swipe(Elm_List_Item *it)
912 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
914 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
916 wd->swipe = EINA_FALSE;
917 for (i = 0; i < wd->movements; i++)
919 sum += wd->history[i].x;
920 if (abs(wd->history[0].y - wd->history[i].y) > 10) return;
923 sum /= wd->movements;
924 if (abs(sum - wd->history[0].x) <= 10) return;
925 evas_object_smart_callback_call(WIDGET(it), "swipe", it);
929 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
931 Elm_List_Item *it = data;
932 Evas_Object *obj2 = WIDGET(it);
933 Widget_Data *wd = elm_widget_data_get(obj2);
934 Evas_Event_Mouse_Down *ev = event_info;
937 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
938 if (ev->button != 1) return;
939 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
940 else wd->on_hold = EINA_FALSE;
941 if (wd->on_hold) return;
942 wd->wasselected = it->selected;
944 evas_object_ref(obj2);
948 wd->longpressed = EINA_FALSE;
949 if (it->long_timer) ecore_timer_del(it->long_timer);
950 it->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, it);
951 if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
952 it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
953 /* Always call the callbacks last - the user may delete our context! */
954 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
956 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
957 evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it);
959 wd->swipe = EINA_FALSE;
962 _elm_list_unwalk(wd);
963 evas_object_unref(obj2);
967 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
969 Elm_List_Item *it = data;
970 Evas_Object *obj2 = WIDGET(it);
971 Widget_Data *wd = elm_widget_data_get(obj2);
972 Evas_Event_Mouse_Up *ev = event_info;
975 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
976 if (ev->button != 1) return;
977 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
978 else wd->on_hold = EINA_FALSE;
979 wd->longpressed = EINA_FALSE;
982 ecore_timer_del(it->long_timer);
983 it->long_timer = NULL;
987 ecore_timer_del(it->swipe_timer);
988 it->swipe_timer = NULL;
992 if (wd->swipe) _swipe(data);
993 wd->on_hold = EINA_FALSE;
998 if (!wd->wasselected) _item_unselect(it);
1003 if (it->base.disabled)
1005 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1007 evas_object_ref(obj2);
1014 _item_highlight(it);
1017 else _item_unselect(it);
1023 while (wd->selected)
1024 _item_unselect(wd->selected->data);
1025 _item_highlight(it);
1030 const Eina_List *l, *l_next;
1033 EINA_LIST_FOREACH_SAFE(wd->selected, l, l_next, it2)
1034 if (it2 != it) _item_unselect(it2);
1035 _item_highlight(it);
1040 _elm_list_unwalk(wd);
1041 evas_object_unref(obj2);
1045 _item_disable(Elm_Object_Item *it)
1047 Elm_List_Item *item = (Elm_List_Item *)it;
1048 if (item->base.disabled)
1049 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
1051 edje_object_signal_emit(VIEW(item), "elm,state,enabled", "elm");
1055 _item_content_set_hook(Elm_Object_Item *it, const char *part, Evas_Object *content)
1057 Elm_List_Item *item = (Elm_List_Item *)it;
1058 Evas_Object **icon_p = NULL;
1059 Eina_Bool dummy = EINA_FALSE;
1061 if ((!part) || (!strcmp(part, "start")))
1063 icon_p = &(item->icon);
1064 dummy = item->dummy_icon;
1065 if (!content) item->dummy_icon = EINA_TRUE;
1066 else item->dummy_icon = EINA_FALSE;
1068 else if (!strcmp(part, "end"))
1070 icon_p = &(item->end);
1071 dummy = item->dummy_end;
1072 if (!content) item->dummy_end = EINA_TRUE;
1073 else item->dummy_end = EINA_FALSE;
1078 if (content == *icon_p) return;
1079 if ((dummy) && (!content)) return;
1080 if (dummy) evas_object_del(*icon_p);
1083 content = evas_object_rectangle_add(evas_object_evas_get(WIDGET(item)));
1084 evas_object_color_set(content, 0, 0, 0, 0);
1088 evas_object_del(*icon_p);
1093 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", content);
1096 static Evas_Object *
1097 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
1099 Elm_List_Item *item = (Elm_List_Item *)it;
1101 if ((!part) || (!strcmp(part, "start")))
1103 if (item->dummy_icon) return NULL;
1106 else if (!strcmp(part, "end"))
1108 if (item->dummy_end) return NULL;
1114 static Evas_Object *
1115 _item_content_unset_hook(const Elm_Object_Item *it, const char *part)
1117 Elm_List_Item *item = (Elm_List_Item *)it;
1119 if ((!part) || (!strcmp(part, "start")))
1121 Evas_Object *obj = item->icon;
1122 _item_content_set_hook((Elm_Object_Item *)it, part, NULL);
1125 else if (!strcmp(part, "end"))
1127 Evas_Object *obj = item->end;
1128 _item_content_set_hook((Elm_Object_Item *)it, part, NULL);
1135 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *text)
1137 Elm_List_Item *list_it = (Elm_List_Item *)it;
1138 if (part && strcmp(part, "default")) return;
1139 if (!eina_stringshare_replace(&list_it->label, text)) return;
1141 edje_object_part_text_set(VIEW(list_it), "elm.text", text);
1145 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
1147 if (part && strcmp(part, "default")) return NULL;
1148 return ((Elm_List_Item *)it)->label;
1152 _item_del_pre_hook(Elm_Object_Item *it)
1154 Evas_Object *obj = WIDGET(it);
1155 Elm_List_Item *item = (Elm_List_Item *)it;
1156 Widget_Data *wd = elm_widget_data_get(obj);
1157 if (!wd) return EINA_FALSE;
1159 if (item->selected) _item_unselect(item);
1161 if (wd->walking > 0)
1163 if (item->deleted) return EINA_FALSE;
1164 item->deleted = EINA_TRUE;
1165 wd->to_delete = eina_list_append(wd->to_delete, item);
1169 wd->items = eina_list_remove_list(wd->items, item->node);
1171 evas_object_ref(obj);
1174 _elm_list_item_free(item);
1176 _elm_list_unwalk(wd);
1177 evas_object_unref(obj);
1182 static Elm_List_Item *
1183 _item_new(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1185 Widget_Data *wd = elm_widget_data_get(obj);
1188 if (!wd) return NULL;
1189 it = elm_widget_item_new(obj, Elm_List_Item);
1191 it->label = eina_stringshare_add(label);
1195 it->base.data = data;
1196 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
1197 edje_object_mirrored_set(VIEW(it), elm_widget_mirrored_get(obj));
1198 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
1200 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
1202 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1204 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1205 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
1208 elm_widget_sub_object_add(obj, it->icon);
1209 evas_object_event_callback_add(it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1210 _changed_size_hints, obj);
1214 elm_widget_sub_object_add(obj, it->end);
1215 evas_object_event_callback_add(it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1216 _changed_size_hints, obj);
1218 elm_widget_item_disable_hook_set(it, _item_disable);
1219 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
1220 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
1221 elm_widget_item_content_unset_hook_set(it, _item_content_unset_hook);
1222 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
1223 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
1224 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
1229 _elm_list_mode_set_internal(Widget_Data *wd)
1234 if (wd->mode == ELM_LIST_LIMIT)
1238 wd->scr_minw = EINA_TRUE;
1239 wd->scr_minh = EINA_FALSE;
1243 wd->scr_minw = EINA_FALSE;
1244 wd->scr_minh = EINA_TRUE;
1247 else if (wd->mode == ELM_LIST_EXPAND)
1249 wd->scr_minw = EINA_TRUE;
1250 wd->scr_minh = EINA_TRUE;
1254 wd->scr_minw = EINA_FALSE;
1255 wd->scr_minh = EINA_FALSE;
1258 _sizing_eval(wd->self);
1262 _fix_items(Evas_Object *obj)
1264 Widget_Data *wd = elm_widget_data_get(obj);
1268 Evas_Coord minw[2] = { 0, 0 }, minh[2] = { 0, 0 };
1271 const char *style = elm_widget_style_get(obj);
1272 const char *it_plain = wd->h_mode ? "h_item" : "item";
1273 const char *it_odd = wd->h_mode ? "h_item_odd" : "item_odd";
1274 const char *it_compress = wd->h_mode ? "h_item_compress" : "item_compress";
1275 const char *it_compress_odd = wd->h_mode ? "h_item_compress_odd" : "item_compress_odd";
1279 wd->fix_pending = EINA_TRUE;
1283 evas_object_ref(obj);
1284 _elm_list_walk(wd); // watch out "return" before unwalk!
1286 EINA_LIST_FOREACH(wd->items, l, it)
1288 if (it->deleted) continue;
1291 evas_object_size_hint_min_get(it->icon, &mw, &mh);
1292 if (mw > minw[0]) minw[0] = mw;
1293 if (mh > minh[0]) minh[0] = mh;
1297 evas_object_size_hint_min_get(it->end, &mw, &mh);
1298 if (mw > minw[1]) minw[1] = mw;
1299 if (mh > minh[1]) minh[1] = mh;
1303 if ((minw[0] != wd->minw[0]) || (minw[1] != wd->minw[1]) ||
1304 (minw[0] != wd->minh[0]) || (minh[1] != wd->minh[1]))
1306 wd->minw[0] = minw[0];
1307 wd->minw[1] = minw[1];
1308 wd->minh[0] = minh[0];
1309 wd->minh[1] = minh[1];
1313 EINA_LIST_FOREACH(wd->items, l, it)
1319 if ((it->even != it->is_even) || (!it->fixed) || (redo))
1321 const char *stacking;
1323 /* FIXME: separators' themes seem to be b0rked */
1324 if (it->is_separator)
1325 _elm_theme_object_set(obj, VIEW(it), "separator",
1326 wd->h_mode ? "horizontal" : "vertical",
1328 else if (wd->mode == ELM_LIST_COMPRESS)
1331 _elm_theme_object_set(obj, VIEW(it), "list",
1332 it_compress, style);
1334 _elm_theme_object_set(obj, VIEW(it), "list",
1335 it_compress_odd, style);
1340 _elm_theme_object_set(obj, VIEW(it), "list", it_plain,
1343 _elm_theme_object_set(obj, VIEW(it), "list", it_odd,
1346 stacking = edje_object_data_get(VIEW(it), "stacking");
1349 if (!strcmp(stacking, "below"))
1350 evas_object_lower(VIEW(it));
1351 else if (!strcmp(stacking, "above"))
1352 evas_object_raise(VIEW(it));
1354 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1356 if ((!it->icon) && (minh[0] > 0))
1358 it->icon = evas_object_rectangle_add(evas_object_evas_get(VIEW(it)));
1359 evas_object_color_set(it->icon, 0, 0, 0, 0);
1360 it->dummy_icon = EINA_TRUE;
1362 if ((!it->end) && (minh[1] > 0))
1364 it->end = evas_object_rectangle_add(evas_object_evas_get(VIEW(it)));
1365 evas_object_color_set(it->end, 0, 0, 0, 0);
1366 it->dummy_end = EINA_TRUE;
1370 evas_object_size_hint_min_set(it->icon, minw[0], minh[0]);
1371 evas_object_size_hint_max_set(it->icon, 99999, 99999);
1372 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
1376 evas_object_size_hint_min_set(it->end, minw[1], minh[1]);
1377 evas_object_size_hint_max_set(it->end, 99999, 99999);
1378 edje_object_part_swallow(VIEW(it), "elm.swallow.end", it->end);
1382 // this may call up user and it may modify the list item
1383 // but we're safe as we're flagged as walking.
1384 // just don't process further
1385 edje_object_message_signal_process(VIEW(it));
1389 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1390 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
1391 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1392 evas_object_size_hint_min_set(VIEW(it), mw, mh);
1393 evas_object_show(VIEW(it));
1395 if ((it->selected) || (it->highlighted))
1397 const char *selectraise;
1399 // this may call up user and it may modify the list item
1400 // but we're safe as we're flagged as walking.
1401 // just don't process further
1402 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
1406 selectraise = edje_object_data_get(VIEW(it), "selectraise");
1407 if ((selectraise) && (!strcmp(selectraise, "on")))
1408 evas_object_raise(VIEW(it));
1410 if (it->base.disabled)
1411 edje_object_signal_emit(VIEW(it), "elm,state,disabled",
1414 it->fixed = EINA_TRUE;
1415 it->is_even = it->even;
1421 evas_object_size_hint_min_get(wd->box, &mw, &mh);
1423 _elm_list_mode_set_internal(wd);
1425 _elm_list_unwalk(wd);
1426 evas_object_unref(obj);
1430 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1432 Widget_Data *wd = elm_widget_data_get(obj);
1435 elm_smart_scroller_hold_set(wd->scr, EINA_TRUE);
1439 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1441 Widget_Data *wd = elm_widget_data_get(obj);
1444 elm_smart_scroller_hold_set(wd->scr, EINA_FALSE);
1448 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1450 Widget_Data *wd = elm_widget_data_get(obj);
1453 elm_smart_scroller_freeze_set(wd->scr, EINA_TRUE);
1457 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1459 Widget_Data *wd = elm_widget_data_get(obj);
1462 elm_smart_scroller_freeze_set(wd->scr, EINA_FALSE);
1466 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1472 elm_list_add(Evas_Object *parent)
1477 Evas_Coord minw, minh;
1479 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1481 ELM_SET_WIDTYPE(widtype, "list");
1482 elm_widget_type_set(obj, "list");
1483 elm_widget_sub_object_add(parent, obj);
1484 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1485 elm_widget_data_set(obj, wd);
1486 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1487 elm_widget_del_hook_set(obj, _del_hook);
1488 elm_widget_theme_hook_set(obj, _theme_hook);
1489 elm_widget_disable_hook_set(obj, _disable_hook);
1490 elm_widget_can_focus_set(obj, EINA_TRUE);
1491 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1492 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1493 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1494 elm_widget_event_hook_set(obj, _event_hook);
1495 elm_widget_translate_hook_set(obj, _translate_hook);
1498 wd->scr = elm_smart_scroller_add(e);
1499 elm_smart_scroller_widget_set(wd->scr, obj);
1500 elm_widget_resize_object_set(obj, wd->scr);
1501 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1502 _changed_size_hints, obj);
1503 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
1504 evas_object_size_hint_min_set(obj, minw, minh);
1505 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
1507 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
1508 _elm_config->thumbscroll_bounce_enable);
1510 wd->box = elm_box_add(parent);
1511 elm_box_homogeneous_set(wd->box, 1);
1512 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1513 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1514 elm_widget_on_show_region_hook_set(wd->box, _show_region_hook, obj);
1515 elm_widget_sub_object_add(obj, wd->box);
1516 elm_smart_scroller_child_set(wd->scr, wd->box);
1517 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1518 _changed_size_hints, obj);
1520 evas_object_show(wd->box);
1524 wd->mode = ELM_LIST_SCROLL;
1526 evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
1527 evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
1528 evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
1529 evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom, obj);
1531 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1532 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1533 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1534 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1535 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1537 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1539 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1545 elm_list_go(Evas_Object *obj)
1547 ELM_CHECK_WIDTYPE(obj, widtype);
1548 Widget_Data *wd = elm_widget_data_get(obj);
1554 elm_list_multi_select_set(Evas_Object *obj, Eina_Bool multi)
1556 ELM_CHECK_WIDTYPE(obj, widtype);
1557 Widget_Data *wd = elm_widget_data_get(obj);
1563 elm_list_multi_select_get(const Evas_Object *obj)
1565 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1566 Widget_Data *wd = elm_widget_data_get(obj);
1567 if (!wd) return EINA_FALSE;
1572 elm_list_mode_set(Evas_Object *obj, Elm_List_Mode mode)
1574 ELM_CHECK_WIDTYPE(obj, widtype);
1578 wd = elm_widget_data_get(obj);
1581 if (wd->mode == mode)
1585 _elm_list_mode_set_internal(wd);
1589 elm_list_mode_get(const Evas_Object *obj)
1591 ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
1592 Widget_Data *wd = elm_widget_data_get(obj);
1593 if (!wd) return ELM_LIST_LAST;
1598 elm_list_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1600 ELM_CHECK_WIDTYPE(obj, widtype);
1603 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1605 wd = elm_widget_data_get(obj);
1609 if (wd->h_mode == horizontal)
1612 wd->h_mode = horizontal;
1613 elm_box_horizontal_set(wd->box, horizontal);
1617 evas_object_size_hint_weight_set(wd->box, 0.0, EVAS_HINT_EXPAND);
1618 evas_object_size_hint_align_set(wd->box, 0.0, EVAS_HINT_FILL);
1619 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1623 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1624 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1625 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE, bounce);
1628 _elm_list_mode_set_internal(wd);
1632 elm_list_horizontal_get(const Evas_Object *obj)
1634 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1638 wd = elm_widget_data_get(obj);
1646 elm_list_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
1648 ELM_CHECK_WIDTYPE(obj, widtype);
1649 Widget_Data *wd = elm_widget_data_get(obj);
1651 if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
1653 if (wd->select_mode != mode)
1654 wd->select_mode = mode;
1657 EAPI Elm_Object_Select_Mode
1658 elm_list_select_mode_get(const Evas_Object *obj)
1660 ELM_CHECK_WIDTYPE(obj, widtype) ELM_OBJECT_SELECT_MODE_MAX;
1661 Widget_Data *wd = elm_widget_data_get(obj);
1662 if (!wd) return ELM_OBJECT_SELECT_MODE_MAX;
1663 return wd->select_mode;
1667 elm_list_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1669 ELM_CHECK_WIDTYPE(obj, widtype);
1670 Widget_Data *wd = elm_widget_data_get(obj);
1673 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1677 elm_list_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1679 ELM_CHECK_WIDTYPE(obj, widtype);
1680 Widget_Data *wd = elm_widget_data_get(obj);
1682 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
1686 elm_list_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1688 ELM_CHECK_WIDTYPE(obj, widtype);
1689 Widget_Data *wd = elm_widget_data_get(obj);
1690 if ((!wd) || (!wd->scr)) return;
1691 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1692 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1694 elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
1698 elm_list_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1700 ELM_CHECK_WIDTYPE(obj, widtype);
1701 Widget_Data *wd = elm_widget_data_get(obj);
1702 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1703 if ((!wd) || (!wd->scr)) return;
1704 elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
1705 if (policy_h) *policy_h = (Elm_Scroller_Policy) s_policy_h;
1706 if (policy_v) *policy_v = (Elm_Scroller_Policy) s_policy_v;
1710 elm_list_clear(Evas_Object *obj)
1712 ELM_CHECK_WIDTYPE(obj, widtype);
1713 Widget_Data *wd = elm_widget_data_get(obj);
1717 if (!wd->items) return;
1719 eina_list_free(wd->selected);
1720 wd->selected = NULL;
1722 if (wd->walking > 0)
1726 EINA_LIST_FOREACH(wd->items, n, it)
1728 if (it->deleted) continue;
1729 it->deleted = EINA_TRUE;
1730 wd->to_delete = eina_list_append(wd->to_delete, it);
1735 evas_object_ref(obj);
1738 EINA_LIST_FREE(wd->items, it)
1740 _elm_list_item_free(it);
1741 elm_widget_item_free(it);
1744 _elm_list_unwalk(wd);
1748 evas_object_unref(obj);
1751 EAPI const Eina_List *
1752 elm_list_items_get(const Evas_Object *obj)
1754 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1755 Widget_Data *wd = elm_widget_data_get(obj);
1756 if (!wd) return NULL;
1760 EAPI Elm_Object_Item *
1761 elm_list_selected_item_get(const Evas_Object *obj)
1763 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1764 Widget_Data *wd = elm_widget_data_get(obj);
1765 if (!wd) return NULL;
1766 if (wd->selected) return (Elm_Object_Item *) wd->selected->data;
1770 EAPI const Eina_List *
1771 elm_list_selected_items_get(const Evas_Object *obj)
1773 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1774 Widget_Data *wd = elm_widget_data_get(obj);
1775 if (!wd) return NULL;
1776 return wd->selected;
1779 EAPI Elm_Object_Item *
1780 elm_list_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1782 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1783 Widget_Data *wd = elm_widget_data_get(obj);
1784 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1786 wd->items = eina_list_append(wd->items, it);
1787 it->node = eina_list_last(wd->items);
1788 elm_box_pack_end(wd->box, VIEW(it));
1789 return (Elm_Object_Item *)it;
1792 EAPI Elm_Object_Item *
1793 elm_list_item_prepend(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1795 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1796 Widget_Data *wd = elm_widget_data_get(obj);
1797 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1799 wd->items = eina_list_prepend(wd->items, it);
1800 it->node = wd->items;
1801 elm_box_pack_start(wd->box, VIEW(it));
1802 return (Elm_Object_Item *)it;
1805 EAPI Elm_Object_Item *
1806 elm_list_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1808 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1809 ELM_LIST_ITEM_CHECK_DELETED_RETURN(before, NULL);
1812 Elm_List_Item *it, *before_it;
1814 wd = elm_widget_data_get(obj);
1815 if (!wd) return NULL;
1817 before_it = (Elm_List_Item *) before;
1818 if (!before_it->node) return NULL;
1820 it = _item_new(obj, label, icon, end, func, data);
1821 wd->items = eina_list_prepend_relative_list(wd->items, it, before_it->node);
1822 it->node = before_it->node->prev;
1823 elm_box_pack_before(wd->box, VIEW(it), VIEW(before_it));
1824 return (Elm_Object_Item *)it;
1827 EAPI Elm_Object_Item *
1828 elm_list_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1830 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1831 ELM_LIST_ITEM_CHECK_DELETED_RETURN(after, NULL);
1834 Elm_List_Item *it, *after_it;
1836 wd = elm_widget_data_get(obj);
1837 if (!wd) return NULL;
1839 after_it = (Elm_List_Item *) after;
1840 if (!after_it->node) return NULL;
1842 it = _item_new(obj, label, icon, end, func, data);
1843 wd->items = eina_list_append_relative_list(wd->items, it, after_it->node);
1844 it->node = after_it->node->next;
1845 elm_box_pack_after(wd->box, VIEW(it), VIEW(after_it));
1846 return (Elm_Object_Item *)it;
1849 EAPI Elm_Object_Item *
1850 elm_list_item_sorted_insert(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data, Eina_Compare_Cb cmp_func)
1852 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1853 Widget_Data *wd = elm_widget_data_get(obj);
1854 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1857 wd->items = eina_list_sorted_insert(wd->items, cmp_func, it);
1858 l = eina_list_data_find_list(wd->items, it);
1859 l = eina_list_next(l);
1862 it->node = eina_list_last(wd->items);
1863 elm_box_pack_end(wd->box, VIEW(it));
1867 Elm_List_Item *before = eina_list_data_get(l);
1868 it->node = before->node->prev;
1869 elm_box_pack_before(wd->box, VIEW(it), VIEW(before));
1871 return (Elm_Object_Item *)it;
1875 elm_list_item_separator_set(Elm_Object_Item *it, Eina_Bool setting)
1877 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1878 ((Elm_List_Item *)it)->is_separator = !!setting;
1882 elm_list_item_separator_get(const Elm_Object_Item *it)
1884 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1885 return ((Elm_List_Item *)it)->is_separator;
1889 elm_list_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1891 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1892 Evas_Object *obj = WIDGET(it);
1893 Widget_Data *wd = elm_widget_data_get(obj);
1894 Elm_List_Item *item = (Elm_List_Item *)it;
1897 selected = !!selected;
1898 if (item->selected == selected) return;
1900 evas_object_ref(obj);
1907 while (wd->selected)
1908 _item_unselect(wd->selected->data);
1910 _item_highlight(item);
1914 _item_unselect(item);
1916 _elm_list_unwalk(wd);
1917 evas_object_unref(obj);
1921 elm_list_item_selected_get(const Elm_Object_Item *it)
1923 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1924 return ((Elm_List_Item *)it)->selected;
1928 elm_list_item_show(Elm_Object_Item *it)
1930 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1931 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1933 Evas_Coord bx, by, bw, bh;
1934 Evas_Coord x, y, w, h;
1936 evas_smart_objects_calculate(evas_object_evas_get(wd->box));
1937 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1938 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1941 if (wd->scr) elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
1945 elm_list_item_bring_in(Elm_Object_Item *it)
1947 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1948 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1950 Evas_Coord bx, by, bw, bh;
1951 Evas_Coord x, y, w, h;
1953 evas_smart_objects_calculate(evas_object_evas_get(wd->box));
1954 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1955 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1958 if (wd->scr) elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);
1962 elm_list_item_object_get(const Elm_Object_Item *it)
1964 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1968 EAPI Elm_Object_Item *
1969 elm_list_item_prev(const Elm_Object_Item *it)
1971 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1972 Elm_List_Item *item = (Elm_List_Item *)it;
1973 if (item->node->prev) return item->node->prev->data;
1977 EAPI Elm_Object_Item *
1978 elm_list_item_next(const Elm_Object_Item *it)
1980 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1981 Elm_List_Item *item = (Elm_List_Item *)it;
1982 if (item->node->next) return item->node->next->data;
1986 EAPI Elm_Object_Item *
1987 elm_list_first_item_get(const Evas_Object *obj)
1989 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1990 Widget_Data *wd = elm_widget_data_get(obj);
1991 if (!wd) return NULL;
1992 if (!wd->items) return NULL;
1993 return eina_list_data_get(wd->items);
1996 EAPI Elm_Object_Item *
1997 elm_list_last_item_get(const Evas_Object *obj)
1999 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2000 Widget_Data *wd = elm_widget_data_get(obj);
2001 if (!wd) return NULL;
2002 if (!wd->items) return NULL;
2003 return eina_list_data_get(eina_list_last(wd->items));