1 #include <Elementary.h>
3 #include "els_scroller.h"
7 typedef struct _Widget_Data Widget_Data;
8 typedef struct _Elm_List_Item Elm_List_Item;
12 Evas_Object *scr, *box, *self;
13 Eina_List *items, *selected, *to_delete;
14 Elm_Object_Item *last_selected_item;
17 Evas_Coord minw[2], minh[2];
18 Elm_Object_Select_Mode select_mode;
24 } history[SWIPE_MOVES];
25 Eina_Bool scr_minw : 1;
26 Eina_Bool scr_minh : 1;
28 Eina_Bool fix_pending : 1;
29 Eina_Bool on_hold : 1;
31 Eina_Bool longpressed : 1;
32 Eina_Bool wasselected : 1;
41 Evas_Object *icon, *end;
43 Ecore_Timer *long_timer;
44 Ecore_Timer *swipe_timer;
45 Eina_Bool deleted : 1;
47 Eina_Bool is_even : 1;
48 Eina_Bool is_separator : 1;
50 Eina_Bool selected : 1;
51 Eina_Bool highlighted : 1;
52 Eina_Bool dummy_icon : 1;
53 Eina_Bool dummy_end : 1;
56 static const char *widtype = NULL;
57 static void _del_hook(Evas_Object *obj);
58 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
59 static void _theme_hook(Evas_Object *obj);
60 static void _sizing_eval(Evas_Object *obj);
61 static void _disable_hook(Evas_Object *obj);
62 static void _on_focus_hook(void *data, Evas_Object *obj);
63 static void _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source);
64 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
65 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
66 static void _fix_items(Evas_Object *obj);
67 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
68 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
69 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
70 static void _edge_left(void *data, Evas_Object *scr, void *event_info);
71 static void _edge_right(void *data, Evas_Object *scr, void *event_info);
72 static void _edge_top(void *data, Evas_Object *scr, void *event_info);
73 static void _edge_bottom(void *data, Evas_Object *scr, void *event_info);
74 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
75 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
76 static Eina_Bool _item_single_select_up(Widget_Data *wd);
77 static Eina_Bool _item_single_select_down(Widget_Data *wd);
78 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
79 Evas_Callback_Type type, void *event_info);
80 static Eina_Bool _deselect_all_items(Widget_Data *wd);
82 static const char SIG_ACTIVATED[] = "activated";
83 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
84 static const char SIG_SELECTED[] = "selected";
85 static const char SIG_UNSELECTED[] = "unselected";
86 static const char SIG_LONGPRESSED[] = "longpressed";
87 static const char SIG_EDGE_TOP[] = "edge,top";
88 static const char SIG_EDGE_BOTTOM[] = "edge,bottom";
89 static const char SIG_EDGE_LEFT[] = "edge,left";
90 static const char SIG_EDGE_RIGHT[] = "edge,right";
92 static const Evas_Smart_Cb_Description _signals[] = {
94 {SIG_CLICKED_DOUBLE, ""},
97 {SIG_LONGPRESSED, ""},
99 {SIG_EDGE_BOTTOM, ""},
101 {SIG_EDGE_RIGHT, ""},
105 #define ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ...) \
106 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, __VA_ARGS__); \
107 if (((Elm_List_Item *)it)->deleted) \
109 ERR("ERROR: "#it" has been DELETED.\n"); \
110 return __VA_ARGS__; \
114 _elm_list_item_free(Elm_List_Item *it)
116 evas_object_event_callback_del_full
117 (VIEW(it), EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, it);
118 evas_object_event_callback_del_full
119 (VIEW(it), EVAS_CALLBACK_MOUSE_UP, _mouse_up, it);
120 evas_object_event_callback_del_full
121 (VIEW(it), EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, it);
124 evas_object_event_callback_del_full
125 (it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
126 _changed_size_hints, WIDGET(it));
129 evas_object_event_callback_del_full
130 (it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
131 _changed_size_hints, WIDGET(it));
133 eina_stringshare_del(it->label);
135 if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
136 if (it->long_timer) ecore_timer_del(it->long_timer);
137 if (it->icon) evas_object_del(it->icon);
138 if (it->end) evas_object_del(it->end);
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((Elm_Object_Item *)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((Elm_Object_Item *)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_Item *) 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((Elm_Object_Item *) wd->selected->data,
315 _item_multi_select_up(Widget_Data *wd)
317 if (!wd->selected) return EINA_FALSE;
318 if (!wd->multi) return EINA_FALSE;
320 Elm_Object_Item *prev = elm_list_item_prev(wd->last_selected_item);
321 if (!prev) return EINA_TRUE;
323 if (elm_list_item_selected_get(prev))
325 elm_list_item_selected_set(wd->last_selected_item, EINA_FALSE);
326 wd->last_selected_item = prev;
327 elm_list_item_show(wd->last_selected_item);
331 elm_list_item_selected_set(prev, EINA_TRUE);
332 elm_list_item_show(prev);
338 _item_multi_select_down(Widget_Data *wd)
340 if (!wd->selected) return EINA_FALSE;
341 if (!wd->multi) return EINA_FALSE;
343 Elm_Object_Item *next = elm_list_item_next(wd->last_selected_item);
344 if (!next) return EINA_TRUE;
346 if (elm_list_item_selected_get(next))
348 elm_list_item_selected_set(wd->last_selected_item, EINA_FALSE);
349 wd->last_selected_item = next;
350 elm_list_item_show(wd->last_selected_item);
354 elm_list_item_selected_set(next, EINA_TRUE);
355 elm_list_item_show(next);
361 _item_single_select_up(Widget_Data *wd)
363 Elm_Object_Item *prev;
365 if (!wd->selected) prev = eina_list_data_get(eina_list_last(wd->items));
366 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)
379 Elm_Object_Item *next;
381 if (!wd->selected) next = eina_list_data_get(wd->items);
382 else next = elm_list_item_next(wd->last_selected_item);
383 if (!next) return EINA_FALSE;
385 _deselect_all_items(wd);
387 elm_list_item_selected_set(next, EINA_TRUE);
388 elm_list_item_show(next);
393 _elm_list_process_deletions(Widget_Data *wd)
397 wd->walking++; // avoid nested deletion and also _sub_del() fix_items
399 EINA_LIST_FREE(wd->to_delete, it)
401 wd->items = eina_list_remove_list(wd->items, it->node);
402 _elm_list_item_free(it);
403 elm_widget_item_free(it);
410 _elm_list_walk(Widget_Data *wd)
414 ERR("ERROR: walking was negative. fixed!\n");
421 _elm_list_unwalk(Widget_Data *wd)
426 ERR("ERROR: walking became negative. fixed!\n");
434 _elm_list_process_deletions(wd);
438 wd->fix_pending = EINA_FALSE;
439 _fix_items(wd->self);
440 _sizing_eval(wd->self);
445 _del_pre_hook(Evas_Object *obj)
447 Widget_Data *wd = elm_widget_data_get(obj);
451 evas_object_smart_callback_del(obj, "sub-object-del", _sub_del);
455 EINA_LIST_FOREACH(wd->items, l, it)
458 evas_object_event_callback_del(it->icon,
459 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
460 _changed_size_hints);
462 evas_object_event_callback_del(it->end,
463 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
464 _changed_size_hints);
467 evas_object_event_callback_del(wd->scr,
468 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
469 _changed_size_hints);
470 evas_object_event_callback_del(wd->box,
471 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
472 _changed_size_hints);
476 _del_hook(Evas_Object *obj)
478 Widget_Data *wd = elm_widget_data_get(obj);
484 ERR("ERROR: list deleted while walking.\n");
487 EINA_LIST_FOREACH(wd->items, n, it) elm_widget_item_pre_notify_del(it);
488 _elm_list_unwalk(wd);
490 ERR("ERROR: leaking nodes!\n");
492 EINA_LIST_FREE(wd->items, it)
494 _elm_list_item_free(it);
495 elm_widget_item_free(it);
497 eina_list_free(wd->selected);
502 _show_region_hook(void *data, Evas_Object *obj)
504 Widget_Data *wd = elm_widget_data_get(data);
505 Evas_Coord x, y, w, h;
507 elm_widget_show_region_get(obj, &x, &y, &w, &h);
508 elm_smart_scroller_child_region_set(wd->scr, x, y, w, h);
512 _disable_hook(Evas_Object *obj)
514 Widget_Data *wd = elm_widget_data_get(obj);
516 if (elm_widget_disabled_get(obj))
518 _signal_emit_hook(obj, "elm,state,disabled", "elm");
519 elm_widget_scroll_freeze_push(obj);
520 elm_widget_scroll_hold_push(obj);
521 /* FIXME: if we get to have a way to only un-highlight items
522 * in the future, keeping them selected... */
523 _deselect_all_items(wd);
527 _signal_emit_hook(obj, "elm,state,enabled", "elm");
528 elm_widget_scroll_freeze_pop(obj);
529 elm_widget_scroll_hold_pop(obj);
534 _sizing_eval(Evas_Object *obj)
537 Widget_Data *wd = elm_widget_data_get(obj);
539 Evas_Coord vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
542 evas_object_size_hint_min_get(wd->box, &minw, &minh);
543 evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
544 evas_object_size_hint_weight_get(wd->box, &xw, &yw);
545 if (!wd->scr) return;
546 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
549 if ((minw > 0) && (vw < minw)) vw = minw;
550 else if ((maxw > 0) && (vw > maxw)) vw = maxw;
552 else if (minw > 0) vw = minw;
555 if ((minh > 0) && (vh < minh)) vh = minh;
556 else if ((maxh > 0) && (vh > maxh)) vh = maxh;
558 else if (minh > 0) vh = minh;
559 evas_object_resize(wd->box, vw, vh);
562 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
564 if (wd->scr_minw) w = vmw + minw;
565 if (wd->scr_minh) h = vmh + minh;
567 evas_object_size_hint_max_get(obj, &maxw, &maxh);
568 if ((maxw > 0) && (w > maxw))
570 if ((maxh > 0) && (h > maxh))
573 evas_object_size_hint_min_set(obj, w, h);
577 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
579 Widget_Data *wd = elm_widget_data_get(obj);
580 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
585 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
587 Widget_Data *wd = elm_widget_data_get(obj);
588 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
589 emission, source, func_cb, data);
593 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
595 Widget_Data *wd = elm_widget_data_get(obj);
596 edje_object_signal_callback_del_full(
597 elm_smart_scroller_edje_object_get(wd->scr),
598 emission, source, func_cb, data);
602 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
604 Widget_Data *wd = elm_widget_data_get(obj);
610 elm_smart_scroller_mirrored_set(wd->scr, rtl);
612 EINA_LIST_FOREACH(wd->items, n, it)
613 edje_object_mirrored_set(VIEW(it), rtl);
617 _theme_hook(Evas_Object *obj)
619 Widget_Data *wd = elm_widget_data_get(obj);
624 _elm_widget_mirrored_reload(obj);
625 _mirrored_set(obj, elm_widget_mirrored_get(obj));
632 elm_smart_scroller_object_theme_set(obj, wd->scr, "list", "base",
633 elm_widget_style_get(obj));
634 // edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
635 edj = elm_smart_scroller_edje_object_get(wd->scr);
636 str = edje_object_data_get(edj, "focus_highlight");
637 if ((str) && (!strcmp(str, "on")))
638 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
640 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
641 elm_object_style_set(wd->scr, elm_widget_style_get(obj));
643 EINA_LIST_FOREACH(wd->items, n, it)
645 edje_object_scale_set(VIEW(it), elm_widget_scale_get(obj) * _elm_config->scale);
653 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
655 Widget_Data *wd = elm_widget_data_get(obj);
657 if (elm_widget_focus_get(obj))
659 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
660 evas_object_focus_set(wd->self, EINA_TRUE);
662 if ((wd->selected) && (!wd->last_selected_item))
663 wd->last_selected_item = eina_list_data_get(wd->selected);
667 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
668 evas_object_focus_set(wd->self, EINA_FALSE);
673 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
675 Widget_Data *wd = elm_widget_data_get(data);
682 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
684 Widget_Data *wd = elm_widget_data_get(obj);
685 Evas_Object *sub = event_info;
691 if ((sub == wd->box) || (sub == wd->scr)) return;
693 EINA_LIST_FOREACH(wd->items, l, it)
695 if ((sub == it->icon) || (sub == it->end))
697 if (it->icon == sub) it->icon = NULL;
698 if (it->end == sub) it->end = NULL;
699 evas_object_event_callback_del_full
700 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints,
708 wd->fix_pending = EINA_TRUE;
715 _item_highlight(Elm_List_Item *it)
717 Evas_Object *obj = WIDGET(it);
718 Widget_Data *wd = elm_widget_data_get(obj);
719 const char *selectraise;
722 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
723 if ((it->highlighted) || (it->base.disabled) ||
724 (wd->select_mode == ELM_OBJECT_SELECT_MODE_NONE)) return;
726 evas_object_ref(obj);
729 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
730 selectraise = edje_object_data_get(VIEW(it), "selectraise");
731 if ((selectraise) && (!strcmp(selectraise, "on")))
732 evas_object_raise(VIEW(it));
733 it->highlighted = EINA_TRUE;
735 _elm_list_unwalk(wd);
736 evas_object_unref(obj);
740 _item_select(Elm_List_Item *it)
742 Evas_Object *obj = WIDGET(it);
743 Widget_Data *wd = elm_widget_data_get(obj);
746 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
747 if (it->base.disabled || (wd->select_mode == ELM_OBJECT_SELECT_MODE_NONE)) return;
750 if (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) goto call;
753 it->selected = EINA_TRUE;
754 wd->selected = eina_list_append(wd->selected, it);
757 evas_object_ref(obj);
760 if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
761 evas_object_smart_callback_call(obj, SIG_SELECTED, it);
762 it->wd->last_selected_item = (Elm_Object_Item *)it;
764 _elm_list_unwalk(wd);
765 evas_object_unref(obj);
769 _item_unselect(Elm_List_Item *it)
771 Evas_Object *obj = WIDGET(it);
772 Widget_Data *wd = elm_widget_data_get(obj);
773 const char *stacking, *selectraise;
776 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
777 if (!it->highlighted) return;
779 evas_object_ref(obj);
782 edje_object_signal_emit(VIEW(it), "elm,state,unselected", "elm");
783 stacking = edje_object_data_get(VIEW(it), "stacking");
784 selectraise = edje_object_data_get(VIEW(it), "selectraise");
785 if ((selectraise) && (!strcmp(selectraise, "on")))
787 if ((stacking) && (!strcmp(stacking, "below")))
788 evas_object_lower(VIEW(it));
790 it->highlighted = EINA_FALSE;
793 it->selected = EINA_FALSE;
794 wd->selected = eina_list_remove(wd->selected, it);
795 evas_object_smart_callback_call(WIDGET(it), SIG_UNSELECTED, it);
798 _elm_list_unwalk(wd);
799 evas_object_unref(obj);
803 _swipe_cancel(void *data)
805 Elm_List_Item *it = data;
806 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
808 if (!wd) return ECORE_CALLBACK_CANCEL;
809 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
810 wd->swipe = EINA_FALSE;
812 return ECORE_CALLBACK_RENEW;
816 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
818 Elm_List_Item *it = data;
819 Evas_Object *obj2 = WIDGET(it);
820 Widget_Data *wd = elm_widget_data_get(obj2);
821 Evas_Event_Mouse_Move *ev = event_info;
824 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
826 evas_object_ref(obj2);
829 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
833 wd->on_hold = EINA_TRUE;
836 ecore_timer_del(it->long_timer);
837 it->long_timer = NULL;
839 if (!wd->wasselected)
842 if (wd->movements == SWIPE_MOVES) wd->swipe = EINA_TRUE;
845 wd->history[wd->movements].x = ev->cur.canvas.x;
846 wd->history[wd->movements].y = ev->cur.canvas.y;
847 if (abs((wd->history[wd->movements].x - wd->history[0].x)) > 40)
848 wd->swipe = EINA_TRUE;
854 _elm_list_unwalk(wd);
855 evas_object_unref(obj2);
859 _edge_left(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
861 Evas_Object *obj = data;
862 evas_object_smart_callback_call(obj, SIG_EDGE_LEFT, NULL);
866 _edge_right(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
868 Evas_Object *obj = data;
869 evas_object_smart_callback_call(obj, SIG_EDGE_RIGHT, NULL);
873 _edge_top(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
875 Evas_Object *obj = data;
876 evas_object_smart_callback_call(obj, SIG_EDGE_TOP, NULL);
880 _edge_bottom(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
882 Evas_Object *obj = data;
883 evas_object_smart_callback_call(obj, SIG_EDGE_BOTTOM, NULL);
887 _long_press(void *data)
889 Elm_List_Item *it = data;
890 Evas_Object *obj = WIDGET(it);
891 Widget_Data *wd = elm_widget_data_get(obj);
895 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
896 it->long_timer = NULL;
897 if (it->base.disabled) goto end;
899 wd->longpressed = EINA_TRUE;
900 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
903 return ECORE_CALLBACK_CANCEL;
907 _swipe(Elm_List_Item *it)
910 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
912 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
914 wd->swipe = EINA_FALSE;
915 for (i = 0; i < wd->movements; i++)
917 sum += wd->history[i].x;
918 if (abs(wd->history[0].y - wd->history[i].y) > 10) return;
921 sum /= wd->movements;
922 if (abs(sum - wd->history[0].x) <= 10) return;
923 evas_object_smart_callback_call(WIDGET(it), "swipe", it);
927 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
929 Elm_List_Item *it = data;
930 Evas_Object *obj2 = WIDGET(it);
931 Widget_Data *wd = elm_widget_data_get(obj2);
932 Evas_Event_Mouse_Down *ev = event_info;
935 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
936 if (ev->button != 1) return;
937 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
938 else wd->on_hold = EINA_FALSE;
939 if (wd->on_hold) return;
940 wd->wasselected = it->selected;
942 evas_object_ref(obj2);
946 wd->longpressed = EINA_FALSE;
947 if (it->long_timer) ecore_timer_del(it->long_timer);
948 it->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, it);
949 if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
950 it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
951 /* Always call the callbacks last - the user may delete our context! */
952 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
954 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
955 evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it);
957 wd->swipe = EINA_FALSE;
960 _elm_list_unwalk(wd);
961 evas_object_unref(obj2);
965 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
967 Elm_List_Item *it = data;
968 Evas_Object *obj2 = WIDGET(it);
969 Widget_Data *wd = elm_widget_data_get(obj2);
970 Evas_Event_Mouse_Up *ev = event_info;
973 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
974 if (ev->button != 1) return;
975 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
976 else wd->on_hold = EINA_FALSE;
977 wd->longpressed = EINA_FALSE;
980 ecore_timer_del(it->long_timer);
981 it->long_timer = NULL;
985 ecore_timer_del(it->swipe_timer);
986 it->swipe_timer = NULL;
990 if (wd->swipe) _swipe(data);
991 wd->on_hold = EINA_FALSE;
996 if (!wd->wasselected) _item_unselect(it);
1001 if (it->base.disabled)
1003 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1005 evas_object_ref(obj2);
1012 _item_highlight(it);
1015 else _item_unselect(it);
1021 while (wd->selected)
1022 _item_unselect(wd->selected->data);
1023 _item_highlight(it);
1028 const Eina_List *l, *l_next;
1031 EINA_LIST_FOREACH_SAFE(wd->selected, l, l_next, it2)
1032 if (it2 != it) _item_unselect(it2);
1033 _item_highlight(it);
1038 _elm_list_unwalk(wd);
1039 evas_object_unref(obj2);
1043 _item_disable(Elm_Object_Item *it)
1045 Elm_List_Item *item = (Elm_List_Item *)it;
1046 if (item->base.disabled)
1047 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
1049 edje_object_signal_emit(VIEW(item), "elm,state,enabled", "elm");
1053 _item_content_set_hook(Elm_Object_Item *it, const char *part, Evas_Object *content)
1055 Elm_List_Item *item = (Elm_List_Item *)it;
1056 Evas_Object **icon_p = NULL;
1057 Eina_Bool dummy = EINA_FALSE;
1059 if ((!part) || (!strcmp(part, "start")))
1061 icon_p = &(item->icon);
1062 dummy = item->dummy_icon;
1063 if (!content) item->dummy_icon = EINA_TRUE;
1064 else item->dummy_icon = EINA_FALSE;
1066 else if (!strcmp(part, "end"))
1068 icon_p = &(item->end);
1069 dummy = item->dummy_end;
1070 if (!content) item->dummy_end = EINA_TRUE;
1071 else item->dummy_end = EINA_FALSE;
1076 if (content == *icon_p) return;
1077 if ((dummy) && (!content)) return;
1078 if (dummy) evas_object_del(*icon_p);
1081 content = evas_object_rectangle_add(evas_object_evas_get(WIDGET(item)));
1082 evas_object_color_set(content, 0, 0, 0, 0);
1086 evas_object_del(*icon_p);
1091 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", content);
1094 static Evas_Object *
1095 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
1097 Elm_List_Item *item = (Elm_List_Item *)it;
1099 if ((!part) || (!strcmp(part, "start")))
1101 if (item->dummy_icon) return NULL;
1104 else if (!strcmp(part, "end"))
1106 if (item->dummy_end) return NULL;
1112 static Evas_Object *
1113 _item_content_unset_hook(const Elm_Object_Item *it, const char *part)
1115 Elm_List_Item *item = (Elm_List_Item *)it;
1117 if ((!part) || (!strcmp(part, "start")))
1119 Evas_Object *obj = item->icon;
1120 _item_content_set_hook((Elm_Object_Item *)it, part, NULL);
1123 else if (!strcmp(part, "end"))
1125 Evas_Object *obj = item->end;
1126 _item_content_set_hook((Elm_Object_Item *)it, part, NULL);
1133 _item_text_set(Elm_Object_Item *it, const char *part, const char *text)
1135 Elm_List_Item *list_it = (Elm_List_Item *)it;
1136 if (part && strcmp(part, "default")) return;
1137 if (!eina_stringshare_replace(&list_it->label, text)) return;
1139 edje_object_part_text_set(VIEW(list_it), "elm.text", text);
1143 _item_text_get(const Elm_Object_Item *it, const char *part)
1145 if (part && strcmp(part, "default")) return NULL;
1146 return ((Elm_List_Item *)it)->label;
1150 _item_del_pre_hook(Elm_Object_Item *it)
1152 Evas_Object *obj = WIDGET(it);
1153 Elm_List_Item *item = (Elm_List_Item *)it;
1154 Widget_Data *wd = elm_widget_data_get(obj);
1155 if (!wd) return EINA_FALSE;
1157 if (item->selected) _item_unselect(item);
1159 if (wd->walking > 0)
1161 if (item->deleted) return EINA_FALSE;
1162 item->deleted = EINA_TRUE;
1163 wd->to_delete = eina_list_append(wd->to_delete, item);
1167 wd->items = eina_list_remove_list(wd->items, item->node);
1169 evas_object_ref(obj);
1172 _elm_list_item_free(item);
1174 _elm_list_unwalk(wd);
1175 evas_object_unref(obj);
1180 static Elm_List_Item *
1181 _item_new(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1183 Widget_Data *wd = elm_widget_data_get(obj);
1186 if (!wd) return NULL;
1187 it = elm_widget_item_new(obj, Elm_List_Item);
1189 it->label = eina_stringshare_add(label);
1193 it->base.data = data;
1194 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
1195 edje_object_mirrored_set(VIEW(it), elm_widget_mirrored_get(obj));
1196 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
1198 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
1200 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1202 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1203 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
1206 elm_widget_sub_object_add(obj, it->icon);
1207 evas_object_event_callback_add(it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1208 _changed_size_hints, obj);
1212 elm_widget_sub_object_add(obj, it->end);
1213 evas_object_event_callback_add(it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1214 _changed_size_hints, obj);
1216 elm_widget_item_disable_hook_set(it, _item_disable);
1217 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
1218 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
1219 elm_widget_item_content_unset_hook_set(it, _item_content_unset_hook);
1220 elm_widget_item_text_set_hook_set(it, _item_text_set);
1221 elm_widget_item_text_get_hook_set(it, _item_text_get);
1222 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
1227 _elm_list_mode_set_internal(Widget_Data *wd)
1232 if (wd->mode == ELM_LIST_LIMIT)
1236 wd->scr_minw = EINA_TRUE;
1237 wd->scr_minh = EINA_FALSE;
1241 wd->scr_minw = EINA_FALSE;
1242 wd->scr_minh = EINA_TRUE;
1245 else if (wd->mode == ELM_LIST_EXPAND)
1247 wd->scr_minw = EINA_TRUE;
1248 wd->scr_minh = EINA_TRUE;
1252 wd->scr_minw = EINA_FALSE;
1253 wd->scr_minh = EINA_FALSE;
1256 _sizing_eval(wd->self);
1260 _fix_items(Evas_Object *obj)
1262 Widget_Data *wd = elm_widget_data_get(obj);
1266 Evas_Coord minw[2] = { 0, 0 }, minh[2] = { 0, 0 };
1269 const char *style = elm_widget_style_get(obj);
1270 const char *it_plain = wd->h_mode ? "h_item" : "item";
1271 const char *it_odd = wd->h_mode ? "h_item_odd" : "item_odd";
1272 const char *it_compress = wd->h_mode ? "h_item_compress" : "item_compress";
1273 const char *it_compress_odd = wd->h_mode ? "h_item_compress_odd" : "item_compress_odd";
1277 wd->fix_pending = EINA_TRUE;
1281 evas_object_ref(obj);
1282 _elm_list_walk(wd); // watch out "return" before unwalk!
1284 EINA_LIST_FOREACH(wd->items, l, it)
1286 if (it->deleted) continue;
1289 evas_object_size_hint_min_get(it->icon, &mw, &mh);
1290 if (mw > minw[0]) minw[0] = mw;
1291 if (mh > minh[0]) minh[0] = mh;
1295 evas_object_size_hint_min_get(it->end, &mw, &mh);
1296 if (mw > minw[1]) minw[1] = mw;
1297 if (mh > minh[1]) minh[1] = mh;
1301 if ((minw[0] != wd->minw[0]) || (minw[1] != wd->minw[1]) ||
1302 (minw[0] != wd->minh[0]) || (minh[1] != wd->minh[1]))
1304 wd->minw[0] = minw[0];
1305 wd->minw[1] = minw[1];
1306 wd->minh[0] = minh[0];
1307 wd->minh[1] = minh[1];
1311 EINA_LIST_FOREACH(wd->items, l, it)
1317 if ((it->even != it->is_even) || (!it->fixed) || (redo))
1319 const char *stacking;
1321 /* FIXME: separators' themes seem to be b0rked */
1322 if (it->is_separator)
1323 _elm_theme_object_set(obj, VIEW(it), "separator",
1324 wd->h_mode ? "horizontal" : "vertical",
1326 else if (wd->mode == ELM_LIST_COMPRESS)
1329 _elm_theme_object_set(obj, VIEW(it), "list",
1330 it_compress, style);
1332 _elm_theme_object_set(obj, VIEW(it), "list",
1333 it_compress_odd, style);
1338 _elm_theme_object_set(obj, VIEW(it), "list", it_plain,
1341 _elm_theme_object_set(obj, VIEW(it), "list", it_odd,
1344 stacking = edje_object_data_get(VIEW(it), "stacking");
1347 if (!strcmp(stacking, "below"))
1348 evas_object_lower(VIEW(it));
1349 else if (!strcmp(stacking, "above"))
1350 evas_object_raise(VIEW(it));
1352 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1354 if ((!it->icon) && (minh[0] > 0))
1356 it->icon = evas_object_rectangle_add(evas_object_evas_get(VIEW(it)));
1357 evas_object_color_set(it->icon, 0, 0, 0, 0);
1358 it->dummy_icon = EINA_TRUE;
1360 if ((!it->end) && (minh[1] > 0))
1362 it->end = evas_object_rectangle_add(evas_object_evas_get(VIEW(it)));
1363 evas_object_color_set(it->end, 0, 0, 0, 0);
1364 it->dummy_end = EINA_TRUE;
1368 evas_object_size_hint_min_set(it->icon, minw[0], minh[0]);
1369 evas_object_size_hint_max_set(it->icon, 99999, 99999);
1370 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
1374 evas_object_size_hint_min_set(it->end, minw[1], minh[1]);
1375 evas_object_size_hint_max_set(it->end, 99999, 99999);
1376 edje_object_part_swallow(VIEW(it), "elm.swallow.end", it->end);
1380 // this may call up user and it may modify the list item
1381 // but we're safe as we're flagged as walking.
1382 // just don't process further
1383 edje_object_message_signal_process(VIEW(it));
1387 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1388 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
1389 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1390 evas_object_size_hint_min_set(VIEW(it), mw, mh);
1391 evas_object_show(VIEW(it));
1393 if ((it->selected) || (it->highlighted))
1395 const char *selectraise;
1397 // this may call up user and it may modify the list item
1398 // but we're safe as we're flagged as walking.
1399 // just don't process further
1400 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
1404 selectraise = edje_object_data_get(VIEW(it), "selectraise");
1405 if ((selectraise) && (!strcmp(selectraise, "on")))
1406 evas_object_raise(VIEW(it));
1408 if (it->base.disabled)
1409 edje_object_signal_emit(VIEW(it), "elm,state,disabled",
1412 it->fixed = EINA_TRUE;
1413 it->is_even = it->even;
1419 evas_object_size_hint_min_get(wd->box, &mw, &mh);
1421 _elm_list_mode_set_internal(wd);
1423 _elm_list_unwalk(wd);
1424 evas_object_unref(obj);
1428 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1430 Widget_Data *wd = elm_widget_data_get(obj);
1433 elm_smart_scroller_hold_set(wd->scr, EINA_TRUE);
1437 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1439 Widget_Data *wd = elm_widget_data_get(obj);
1442 elm_smart_scroller_hold_set(wd->scr, EINA_FALSE);
1446 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1448 Widget_Data *wd = elm_widget_data_get(obj);
1451 elm_smart_scroller_freeze_set(wd->scr, EINA_TRUE);
1455 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1457 Widget_Data *wd = elm_widget_data_get(obj);
1460 elm_smart_scroller_freeze_set(wd->scr, EINA_FALSE);
1464 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1470 elm_list_add(Evas_Object *parent)
1475 Evas_Coord minw, minh;
1477 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1479 ELM_SET_WIDTYPE(widtype, "list");
1480 elm_widget_type_set(obj, "list");
1481 elm_widget_sub_object_add(parent, obj);
1482 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1483 elm_widget_data_set(obj, wd);
1484 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1485 elm_widget_del_hook_set(obj, _del_hook);
1486 elm_widget_theme_hook_set(obj, _theme_hook);
1487 elm_widget_disable_hook_set(obj, _disable_hook);
1488 elm_widget_can_focus_set(obj, EINA_TRUE);
1489 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1490 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1491 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1492 elm_widget_event_hook_set(obj, _event_hook);
1493 elm_widget_translate_hook_set(obj, _translate_hook);
1496 wd->scr = elm_smart_scroller_add(e);
1497 elm_smart_scroller_widget_set(wd->scr, obj);
1498 elm_widget_resize_object_set(obj, wd->scr);
1499 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1500 _changed_size_hints, obj);
1501 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
1502 evas_object_size_hint_min_set(obj, minw, minh);
1503 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
1505 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
1506 _elm_config->thumbscroll_bounce_enable);
1508 wd->box = elm_box_add(parent);
1509 elm_box_homogeneous_set(wd->box, 1);
1510 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1511 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1512 elm_widget_on_show_region_hook_set(wd->box, _show_region_hook, obj);
1513 elm_widget_sub_object_add(obj, wd->box);
1514 elm_smart_scroller_child_set(wd->scr, wd->box);
1515 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1516 _changed_size_hints, obj);
1518 evas_object_show(wd->box);
1522 wd->mode = ELM_LIST_SCROLL;
1524 evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
1525 evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
1526 evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
1527 evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom, obj);
1529 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1530 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1531 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1532 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1533 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1535 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1537 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1543 elm_list_go(Evas_Object *obj)
1545 ELM_CHECK_WIDTYPE(obj, widtype);
1546 Widget_Data *wd = elm_widget_data_get(obj);
1552 elm_list_multi_select_set(Evas_Object *obj, Eina_Bool multi)
1554 ELM_CHECK_WIDTYPE(obj, widtype);
1555 Widget_Data *wd = elm_widget_data_get(obj);
1561 elm_list_multi_select_get(const Evas_Object *obj)
1563 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1564 Widget_Data *wd = elm_widget_data_get(obj);
1565 if (!wd) return EINA_FALSE;
1570 elm_list_mode_set(Evas_Object *obj, Elm_List_Mode mode)
1572 ELM_CHECK_WIDTYPE(obj, widtype);
1576 wd = elm_widget_data_get(obj);
1579 if (wd->mode == mode)
1583 _elm_list_mode_set_internal(wd);
1587 elm_list_mode_get(const Evas_Object *obj)
1589 ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
1590 Widget_Data *wd = elm_widget_data_get(obj);
1591 if (!wd) return ELM_LIST_LAST;
1596 elm_list_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1598 ELM_CHECK_WIDTYPE(obj, widtype);
1601 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1603 wd = elm_widget_data_get(obj);
1607 if (wd->h_mode == horizontal)
1610 wd->h_mode = horizontal;
1611 elm_box_horizontal_set(wd->box, horizontal);
1615 evas_object_size_hint_weight_set(wd->box, 0.0, EVAS_HINT_EXPAND);
1616 evas_object_size_hint_align_set(wd->box, 0.0, EVAS_HINT_FILL);
1617 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1621 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1622 evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1623 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE, bounce);
1626 _elm_list_mode_set_internal(wd);
1630 elm_list_horizontal_get(const Evas_Object *obj)
1632 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1636 wd = elm_widget_data_get(obj);
1644 elm_list_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
1646 ELM_CHECK_WIDTYPE(obj, widtype);
1647 Widget_Data *wd = elm_widget_data_get(obj);
1649 if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
1651 if (wd->select_mode != mode)
1652 wd->select_mode = mode;
1655 EAPI Elm_Object_Select_Mode
1656 elm_list_select_mode_get(const Evas_Object *obj)
1658 ELM_CHECK_WIDTYPE(obj, widtype) ELM_OBJECT_SELECT_MODE_MAX;
1659 Widget_Data *wd = elm_widget_data_get(obj);
1660 if (!wd) return ELM_OBJECT_SELECT_MODE_MAX;
1661 return wd->select_mode;
1665 elm_list_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1667 ELM_CHECK_WIDTYPE(obj, widtype);
1668 Widget_Data *wd = elm_widget_data_get(obj);
1671 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1675 elm_list_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1677 ELM_CHECK_WIDTYPE(obj, widtype);
1678 Widget_Data *wd = elm_widget_data_get(obj);
1680 elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
1684 elm_list_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1686 ELM_CHECK_WIDTYPE(obj, widtype);
1687 Widget_Data *wd = elm_widget_data_get(obj);
1688 if ((!wd) || (!wd->scr)) return;
1689 if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1690 (policy_v >= ELM_SCROLLER_POLICY_LAST))
1692 elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
1696 elm_list_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1698 ELM_CHECK_WIDTYPE(obj, widtype);
1699 Widget_Data *wd = elm_widget_data_get(obj);
1700 Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1701 if ((!wd) || (!wd->scr)) return;
1702 elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
1703 if (policy_h) *policy_h = (Elm_Scroller_Policy) s_policy_h;
1704 if (policy_v) *policy_v = (Elm_Scroller_Policy) s_policy_v;
1708 elm_list_clear(Evas_Object *obj)
1710 ELM_CHECK_WIDTYPE(obj, widtype);
1711 Widget_Data *wd = elm_widget_data_get(obj);
1715 if (!wd->items) return;
1717 eina_list_free(wd->selected);
1718 wd->selected = NULL;
1720 if (wd->walking > 0)
1724 EINA_LIST_FOREACH(wd->items, n, it)
1726 if (it->deleted) continue;
1727 it->deleted = EINA_TRUE;
1728 wd->to_delete = eina_list_append(wd->to_delete, it);
1733 evas_object_ref(obj);
1736 EINA_LIST_FREE(wd->items, it)
1738 _elm_list_item_free(it);
1739 elm_widget_item_free(it);
1742 _elm_list_unwalk(wd);
1746 evas_object_unref(obj);
1749 EAPI const Eina_List *
1750 elm_list_items_get(const Evas_Object *obj)
1752 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1753 Widget_Data *wd = elm_widget_data_get(obj);
1754 if (!wd) return NULL;
1758 EAPI Elm_Object_Item *
1759 elm_list_selected_item_get(const Evas_Object *obj)
1761 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1762 Widget_Data *wd = elm_widget_data_get(obj);
1763 if (!wd) return NULL;
1764 if (wd->selected) return (Elm_Object_Item *) wd->selected->data;
1768 EAPI const Eina_List *
1769 elm_list_selected_items_get(const Evas_Object *obj)
1771 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1772 Widget_Data *wd = elm_widget_data_get(obj);
1773 if (!wd) return NULL;
1774 return wd->selected;
1777 EAPI Elm_Object_Item *
1778 elm_list_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1780 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1781 Widget_Data *wd = elm_widget_data_get(obj);
1782 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1784 wd->items = eina_list_append(wd->items, it);
1785 it->node = eina_list_last(wd->items);
1786 elm_box_pack_end(wd->box, VIEW(it));
1787 return (Elm_Object_Item *)it;
1790 EAPI Elm_Object_Item *
1791 elm_list_item_prepend(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1793 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1794 Widget_Data *wd = elm_widget_data_get(obj);
1795 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1797 wd->items = eina_list_prepend(wd->items, it);
1798 it->node = wd->items;
1799 elm_box_pack_start(wd->box, VIEW(it));
1800 return (Elm_Object_Item *)it;
1803 EAPI Elm_Object_Item *
1804 elm_list_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1806 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1807 ELM_LIST_ITEM_CHECK_DELETED_RETURN(before, NULL);
1810 Elm_List_Item *it, *before_it;
1812 wd = elm_widget_data_get(obj);
1813 if (!wd) return NULL;
1815 before_it = (Elm_List_Item *) before;
1816 if (!before_it->node) return NULL;
1818 it = _item_new(obj, label, icon, end, func, data);
1819 wd->items = eina_list_prepend_relative_list(wd->items, it, before_it->node);
1820 it->node = before_it->node->prev;
1821 elm_box_pack_before(wd->box, VIEW(it), VIEW(before_it));
1822 return (Elm_Object_Item *)it;
1825 EAPI Elm_Object_Item *
1826 elm_list_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1828 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1829 ELM_LIST_ITEM_CHECK_DELETED_RETURN(after, NULL);
1832 Elm_List_Item *it, *after_it;
1834 wd = elm_widget_data_get(obj);
1835 if (!wd) return NULL;
1837 after_it = (Elm_List_Item *) after;
1838 if (!after_it->node) return NULL;
1840 it = _item_new(obj, label, icon, end, func, data);
1841 wd->items = eina_list_append_relative_list(wd->items, it, after_it->node);
1842 it->node = after_it->node->next;
1843 elm_box_pack_after(wd->box, VIEW(it), VIEW(after_it));
1844 return (Elm_Object_Item *)it;
1847 EAPI Elm_Object_Item *
1848 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)
1850 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1851 Widget_Data *wd = elm_widget_data_get(obj);
1852 Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1855 wd->items = eina_list_sorted_insert(wd->items, cmp_func, it);
1856 l = eina_list_data_find_list(wd->items, it);
1857 l = eina_list_next(l);
1860 it->node = eina_list_last(wd->items);
1861 elm_box_pack_end(wd->box, VIEW(it));
1865 Elm_List_Item *before = eina_list_data_get(l);
1866 it->node = before->node->prev;
1867 elm_box_pack_before(wd->box, VIEW(it), VIEW(before));
1869 return (Elm_Object_Item *)it;
1873 elm_list_item_separator_set(Elm_Object_Item *it, Eina_Bool setting)
1875 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1876 ((Elm_List_Item *)it)->is_separator = !!setting;
1880 elm_list_item_separator_get(const Elm_Object_Item *it)
1882 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1883 return ((Elm_List_Item *)it)->is_separator;
1887 elm_list_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1889 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1890 Evas_Object *obj = WIDGET(it);
1891 Widget_Data *wd = elm_widget_data_get(obj);
1892 Elm_List_Item *item = (Elm_List_Item *)it;
1895 selected = !!selected;
1896 if (item->selected == selected) return;
1898 evas_object_ref(obj);
1905 while (wd->selected)
1906 _item_unselect(wd->selected->data);
1908 _item_highlight(item);
1912 _item_unselect(item);
1914 _elm_list_unwalk(wd);
1915 evas_object_unref(obj);
1919 elm_list_item_selected_get(const Elm_Object_Item *it)
1921 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1922 return ((Elm_List_Item *)it)->selected;
1926 elm_list_item_show(Elm_Object_Item *it)
1928 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1929 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1931 Evas_Coord bx, by, bw, bh;
1932 Evas_Coord x, y, w, h;
1934 evas_smart_objects_calculate(evas_object_evas_get(wd->box));
1935 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1936 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1939 if (wd->scr) elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
1943 elm_list_item_bring_in(Elm_Object_Item *it)
1945 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1946 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1948 Evas_Coord bx, by, bw, bh;
1949 Evas_Coord x, y, w, h;
1951 evas_smart_objects_calculate(evas_object_evas_get(wd->box));
1952 evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1953 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1956 if (wd->scr) elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);
1960 elm_list_item_object_get(const Elm_Object_Item *it)
1962 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1966 EAPI Elm_Object_Item *
1967 elm_list_item_prev(const Elm_Object_Item *it)
1969 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1970 Elm_List_Item *item = (Elm_List_Item *)it;
1971 if (item->node->prev) return item->node->prev->data;
1975 EAPI Elm_Object_Item *
1976 elm_list_item_next(const Elm_Object_Item *it)
1978 ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1979 Elm_List_Item *item = (Elm_List_Item *)it;
1980 if (item->node->next) return item->node->next->data;
1984 EAPI Elm_Object_Item *
1985 elm_list_first_item_get(const Evas_Object *obj)
1987 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1988 Widget_Data *wd = elm_widget_data_get(obj);
1989 if (!wd) return NULL;
1990 if (!wd->items) return NULL;
1991 return eina_list_data_get(wd->items);
1994 EAPI Elm_Object_Item *
1995 elm_list_last_item_get(const Evas_Object *obj)
1997 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1998 Widget_Data *wd = elm_widget_data_get(obj);
1999 if (!wd) return NULL;
2000 if (!wd->items) return NULL;
2001 return eina_list_data_get(eina_list_last(wd->items));