1 #include <Elementary.h>
10 * A list is a very simple type of list widget. For more robust
11 * lists, @ref Genlist should probably be used.
14 typedef struct _Widget_Data Widget_Data;
18 Evas_Object *scr, *box, *self;
19 Eina_List *items, *selected, *to_delete;
20 Elm_List_Item *last_selected_item;
23 Evas_Coord minw[2], minh[2];
24 Eina_Bool scr_minw : 1;
25 Eina_Bool scr_minh : 1;
31 } history[SWIPE_MOVES];
33 Eina_Bool fix_pending : 1;
34 Eina_Bool on_hold : 1;
36 Eina_Bool always_select : 1;
37 Eina_Bool longpressed : 1;
38 Eina_Bool wasselected : 1;
47 Evas_Object *icon, *end;
49 Ecore_Timer *long_timer;
50 Ecore_Timer *swipe_timer;
51 Eina_Bool deleted : 1;
52 Eina_Bool disabled : 1;
54 Eina_Bool is_even : 1;
55 Eina_Bool is_separator : 1;
57 Eina_Bool selected : 1;
58 Eina_Bool hilighted : 1;
59 Eina_Bool dummy_icon : 1;
60 Eina_Bool dummy_end : 1;
63 static const char *widtype = NULL;
64 static void _del_hook(Evas_Object *obj);
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;
444 elm_widget_show_region_get(obj, &x, &y, &w, &h);
445 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
449 _disable_hook(Evas_Object *obj)
451 Widget_Data *wd = elm_widget_data_get(obj);
453 if (elm_widget_disabled_get(obj))
455 _signal_emit_hook(obj, "elm,state,disabled", "elm");
456 elm_widget_scroll_freeze_push(obj);
457 elm_widget_scroll_hold_push(obj);
458 /* FIXME: if we get to have a way to only un-hilight items
459 * in the future, keeping them selected... */
460 _deselect_all_items(wd);
464 _signal_emit_hook(obj, "elm,state,enabled", "elm");
465 elm_widget_scroll_freeze_pop(obj);
466 elm_widget_scroll_hold_pop(obj);
471 _sizing_eval(Evas_Object *obj)
474 Widget_Data *wd = elm_widget_data_get(obj);
476 Evas_Coord vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
479 evas_object_size_hint_min_get(wd->box, &minw, &minh);
480 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
481 evas_object_size_hint_weight_get(wd->box, &xw, &yw);
482 if (!wd->scr) return;
483 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
486 if ((minw > 0) && (vw < minw)) vw = minw;
487 else if ((maxw > 0) && (vw > maxw)) vw = maxw;
489 else if (minw > 0) vw = minw;
492 if ((minh > 0) && (vh < minh)) vh = minh;
493 else if ((maxh > 0) && (vh > maxh)) vh = maxh;
495 else if (minh > 0) vh = minh;
496 evas_object_resize(wd->box, vw, vh);
499 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
501 if (wd->scr_minw) w = vmw + minw;
502 if (wd->scr_minh) h = vmh + minh;
504 evas_object_size_hint_max_get(obj, &maxw, &maxh);
505 if ((maxw > 0) && (w > maxw))
507 if ((maxh > 0) && (h > maxh))
510 evas_object_size_hint_min_set(obj, w, h);
514 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
516 Widget_Data *wd = elm_widget_data_get(obj);
517 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
522 _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)
524 Widget_Data *wd = elm_widget_data_get(obj);
525 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
526 emission, source, func_cb, data);
530 _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)
532 Widget_Data *wd = elm_widget_data_get(obj);
533 edje_object_signal_callback_del_full(
534 elm_smart_scroller_edje_object_get(wd->scr),
535 emission, source, func_cb, data);
539 _theme_hook(Evas_Object *obj)
541 Widget_Data *wd = elm_widget_data_get(obj);
551 elm_smart_scroller_object_theme_set(obj, wd->scr, "list", "base",
552 elm_widget_style_get(obj));
553 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
554 edj = elm_smart_scroller_edje_object_get(wd->scr);
555 str = edje_object_data_get(edj, "focus_highlight");
556 if ((str) && (!strcmp(str, "on")))
557 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
559 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
560 elm_object_style_set(wd->scr, elm_widget_style_get(obj));
562 EINA_LIST_FOREACH(wd->items, n, it)
564 edje_object_scale_set(it->base.view, elm_widget_scale_get(obj) * _elm_config->scale);
572 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
574 Widget_Data *wd = elm_widget_data_get(obj);
576 if (elm_widget_focus_get(obj))
578 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
579 evas_object_focus_set(wd->self, EINA_TRUE);
581 if ((wd->selected) && (!wd->last_selected_item))
582 wd->last_selected_item = eina_list_data_get(wd->selected);
586 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
587 evas_object_focus_set(wd->self, EINA_FALSE);
592 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
594 Widget_Data *wd = elm_widget_data_get(data);
601 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
603 Widget_Data *wd = elm_widget_data_get(obj);
604 Evas_Object *sub = event_info;
614 EINA_LIST_FOREACH(wd->items, l, it)
616 if ((sub == it->icon) || (sub == it->end))
618 if (it->icon == sub) it->icon = NULL;
619 if (it->end == sub) it->end = NULL;
620 evas_object_event_callback_del_full
621 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints,
629 wd->fix_pending = EINA_TRUE;
637 _item_hilight(Elm_List_Item *it)
639 Widget_Data *wd = elm_widget_data_get(it->base.widget);
640 const char *selectraise;
643 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
644 if (it->hilighted) return;
647 edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
648 selectraise = edje_object_data_get(it->base.view, "selectraise");
649 if ((selectraise) && (!strcmp(selectraise, "on")))
650 evas_object_raise(it->base.view);
651 it->hilighted = EINA_TRUE;
653 _elm_list_unwalk(wd);
657 _item_select(Elm_List_Item *it)
659 Widget_Data *wd = elm_widget_data_get(it->base.widget);
662 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
665 if (wd->always_select) goto call;
668 it->selected = EINA_TRUE;
669 wd->selected = eina_list_append(wd->selected, it);
673 if (it->func) it->func((void *)it->base.data, it->base.widget, it);
674 evas_object_smart_callback_call(it->base.widget, "selected", it);
676 _elm_list_unwalk(wd);
677 it->wd->last_selected_item = it;
681 _item_unselect(Elm_List_Item *it)
683 Widget_Data *wd = elm_widget_data_get(it->base.widget);
684 const char *stacking, *selectraise;
687 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
688 if (!it->hilighted) return;
691 edje_object_signal_emit(it->base.view, "elm,state,unselected", "elm");
692 stacking = edje_object_data_get(it->base.view, "stacking");
693 selectraise = edje_object_data_get(it->base.view, "selectraise");
694 if ((selectraise) && (!strcmp(selectraise, "on")))
696 if ((stacking) && (!strcmp(stacking, "below")))
697 evas_object_lower(it->base.view);
699 it->hilighted = EINA_FALSE;
702 it->selected = EINA_FALSE;
703 wd->selected = eina_list_remove(wd->selected, it);
704 evas_object_smart_callback_call(it->base.widget, "unselected", it);
707 _elm_list_unwalk(wd);
711 _swipe_cancel(void *data)
713 Elm_List_Item *it = data;
714 Widget_Data *wd = elm_widget_data_get(it->base.widget);
716 if (!wd) return ECORE_CALLBACK_CANCEL;
717 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
718 wd->swipe = EINA_FALSE;
720 return ECORE_CALLBACK_RENEW;
724 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
726 Elm_List_Item *it = data;
727 Widget_Data *wd = elm_widget_data_get(it->base.widget);
728 Evas_Event_Mouse_Move *ev = event_info;
731 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
732 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
736 wd->on_hold = EINA_TRUE;
739 ecore_timer_del(it->long_timer);
740 it->long_timer = NULL;
742 if (!wd->wasselected)
745 if (wd->movements == SWIPE_MOVES) wd->swipe = EINA_TRUE;
748 wd->history[wd->movements].x = ev->cur.canvas.x;
749 wd->history[wd->movements].y = ev->cur.canvas.y;
750 if (abs((wd->history[wd->movements].x - wd->history[0].x)) > 40)
751 wd->swipe = EINA_TRUE;
759 _scroll_edge_left(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
761 Evas_Object *obj = data;
762 evas_object_smart_callback_call(obj, "scroll,edge,left", NULL);
766 _scroll_edge_right(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
768 Evas_Object *obj = data;
769 evas_object_smart_callback_call(obj, "scroll,edge,right", NULL);
773 _scroll_edge_top(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
775 Evas_Object *obj = data;
776 evas_object_smart_callback_call(obj, "scroll,edge,top", NULL);
780 _scroll_edge_bottom(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
782 Evas_Object *obj = data;
783 evas_object_smart_callback_call(obj, "scroll,edge,bottom", NULL);
787 _long_press(void *data)
789 Elm_List_Item *it = data;
790 Widget_Data *wd = elm_widget_data_get(it->base.widget);
795 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
797 it->long_timer = NULL;
802 wd->longpressed = EINA_TRUE;
803 evas_object_smart_callback_call(it->base.widget, "longpressed", it);
806 return ECORE_CALLBACK_CANCEL;
810 _swipe(Elm_List_Item *it)
813 Widget_Data *wd = elm_widget_data_get(it->base.widget);
815 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
817 wd->swipe = EINA_FALSE;
818 for (i = 0; i < wd->movements; i++)
820 sum += wd->history[i].x;
821 if (abs(wd->history[0].y - wd->history[i].y) > 10) return;
824 sum /= wd->movements;
825 if (abs(sum - wd->history[0].x) <= 10) return;
826 evas_object_smart_callback_call(it->base.widget, "swipe", it);
830 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
832 Elm_List_Item *it = data;
833 Widget_Data *wd = elm_widget_data_get(it->base.widget);
834 Evas_Event_Mouse_Down *ev = event_info;
837 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
838 if (ev->button != 1) return;
839 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
840 else wd->on_hold = EINA_FALSE;
841 if (wd->on_hold) return;
842 wd->wasselected = it->selected;
844 wd->longpressed = EINA_FALSE;
845 if (it->long_timer) ecore_timer_del(it->long_timer);
846 it->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, it);
847 if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
848 it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
849 /* Always call the callbacks last - the user may delete our context! */
850 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
852 evas_object_smart_callback_call(it->base.widget, "clicked,double", it);
853 evas_object_smart_callback_call(it->base.widget, "clicked", it); // will be removed
855 wd->swipe = EINA_FALSE;
860 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
862 Elm_List_Item *it = data;
863 Widget_Data *wd = elm_widget_data_get(it->base.widget);
864 Evas_Event_Mouse_Up *ev = event_info;
867 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
868 if (ev->button != 1) return;
869 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
870 else wd->on_hold = EINA_FALSE;
871 wd->longpressed = EINA_FALSE;
874 ecore_timer_del(it->long_timer);
875 it->long_timer = NULL;
879 ecore_timer_del(it->swipe_timer);
880 it->swipe_timer = NULL;
884 if (wd->swipe) _swipe(data);
885 wd->on_hold = EINA_FALSE;
890 if (!wd->wasselected) _item_unselect(it);
897 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
899 _elm_list_walk(wd); // watch out "return" before unwalk!
908 else _item_unselect(it);
915 _item_unselect(wd->selected->data);
921 const Eina_List *l, *l_next;
924 EINA_LIST_FOREACH_SAFE(wd->selected, l, l_next, it2)
925 if (it2 != it) _item_unselect(it2);
931 _elm_list_unwalk(wd);
934 static Elm_List_Item *
935 _item_new(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
937 Widget_Data *wd = elm_widget_data_get(obj);
940 if (!wd) return NULL;
941 it = elm_widget_item_new(obj, Elm_List_Item);
943 it->label = eina_stringshare_add(label);
947 it->base.data = data;
948 it->base.view = edje_object_add(evas_object_evas_get(obj));
949 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_DOWN,
951 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_UP,
953 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_MOVE,
955 evas_object_size_hint_weight_set(it->base.view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
956 evas_object_size_hint_align_set(it->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
959 elm_widget_sub_object_add(obj, it->icon);
960 evas_object_event_callback_add(it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
961 _changed_size_hints, obj);
965 elm_widget_sub_object_add(obj, it->end);
966 evas_object_event_callback_add(it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
967 _changed_size_hints, obj);
973 _elm_list_mode_set_internal(Widget_Data *wd)
978 if (wd->mode == ELM_LIST_LIMIT)
982 wd->scr_minw = EINA_TRUE;
983 wd->scr_minh = EINA_FALSE;
987 wd->scr_minw = EINA_FALSE;
988 wd->scr_minh = EINA_TRUE;
991 else if (wd->mode == ELM_LIST_EXPAND)
993 wd->scr_minw = EINA_TRUE;
994 wd->scr_minh = EINA_TRUE;
998 wd->scr_minw = EINA_FALSE;
999 wd->scr_minh = EINA_FALSE;
1002 _sizing_eval(wd->self);
1006 _fix_items(Evas_Object *obj)
1008 Widget_Data *wd = elm_widget_data_get(obj);
1011 Evas_Coord minw[2] = { 0, 0 }, minh[2] = { 0, 0 };
1014 const char *style = elm_widget_style_get(obj);
1015 const char *it_plain = wd->h_mode ? "h_item" : "item";
1016 const char *it_odd = wd->h_mode ? "h_item_odd" : "item_odd";
1017 const char *it_compress = wd->h_mode ? "h_item_compress" : "item_compress";
1018 const char *it_compress_odd = wd->h_mode ? "h_item_compress_odd" : "item_compress_odd";
1023 wd->fix_pending = EINA_TRUE;
1027 _elm_list_walk(wd); // watch out "return" before unwalk!
1029 EINA_LIST_FOREACH(wd->items, l, it)
1031 if (it->deleted) continue;
1034 evas_object_size_hint_min_get(it->icon, &mw, &mh);
1035 if (mw > minw[0]) minw[0] = mw;
1036 if (mh > minh[0]) minh[0] = mh;
1040 evas_object_size_hint_min_get(it->end, &mw, &mh);
1041 if (mw > minw[1]) minw[1] = mw;
1042 if (mh > minh[1]) minh[1] = mh;
1046 if ((minw[0] != wd->minw[0]) || (minw[1] != wd->minw[1]) ||
1047 (minw[0] != wd->minh[0]) || (minh[1] != wd->minh[1]))
1049 wd->minw[0] = minw[0];
1050 wd->minw[1] = minw[1];
1051 wd->minh[0] = minh[0];
1052 wd->minh[1] = minh[1];
1056 EINA_LIST_FOREACH(wd->items, l, it)
1062 if ((it->even != it->is_even) || (!it->fixed) || (redo))
1064 const char *stacking;
1066 /* FIXME: separators' themes seem to be b0rked */
1067 if (it->is_separator)
1068 _elm_theme_object_set(obj, it->base.view, "separator",
1069 wd->h_mode ? "horizontal" : "vertical",
1071 else if (wd->mode == ELM_LIST_COMPRESS)
1074 _elm_theme_object_set(obj, it->base.view, "list",
1075 it_compress, style);
1077 _elm_theme_object_set(obj, it->base.view, "list",
1078 it_compress_odd, style);
1083 _elm_theme_object_set(obj, it->base.view, "list", it_plain,
1086 _elm_theme_object_set(obj, it->base.view, "list", it_odd,
1089 stacking = edje_object_data_get(it->base.view, "stacking");
1092 if (!strcmp(stacking, "below"))
1093 evas_object_lower(it->base.view);
1094 else if (!strcmp(stacking, "above"))
1095 evas_object_raise(it->base.view);
1097 edje_object_part_text_set(it->base.view, "elm.text", it->label);
1099 if ((!it->icon) && (minh[0] > 0))
1101 it->icon = evas_object_rectangle_add(evas_object_evas_get(it->base.view));
1102 evas_object_color_set(it->icon, 0, 0, 0, 0);
1103 it->dummy_icon = EINA_TRUE;
1105 if ((!it->end) && (minh[1] > 0))
1107 it->end = evas_object_rectangle_add(evas_object_evas_get(it->base.view));
1108 evas_object_color_set(it->end, 0, 0, 0, 0);
1109 it->dummy_end = EINA_TRUE;
1113 evas_object_size_hint_min_set(it->icon, minw[0], minh[0]);
1114 evas_object_size_hint_max_set(it->icon, 99999, 99999);
1115 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
1119 evas_object_size_hint_min_set(it->end, minw[1], minh[1]);
1120 evas_object_size_hint_max_set(it->end, 99999, 99999);
1121 edje_object_part_swallow(it->base.view, "elm.swallow.end", it->end);
1125 // this may call up user and it may modify the list item
1126 // but we're safe as we're flagged as walking.
1127 // just don't process further
1128 edje_object_message_signal_process(it->base.view);
1132 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1133 edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw, mh);
1134 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1135 evas_object_size_hint_min_set(it->base.view, mw, mh);
1136 evas_object_show(it->base.view);
1138 if ((it->selected) || (it->hilighted))
1140 const char *selectraise;
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_signal_emit(it->base.view, "elm,state,selected", "elm");
1149 selectraise = edje_object_data_get(it->base.view, "selectraise");
1150 if ((selectraise) && (!strcmp(selectraise, "on")))
1151 evas_object_raise(it->base.view);
1154 edje_object_signal_emit(it->base.view, "elm,state,disabled",
1157 it->fixed = EINA_TRUE;
1158 it->is_even = it->even;
1163 _elm_list_unwalk(wd);
1166 evas_object_size_hint_min_get(wd->box, &mw, &mh);
1168 _elm_list_mode_set_internal(wd);
1172 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1174 Widget_Data *wd = elm_widget_data_get(obj);
1177 elm_smart_scroller_hold_set(wd->scr, EINA_TRUE);
1181 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1183 Widget_Data *wd = elm_widget_data_get(obj);
1186 elm_smart_scroller_hold_set(wd->scr, EINA_FALSE);
1190 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1192 Widget_Data *wd = elm_widget_data_get(obj);
1195 elm_smart_scroller_freeze_set(wd->scr, EINA_TRUE);
1199 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1201 Widget_Data *wd = elm_widget_data_get(obj);
1204 elm_smart_scroller_freeze_set(wd->scr, EINA_FALSE);
1208 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1214 * Adds a list object.
1216 * @param parent The parent object
1217 * @return The created object or NULL upon failure
1222 elm_list_add(Evas_Object *parent)
1227 Evas_Coord minw, minh;
1229 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1231 wd = ELM_NEW(Widget_Data);
1232 e = evas_object_evas_get(parent);
1233 if (!e) return NULL;
1234 wd->self = obj = elm_widget_add(e);
1235 ELM_SET_WIDTYPE(widtype, "list");
1236 elm_widget_type_set(obj, "list");
1237 elm_widget_sub_object_add(parent, obj);
1238 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1239 elm_widget_data_set(obj, wd);
1240 elm_widget_del_hook_set(obj, _del_hook);
1241 elm_widget_theme_hook_set(obj, _theme_hook);
1242 elm_widget_disable_hook_set(obj, _disable_hook);
1243 elm_widget_can_focus_set(obj, EINA_TRUE);
1244 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1245 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1246 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1247 elm_widget_event_hook_set(obj, _event_hook);
1249 wd->scr = elm_smart_scroller_add(e);
1250 elm_smart_scroller_widget_set(wd->scr, obj);
1251 elm_widget_resize_object_set(obj, wd->scr);
1252 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1253 _changed_size_hints, obj);
1254 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
1255 evas_object_size_hint_min_set(obj, minw, minh);
1256 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
1258 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
1259 _elm_config->thumbscroll_bounce_enable);
1261 wd->box = elm_box_add(parent);
1262 elm_box_homogenous_set(wd->box, 1);
1263 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1264 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1265 elm_widget_on_show_region_hook_set(wd->box, _show_region_hook, obj);
1266 elm_widget_sub_object_add(obj, wd->box);
1267 elm_smart_scroller_child_set(wd->scr, wd->box);
1268 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1269 _changed_size_hints, obj);
1271 evas_object_show(wd->box);
1275 wd->mode = ELM_LIST_SCROLL;
1277 evas_object_smart_callback_add(wd->scr, "edge,left", _scroll_edge_left, obj);
1278 evas_object_smart_callback_add(wd->scr, "edge,right", _scroll_edge_right, obj);
1279 evas_object_smart_callback_add(wd->scr, "edge,top", _scroll_edge_top, obj);
1280 evas_object_smart_callback_add(wd->scr, "edge,bottom", _scroll_edge_bottom, obj);
1282 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1283 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1284 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1285 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1286 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1293 * Appends an item to the list object.
1295 * @param obj The list object
1296 * @param label The label of the list item
1297 * @param icon The icon object to use for the left side of the item
1298 * @param end The icon object to use for the right side of the item
1299 * @param func The function to call when the item is clicked
1300 * @param data The data to associate with the item for related callbacks
1302 * @return The created item or NULL upon failure
1306 EAPI Elm_List_Item *
1307 elm_list_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1309 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1310 Widget_Data *wd = elm_widget_data_get(obj);
1311 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1313 wd->items = eina_list_append(wd->items, it);
1314 it->node = eina_list_last(wd->items);
1315 elm_box_pack_end(wd->box, it->base.view);
1320 * Prepends an item to the list object.
1322 * @param obj The list object
1323 * @param label The label of the list item
1324 * @param icon The icon object to use for the left side of the item
1325 * @param end The icon object to use for the right side of the item
1326 * @param func The function to call when the item is clicked
1327 * @param data The data to associate with the item for related callbacks
1329 * @return The created item or NULL upon failure
1333 EAPI Elm_List_Item *
1334 elm_list_item_prepend(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1336 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1337 Widget_Data *wd = elm_widget_data_get(obj);
1338 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1340 wd->items = eina_list_prepend(wd->items, it);
1341 it->node = wd->items;
1342 elm_box_pack_start(wd->box, it->base.view);
1347 * Inserts an item into the list object before @p before.
1349 * @param obj The list object
1350 * @param before The list item to insert before
1351 * @param label The label of the list item
1352 * @param icon The icon object to use for the left side of the item
1353 * @param end The icon object to use for the right side of the item
1354 * @param func The function to call when the item is clicked
1355 * @param data The data to associate with the item for related callbacks
1357 * @return The created item or NULL upon failure
1361 EAPI Elm_List_Item *
1362 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)
1367 EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
1368 if (!before->node) return NULL;
1369 ELM_LIST_ITEM_CHECK_DELETED_RETURN(before, NULL);
1371 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1372 wd = elm_widget_data_get(obj);
1373 if (!wd) return NULL;
1374 it = _item_new(obj, label, icon, end, func, data);
1375 wd->items = eina_list_prepend_relative_list(wd->items, it, before->node);
1376 it->node = before->node->prev;
1377 elm_box_pack_before(wd->box, it->base.view, before->base.view);
1382 * Inserts an item into the list object after @p after.
1384 * @param obj The list object
1385 * @param after The list item to insert after
1386 * @param label The label of the list item
1387 * @param icon The icon object to use for the left side of the item
1388 * @param end The icon object to use for the right side of the item
1389 * @param func The function to call when the item is clicked
1390 * @param data The data to associate with the item for related callbacks
1392 * @return The created item or NULL upon failure
1396 EAPI Elm_List_Item *
1397 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)
1402 EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
1403 if (!after->node) return NULL;
1404 ELM_LIST_ITEM_CHECK_DELETED_RETURN(after, NULL);
1406 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1407 wd = elm_widget_data_get(obj);
1408 if (!wd) return NULL;
1409 it = _item_new(obj, label, icon, end, func, data);
1410 wd->items = eina_list_append_relative_list(wd->items, it, after->node);
1411 it->node = after->node->next;
1412 elm_box_pack_after(wd->box, it->base.view, after->base.view);
1417 * Insert a new item into the sorted list object.
1419 * @param obj The list object
1420 * @param label The label of the list item
1421 * @param icon The icon object to use for the left side of the item
1422 * @param end The icon object to use for the right side of the item
1423 * @param func The function to call when the item is clicked
1424 * @param data The data to associate with the item for related callbacks
1425 * @param cmp_func The function called for the sort.
1427 * @return The created item or NULL upon failure
1431 EAPI Elm_List_Item *
1432 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)
1434 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1435 Widget_Data *wd = elm_widget_data_get(obj);
1436 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1439 wd->items = eina_list_sorted_insert(wd->items, cmp_func, it);
1440 l = eina_list_data_find_list(wd->items, it);
1441 l = eina_list_next(l);
1444 it->node = eina_list_last(wd->items);
1445 elm_box_pack_end(wd->box, it->base.view);
1449 Elm_List_Item *before = eina_list_data_get(l);
1450 it->node = before->node->prev;
1451 elm_box_pack_before(wd->box, it->base.view, before->base.view);
1457 * Clears a list of all items.
1459 * @param obj The list object
1464 elm_list_clear(Evas_Object *obj)
1466 ELM_CHECK_WIDTYPE(obj, widtype);
1467 Widget_Data *wd = elm_widget_data_get(obj);
1471 if (!wd->items) return;
1473 eina_list_free(wd->selected);
1474 wd->selected = NULL;
1476 if (wd->walking > 0)
1480 EINA_LIST_FOREACH(wd->items, n, it)
1482 if (it->deleted) continue;
1483 it->deleted = EINA_TRUE;
1484 wd->to_delete = eina_list_append(wd->to_delete, it);
1491 EINA_LIST_FREE(wd->items, it)
1493 elm_widget_item_pre_notify_del(it);
1494 _elm_list_item_free(it);
1497 _elm_list_unwalk(wd);
1504 * Starts the list. Call before running show() on the list object.
1506 * @param obj The list object
1511 elm_list_go(Evas_Object *obj)
1513 ELM_CHECK_WIDTYPE(obj, widtype);
1514 Widget_Data *wd = elm_widget_data_get(obj);
1520 * Enables/disables the state of multi-select on the list object.
1522 * @param obj The list object
1523 * @param multi If true, multi-select is enabled
1528 elm_list_multi_select_set(Evas_Object *obj, Eina_Bool multi)
1530 ELM_CHECK_WIDTYPE(obj, widtype);
1531 Widget_Data *wd = elm_widget_data_get(obj);
1537 * Gets the state of multi-select on the list object.
1539 * @param obj The list object
1540 * @return If true, multi-select is enabled
1545 elm_list_multi_select_get(const Evas_Object *obj)
1547 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1548 Widget_Data *wd = elm_widget_data_get(obj);
1549 if (!wd) return EINA_FALSE;
1554 * Set which mode to use for the list with.
1556 * @param obj The list object
1557 * @param mode One of @c ELM_LIST_COMPRESS, @c ELM_LIST_SCROLL, @c
1558 * ELM_LIST_LIMIT or @c ELM_LIST_EXPAND.
1560 * @note Default value is @c ELM_LIST_SCROLL. At this mode, the list
1561 * object won't set any of its size hints to inform how a possible
1562 * container should resize it. Then, if it's not created as a "resize
1563 * object", it might end with zero dimensions. The list will respect
1564 * the container's geometry and, if any of its items won't fit into
1565 * its transverse axis, one will be able to scroll it in that
1566 * direction. @c ELM_LIST_COMPRESS is the same as the previous, except
1567 * that it <b>won't</b> let one scroll in the transverse axis, on
1568 * those cases (large items will get cropped). @c ELM_LIST_LIMIT will
1569 * actually set a minimun size hint on the list object, so that
1570 * containers may respect it (and resize itself to fit the child
1571 * properly). More specifically, a minimum size hint will be set for
1572 * its transverse axis, so that the <b>largest</b> item in that
1573 * direction fits well. @c ELM_LIST_EXPAND, besides setting a minimum
1574 * size on the transverse axis, just like the previous mode, will set
1575 * a minimum size on the longitudinal axis too, trying to reserve
1576 * space to all its children to be visible at a time. The last two
1577 * modes can always have effects bounded by setting the list object's
1578 * maximum size hints, though.
1583 elm_list_mode_set(Evas_Object *obj, Elm_List_Mode mode)
1585 ELM_CHECK_WIDTYPE(obj, widtype);
1589 wd = elm_widget_data_get(obj);
1592 if (wd->mode == mode)
1596 _elm_list_mode_set_internal(wd);
1600 * Get the mode the list is at.
1602 * @param obj The list object
1603 * @return mode One of @c ELM_LIST_COMPRESS, @c ELM_LIST_SCROLL or @c
1604 * ELM_LIST_LIMIT (@c ELM_LIST_LAST on errors).
1606 * @note see elm_list_mode_set() for more information.
1611 elm_list_mode_get(const Evas_Object *obj)
1613 ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
1614 Widget_Data *wd = elm_widget_data_get(obj);
1615 if (!wd) return ELM_LIST_LAST;
1620 * Enables/disables horizontal mode of the list.
1622 * @param obj The list object
1623 * @param mode If true, horizontale mode is enabled
1625 * @note Bounce options for the list will be reset to default values
1626 * with this funcion. Re-call elm_list_bounce_set() once more after
1627 * this one, if you had custom values.
1632 elm_list_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1634 ELM_CHECK_WIDTYPE(obj, widtype);
1637 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1639 wd = elm_widget_data_get(obj);
1643 if (wd->h_mode == horizontal)
1646 wd->h_mode = horizontal;
1647 elm_box_horizontal_set(wd->box, horizontal);
1651 evas_object_size_hint_weight_set(wd->box, 0.0, EVAS_HINT_EXPAND);
1652 evas_object_size_hint_align_set(wd->box, 0.0, EVAS_HINT_FILL);
1653 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1657 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1658 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1659 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE, bounce);
1662 _elm_list_mode_set_internal(wd);
1666 * Retrieve whether horizontal mode is enabled for a list.
1668 * @param obj The list object
1669 * @return @c EINA_TRUE, if horizontal mode is enabled and @c
1670 * EINA_FALSE, otherwise.
1672 * @note see elm_list_horizontal_set() for more information.
1677 elm_list_horizontal_get(const Evas_Object *obj)
1679 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1683 wd = elm_widget_data_get(obj);
1691 * Enables/disables the state of always_select, meaning that
1692 * an item will always be selected.
1694 * @param obj The list object
1695 * @param always_select If true, always_select is enabled
1700 elm_list_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
1702 ELM_CHECK_WIDTYPE(obj, widtype);
1703 Widget_Data *wd = elm_widget_data_get(obj);
1705 wd->always_select = always_select;
1709 * Gets the state of always_select.
1710 * See also elm_list_always_select_mode_set()
1712 * @param obj The list object
1713 * @return If true, always_select is enabled
1718 elm_list_always_select_mode_get(const Evas_Object *obj)
1720 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1721 Widget_Data *wd = elm_widget_data_get(obj);
1722 if (!wd) return EINA_FALSE;
1723 return wd->always_select;
1727 * Returns a list of all the list items.
1729 * @param obj The list object
1730 * @return An Eina_List* of the list items, or NULL on failure
1734 EAPI const Eina_List *
1735 elm_list_items_get(const Evas_Object *obj)
1737 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1738 Widget_Data *wd = elm_widget_data_get(obj);
1739 if (!wd) return NULL;
1744 * Returns the currently selected list item.
1746 * @param obj The list object
1747 * @return The selected list item, or NULL on failure
1751 EAPI Elm_List_Item *
1752 elm_list_selected_item_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;
1757 if (wd->selected) return wd->selected->data;
1762 * Returns a list of the currently selected list items.
1764 * @param obj The list object
1765 * @return An Eina_List* of the selected list items, or NULL on failure
1769 EAPI const Eina_List *
1770 elm_list_selected_items_get(const Evas_Object *obj)
1772 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1773 Widget_Data *wd = elm_widget_data_get(obj);
1774 if (!wd) return NULL;
1775 return wd->selected;
1779 * Sets if item is a separator.
1781 * @param it The list item object
1785 elm_list_item_separator_set(Elm_List_Item *it, Eina_Bool setting)
1787 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1788 it->is_separator = !!setting;
1792 * Returns EINA_TRUE if Elm_List_Item is a separator.
1794 * @param it The list item object
1797 elm_list_item_separator_get(const Elm_List_Item *it)
1799 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1800 return it->is_separator;
1805 * Sets the selected state of @p it.
1807 * @param it The list item
1808 * @param selected Enables/disables the selected state
1813 elm_list_item_selected_set(Elm_List_Item *it, Eina_Bool selected)
1815 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1817 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1820 selected = !!selected;
1821 if (it->selected == selected) return;
1829 while (wd->selected)
1830 _item_unselect(wd->selected->data);
1838 _elm_list_unwalk(wd);
1842 * Gets the selected state of @p it.
1844 * @param it The list item
1845 * @return If true, the item is selected
1850 elm_list_item_selected_get(const Elm_List_Item *it)
1852 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1853 return it->selected;
1857 * Brings @p it to the center of the list view.
1859 * @param it The list item
1864 elm_list_item_show(Elm_List_Item *it)
1866 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1867 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1868 Evas_Coord bx, by, bw, bh;
1869 Evas_Coord x, y, w, h;
1871 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1872 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
1876 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
1880 * Bring in the given item
1882 * This causes list to jump to the given item @p it and show it (by scrolling),
1883 * if it is not fully visible. This may use animation to do so and take a
1886 * @param it The item
1891 elm_list_item_bring_in(Elm_List_Item *it)
1893 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1894 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1895 Evas_Coord bx, by, bw, bh;
1896 Evas_Coord x, y, w, h;
1898 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1899 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
1903 elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);
1907 * Deletes item @p it from the list.
1909 * @param it The list item to delete
1914 elm_list_item_del(Elm_List_Item *it)
1916 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1917 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1920 if (it->selected) _item_unselect(it);
1922 if (wd->walking > 0)
1924 if (it->deleted) return;
1925 it->deleted = EINA_TRUE;
1926 wd->to_delete = eina_list_append(wd->to_delete, it);
1930 wd->items = eina_list_remove_list(wd->items, it->node);
1934 elm_widget_item_pre_notify_del(it);
1935 _elm_list_item_free(it);
1937 _elm_list_unwalk(wd);
1941 * Set the function called when a list item is freed.
1943 * @param it The item to set the callback on
1944 * @param func The function called
1949 elm_list_item_del_cb_set(Elm_List_Item *it, Evas_Smart_Cb func)
1951 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1952 elm_widget_item_del_cb_set(it, func);
1956 * Returns the data associated with the item.
1958 * @param it The list item
1959 * @return The data associated with @p it
1964 elm_list_item_data_get(const Elm_List_Item *it)
1966 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1967 return elm_widget_item_data_get(it);
1971 * Returns the left side icon associated with the item.
1973 * @param it The list item
1974 * @return The left side icon associated with @p it
1979 elm_list_item_icon_get(const Elm_List_Item *it)
1981 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1982 if (it->dummy_icon) return NULL;
1987 * Sets the left side icon associated with the item.
1989 * Once the icon object is set, a previously set one will be deleted.
1990 * You probably don't want, then, to have the <b>same</b> icon object set
1991 * for more than one item of the list.
1993 * @param it The list item
1994 * @param icon The left side icon object to associate with @p it
1999 elm_list_item_icon_set(Elm_List_Item *it, Evas_Object *icon)
2001 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2002 if (it->icon == icon) return;
2003 if ((it->dummy_icon) && (!icon)) return;
2006 evas_object_del(it->icon);
2007 it->dummy_icon = EINA_FALSE;
2011 icon = evas_object_rectangle_add(evas_object_evas_get(it->base.widget));
2012 evas_object_color_set(icon, 0, 0, 0, 0);
2013 it->dummy_icon = EINA_TRUE;
2017 evas_object_del(it->icon);
2022 edje_object_part_swallow(it->base.view, "elm.swallow.icon", icon);
2026 * Gets the right side icon associated with the item.
2028 * @param it The list item
2029 * @return The right side icon object associated with @p it
2034 elm_list_item_end_get(const Elm_List_Item *it)
2036 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2037 if (it->dummy_end) return NULL;
2042 * Sets the right side icon associated with the item.
2044 * Once the icon object is set, a previously set one will be deleted.
2045 * You probably don't want, then, to have the <b>same</b> icon object set
2046 * for more than one item of the list.
2048 * @param it The list item
2049 * @param icon The right side icon object to associate with @p it
2054 elm_list_item_end_set(Elm_List_Item *it, Evas_Object *end)
2056 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2057 if (it->end == end) return;
2058 if ((it->dummy_end) && (!end)) return;
2061 evas_object_del(it->end);
2062 it->dummy_icon = EINA_FALSE;
2066 end = evas_object_rectangle_add(evas_object_evas_get(it->base.widget));
2067 evas_object_color_set(end, 0, 0, 0, 0);
2068 it->dummy_end = EINA_TRUE;
2072 evas_object_del(it->end);
2077 edje_object_part_swallow(it->base.view, "elm.swallow.end", end);
2081 * Gets the base object of the item.
2083 * @param it The list item
2084 * @return The base object associated with @p it
2089 elm_list_item_base_get(const Elm_List_Item *it)
2091 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2092 return it->base.view;
2096 * Gets the label of the item.
2098 * @param it The list item
2099 * @return The label of @p it
2104 elm_list_item_label_get(const Elm_List_Item *it)
2106 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2111 * Sets the label of the item.
2113 * @param it The list item
2114 * @param text The label of @p it
2119 elm_list_item_label_set(Elm_List_Item *it, const char *text)
2121 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2122 if (!eina_stringshare_replace(&it->label, text)) return;
2124 edje_object_part_text_set(it->base.view, "elm.text", it->label);
2128 * Gets the item before @p it in the list.
2130 * @param it The list item
2131 * @return The item before @p it, or NULL on failure
2135 EAPI Elm_List_Item *
2136 elm_list_item_prev(const Elm_List_Item *it)
2138 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2139 if (it->node->prev) return it->node->prev->data;
2144 * Gets the item after @p it in the list.
2146 * @param it The list item
2147 * @return The item after @p it, or NULL on failure
2151 EAPI Elm_List_Item *
2152 elm_list_item_next(const Elm_List_Item *it)
2154 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2155 if (it->node->next) return it->node->next->data;
2160 * Set the text to be shown in the list item.
2162 * @param item Target item
2163 * @param text The text to set in the content
2165 * Setup the text as tooltip to object. The item can have only one tooltip,
2166 * so any previous tooltip data is removed.
2171 elm_list_item_tooltip_text_set(Elm_List_Item *item, const char *text)
2173 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2174 elm_widget_item_tooltip_text_set(item, text);
2178 * Set the content to be shown in the tooltip item
2180 * Setup the tooltip to item. The item can have only one tooltip,
2181 * so any previous tooltip data is removed. @p func(with @p data) will
2182 * be called every time that need show the tooltip and it should
2183 * return a valid Evas_Object. This object is then managed fully by
2184 * tooltip system and is deleted when the tooltip is gone.
2186 * @param item the list item being attached a tooltip.
2187 * @param func the function used to create the tooltip contents.
2188 * @param data what to provide to @a func as callback data/context.
2189 * @param del_cb called when data is not needed anymore, either when
2190 * another callback replaces @func, the tooltip is unset with
2191 * elm_list_item_tooltip_unset() or the owner @a item
2192 * dies. This callback receives as the first parameter the
2193 * given @a data, and @c event_info is the item.
2198 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)
2200 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2201 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
2205 * Unset tooltip from item
2207 * @param item list item to remove previously set tooltip.
2209 * Remove tooltip from item. The callback provided as del_cb to
2210 * elm_list_item_tooltip_content_cb_set() will be called to notify
2211 * it is not used anymore.
2213 * @see elm_list_item_tooltip_content_cb_set()
2218 elm_list_item_tooltip_unset(Elm_List_Item *item)
2220 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2221 elm_widget_item_tooltip_unset(item);
2225 * Sets a different style for this item tooltip.
2227 * @note before you set a style you should define a tooltip with
2228 * elm_list_item_tooltip_content_cb_set() or
2229 * elm_list_item_tooltip_text_set()
2231 * @param item list item with tooltip already set.
2232 * @param style the theme style to use (default, transparent, ...)
2237 elm_list_item_tooltip_style_set(Elm_List_Item *item, const char *style)
2239 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2240 elm_widget_item_tooltip_style_set(item, style);
2244 * Get the style for this item tooltip.
2246 * @param item list item with tooltip already set.
2247 * @return style the theme style in use, defaults to "default". If the
2248 * object does not have a tooltip set, then NULL is returned.
2253 elm_list_item_tooltip_style_get(const Elm_List_Item *item)
2255 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2256 return elm_widget_item_tooltip_style_get(item);
2260 * Set the cursor to be shown when mouse is over the list item
2262 * @param item Target item
2263 * @param cursor the cursor name to be used.
2265 * @see elm_object_cursor_set()
2269 elm_list_item_cursor_set(Elm_List_Item *item, const char *cursor)
2271 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2272 elm_widget_item_cursor_set(item, cursor);
2276 * Get the cursor to be shown when mouse is over the list item
2278 * @param item list item with cursor already set.
2279 * @return the cursor name.
2284 elm_list_item_cursor_get(const Elm_List_Item *item)
2286 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2287 return elm_widget_item_cursor_get(item);
2291 * Unset the cursor to be shown when mouse is over the list item
2293 * @param item Target item
2295 * @see elm_object_cursor_unset()
2299 elm_list_item_cursor_unset(Elm_List_Item *item)
2301 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2302 elm_widget_item_cursor_unset(item);
2306 * Sets a different style for this item cursor.
2308 * @note before you set a style you should define a cursor with
2309 * elm_list_item_cursor_set()
2311 * @param item list item with cursor already set.
2312 * @param style the theme style to use (default, transparent, ...)
2317 elm_list_item_cursor_style_set(Elm_List_Item *item, const char *style)
2319 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2320 elm_widget_item_cursor_style_set(item, style);
2324 * Get the style for this item cursor.
2326 * @param item list item with cursor already set.
2327 * @return style the theme style in use, defaults to "default". If the
2328 * object does not have a cursor set, then NULL is returned.
2333 elm_list_item_cursor_style_get(const Elm_List_Item *item)
2335 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2336 return elm_widget_item_cursor_style_get(item);
2340 * Set if the cursor set should be searched on the theme or should use
2341 * the provided by the engine, only.
2343 * @note before you set if should look on theme you should define a cursor
2344 * with elm_object_cursor_set(). By default it will only look for cursors
2345 * provided by the engine.
2347 * @param item widget item with cursor already set.
2348 * @param engine_only boolean to define it cursors should be looked only
2349 * between the provided by the engine or searched on widget's theme as well.
2354 elm_list_item_cursor_engine_only_set(Elm_List_Item *item, Eina_Bool engine_only)
2356 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2357 elm_widget_item_cursor_engine_only_set(item, engine_only);
2361 * Get the cursor engine only usage for this item cursor.
2363 * @param item widget item with cursor already set.
2364 * @return engine_only boolean to define it cursors should be looked only
2365 * between the provided by the engine or searched on widget's theme as well. If
2366 * the object does not have a cursor set, then EINA_FALSE is returned.
2371 elm_list_item_cursor_engine_only_get(const Elm_List_Item *item)
2373 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, EINA_FALSE);
2374 return elm_widget_item_cursor_engine_only_get(item);
2380 * This will enable or disable the scroller bounce mode for the list. See
2381 * elm_scroller_bounce_set() for details
2383 * @param obj The list object
2384 * @param h_bounce Allow bounce horizontally
2385 * @param v_bounce Allow bounce vertically
2390 elm_list_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
2392 ELM_CHECK_WIDTYPE(obj, widtype);
2393 Widget_Data *wd = elm_widget_data_get(obj);
2396 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
2400 * Get the bounce mode
2402 * @param obj The List object
2403 * @param h_bounce Allow bounce horizontally
2404 * @param v_bounce Allow bounce vertically
2409 elm_list_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
2411 ELM_CHECK_WIDTYPE(obj, widtype);
2412 Widget_Data *wd = elm_widget_data_get(obj);
2414 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
2418 * Set the scrollbar policy
2420 * This sets the scrollbar visibility policy for the given list scroller.
2421 * ELM_SMART_SCROLLER_POLICY_AUTO means the scrollber is made visible if it
2422 * is needed, and otherwise kept hidden. ELM_SMART_SCROLLER_POLICY_ON turns
2423 * it on all the time, and ELM_SMART_SCROLLER_POLICY_OFF always keeps it off.
2424 * This applies respectively for the horizontal and vertical scrollbars.
2426 * @param obj The list object
2427 * @param policy_h Horizontal scrollbar policy
2428 * @param policy_v Vertical scrollbar policy
2433 elm_list_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
2435 ELM_CHECK_WIDTYPE(obj, widtype);
2436 Widget_Data *wd = elm_widget_data_get(obj);
2438 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
2439 (policy_v >= ELM_SCROLLER_POLICY_LAST))
2441 elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
2445 elm_list_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
2447 ELM_CHECK_WIDTYPE(obj, widtype);
2448 Widget_Data *wd = elm_widget_data_get(obj);
2449 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
2450 if ((!wd) || (!wd->scr)) return;
2451 elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
2452 if (policy_h) *policy_h = (Elm_Scroller_Policy) s_policy_h;
2453 if (policy_v) *policy_v = (Elm_Scroller_Policy) s_policy_v;
2457 * Sets the disabled/enabled state of a list item.
2459 * A disabled item cannot be selected or unselected. It will also
2460 * change its appearance (generally greyed out). This sets the
2461 * disabled state (@c EINA_TRUE for disabled, @c EINA_FALSE for
2464 * @param it The item
2465 * @param disabled The disabled state
2470 elm_list_item_disabled_set(Elm_List_Item *it, Eina_Bool disabled)
2472 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2474 if (it->disabled == disabled)
2477 it->disabled = !!disabled;
2480 edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
2482 edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
2486 * Get the disabled/enabled state of a list item
2488 * @param it The item
2489 * @return The disabled state
2491 * See elm_list_item_disabled_set().
2496 elm_list_item_disabled_get(const Elm_List_Item *it)
2498 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
2500 return it->disabled;