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.
13 typedef struct _Widget_Data Widget_Data;
17 Evas_Object *scr, *box, *self;
18 Eina_List *items, *selected, *to_delete;
19 Elm_List_Item *last_selected_item;
22 Evas_Coord minw[2], minh[2];
23 Eina_Bool scr_minw : 1;
24 Eina_Bool scr_minh : 1;
30 } history[SWIPE_MOVES];
32 Eina_Bool fix_pending : 1;
33 Eina_Bool on_hold : 1;
35 Eina_Bool always_select : 1;
36 Eina_Bool longpressed : 1;
37 Eina_Bool wasselected : 1;
46 Evas_Object *icon, *end;
48 Ecore_Timer *long_timer;
49 Ecore_Timer *swipe_timer;
50 Eina_Bool deleted : 1;
51 Eina_Bool disabled : 1;
53 Eina_Bool is_even : 1;
54 Eina_Bool is_separator : 1;
56 Eina_Bool selected : 1;
57 Eina_Bool hilighted : 1;
58 Eina_Bool dummy_icon : 1;
59 Eina_Bool dummy_end : 1;
62 static const char *widtype = NULL;
63 static void _del_hook(Evas_Object *obj);
64 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
65 static void _theme_hook(Evas_Object *obj);
66 static void _sizing_eval(Evas_Object *obj);
67 static void _disable_hook(Evas_Object *obj);
68 static void _on_focus_hook(void *data, Evas_Object *obj);
69 static void _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source);
70 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
71 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
72 static void _fix_items(Evas_Object *obj);
73 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
74 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
75 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
76 static void _scroll_edge_left(void *data, Evas_Object *scr, void *event_info);
77 static void _scroll_edge_right(void *data, Evas_Object *scr, void *event_info);
78 static void _scroll_edge_top(void *data, Evas_Object *scr, void *event_info);
79 static void _scroll_edge_bottom(void *data, Evas_Object *scr, void *event_info);
80 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
81 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
82 static Eina_Bool _item_single_select_up(Widget_Data *wd);
83 static Eina_Bool _item_single_select_down(Widget_Data *wd);
84 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
85 Evas_Callback_Type type, void *event_info);
86 static Eina_Bool _deselect_all_items(Widget_Data *wd);
88 #define ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ...) \
89 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, __VA_ARGS__); \
92 ERR("ERROR: "#it" has been DELETED.\n"); \
97 _elm_list_item_free(Elm_List_Item *it)
99 evas_object_event_callback_del_full
100 (it->base.view, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, it);
101 evas_object_event_callback_del_full
102 (it->base.view, EVAS_CALLBACK_MOUSE_UP, _mouse_up, it);
103 evas_object_event_callback_del_full
104 (it->base.view, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, it);
107 evas_object_event_callback_del_full
108 (it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
109 _changed_size_hints, it->base.widget);
112 evas_object_event_callback_del_full
113 (it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
114 _changed_size_hints, it->base.widget);
116 eina_stringshare_del(it->label);
118 if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
119 if (it->long_timer) ecore_timer_del(it->long_timer);
120 if (it->icon) evas_object_del(it->icon);
121 if (it->end) evas_object_del(it->end);
123 elm_widget_item_del(it);
127 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
129 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
130 Evas_Event_Key_Down *ev = event_info;
131 Widget_Data *wd = elm_widget_data_get(obj);
132 if (!wd) return EINA_FALSE;
133 if (!wd->items) return EINA_FALSE;
134 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
135 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
137 Elm_List_Item *it = NULL;
140 Evas_Coord step_x = 0;
141 Evas_Coord step_y = 0;
144 Evas_Coord page_x = 0;
145 Evas_Coord page_y = 0;
147 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
148 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
149 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
150 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
152 /* TODO: fix logic for horizontal mode */
153 if ((!strcmp(ev->keyname, "Left")) ||
154 (!strcmp(ev->keyname, "KP_Left")))
157 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
158 (_item_multi_select_up(wd)))
159 || (_item_single_select_up(wd))))
161 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
167 else if ((!strcmp(ev->keyname, "Right")) ||
168 (!strcmp(ev->keyname, "KP_Right")))
171 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
172 (_item_multi_select_down(wd)))
173 || (_item_single_select_down(wd))))
175 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
181 else if ((!strcmp(ev->keyname, "Up")) ||
182 (!strcmp(ev->keyname, "KP_Up")))
185 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
186 (_item_multi_select_up(wd)))
187 || (_item_single_select_up(wd))))
189 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
195 else if ((!strcmp(ev->keyname, "Down")) ||
196 (!strcmp(ev->keyname, "KP_Down")))
199 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
200 (_item_multi_select_down(wd)))
201 || (_item_single_select_down(wd))))
203 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
209 else if ((!strcmp(ev->keyname, "Home")) ||
210 (!strcmp(ev->keyname, "KP_Home")))
212 it = eina_list_data_get(wd->items);
213 elm_list_item_bring_in(it);
214 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
217 else if ((!strcmp(ev->keyname, "End")) ||
218 (!strcmp(ev->keyname, "KP_End")))
220 it = eina_list_data_get(eina_list_last(wd->items));
221 elm_list_item_bring_in(it);
222 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
225 else if ((!strcmp(ev->keyname, "Prior")) ||
226 (!strcmp(ev->keyname, "KP_Prior")))
231 x -= -(page_x * v_w) / 100;
238 y -= -(page_y * v_h) / 100;
243 else if ((!strcmp(ev->keyname, "Next")) ||
244 (!strcmp(ev->keyname, "KP_Next")))
249 x += -(page_x * v_w) / 100;
256 y += -(page_y * v_h) / 100;
261 else if (!strcmp(ev->keyname, "Escape"))
263 if (!_deselect_all_items(wd)) return EINA_FALSE;
264 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
267 else return EINA_FALSE;
269 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
270 elm_smart_scroller_child_pos_set(wd->scr, x, y);
275 _deselect_all_items(Widget_Data *wd)
277 if (!wd->selected) return EINA_FALSE;
279 elm_list_item_selected_set(wd->selected->data, EINA_FALSE);
285 _item_multi_select_up(Widget_Data *wd)
287 if (!wd->selected) return EINA_FALSE;
288 if (!wd->multi) return EINA_FALSE;
290 Elm_List_Item *prev = elm_list_item_prev(wd->last_selected_item);
291 if (!prev) return EINA_TRUE;
293 if (elm_list_item_selected_get(prev))
295 elm_list_item_selected_set(wd->last_selected_item, EINA_FALSE);
296 wd->last_selected_item = prev;
297 elm_list_item_show(wd->last_selected_item);
301 elm_list_item_selected_set(prev, EINA_TRUE);
302 elm_list_item_show(prev);
308 _item_multi_select_down(Widget_Data *wd)
310 if (!wd->selected) return EINA_FALSE;
311 if (!wd->multi) return EINA_FALSE;
313 Elm_List_Item *next = elm_list_item_next(wd->last_selected_item);
314 if (!next) return EINA_TRUE;
316 if (elm_list_item_selected_get(next))
318 elm_list_item_selected_set(wd->last_selected_item, EINA_FALSE);
319 wd->last_selected_item = next;
320 elm_list_item_show(wd->last_selected_item);
324 elm_list_item_selected_set(next, EINA_TRUE);
325 elm_list_item_show(next);
331 _item_single_select_up(Widget_Data *wd)
335 if (!wd->selected) prev = eina_list_data_get(eina_list_last(wd->items));
336 else prev = elm_list_item_prev(wd->last_selected_item);
338 if (!prev) return EINA_FALSE;
340 _deselect_all_items(wd);
342 elm_list_item_selected_set(prev, EINA_TRUE);
343 elm_list_item_show(prev);
348 _item_single_select_down(Widget_Data *wd)
352 if (!wd->selected) next = eina_list_data_get(wd->items);
353 else next = elm_list_item_next(wd->last_selected_item);
355 if (!next) return EINA_FALSE;
357 _deselect_all_items(wd);
359 elm_list_item_selected_set(next, EINA_TRUE);
360 elm_list_item_show(next);
365 _elm_list_process_deletions(Widget_Data *wd)
369 wd->walking++; // avoid nested deletion and also _sub_del() fix_items
371 EINA_LIST_FREE(wd->to_delete, it)
373 elm_widget_item_pre_notify_del(it);
375 wd->items = eina_list_remove_list(wd->items, it->node);
376 _elm_list_item_free(it);
383 _elm_list_walk(Widget_Data *wd)
387 ERR("ERROR: walking was negative. fixed!\n");
394 _elm_list_unwalk(Widget_Data *wd)
399 ERR("ERROR: walking became negative. fixed!\n");
407 _elm_list_process_deletions(wd);
411 wd->fix_pending = EINA_FALSE;
412 _fix_items(wd->self);
413 _sizing_eval(wd->self);
418 _del_hook(Evas_Object *obj)
420 Widget_Data *wd = elm_widget_data_get(obj);
426 ERR("ERROR: list deleted while walking.\n");
429 EINA_LIST_FOREACH(wd->items, n, it) elm_widget_item_pre_notify_del(it);
430 _elm_list_unwalk(wd);
432 ERR("ERROR: leaking nodes!\n");
434 EINA_LIST_FREE(wd->items, it) _elm_list_item_free(it);
435 eina_list_free(wd->selected);
440 _show_region_hook(void *data, Evas_Object *obj)
442 Widget_Data *wd = elm_widget_data_get(data);
443 Evas_Coord x, y, w, h;
445 elm_widget_show_region_get(obj, &x, &y, &w, &h);
446 elm_smart_scroller_child_region_set(wd->scr, x, y, w, h);
450 _disable_hook(Evas_Object *obj)
452 Widget_Data *wd = elm_widget_data_get(obj);
454 if (elm_widget_disabled_get(obj))
456 _signal_emit_hook(obj, "elm,state,disabled", "elm");
457 elm_widget_scroll_freeze_push(obj);
458 elm_widget_scroll_hold_push(obj);
459 /* FIXME: if we get to have a way to only un-hilight items
460 * in the future, keeping them selected... */
461 _deselect_all_items(wd);
465 _signal_emit_hook(obj, "elm,state,enabled", "elm");
466 elm_widget_scroll_freeze_pop(obj);
467 elm_widget_scroll_hold_pop(obj);
472 _sizing_eval(Evas_Object *obj)
475 Widget_Data *wd = elm_widget_data_get(obj);
477 Evas_Coord vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
480 evas_object_size_hint_min_get(wd->box, &minw, &minh);
481 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
482 evas_object_size_hint_weight_get(wd->box, &xw, &yw);
483 if (!wd->scr) return;
484 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
487 if ((minw > 0) && (vw < minw)) vw = minw;
488 else if ((maxw > 0) && (vw > maxw)) vw = maxw;
490 else if (minw > 0) vw = minw;
493 if ((minh > 0) && (vh < minh)) vh = minh;
494 else if ((maxh > 0) && (vh > maxh)) vh = maxh;
496 else if (minh > 0) vh = minh;
497 evas_object_resize(wd->box, vw, vh);
500 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
502 if (wd->scr_minw) w = vmw + minw;
503 if (wd->scr_minh) h = vmh + minh;
505 evas_object_size_hint_max_get(obj, &maxw, &maxh);
506 if ((maxw > 0) && (w > maxw))
508 if ((maxh > 0) && (h > maxh))
511 evas_object_size_hint_min_set(obj, w, h);
515 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
517 Widget_Data *wd = elm_widget_data_get(obj);
518 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
523 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
525 Widget_Data *wd = elm_widget_data_get(obj);
526 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
527 emission, source, func_cb, data);
531 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
533 Widget_Data *wd = elm_widget_data_get(obj);
534 edje_object_signal_callback_del_full(
535 elm_smart_scroller_edje_object_get(wd->scr),
536 emission, source, func_cb, data);
540 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
542 Widget_Data *wd = elm_widget_data_get(obj);
548 elm_smart_scroller_mirrored_set(wd->scr, rtl);
550 EINA_LIST_FOREACH(wd->items, n, it)
551 edje_object_mirrored_set(it->base.view, rtl);
555 _theme_hook(Evas_Object *obj)
557 Widget_Data *wd = elm_widget_data_get(obj);
562 _elm_widget_mirrored_reload(obj);
563 _mirrored_set(obj, elm_widget_mirrored_get(obj));
570 elm_smart_scroller_object_theme_set(obj, wd->scr, "list", "base",
571 elm_widget_style_get(obj));
572 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
573 edj = elm_smart_scroller_edje_object_get(wd->scr);
574 str = edje_object_data_get(edj, "focus_highlight");
575 if ((str) && (!strcmp(str, "on")))
576 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
578 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
579 elm_object_style_set(wd->scr, elm_widget_style_get(obj));
581 EINA_LIST_FOREACH(wd->items, n, it)
583 edje_object_scale_set(it->base.view, elm_widget_scale_get(obj) * _elm_config->scale);
591 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
593 Widget_Data *wd = elm_widget_data_get(obj);
595 if (elm_widget_focus_get(obj))
597 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
598 evas_object_focus_set(wd->self, EINA_TRUE);
600 if ((wd->selected) && (!wd->last_selected_item))
601 wd->last_selected_item = eina_list_data_get(wd->selected);
605 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
606 evas_object_focus_set(wd->self, EINA_FALSE);
611 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
613 Widget_Data *wd = elm_widget_data_get(data);
620 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
622 Widget_Data *wd = elm_widget_data_get(obj);
623 Evas_Object *sub = event_info;
633 EINA_LIST_FOREACH(wd->items, l, it)
635 if ((sub == it->icon) || (sub == it->end))
637 if (it->icon == sub) it->icon = NULL;
638 if (it->end == sub) it->end = NULL;
639 evas_object_event_callback_del_full
640 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints,
648 wd->fix_pending = EINA_TRUE;
656 _item_hilight(Elm_List_Item *it)
658 Widget_Data *wd = elm_widget_data_get(it->base.widget);
659 const char *selectraise;
662 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
663 if (it->hilighted) return;
666 edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
667 selectraise = edje_object_data_get(it->base.view, "selectraise");
668 if ((selectraise) && (!strcmp(selectraise, "on")))
669 evas_object_raise(it->base.view);
670 it->hilighted = EINA_TRUE;
672 _elm_list_unwalk(wd);
676 _item_select(Elm_List_Item *it)
678 Widget_Data *wd = elm_widget_data_get(it->base.widget);
681 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
684 if (wd->always_select) goto call;
687 it->selected = EINA_TRUE;
688 wd->selected = eina_list_append(wd->selected, it);
692 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
693 evas_object_smart_callback_call(it->base.widget, "selected", it);
695 _elm_list_unwalk(wd);
696 it->wd->last_selected_item = it;
700 _item_unselect(Elm_List_Item *it)
702 Widget_Data *wd = elm_widget_data_get(it->base.widget);
703 const char *stacking, *selectraise;
706 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
707 if (!it->hilighted) return;
710 edje_object_signal_emit(it->base.view, "elm,state,unselected", "elm");
711 stacking = edje_object_data_get(it->base.view, "stacking");
712 selectraise = edje_object_data_get(it->base.view, "selectraise");
713 if ((selectraise) && (!strcmp(selectraise, "on")))
715 if ((stacking) && (!strcmp(stacking, "below")))
716 evas_object_lower(it->base.view);
718 it->hilighted = EINA_FALSE;
721 it->selected = EINA_FALSE;
722 wd->selected = eina_list_remove(wd->selected, it);
723 evas_object_smart_callback_call(it->base.widget, "unselected", it);
726 _elm_list_unwalk(wd);
730 _swipe_cancel(void *data)
732 Elm_List_Item *it = data;
733 Widget_Data *wd = elm_widget_data_get(it->base.widget);
735 if (!wd) return ECORE_CALLBACK_CANCEL;
736 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
737 wd->swipe = EINA_FALSE;
739 return ECORE_CALLBACK_RENEW;
743 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
745 Elm_List_Item *it = data;
746 Widget_Data *wd = elm_widget_data_get(it->base.widget);
747 Evas_Event_Mouse_Move *ev = event_info;
750 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
751 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
755 wd->on_hold = EINA_TRUE;
758 ecore_timer_del(it->long_timer);
759 it->long_timer = NULL;
761 if (!wd->wasselected)
764 if (wd->movements == SWIPE_MOVES) wd->swipe = EINA_TRUE;
767 wd->history[wd->movements].x = ev->cur.canvas.x;
768 wd->history[wd->movements].y = ev->cur.canvas.y;
769 if (abs((wd->history[wd->movements].x - wd->history[0].x)) > 40)
770 wd->swipe = EINA_TRUE;
778 _scroll_edge_left(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
780 Evas_Object *obj = data;
781 evas_object_smart_callback_call(obj, "scroll,edge,left", NULL);
785 _scroll_edge_right(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
787 Evas_Object *obj = data;
788 evas_object_smart_callback_call(obj, "scroll,edge,right", NULL);
792 _scroll_edge_top(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
794 Evas_Object *obj = data;
795 evas_object_smart_callback_call(obj, "scroll,edge,top", NULL);
799 _scroll_edge_bottom(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
801 Evas_Object *obj = data;
802 evas_object_smart_callback_call(obj, "scroll,edge,bottom", NULL);
806 _long_press(void *data)
808 Elm_List_Item *it = data;
809 Widget_Data *wd = elm_widget_data_get(it->base.widget);
814 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
816 it->long_timer = NULL;
821 wd->longpressed = EINA_TRUE;
822 evas_object_smart_callback_call(it->base.widget, "longpressed", it);
825 return ECORE_CALLBACK_CANCEL;
829 _swipe(Elm_List_Item *it)
832 Widget_Data *wd = elm_widget_data_get(it->base.widget);
834 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
836 wd->swipe = EINA_FALSE;
837 for (i = 0; i < wd->movements; i++)
839 sum += wd->history[i].x;
840 if (abs(wd->history[0].y - wd->history[i].y) > 10) return;
843 sum /= wd->movements;
844 if (abs(sum - wd->history[0].x) <= 10) return;
845 evas_object_smart_callback_call(it->base.widget, "swipe", it);
849 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
851 Elm_List_Item *it = data;
852 Widget_Data *wd = elm_widget_data_get(it->base.widget);
853 Evas_Event_Mouse_Down *ev = event_info;
856 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
857 if (ev->button != 1) return;
858 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
859 else wd->on_hold = EINA_FALSE;
860 if (wd->on_hold) return;
861 wd->wasselected = it->selected;
863 wd->longpressed = EINA_FALSE;
864 if (it->long_timer) ecore_timer_del(it->long_timer);
865 it->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, it);
866 if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
867 it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
868 /* Always call the callbacks last - the user may delete our context! */
869 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
870 evas_object_smart_callback_call(it->base.widget, "clicked", it);
871 wd->swipe = EINA_FALSE;
876 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
878 Elm_List_Item *it = data;
879 Widget_Data *wd = elm_widget_data_get(it->base.widget);
880 Evas_Event_Mouse_Up *ev = event_info;
883 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
884 if (ev->button != 1) return;
885 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
886 else wd->on_hold = EINA_FALSE;
887 wd->longpressed = EINA_FALSE;
890 ecore_timer_del(it->long_timer);
891 it->long_timer = NULL;
895 ecore_timer_del(it->swipe_timer);
896 it->swipe_timer = NULL;
900 if (wd->swipe) _swipe(data);
901 wd->on_hold = EINA_FALSE;
906 if (!wd->wasselected) _item_unselect(it);
913 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
915 _elm_list_walk(wd); // watch out "return" before unwalk!
924 else _item_unselect(it);
931 _item_unselect(wd->selected->data);
937 const Eina_List *l, *l_next;
940 EINA_LIST_FOREACH_SAFE(wd->selected, l, l_next, it2)
941 if (it2 != it) _item_unselect(it2);
947 _elm_list_unwalk(wd);
950 static Elm_List_Item *
951 _item_new(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
953 Widget_Data *wd = elm_widget_data_get(obj);
956 if (!wd) return NULL;
957 it = elm_widget_item_new(obj, Elm_List_Item);
959 it->label = eina_stringshare_add(label);
963 it->base.data = data;
964 it->base.view = edje_object_add(evas_object_evas_get(obj));
965 edje_object_mirrored_set(it->base.view, elm_widget_mirrored_get(obj));
966 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_DOWN,
968 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_UP,
970 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_MOVE,
972 evas_object_size_hint_weight_set(it->base.view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
973 evas_object_size_hint_align_set(it->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
976 elm_widget_sub_object_add(obj, it->icon);
977 evas_object_event_callback_add(it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
978 _changed_size_hints, obj);
982 elm_widget_sub_object_add(obj, it->end);
983 evas_object_event_callback_add(it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
984 _changed_size_hints, obj);
990 _elm_list_mode_set_internal(Widget_Data *wd)
995 if (wd->mode == ELM_LIST_LIMIT)
999 wd->scr_minw = EINA_TRUE;
1000 wd->scr_minh = EINA_FALSE;
1004 wd->scr_minw = EINA_FALSE;
1005 wd->scr_minh = EINA_TRUE;
1008 else if (wd->mode == ELM_LIST_EXPAND)
1010 wd->scr_minw = EINA_TRUE;
1011 wd->scr_minh = EINA_TRUE;
1015 wd->scr_minw = EINA_FALSE;
1016 wd->scr_minh = EINA_FALSE;
1019 _sizing_eval(wd->self);
1023 _fix_items(Evas_Object *obj)
1025 Widget_Data *wd = elm_widget_data_get(obj);
1028 Evas_Coord minw[2] = { 0, 0 }, minh[2] = { 0, 0 };
1031 const char *style = elm_widget_style_get(obj);
1032 const char *it_plain = wd->h_mode ? "h_item" : "item";
1033 const char *it_odd = wd->h_mode ? "h_item_odd" : "item_odd";
1034 const char *it_compress = wd->h_mode ? "h_item_compress" : "item_compress";
1035 const char *it_compress_odd = wd->h_mode ? "h_item_compress_odd" : "item_compress_odd";
1040 wd->fix_pending = EINA_TRUE;
1044 _elm_list_walk(wd); // watch out "return" before unwalk!
1046 EINA_LIST_FOREACH(wd->items, l, it)
1048 if (it->deleted) continue;
1051 evas_object_size_hint_min_get(it->icon, &mw, &mh);
1052 if (mw > minw[0]) minw[0] = mw;
1053 if (mh > minh[0]) minh[0] = mh;
1057 evas_object_size_hint_min_get(it->end, &mw, &mh);
1058 if (mw > minw[1]) minw[1] = mw;
1059 if (mh > minh[1]) minh[1] = mh;
1063 if ((minw[0] != wd->minw[0]) || (minw[1] != wd->minw[1]) ||
1064 (minw[0] != wd->minh[0]) || (minh[1] != wd->minh[1]))
1066 wd->minw[0] = minw[0];
1067 wd->minw[1] = minw[1];
1068 wd->minh[0] = minh[0];
1069 wd->minh[1] = minh[1];
1073 EINA_LIST_FOREACH(wd->items, l, it)
1079 if ((it->even != it->is_even) || (!it->fixed) || (redo))
1081 const char *stacking;
1083 /* FIXME: separators' themes seem to be b0rked */
1084 if (it->is_separator)
1085 _elm_theme_object_set(obj, it->base.view, "separator",
1086 wd->h_mode ? "horizontal" : "vertical",
1088 else if (wd->mode == ELM_LIST_COMPRESS)
1091 _elm_theme_object_set(obj, it->base.view, "list",
1092 it_compress, style);
1094 _elm_theme_object_set(obj, it->base.view, "list",
1095 it_compress_odd, style);
1100 _elm_theme_object_set(obj, it->base.view, "list", it_plain,
1103 _elm_theme_object_set(obj, it->base.view, "list", it_odd,
1106 stacking = edje_object_data_get(it->base.view, "stacking");
1109 if (!strcmp(stacking, "below"))
1110 evas_object_lower(it->base.view);
1111 else if (!strcmp(stacking, "above"))
1112 evas_object_raise(it->base.view);
1114 edje_object_part_text_set(it->base.view, "elm.text", it->label);
1116 if ((!it->icon) && (minh[0] > 0))
1118 it->icon = evas_object_rectangle_add(evas_object_evas_get(it->base.view));
1119 evas_object_color_set(it->icon, 0, 0, 0, 0);
1120 it->dummy_icon = EINA_TRUE;
1122 if ((!it->end) && (minh[1] > 0))
1124 it->end = evas_object_rectangle_add(evas_object_evas_get(it->base.view));
1125 evas_object_color_set(it->end, 0, 0, 0, 0);
1126 it->dummy_end = EINA_TRUE;
1130 evas_object_size_hint_min_set(it->icon, minw[0], minh[0]);
1131 evas_object_size_hint_max_set(it->icon, 99999, 99999);
1132 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
1136 evas_object_size_hint_min_set(it->end, minw[1], minh[1]);
1137 evas_object_size_hint_max_set(it->end, 99999, 99999);
1138 edje_object_part_swallow(it->base.view, "elm.swallow.end", it->end);
1142 // this may call up user and it may modify the list item
1143 // but we're safe as we're flagged as walking.
1144 // just don't process further
1145 edje_object_message_signal_process(it->base.view);
1149 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1150 edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw, mh);
1151 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1152 evas_object_size_hint_min_set(it->base.view, mw, mh);
1153 evas_object_show(it->base.view);
1155 if ((it->selected) || (it->hilighted))
1157 const char *selectraise;
1159 // this may call up user and it may modify the list item
1160 // but we're safe as we're flagged as walking.
1161 // just don't process further
1162 edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
1166 selectraise = edje_object_data_get(it->base.view, "selectraise");
1167 if ((selectraise) && (!strcmp(selectraise, "on")))
1168 evas_object_raise(it->base.view);
1171 edje_object_signal_emit(it->base.view, "elm,state,disabled",
1174 it->fixed = EINA_TRUE;
1175 it->is_even = it->even;
1180 _elm_list_unwalk(wd);
1183 evas_object_size_hint_min_get(wd->box, &mw, &mh);
1185 _elm_list_mode_set_internal(wd);
1189 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1191 Widget_Data *wd = elm_widget_data_get(obj);
1194 elm_smart_scroller_hold_set(wd->scr, EINA_TRUE);
1198 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1200 Widget_Data *wd = elm_widget_data_get(obj);
1203 elm_smart_scroller_hold_set(wd->scr, EINA_FALSE);
1207 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1209 Widget_Data *wd = elm_widget_data_get(obj);
1212 elm_smart_scroller_freeze_set(wd->scr, EINA_TRUE);
1216 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1218 Widget_Data *wd = elm_widget_data_get(obj);
1221 elm_smart_scroller_freeze_set(wd->scr, EINA_FALSE);
1225 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1231 * Adds a list object.
1233 * @param parent The parent object
1234 * @return The created object or NULL upon failure
1239 elm_list_add(Evas_Object *parent)
1244 Evas_Coord minw, minh;
1246 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1248 wd = ELM_NEW(Widget_Data);
1249 e = evas_object_evas_get(parent);
1250 if (!e) return NULL;
1251 wd->self = obj = elm_widget_add(e);
1252 ELM_SET_WIDTYPE(widtype, "list");
1253 elm_widget_type_set(obj, "list");
1254 elm_widget_sub_object_add(parent, obj);
1255 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1256 elm_widget_data_set(obj, wd);
1257 elm_widget_del_hook_set(obj, _del_hook);
1258 elm_widget_theme_hook_set(obj, _theme_hook);
1259 elm_widget_disable_hook_set(obj, _disable_hook);
1260 elm_widget_can_focus_set(obj, EINA_TRUE);
1261 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1262 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1263 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1264 elm_widget_event_hook_set(obj, _event_hook);
1266 wd->scr = elm_smart_scroller_add(e);
1267 elm_smart_scroller_widget_set(wd->scr, obj);
1269 elm_widget_resize_object_set(obj, wd->scr);
1270 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1271 _changed_size_hints, obj);
1272 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
1273 evas_object_size_hint_min_set(obj, minw, minh);
1274 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
1276 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
1277 _elm_config->thumbscroll_bounce_enable);
1279 wd->box = elm_box_add(parent);
1280 elm_box_homogenous_set(wd->box, 1);
1281 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1282 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1283 elm_widget_on_show_region_hook_set(wd->box, _show_region_hook, obj);
1284 elm_widget_sub_object_add(obj, wd->box);
1285 elm_smart_scroller_child_set(wd->scr, wd->box);
1286 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1287 _changed_size_hints, obj);
1289 evas_object_show(wd->box);
1291 wd->mode = ELM_LIST_SCROLL;
1293 evas_object_smart_callback_add(wd->scr, "edge,left", _scroll_edge_left, obj);
1294 evas_object_smart_callback_add(wd->scr, "edge,right", _scroll_edge_right, obj);
1295 evas_object_smart_callback_add(wd->scr, "edge,top", _scroll_edge_top, obj);
1296 evas_object_smart_callback_add(wd->scr, "edge,bottom", _scroll_edge_bottom, obj);
1298 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1299 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1300 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1301 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1302 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1304 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1310 * Appends an item to the list object.
1312 * @param obj The list object
1313 * @param label The label of the list item
1314 * @param icon The icon object to use for the left side of the item
1315 * @param end The icon object to use for the right side of the item
1316 * @param func The function to call when the item is clicked
1317 * @param data The data to associate with the item for related callbacks
1319 * @return The created item or NULL upon failure
1323 EAPI Elm_List_Item *
1324 elm_list_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1326 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1327 Widget_Data *wd = elm_widget_data_get(obj);
1328 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1330 wd->items = eina_list_append(wd->items, it);
1331 it->node = eina_list_last(wd->items);
1332 elm_box_pack_end(wd->box, it->base.view);
1337 * Prepends an item to the list object.
1339 * @param obj The list object
1340 * @param label The label of the list item
1341 * @param icon The icon object to use for the left side of the item
1342 * @param end The icon object to use for the right side of the item
1343 * @param func The function to call when the item is clicked
1344 * @param data The data to associate with the item for related callbacks
1346 * @return The created item or NULL upon failure
1350 EAPI Elm_List_Item *
1351 elm_list_item_prepend(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1353 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1354 Widget_Data *wd = elm_widget_data_get(obj);
1355 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1357 wd->items = eina_list_prepend(wd->items, it);
1358 it->node = wd->items;
1359 elm_box_pack_start(wd->box, it->base.view);
1364 * Inserts an item into the list object before @p before.
1366 * @param obj The list object
1367 * @param before The list item to insert before
1368 * @param label The label of the list item
1369 * @param icon The icon object to use for the left side of the item
1370 * @param end The icon object to use for the right side of the item
1371 * @param func The function to call when the item is clicked
1372 * @param data The data to associate with the item for related callbacks
1374 * @return The created item or NULL upon failure
1378 EAPI Elm_List_Item *
1379 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)
1384 EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
1385 if (!before->node) return NULL;
1386 ELM_LIST_ITEM_CHECK_DELETED_RETURN(before, NULL);
1388 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1389 wd = elm_widget_data_get(obj);
1390 if (!wd) return NULL;
1391 it = _item_new(obj, label, icon, end, func, data);
1392 wd->items = eina_list_prepend_relative_list(wd->items, it, before->node);
1393 it->node = before->node->prev;
1394 elm_box_pack_before(wd->box, it->base.view, before->base.view);
1399 * Inserts an item into the list object after @p after.
1401 * @param obj The list object
1402 * @param after The list item to insert after
1403 * @param label The label of the list item
1404 * @param icon The icon object to use for the left side of the item
1405 * @param end The icon object to use for the right side of the item
1406 * @param func The function to call when the item is clicked
1407 * @param data The data to associate with the item for related callbacks
1409 * @return The created item or NULL upon failure
1413 EAPI Elm_List_Item *
1414 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)
1419 EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
1420 if (!after->node) return NULL;
1421 ELM_LIST_ITEM_CHECK_DELETED_RETURN(after, NULL);
1423 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1424 wd = elm_widget_data_get(obj);
1425 if (!wd) return NULL;
1426 it = _item_new(obj, label, icon, end, func, data);
1427 wd->items = eina_list_append_relative_list(wd->items, it, after->node);
1428 it->node = after->node->next;
1429 elm_box_pack_after(wd->box, it->base.view, after->base.view);
1434 * Insert a new item into the sorted list object.
1436 * @param obj The list object
1437 * @param label The label of the list item
1438 * @param icon The icon object to use for the left side of the item
1439 * @param end The icon object to use for the right side of the item
1440 * @param func The function to call when the item is clicked
1441 * @param data The data to associate with the item for related callbacks
1442 * @param cmp_func The function called for the sort.
1444 * @return The created item or NULL upon failure
1448 EAPI Elm_List_Item *
1449 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)
1451 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1452 Widget_Data *wd = elm_widget_data_get(obj);
1453 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1456 wd->items = eina_list_sorted_insert(wd->items, cmp_func, it);
1457 l = eina_list_data_find_list(wd->items, it);
1458 l = eina_list_next(l);
1461 it->node = eina_list_last(wd->items);
1462 elm_box_pack_end(wd->box, it->base.view);
1466 Elm_List_Item *before = eina_list_data_get(l);
1467 it->node = before->node->prev;
1468 elm_box_pack_before(wd->box, it->base.view, before->base.view);
1474 * Clears a list of all items.
1476 * @param obj The list object
1481 elm_list_clear(Evas_Object *obj)
1483 ELM_CHECK_WIDTYPE(obj, widtype);
1484 Widget_Data *wd = elm_widget_data_get(obj);
1488 if (!wd->items) return;
1490 eina_list_free(wd->selected);
1491 wd->selected = NULL;
1493 if (wd->walking > 0)
1497 EINA_LIST_FOREACH(wd->items, n, it)
1499 if (it->deleted) continue;
1500 it->deleted = EINA_TRUE;
1501 wd->to_delete = eina_list_append(wd->to_delete, it);
1508 EINA_LIST_FREE(wd->items, it)
1510 elm_widget_item_pre_notify_del(it);
1511 _elm_list_item_free(it);
1514 _elm_list_unwalk(wd);
1521 * Starts the list. Call before running show() on the list object.
1523 * @param obj The list object
1528 elm_list_go(Evas_Object *obj)
1530 ELM_CHECK_WIDTYPE(obj, widtype);
1531 Widget_Data *wd = elm_widget_data_get(obj);
1537 * Enables/disables the state of multi-select on the list object.
1539 * @param obj The list object
1540 * @param multi If true, multi-select is enabled
1545 elm_list_multi_select_set(Evas_Object *obj, Eina_Bool multi)
1547 ELM_CHECK_WIDTYPE(obj, widtype);
1548 Widget_Data *wd = elm_widget_data_get(obj);
1554 * Gets the state of multi-select on the list object.
1556 * @param obj The list object
1557 * @return If true, multi-select is enabled
1562 elm_list_multi_select_get(const Evas_Object *obj)
1564 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1565 Widget_Data *wd = elm_widget_data_get(obj);
1566 if (!wd) return EINA_FALSE;
1571 * Set which mode to use for the list with.
1573 * @param obj The list object
1574 * @param mode One of @c ELM_LIST_COMPRESS, @c ELM_LIST_SCROLL, @c
1575 * ELM_LIST_LIMIT or @c ELM_LIST_EXPAND.
1577 * @note Default value is @c ELM_LIST_SCROLL. At this mode, the list
1578 * object won't set any of its size hints to inform how a possible
1579 * container should resize it. Then, if it's not created as a "resize
1580 * object", it might end with zero dimensions. The list will respect
1581 * the container's geometry and, if any of its items won't fit into
1582 * its transverse axis, one will be able to scroll it in that
1583 * direction. @c ELM_LIST_COMPRESS is the same as the previous, except
1584 * that it <b>won't</b> let one scroll in the transverse axis, on
1585 * those cases (large items will get cropped). @c ELM_LIST_LIMIT will
1586 * actually set a minimun size hint on the list object, so that
1587 * containers may respect it (and resize itself to fit the child
1588 * properly). More specifically, a minimum size hint will be set for
1589 * its transverse axis, so that the <b>largest</b> item in that
1590 * direction fits well. @c ELM_LIST_EXPAND, besides setting a minimum
1591 * size on the transverse axis, just like the previous mode, will set
1592 * a minimum size on the longitudinal axis too, trying to reserve
1593 * space to all its children to be visible at a time. The last two
1594 * modes can always have effects bounded by setting the list object's
1595 * maximum size hints, though.
1600 elm_list_mode_set(Evas_Object *obj, Elm_List_Mode mode)
1602 ELM_CHECK_WIDTYPE(obj, widtype);
1606 wd = elm_widget_data_get(obj);
1609 if (wd->mode == mode)
1613 _elm_list_mode_set_internal(wd);
1617 * Get the mode the list is at.
1619 * @param obj The list object
1620 * @return mode One of @c ELM_LIST_COMPRESS, @c ELM_LIST_SCROLL or @c
1621 * ELM_LIST_LIMIT (@c ELM_LIST_LAST on errors).
1623 * @note see elm_list_mode_set() for more information.
1628 elm_list_mode_get(const Evas_Object *obj)
1630 ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
1631 Widget_Data *wd = elm_widget_data_get(obj);
1632 if (!wd) return ELM_LIST_LAST;
1637 * Enables/disables horizontal mode of the list.
1639 * @param obj The list object
1640 * @param mode If true, horizontale mode is enabled
1642 * @note Bounce options for the list will be reset to default values
1643 * with this funcion. Re-call elm_list_bounce_set() once more after
1644 * this one, if you had custom values.
1649 elm_list_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1651 ELM_CHECK_WIDTYPE(obj, widtype);
1654 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1656 wd = elm_widget_data_get(obj);
1660 if (wd->h_mode == horizontal)
1663 wd->h_mode = horizontal;
1664 elm_box_horizontal_set(wd->box, horizontal);
1668 evas_object_size_hint_weight_set(wd->box, 0.0, EVAS_HINT_EXPAND);
1669 evas_object_size_hint_align_set(wd->box, 0.0, EVAS_HINT_FILL);
1670 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1674 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1675 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1676 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE, bounce);
1679 _elm_list_mode_set_internal(wd);
1683 * Retrieve whether horizontal mode is enabled for a list.
1685 * @param obj The list object
1686 * @return @c EINA_TRUE, if horizontal mode is enabled and @c
1687 * EINA_FALSE, otherwise.
1689 * @note see elm_list_horizontal_set() for more information.
1694 elm_list_horizontal_get(const Evas_Object *obj)
1696 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1700 wd = elm_widget_data_get(obj);
1708 * Enables/disables the state of always_select, meaning that
1709 * an item will always be selected.
1711 * @param obj The list object
1712 * @param always_select If true, always_select is enabled
1717 elm_list_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
1719 ELM_CHECK_WIDTYPE(obj, widtype);
1720 Widget_Data *wd = elm_widget_data_get(obj);
1722 wd->always_select = always_select;
1726 * Gets the state of always_select.
1727 * See also elm_list_always_select_mode_set()
1729 * @param obj The list object
1730 * @return If true, always_select is enabled
1735 elm_list_always_select_mode_get(const Evas_Object *obj)
1737 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1738 Widget_Data *wd = elm_widget_data_get(obj);
1739 if (!wd) return EINA_FALSE;
1740 return wd->always_select;
1744 * Returns a list of all the list items.
1746 * @param obj The list object
1747 * @return An Eina_List* of the list items, or NULL on failure
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;
1761 * Returns the currently selected list item.
1763 * @param obj The list object
1764 * @return The selected list item, or NULL on failure
1768 EAPI Elm_List_Item *
1769 elm_list_selected_item_get(const Evas_Object *obj)
1771 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1772 Widget_Data *wd = elm_widget_data_get(obj);
1773 if (!wd) return NULL;
1774 if (wd->selected) return wd->selected->data;
1779 * Returns a list of the currently selected list items.
1781 * @param obj The list object
1782 * @return An Eina_List* of the selected list items, or NULL on failure
1786 EAPI const Eina_List *
1787 elm_list_selected_items_get(const Evas_Object *obj)
1789 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1790 Widget_Data *wd = elm_widget_data_get(obj);
1791 if (!wd) return NULL;
1792 return wd->selected;
1796 * Sets if item is a separator.
1798 * @param it The list item object
1802 elm_list_item_separator_set(Elm_List_Item *it, Eina_Bool setting)
1804 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1805 it->is_separator = !!setting;
1809 * Returns EINA_TRUE if Elm_List_Item is a separator.
1811 * @param it The list item object
1814 elm_list_item_separator_get(const Elm_List_Item *it)
1816 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1817 return it->is_separator;
1822 * Sets the selected state of @p it.
1824 * @param it The list item
1825 * @param selected Enables/disables the selected state
1830 elm_list_item_selected_set(Elm_List_Item *it, Eina_Bool selected)
1832 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1834 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1837 selected = !!selected;
1838 if (it->selected == selected) return;
1846 while (wd->selected)
1847 _item_unselect(wd->selected->data);
1855 _elm_list_unwalk(wd);
1859 * Gets the selected state of @p it.
1861 * @param it The list item
1862 * @return If true, the item is selected
1867 elm_list_item_selected_get(const Elm_List_Item *it)
1869 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1870 return it->selected;
1874 * Brings @p it to the center of the list view.
1876 * @param it The list item
1881 elm_list_item_show(Elm_List_Item *it)
1883 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1884 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1885 Evas_Coord bx, by, bw, bh;
1886 Evas_Coord x, y, w, h;
1888 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1889 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
1893 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
1897 * Bring in the given item
1899 * This causes list to jump to the given item @p it and show it (by scrolling),
1900 * if it is not fully visible. This may use animation to do so and take a
1903 * @param it The item
1908 elm_list_item_bring_in(Elm_List_Item *it)
1910 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1911 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1912 Evas_Coord bx, by, bw, bh;
1913 Evas_Coord x, y, w, h;
1915 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1916 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
1920 elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);
1924 * Deletes item @p it from the list.
1926 * @param it The list item to delete
1931 elm_list_item_del(Elm_List_Item *it)
1933 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1934 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1937 if (it->selected) _item_unselect(it);
1939 if (wd->walking > 0)
1941 if (it->deleted) return;
1942 it->deleted = EINA_TRUE;
1943 wd->to_delete = eina_list_append(wd->to_delete, it);
1947 wd->items = eina_list_remove_list(wd->items, it->node);
1951 elm_widget_item_pre_notify_del(it);
1952 _elm_list_item_free(it);
1954 _elm_list_unwalk(wd);
1958 * Set the function called when a list item is freed.
1960 * @param it The item to set the callback on
1961 * @param func The function called
1966 elm_list_item_del_cb_set(Elm_List_Item *it, Evas_Smart_Cb func)
1968 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1969 elm_widget_item_del_cb_set(it, func);
1973 * Returns the data associated with the item.
1975 * @param it The list item
1976 * @return The data associated with @p it
1981 elm_list_item_data_get(const Elm_List_Item *it)
1983 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1984 return elm_widget_item_data_get(it);
1988 * Returns the left side icon associated with the item.
1990 * @param it The list item
1991 * @return The left side icon associated with @p it
1996 elm_list_item_icon_get(const Elm_List_Item *it)
1998 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1999 if (it->dummy_icon) return NULL;
2004 * Sets the left side icon associated with the item.
2006 * Once the icon object is set, a previously set one will be deleted.
2007 * You probably don't want, then, to have the <b>same</b> icon object set
2008 * for more than one item of the list.
2010 * @param it The list item
2011 * @param icon The left side icon object to associate with @p it
2016 elm_list_item_icon_set(Elm_List_Item *it, Evas_Object *icon)
2018 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2019 if (it->icon == icon) return;
2020 if ((it->dummy_icon) && (!icon)) return;
2023 evas_object_del(it->icon);
2024 it->dummy_icon = EINA_FALSE;
2028 icon = evas_object_rectangle_add(evas_object_evas_get(it->base.widget));
2029 evas_object_color_set(icon, 0, 0, 0, 0);
2030 it->dummy_icon = EINA_TRUE;
2034 evas_object_del(it->icon);
2039 edje_object_part_swallow(it->base.view, "elm.swallow.icon", icon);
2043 * Gets the right side icon associated with the item.
2045 * @param it The list item
2046 * @return The right side icon object associated with @p it
2051 elm_list_item_end_get(const Elm_List_Item *it)
2053 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2054 if (it->dummy_end) return NULL;
2059 * Sets the right side icon associated with the item.
2061 * Once the icon object is set, a previously set one will be deleted.
2062 * You probably don't want, then, to have the <b>same</b> icon object set
2063 * for more than one item of the list.
2065 * @param it The list item
2066 * @param icon The right side icon object to associate with @p it
2071 elm_list_item_end_set(Elm_List_Item *it, Evas_Object *end)
2073 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2074 if (it->end == end) return;
2075 if ((it->dummy_end) && (!end)) return;
2078 evas_object_del(it->end);
2079 it->dummy_icon = EINA_FALSE;
2083 end = evas_object_rectangle_add(evas_object_evas_get(it->base.widget));
2084 evas_object_color_set(end, 0, 0, 0, 0);
2085 it->dummy_end = EINA_TRUE;
2089 evas_object_del(it->end);
2094 edje_object_part_swallow(it->base.view, "elm.swallow.end", end);
2098 * Gets the base object of the item.
2100 * @param it The list item
2101 * @return The base object associated with @p it
2106 elm_list_item_base_get(const Elm_List_Item *it)
2108 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2109 return it->base.view;
2113 * Gets the label of the item.
2115 * @param it The list item
2116 * @return The label of @p it
2121 elm_list_item_label_get(const Elm_List_Item *it)
2123 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2128 * Sets the label of the item.
2130 * @param it The list item
2131 * @param text The label of @p it
2136 elm_list_item_label_set(Elm_List_Item *it, const char *text)
2138 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2139 if (!eina_stringshare_replace(&it->label, text)) return;
2141 edje_object_part_text_set(it->base.view, "elm.text", it->label);
2145 * Gets the item before @p it in the list.
2147 * @param it The list item
2148 * @return The item before @p it, or NULL on failure
2152 EAPI Elm_List_Item *
2153 elm_list_item_prev(const Elm_List_Item *it)
2155 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2156 if (it->node->prev) return it->node->prev->data;
2161 * Gets the item after @p it in the list.
2163 * @param it The list item
2164 * @return The item after @p it, or NULL on failure
2168 EAPI Elm_List_Item *
2169 elm_list_item_next(const Elm_List_Item *it)
2171 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2172 if (it->node->next) return it->node->next->data;
2177 * Set the text to be shown in the list item.
2179 * @param item Target item
2180 * @param text The text to set in the content
2182 * Setup the text as tooltip to object. The item can have only one tooltip,
2183 * so any previous tooltip data is removed.
2188 elm_list_item_tooltip_text_set(Elm_List_Item *item, const char *text)
2190 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2191 elm_widget_item_tooltip_text_set(item, text);
2195 * Set the content to be shown in the tooltip item
2197 * Setup the tooltip to item. The item can have only one tooltip,
2198 * so any previous tooltip data is removed. @p func(with @p data) will
2199 * be called every time that need show the tooltip and it should
2200 * return a valid Evas_Object. This object is then managed fully by
2201 * tooltip system and is deleted when the tooltip is gone.
2203 * @param item the list item being attached a tooltip.
2204 * @param func the function used to create the tooltip contents.
2205 * @param data what to provide to @a func as callback data/context.
2206 * @param del_cb called when data is not needed anymore, either when
2207 * another callback replaces @func, the tooltip is unset with
2208 * elm_list_item_tooltip_unset() or the owner @a item
2209 * dies. This callback receives as the first parameter the
2210 * given @a data, and @c event_info is the item.
2215 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)
2217 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2218 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
2222 * Unset tooltip from item
2224 * @param item list item to remove previously set tooltip.
2226 * Remove tooltip from item. The callback provided as del_cb to
2227 * elm_list_item_tooltip_content_cb_set() will be called to notify
2228 * it is not used anymore.
2230 * @see elm_list_item_tooltip_content_cb_set()
2235 elm_list_item_tooltip_unset(Elm_List_Item *item)
2237 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2238 elm_widget_item_tooltip_unset(item);
2242 * Sets a different style for this item tooltip.
2244 * @note before you set a style you should define a tooltip with
2245 * elm_list_item_tooltip_content_cb_set() or
2246 * elm_list_item_tooltip_text_set()
2248 * @param item list item with tooltip already set.
2249 * @param style the theme style to use (default, transparent, ...)
2254 elm_list_item_tooltip_style_set(Elm_List_Item *item, const char *style)
2256 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2257 elm_widget_item_tooltip_style_set(item, style);
2261 * Get the style for this item tooltip.
2263 * @param item list item with tooltip already set.
2264 * @return style the theme style in use, defaults to "default". If the
2265 * object does not have a tooltip set, then NULL is returned.
2270 elm_list_item_tooltip_style_get(const Elm_List_Item *item)
2272 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2273 return elm_widget_item_tooltip_style_get(item);
2277 * Set the cursor to be shown when mouse is over the list item
2279 * @param item Target item
2280 * @param cursor the cursor name to be used.
2282 * @see elm_object_cursor_set()
2286 elm_list_item_cursor_set(Elm_List_Item *item, const char *cursor)
2288 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2289 elm_widget_item_cursor_set(item, cursor);
2293 * Get the cursor to be shown when mouse is over the list item
2295 * @param item list item with cursor already set.
2296 * @return the cursor name.
2301 elm_list_item_cursor_get(const Elm_List_Item *item)
2303 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2304 return elm_widget_item_cursor_get(item);
2308 * Unset the cursor to be shown when mouse is over the list item
2310 * @param item Target item
2312 * @see elm_object_cursor_unset()
2316 elm_list_item_cursor_unset(Elm_List_Item *item)
2318 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2319 elm_widget_item_cursor_unset(item);
2323 * Sets a different style for this item cursor.
2325 * @note before you set a style you should define a cursor with
2326 * elm_list_item_cursor_set()
2328 * @param item list item with cursor already set.
2329 * @param style the theme style to use (default, transparent, ...)
2334 elm_list_item_cursor_style_set(Elm_List_Item *item, const char *style)
2336 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2337 elm_widget_item_cursor_style_set(item, style);
2341 * Get the style for this item cursor.
2343 * @param item list item with cursor already set.
2344 * @return style the theme style in use, defaults to "default". If the
2345 * object does not have a cursor set, then NULL is returned.
2350 elm_list_item_cursor_style_get(const Elm_List_Item *item)
2352 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2353 return elm_widget_item_cursor_style_get(item);
2357 * Set if the cursor set should be searched on the theme or should use
2358 * the provided by the engine, only.
2360 * @note before you set if should look on theme you should define a cursor
2361 * with elm_object_cursor_set(). By default it will only look for cursors
2362 * provided by the engine.
2364 * @param item widget item with cursor already set.
2365 * @param engine_only boolean to define it cursors should be looked only
2366 * between the provided by the engine or searched on widget's theme as well.
2371 elm_list_item_cursor_engine_only_set(Elm_List_Item *item, Eina_Bool engine_only)
2373 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2374 elm_widget_item_cursor_engine_only_set(item, engine_only);
2378 * Get the cursor engine only usage for this item cursor.
2380 * @param item widget item with cursor already set.
2381 * @return engine_only boolean to define it cursors should be looked only
2382 * between the provided by the engine or searched on widget's theme as well. If
2383 * the object does not have a cursor set, then EINA_FALSE is returned.
2388 elm_list_item_cursor_engine_only_get(const Elm_List_Item *item)
2390 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, EINA_FALSE);
2391 return elm_widget_item_cursor_engine_only_get(item);
2397 * This will enable or disable the scroller bounce mode for the list. See
2398 * elm_scroller_bounce_set() for details
2400 * @param obj The list object
2401 * @param h_bounce Allow bounce horizontally
2402 * @param v_bounce Allow bounce vertically
2407 elm_list_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
2409 ELM_CHECK_WIDTYPE(obj, widtype);
2410 Widget_Data *wd = elm_widget_data_get(obj);
2413 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
2417 * Get the bounce mode
2419 * @param obj The List object
2420 * @param h_bounce Allow bounce horizontally
2421 * @param v_bounce Allow bounce vertically
2426 elm_list_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
2428 ELM_CHECK_WIDTYPE(obj, widtype);
2429 Widget_Data *wd = elm_widget_data_get(obj);
2431 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
2435 * Set the scrollbar policy
2437 * This sets the scrollbar visibility policy for the given list scroller.
2438 * ELM_SMART_SCROLLER_POLICY_AUTO means the scrollber is made visible if it
2439 * is needed, and otherwise kept hidden. ELM_SMART_SCROLLER_POLICY_ON turns
2440 * it on all the time, and ELM_SMART_SCROLLER_POLICY_OFF always keeps it off.
2441 * This applies respectively for the horizontal and vertical scrollbars.
2443 * @param obj The list object
2444 * @param policy_h Horizontal scrollbar policy
2445 * @param policy_v Vertical scrollbar policy
2450 elm_list_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
2452 ELM_CHECK_WIDTYPE(obj, widtype);
2453 Widget_Data *wd = elm_widget_data_get(obj);
2455 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
2456 (policy_v >= ELM_SCROLLER_POLICY_LAST))
2458 elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
2462 elm_list_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
2464 ELM_CHECK_WIDTYPE(obj, widtype);
2465 Widget_Data *wd = elm_widget_data_get(obj);
2466 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
2467 if ((!wd) || (!wd->scr)) return;
2468 elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
2469 if (policy_h) *policy_h = (Elm_Scroller_Policy) s_policy_h;
2470 if (policy_v) *policy_v = (Elm_Scroller_Policy) s_policy_v;
2474 * Sets the disabled/enabled state of a list item.
2476 * A disabled item cannot be selected or unselected. It will also
2477 * change its appearance (generally greyed out). This sets the
2478 * disabled state (@c EINA_TRUE for disabled, @c EINA_FALSE for
2481 * @param it The item
2482 * @param disabled The disabled state
2487 elm_list_item_disabled_set(Elm_List_Item *it, Eina_Bool disabled)
2489 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2491 if (it->disabled == disabled)
2494 it->disabled = !!disabled;
2497 edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
2499 edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
2503 * Get the disabled/enabled state of a list item
2505 * @param it The item
2506 * @return The disabled state
2508 * See elm_list_item_disabled_set().
2513 elm_list_item_disabled_get(const Elm_List_Item *it)
2515 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
2517 return it->disabled;