1 #include <Elementary.h>
9 * A list is a very simple type of list widget. For more robust
10 * lists, @ref Genlist should probably be used.
12 * Signals that you can add callbacks for are:
14 * "clicked" - when the user double-clicked an item
15 * "selected" - when the user selected an item
16 * "unselected" - when the user selected an item
17 * "longpressed" - an item in the hoversel list is long-pressed
18 * "scroll,edge,top" - the list is scrolled until the top edge
19 * "scroll,edge,bottom" - the list is scrolled until the bottom edge
20 * "scroll,edge,left" - the list is scrolled until the left edge
21 * "scroll,edge,right" - the list is scrolled until the right edge
24 typedef struct _Widget_Data Widget_Data;
28 Evas_Object *scr, *box, *self;
29 Eina_List *items, *selected, *to_delete;
30 Elm_List_Item *last_selected_item;
33 Evas_Coord minw[2], minh[2];
34 Eina_Bool scr_minw : 1;
35 Eina_Bool scr_minh : 1;
40 } history[SWIPE_MOVES];
42 Eina_Bool fix_pending : 1;
43 Eina_Bool on_hold : 1;
45 Eina_Bool always_select : 1;
46 Eina_Bool longpressed : 1;
47 Eina_Bool wasselected : 1;
56 Evas_Object *icon, *end;
58 Ecore_Timer *long_timer;
59 Ecore_Timer *swipe_timer;
60 Eina_Bool deleted : 1;
61 Eina_Bool disabled : 1;
63 Eina_Bool is_even : 1;
64 Eina_Bool is_separator : 1;
66 Eina_Bool selected : 1;
67 Eina_Bool hilighted : 1;
68 Eina_Bool dummy_icon : 1;
69 Eina_Bool dummy_end : 1;
72 static const char *widtype = NULL;
73 static void _del_hook(Evas_Object *obj);
74 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
75 static void _theme_hook(Evas_Object *obj);
76 static void _sizing_eval(Evas_Object *obj);
77 static void _disable_hook(Evas_Object *obj);
78 static void _on_focus_hook(void *data, Evas_Object *obj);
79 static void _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source);
80 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
81 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
82 static void _fix_items(Evas_Object *obj);
83 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
84 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
85 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
86 static void _scroll_edge_left(void *data, Evas_Object *scr, void *event_info);
87 static void _scroll_edge_right(void *data, Evas_Object *scr, void *event_info);
88 static void _scroll_edge_top(void *data, Evas_Object *scr, void *event_info);
89 static void _scroll_edge_bottom(void *data, Evas_Object *scr, void *event_info);
90 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
91 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
92 static Eina_Bool _item_single_select_up(Widget_Data *wd);
93 static Eina_Bool _item_single_select_down(Widget_Data *wd);
94 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
95 Evas_Callback_Type type, void *event_info);
96 static Eina_Bool _deselect_all_items(Widget_Data *wd);
98 #define ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ...) \
99 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, __VA_ARGS__); \
102 ERR("ERROR: "#it" has been DELETED.\n"); \
103 return __VA_ARGS__; \
107 _elm_list_item_free(Elm_List_Item *it)
109 evas_object_event_callback_del_full
110 (it->base.view, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, it);
111 evas_object_event_callback_del_full
112 (it->base.view, EVAS_CALLBACK_MOUSE_UP, _mouse_up, it);
113 evas_object_event_callback_del_full
114 (it->base.view, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, it);
117 evas_object_event_callback_del_full
118 (it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
119 _changed_size_hints, it->base.widget);
122 evas_object_event_callback_del_full
123 (it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
124 _changed_size_hints, it->base.widget);
126 eina_stringshare_del(it->label);
128 if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
129 if (it->long_timer) ecore_timer_del(it->long_timer);
130 if (it->icon) evas_object_del(it->icon);
131 if (it->end) evas_object_del(it->end);
133 elm_widget_item_del(it);
137 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
139 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
140 Evas_Event_Key_Down *ev = event_info;
141 Widget_Data *wd = elm_widget_data_get(obj);
142 if (!wd) return EINA_FALSE;
143 if (!wd->items) return EINA_FALSE;
144 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
145 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
147 Elm_List_Item *it = NULL;
150 Evas_Coord step_x = 0;
151 Evas_Coord step_y = 0;
154 Evas_Coord page_x = 0;
155 Evas_Coord page_y = 0;
157 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
158 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
159 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
160 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
162 /* TODO: fix logic for horizontal mode */
163 if ((!strcmp(ev->keyname, "Left")) ||
164 (!strcmp(ev->keyname, "KP_Left")))
167 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
168 (_item_multi_select_up(wd)))
169 || (_item_single_select_up(wd))))
171 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
177 else if ((!strcmp(ev->keyname, "Right")) ||
178 (!strcmp(ev->keyname, "KP_Right")))
181 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
182 (_item_multi_select_down(wd)))
183 || (_item_single_select_down(wd))))
185 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
191 else if ((!strcmp(ev->keyname, "Up")) ||
192 (!strcmp(ev->keyname, "KP_Up")))
195 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
196 (_item_multi_select_up(wd)))
197 || (_item_single_select_up(wd))))
199 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
205 else if ((!strcmp(ev->keyname, "Down")) ||
206 (!strcmp(ev->keyname, "KP_Down")))
209 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
210 (_item_multi_select_down(wd)))
211 || (_item_single_select_down(wd))))
213 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
219 else if ((!strcmp(ev->keyname, "Home")) ||
220 (!strcmp(ev->keyname, "KP_Home")))
222 it = eina_list_data_get(wd->items);
223 elm_list_item_bring_in(it);
224 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
227 else if ((!strcmp(ev->keyname, "End")) ||
228 (!strcmp(ev->keyname, "KP_End")))
230 it = eina_list_data_get(eina_list_last(wd->items));
231 elm_list_item_bring_in(it);
232 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
235 else if ((!strcmp(ev->keyname, "Prior")) ||
236 (!strcmp(ev->keyname, "KP_Prior")))
241 x -= -(page_x * v_w) / 100;
248 y -= -(page_y * v_h) / 100;
253 else if ((!strcmp(ev->keyname, "Next")) ||
254 (!strcmp(ev->keyname, "KP_Next")))
259 x += -(page_x * v_w) / 100;
266 y += -(page_y * v_h) / 100;
271 else if (!strcmp(ev->keyname, "Escape"))
273 if (!_deselect_all_items(wd)) return EINA_FALSE;
274 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
277 else return EINA_FALSE;
279 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
280 elm_smart_scroller_child_pos_set(wd->scr, x, y);
285 _deselect_all_items(Widget_Data *wd)
287 if (!wd->selected) return EINA_FALSE;
289 elm_list_item_selected_set(wd->selected->data, EINA_FALSE);
295 _item_multi_select_up(Widget_Data *wd)
297 if (!wd->selected) return EINA_FALSE;
298 if (!wd->multi) return EINA_FALSE;
300 Elm_List_Item *prev = elm_list_item_prev(wd->last_selected_item);
301 if (!prev) return EINA_TRUE;
303 if (elm_list_item_selected_get(prev))
305 elm_list_item_selected_set(wd->last_selected_item, EINA_FALSE);
306 wd->last_selected_item = prev;
307 elm_list_item_show(wd->last_selected_item);
311 elm_list_item_selected_set(prev, EINA_TRUE);
312 elm_list_item_show(prev);
318 _item_multi_select_down(Widget_Data *wd)
320 if (!wd->selected) return EINA_FALSE;
321 if (!wd->multi) return EINA_FALSE;
323 Elm_List_Item *next = elm_list_item_next(wd->last_selected_item);
324 if (!next) return EINA_TRUE;
326 if (elm_list_item_selected_get(next))
328 elm_list_item_selected_set(wd->last_selected_item, EINA_FALSE);
329 wd->last_selected_item = next;
330 elm_list_item_show(wd->last_selected_item);
334 elm_list_item_selected_set(next, EINA_TRUE);
335 elm_list_item_show(next);
341 _item_single_select_up(Widget_Data *wd)
345 if (!wd->selected) prev = eina_list_data_get(eina_list_last(wd->items));
346 else prev = elm_list_item_prev(wd->last_selected_item);
348 if (!prev) return EINA_FALSE;
350 _deselect_all_items(wd);
352 elm_list_item_selected_set(prev, EINA_TRUE);
353 elm_list_item_show(prev);
358 _item_single_select_down(Widget_Data *wd)
362 if (!wd->selected) next = eina_list_data_get(wd->items);
363 else next = elm_list_item_next(wd->last_selected_item);
365 if (!next) return EINA_FALSE;
367 _deselect_all_items(wd);
369 elm_list_item_selected_set(next, EINA_TRUE);
370 elm_list_item_show(next);
375 _elm_list_process_deletions(Widget_Data *wd)
379 wd->walking++; // avoid nested deletion and also _sub_del() fix_items
381 EINA_LIST_FREE(wd->to_delete, it)
383 elm_widget_item_pre_notify_del(it);
385 wd->items = eina_list_remove_list(wd->items, it->node);
386 _elm_list_item_free(it);
393 _elm_list_walk(Widget_Data *wd)
397 ERR("ERROR: walking was negative. fixed!\n");
404 _elm_list_unwalk(Widget_Data *wd)
409 ERR("ERROR: walking became negative. fixed!\n");
417 _elm_list_process_deletions(wd);
421 wd->fix_pending = EINA_FALSE;
422 _fix_items(wd->self);
423 _sizing_eval(wd->self);
428 _del_hook(Evas_Object *obj)
430 Widget_Data *wd = elm_widget_data_get(obj);
436 ERR("ERROR: list deleted while walking.\n");
439 EINA_LIST_FOREACH(wd->items, n, it) elm_widget_item_pre_notify_del(it);
440 _elm_list_unwalk(wd);
442 ERR("ERROR: leaking nodes!\n");
444 EINA_LIST_FREE(wd->items, it) _elm_list_item_free(it);
445 eina_list_free(wd->selected);
450 _show_region_hook(void *data, Evas_Object *obj)
452 Widget_Data *wd = elm_widget_data_get(data);
453 Evas_Coord x, y, w, h;
455 elm_widget_show_region_get(obj, &x, &y, &w, &h);
456 elm_smart_scroller_child_region_set(wd->scr, x, y, w, h);
460 _disable_hook(Evas_Object *obj)
462 Widget_Data *wd = elm_widget_data_get(obj);
464 if (elm_widget_disabled_get(obj))
466 _signal_emit_hook(obj, "elm,state,disabled", "elm");
467 elm_widget_scroll_freeze_push(obj);
468 elm_widget_scroll_hold_push(obj);
469 /* FIXME: if we get to have a way to only un-hilight items
470 * in the future, keeping them selected... */
471 _deselect_all_items(wd);
475 _signal_emit_hook(obj, "elm,state,enabled", "elm");
476 elm_widget_scroll_freeze_pop(obj);
477 elm_widget_scroll_hold_pop(obj);
482 _sizing_eval(Evas_Object *obj)
485 Widget_Data *wd = elm_widget_data_get(obj);
487 Evas_Coord vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
490 evas_object_size_hint_min_get(wd->box, &minw, &minh);
491 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
492 evas_object_size_hint_weight_get(wd->box, &xw, &yw);
493 if (!wd->scr) return;
494 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
497 if ((minw > 0) && (vw < minw)) vw = minw;
498 else if ((maxw > 0) && (vw > maxw)) vw = maxw;
500 else if (minw > 0) vw = minw;
503 if ((minh > 0) && (vh < minh)) vh = minh;
504 else if ((maxh > 0) && (vh > maxh)) vh = maxh;
506 else if (minh > 0) vh = minh;
507 evas_object_resize(wd->box, vw, vh);
510 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
512 if (wd->scr_minw) w = vmw + minw;
513 if (wd->scr_minh) h = vmh + minh;
515 evas_object_size_hint_max_get(obj, &maxw, &maxh);
516 if ((maxw > 0) && (w > maxw))
518 if ((maxh > 0) && (h > maxh))
521 evas_object_size_hint_min_set(obj, w, h);
525 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
527 Widget_Data *wd = elm_widget_data_get(obj);
528 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
533 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
535 Widget_Data *wd = elm_widget_data_get(obj);
536 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
537 emission, source, func_cb, data);
541 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
543 Widget_Data *wd = elm_widget_data_get(obj);
544 edje_object_signal_callback_del_full(
545 elm_smart_scroller_edje_object_get(wd->scr),
546 emission, source, func_cb, data);
550 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
552 Widget_Data *wd = elm_widget_data_get(obj);
558 elm_smart_scroller_mirrored_set(wd->scr, rtl);
560 EINA_LIST_FOREACH(wd->items, n, it)
561 edje_object_mirrored_set(it->base.view, rtl);
565 _theme_hook(Evas_Object *obj)
567 Widget_Data *wd = elm_widget_data_get(obj);
572 _elm_widget_mirrored_reload(obj);
573 _mirrored_set(obj, elm_widget_mirrored_get(obj));
580 elm_smart_scroller_object_theme_set(obj, wd->scr, "list", "base",
581 elm_widget_style_get(obj));
582 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
583 edj = elm_smart_scroller_edje_object_get(wd->scr);
584 str = edje_object_data_get(edj, "focus_highlight");
585 if ((str) && (!strcmp(str, "on")))
586 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
588 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
589 elm_object_style_set(wd->scr, elm_widget_style_get(obj));
591 EINA_LIST_FOREACH(wd->items, n, it)
593 edje_object_scale_set(it->base.view, elm_widget_scale_get(obj) * _elm_config->scale);
601 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
603 Widget_Data *wd = elm_widget_data_get(obj);
605 if (elm_widget_focus_get(obj))
607 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
608 evas_object_focus_set(wd->self, EINA_TRUE);
610 if ((wd->selected) && (!wd->last_selected_item))
611 wd->last_selected_item = eina_list_data_get(wd->selected);
615 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
616 evas_object_focus_set(wd->self, EINA_FALSE);
621 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
623 Widget_Data *wd = elm_widget_data_get(data);
630 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
632 Widget_Data *wd = elm_widget_data_get(obj);
633 Evas_Object *sub = event_info;
643 EINA_LIST_FOREACH(wd->items, l, it)
645 if ((sub == it->icon) || (sub == it->end))
647 if (it->icon == sub) it->icon = NULL;
648 if (it->end == sub) it->end = NULL;
649 evas_object_event_callback_del_full
650 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints,
658 wd->fix_pending = EINA_TRUE;
666 _item_hilight(Elm_List_Item *it)
668 Evas_Object *obj = it->base.widget;
669 Widget_Data *wd = elm_widget_data_get(obj);
670 const char *selectraise;
673 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
674 if (it->hilighted) return;
676 evas_object_ref(obj);
679 edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
680 selectraise = edje_object_data_get(it->base.view, "selectraise");
681 if ((selectraise) && (!strcmp(selectraise, "on")))
682 evas_object_raise(it->base.view);
683 it->hilighted = EINA_TRUE;
685 _elm_list_unwalk(wd);
686 evas_object_unref(obj);
690 _item_select(Elm_List_Item *it)
692 Evas_Object *obj = it->base.widget;
693 Widget_Data *wd = elm_widget_data_get(obj);
696 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
699 if (wd->always_select) goto call;
702 it->selected = EINA_TRUE;
703 wd->selected = eina_list_append(wd->selected, it);
706 evas_object_ref(obj);
709 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
710 evas_object_smart_callback_call(obj, "selected", it);
711 it->wd->last_selected_item = it;
713 _elm_list_unwalk(wd);
714 evas_object_unref(obj);
718 _item_unselect(Elm_List_Item *it)
720 Evas_Object *obj = it->base.widget;
721 Widget_Data *wd = elm_widget_data_get(obj);
722 const char *stacking, *selectraise;
725 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
726 if (!it->hilighted) return;
728 evas_object_ref(obj);
731 edje_object_signal_emit(it->base.view, "elm,state,unselected", "elm");
732 stacking = edje_object_data_get(it->base.view, "stacking");
733 selectraise = edje_object_data_get(it->base.view, "selectraise");
734 if ((selectraise) && (!strcmp(selectraise, "on")))
736 if ((stacking) && (!strcmp(stacking, "below")))
737 evas_object_lower(it->base.view);
739 it->hilighted = EINA_FALSE;
742 it->selected = EINA_FALSE;
743 wd->selected = eina_list_remove(wd->selected, it);
744 evas_object_smart_callback_call(it->base.widget, "unselected", it);
747 _elm_list_unwalk(wd);
748 evas_object_unref(obj);
752 _swipe_cancel(void *data)
754 Elm_List_Item *it = data;
755 Widget_Data *wd = elm_widget_data_get(it->base.widget);
757 if (!wd) return ECORE_CALLBACK_CANCEL;
758 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
759 wd->swipe = EINA_FALSE;
761 return ECORE_CALLBACK_RENEW;
765 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
767 Elm_List_Item *it = data;
768 Evas_Object *obj2 = it->base.widget;
769 Widget_Data *wd = elm_widget_data_get(obj2);
770 Evas_Event_Mouse_Move *ev = event_info;
773 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
775 evas_object_ref(obj2);
778 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
782 wd->on_hold = EINA_TRUE;
785 ecore_timer_del(it->long_timer);
786 it->long_timer = NULL;
788 if (!wd->wasselected)
791 if (wd->movements == SWIPE_MOVES) wd->swipe = EINA_TRUE;
794 wd->history[wd->movements].x = ev->cur.canvas.x;
795 wd->history[wd->movements].y = ev->cur.canvas.y;
796 if (abs((wd->history[wd->movements].x - wd->history[0].x)) > 40)
797 wd->swipe = EINA_TRUE;
803 _elm_list_unwalk(wd);
804 evas_object_unref(obj2);
808 _scroll_edge_left(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
810 Evas_Object *obj = data;
811 evas_object_smart_callback_call(obj, "scroll,edge,left", NULL);
815 _scroll_edge_right(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
817 Evas_Object *obj = data;
818 evas_object_smart_callback_call(obj, "scroll,edge,right", NULL);
822 _scroll_edge_top(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
824 Evas_Object *obj = data;
825 evas_object_smart_callback_call(obj, "scroll,edge,top", NULL);
829 _scroll_edge_bottom(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
831 Evas_Object *obj = data;
832 evas_object_smart_callback_call(obj, "scroll,edge,bottom", NULL);
836 _long_press(void *data)
838 Elm_List_Item *it = data;
839 Evas_Object *obj = it->base.widget;
840 Widget_Data *wd = elm_widget_data_get(obj);
844 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
845 it->long_timer = NULL;
846 if (it->disabled) goto end;
848 wd->longpressed = EINA_TRUE;
849 evas_object_smart_callback_call(it->base.widget, "longpressed", it);
852 return ECORE_CALLBACK_CANCEL;
856 _swipe(Elm_List_Item *it)
859 Widget_Data *wd = elm_widget_data_get(it->base.widget);
861 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
863 wd->swipe = EINA_FALSE;
864 for (i = 0; i < wd->movements; i++)
866 sum += wd->history[i].x;
867 if (abs(wd->history[0].y - wd->history[i].y) > 10) return;
870 sum /= wd->movements;
871 if (abs(sum - wd->history[0].x) <= 10) return;
872 evas_object_smart_callback_call(it->base.widget, "swipe", it);
876 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
878 Elm_List_Item *it = data;
879 Evas_Object *obj2 = it->base.widget;
880 Widget_Data *wd = elm_widget_data_get(obj2);
881 Evas_Event_Mouse_Down *ev = event_info;
884 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
885 if (ev->button != 1) return;
886 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
887 else wd->on_hold = EINA_FALSE;
888 if (wd->on_hold) return;
889 wd->wasselected = it->selected;
891 evas_object_ref(obj2);
895 wd->longpressed = EINA_FALSE;
896 if (it->long_timer) ecore_timer_del(it->long_timer);
897 it->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, it);
898 if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
899 it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
900 /* Always call the callbacks last - the user may delete our context! */
901 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
903 evas_object_smart_callback_call(it->base.widget, "clicked,double", it);
904 evas_object_smart_callback_call(it->base.widget, "clicked", it); // will be removed
906 wd->swipe = EINA_FALSE;
909 _elm_list_unwalk(wd);
910 evas_object_unref(obj2);
914 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
916 Elm_List_Item *it = data;
917 Evas_Object *obj2 = it->base.widget;
918 Widget_Data *wd = elm_widget_data_get(obj2);
919 Evas_Event_Mouse_Up *ev = event_info;
922 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
923 if (ev->button != 1) return;
924 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
925 else wd->on_hold = EINA_FALSE;
926 wd->longpressed = EINA_FALSE;
929 ecore_timer_del(it->long_timer);
930 it->long_timer = NULL;
934 ecore_timer_del(it->swipe_timer);
935 it->swipe_timer = NULL;
939 if (wd->swipe) _swipe(data);
940 wd->on_hold = EINA_FALSE;
945 if (!wd->wasselected) _item_unselect(it);
952 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
954 evas_object_ref(obj2);
964 else _item_unselect(it);
971 _item_unselect(wd->selected->data);
977 const Eina_List *l, *l_next;
980 EINA_LIST_FOREACH_SAFE(wd->selected, l, l_next, it2)
981 if (it2 != it) _item_unselect(it2);
987 _elm_list_unwalk(wd);
988 evas_object_unref(obj2);
991 static Elm_List_Item *
992 _item_new(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
994 Widget_Data *wd = elm_widget_data_get(obj);
997 if (!wd) return NULL;
998 it = elm_widget_item_new(obj, Elm_List_Item);
1000 it->label = eina_stringshare_add(label);
1004 it->base.data = data;
1005 it->base.view = edje_object_add(evas_object_evas_get(obj));
1006 edje_object_mirrored_set(it->base.view, elm_widget_mirrored_get(obj));
1007 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_DOWN,
1009 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_UP,
1011 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_MOVE,
1013 evas_object_size_hint_weight_set(it->base.view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1014 evas_object_size_hint_align_set(it->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
1017 elm_widget_sub_object_add(obj, it->icon);
1018 evas_object_event_callback_add(it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1019 _changed_size_hints, obj);
1023 elm_widget_sub_object_add(obj, it->end);
1024 evas_object_event_callback_add(it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1025 _changed_size_hints, obj);
1031 _elm_list_mode_set_internal(Widget_Data *wd)
1036 if (wd->mode == ELM_LIST_LIMIT)
1040 wd->scr_minw = EINA_TRUE;
1041 wd->scr_minh = EINA_FALSE;
1045 wd->scr_minw = EINA_FALSE;
1046 wd->scr_minh = EINA_TRUE;
1049 else if (wd->mode == ELM_LIST_EXPAND)
1051 wd->scr_minw = EINA_TRUE;
1052 wd->scr_minh = EINA_TRUE;
1056 wd->scr_minw = EINA_FALSE;
1057 wd->scr_minh = EINA_FALSE;
1060 _sizing_eval(wd->self);
1064 _fix_items(Evas_Object *obj)
1066 Widget_Data *wd = elm_widget_data_get(obj);
1070 Evas_Coord minw[2] = { 0, 0 }, minh[2] = { 0, 0 };
1073 const char *style = elm_widget_style_get(obj);
1074 const char *it_plain = wd->h_mode ? "h_item" : "item";
1075 const char *it_odd = wd->h_mode ? "h_item_odd" : "item_odd";
1076 const char *it_compress = wd->h_mode ? "h_item_compress" : "item_compress";
1077 const char *it_compress_odd = wd->h_mode ? "h_item_compress_odd" : "item_compress_odd";
1081 wd->fix_pending = EINA_TRUE;
1085 evas_object_ref(obj);
1086 _elm_list_walk(wd); // watch out "return" before unwalk!
1088 EINA_LIST_FOREACH(wd->items, l, it)
1090 if (it->deleted) continue;
1093 evas_object_size_hint_min_get(it->icon, &mw, &mh);
1094 if (mw > minw[0]) minw[0] = mw;
1095 if (mh > minh[0]) minh[0] = mh;
1099 evas_object_size_hint_min_get(it->end, &mw, &mh);
1100 if (mw > minw[1]) minw[1] = mw;
1101 if (mh > minh[1]) minh[1] = mh;
1105 if ((minw[0] != wd->minw[0]) || (minw[1] != wd->minw[1]) ||
1106 (minw[0] != wd->minh[0]) || (minh[1] != wd->minh[1]))
1108 wd->minw[0] = minw[0];
1109 wd->minw[1] = minw[1];
1110 wd->minh[0] = minh[0];
1111 wd->minh[1] = minh[1];
1115 EINA_LIST_FOREACH(wd->items, l, it)
1121 if ((it->even != it->is_even) || (!it->fixed) || (redo))
1123 const char *stacking;
1125 /* FIXME: separators' themes seem to be b0rked */
1126 if (it->is_separator)
1127 _elm_theme_object_set(obj, it->base.view, "separator",
1128 wd->h_mode ? "horizontal" : "vertical",
1130 else if (wd->mode == ELM_LIST_COMPRESS)
1133 _elm_theme_object_set(obj, it->base.view, "list",
1134 it_compress, style);
1136 _elm_theme_object_set(obj, it->base.view, "list",
1137 it_compress_odd, style);
1142 _elm_theme_object_set(obj, it->base.view, "list", it_plain,
1145 _elm_theme_object_set(obj, it->base.view, "list", it_odd,
1148 stacking = edje_object_data_get(it->base.view, "stacking");
1151 if (!strcmp(stacking, "below"))
1152 evas_object_lower(it->base.view);
1153 else if (!strcmp(stacking, "above"))
1154 evas_object_raise(it->base.view);
1156 edje_object_part_text_set(it->base.view, "elm.text", it->label);
1158 if ((!it->icon) && (minh[0] > 0))
1160 it->icon = evas_object_rectangle_add(evas_object_evas_get(it->base.view));
1161 evas_object_color_set(it->icon, 0, 0, 0, 0);
1162 it->dummy_icon = EINA_TRUE;
1164 if ((!it->end) && (minh[1] > 0))
1166 it->end = evas_object_rectangle_add(evas_object_evas_get(it->base.view));
1167 evas_object_color_set(it->end, 0, 0, 0, 0);
1168 it->dummy_end = EINA_TRUE;
1172 evas_object_size_hint_min_set(it->icon, minw[0], minh[0]);
1173 evas_object_size_hint_max_set(it->icon, 99999, 99999);
1174 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
1178 evas_object_size_hint_min_set(it->end, minw[1], minh[1]);
1179 evas_object_size_hint_max_set(it->end, 99999, 99999);
1180 edje_object_part_swallow(it->base.view, "elm.swallow.end", it->end);
1184 // this may call up user and it may modify the list item
1185 // but we're safe as we're flagged as walking.
1186 // just don't process further
1187 edje_object_message_signal_process(it->base.view);
1191 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1192 edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw, mh);
1193 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1194 evas_object_size_hint_min_set(it->base.view, mw, mh);
1195 evas_object_show(it->base.view);
1197 if ((it->selected) || (it->hilighted))
1199 const char *selectraise;
1201 // this may call up user and it may modify the list item
1202 // but we're safe as we're flagged as walking.
1203 // just don't process further
1204 edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
1208 selectraise = edje_object_data_get(it->base.view, "selectraise");
1209 if ((selectraise) && (!strcmp(selectraise, "on")))
1210 evas_object_raise(it->base.view);
1213 edje_object_signal_emit(it->base.view, "elm,state,disabled",
1216 it->fixed = EINA_TRUE;
1217 it->is_even = it->even;
1223 evas_object_size_hint_min_get(wd->box, &mw, &mh);
1225 _elm_list_mode_set_internal(wd);
1227 _elm_list_unwalk(wd);
1228 evas_object_unref(obj);
1232 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1234 Widget_Data *wd = elm_widget_data_get(obj);
1237 elm_smart_scroller_hold_set(wd->scr, EINA_TRUE);
1241 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1243 Widget_Data *wd = elm_widget_data_get(obj);
1246 elm_smart_scroller_hold_set(wd->scr, EINA_FALSE);
1250 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1252 Widget_Data *wd = elm_widget_data_get(obj);
1255 elm_smart_scroller_freeze_set(wd->scr, EINA_TRUE);
1259 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1261 Widget_Data *wd = elm_widget_data_get(obj);
1264 elm_smart_scroller_freeze_set(wd->scr, EINA_FALSE);
1268 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1274 * Adds a list object.
1276 * @param parent The parent object
1277 * @return The created object or NULL upon failure
1282 elm_list_add(Evas_Object *parent)
1287 Evas_Coord minw, minh;
1289 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1291 ELM_SET_WIDTYPE(widtype, "list");
1292 elm_widget_type_set(obj, "list");
1293 elm_widget_sub_object_add(parent, obj);
1294 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1295 elm_widget_data_set(obj, wd);
1296 elm_widget_del_hook_set(obj, _del_hook);
1297 elm_widget_theme_hook_set(obj, _theme_hook);
1298 elm_widget_disable_hook_set(obj, _disable_hook);
1299 elm_widget_can_focus_set(obj, EINA_TRUE);
1300 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1301 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1302 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1303 elm_widget_event_hook_set(obj, _event_hook);
1305 wd->scr = elm_smart_scroller_add(e);
1306 elm_smart_scroller_widget_set(wd->scr, obj);
1307 elm_widget_resize_object_set(obj, wd->scr);
1308 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1309 _changed_size_hints, obj);
1310 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
1311 evas_object_size_hint_min_set(obj, minw, minh);
1312 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
1314 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
1315 _elm_config->thumbscroll_bounce_enable);
1317 wd->box = elm_box_add(parent);
1318 elm_box_homogenous_set(wd->box, 1);
1319 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1320 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1321 elm_widget_on_show_region_hook_set(wd->box, _show_region_hook, obj);
1322 elm_widget_sub_object_add(obj, wd->box);
1323 elm_smart_scroller_child_set(wd->scr, wd->box);
1324 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1325 _changed_size_hints, obj);
1327 evas_object_show(wd->box);
1331 wd->mode = ELM_LIST_SCROLL;
1333 evas_object_smart_callback_add(wd->scr, "edge,left", _scroll_edge_left, obj);
1334 evas_object_smart_callback_add(wd->scr, "edge,right", _scroll_edge_right, obj);
1335 evas_object_smart_callback_add(wd->scr, "edge,top", _scroll_edge_top, obj);
1336 evas_object_smart_callback_add(wd->scr, "edge,bottom", _scroll_edge_bottom, obj);
1338 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1339 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1340 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1341 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1342 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1344 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1350 * Appends an item to the list object.
1352 * @param obj The list object
1353 * @param label The label of the list item
1354 * @param icon The icon object to use for the left side of the item
1355 * @param end The icon object to use for the right side of the item
1356 * @param func The function to call when the item is clicked
1357 * @param data The data to associate with the item for related callbacks
1359 * @return The created item or NULL upon failure
1363 EAPI Elm_List_Item *
1364 elm_list_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1366 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1367 Widget_Data *wd = elm_widget_data_get(obj);
1368 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1370 wd->items = eina_list_append(wd->items, it);
1371 it->node = eina_list_last(wd->items);
1372 elm_box_pack_end(wd->box, it->base.view);
1377 * Prepends an item to the list object.
1379 * @param obj The list object
1380 * @param label The label of the list item
1381 * @param icon The icon object to use for the left side of the item
1382 * @param end The icon object to use for the right side of the item
1383 * @param func The function to call when the item is clicked
1384 * @param data The data to associate with the item for related callbacks
1386 * @return The created item or NULL upon failure
1390 EAPI Elm_List_Item *
1391 elm_list_item_prepend(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1393 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1394 Widget_Data *wd = elm_widget_data_get(obj);
1395 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1397 wd->items = eina_list_prepend(wd->items, it);
1398 it->node = wd->items;
1399 elm_box_pack_start(wd->box, it->base.view);
1404 * Inserts an item into the list object before @p before.
1406 * @param obj The list object
1407 * @param before The list item to insert before
1408 * @param label The label of the list item
1409 * @param icon The icon object to use for the left side of the item
1410 * @param end The icon object to use for the right side of the item
1411 * @param func The function to call when the item is clicked
1412 * @param data The data to associate with the item for related callbacks
1414 * @return The created item or NULL upon failure
1418 EAPI Elm_List_Item *
1419 elm_list_item_insert_before(Evas_Object *obj, Elm_List_Item *before, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1424 EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
1425 if (!before->node) return NULL;
1426 ELM_LIST_ITEM_CHECK_DELETED_RETURN(before, NULL);
1428 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1429 wd = elm_widget_data_get(obj);
1430 if (!wd) return NULL;
1431 it = _item_new(obj, label, icon, end, func, data);
1432 wd->items = eina_list_prepend_relative_list(wd->items, it, before->node);
1433 it->node = before->node->prev;
1434 elm_box_pack_before(wd->box, it->base.view, before->base.view);
1439 * Inserts an item into the list object after @p after.
1441 * @param obj The list object
1442 * @param after The list item to insert after
1443 * @param label The label of the list item
1444 * @param icon The icon object to use for the left side of the item
1445 * @param end The icon object to use for the right side of the item
1446 * @param func The function to call when the item is clicked
1447 * @param data The data to associate with the item for related callbacks
1449 * @return The created item or NULL upon failure
1453 EAPI Elm_List_Item *
1454 elm_list_item_insert_after(Evas_Object *obj, Elm_List_Item *after, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1459 EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
1460 if (!after->node) return NULL;
1461 ELM_LIST_ITEM_CHECK_DELETED_RETURN(after, NULL);
1463 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1464 wd = elm_widget_data_get(obj);
1465 if (!wd) return NULL;
1466 it = _item_new(obj, label, icon, end, func, data);
1467 wd->items = eina_list_append_relative_list(wd->items, it, after->node);
1468 it->node = after->node->next;
1469 elm_box_pack_after(wd->box, it->base.view, after->base.view);
1474 * Insert a new item into the sorted list object.
1476 * @param obj The list object
1477 * @param label The label of the list item
1478 * @param icon The icon object to use for the left side of the item
1479 * @param end The icon object to use for the right side of the item
1480 * @param func The function to call when the item is clicked
1481 * @param data The data to associate with the item for related callbacks
1482 * @param cmp_func The function called for the sort.
1484 * @return The created item or NULL upon failure
1488 EAPI Elm_List_Item *
1489 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)
1491 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1492 Widget_Data *wd = elm_widget_data_get(obj);
1493 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1496 wd->items = eina_list_sorted_insert(wd->items, cmp_func, it);
1497 l = eina_list_data_find_list(wd->items, it);
1498 l = eina_list_next(l);
1501 it->node = eina_list_last(wd->items);
1502 elm_box_pack_end(wd->box, it->base.view);
1506 Elm_List_Item *before = eina_list_data_get(l);
1507 it->node = before->node->prev;
1508 elm_box_pack_before(wd->box, it->base.view, before->base.view);
1514 * Clears a list of all items.
1516 * @param obj The list object
1521 elm_list_clear(Evas_Object *obj)
1523 ELM_CHECK_WIDTYPE(obj, widtype);
1524 Widget_Data *wd = elm_widget_data_get(obj);
1528 if (!wd->items) return;
1530 eina_list_free(wd->selected);
1531 wd->selected = NULL;
1533 if (wd->walking > 0)
1537 EINA_LIST_FOREACH(wd->items, n, it)
1539 if (it->deleted) continue;
1540 it->deleted = EINA_TRUE;
1541 wd->to_delete = eina_list_append(wd->to_delete, it);
1546 evas_object_ref(obj);
1549 EINA_LIST_FREE(wd->items, it)
1551 elm_widget_item_pre_notify_del(it);
1552 _elm_list_item_free(it);
1555 _elm_list_unwalk(wd);
1559 evas_object_unref(obj);
1563 * Starts the list. Call before running show() on the list object.
1565 * @param obj The list object
1570 elm_list_go(Evas_Object *obj)
1572 ELM_CHECK_WIDTYPE(obj, widtype);
1573 Widget_Data *wd = elm_widget_data_get(obj);
1579 * Enables/disables the state of multi-select on the list object.
1581 * @param obj The list object
1582 * @param multi If true, multi-select is enabled
1587 elm_list_multi_select_set(Evas_Object *obj, Eina_Bool multi)
1589 ELM_CHECK_WIDTYPE(obj, widtype);
1590 Widget_Data *wd = elm_widget_data_get(obj);
1596 * Gets the state of multi-select on the list object.
1598 * @param obj The list object
1599 * @return If true, multi-select is enabled
1604 elm_list_multi_select_get(const Evas_Object *obj)
1606 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1607 Widget_Data *wd = elm_widget_data_get(obj);
1608 if (!wd) return EINA_FALSE;
1613 * Set which mode to use for the list with.
1615 * @param obj The list object
1616 * @param mode One of @c ELM_LIST_COMPRESS, @c ELM_LIST_SCROLL, @c
1617 * ELM_LIST_LIMIT or @c ELM_LIST_EXPAND.
1619 * @note Default value is @c ELM_LIST_SCROLL. At this mode, the list
1620 * object won't set any of its size hints to inform how a possible
1621 * container should resize it. Then, if it's not created as a "resize
1622 * object", it might end with zero dimensions. The list will respect
1623 * the container's geometry and, if any of its items won't fit into
1624 * its transverse axis, one will be able to scroll it in that
1625 * direction. @c ELM_LIST_COMPRESS is the same as the previous, except
1626 * that it <b>won't</b> let one scroll in the transverse axis, on
1627 * those cases (large items will get cropped). @c ELM_LIST_LIMIT will
1628 * actually set a minimun size hint on the list object, so that
1629 * containers may respect it (and resize itself to fit the child
1630 * properly). More specifically, a minimum size hint will be set for
1631 * its transverse axis, so that the <b>largest</b> item in that
1632 * direction fits well. @c ELM_LIST_EXPAND, besides setting a minimum
1633 * size on the transverse axis, just like the previous mode, will set
1634 * a minimum size on the longitudinal axis too, trying to reserve
1635 * space to all its children to be visible at a time. The last two
1636 * modes can always have effects bounded by setting the list object's
1637 * maximum size hints, though.
1642 elm_list_mode_set(Evas_Object *obj, Elm_List_Mode mode)
1644 ELM_CHECK_WIDTYPE(obj, widtype);
1648 wd = elm_widget_data_get(obj);
1651 if (wd->mode == mode)
1655 _elm_list_mode_set_internal(wd);
1659 * Get the mode the list is at.
1661 * @param obj The list object
1662 * @return mode One of @c ELM_LIST_COMPRESS, @c ELM_LIST_SCROLL or @c
1663 * ELM_LIST_LIMIT (@c ELM_LIST_LAST on errors).
1665 * @note see elm_list_mode_set() for more information.
1670 elm_list_mode_get(const Evas_Object *obj)
1672 ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
1673 Widget_Data *wd = elm_widget_data_get(obj);
1674 if (!wd) return ELM_LIST_LAST;
1679 * Enables/disables horizontal mode of the list.
1681 * @param obj The list object
1682 * @param mode If true, horizontale mode is enabled
1684 * @note Bounce options for the list will be reset to default values
1685 * with this funcion. Re-call elm_list_bounce_set() once more after
1686 * this one, if you had custom values.
1691 elm_list_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1693 ELM_CHECK_WIDTYPE(obj, widtype);
1696 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1698 wd = elm_widget_data_get(obj);
1702 if (wd->h_mode == horizontal)
1705 wd->h_mode = horizontal;
1706 elm_box_horizontal_set(wd->box, horizontal);
1710 evas_object_size_hint_weight_set(wd->box, 0.0, EVAS_HINT_EXPAND);
1711 evas_object_size_hint_align_set(wd->box, 0.0, EVAS_HINT_FILL);
1712 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1716 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1717 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1718 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE, bounce);
1721 _elm_list_mode_set_internal(wd);
1725 * Retrieve whether horizontal mode is enabled for a list.
1727 * @param obj The list object
1728 * @return @c EINA_TRUE, if horizontal mode is enabled and @c
1729 * EINA_FALSE, otherwise.
1731 * @note see elm_list_horizontal_set() for more information.
1736 elm_list_horizontal_get(const Evas_Object *obj)
1738 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1742 wd = elm_widget_data_get(obj);
1750 * Enables/disables the state of always_select, meaning that
1751 * an item will always be selected.
1753 * @param obj The list object
1754 * @param always_select If true, always_select is enabled
1759 elm_list_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
1761 ELM_CHECK_WIDTYPE(obj, widtype);
1762 Widget_Data *wd = elm_widget_data_get(obj);
1764 wd->always_select = always_select;
1768 * Gets the state of always_select.
1769 * See also elm_list_always_select_mode_set()
1771 * @param obj The list object
1772 * @return If true, always_select is enabled
1777 elm_list_always_select_mode_get(const Evas_Object *obj)
1779 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1780 Widget_Data *wd = elm_widget_data_get(obj);
1781 if (!wd) return EINA_FALSE;
1782 return wd->always_select;
1786 * Returns a list of all the list items.
1788 * @param obj The list object
1789 * @return An Eina_List* of the list items, or NULL on failure
1793 EAPI const Eina_List *
1794 elm_list_items_get(const Evas_Object *obj)
1796 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1797 Widget_Data *wd = elm_widget_data_get(obj);
1798 if (!wd) return NULL;
1803 * Returns the currently selected list item.
1805 * @param obj The list object
1806 * @return The selected list item, or NULL on failure
1810 EAPI Elm_List_Item *
1811 elm_list_selected_item_get(const Evas_Object *obj)
1813 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1814 Widget_Data *wd = elm_widget_data_get(obj);
1815 if (!wd) return NULL;
1816 if (wd->selected) return wd->selected->data;
1821 * Returns a list of the currently selected list items.
1823 * @param obj The list object
1824 * @return An Eina_List* of the selected list items, or NULL on failure
1828 EAPI const Eina_List *
1829 elm_list_selected_items_get(const Evas_Object *obj)
1831 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1832 Widget_Data *wd = elm_widget_data_get(obj);
1833 if (!wd) return NULL;
1834 return wd->selected;
1838 * Sets if item is a separator.
1840 * @param it The list item object
1844 elm_list_item_separator_set(Elm_List_Item *it, Eina_Bool setting)
1846 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1847 it->is_separator = !!setting;
1851 * Returns EINA_TRUE if Elm_List_Item is a separator.
1853 * @param it The list item object
1856 elm_list_item_separator_get(const Elm_List_Item *it)
1858 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1859 return it->is_separator;
1864 * Sets the selected state of @p it.
1866 * @param it The list item
1867 * @param selected Enables/disables the selected state
1872 elm_list_item_selected_set(Elm_List_Item *it, Eina_Bool selected)
1874 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1875 Evas_Object *obj = it->base.widget;
1876 Widget_Data *wd = elm_widget_data_get(obj);
1879 selected = !!selected;
1880 if (it->selected == selected) return;
1882 evas_object_ref(obj);
1889 while (wd->selected)
1890 _item_unselect(wd->selected->data);
1898 _elm_list_unwalk(wd);
1899 evas_object_unref(obj);
1903 * Gets the selected state of @p it.
1905 * @param it The list item
1906 * @return If true, the item is selected
1911 elm_list_item_selected_get(const Elm_List_Item *it)
1913 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1914 return it->selected;
1918 * Brings @p it to the center of the list view.
1920 * @param it The list item
1925 elm_list_item_show(Elm_List_Item *it)
1927 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1928 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1929 Evas_Coord bx, by, bw, bh;
1930 Evas_Coord x, y, w, h;
1932 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1933 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
1937 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
1941 * Bring in the given item
1943 * This causes list to jump to the given item @p it and show it (by scrolling),
1944 * if it is not fully visible. This may use animation to do so and take a
1947 * @param it The item
1952 elm_list_item_bring_in(Elm_List_Item *it)
1954 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1955 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1956 Evas_Coord bx, by, bw, bh;
1957 Evas_Coord x, y, w, h;
1959 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1960 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
1964 elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);
1968 * Deletes item @p it from the list.
1970 * @param it The list item to delete
1975 elm_list_item_del(Elm_List_Item *it)
1977 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1978 Evas_Object *obj = it->base.widget;
1979 Widget_Data *wd = elm_widget_data_get(obj);
1982 if (it->selected) _item_unselect(it);
1984 if (wd->walking > 0)
1986 if (it->deleted) return;
1987 it->deleted = EINA_TRUE;
1988 wd->to_delete = eina_list_append(wd->to_delete, it);
1992 wd->items = eina_list_remove_list(wd->items, it->node);
1994 evas_object_ref(obj);
1997 elm_widget_item_pre_notify_del(it);
1998 _elm_list_item_free(it);
2000 _elm_list_unwalk(wd);
2001 evas_object_unref(obj);
2005 * Set the function called when a list item is freed.
2007 * @param it The item to set the callback on
2008 * @param func The function called
2013 elm_list_item_del_cb_set(Elm_List_Item *it, Evas_Smart_Cb func)
2015 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2016 elm_widget_item_del_cb_set(it, func);
2020 * Returns the data associated with the item.
2022 * @param it The list item
2023 * @return The data associated with @p it
2028 elm_list_item_data_get(const Elm_List_Item *it)
2030 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2031 return elm_widget_item_data_get(it);
2035 * Returns the left side icon associated with the item.
2037 * @param it The list item
2038 * @return The left side icon associated with @p it
2043 elm_list_item_icon_get(const Elm_List_Item *it)
2045 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2046 if (it->dummy_icon) return NULL;
2051 * Sets the left side icon associated with the item.
2053 * Once the icon object is set, a previously set one will be deleted.
2054 * You probably don't want, then, to have the <b>same</b> icon object set
2055 * for more than one item of the list.
2057 * @param it The list item
2058 * @param icon The left side icon object to associate with @p it
2063 elm_list_item_icon_set(Elm_List_Item *it, Evas_Object *icon)
2065 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2066 if (it->icon == icon) return;
2067 if ((it->dummy_icon) && (!icon)) return;
2070 evas_object_del(it->icon);
2071 it->dummy_icon = EINA_FALSE;
2075 icon = evas_object_rectangle_add(evas_object_evas_get(it->base.widget));
2076 evas_object_color_set(icon, 0, 0, 0, 0);
2077 it->dummy_icon = EINA_TRUE;
2081 evas_object_del(it->icon);
2086 edje_object_part_swallow(it->base.view, "elm.swallow.icon", icon);
2090 * Gets the right side icon associated with the item.
2092 * @param it The list item
2093 * @return The right side icon object associated with @p it
2098 elm_list_item_end_get(const Elm_List_Item *it)
2100 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2101 if (it->dummy_end) return NULL;
2106 * Sets the right side icon associated with the item.
2108 * Once the icon object is set, a previously set one will be deleted.
2109 * You probably don't want, then, to have the <b>same</b> icon object set
2110 * for more than one item of the list.
2112 * @param it The list item
2113 * @param icon The right side icon object to associate with @p it
2118 elm_list_item_end_set(Elm_List_Item *it, Evas_Object *end)
2120 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2121 if (it->end == end) return;
2122 if ((it->dummy_end) && (!end)) return;
2125 evas_object_del(it->end);
2126 it->dummy_icon = EINA_FALSE;
2130 end = evas_object_rectangle_add(evas_object_evas_get(it->base.widget));
2131 evas_object_color_set(end, 0, 0, 0, 0);
2132 it->dummy_end = EINA_TRUE;
2136 evas_object_del(it->end);
2141 edje_object_part_swallow(it->base.view, "elm.swallow.end", end);
2145 * Gets the base object of the item.
2147 * @param it The list item
2148 * @return The base object associated with @p it
2153 elm_list_item_base_get(const Elm_List_Item *it)
2155 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2156 return it->base.view;
2160 * Gets the label of the item.
2162 * @param it The list item
2163 * @return The label of @p it
2168 elm_list_item_label_get(const Elm_List_Item *it)
2170 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2175 * Sets the label of the item.
2177 * @param it The list item
2178 * @param text The label of @p it
2183 elm_list_item_label_set(Elm_List_Item *it, const char *text)
2185 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2186 if (!eina_stringshare_replace(&it->label, text)) return;
2188 edje_object_part_text_set(it->base.view, "elm.text", it->label);
2192 * Gets the item before @p it in the list.
2194 * @param it The list item
2195 * @return The item before @p it, or NULL on failure
2199 EAPI Elm_List_Item *
2200 elm_list_item_prev(const Elm_List_Item *it)
2202 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2203 if (it->node->prev) return it->node->prev->data;
2208 * Gets the item after @p it in the list.
2210 * @param it The list item
2211 * @return The item after @p it, or NULL on failure
2215 EAPI Elm_List_Item *
2216 elm_list_item_next(const Elm_List_Item *it)
2218 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2219 if (it->node->next) return it->node->next->data;
2224 * Set the text to be shown in the list item.
2226 * @param item Target item
2227 * @param text The text to set in the content
2229 * Setup the text as tooltip to object. The item can have only one tooltip,
2230 * so any previous tooltip data is removed.
2235 elm_list_item_tooltip_text_set(Elm_List_Item *item, const char *text)
2237 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2238 elm_widget_item_tooltip_text_set(item, text);
2242 * Set the content to be shown in the tooltip item
2244 * Setup the tooltip to item. The item can have only one tooltip,
2245 * so any previous tooltip data is removed. @p func(with @p data) will
2246 * be called every time that need show the tooltip and it should
2247 * return a valid Evas_Object. This object is then managed fully by
2248 * tooltip system and is deleted when the tooltip is gone.
2250 * @param item the list item being attached a tooltip.
2251 * @param func the function used to create the tooltip contents.
2252 * @param data what to provide to @a func as callback data/context.
2253 * @param del_cb called when data is not needed anymore, either when
2254 * another callback replaces @func, the tooltip is unset with
2255 * elm_list_item_tooltip_unset() or the owner @a item
2256 * dies. This callback receives as the first parameter the
2257 * given @a data, and @c event_info is the item.
2262 elm_list_item_tooltip_content_cb_set(Elm_List_Item *item, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
2264 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2265 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
2269 * Unset tooltip from item
2271 * @param item list item to remove previously set tooltip.
2273 * Remove tooltip from item. The callback provided as del_cb to
2274 * elm_list_item_tooltip_content_cb_set() will be called to notify
2275 * it is not used anymore.
2277 * @see elm_list_item_tooltip_content_cb_set()
2282 elm_list_item_tooltip_unset(Elm_List_Item *item)
2284 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2285 elm_widget_item_tooltip_unset(item);
2289 * Sets a different style for this item tooltip.
2291 * @note before you set a style you should define a tooltip with
2292 * elm_list_item_tooltip_content_cb_set() or
2293 * elm_list_item_tooltip_text_set()
2295 * @param item list item with tooltip already set.
2296 * @param style the theme style to use (default, transparent, ...)
2301 elm_list_item_tooltip_style_set(Elm_List_Item *item, const char *style)
2303 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2304 elm_widget_item_tooltip_style_set(item, style);
2308 * Get the style for this item tooltip.
2310 * @param item list item with tooltip already set.
2311 * @return style the theme style in use, defaults to "default". If the
2312 * object does not have a tooltip set, then NULL is returned.
2317 elm_list_item_tooltip_style_get(const Elm_List_Item *item)
2319 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2320 return elm_widget_item_tooltip_style_get(item);
2324 * Set the cursor to be shown when mouse is over the list item
2326 * @param item Target item
2327 * @param cursor the cursor name to be used.
2329 * @see elm_object_cursor_set()
2333 elm_list_item_cursor_set(Elm_List_Item *item, const char *cursor)
2335 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2336 elm_widget_item_cursor_set(item, cursor);
2340 * Get the cursor to be shown when mouse is over the list item
2342 * @param item list item with cursor already set.
2343 * @return the cursor name.
2348 elm_list_item_cursor_get(const Elm_List_Item *item)
2350 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2351 return elm_widget_item_cursor_get(item);
2355 * Unset the cursor to be shown when mouse is over the list item
2357 * @param item Target item
2359 * @see elm_object_cursor_unset()
2363 elm_list_item_cursor_unset(Elm_List_Item *item)
2365 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2366 elm_widget_item_cursor_unset(item);
2370 * Sets a different style for this item cursor.
2372 * @note before you set a style you should define a cursor with
2373 * elm_list_item_cursor_set()
2375 * @param item list item with cursor already set.
2376 * @param style the theme style to use (default, transparent, ...)
2381 elm_list_item_cursor_style_set(Elm_List_Item *item, const char *style)
2383 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2384 elm_widget_item_cursor_style_set(item, style);
2388 * Get the style for this item cursor.
2390 * @param item list item with cursor already set.
2391 * @return style the theme style in use, defaults to "default". If the
2392 * object does not have a cursor set, then NULL is returned.
2397 elm_list_item_cursor_style_get(const Elm_List_Item *item)
2399 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2400 return elm_widget_item_cursor_style_get(item);
2404 * Set if the cursor set should be searched on the theme or should use
2405 * the provided by the engine, only.
2407 * @note before you set if should look on theme you should define a cursor
2408 * with elm_object_cursor_set(). By default it will only look for cursors
2409 * provided by the engine.
2411 * @param item widget item with cursor already set.
2412 * @param engine_only boolean to define it cursors should be looked only
2413 * between the provided by the engine or searched on widget's theme as well.
2418 elm_list_item_cursor_engine_only_set(Elm_List_Item *item, Eina_Bool engine_only)
2420 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2421 elm_widget_item_cursor_engine_only_set(item, engine_only);
2425 * Get the cursor engine only usage for this item cursor.
2427 * @param item widget item with cursor already set.
2428 * @return engine_only boolean to define it cursors should be looked only
2429 * between the provided by the engine or searched on widget's theme as well. If
2430 * the object does not have a cursor set, then EINA_FALSE is returned.
2435 elm_list_item_cursor_engine_only_get(const Elm_List_Item *item)
2437 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, EINA_FALSE);
2438 return elm_widget_item_cursor_engine_only_get(item);
2444 * This will enable or disable the scroller bounce mode for the list. See
2445 * elm_scroller_bounce_set() for details
2447 * @param obj The list object
2448 * @param h_bounce Allow bounce horizontally
2449 * @param v_bounce Allow bounce vertically
2454 elm_list_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
2456 ELM_CHECK_WIDTYPE(obj, widtype);
2457 Widget_Data *wd = elm_widget_data_get(obj);
2460 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
2464 * Get the bounce mode
2466 * @param obj The List object
2467 * @param h_bounce Allow bounce horizontally
2468 * @param v_bounce Allow bounce vertically
2473 elm_list_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
2475 ELM_CHECK_WIDTYPE(obj, widtype);
2476 Widget_Data *wd = elm_widget_data_get(obj);
2478 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
2482 * Set the scrollbar policy
2484 * This sets the scrollbar visibility policy for the given list scroller.
2485 * ELM_SMART_SCROLLER_POLICY_AUTO means the scrollber is made visible if it
2486 * is needed, and otherwise kept hidden. ELM_SMART_SCROLLER_POLICY_ON turns
2487 * it on all the time, and ELM_SMART_SCROLLER_POLICY_OFF always keeps it off.
2488 * This applies respectively for the horizontal and vertical scrollbars.
2490 * @param obj The list object
2491 * @param policy_h Horizontal scrollbar policy
2492 * @param policy_v Vertical scrollbar policy
2497 elm_list_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
2499 ELM_CHECK_WIDTYPE(obj, widtype);
2500 Widget_Data *wd = elm_widget_data_get(obj);
2502 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
2503 (policy_v >= ELM_SCROLLER_POLICY_LAST))
2505 elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
2509 elm_list_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
2511 ELM_CHECK_WIDTYPE(obj, widtype);
2512 Widget_Data *wd = elm_widget_data_get(obj);
2513 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
2514 if ((!wd) || (!wd->scr)) return;
2515 elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
2516 if (policy_h) *policy_h = (Elm_Scroller_Policy) s_policy_h;
2517 if (policy_v) *policy_v = (Elm_Scroller_Policy) s_policy_v;
2521 * Sets the disabled/enabled state of a list item.
2523 * A disabled item cannot be selected or unselected. It will also
2524 * change its appearance (generally greyed out). This sets the
2525 * disabled state (@c EINA_TRUE for disabled, @c EINA_FALSE for
2528 * @param it The item
2529 * @param disabled The disabled state
2534 elm_list_item_disabled_set(Elm_List_Item *it, Eina_Bool disabled)
2536 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2538 if (it->disabled == disabled)
2541 it->disabled = !!disabled;
2544 edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
2546 edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
2550 * Get the disabled/enabled state of a list item
2552 * @param it The item
2553 * @return The disabled state
2555 * See elm_list_item_disabled_set().
2560 elm_list_item_disabled_get(const Elm_List_Item *it)
2562 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
2564 return it->disabled;