1 #include <Elementary.h>
3 #include "els_scroller.h"
7 typedef struct _Widget_Data Widget_Data;
11 Evas_Object *scr, *box, *self;
12 Eina_List *items, *selected, *to_delete;
13 Elm_List_Item *last_selected_item;
16 Evas_Coord minw[2], minh[2];
17 Eina_Bool scr_minw : 1;
18 Eina_Bool scr_minh : 1;
23 } history[SWIPE_MOVES];
25 Eina_Bool fix_pending : 1;
26 Eina_Bool on_hold : 1;
28 Eina_Bool always_select : 1;
29 Eina_Bool longpressed : 1;
30 Eina_Bool wasselected : 1;
39 Evas_Object *icon, *end;
41 Ecore_Timer *long_timer;
42 Ecore_Timer *swipe_timer;
43 Eina_Bool deleted : 1;
45 Eina_Bool is_even : 1;
46 Eina_Bool is_separator : 1;
48 Eina_Bool selected : 1;
49 Eina_Bool highlighted : 1;
50 Eina_Bool dummy_icon : 1;
51 Eina_Bool dummy_end : 1;
54 static const char *widtype = NULL;
55 static void _del_hook(Evas_Object *obj);
56 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
57 static void _theme_hook(Evas_Object *obj);
58 static void _sizing_eval(Evas_Object *obj);
59 static void _disable_hook(Evas_Object *obj);
60 static void _on_focus_hook(void *data, Evas_Object *obj);
61 static void _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source);
62 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
63 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
64 static void _fix_items(Evas_Object *obj);
65 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
66 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
67 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
68 static void _edge_left(void *data, Evas_Object *scr, void *event_info);
69 static void _edge_right(void *data, Evas_Object *scr, void *event_info);
70 static void _edge_top(void *data, Evas_Object *scr, void *event_info);
71 static void _edge_bottom(void *data, Evas_Object *scr, void *event_info);
72 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
73 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
74 static Eina_Bool _item_single_select_up(Widget_Data *wd);
75 static Eina_Bool _item_single_select_down(Widget_Data *wd);
76 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
77 Evas_Callback_Type type, void *event_info);
78 static Eina_Bool _deselect_all_items(Widget_Data *wd);
80 static const char SIG_ACTIVATED[] = "activated";
81 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
82 static const char SIG_SELECTED[] = "selected";
83 static const char SIG_UNSELECTED[] = "unselected";
84 static const char SIG_LONGPRESSED[] = "longpressed";
85 static const char SIG_EDGE_TOP[] = "edge,top";
86 static const char SIG_EDGE_BOTTOM[] = "edge,bottom";
87 static const char SIG_EDGE_LEFT[] = "edge,left";
88 static const char SIG_EDGE_RIGHT[] = "edge,right";
90 static const Evas_Smart_Cb_Description _signals[] = {
92 {SIG_CLICKED_DOUBLE, ""},
95 {SIG_LONGPRESSED, ""},
97 {SIG_EDGE_BOTTOM, ""},
103 #define ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ...) \
104 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, __VA_ARGS__); \
107 ERR("ERROR: "#it" has been DELETED.\n"); \
108 return __VA_ARGS__; \
112 _elm_list_item_free(Elm_List_Item *it)
114 evas_object_event_callback_del_full
115 (VIEW(it), EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, it);
116 evas_object_event_callback_del_full
117 (VIEW(it), EVAS_CALLBACK_MOUSE_UP, _mouse_up, it);
118 evas_object_event_callback_del_full
119 (VIEW(it), EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, it);
122 evas_object_event_callback_del_full
123 (it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
124 _changed_size_hints, WIDGET(it));
127 evas_object_event_callback_del_full
128 (it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
129 _changed_size_hints, WIDGET(it));
131 eina_stringshare_del(it->label);
133 if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
134 if (it->long_timer) ecore_timer_del(it->long_timer);
135 if (it->icon) evas_object_del(it->icon);
136 if (it->end) evas_object_del(it->end);
138 elm_widget_item_del(it);
142 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
144 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
145 Evas_Event_Key_Down *ev = event_info;
146 Widget_Data *wd = elm_widget_data_get(obj);
147 if (!wd) return EINA_FALSE;
148 if (!wd->items) return EINA_FALSE;
149 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
150 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
152 Elm_List_Item *it = NULL;
155 Evas_Coord step_x = 0;
156 Evas_Coord step_y = 0;
159 Evas_Coord page_x = 0;
160 Evas_Coord page_y = 0;
162 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
163 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
164 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
165 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
167 /* TODO: fix logic for horizontal mode */
168 if ((!strcmp(ev->keyname, "Left")) ||
169 (!strcmp(ev->keyname, "KP_Left")))
172 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
173 (_item_multi_select_up(wd)))
174 || (_item_single_select_up(wd))))
176 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
182 else if ((!strcmp(ev->keyname, "Right")) ||
183 (!strcmp(ev->keyname, "KP_Right")))
186 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
187 (_item_multi_select_down(wd)))
188 || (_item_single_select_down(wd))))
190 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
196 else if ((!strcmp(ev->keyname, "Up")) ||
197 (!strcmp(ev->keyname, "KP_Up")))
200 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
201 (_item_multi_select_up(wd)))
202 || (_item_single_select_up(wd))))
204 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
210 else if ((!strcmp(ev->keyname, "Down")) ||
211 (!strcmp(ev->keyname, "KP_Down")))
214 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
215 (_item_multi_select_down(wd)))
216 || (_item_single_select_down(wd))))
218 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
224 else if ((!strcmp(ev->keyname, "Home")) ||
225 (!strcmp(ev->keyname, "KP_Home")))
227 it = eina_list_data_get(wd->items);
228 elm_list_item_bring_in(it);
229 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
232 else if ((!strcmp(ev->keyname, "End")) ||
233 (!strcmp(ev->keyname, "KP_End")))
235 it = eina_list_data_get(eina_list_last(wd->items));
236 elm_list_item_bring_in(it);
237 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
240 else if ((!strcmp(ev->keyname, "Prior")) ||
241 (!strcmp(ev->keyname, "KP_Prior")))
246 x -= -(page_x * v_w) / 100;
253 y -= -(page_y * v_h) / 100;
258 else if ((!strcmp(ev->keyname, "Next")) ||
259 (!strcmp(ev->keyname, "KP_Next")))
264 x += -(page_x * v_w) / 100;
271 y += -(page_y * v_h) / 100;
276 else if (((!strcmp(ev->keyname, "Return")) ||
277 (!strcmp(ev->keyname, "KP_Enter")) ||
278 (!strcmp(ev->keyname, "space")))
279 && (!wd->multi) && (wd->selected))
281 it = elm_list_selected_item_get(obj);
282 evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it);
284 else if (!strcmp(ev->keyname, "Escape"))
286 if (!_deselect_all_items(wd)) return EINA_FALSE;
287 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
290 else return EINA_FALSE;
292 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
293 elm_smart_scroller_child_pos_set(wd->scr, x, y);
298 _translate_hook(Evas_Object *obj)
300 evas_object_smart_callback_call(obj, "language,changed", NULL);
304 _deselect_all_items(Widget_Data *wd)
306 if (!wd->selected) return EINA_FALSE;
308 elm_list_item_selected_set(wd->selected->data, EINA_FALSE);
314 _item_multi_select_up(Widget_Data *wd)
316 if (!wd->selected) return EINA_FALSE;
317 if (!wd->multi) return EINA_FALSE;
319 Elm_List_Item *prev = elm_list_item_prev(wd->last_selected_item);
320 if (!prev) return EINA_TRUE;
322 if (elm_list_item_selected_get(prev))
324 elm_list_item_selected_set(wd->last_selected_item, EINA_FALSE);
325 wd->last_selected_item = prev;
326 elm_list_item_show(wd->last_selected_item);
330 elm_list_item_selected_set(prev, EINA_TRUE);
331 elm_list_item_show(prev);
337 _item_multi_select_down(Widget_Data *wd)
339 if (!wd->selected) return EINA_FALSE;
340 if (!wd->multi) return EINA_FALSE;
342 Elm_List_Item *next = elm_list_item_next(wd->last_selected_item);
343 if (!next) return EINA_TRUE;
345 if (elm_list_item_selected_get(next))
347 elm_list_item_selected_set(wd->last_selected_item, EINA_FALSE);
348 wd->last_selected_item = next;
349 elm_list_item_show(wd->last_selected_item);
353 elm_list_item_selected_set(next, EINA_TRUE);
354 elm_list_item_show(next);
360 _item_single_select_up(Widget_Data *wd)
364 if (!wd->selected) prev = eina_list_data_get(eina_list_last(wd->items));
365 else prev = elm_list_item_prev(wd->last_selected_item);
367 if (!prev) return EINA_FALSE;
369 _deselect_all_items(wd);
371 elm_list_item_selected_set(prev, EINA_TRUE);
372 elm_list_item_show(prev);
377 _item_single_select_down(Widget_Data *wd)
381 if (!wd->selected) next = eina_list_data_get(wd->items);
382 else next = elm_list_item_next(wd->last_selected_item);
384 if (!next) return EINA_FALSE;
386 _deselect_all_items(wd);
388 elm_list_item_selected_set(next, EINA_TRUE);
389 elm_list_item_show(next);
394 _elm_list_process_deletions(Widget_Data *wd)
398 wd->walking++; // avoid nested deletion and also _sub_del() fix_items
400 EINA_LIST_FREE(wd->to_delete, it)
402 elm_widget_item_pre_notify_del(it);
404 wd->items = eina_list_remove_list(wd->items, it->node);
405 _elm_list_item_free(it);
412 _elm_list_walk(Widget_Data *wd)
416 ERR("ERROR: walking was negative. fixed!\n");
423 _elm_list_unwalk(Widget_Data *wd)
428 ERR("ERROR: walking became negative. fixed!\n");
436 _elm_list_process_deletions(wd);
440 wd->fix_pending = EINA_FALSE;
441 _fix_items(wd->self);
442 _sizing_eval(wd->self);
447 _del_pre_hook(Evas_Object *obj)
449 Widget_Data *wd = elm_widget_data_get(obj);
452 evas_object_event_callback_del(wd->scr,
453 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
454 _changed_size_hints);
455 evas_object_event_callback_del(wd->box,
456 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
457 _changed_size_hints);
461 _del_hook(Evas_Object *obj)
463 Widget_Data *wd = elm_widget_data_get(obj);
469 ERR("ERROR: list deleted while walking.\n");
472 EINA_LIST_FOREACH(wd->items, n, it) elm_widget_item_pre_notify_del(it);
473 _elm_list_unwalk(wd);
475 ERR("ERROR: leaking nodes!\n");
477 EINA_LIST_FREE(wd->items, it) _elm_list_item_free(it);
478 eina_list_free(wd->selected);
483 _show_region_hook(void *data, Evas_Object *obj)
485 Widget_Data *wd = elm_widget_data_get(data);
486 Evas_Coord x, y, w, h;
488 elm_widget_show_region_get(obj, &x, &y, &w, &h);
489 elm_smart_scroller_child_region_set(wd->scr, x, y, w, h);
493 _disable_hook(Evas_Object *obj)
495 Widget_Data *wd = elm_widget_data_get(obj);
497 if (elm_widget_disabled_get(obj))
499 _signal_emit_hook(obj, "elm,state,disabled", "elm");
500 elm_widget_scroll_freeze_push(obj);
501 elm_widget_scroll_hold_push(obj);
502 /* FIXME: if we get to have a way to only un-highlight items
503 * in the future, keeping them selected... */
504 _deselect_all_items(wd);
508 _signal_emit_hook(obj, "elm,state,enabled", "elm");
509 elm_widget_scroll_freeze_pop(obj);
510 elm_widget_scroll_hold_pop(obj);
515 _sizing_eval(Evas_Object *obj)
518 Widget_Data *wd = elm_widget_data_get(obj);
520 Evas_Coord vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
523 evas_object_size_hint_min_get(wd->box, &minw, &minh);
524 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
525 evas_object_size_hint_weight_get(wd->box, &xw, &yw);
526 if (!wd->scr) return;
527 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
530 if ((minw > 0) && (vw < minw)) vw = minw;
531 else if ((maxw > 0) && (vw > maxw)) vw = maxw;
533 else if (minw > 0) vw = minw;
536 if ((minh > 0) && (vh < minh)) vh = minh;
537 else if ((maxh > 0) && (vh > maxh)) vh = maxh;
539 else if (minh > 0) vh = minh;
540 evas_object_resize(wd->box, vw, vh);
543 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
545 if (wd->scr_minw) w = vmw + minw;
546 if (wd->scr_minh) h = vmh + minh;
548 evas_object_size_hint_max_get(obj, &maxw, &maxh);
549 if ((maxw > 0) && (w > maxw))
551 if ((maxh > 0) && (h > maxh))
554 evas_object_size_hint_min_set(obj, w, h);
558 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
560 Widget_Data *wd = elm_widget_data_get(obj);
561 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
566 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
568 Widget_Data *wd = elm_widget_data_get(obj);
569 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
570 emission, source, func_cb, data);
574 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
576 Widget_Data *wd = elm_widget_data_get(obj);
577 edje_object_signal_callback_del_full(
578 elm_smart_scroller_edje_object_get(wd->scr),
579 emission, source, func_cb, data);
583 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
585 Widget_Data *wd = elm_widget_data_get(obj);
591 elm_smart_scroller_mirrored_set(wd->scr, rtl);
593 EINA_LIST_FOREACH(wd->items, n, it)
594 edje_object_mirrored_set(VIEW(it), rtl);
598 _theme_hook(Evas_Object *obj)
600 Widget_Data *wd = elm_widget_data_get(obj);
605 _elm_widget_mirrored_reload(obj);
606 _mirrored_set(obj, elm_widget_mirrored_get(obj));
613 elm_smart_scroller_object_theme_set(obj, wd->scr, "list", "base",
614 elm_widget_style_get(obj));
615 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
616 edj = elm_smart_scroller_edje_object_get(wd->scr);
617 str = edje_object_data_get(edj, "focus_highlight");
618 if ((str) && (!strcmp(str, "on")))
619 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
621 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
622 elm_object_style_set(wd->scr, elm_widget_style_get(obj));
624 EINA_LIST_FOREACH(wd->items, n, it)
626 edje_object_scale_set(VIEW(it), elm_widget_scale_get(obj) * _elm_config->scale);
634 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
636 Widget_Data *wd = elm_widget_data_get(obj);
638 if (elm_widget_focus_get(obj))
640 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
641 evas_object_focus_set(wd->self, EINA_TRUE);
643 if ((wd->selected) && (!wd->last_selected_item))
644 wd->last_selected_item = eina_list_data_get(wd->selected);
648 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
649 evas_object_focus_set(wd->self, EINA_FALSE);
654 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
656 Widget_Data *wd = elm_widget_data_get(data);
663 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
665 Widget_Data *wd = elm_widget_data_get(obj);
666 Evas_Object *sub = event_info;
672 if ((sub == wd->box) || (sub == wd->scr)) return;
674 EINA_LIST_FOREACH(wd->items, l, it)
676 if ((sub == it->icon) || (sub == it->end))
678 if (it->icon == sub) it->icon = NULL;
679 if (it->end == sub) it->end = NULL;
680 evas_object_event_callback_del_full
681 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints,
689 wd->fix_pending = EINA_TRUE;
696 _item_highlight(Elm_List_Item *it)
698 Evas_Object *obj = WIDGET(it);
699 Widget_Data *wd = elm_widget_data_get(obj);
700 const char *selectraise;
703 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
704 if ((it->highlighted) || (it->base.disabled)) return;
706 evas_object_ref(obj);
709 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
710 selectraise = edje_object_data_get(VIEW(it), "selectraise");
711 if ((selectraise) && (!strcmp(selectraise, "on")))
712 evas_object_raise(VIEW(it));
713 it->highlighted = EINA_TRUE;
715 _elm_list_unwalk(wd);
716 evas_object_unref(obj);
720 _item_select(Elm_List_Item *it)
722 Evas_Object *obj = WIDGET(it);
723 Widget_Data *wd = elm_widget_data_get(obj);
726 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
727 if (it->base.disabled) return;
730 if (wd->always_select) goto call;
733 it->selected = EINA_TRUE;
734 wd->selected = eina_list_append(wd->selected, it);
737 evas_object_ref(obj);
740 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
741 evas_object_smart_callback_call(obj, SIG_SELECTED, it);
742 it->wd->last_selected_item = it;
744 _elm_list_unwalk(wd);
745 evas_object_unref(obj);
749 _item_unselect(Elm_List_Item *it)
751 Evas_Object *obj = WIDGET(it);
752 Widget_Data *wd = elm_widget_data_get(obj);
753 const char *stacking, *selectraise;
756 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
757 if (!it->highlighted) return;
759 evas_object_ref(obj);
762 edje_object_signal_emit(VIEW(it), "elm,state,unselected", "elm");
763 stacking = edje_object_data_get(VIEW(it), "stacking");
764 selectraise = edje_object_data_get(VIEW(it), "selectraise");
765 if ((selectraise) && (!strcmp(selectraise, "on")))
767 if ((stacking) && (!strcmp(stacking, "below")))
768 evas_object_lower(VIEW(it));
770 it->highlighted = EINA_FALSE;
773 it->selected = EINA_FALSE;
774 wd->selected = eina_list_remove(wd->selected, it);
775 evas_object_smart_callback_call(WIDGET(it), SIG_UNSELECTED, it);
778 _elm_list_unwalk(wd);
779 evas_object_unref(obj);
783 _swipe_cancel(void *data)
785 Elm_List_Item *it = data;
786 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
788 if (!wd) return ECORE_CALLBACK_CANCEL;
789 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
790 wd->swipe = EINA_FALSE;
792 return ECORE_CALLBACK_RENEW;
796 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
798 Elm_List_Item *it = data;
799 Evas_Object *obj2 = WIDGET(it);
800 Widget_Data *wd = elm_widget_data_get(obj2);
801 Evas_Event_Mouse_Move *ev = event_info;
804 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
806 evas_object_ref(obj2);
809 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
813 wd->on_hold = EINA_TRUE;
816 ecore_timer_del(it->long_timer);
817 it->long_timer = NULL;
819 if (!wd->wasselected)
822 if (wd->movements == SWIPE_MOVES) wd->swipe = EINA_TRUE;
825 wd->history[wd->movements].x = ev->cur.canvas.x;
826 wd->history[wd->movements].y = ev->cur.canvas.y;
827 if (abs((wd->history[wd->movements].x - wd->history[0].x)) > 40)
828 wd->swipe = EINA_TRUE;
834 _elm_list_unwalk(wd);
835 evas_object_unref(obj2);
839 _edge_left(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
841 Evas_Object *obj = data;
842 evas_object_smart_callback_call(obj, SIG_EDGE_LEFT, NULL);
846 _edge_right(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
848 Evas_Object *obj = data;
849 evas_object_smart_callback_call(obj, SIG_EDGE_RIGHT, NULL);
853 _edge_top(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
855 Evas_Object *obj = data;
856 evas_object_smart_callback_call(obj, SIG_EDGE_TOP, NULL);
860 _edge_bottom(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
862 Evas_Object *obj = data;
863 evas_object_smart_callback_call(obj, SIG_EDGE_BOTTOM, NULL);
867 _long_press(void *data)
869 Elm_List_Item *it = data;
870 Evas_Object *obj = WIDGET(it);
871 Widget_Data *wd = elm_widget_data_get(obj);
875 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
876 it->long_timer = NULL;
877 if (it->base.disabled) goto end;
879 wd->longpressed = EINA_TRUE;
880 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
883 return ECORE_CALLBACK_CANCEL;
887 _swipe(Elm_List_Item *it)
890 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
892 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
894 wd->swipe = EINA_FALSE;
895 for (i = 0; i < wd->movements; i++)
897 sum += wd->history[i].x;
898 if (abs(wd->history[0].y - wd->history[i].y) > 10) return;
901 sum /= wd->movements;
902 if (abs(sum - wd->history[0].x) <= 10) return;
903 evas_object_smart_callback_call(WIDGET(it), "swipe", it);
907 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
909 Elm_List_Item *it = data;
910 Evas_Object *obj2 = WIDGET(it);
911 Widget_Data *wd = elm_widget_data_get(obj2);
912 Evas_Event_Mouse_Down *ev = event_info;
915 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
916 if (ev->button != 1) return;
917 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
918 else wd->on_hold = EINA_FALSE;
919 if (wd->on_hold) return;
920 wd->wasselected = it->selected;
922 evas_object_ref(obj2);
926 wd->longpressed = EINA_FALSE;
927 if (it->long_timer) ecore_timer_del(it->long_timer);
928 it->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, it);
929 if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
930 it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
931 /* Always call the callbacks last - the user may delete our context! */
932 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
934 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
935 evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it);
937 wd->swipe = EINA_FALSE;
940 _elm_list_unwalk(wd);
941 evas_object_unref(obj2);
945 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
947 Elm_List_Item *it = data;
948 Evas_Object *obj2 = WIDGET(it);
949 Widget_Data *wd = elm_widget_data_get(obj2);
950 Evas_Event_Mouse_Up *ev = event_info;
953 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
954 if (ev->button != 1) return;
955 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
956 else wd->on_hold = EINA_FALSE;
957 wd->longpressed = EINA_FALSE;
960 ecore_timer_del(it->long_timer);
961 it->long_timer = NULL;
965 ecore_timer_del(it->swipe_timer);
966 it->swipe_timer = NULL;
970 if (wd->swipe) _swipe(data);
971 wd->on_hold = EINA_FALSE;
976 if (!wd->wasselected) _item_unselect(it);
981 if (it->base.disabled)
983 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
985 evas_object_ref(obj2);
995 else _item_unselect(it);
1001 while (wd->selected)
1002 _item_unselect(wd->selected->data);
1003 _item_highlight(it);
1008 const Eina_List *l, *l_next;
1011 EINA_LIST_FOREACH_SAFE(wd->selected, l, l_next, it2)
1012 if (it2 != it) _item_unselect(it2);
1013 _item_highlight(it);
1018 _elm_list_unwalk(wd);
1019 evas_object_unref(obj2);
1023 _item_disable(void *data)
1025 Elm_List_Item *it = data;
1026 if (it->base.disabled)
1027 edje_object_signal_emit(VIEW(it), "elm,state,disabled", "elm");
1029 edje_object_signal_emit(VIEW(it), "elm,state,enabled", "elm");
1032 static Elm_List_Item *
1033 _item_new(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1035 Widget_Data *wd = elm_widget_data_get(obj);
1038 if (!wd) return NULL;
1039 it = elm_widget_item_new(obj, Elm_List_Item);
1041 it->label = eina_stringshare_add(label);
1045 it->base.data = data;
1046 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
1047 edje_object_mirrored_set(VIEW(it), elm_widget_mirrored_get(obj));
1048 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
1050 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
1052 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1054 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1055 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
1058 elm_widget_sub_object_add(obj, it->icon);
1059 evas_object_event_callback_add(it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1060 _changed_size_hints, obj);
1064 elm_widget_sub_object_add(obj, it->end);
1065 evas_object_event_callback_add(it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1066 _changed_size_hints, obj);
1068 _elm_widget_item_disable_set_hook_set((Elm_Widget_Item *)it, _item_disable);
1073 _elm_list_mode_set_internal(Widget_Data *wd)
1078 if (wd->mode == ELM_LIST_LIMIT)
1082 wd->scr_minw = EINA_TRUE;
1083 wd->scr_minh = EINA_FALSE;
1087 wd->scr_minw = EINA_FALSE;
1088 wd->scr_minh = EINA_TRUE;
1091 else if (wd->mode == ELM_LIST_EXPAND)
1093 wd->scr_minw = EINA_TRUE;
1094 wd->scr_minh = EINA_TRUE;
1098 wd->scr_minw = EINA_FALSE;
1099 wd->scr_minh = EINA_FALSE;
1102 _sizing_eval(wd->self);
1106 _fix_items(Evas_Object *obj)
1108 Widget_Data *wd = elm_widget_data_get(obj);
1112 Evas_Coord minw[2] = { 0, 0 }, minh[2] = { 0, 0 };
1115 const char *style = elm_widget_style_get(obj);
1116 const char *it_plain = wd->h_mode ? "h_item" : "item";
1117 const char *it_odd = wd->h_mode ? "h_item_odd" : "item_odd";
1118 const char *it_compress = wd->h_mode ? "h_item_compress" : "item_compress";
1119 const char *it_compress_odd = wd->h_mode ? "h_item_compress_odd" : "item_compress_odd";
1123 wd->fix_pending = EINA_TRUE;
1127 evas_object_ref(obj);
1128 _elm_list_walk(wd); // watch out "return" before unwalk!
1130 EINA_LIST_FOREACH(wd->items, l, it)
1132 if (it->deleted) continue;
1135 evas_object_size_hint_min_get(it->icon, &mw, &mh);
1136 if (mw > minw[0]) minw[0] = mw;
1137 if (mh > minh[0]) minh[0] = mh;
1141 evas_object_size_hint_min_get(it->end, &mw, &mh);
1142 if (mw > minw[1]) minw[1] = mw;
1143 if (mh > minh[1]) minh[1] = mh;
1147 if ((minw[0] != wd->minw[0]) || (minw[1] != wd->minw[1]) ||
1148 (minw[0] != wd->minh[0]) || (minh[1] != wd->minh[1]))
1150 wd->minw[0] = minw[0];
1151 wd->minw[1] = minw[1];
1152 wd->minh[0] = minh[0];
1153 wd->minh[1] = minh[1];
1157 EINA_LIST_FOREACH(wd->items, l, it)
1163 if ((it->even != it->is_even) || (!it->fixed) || (redo))
1165 const char *stacking;
1167 /* FIXME: separators' themes seem to be b0rked */
1168 if (it->is_separator)
1169 _elm_theme_object_set(obj, VIEW(it), "separator",
1170 wd->h_mode ? "horizontal" : "vertical",
1172 else if (wd->mode == ELM_LIST_COMPRESS)
1175 _elm_theme_object_set(obj, VIEW(it), "list",
1176 it_compress, style);
1178 _elm_theme_object_set(obj, VIEW(it), "list",
1179 it_compress_odd, style);
1184 _elm_theme_object_set(obj, VIEW(it), "list", it_plain,
1187 _elm_theme_object_set(obj, VIEW(it), "list", it_odd,
1190 stacking = edje_object_data_get(VIEW(it), "stacking");
1193 if (!strcmp(stacking, "below"))
1194 evas_object_lower(VIEW(it));
1195 else if (!strcmp(stacking, "above"))
1196 evas_object_raise(VIEW(it));
1198 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1200 if ((!it->icon) && (minh[0] > 0))
1202 it->icon = evas_object_rectangle_add(evas_object_evas_get(VIEW(it)));
1203 evas_object_color_set(it->icon, 0, 0, 0, 0);
1204 it->dummy_icon = EINA_TRUE;
1206 if ((!it->end) && (minh[1] > 0))
1208 it->end = evas_object_rectangle_add(evas_object_evas_get(VIEW(it)));
1209 evas_object_color_set(it->end, 0, 0, 0, 0);
1210 it->dummy_end = EINA_TRUE;
1214 evas_object_size_hint_min_set(it->icon, minw[0], minh[0]);
1215 evas_object_size_hint_max_set(it->icon, 99999, 99999);
1216 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
1220 evas_object_size_hint_min_set(it->end, minw[1], minh[1]);
1221 evas_object_size_hint_max_set(it->end, 99999, 99999);
1222 edje_object_part_swallow(VIEW(it), "elm.swallow.end", it->end);
1226 // this may call up user and it may modify the list item
1227 // but we're safe as we're flagged as walking.
1228 // just don't process further
1229 edje_object_message_signal_process(VIEW(it));
1233 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1234 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
1235 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1236 evas_object_size_hint_min_set(VIEW(it), mw, mh);
1237 evas_object_show(VIEW(it));
1239 if ((it->selected) || (it->highlighted))
1241 const char *selectraise;
1243 // this may call up user and it may modify the list item
1244 // but we're safe as we're flagged as walking.
1245 // just don't process further
1246 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
1250 selectraise = edje_object_data_get(VIEW(it), "selectraise");
1251 if ((selectraise) && (!strcmp(selectraise, "on")))
1252 evas_object_raise(VIEW(it));
1254 if (it->base.disabled)
1255 edje_object_signal_emit(VIEW(it), "elm,state,disabled",
1258 it->fixed = EINA_TRUE;
1259 it->is_even = it->even;
1265 evas_object_size_hint_min_get(wd->box, &mw, &mh);
1267 _elm_list_mode_set_internal(wd);
1269 _elm_list_unwalk(wd);
1270 evas_object_unref(obj);
1274 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1276 Widget_Data *wd = elm_widget_data_get(obj);
1279 elm_smart_scroller_hold_set(wd->scr, EINA_TRUE);
1283 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1285 Widget_Data *wd = elm_widget_data_get(obj);
1288 elm_smart_scroller_hold_set(wd->scr, EINA_FALSE);
1292 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1294 Widget_Data *wd = elm_widget_data_get(obj);
1297 elm_smart_scroller_freeze_set(wd->scr, EINA_TRUE);
1301 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1303 Widget_Data *wd = elm_widget_data_get(obj);
1306 elm_smart_scroller_freeze_set(wd->scr, EINA_FALSE);
1310 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1316 elm_list_add(Evas_Object *parent)
1321 Evas_Coord minw, minh;
1323 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1325 ELM_SET_WIDTYPE(widtype, "list");
1326 elm_widget_type_set(obj, "list");
1327 elm_widget_sub_object_add(parent, obj);
1328 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1329 elm_widget_data_set(obj, wd);
1330 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1331 elm_widget_del_hook_set(obj, _del_hook);
1332 elm_widget_theme_hook_set(obj, _theme_hook);
1333 elm_widget_disable_hook_set(obj, _disable_hook);
1334 elm_widget_can_focus_set(obj, EINA_TRUE);
1335 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1336 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1337 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1338 elm_widget_event_hook_set(obj, _event_hook);
1339 elm_widget_translate_hook_set(obj, _translate_hook);
1342 wd->scr = elm_smart_scroller_add(e);
1343 elm_smart_scroller_widget_set(wd->scr, obj);
1344 elm_widget_resize_object_set(obj, wd->scr);
1345 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1346 _changed_size_hints, obj);
1347 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
1348 evas_object_size_hint_min_set(obj, minw, minh);
1349 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
1351 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
1352 _elm_config->thumbscroll_bounce_enable);
1354 wd->box = elm_box_add(parent);
1355 elm_box_homogeneous_set(wd->box, 1);
1356 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1357 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1358 elm_widget_on_show_region_hook_set(wd->box, _show_region_hook, obj);
1359 elm_widget_sub_object_add(obj, wd->box);
1360 elm_smart_scroller_child_set(wd->scr, wd->box);
1361 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1362 _changed_size_hints, obj);
1364 evas_object_show(wd->box);
1368 wd->mode = ELM_LIST_SCROLL;
1370 evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
1371 evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
1372 evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
1373 evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom, obj);
1375 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1376 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1377 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1378 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1379 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1381 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1383 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1389 elm_list_go(Evas_Object *obj)
1391 ELM_CHECK_WIDTYPE(obj, widtype);
1392 Widget_Data *wd = elm_widget_data_get(obj);
1398 elm_list_multi_select_set(Evas_Object *obj, Eina_Bool multi)
1400 ELM_CHECK_WIDTYPE(obj, widtype);
1401 Widget_Data *wd = elm_widget_data_get(obj);
1407 elm_list_multi_select_get(const Evas_Object *obj)
1409 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1410 Widget_Data *wd = elm_widget_data_get(obj);
1411 if (!wd) return EINA_FALSE;
1416 elm_list_mode_set(Evas_Object *obj, Elm_List_Mode mode)
1418 ELM_CHECK_WIDTYPE(obj, widtype);
1422 wd = elm_widget_data_get(obj);
1425 if (wd->mode == mode)
1429 _elm_list_mode_set_internal(wd);
1433 elm_list_mode_get(const Evas_Object *obj)
1435 ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
1436 Widget_Data *wd = elm_widget_data_get(obj);
1437 if (!wd) return ELM_LIST_LAST;
1442 elm_list_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1444 ELM_CHECK_WIDTYPE(obj, widtype);
1447 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1449 wd = elm_widget_data_get(obj);
1453 if (wd->h_mode == horizontal)
1456 wd->h_mode = horizontal;
1457 elm_box_horizontal_set(wd->box, horizontal);
1461 evas_object_size_hint_weight_set(wd->box, 0.0, EVAS_HINT_EXPAND);
1462 evas_object_size_hint_align_set(wd->box, 0.0, EVAS_HINT_FILL);
1463 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1467 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1468 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1469 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE, bounce);
1472 _elm_list_mode_set_internal(wd);
1476 elm_list_horizontal_get(const Evas_Object *obj)
1478 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1482 wd = elm_widget_data_get(obj);
1490 elm_list_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
1492 ELM_CHECK_WIDTYPE(obj, widtype);
1493 Widget_Data *wd = elm_widget_data_get(obj);
1495 wd->always_select = always_select;
1499 elm_list_always_select_mode_get(const Evas_Object *obj)
1501 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1502 Widget_Data *wd = elm_widget_data_get(obj);
1503 if (!wd) return EINA_FALSE;
1504 return wd->always_select;
1508 elm_list_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1510 ELM_CHECK_WIDTYPE(obj, widtype);
1511 Widget_Data *wd = elm_widget_data_get(obj);
1514 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1518 elm_list_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1520 ELM_CHECK_WIDTYPE(obj, widtype);
1521 Widget_Data *wd = elm_widget_data_get(obj);
1523 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
1527 elm_list_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1529 ELM_CHECK_WIDTYPE(obj, widtype);
1530 Widget_Data *wd = elm_widget_data_get(obj);
1531 if ((!wd) || (!wd->scr)) return;
1532 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1533 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1535 elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
1539 elm_list_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1541 ELM_CHECK_WIDTYPE(obj, widtype);
1542 Widget_Data *wd = elm_widget_data_get(obj);
1543 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1544 if ((!wd) || (!wd->scr)) return;
1545 elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
1546 if (policy_h) *policy_h = (Elm_Scroller_Policy) s_policy_h;
1547 if (policy_v) *policy_v = (Elm_Scroller_Policy) s_policy_v;
1551 elm_list_clear(Evas_Object *obj)
1553 ELM_CHECK_WIDTYPE(obj, widtype);
1554 Widget_Data *wd = elm_widget_data_get(obj);
1558 if (!wd->items) return;
1560 eina_list_free(wd->selected);
1561 wd->selected = NULL;
1563 if (wd->walking > 0)
1567 EINA_LIST_FOREACH(wd->items, n, it)
1569 if (it->deleted) continue;
1570 it->deleted = EINA_TRUE;
1571 wd->to_delete = eina_list_append(wd->to_delete, it);
1576 evas_object_ref(obj);
1579 EINA_LIST_FREE(wd->items, it)
1581 elm_widget_item_pre_notify_del(it);
1582 _elm_list_item_free(it);
1585 _elm_list_unwalk(wd);
1589 evas_object_unref(obj);
1592 EAPI const Eina_List *
1593 elm_list_items_get(const Evas_Object *obj)
1595 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1596 Widget_Data *wd = elm_widget_data_get(obj);
1597 if (!wd) return NULL;
1601 EAPI Elm_List_Item *
1602 elm_list_selected_item_get(const Evas_Object *obj)
1604 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1605 Widget_Data *wd = elm_widget_data_get(obj);
1606 if (!wd) return NULL;
1607 if (wd->selected) return wd->selected->data;
1611 EAPI const Eina_List *
1612 elm_list_selected_items_get(const Evas_Object *obj)
1614 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1615 Widget_Data *wd = elm_widget_data_get(obj);
1616 if (!wd) return NULL;
1617 return wd->selected;
1620 EAPI Elm_List_Item *
1621 elm_list_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1623 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1624 Widget_Data *wd = elm_widget_data_get(obj);
1625 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1627 wd->items = eina_list_append(wd->items, it);
1628 it->node = eina_list_last(wd->items);
1629 elm_box_pack_end(wd->box, VIEW(it));
1633 EAPI Elm_List_Item *
1634 elm_list_item_prepend(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1636 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1637 Widget_Data *wd = elm_widget_data_get(obj);
1638 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1640 wd->items = eina_list_prepend(wd->items, it);
1641 it->node = wd->items;
1642 elm_box_pack_start(wd->box, VIEW(it));
1646 EAPI Elm_List_Item *
1647 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)
1652 EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
1653 if (!before->node) return NULL;
1654 ELM_LIST_ITEM_CHECK_DELETED_RETURN(before, NULL);
1656 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1657 wd = elm_widget_data_get(obj);
1658 if (!wd) return NULL;
1659 it = _item_new(obj, label, icon, end, func, data);
1660 wd->items = eina_list_prepend_relative_list(wd->items, it, before->node);
1661 it->node = before->node->prev;
1662 elm_box_pack_before(wd->box, VIEW(it), VIEW(before));
1666 EAPI Elm_List_Item *
1667 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)
1672 EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
1673 if (!after->node) return NULL;
1674 ELM_LIST_ITEM_CHECK_DELETED_RETURN(after, NULL);
1676 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1677 wd = elm_widget_data_get(obj);
1678 if (!wd) return NULL;
1679 it = _item_new(obj, label, icon, end, func, data);
1680 wd->items = eina_list_append_relative_list(wd->items, it, after->node);
1681 it->node = after->node->next;
1682 elm_box_pack_after(wd->box, VIEW(it), VIEW(after));
1686 EAPI Elm_List_Item *
1687 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)
1689 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1690 Widget_Data *wd = elm_widget_data_get(obj);
1691 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1694 wd->items = eina_list_sorted_insert(wd->items, cmp_func, it);
1695 l = eina_list_data_find_list(wd->items, it);
1696 l = eina_list_next(l);
1699 it->node = eina_list_last(wd->items);
1700 elm_box_pack_end(wd->box, VIEW(it));
1704 Elm_List_Item *before = eina_list_data_get(l);
1705 it->node = before->node->prev;
1706 elm_box_pack_before(wd->box, VIEW(it), VIEW(before));
1712 elm_list_item_separator_set(Elm_List_Item *it, Eina_Bool setting)
1714 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1715 it->is_separator = !!setting;
1719 elm_list_item_separator_get(const Elm_List_Item *it)
1721 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1722 return it->is_separator;
1726 elm_list_item_selected_set(Elm_List_Item *it, Eina_Bool selected)
1728 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1729 Evas_Object *obj = WIDGET(it);
1730 Widget_Data *wd = elm_widget_data_get(obj);
1733 selected = !!selected;
1734 if (it->selected == selected) return;
1736 evas_object_ref(obj);
1743 while (wd->selected)
1744 _item_unselect(wd->selected->data);
1746 _item_highlight(it);
1752 _elm_list_unwalk(wd);
1753 evas_object_unref(obj);
1757 elm_list_item_selected_get(const Elm_List_Item *it)
1759 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1760 return it->selected;
1764 elm_list_item_show(Elm_List_Item *it)
1766 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1767 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1768 Evas_Coord bx, by, bw, bh;
1769 Evas_Coord x, y, w, h;
1771 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1772 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1776 elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
1780 elm_list_item_bring_in(Elm_List_Item *it)
1782 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1783 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1784 Evas_Coord bx, by, bw, bh;
1785 Evas_Coord x, y, w, h;
1787 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1788 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1792 elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);
1796 elm_list_item_del(Elm_List_Item *it)
1798 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1799 Evas_Object *obj = WIDGET(it);
1800 Widget_Data *wd = elm_widget_data_get(obj);
1803 if (it->selected) _item_unselect(it);
1805 if (wd->walking > 0)
1807 if (it->deleted) return;
1808 it->deleted = EINA_TRUE;
1809 wd->to_delete = eina_list_append(wd->to_delete, it);
1813 wd->items = eina_list_remove_list(wd->items, it->node);
1815 evas_object_ref(obj);
1818 elm_widget_item_pre_notify_del(it);
1819 _elm_list_item_free(it);
1821 _elm_list_unwalk(wd);
1822 evas_object_unref(obj);
1826 elm_list_item_object_get(const Elm_List_Item *it)
1828 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1832 EAPI Elm_List_Item *
1833 elm_list_item_prev(const Elm_List_Item *it)
1835 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1836 if (it->node->prev) return it->node->prev->data;
1840 EAPI Elm_List_Item *
1841 elm_list_item_next(const Elm_List_Item *it)
1843 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1844 if (it->node->next) return it->node->next->data;
1848 EINA_DEPRECATED EAPI Evas_Object *
1849 elm_list_item_base_get(const Elm_List_Item *it)
1851 return elm_list_item_object_get(it);
1854 EINA_DEPRECATED EAPI void
1855 elm_list_item_disabled_set(Elm_List_Item *it, Eina_Bool disabled)
1857 elm_object_item_disabled_set((Elm_Object_Item *)it, disabled);
1860 EINA_DEPRECATED EAPI Eina_Bool
1861 elm_list_item_disabled_get(const Elm_List_Item *it)
1863 return elm_object_item_disabled_get((Elm_Object_Item *)it);
1866 EINA_DEPRECATED EAPI void
1867 elm_list_item_del_cb_set(Elm_List_Item *it, Evas_Smart_Cb func)
1869 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1870 elm_widget_item_del_cb_set(it, func);
1873 EINA_DEPRECATED EAPI void *
1874 elm_list_item_data_get(const Elm_List_Item *it)
1876 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1877 return elm_widget_item_data_get(it);
1880 // XXX: the below need to use the elm_object_item infra indicated
1881 // use elm_object_item_part_content_get
1882 EINA_DEPRECATED EAPI Evas_Object *
1883 elm_list_item_icon_get(const Elm_List_Item *it)
1885 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1886 if (it->dummy_icon) return NULL;
1890 // use elm_object_item_part_content_set
1891 EINA_DEPRECATED EAPI void
1892 elm_list_item_icon_set(Elm_List_Item *it, Evas_Object *icon)
1894 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1895 if (it->icon == icon) return;
1896 if ((it->dummy_icon) && (!icon)) return;
1899 evas_object_del(it->icon);
1900 it->dummy_icon = EINA_FALSE;
1904 icon = evas_object_rectangle_add(evas_object_evas_get(WIDGET(it)));
1905 evas_object_color_set(icon, 0, 0, 0, 0);
1906 it->dummy_icon = EINA_TRUE;
1910 evas_object_del(it->icon);
1915 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", icon);
1918 // use elm_object_item_part_content_get
1919 EINA_DEPRECATED EAPI Evas_Object *
1920 elm_list_item_end_get(const Elm_List_Item *it)
1922 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1923 if (it->dummy_end) return NULL;
1927 // use elm_object_item_part_content_set
1928 EINA_DEPRECATED EAPI void
1929 elm_list_item_end_set(Elm_List_Item *it, Evas_Object *end)
1931 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1932 if (it->end == end) return;
1933 if ((it->dummy_end) && (!end)) return;
1936 evas_object_del(it->end);
1937 it->dummy_icon = EINA_FALSE;
1941 end = evas_object_rectangle_add(evas_object_evas_get(WIDGET(it)));
1942 evas_object_color_set(end, 0, 0, 0, 0);
1943 it->dummy_end = EINA_TRUE;
1947 evas_object_del(it->end);
1952 edje_object_part_swallow(VIEW(it), "elm.swallow.end", end);
1955 // use elm_object_item_part_text_get
1956 EINA_DEPRECATED EAPI const char *
1957 elm_list_item_label_get(const Elm_List_Item *it)
1959 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1963 // use elm_object_item_part_text_set
1964 EINA_DEPRECATED EAPI void
1965 elm_list_item_label_set(Elm_List_Item *it, const char *text)
1967 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1968 if (!eina_stringshare_replace(&it->label, text)) return;
1970 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1973 // XXX: all the below - make elm_object_item*() calls to do these
1974 EINA_DEPRECATED EAPI void
1975 elm_list_item_tooltip_text_set(Elm_List_Item *item, const char *text)
1977 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
1978 elm_widget_item_tooltip_text_set(item, text);
1981 EINA_DEPRECATED EAPI void
1982 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)
1984 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
1985 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1988 EINA_DEPRECATED EAPI void
1989 elm_list_item_tooltip_unset(Elm_List_Item *item)
1991 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
1992 elm_widget_item_tooltip_unset(item);
1995 EINA_DEPRECATED EAPI Eina_Bool
1996 elm_list_item_tooltip_window_mode_set(Elm_List_Item *item, Eina_Bool disable)
1998 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, EINA_FALSE);
1999 return elm_widget_item_tooltip_window_mode_set(item, disable);
2002 EINA_DEPRECATED EAPI Eina_Bool
2003 elm_list_item_tooltip_window_mode_get(const Elm_List_Item *item)
2005 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, EINA_FALSE);
2006 return elm_widget_item_tooltip_window_mode_get(item);
2009 EINA_DEPRECATED EAPI void
2010 elm_list_item_tooltip_style_set(Elm_List_Item *item, const char *style)
2012 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2013 elm_widget_item_tooltip_style_set(item, style);
2016 EINA_DEPRECATED EAPI const char *
2017 elm_list_item_tooltip_style_get(const Elm_List_Item *item)
2019 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2020 return elm_widget_item_tooltip_style_get(item);
2023 EINA_DEPRECATED EAPI void
2024 elm_list_item_cursor_set(Elm_List_Item *item, const char *cursor)
2026 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2027 elm_widget_item_cursor_set(item, cursor);
2030 EINA_DEPRECATED EAPI const char *
2031 elm_list_item_cursor_get(const Elm_List_Item *item)
2033 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2034 return elm_widget_item_cursor_get(item);
2037 EINA_DEPRECATED EAPI void
2038 elm_list_item_cursor_unset(Elm_List_Item *item)
2040 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2041 elm_widget_item_cursor_unset(item);
2044 EINA_DEPRECATED EAPI void
2045 elm_list_item_cursor_style_set(Elm_List_Item *item, const char *style)
2047 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2048 elm_widget_item_cursor_style_set(item, style);
2051 EINA_DEPRECATED EAPI const char *
2052 elm_list_item_cursor_style_get(const Elm_List_Item *item)
2054 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, NULL);
2055 return elm_widget_item_cursor_style_get(item);
2058 EINA_DEPRECATED EAPI void
2059 elm_list_item_cursor_engine_only_set(Elm_List_Item *item, Eina_Bool engine_only)
2061 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item);
2062 elm_widget_item_cursor_engine_only_set(item, engine_only);
2065 EINA_DEPRECATED EAPI Eina_Bool
2066 elm_list_item_cursor_engine_only_get(const Elm_List_Item *item)
2068 ELM_LIST_ITEM_CHECK_DELETED_RETURN(item, EINA_FALSE);
2069 return elm_widget_item_cursor_engine_only_get(item);