1 #include <Elementary.h>
8 * A list is a very simple type of list widget. For more robust
9 * lists, @ref Genlist should probably be used.
12 typedef struct _Widget_Data Widget_Data;
16 Evas_Object *scr, *box, *self;
17 Eina_List *items, *selected, *to_delete;
19 Evas_Coord minw[2], minh[2];
21 Eina_Bool fix_pending : 1;
22 Eina_Bool on_hold : 1;
24 Eina_Bool always_select : 1;
25 Eina_Bool longpressed : 1;
26 Eina_Bool wasselected : 1;
32 Evas_Object *obj, *base;
34 Evas_Object *icon, *end;
38 Ecore_Timer *long_timer;
39 Eina_Bool deleted : 1;
41 Eina_Bool is_even : 1;
42 Eina_Bool is_separator : 1;
44 Eina_Bool selected : 1;
45 Eina_Bool hilighted : 1;
46 Eina_Bool dummy_icon : 1;
47 Eina_Bool dummy_end : 1;
50 static const char *widtype = NULL;
51 static void _del_hook(Evas_Object *obj);
52 static void _theme_hook(Evas_Object *obj);
53 static void _sizing_eval(Evas_Object *obj);
54 static void _on_focus_hook(void *data, Evas_Object *obj);
55 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
56 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
57 static void _fix_items(Evas_Object *obj);
58 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
59 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
60 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
62 #define ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ...) \
65 fprintf(stderr, "ERROR: %s:%d:%s() "#it" is NULL.\n", \
66 __FILE__, __LINE__, __FUNCTION__); \
69 else if (it->deleted) \
71 fprintf(stderr, "ERROR: %s:%d:%s() "#it" has been DELETED.\n", \
72 __FILE__, __LINE__, __FUNCTION__); \
79 _elm_list_item_call_del_cb(Elm_List_Item *it)
81 if (it->del_cb) it->del_cb((void *)it->data, it->obj, it);
85 _elm_list_item_free(Elm_List_Item *it)
87 evas_object_event_callback_del_full
88 (it->base, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, it);
89 evas_object_event_callback_del_full
90 (it->base, EVAS_CALLBACK_MOUSE_UP, _mouse_up, it);
91 evas_object_event_callback_del_full
92 (it->base, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, it);
95 evas_object_event_callback_del_full
96 (it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
97 _changed_size_hints, it->obj);
100 evas_object_event_callback_del_full
101 (it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
102 _changed_size_hints, it->obj);
104 eina_stringshare_del(it->label);
106 if (it->long_timer) ecore_timer_del(it->long_timer);
107 if (it->icon) evas_object_del(it->icon);
108 if (it->end) evas_object_del(it->end);
109 if (it->base) evas_object_del(it->base);
114 _elm_list_process_deletions(Widget_Data *wd)
118 wd->walking++; // avoid nested deletion and also _sub_del() fix_items
120 EINA_LIST_FREE(wd->to_delete, it)
122 _elm_list_item_call_del_cb(it);
124 wd->items = eina_list_remove_list(wd->items, it->node);
125 _elm_list_item_free(it);
132 _elm_list_walk(Widget_Data *wd)
136 fprintf(stderr, "ERROR: walking was negative. fixed!\n");
143 _elm_list_unwalk(Widget_Data *wd)
148 fprintf(stderr, "ERROR: walking became negative. fixed!\n");
156 _elm_list_process_deletions(wd);
160 wd->fix_pending = EINA_FALSE;
161 _fix_items(wd->self);
162 _sizing_eval(wd->self);
167 _del_hook(Evas_Object *obj)
169 Widget_Data *wd = elm_widget_data_get(obj);
174 if (wd->walking != 0)
175 fprintf(stderr, "ERROR: list deleted while walking.\n");
178 EINA_LIST_FOREACH(wd->items, n, it) _elm_list_item_call_del_cb(it);
179 _elm_list_unwalk(wd);
180 if (wd->to_delete) fprintf(stderr, "ERROR: leaking nodes!\n");
182 EINA_LIST_FREE(wd->items, it) _elm_list_item_free(it);
183 eina_list_free(wd->selected);
188 _sizing_eval(Evas_Object *obj)
190 Widget_Data *wd = elm_widget_data_get(obj);
191 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
195 evas_object_size_hint_min_get(wd->scr, &minw, &minh);
196 evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
197 evas_object_size_hint_min_set(obj, minw, minh);
198 evas_object_size_hint_max_set(obj, maxw, maxh);
203 _theme_hook(Evas_Object *obj)
205 Widget_Data *wd = elm_widget_data_get(obj);
212 elm_scroller_custom_widget_base_theme_set(wd->scr, "list", "base");
213 elm_object_style_set(wd->scr, elm_widget_style_get(obj));
214 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
216 EINA_LIST_FOREACH(wd->items, n, it)
225 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
227 Widget_Data *wd = elm_widget_data_get(obj);
229 if (elm_widget_focus_get(obj))
230 evas_object_focus_set(wd->scr, 1);
232 evas_object_focus_set(wd->scr, 0);
236 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
238 Widget_Data *wd = elm_widget_data_get(data);
241 // _sizing_eval(data);
245 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
247 Widget_Data *wd = elm_widget_data_get(obj);
248 Evas_Object *sub = event_info;
258 EINA_LIST_FOREACH(wd->items, l, it)
260 if ((sub == it->icon) || (sub == it->end))
262 if (it->icon == sub) it->icon = NULL;
263 if (it->end == sub) it->end = NULL;
264 evas_object_event_callback_del_full
265 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints,
273 wd->fix_pending = EINA_TRUE;
281 _item_hilight(Elm_List_Item *it)
283 Widget_Data *wd = elm_widget_data_get(it->obj);
284 const char *selectraise;
287 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
288 if (it->hilighted) return;
291 edje_object_signal_emit(it->base, "elm,state,selected", "elm");
292 selectraise = edje_object_data_get(it->base, "selectraise");
293 if ((selectraise) && (!strcmp(selectraise, "on")))
294 evas_object_raise(it->base);
295 it->hilighted = EINA_TRUE;
297 _elm_list_unwalk(wd);
301 _item_select(Elm_List_Item *it)
303 Widget_Data *wd = elm_widget_data_get(it->obj);
306 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
309 if (wd->always_select) goto call;
312 it->selected = EINA_TRUE;
313 wd->selected = eina_list_append(wd->selected, it);
317 if (it->func) it->func((void *)it->data, it->obj, it);
318 evas_object_smart_callback_call(it->obj, "selected", it);
320 _elm_list_unwalk(wd);
324 _item_unselect(Elm_List_Item *it)
326 Widget_Data *wd = elm_widget_data_get(it->obj);
327 const char *stacking, *selectraise;
330 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
331 if (!it->hilighted) return;
334 edje_object_signal_emit(it->base, "elm,state,unselected", "elm");
335 stacking = edje_object_data_get(it->base, "stacking");
336 selectraise = edje_object_data_get(it->base, "selectraise");
337 if ((selectraise) && (!strcmp(selectraise, "on")))
339 if ((stacking) && (!strcmp(stacking, "below")))
340 evas_object_lower(it->base);
342 it->hilighted = EINA_FALSE;
345 it->selected = EINA_FALSE;
346 wd->selected = eina_list_remove(wd->selected, it);
347 evas_object_smart_callback_call(it->obj, "unselected", it);
350 _elm_list_unwalk(wd);
354 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
356 Elm_List_Item *it = data;
357 Widget_Data *wd = elm_widget_data_get(it->obj);
358 Evas_Event_Mouse_Move *ev = event_info;
361 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
362 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
366 wd->on_hold = EINA_TRUE;
369 ecore_timer_del(it->long_timer);
370 it->long_timer = NULL;
372 if (!wd->wasselected)
379 _long_press(void *data)
381 Elm_List_Item *it = data;
382 Widget_Data *wd = elm_widget_data_get(it->obj);
384 if (!wd) return ECORE_CALLBACK_CANCEL;
385 it->long_timer = NULL;
386 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, 0);
387 wd->longpressed = EINA_TRUE;
388 evas_object_smart_callback_call(it->obj, "longpressed", it);
389 return ECORE_CALLBACK_CANCEL;
393 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
395 Elm_List_Item *it = data;
396 Widget_Data *wd = elm_widget_data_get(it->obj);
397 Evas_Event_Mouse_Down *ev = event_info;
400 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
401 if (ev->button != 1) return;
402 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
403 else wd->on_hold = EINA_FALSE;
404 if (wd->on_hold) return;
405 wd->wasselected = it->selected;
407 wd->longpressed = EINA_FALSE;
408 if (it->long_timer) ecore_timer_del(it->long_timer);
409 it->long_timer = ecore_timer_add(1.0, _long_press, it);
410 /* Always call the callbacks last - the user may delete our context! */
411 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
412 evas_object_smart_callback_call(it->obj, "clicked", it);
416 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
418 Elm_List_Item *it = data;
419 Widget_Data *wd = elm_widget_data_get(it->obj);
420 Evas_Event_Mouse_Up *ev = event_info;
423 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
424 if (ev->button != 1) return;
425 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
426 else wd->on_hold = EINA_FALSE;
427 wd->longpressed = EINA_FALSE;
430 ecore_timer_del(it->long_timer);
431 it->long_timer = NULL;
435 wd->on_hold = EINA_FALSE;
440 if (!wd->wasselected) _item_unselect(it);
445 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
447 _elm_list_walk(wd); // watch out "return" before unwalk!
456 else _item_unselect(it);
463 _item_unselect(wd->selected->data);
469 const Eina_List *l, *l_next;
472 EINA_LIST_FOREACH_SAFE(wd->selected, l, l_next, it2)
473 if (it2 != it) _item_unselect(it2);
479 _elm_list_unwalk(wd);
482 static Elm_List_Item *
483 _item_new(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
485 Widget_Data *wd = elm_widget_data_get(obj);
488 if (!wd) return NULL;
489 it = calloc(1, sizeof(Elm_List_Item));
491 it->label = eina_stringshare_add(label);
496 it->base = edje_object_add(evas_object_evas_get(obj));
497 evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_DOWN,
499 evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_UP,
501 evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_MOVE,
503 evas_object_size_hint_weight_set(it->base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
504 evas_object_size_hint_align_set(it->base, EVAS_HINT_FILL, EVAS_HINT_FILL);
507 elm_widget_sub_object_add(obj, it->icon);
508 evas_object_event_callback_add(it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
509 _changed_size_hints, obj);
513 elm_widget_sub_object_add(obj, it->end);
514 evas_object_event_callback_add(it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
515 _changed_size_hints, obj);
521 _fix_items(Evas_Object *obj)
523 Widget_Data *wd = elm_widget_data_get(obj);
526 Evas_Coord minw[2] = { 0, 0 }, minh[2] = { 0, 0 };
529 const char *style = elm_widget_style_get(obj);
534 wd->fix_pending = EINA_TRUE;
538 _elm_list_walk(wd); // watch out "return" before unwalk!
540 EINA_LIST_FOREACH(wd->items, l, it)
542 if (it->deleted) continue;
545 evas_object_size_hint_min_get(it->icon, &mw, &mh);
546 if (mw > minw[0]) minw[0] = mw;
547 if (mh > minh[0]) minh[0] = mh;
551 evas_object_size_hint_min_get(it->end, &mw, &mh);
552 if (mw > minw[1]) minw[1] = mw;
553 if (mh > minh[1]) minh[1] = mh;
556 if ((minw[0] != wd->minw[0]) || (minw[1] != wd->minw[1]) ||
557 (minw[0] != wd->minh[0]) || (minh[1] != wd->minh[1]))
559 wd->minw[0] = minw[0];
560 wd->minw[1] = minw[1];
561 wd->minh[0] = minh[0];
562 wd->minh[1] = minh[1];
566 EINA_LIST_FOREACH(wd->items, l, it)
568 if (it->deleted) continue;
570 if ((it->even != it->is_even) || (!it->fixed) || (redo))
572 const char *stacking;
574 if (it->is_separator)
575 _elm_theme_object_set(obj, it->base, "list", "separator", style);
576 else if (wd->mode == ELM_LIST_COMPRESS)
579 _elm_theme_object_set(obj, it->base, "list", "item_compress", style);
581 _elm_theme_object_set(obj, it->base, "list", "item_compress_odd", style);
586 _elm_theme_object_set(obj, it->base, "list", "item", style);
588 _elm_theme_object_set(obj, it->base, "list", "item_odd", style);
590 stacking = edje_object_data_get(it->base, "stacking");
593 if (!strcmp(stacking, "below"))
594 evas_object_lower(it->base);
595 else if (!strcmp(stacking, "above"))
596 evas_object_raise(it->base);
598 edje_object_part_text_set(it->base, "elm.text", it->label);
599 if ((!it->icon) && (minh[0] > 0))
601 it->icon = evas_object_rectangle_add(evas_object_evas_get(it->base));
602 evas_object_color_set(it->icon, 0, 0, 0, 0);
603 it->dummy_icon = EINA_TRUE;
605 if ((!it->end) && (minh[1] > 0))
607 it->end = evas_object_rectangle_add(evas_object_evas_get(it->base));
608 evas_object_color_set(it->end, 0, 0, 0, 0);
609 it->dummy_end = EINA_TRUE;
613 evas_object_size_hint_min_set(it->icon, minw[0], minh[0]);
614 evas_object_size_hint_max_set(it->icon, 99999, 99999);
615 edje_object_part_swallow(it->base, "elm.swallow.icon", it->icon);
619 evas_object_size_hint_min_set(it->end, minw[1], minh[1]);
620 evas_object_size_hint_max_set(it->end, 99999, 99999);
621 edje_object_part_swallow(it->base, "elm.swallow.end", it->end);
625 // this may call up user and it may modify the list item
626 // but we're safe as we're flagged as walking.
627 // just don't process further
628 edje_object_message_signal_process(it->base);
632 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
633 edje_object_size_min_restricted_calc(it->base, &mw, &mh, mw, mh);
634 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
635 evas_object_size_hint_min_set(it->base, mw, mh);
636 evas_object_show(it->base);
638 if ((it->selected) || (it->hilighted))
640 const char *selectraise;
642 // this may call up user and it may modify the list item
643 // but we're safe as we're flagged as walking.
644 // just don't process further
645 edje_object_signal_emit(it->base, "elm,state,selected", "elm");
649 selectraise = edje_object_data_get(it->base, "selectraise");
650 if ((selectraise) && (!strcmp(selectraise, "on")))
651 evas_object_raise(it->base);
652 stacking = edje_object_data_get(it->base, "stacking");
654 it->fixed = EINA_TRUE;
655 it->is_even = it->even;
660 _elm_list_unwalk(wd);
663 evas_object_size_hint_min_get(wd->box, &mw, &mh);
666 if (wd->mode == ELM_LIST_LIMIT)
667 elm_scroller_content_min_limit(wd->scr, 1, 0);
669 elm_scroller_content_min_limit(wd->scr, 0, 0);
675 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
677 Widget_Data *wd = elm_widget_data_get(obj);
680 elm_widget_scroll_hold_push(wd->scr);
684 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
686 Widget_Data *wd = elm_widget_data_get(obj);
689 elm_widget_scroll_hold_pop(wd->scr);
693 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
695 Widget_Data *wd = elm_widget_data_get(obj);
698 elm_widget_scroll_hold_push(wd->scr);
702 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
704 Widget_Data *wd = elm_widget_data_get(obj);
707 elm_widget_scroll_hold_pop(wd->scr);
711 * Adds a list object.
713 * @param parent The parent object
714 * @return The created object or NULL upon failure
719 elm_list_add(Evas_Object *parent)
725 wd = ELM_NEW(Widget_Data);
726 e = evas_object_evas_get(parent);
727 wd->self = obj = elm_widget_add(e);
728 ELM_SET_WIDTYPE(widtype, "list");
729 elm_widget_type_set(obj, "list");
730 elm_widget_sub_object_add(parent, obj);
731 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
732 elm_widget_data_set(obj, wd);
733 elm_widget_del_hook_set(obj, _del_hook);
734 elm_widget_theme_hook_set(obj, _theme_hook);
735 elm_widget_can_focus_set(obj, 1);
737 wd->scr = elm_scroller_add(parent);
738 elm_scroller_custom_widget_base_theme_set(wd->scr, "list", "base");
739 elm_widget_resize_object_set(obj, wd->scr);
741 elm_scroller_bounce_set(wd->scr, 0, 1);
743 wd->box = elm_box_add(parent);
744 elm_box_homogenous_set(wd->box, 1);
745 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
746 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
747 elm_scroller_content_set(wd->scr, wd->box);
748 evas_object_show(wd->box);
750 wd->mode = ELM_LIST_SCROLL;
752 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
753 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
754 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
755 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
756 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
763 * Appends an item to the list object.
765 * @param obj The list object
766 * @param label The label of the list item
767 * @param icon The icon object to use for the left side of the item
768 * @param end The icon object to use for the right side of the item
769 * @param func The function to call when the item is clicked
770 * @param data The data to associate with the item for related callbacks
772 * @return The created item or NULL upon failure
777 elm_list_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
779 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
780 Widget_Data *wd = elm_widget_data_get(obj);
781 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
783 wd->items = eina_list_append(wd->items, it);
784 it->node = eina_list_last(wd->items);
785 elm_box_pack_end(wd->box, it->base);
790 * Prepends an item to the list object.
792 * @param obj The list object
793 * @param label The label of the list item
794 * @param icon The icon object to use for the left side of the item
795 * @param end The icon object to use for the right side of the item
796 * @param func The function to call when the item is clicked
797 * @param data The data to associate with the item for related callbacks
799 * @return The created item or NULL upon failure
804 elm_list_item_prepend(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
806 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
807 Widget_Data *wd = elm_widget_data_get(obj);
808 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
810 wd->items = eina_list_prepend(wd->items, it);
811 it->node = wd->items;
812 elm_box_pack_start(wd->box, it->base);
817 * Inserts an item into the list object before @p before.
819 * @param obj The list object
820 * @param before The list item to insert before
821 * @param label The label of the list item
822 * @param icon The icon object to use for the left side of the item
823 * @param end The icon object to use for the right side of the item
824 * @param func The function to call when the item is clicked
825 * @param data The data to associate with the item for related callbacks
827 * @return The created item or NULL upon failure
832 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)
837 if ((!before) || (!before->node)) return NULL;
838 ELM_LIST_ITEM_CHECK_DELETED_RETURN(before, NULL);
840 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
841 wd = elm_widget_data_get(obj);
842 if (!wd) return NULL;
843 it = _item_new(obj, label, icon, end, func, data);
844 wd->items = eina_list_prepend_relative_list(wd->items, it, before->node);
845 it->node = before->node->prev;
846 elm_box_pack_before(wd->box, it->base, before->base);
851 * Inserts an item into the list object after @p after.
853 * @param obj The list object
854 * @param after The list item to insert after
855 * @param label The label of the list item
856 * @param icon The icon object to use for the left side of the item
857 * @param end The icon object to use for the right side of the item
858 * @param func The function to call when the item is clicked
859 * @param data The data to associate with the item for related callbacks
861 * @return The created item or NULL upon failure
866 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)
871 if ((!after) || (!after->node)) return NULL;
872 ELM_LIST_ITEM_CHECK_DELETED_RETURN(after, NULL);
874 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
875 wd = elm_widget_data_get(obj);
876 if (!wd) return NULL;
877 it = _item_new(obj, label, icon, end, func, data);
878 wd->items = eina_list_append_relative_list(wd->items, it, after->node);
879 it->node = after->node->next;
880 elm_box_pack_after(wd->box, it->base, after->base);
885 * Insert a new item into the sorted list object.
887 * @param obj The list object
888 * @param label The label of the list item
889 * @param icon The icon object to use for the left side of the item
890 * @param end The icon object to use for the right side of the item
891 * @param func The function to call when the item is clicked
892 * @param data The data to associate with the item for related callbacks
893 * @param cmp_func The function called for the sort.
895 * @return The created item or NULL upon failure
900 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)
902 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
903 Widget_Data *wd = elm_widget_data_get(obj);
904 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
907 wd->items = eina_list_sorted_insert(wd->items, cmp_func, it);
908 l = eina_list_data_find_list(wd->items, it);
909 l = eina_list_next(l);
912 it->node = eina_list_last(wd->items);
913 elm_box_pack_end(wd->box, it->base);
917 Elm_List_Item *before = eina_list_data_get(l);
918 it->node = before->node->prev;
919 elm_box_pack_before(wd->box, it->base, before->base);
925 * Clears a list of all items.
927 * @param obj The list object
932 elm_list_clear(Evas_Object *obj)
934 ELM_CHECK_WIDTYPE(obj, widtype);
935 Widget_Data *wd = elm_widget_data_get(obj);
939 if (!wd->items) return;
941 eina_list_free(wd->selected);
948 EINA_LIST_FOREACH(wd->items, n, it)
950 if (it->deleted) continue;
951 it->deleted = EINA_TRUE;
952 wd->to_delete = eina_list_append(wd->to_delete, it);
959 EINA_LIST_FREE(wd->items, it)
961 _elm_list_item_call_del_cb(it);
962 _elm_list_item_free(it);
965 _elm_list_unwalk(wd);
972 * Starts the list. Call before running show() on the list object.
974 * @param obj The list object
979 elm_list_go(Evas_Object *obj)
981 ELM_CHECK_WIDTYPE(obj, widtype);
982 Widget_Data *wd = elm_widget_data_get(obj);
988 * Enables/disables the state of multi-select on the list object.
990 * @param obj The list object
991 * @param multi If true, multi-select is enabled
996 elm_list_multi_select_set(Evas_Object *obj, Eina_Bool multi)
998 ELM_CHECK_WIDTYPE(obj, widtype);
999 Widget_Data *wd = elm_widget_data_get(obj);
1005 * Gets the state of multi-select on the list object.
1007 * @param obj The list object
1008 * @return If true, multi-select is enabled
1013 elm_list_multi_select_get(const Evas_Object *obj)
1015 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1016 Widget_Data *wd = elm_widget_data_get(obj);
1017 if (!wd) return EINA_FALSE;
1022 * Enables/disables horizontal mode of the list
1024 * @param obj The list object
1025 * @param mode If true, horizontale mode is enabled
1030 elm_list_horizontal_mode_set(Evas_Object *obj, Elm_List_Mode mode)
1032 ELM_CHECK_WIDTYPE(obj, widtype);
1033 Widget_Data *wd = elm_widget_data_get(obj);
1035 if (wd->mode == mode) return;
1039 if (wd->mode == ELM_LIST_LIMIT)
1040 elm_scroller_content_min_limit(wd->scr, 1, 0);
1042 elm_scroller_content_min_limit(wd->scr, 0, 0);
1047 * Gets the state of horizontal mode of the list
1049 * @param obj The list object
1050 * @return If true, horizontale mode is enabled
1055 elm_list_horizontal_mode_get(const Evas_Object *obj)
1057 ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_SCROLL;
1058 Widget_Data *wd = elm_widget_data_get(obj);
1059 if (!wd) return ELM_LIST_SCROLL;
1064 * Enables/disables the state of always_select, meaning that
1065 * an item will always be selected.
1067 * @param obj The list object
1068 * @param always_select If true, always_select is enabled
1073 elm_list_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
1075 ELM_CHECK_WIDTYPE(obj, widtype);
1076 Widget_Data *wd = elm_widget_data_get(obj);
1078 wd->always_select = always_select;
1082 * Gets the state of always_select.
1083 * See also elm_list_always_select_mode_set()
1085 * @param obj The list object
1086 * @return If true, always_select is enabled
1091 elm_list_always_select_mode_get(const Evas_Object *obj)
1093 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1094 Widget_Data *wd = elm_widget_data_get(obj);
1095 if (!wd) return EINA_FALSE;
1096 return wd->always_select;
1100 * Returns a list of all the list items.
1102 * @param obj The list object
1103 * @return An Eina_List* of the list items, or NULL on failure
1107 EAPI const Eina_List *
1108 elm_list_items_get(const Evas_Object *obj)
1110 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1111 Widget_Data *wd = elm_widget_data_get(obj);
1112 if (!wd) return NULL;
1117 * Returns the currently selected list item.
1119 * @param obj The list object
1120 * @return The selected list item, or NULL on failure
1124 EAPI Elm_List_Item *
1125 elm_list_selected_item_get(const Evas_Object *obj)
1127 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1128 Widget_Data *wd = elm_widget_data_get(obj);
1129 if (!wd) return NULL;
1130 if (wd->selected) return wd->selected->data;
1135 * Returns a list of the currently selected list items.
1137 * @param obj The list object
1138 * @return An Eina_List* of the selected list items, or NULL on failure
1142 EAPI const Eina_List *
1143 elm_list_selected_items_get(const Evas_Object *obj)
1145 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1146 Widget_Data *wd = elm_widget_data_get(obj);
1147 if (!wd) return NULL;
1148 return wd->selected;
1152 * Sets if item is a separator.
1154 * @param it The list item object
1158 elm_list_item_separator_set(Elm_List_Item *it, Eina_Bool setting)
1160 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1161 it->is_separator = !!setting;
1165 * Returns EINA_TRUE if Elm_List_Item is a separator.
1167 * @param it The list item object
1170 elm_list_item_separator_get(const Elm_List_Item *it)
1172 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1173 return it->is_separator;
1178 * Sets the selected state of @p it.
1180 * @param it The list item
1181 * @param selected Enables/disables the selected state
1186 elm_list_item_selected_set(Elm_List_Item *it, Eina_Bool selected)
1188 Widget_Data *wd = elm_widget_data_get(it->obj);
1190 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1191 selected = !!selected;
1192 if (it->selected == selected) return;
1200 while (wd->selected)
1201 _item_unselect(wd->selected->data);
1209 _elm_list_unwalk(wd);
1213 * Gets the selected state of @p it.
1215 * @param it The list item
1216 * @return If true, the item is selected
1221 elm_list_item_selected_get(Elm_List_Item *it)
1223 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1224 return it->selected;
1228 * Brings @p it to the center of the list view.
1230 * @param it The list item
1235 elm_list_item_show(Elm_List_Item *it)
1237 Widget_Data *wd = elm_widget_data_get(it->obj);
1238 Evas_Coord bx, by, bw, bh;
1239 Evas_Coord x, y, w, h;
1241 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1242 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1243 evas_object_geometry_get(it->base, &x, &y, &w, &h);
1247 elm_scroller_region_show(wd->scr, x, y, w, h);
1251 * Deletes item @p it from the list.
1253 * @param it The list item to delete
1258 elm_list_item_del(Elm_List_Item *it)
1260 Widget_Data *wd = elm_widget_data_get(it->obj);
1262 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1264 if (it->selected) _item_unselect(it);
1266 if (wd->walking > 0)
1268 if (it->deleted) return;
1269 it->deleted = EINA_TRUE;
1270 wd->to_delete = eina_list_append(wd->to_delete, it);
1274 wd->items = eina_list_remove_list(wd->items, it->node);
1278 _elm_list_item_call_del_cb(it);
1279 _elm_list_item_free(it);
1281 _elm_list_unwalk(wd);
1285 * Set the function called when a list item is freed.
1287 * @param it The item to set the callback on
1288 * @param func The function called
1293 elm_list_item_del_cb_set(Elm_List_Item *it, Evas_Smart_Cb func)
1295 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1300 * Returns the data associated with the item.
1302 * @param it The list item
1303 * @return The data associated with @p it
1308 elm_list_item_data_get(const Elm_List_Item *it)
1310 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1311 return (void *)it->data;
1315 * Returns the left side icon associated with the item.
1317 * @param it The list item
1318 * @return The left side icon associated with @p it
1323 elm_list_item_icon_get(const Elm_List_Item *it)
1325 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1326 if (it->dummy_icon) return NULL;
1331 * Sets the left side icon associated with the item.
1333 * Once the icon object is set, a previously set one will be deleted.
1334 * You probably don't want, then, to have the <b>same</b> icon object set
1335 * for more than one item of the list.
1337 * @param it The list item
1338 * @param icon The left side icon object to associate with @p it
1343 elm_list_item_icon_set(Elm_List_Item *it, Evas_Object *icon)
1345 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1346 if (it->icon == icon) return;
1347 if (it->dummy_icon && !icon) return;
1350 evas_object_del(it->icon);
1351 it->dummy_icon = EINA_FALSE;
1355 icon = evas_object_rectangle_add(evas_object_evas_get(it->obj));
1356 evas_object_color_set(icon, 0, 0, 0, 0);
1357 it->dummy_icon = EINA_TRUE;
1361 evas_object_del(it->icon);
1366 edje_object_part_swallow(it->base, "elm.swallow.icon", icon);
1370 * Gets the right side icon associated with the item.
1372 * @param it The list item
1373 * @return The right side icon object associated with @p it
1378 elm_list_item_end_get(const Elm_List_Item *it)
1380 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1381 if (it->dummy_end) return NULL;
1386 * Sets the right side icon associated with the item.
1388 * Once the icon object is set, a previously set one will be deleted.
1389 * You probably don't want, then, to have the <b>same</b> icon object set
1390 * for more than one item of the list.
1392 * @param it The list item
1393 * @param icon The right side icon object to associate with @p it
1398 elm_list_item_end_set(Elm_List_Item *it, Evas_Object *end)
1400 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1401 if (it->end == end) return;
1402 if (it->dummy_end && !end) return;
1405 evas_object_del(it->end);
1406 it->dummy_icon = EINA_FALSE;
1410 end = evas_object_rectangle_add(evas_object_evas_get(it->obj));
1411 evas_object_color_set(end, 0, 0, 0, 0);
1412 it->dummy_end = EINA_TRUE;
1416 evas_object_del(it->end);
1421 edje_object_part_swallow(it->base, "elm.swallow.end", end);
1425 * Gets the base object of the item.
1427 * @param it The list item
1428 * @return The base object associated with @p it
1433 elm_list_item_base_get(const Elm_List_Item *it)
1435 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1440 * Gets the label of the item.
1442 * @param it The list item
1443 * @return The label of @p it
1448 elm_list_item_label_get(const Elm_List_Item *it)
1450 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1455 * Sets the label of the item.
1457 * @param it The list item
1458 * @param text The label of @p it
1463 elm_list_item_label_set(Elm_List_Item *it, const char *text)
1465 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1466 if (!eina_stringshare_replace(&it->label, text)) return;
1468 edje_object_part_text_set(it->base, "elm.text", it->label);
1472 * Gets the item before @p it in the list.
1474 * @param it The list item
1475 * @return The item before @p it, or NULL on failure
1479 EAPI Elm_List_Item *
1480 elm_list_item_prev(const Elm_List_Item *it)
1482 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1483 if (it->node->prev) return it->node->prev->data;
1488 * Gets the item after @p it in the list.
1490 * @param it The list item
1491 * @return The item after @p it, or NULL on failure
1495 EAPI Elm_List_Item *
1496 elm_list_item_next(const Elm_List_Item *it)
1498 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1499 if (it->node->next) return it->node->next->data;
1506 * This will enable or disable the scroller bounce mode for the list. See
1507 * elm_scroller_bounce_set() for details
1509 * @param obj The list object
1510 * @param h_bounce Allow bounce horizontally
1511 * @param v_bounce Allow bounce vertically
1516 elm_list_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1518 ELM_CHECK_WIDTYPE(obj, widtype);
1519 Widget_Data *wd = elm_widget_data_get(obj);
1522 elm_scroller_bounce_set(wd->scr, h_bounce, v_bounce);
1526 * Set the scrollbar policy
1528 * This sets the scrollbar visibility policy for the given scroller.
1529 * ELM_SMART_SCROLLER_POLICY_AUTO means the scrollber is made visible if it
1530 * is needed, and otherwise kept hidden. ELM_SMART_SCROLLER_POLICY_ON turns
1531 * it on all the time, and ELM_SMART_SCROLLER_POLICY_OFF always keeps it off.
1532 * This applies respectively for the horizontal and vertical scrollbars.
1534 * @param obj The list object
1535 * @param policy_h Horizontal scrollbar policy
1536 * @param policy_v Vertical scrollbar policy
1541 elm_list_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1543 ELM_CHECK_WIDTYPE(obj, widtype);
1544 Widget_Data *wd = elm_widget_data_get(obj);
1547 elm_scroller_policy_set(wd->scr, policy_h, policy_v);
1551 elm_list_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1553 ELM_CHECK_WIDTYPE(obj, widtype);
1554 Widget_Data *wd = elm_widget_data_get(obj);
1557 elm_scroller_policy_get(wd->scr, policy_h, policy_v);