Elementary/list - Elm_List_Item -> Elm_Object_Item
[framework/uifw/elementary.git] / src / lib / elm_list.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "els_scroller.h"
4
5 #define SWIPE_MOVES 12
6
7 typedef struct _Widget_Data Widget_Data;
8 typedef struct _Elm_List_Item Elm_List_Item;
9
10 struct _Widget_Data
11 {
12    Evas_Object *scr, *box, *self;
13    Eina_List *items, *selected, *to_delete;
14    Elm_List_Item *last_selected_item;
15    Elm_List_Mode mode;
16    Elm_List_Mode h_mode;
17    Evas_Coord minw[2], minh[2];
18    Eina_Bool scr_minw : 1;
19    Eina_Bool scr_minh : 1;
20    int walking;
21    int movements;
22    struct {
23         Evas_Coord x, y;
24    } history[SWIPE_MOVES];
25    Eina_Bool swipe : 1;
26    Eina_Bool fix_pending : 1;
27    Eina_Bool on_hold : 1;
28    Eina_Bool multi : 1;
29    Eina_Bool always_select : 1;
30    Eina_Bool longpressed : 1;
31    Eina_Bool wasselected : 1;
32 };
33
34 struct _Elm_List_Item
35 {
36    ELM_WIDGET_ITEM;
37    Widget_Data *wd;
38    Eina_List *node;
39    const char *label;
40    Evas_Object *icon, *end;
41    Evas_Smart_Cb func;
42    Ecore_Timer *long_timer;
43    Ecore_Timer *swipe_timer;
44    Eina_Bool deleted : 1;
45    Eina_Bool even : 1;
46    Eina_Bool is_even : 1;
47    Eina_Bool is_separator : 1;
48    Eina_Bool fixed : 1;
49    Eina_Bool selected : 1;
50    Eina_Bool highlighted : 1;
51    Eina_Bool dummy_icon : 1;
52    Eina_Bool dummy_end : 1;
53 };
54
55 static const char *widtype = NULL;
56 static void _del_hook(Evas_Object *obj);
57 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
58 static void _theme_hook(Evas_Object *obj);
59 static void _sizing_eval(Evas_Object *obj);
60 static void _disable_hook(Evas_Object *obj);
61 static void _on_focus_hook(void *data, Evas_Object *obj);
62 static void _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source);
63 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
64 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
65 static void _fix_items(Evas_Object *obj);
66 static void _mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info);
67 static void _mouse_up(void *data, Evas *evas, Evas_Object *obj, void *event_info);
68 static void _mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info);
69 static void _edge_left(void *data, Evas_Object *scr, void *event_info);
70 static void _edge_right(void *data, Evas_Object *scr, void *event_info);
71 static void _edge_top(void *data, Evas_Object *scr, void *event_info);
72 static void _edge_bottom(void *data, Evas_Object *scr, void *event_info);
73 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
74 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
75 static Eina_Bool _item_single_select_up(Widget_Data *wd);
76 static Eina_Bool _item_single_select_down(Widget_Data *wd);
77 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
78                              Evas_Callback_Type type, void *event_info);
79 static Eina_Bool _deselect_all_items(Widget_Data *wd);
80
81 static const char SIG_ACTIVATED[] = "activated";
82 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
83 static const char SIG_SELECTED[] = "selected";
84 static const char SIG_UNSELECTED[] = "unselected";
85 static const char SIG_LONGPRESSED[] = "longpressed";
86 static const char SIG_EDGE_TOP[] = "edge,top";
87 static const char SIG_EDGE_BOTTOM[] = "edge,bottom";
88 static const char SIG_EDGE_LEFT[] = "edge,left";
89 static const char SIG_EDGE_RIGHT[] = "edge,right";
90
91 static const Evas_Smart_Cb_Description _signals[] = {
92    {SIG_ACTIVATED, ""},
93    {SIG_CLICKED_DOUBLE, ""},
94    {SIG_SELECTED, ""},
95    {SIG_UNSELECTED, ""},
96    {SIG_LONGPRESSED, ""},
97    {SIG_EDGE_TOP, ""},
98    {SIG_EDGE_BOTTOM, ""},
99    {SIG_EDGE_LEFT, ""},
100    {SIG_EDGE_RIGHT, ""},
101    {NULL, NULL}
102 };
103
104 #define ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ...)                      \
105    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, __VA_ARGS__);                        \
106 if (((Elm_List_Item *) it)->deleted)                                     \
107 {                                                                        \
108    ERR("ERROR: "#it" has been DELETED.\n");                              \
109    return __VA_ARGS__;                                                   \
110 }
111
112 static inline void
113 _elm_list_item_free(Elm_List_Item *it)
114 {
115    evas_object_event_callback_del_full
116       (VIEW(it), EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, it);
117    evas_object_event_callback_del_full
118       (VIEW(it), EVAS_CALLBACK_MOUSE_UP, _mouse_up, it);
119    evas_object_event_callback_del_full
120       (VIEW(it), EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, it);
121
122    if (it->icon)
123      evas_object_event_callback_del_full
124         (it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
125          _changed_size_hints, WIDGET(it));
126
127    if (it->end)
128      evas_object_event_callback_del_full
129         (it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
130          _changed_size_hints, WIDGET(it));
131
132    eina_stringshare_del(it->label);
133
134    if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
135    if (it->long_timer) ecore_timer_del(it->long_timer);
136    if (it->icon) evas_object_del(it->icon);
137    if (it->end) evas_object_del(it->end);
138
139    elm_widget_item_del(it);
140 }
141
142 static Eina_Bool
143 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
144 {
145    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
146    Evas_Event_Key_Down *ev = event_info;
147    Widget_Data *wd = elm_widget_data_get(obj);
148    if (!wd) return EINA_FALSE;
149    if (!wd->items) return EINA_FALSE;
150    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
151    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
152
153    Elm_List_Item *it = NULL;
154    Evas_Coord x = 0;
155    Evas_Coord y = 0;
156    Evas_Coord step_x = 0;
157    Evas_Coord step_y = 0;
158    Evas_Coord v_w = 0;
159    Evas_Coord v_h = 0;
160    Evas_Coord page_x = 0;
161    Evas_Coord page_y = 0;
162
163    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
164    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
165    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
166    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
167
168    /* TODO: fix logic for horizontal mode */
169    if ((!strcmp(ev->keyname, "Left")) ||
170        (!strcmp(ev->keyname, "KP_Left")))
171      {
172         if ((wd->h_mode) &&
173             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
174               (_item_multi_select_up(wd)))
175              || (_item_single_select_up(wd))))
176           {
177              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
178              return EINA_TRUE;
179           }
180         else
181           x -= step_x;
182      }
183    else if ((!strcmp(ev->keyname, "Right")) ||
184             (!strcmp(ev->keyname, "KP_Right")))
185      {
186         if ((wd->h_mode) &&
187             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
188               (_item_multi_select_down(wd)))
189              || (_item_single_select_down(wd))))
190           {
191              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
192              return EINA_TRUE;
193           }
194         else
195           x += step_x;
196      }
197    else if ((!strcmp(ev->keyname, "Up"))  ||
198             (!strcmp(ev->keyname, "KP_Up")))
199      {
200         if ((!wd->h_mode) &&
201             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
202               (_item_multi_select_up(wd)))
203              || (_item_single_select_up(wd))))
204           {
205              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
206              return EINA_TRUE;
207           }
208         else
209           y -= step_y;
210      }
211    else if ((!strcmp(ev->keyname, "Down")) ||
212             (!strcmp(ev->keyname, "KP_Down")))
213      {
214         if ((!wd->h_mode) &&
215             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
216               (_item_multi_select_down(wd)))
217              || (_item_single_select_down(wd))))
218           {
219              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
220              return EINA_TRUE;
221           }
222         else
223           y += step_y;
224      }
225    else if ((!strcmp(ev->keyname, "Home")) ||
226             (!strcmp(ev->keyname, "KP_Home")))
227      {
228         it = eina_list_data_get(wd->items);
229         elm_list_item_bring_in((Elm_Object_Item *) it);
230         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
231         return EINA_TRUE;
232      }
233    else if ((!strcmp(ev->keyname, "End")) ||
234             (!strcmp(ev->keyname, "KP_End")))
235      {
236         it = eina_list_data_get(eina_list_last(wd->items));
237         elm_list_item_bring_in((Elm_Object_Item *) it);
238         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
239         return EINA_TRUE;
240      }
241    else if ((!strcmp(ev->keyname, "Prior")) ||
242             (!strcmp(ev->keyname, "KP_Prior")))
243      {
244         if (wd->h_mode)
245           {
246              if (page_x < 0)
247                x -= -(page_x * v_w) / 100;
248              else
249                x -= page_x;
250           }
251         else
252           {
253              if (page_y < 0)
254                y -= -(page_y * v_h) / 100;
255              else
256                y -= page_y;
257           }
258      }
259    else if ((!strcmp(ev->keyname, "Next")) ||
260             (!strcmp(ev->keyname, "KP_Next")))
261      {
262         if (wd->h_mode)
263           {
264              if (page_x < 0)
265                x += -(page_x * v_w) / 100;
266              else
267                x += page_x;
268           }
269         else
270           {
271              if (page_y < 0)
272                y += -(page_y * v_h) / 100;
273              else
274                y += page_y;
275           }
276      }
277    else if (((!strcmp(ev->keyname, "Return")) ||
278             (!strcmp(ev->keyname, "KP_Enter")) ||
279             (!strcmp(ev->keyname, "space")))
280            && (!wd->multi) && (wd->selected))
281      {
282         it = (Elm_List_Item *) elm_list_selected_item_get(obj);
283         evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it);
284      }
285    else if (!strcmp(ev->keyname, "Escape"))
286      {
287         if (!_deselect_all_items(wd)) return EINA_FALSE;
288         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
289         return EINA_TRUE;
290      }
291    else return EINA_FALSE;
292
293    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
294    elm_smart_scroller_child_pos_set(wd->scr, x, y);
295    return EINA_TRUE;
296 }
297
298 static void
299 _translate_hook(Evas_Object *obj)
300 {
301    evas_object_smart_callback_call(obj, "language,changed", NULL);
302 }
303
304 static Eina_Bool
305 _deselect_all_items(Widget_Data *wd)
306 {
307    if (!wd->selected) return EINA_FALSE;
308    while (wd->selected)
309      elm_list_item_selected_set((Elm_Object_Item *) wd->selected->data,
310                                 EINA_FALSE);
311
312    return EINA_TRUE;
313 }
314
315 static Eina_Bool
316 _item_multi_select_up(Widget_Data *wd)
317 {
318    if (!wd->selected) return EINA_FALSE;
319    if (!wd->multi) return EINA_FALSE;
320
321    Elm_Object_Item *prev = elm_list_item_prev((Elm_Object_Item *) wd->last_selected_item);
322    if (!prev) return EINA_TRUE;
323
324    if (elm_list_item_selected_get(prev))
325      {
326         elm_list_item_selected_set((Elm_Object_Item *) wd->last_selected_item,
327                                    EINA_FALSE);
328         wd->last_selected_item = (Elm_List_Item *) prev;
329         elm_list_item_show((Elm_Object_Item *) wd->last_selected_item);
330      }
331    else
332      {
333         elm_list_item_selected_set(prev, EINA_TRUE);
334         elm_list_item_show(prev);
335      }
336    return EINA_TRUE;
337 }
338
339 static Eina_Bool
340 _item_multi_select_down(Widget_Data *wd)
341 {
342    if (!wd->selected) return EINA_FALSE;
343    if (!wd->multi) return EINA_FALSE;
344
345    Elm_Object_Item *next = elm_list_item_next((Elm_Object_Item *) wd->last_selected_item);
346    if (!next) return EINA_TRUE;
347
348    if (elm_list_item_selected_get(next))
349      {
350         elm_list_item_selected_set((Elm_Object_Item *) wd->last_selected_item,
351                                    EINA_FALSE);
352         wd->last_selected_item = (Elm_List_Item *) next;
353         elm_list_item_show((Elm_Object_Item *) wd->last_selected_item);
354      }
355    else
356      {
357         elm_list_item_selected_set(next, EINA_TRUE);
358         elm_list_item_show(next);
359      }
360    return EINA_TRUE;
361 }
362
363 static Eina_Bool
364 _item_single_select_up(Widget_Data *wd)
365 {
366    Elm_Object_Item *prev;
367
368    if (!wd->selected) prev = eina_list_data_get(eina_list_last(wd->items));
369    else prev = elm_list_item_prev((Elm_Object_Item *) wd->last_selected_item);
370    if (!prev) return EINA_FALSE;
371
372    _deselect_all_items(wd);
373
374    elm_list_item_selected_set(prev, EINA_TRUE);
375    elm_list_item_show(prev);
376    return EINA_TRUE;
377 }
378
379 static Eina_Bool
380 _item_single_select_down(Widget_Data *wd)
381 {
382    Elm_Object_Item *next;
383
384    if (!wd->selected) next = eina_list_data_get(wd->items);
385    else next = elm_list_item_next((Elm_Object_Item *) wd->last_selected_item);
386    if (!next) return EINA_FALSE;
387
388    _deselect_all_items(wd);
389
390    elm_list_item_selected_set(next, EINA_TRUE);
391    elm_list_item_show(next);
392    return EINA_TRUE;
393 }
394
395 static void
396 _elm_list_process_deletions(Widget_Data *wd)
397 {
398    Elm_List_Item *it;
399
400    wd->walking++; // avoid nested deletion and also _sub_del() fix_items
401
402    EINA_LIST_FREE(wd->to_delete, it)
403      {
404         elm_widget_item_pre_notify_del(it);
405
406         wd->items = eina_list_remove_list(wd->items, it->node);
407         _elm_list_item_free(it);
408      }
409
410    wd->walking--;
411 }
412
413 static inline void
414 _elm_list_walk(Widget_Data *wd)
415 {
416    if (wd->walking < 0)
417      {
418         ERR("ERROR: walking was negative. fixed!\n");
419         wd->walking = 0;
420      }
421    wd->walking++;
422 }
423
424 static inline void
425 _elm_list_unwalk(Widget_Data *wd)
426 {
427    wd->walking--;
428    if (wd->walking < 0)
429      {
430         ERR("ERROR: walking became negative. fixed!\n");
431         wd->walking = 0;
432      }
433
434    if (wd->walking)
435      return;
436
437    if (wd->to_delete)
438      _elm_list_process_deletions(wd);
439
440    if (wd->fix_pending)
441      {
442         wd->fix_pending = EINA_FALSE;
443         _fix_items(wd->self);
444         _sizing_eval(wd->self);
445      }
446 }
447
448 static void
449 _del_pre_hook(Evas_Object *obj)
450 {
451    Widget_Data *wd = elm_widget_data_get(obj);
452    if (!wd) return;
453
454    evas_object_event_callback_del(wd->scr,
455                                   EVAS_CALLBACK_CHANGED_SIZE_HINTS,
456                                   _changed_size_hints);
457    evas_object_event_callback_del(wd->box,
458                                   EVAS_CALLBACK_CHANGED_SIZE_HINTS,
459                                   _changed_size_hints);
460 }
461
462 static void
463 _del_hook(Evas_Object *obj)
464 {
465    Widget_Data *wd = elm_widget_data_get(obj);
466    Elm_List_Item *it;
467    Eina_List *n;
468
469    if (!wd) return;
470    if (wd->walking)
471      ERR("ERROR: list deleted while walking.\n");
472
473    _elm_list_walk(wd);
474    EINA_LIST_FOREACH(wd->items, n, it) elm_widget_item_pre_notify_del(it);
475    _elm_list_unwalk(wd);
476    if (wd->to_delete)
477      ERR("ERROR: leaking nodes!\n");
478
479    EINA_LIST_FREE(wd->items, it) _elm_list_item_free(it);
480    eina_list_free(wd->selected);
481    free(wd);
482 }
483
484 static void
485 _show_region_hook(void *data, Evas_Object *obj)
486 {
487    Widget_Data *wd = elm_widget_data_get(data);
488    Evas_Coord x, y, w, h;
489    if (!wd) return;
490    elm_widget_show_region_get(obj, &x, &y, &w, &h);
491    elm_smart_scroller_child_region_set(wd->scr, x, y, w, h);
492 }
493
494 static void
495 _disable_hook(Evas_Object *obj)
496 {
497    Widget_Data *wd = elm_widget_data_get(obj);
498    if (!wd) return;
499    if (elm_widget_disabled_get(obj))
500      {
501         _signal_emit_hook(obj, "elm,state,disabled", "elm");
502         elm_widget_scroll_freeze_push(obj);
503         elm_widget_scroll_hold_push(obj);
504         /* FIXME: if we get to have a way to only un-highlight items
505          * in the future, keeping them selected... */
506         _deselect_all_items(wd);
507      }
508    else
509      {
510         _signal_emit_hook(obj, "elm,state,enabled", "elm");
511         elm_widget_scroll_freeze_pop(obj);
512         elm_widget_scroll_hold_pop(obj);
513      }
514 }
515
516 static void
517 _sizing_eval(Evas_Object *obj)
518 {
519
520    Widget_Data *wd = elm_widget_data_get(obj);
521    if (!wd) return;
522    Evas_Coord  vw, vh, minw, minh, maxw, maxh, w, h, vmw, vmh;
523    double xw, yw;
524
525    evas_object_size_hint_min_get(wd->box, &minw, &minh);
526    evas_object_size_hint_max_get(wd->box, &maxw, &maxh);
527    evas_object_size_hint_weight_get(wd->box, &xw, &yw);
528    if (!wd->scr) return;
529    elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
530    if (xw > 0.0)
531      {
532         if ((minw > 0) && (vw < minw)) vw = minw;
533         else if ((maxw > 0) && (vw > maxw)) vw = maxw;
534      }
535    else if (minw > 0) vw = minw;
536    if (yw > 0.0)
537      {
538         if ((minh > 0) && (vh < minh)) vh = minh;
539         else if ((maxh > 0) && (vh > maxh)) vh = maxh;
540      }
541    else if (minh > 0) vh = minh;
542    evas_object_resize(wd->box, vw, vh);
543    w = -1;
544    h = -1;
545    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
546                              &vmw, &vmh);
547    if (wd->scr_minw) w = vmw + minw;
548    if (wd->scr_minh) h = vmh + minh;
549
550    evas_object_size_hint_max_get(obj, &maxw, &maxh);
551    if ((maxw > 0) && (w > maxw))
552      w = maxw;
553    if ((maxh > 0) && (h > maxh))
554      h = maxh;
555
556    evas_object_size_hint_min_set(obj, w, h);
557 }
558
559 static void
560 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
561 {
562    Widget_Data *wd = elm_widget_data_get(obj);
563    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
564                            emission, source);
565 }
566
567 static void
568 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
569 {
570    Widget_Data *wd = elm_widget_data_get(obj);
571    edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
572                                    emission, source, func_cb, data);
573 }
574
575 static void
576 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
577 {
578    Widget_Data *wd = elm_widget_data_get(obj);
579    edje_object_signal_callback_del_full(
580       elm_smart_scroller_edje_object_get(wd->scr),
581       emission, source, func_cb, data);
582 }
583
584 static void
585 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
586 {
587    Widget_Data *wd = elm_widget_data_get(obj);
588    Elm_List_Item *it;
589    Eina_List *n;
590
591    if (!wd) return;
592    if (wd->scr)
593      elm_smart_scroller_mirrored_set(wd->scr, rtl);
594
595    EINA_LIST_FOREACH(wd->items, n, it)
596       edje_object_mirrored_set(VIEW(it), rtl);
597 }
598
599 static void
600 _theme_hook(Evas_Object *obj)
601 {
602    Widget_Data *wd = elm_widget_data_get(obj);
603    Elm_List_Item *it;
604    Eina_List *n;
605
606    if (!wd) return;
607    _elm_widget_mirrored_reload(obj);
608    _mirrored_set(obj, elm_widget_mirrored_get(obj));
609
610    if (wd->scr)
611      {
612         Evas_Object *edj;
613         const char *str;
614
615         elm_smart_scroller_object_theme_set(obj, wd->scr, "list", "base",
616                                             elm_widget_style_get(obj));
617         //        edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
618         edj = elm_smart_scroller_edje_object_get(wd->scr);
619         str = edje_object_data_get(edj, "focus_highlight");
620         if ((str) && (!strcmp(str, "on")))
621           elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
622         else
623           elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
624         elm_object_style_set(wd->scr, elm_widget_style_get(obj));
625      }
626    EINA_LIST_FOREACH(wd->items, n, it)
627      {
628         edje_object_scale_set(VIEW(it), elm_widget_scale_get(obj) * _elm_config->scale);
629         it->fixed = 0;
630      }
631    _fix_items(obj);
632    _sizing_eval(obj);
633 }
634
635 static void
636 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
637 {
638    Widget_Data *wd = elm_widget_data_get(obj);
639    if (!wd) return;
640    if (elm_widget_focus_get(obj))
641      {
642         edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
643         evas_object_focus_set(wd->self, EINA_TRUE);
644
645         if ((wd->selected) && (!wd->last_selected_item))
646           wd->last_selected_item = eina_list_data_get(wd->selected);
647      }
648    else
649      {
650         edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
651         evas_object_focus_set(wd->self, EINA_FALSE);
652      }
653 }
654
655 static void
656 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
657 {
658    Widget_Data *wd = elm_widget_data_get(data);
659    if (!wd) return;
660    _fix_items(data);
661    _sizing_eval(data);
662 }
663
664 static void
665 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
666 {
667    Widget_Data *wd = elm_widget_data_get(obj);
668    Evas_Object *sub = event_info;
669    const Eina_List *l;
670    Elm_List_Item *it;
671
672    if (!wd) return;
673    if (!sub) abort();
674    if ((sub == wd->box) || (sub == wd->scr)) return;
675
676    EINA_LIST_FOREACH(wd->items, l, it)
677      {
678         if ((sub == it->icon) || (sub == it->end))
679           {
680              if (it->icon == sub) it->icon = NULL;
681              if (it->end == sub) it->end = NULL;
682              evas_object_event_callback_del_full
683              (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints,
684               obj);
685              if (!wd->walking)
686                {
687                   _fix_items(obj);
688                   _sizing_eval(obj);
689                }
690              else
691                wd->fix_pending = EINA_TRUE;
692              break;
693           }
694      }
695 }
696
697 static void
698 _item_highlight(Elm_List_Item *it)
699 {
700    Evas_Object *obj = WIDGET(it);
701    Widget_Data *wd = elm_widget_data_get(obj);
702    const char *selectraise;
703
704    if (!wd) return;
705    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
706    if ((it->highlighted) || (it->base.disabled)) return;
707
708    evas_object_ref(obj);
709    _elm_list_walk(wd);
710
711    edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
712    selectraise = edje_object_data_get(VIEW(it), "selectraise");
713    if ((selectraise) && (!strcmp(selectraise, "on")))
714      evas_object_raise(VIEW(it));
715    it->highlighted = EINA_TRUE;
716
717    _elm_list_unwalk(wd);
718    evas_object_unref(obj);
719 }
720
721 static void
722 _item_select(Elm_List_Item *it)
723 {
724    Evas_Object *obj = WIDGET(it);
725    Widget_Data *wd = elm_widget_data_get(obj);
726
727    if (!wd) return;
728    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
729    if (it->base.disabled) return;
730    if (it->selected)
731      {
732         if (wd->always_select) goto call;
733         return;
734      }
735    it->selected = EINA_TRUE;
736    wd->selected = eina_list_append(wd->selected, it);
737
738 call:
739    evas_object_ref(obj);
740    _elm_list_walk(wd);
741
742    if (it->func) it->func((void *)it->base.data, WIDGET(it), it);
743    evas_object_smart_callback_call(obj, SIG_SELECTED, it);
744    it->wd->last_selected_item = it;
745
746    _elm_list_unwalk(wd);
747    evas_object_unref(obj);
748 }
749
750 static void
751 _item_unselect(Elm_List_Item *it)
752 {
753    Evas_Object *obj = WIDGET(it);
754    Widget_Data *wd = elm_widget_data_get(obj);
755    const char *stacking, *selectraise;
756
757    if (!wd) return;
758    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
759    if (!it->highlighted) return;
760
761    evas_object_ref(obj);
762    _elm_list_walk(wd);
763
764    edje_object_signal_emit(VIEW(it), "elm,state,unselected", "elm");
765    stacking = edje_object_data_get(VIEW(it), "stacking");
766    selectraise = edje_object_data_get(VIEW(it), "selectraise");
767    if ((selectraise) && (!strcmp(selectraise, "on")))
768      {
769         if ((stacking) && (!strcmp(stacking, "below")))
770           evas_object_lower(VIEW(it));
771      }
772    it->highlighted = EINA_FALSE;
773    if (it->selected)
774      {
775         it->selected = EINA_FALSE;
776         wd->selected = eina_list_remove(wd->selected, it);
777         evas_object_smart_callback_call(WIDGET(it), SIG_UNSELECTED, it);
778      }
779
780    _elm_list_unwalk(wd);
781    evas_object_unref(obj);
782 }
783
784 static Eina_Bool
785 _swipe_cancel(void *data)
786 {
787    Elm_List_Item *it = data;
788    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
789
790    if (!wd) return ECORE_CALLBACK_CANCEL;
791    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
792    wd->swipe = EINA_FALSE;
793    wd->movements = 0;
794    return ECORE_CALLBACK_RENEW;
795 }
796
797 static void
798 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
799 {
800    Elm_List_Item *it = data;
801    Evas_Object *obj2 = WIDGET(it);
802    Widget_Data *wd = elm_widget_data_get(obj2);
803    Evas_Event_Mouse_Move *ev = event_info;
804
805    if (!wd) return;
806    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
807
808    evas_object_ref(obj2);
809    _elm_list_walk(wd);
810
811    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
812      {
813         if (!wd->on_hold)
814           {
815              wd->on_hold = EINA_TRUE;
816              if (it->long_timer)
817                {
818                   ecore_timer_del(it->long_timer);
819                   it->long_timer = NULL;
820                }
821              if (!wd->wasselected)
822                _item_unselect(it);
823           }
824         if (wd->movements == SWIPE_MOVES) wd->swipe = EINA_TRUE;
825         else
826           {
827              wd->history[wd->movements].x = ev->cur.canvas.x;
828              wd->history[wd->movements].y = ev->cur.canvas.y;
829              if (abs((wd->history[wd->movements].x - wd->history[0].x)) > 40)
830                wd->swipe = EINA_TRUE;
831              else
832                wd->movements++;
833           }
834      }
835
836    _elm_list_unwalk(wd);
837    evas_object_unref(obj2);
838 }
839
840 static void
841 _edge_left(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
842 {
843    Evas_Object *obj = data;
844    evas_object_smart_callback_call(obj, SIG_EDGE_LEFT, NULL);
845 }
846
847 static void
848 _edge_right(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
849 {
850    Evas_Object *obj = data;
851    evas_object_smart_callback_call(obj, SIG_EDGE_RIGHT, NULL);
852 }
853
854 static void
855 _edge_top(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
856 {
857    Evas_Object *obj = data;
858    evas_object_smart_callback_call(obj, SIG_EDGE_TOP, NULL);
859 }
860
861 static void
862 _edge_bottom(void *data, Evas_Object *scr __UNUSED__, void *event_info __UNUSED__)
863 {
864    Evas_Object *obj = data;
865    evas_object_smart_callback_call(obj, SIG_EDGE_BOTTOM, NULL);
866 }
867
868 static Eina_Bool
869 _long_press(void *data)
870 {
871    Elm_List_Item *it = data;
872    Evas_Object *obj = WIDGET(it);
873    Widget_Data *wd = elm_widget_data_get(obj);
874
875    if (!wd) goto end;
876
877    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, ECORE_CALLBACK_CANCEL);
878    it->long_timer = NULL;
879    if (it->base.disabled) goto end;
880
881    wd->longpressed = EINA_TRUE;
882    evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
883
884 end:
885    return ECORE_CALLBACK_CANCEL;
886 }
887
888 static void
889 _swipe(Elm_List_Item *it)
890 {
891    int i, sum = 0;
892    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
893
894    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
895    if (!wd) return;
896    wd->swipe = EINA_FALSE;
897    for (i = 0; i < wd->movements; i++)
898      {
899         sum += wd->history[i].x;
900         if (abs(wd->history[0].y - wd->history[i].y) > 10) return;
901      }
902
903    sum /= wd->movements;
904    if (abs(sum - wd->history[0].x) <= 10) return;
905    evas_object_smart_callback_call(WIDGET(it), "swipe", it);
906 }
907
908 static void
909 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
910 {
911    Elm_List_Item *it = data;
912    Evas_Object *obj2 = WIDGET(it);
913    Widget_Data *wd = elm_widget_data_get(obj2);
914    Evas_Event_Mouse_Down *ev = event_info;
915
916    if (!wd) return;
917    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
918    if (ev->button != 1) return;
919    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
920    else wd->on_hold = EINA_FALSE;
921    if (wd->on_hold) return;
922    wd->wasselected = it->selected;
923
924    evas_object_ref(obj2);
925    _elm_list_walk(wd);
926
927    _item_highlight(it);
928    wd->longpressed = EINA_FALSE;
929    if (it->long_timer) ecore_timer_del(it->long_timer);
930    it->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, it);
931    if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
932    it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
933    /* Always call the callbacks last - the user may delete our context! */
934    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
935      {
936         evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
937         evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it);
938      }
939    wd->swipe = EINA_FALSE;
940    wd->movements = 0;
941
942    _elm_list_unwalk(wd);
943    evas_object_unref(obj2);
944 }
945
946 static void
947 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
948 {
949    Elm_List_Item *it = data;
950    Evas_Object *obj2 = WIDGET(it);
951    Widget_Data *wd = elm_widget_data_get(obj2);
952    Evas_Event_Mouse_Up *ev = event_info;
953
954    if (!wd) return;
955    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
956    if (ev->button != 1) return;
957    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
958    else wd->on_hold = EINA_FALSE;
959    wd->longpressed = EINA_FALSE;
960    if (it->long_timer)
961      {
962         ecore_timer_del(it->long_timer);
963         it->long_timer = NULL;
964      }
965    if (it->swipe_timer)
966      {
967         ecore_timer_del(it->swipe_timer);
968         it->swipe_timer = NULL;
969      }
970    if (wd->on_hold)
971      {
972         if (wd->swipe) _swipe(data);
973         wd->on_hold = EINA_FALSE;
974         return;
975      }
976    if (wd->longpressed)
977      {
978         if (!wd->wasselected) _item_unselect(it);
979         wd->wasselected = 0;
980         return;
981      }
982
983    if (it->base.disabled)
984      return;
985    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
986
987    evas_object_ref(obj2);
988    _elm_list_walk(wd);
989
990    if (wd->multi)
991      {
992         if (!it->selected)
993           {
994              _item_highlight(it);
995              _item_select(it);
996           }
997         else _item_unselect(it);
998      }
999    else
1000      {
1001         if (!it->selected)
1002           {
1003              while (wd->selected)
1004                _item_unselect(wd->selected->data);
1005              _item_highlight(it);
1006              _item_select(it);
1007           }
1008         else
1009           {
1010              const Eina_List *l, *l_next;
1011              Elm_List_Item *it2;
1012
1013              EINA_LIST_FOREACH_SAFE(wd->selected, l, l_next, it2)
1014                 if (it2 != it) _item_unselect(it2);
1015              _item_highlight(it);
1016              _item_select(it);
1017           }
1018      }
1019
1020    _elm_list_unwalk(wd);
1021    evas_object_unref(obj2);
1022 }
1023
1024 static void
1025 _item_disable(void *data)
1026 {
1027    Elm_List_Item *it = data;
1028    if (it->base.disabled)
1029      edje_object_signal_emit(VIEW(it), "elm,state,disabled", "elm");
1030    else
1031      edje_object_signal_emit(VIEW(it), "elm,state,enabled", "elm");
1032 }
1033
1034 static void
1035 _item_content_set(void *data, const char *part, Evas_Object *content)
1036 {
1037    Elm_List_Item *it = data;
1038    Evas_Object **icon_p = NULL;
1039    Eina_Bool dummy = EINA_FALSE;
1040    
1041    if ((!part) || (!strcmp(part, "start")))
1042      {
1043         icon_p = &(it->icon);
1044         dummy = it->dummy_icon;
1045         if (!content) it->dummy_icon = EINA_FALSE;
1046         else it->dummy_icon = EINA_TRUE;
1047      }
1048    else if (!strcmp(part, "end"))
1049      {
1050         icon_p = &(it->end);
1051         dummy = it->dummy_end;
1052         if (!content) it->dummy_end = EINA_FALSE;
1053         else it->dummy_end = EINA_TRUE;
1054      }
1055    else
1056      return;
1057         
1058    if (content == *icon_p) return;
1059    if ((dummy) && (!content)) return;
1060    if (dummy) evas_object_del(*icon_p);
1061    if (!content)
1062      {
1063         content = evas_object_rectangle_add(evas_object_evas_get(WIDGET(it)));
1064         evas_object_color_set(content, 0, 0, 0, 0);
1065      }
1066    if (*icon_p)
1067      {
1068         evas_object_del(*icon_p);
1069         *icon_p = NULL;
1070      }
1071    *icon_p = content;
1072    if (VIEW(it))
1073      edje_object_part_swallow(VIEW(it), "elm.swallow.icon", content);
1074 }
1075
1076 static Evas_Object *
1077 _item_content_get(const void *data, const char *part)
1078 {
1079    Elm_List_Item *it = (Elm_List_Item *)data;
1080
1081    if ((!part) || (!strcmp(part, "start")))
1082      {
1083         if (it->dummy_icon) return NULL;
1084         return it->icon;
1085      }
1086    else if (!strcmp(part, "end"))
1087      {
1088         if (it->dummy_end) return NULL;
1089         return it->end;
1090      }
1091    return NULL;
1092 }
1093
1094 static Evas_Object *
1095 _item_content_unset(const void *data, const char *part)
1096 {
1097    Elm_List_Item *it = (Elm_List_Item *)data;
1098
1099    if ((!part) || (!strcmp(part, "start")))
1100      {
1101         Evas_Object *obj = it->icon;
1102         _item_content_set((void *)data, part, NULL);
1103         return obj;
1104      }
1105    else if (!strcmp(part, "end"))
1106      {
1107         Evas_Object *obj = it->end;
1108         _item_content_set((void *)data, part, NULL);
1109         return obj;
1110      }
1111    return NULL;
1112 }
1113
1114 static void
1115 _item_text_set(void *data, const char *part __UNUSED__, const char *text)
1116 {
1117    Elm_List_Item *it = data;
1118
1119    if (!eina_stringshare_replace(&it->label, text)) return;
1120    if (VIEW(it))
1121      edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1122 }
1123
1124 static const char *
1125 _item_text_get(const void *data, const char *part __UNUSED__)
1126 {
1127    Elm_List_Item *it = (Elm_List_Item *)data;
1128
1129    return it->label;
1130 }
1131
1132 static Elm_List_Item *
1133 _item_new(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1134 {
1135    Widget_Data *wd = elm_widget_data_get(obj);
1136    Elm_List_Item *it;
1137
1138    if (!wd) return NULL;
1139    it = elm_widget_item_new(obj, Elm_List_Item);
1140    it->wd = wd;
1141    it->label = eina_stringshare_add(label);
1142    it->icon = icon;
1143    it->end = end;
1144    it->func = func;
1145    it->base.data = data;
1146    VIEW(it) = edje_object_add(evas_object_evas_get(obj));
1147    edje_object_mirrored_set(VIEW(it), elm_widget_mirrored_get(obj));
1148    evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
1149                                   _mouse_down, it);
1150    evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
1151                                   _mouse_up, it);
1152    evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1153                                   _mouse_move, it);
1154    evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1155    evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
1156    if (it->icon)
1157      {
1158         elm_widget_sub_object_add(obj, it->icon);
1159         evas_object_event_callback_add(it->icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1160                                        _changed_size_hints, obj);
1161      }
1162    if (it->end)
1163      {
1164         elm_widget_sub_object_add(obj, it->end);
1165         evas_object_event_callback_add(it->end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1166                                        _changed_size_hints, obj);
1167      }
1168    _elm_widget_item_disable_hook_set((Elm_Widget_Item *)it, _item_disable);
1169    _elm_widget_item_content_set_hook_set((Elm_Widget_Item *)it, _item_content_set);
1170    _elm_widget_item_content_get_hook_set((Elm_Widget_Item *)it, _item_content_get);
1171    _elm_widget_item_content_unset_hook_set((Elm_Widget_Item *)it, _item_content_unset);
1172    _elm_widget_item_text_set_hook_set((Elm_Widget_Item *)it, _item_text_set);
1173    _elm_widget_item_text_get_hook_set((Elm_Widget_Item *)it, _item_text_get);
1174    return it;
1175 }
1176
1177 static void
1178 _elm_list_mode_set_internal(Widget_Data *wd)
1179 {
1180    if (!wd->scr)
1181      return;
1182
1183    if (wd->mode == ELM_LIST_LIMIT)
1184      {
1185         if (!wd->h_mode)
1186           {
1187              wd->scr_minw = EINA_TRUE;
1188              wd->scr_minh = EINA_FALSE;
1189           }
1190         else
1191           {
1192              wd->scr_minw = EINA_FALSE;
1193              wd->scr_minh = EINA_TRUE;
1194           }
1195      }
1196    else if (wd->mode == ELM_LIST_EXPAND)
1197      {
1198         wd->scr_minw = EINA_TRUE;
1199         wd->scr_minh = EINA_TRUE;
1200      }
1201    else
1202      {
1203         wd->scr_minw = EINA_FALSE;
1204         wd->scr_minh = EINA_FALSE;
1205      }
1206
1207    _sizing_eval(wd->self);
1208 }
1209
1210 static void
1211 _fix_items(Evas_Object *obj)
1212 {
1213    Widget_Data *wd = elm_widget_data_get(obj);
1214    if (!wd) return;
1215    const Eina_List *l;
1216    Elm_List_Item *it;
1217    Evas_Coord minw[2] = { 0, 0 }, minh[2] = { 0, 0 };
1218    Evas_Coord mw, mh;
1219    int i, redo = 0;
1220    const char *style = elm_widget_style_get(obj);
1221    const char *it_plain = wd->h_mode ? "h_item" : "item";
1222    const char *it_odd = wd->h_mode ? "h_item_odd" : "item_odd";
1223    const char *it_compress = wd->h_mode ? "h_item_compress" : "item_compress";
1224    const char *it_compress_odd = wd->h_mode ? "h_item_compress_odd" : "item_compress_odd";
1225
1226    if (wd->walking)
1227      {
1228         wd->fix_pending = EINA_TRUE;
1229         return;
1230      }
1231
1232    evas_object_ref(obj);
1233    _elm_list_walk(wd); // watch out "return" before unwalk!
1234
1235    EINA_LIST_FOREACH(wd->items, l, it)
1236      {
1237         if (it->deleted) continue;
1238         if (it->icon)
1239           {
1240              evas_object_size_hint_min_get(it->icon, &mw, &mh);
1241              if (mw > minw[0]) minw[0] = mw;
1242              if (mh > minh[0]) minh[0] = mh;
1243           }
1244         if (it->end)
1245           {
1246              evas_object_size_hint_min_get(it->end, &mw, &mh);
1247              if (mw > minw[1]) minw[1] = mw;
1248              if (mh > minh[1]) minh[1] = mh;
1249           }
1250      }
1251
1252    if ((minw[0] != wd->minw[0]) || (minw[1] != wd->minw[1]) ||
1253        (minw[0] != wd->minh[0]) || (minh[1] != wd->minh[1]))
1254      {
1255         wd->minw[0] = minw[0];
1256         wd->minw[1] = minw[1];
1257         wd->minh[0] = minh[0];
1258         wd->minh[1] = minh[1];
1259         redo = 1;
1260      }
1261    i = 0;
1262    EINA_LIST_FOREACH(wd->items, l, it)
1263      {
1264         if (it->deleted)
1265           continue;
1266
1267         it->even = i & 0x1;
1268         if ((it->even != it->is_even) || (!it->fixed) || (redo))
1269           {
1270              const char *stacking;
1271
1272              /* FIXME: separators' themes seem to be b0rked */
1273              if (it->is_separator)
1274                _elm_theme_object_set(obj, VIEW(it), "separator",
1275                                      wd->h_mode ? "horizontal" : "vertical",
1276                                      style);
1277              else if (wd->mode == ELM_LIST_COMPRESS)
1278                {
1279                   if (it->even)
1280                     _elm_theme_object_set(obj, VIEW(it), "list",
1281                                           it_compress, style);
1282                   else
1283                     _elm_theme_object_set(obj, VIEW(it), "list",
1284                                           it_compress_odd, style);
1285                }
1286              else
1287                {
1288                   if (it->even)
1289                     _elm_theme_object_set(obj, VIEW(it), "list", it_plain,
1290                                           style);
1291                   else
1292                     _elm_theme_object_set(obj, VIEW(it), "list", it_odd,
1293                                           style);
1294                }
1295              stacking = edje_object_data_get(VIEW(it), "stacking");
1296              if (stacking)
1297                {
1298                   if (!strcmp(stacking, "below"))
1299                     evas_object_lower(VIEW(it));
1300                   else if (!strcmp(stacking, "above"))
1301                     evas_object_raise(VIEW(it));
1302                }
1303              edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1304
1305              if ((!it->icon) && (minh[0] > 0))
1306                {
1307                   it->icon = evas_object_rectangle_add(evas_object_evas_get(VIEW(it)));
1308                   evas_object_color_set(it->icon, 0, 0, 0, 0);
1309                   it->dummy_icon = EINA_TRUE;
1310                }
1311              if ((!it->end) && (minh[1] > 0))
1312                {
1313                   it->end = evas_object_rectangle_add(evas_object_evas_get(VIEW(it)));
1314                   evas_object_color_set(it->end, 0, 0, 0, 0);
1315                   it->dummy_end = EINA_TRUE;
1316                }
1317              if (it->icon)
1318                {
1319                   evas_object_size_hint_min_set(it->icon, minw[0], minh[0]);
1320                   evas_object_size_hint_max_set(it->icon, 99999, 99999);
1321                   edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
1322                }
1323              if (it->end)
1324                {
1325                   evas_object_size_hint_min_set(it->end, minw[1], minh[1]);
1326                   evas_object_size_hint_max_set(it->end, 99999, 99999);
1327                   edje_object_part_swallow(VIEW(it), "elm.swallow.end", it->end);
1328                }
1329              if (!it->fixed)
1330                {
1331                   // this may call up user and it may modify the list item
1332                   // but we're safe as we're flagged as walking.
1333                   // just don't process further
1334                   edje_object_message_signal_process(VIEW(it));
1335                   if (it->deleted)
1336                     continue;
1337                   mw = mh = -1;
1338                   elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1339                   edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
1340                   elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1341                   evas_object_size_hint_min_set(VIEW(it), mw, mh);
1342                   evas_object_show(VIEW(it));
1343                }
1344              if ((it->selected) || (it->highlighted))
1345                {
1346                   const char *selectraise;
1347
1348                   // this may call up user and it may modify the list item
1349                   // but we're safe as we're flagged as walking.
1350                   // just don't process further
1351                   edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
1352                   if (it->deleted)
1353                     continue;
1354
1355                   selectraise = edje_object_data_get(VIEW(it), "selectraise");
1356                   if ((selectraise) && (!strcmp(selectraise, "on")))
1357                     evas_object_raise(VIEW(it));
1358                }
1359              if (it->base.disabled)
1360                edje_object_signal_emit(VIEW(it), "elm,state,disabled",
1361                                        "elm");
1362
1363              it->fixed = EINA_TRUE;
1364              it->is_even = it->even;
1365           }
1366         i++;
1367      }
1368
1369    mw = 0; mh = 0;
1370    evas_object_size_hint_min_get(wd->box, &mw, &mh);
1371
1372    _elm_list_mode_set_internal(wd);
1373
1374    _elm_list_unwalk(wd);
1375    evas_object_unref(obj);
1376 }
1377
1378 static void
1379 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1380 {
1381    Widget_Data *wd = elm_widget_data_get(obj);
1382    if (!wd) return;
1383    if (wd->scr)
1384      elm_smart_scroller_hold_set(wd->scr, EINA_TRUE);
1385 }
1386
1387 static void
1388 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1389 {
1390    Widget_Data *wd = elm_widget_data_get(obj);
1391    if (!wd) return;
1392    if (wd->scr)
1393      elm_smart_scroller_hold_set(wd->scr, EINA_FALSE);
1394 }
1395
1396 static void
1397 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1398 {
1399    Widget_Data *wd = elm_widget_data_get(obj);
1400    if (!wd) return;
1401    if (wd->scr)
1402      elm_smart_scroller_freeze_set(wd->scr, EINA_TRUE);
1403 }
1404
1405 static void
1406 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1407 {
1408    Widget_Data *wd = elm_widget_data_get(obj);
1409    if (!wd) return;
1410    if (wd->scr)
1411      elm_smart_scroller_freeze_set(wd->scr, EINA_FALSE);
1412 }
1413
1414 static void
1415 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1416 {
1417    _sizing_eval(data);
1418 }
1419
1420 EAPI Evas_Object *
1421 elm_list_add(Evas_Object *parent)
1422 {
1423    Evas_Object *obj;
1424    Evas *e;
1425    Widget_Data *wd;
1426    Evas_Coord minw, minh;
1427
1428    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1429
1430    ELM_SET_WIDTYPE(widtype, "list");
1431    elm_widget_type_set(obj, "list");
1432    elm_widget_sub_object_add(parent, obj);
1433    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1434    elm_widget_data_set(obj, wd);
1435    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1436    elm_widget_del_hook_set(obj, _del_hook);
1437    elm_widget_theme_hook_set(obj, _theme_hook);
1438    elm_widget_disable_hook_set(obj, _disable_hook);
1439    elm_widget_can_focus_set(obj, EINA_TRUE);
1440    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1441    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1442    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1443    elm_widget_event_hook_set(obj, _event_hook);
1444    elm_widget_translate_hook_set(obj, _translate_hook);
1445
1446    wd->self = obj;
1447    wd->scr = elm_smart_scroller_add(e);
1448    elm_smart_scroller_widget_set(wd->scr, obj);
1449    elm_widget_resize_object_set(obj, wd->scr);
1450    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1451                                   _changed_size_hints, obj);
1452    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &minw, &minh);
1453    evas_object_size_hint_min_set(obj, minw, minh);
1454    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
1455
1456    elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
1457                                        _elm_config->thumbscroll_bounce_enable);
1458
1459    wd->box = elm_box_add(parent);
1460    elm_box_homogeneous_set(wd->box, 1);
1461    evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1462    evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1463    elm_widget_on_show_region_hook_set(wd->box, _show_region_hook, obj);
1464    elm_widget_sub_object_add(obj, wd->box);
1465    elm_smart_scroller_child_set(wd->scr, wd->box);
1466    evas_object_event_callback_add(wd->box, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1467                                   _changed_size_hints, obj);
1468
1469    evas_object_show(wd->box);
1470
1471    _theme_hook(obj);
1472
1473    wd->mode = ELM_LIST_SCROLL;
1474
1475    evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
1476    evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
1477    evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
1478    evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom, obj);
1479
1480    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1481    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1482    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1483    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1484    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1485
1486    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1487
1488    _mirrored_set(obj, elm_widget_mirrored_get(obj));
1489    _sizing_eval(obj);
1490    return obj;
1491 }
1492
1493 EAPI void
1494 elm_list_go(Evas_Object *obj)
1495 {
1496    ELM_CHECK_WIDTYPE(obj, widtype);
1497    Widget_Data *wd = elm_widget_data_get(obj);
1498    if (!wd) return;
1499    _fix_items(obj);
1500 }
1501
1502 EAPI void
1503 elm_list_multi_select_set(Evas_Object *obj, Eina_Bool multi)
1504 {
1505    ELM_CHECK_WIDTYPE(obj, widtype);
1506    Widget_Data *wd = elm_widget_data_get(obj);
1507    if (!wd) return;
1508    wd->multi = multi;
1509 }
1510
1511 EAPI Eina_Bool
1512 elm_list_multi_select_get(const Evas_Object *obj)
1513 {
1514    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1515    Widget_Data *wd = elm_widget_data_get(obj);
1516    if (!wd) return EINA_FALSE;
1517    return wd->multi;
1518 }
1519
1520 EAPI void
1521 elm_list_mode_set(Evas_Object *obj, Elm_List_Mode mode)
1522 {
1523    ELM_CHECK_WIDTYPE(obj, widtype);
1524
1525    Widget_Data *wd;
1526
1527    wd = elm_widget_data_get(obj);
1528    if (!wd)
1529      return;
1530    if (wd->mode == mode)
1531      return;
1532    wd->mode = mode;
1533
1534    _elm_list_mode_set_internal(wd);
1535 }
1536
1537 EAPI Elm_List_Mode
1538 elm_list_mode_get(const Evas_Object *obj)
1539 {
1540    ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
1541    Widget_Data *wd = elm_widget_data_get(obj);
1542    if (!wd) return ELM_LIST_LAST;
1543    return wd->mode;
1544 }
1545
1546 EAPI void
1547 elm_list_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1548 {
1549    ELM_CHECK_WIDTYPE(obj, widtype);
1550
1551    Widget_Data *wd;
1552    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1553
1554    wd = elm_widget_data_get(obj);
1555    if (!wd)
1556      return;
1557
1558    if (wd->h_mode == horizontal)
1559      return;
1560
1561    wd->h_mode = horizontal;
1562    elm_box_horizontal_set(wd->box, horizontal);
1563
1564    if (horizontal)
1565      {
1566         evas_object_size_hint_weight_set(wd->box, 0.0, EVAS_HINT_EXPAND);
1567         evas_object_size_hint_align_set(wd->box, 0.0, EVAS_HINT_FILL);
1568         elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1569      }
1570    else
1571      {
1572         evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND, 0.0);
1573         evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0.0);
1574         elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE, bounce);
1575      }
1576
1577    _elm_list_mode_set_internal(wd);
1578 }
1579
1580 EAPI Eina_Bool
1581 elm_list_horizontal_get(const Evas_Object *obj)
1582 {
1583    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1584
1585    Widget_Data *wd;
1586
1587    wd = elm_widget_data_get(obj);
1588    if (!wd)
1589      return EINA_FALSE;
1590
1591    return wd->h_mode;
1592 }
1593
1594 EAPI void
1595 elm_list_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
1596 {
1597    ELM_CHECK_WIDTYPE(obj, widtype);
1598    Widget_Data *wd = elm_widget_data_get(obj);
1599    if (!wd) return;
1600    wd->always_select = always_select;
1601 }
1602
1603 EAPI Eina_Bool
1604 elm_list_always_select_mode_get(const Evas_Object *obj)
1605 {
1606    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1607    Widget_Data *wd = elm_widget_data_get(obj);
1608    if (!wd) return EINA_FALSE;
1609    return wd->always_select;
1610 }
1611
1612 EAPI void
1613 elm_list_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1614 {
1615    ELM_CHECK_WIDTYPE(obj, widtype);
1616    Widget_Data *wd = elm_widget_data_get(obj);
1617    if (!wd) return;
1618    if (wd->scr)
1619      elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1620 }
1621
1622 EAPI void
1623 elm_list_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1624 {
1625    ELM_CHECK_WIDTYPE(obj, widtype);
1626    Widget_Data *wd = elm_widget_data_get(obj);
1627    if (!wd) return;
1628    elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
1629 }
1630
1631 EAPI void
1632 elm_list_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
1633 {
1634    ELM_CHECK_WIDTYPE(obj, widtype);
1635    Widget_Data *wd = elm_widget_data_get(obj);
1636    if ((!wd) || (!wd->scr)) return;
1637    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
1638        (policy_v >= ELM_SCROLLER_POLICY_LAST))
1639      return;
1640    elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
1641 }
1642
1643 EAPI void
1644 elm_list_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
1645 {
1646    ELM_CHECK_WIDTYPE(obj, widtype);
1647    Widget_Data *wd = elm_widget_data_get(obj);
1648    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
1649    if ((!wd) || (!wd->scr)) return;
1650    elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
1651    if (policy_h) *policy_h = (Elm_Scroller_Policy) s_policy_h;
1652    if (policy_v) *policy_v = (Elm_Scroller_Policy) s_policy_v;
1653 }
1654
1655 EAPI void
1656 elm_list_clear(Evas_Object *obj)
1657 {
1658    ELM_CHECK_WIDTYPE(obj, widtype);
1659    Widget_Data *wd = elm_widget_data_get(obj);
1660    Elm_List_Item *it;
1661
1662    if (!wd) return;
1663    if (!wd->items) return;
1664
1665    eina_list_free(wd->selected);
1666    wd->selected = NULL;
1667
1668    if (wd->walking > 0)
1669      {
1670         Eina_List *n;
1671
1672         EINA_LIST_FOREACH(wd->items, n, it)
1673           {
1674              if (it->deleted) continue;
1675              it->deleted = EINA_TRUE;
1676              wd->to_delete = eina_list_append(wd->to_delete, it);
1677           }
1678         return;
1679      }
1680
1681    evas_object_ref(obj);
1682    _elm_list_walk(wd);
1683
1684    EINA_LIST_FREE(wd->items, it)
1685      {
1686         elm_widget_item_pre_notify_del(it);
1687         _elm_list_item_free(it);
1688      }
1689
1690    _elm_list_unwalk(wd);
1691
1692    _fix_items(obj);
1693    _sizing_eval(obj);
1694    evas_object_unref(obj);
1695 }
1696
1697 EAPI const Eina_List *
1698 elm_list_items_get(const Evas_Object *obj)
1699 {
1700    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1701    Widget_Data *wd = elm_widget_data_get(obj);
1702    if (!wd) return NULL;
1703    return wd->items;
1704 }
1705
1706 EAPI Elm_Object_Item *
1707 elm_list_selected_item_get(const Evas_Object *obj)
1708 {
1709    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1710    Widget_Data *wd = elm_widget_data_get(obj);
1711    if (!wd) return NULL;
1712    if (wd->selected) return (Elm_Object_Item *) wd->selected->data;
1713    return NULL;
1714 }
1715
1716 EAPI const Eina_List *
1717 elm_list_selected_items_get(const Evas_Object *obj)
1718 {
1719    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1720    Widget_Data *wd = elm_widget_data_get(obj);
1721    if (!wd) return NULL;
1722    return wd->selected;
1723 }
1724
1725 EAPI Elm_Object_Item *
1726 elm_list_item_append(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1727 {
1728    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1729    Widget_Data *wd = elm_widget_data_get(obj);
1730    Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1731
1732    wd->items = eina_list_append(wd->items, it);
1733    it->node = eina_list_last(wd->items);
1734    elm_box_pack_end(wd->box, VIEW(it));
1735    return (Elm_Object_Item *) it;
1736 }
1737
1738 EAPI Elm_Object_Item *
1739 elm_list_item_prepend(Evas_Object *obj, const char *label, Evas_Object *icon, Evas_Object *end, Evas_Smart_Cb func, const void *data)
1740 {
1741    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1742    Widget_Data *wd = elm_widget_data_get(obj);
1743    Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1744
1745    wd->items = eina_list_prepend(wd->items, it);
1746    it->node = wd->items;
1747    elm_box_pack_start(wd->box, VIEW(it));
1748    return (Elm_Object_Item *) it;
1749 }
1750
1751 EAPI Elm_Object_Item *
1752 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)
1753 {
1754    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1755    ELM_LIST_ITEM_CHECK_DELETED_RETURN(before, NULL);
1756
1757    Widget_Data *wd;
1758    Elm_List_Item *it, *before_it;
1759
1760    wd = elm_widget_data_get(obj);
1761    if (!wd) return NULL;
1762
1763    before_it = (Elm_List_Item *) before;
1764    if (!before_it->node) return NULL;
1765
1766    it = _item_new(obj, label, icon, end, func, data);
1767    wd->items = eina_list_prepend_relative_list(wd->items, it, before_it->node);
1768    it->node = before_it->node->prev;
1769    elm_box_pack_before(wd->box, VIEW(it), VIEW(before_it));
1770    return (Elm_Object_Item *) it;
1771 }
1772
1773 EAPI Elm_Object_Item *
1774 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)
1775 {
1776    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1777    ELM_LIST_ITEM_CHECK_DELETED_RETURN(after, NULL);
1778
1779    Widget_Data *wd;
1780    Elm_List_Item *it, *after_it;
1781
1782    wd = elm_widget_data_get(obj);
1783    if (!wd) return NULL;
1784
1785    after_it = (Elm_List_Item *) after;
1786    if (!after_it->node) return NULL;
1787
1788    it = _item_new(obj, label, icon, end, func, data);
1789    wd->items = eina_list_append_relative_list(wd->items, it, after_it->node);
1790    it->node = after_it->node->next;
1791    elm_box_pack_after(wd->box, VIEW(it), VIEW(after_it));
1792    return (Elm_Object_Item *) it;
1793 }
1794
1795 EAPI Elm_Object_Item *
1796 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)
1797 {
1798    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1799    Widget_Data *wd = elm_widget_data_get(obj);
1800    Elm_List_Item *it = _item_new(obj, label, icon, end, func, data);
1801    Eina_List *l;
1802
1803    wd->items = eina_list_sorted_insert(wd->items, cmp_func, it);
1804    l = eina_list_data_find_list(wd->items, it);
1805    l = eina_list_next(l);
1806    if (!l)
1807      {
1808         it->node = eina_list_last(wd->items);
1809         elm_box_pack_end(wd->box, VIEW(it));
1810      }
1811    else
1812      {
1813         Elm_List_Item *before = eina_list_data_get(l);
1814         it->node = before->node->prev;
1815         elm_box_pack_before(wd->box, VIEW(it), VIEW(before));
1816      }
1817    return (Elm_Object_Item *) it;
1818 }
1819
1820 EAPI void
1821 elm_list_item_separator_set(Elm_Object_Item *it, Eina_Bool setting)
1822 {
1823    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1824    ((Elm_List_Item *) it)->is_separator = !!setting;
1825 }
1826
1827 EAPI Eina_Bool
1828 elm_list_item_separator_get(const Elm_Object_Item *it)
1829 {
1830    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1831    return ((Elm_List_Item *) it)->is_separator;
1832 }
1833
1834 EAPI void
1835 elm_list_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1836 {
1837    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1838    Evas_Object *obj = WIDGET(it);
1839    Widget_Data *wd = elm_widget_data_get(obj);
1840    Elm_List_Item *item = (Elm_List_Item *) it;
1841    if (!wd) return;
1842
1843    selected = !!selected;
1844    if (item->selected == selected) return;
1845
1846    evas_object_ref(obj);
1847    _elm_list_walk(wd);
1848
1849    if (selected)
1850      {
1851         if (!wd->multi)
1852           {
1853              while (wd->selected)
1854                _item_unselect(wd->selected->data);
1855           }
1856         _item_highlight(item);
1857         _item_select(item);
1858      }
1859    else
1860      _item_unselect(item);
1861
1862    _elm_list_unwalk(wd);
1863    evas_object_unref(obj);
1864 }
1865
1866 EAPI Eina_Bool
1867 elm_list_item_selected_get(const Elm_Object_Item *it)
1868 {
1869    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
1870    return ((Elm_List_Item *) it)->selected;
1871 }
1872
1873 EAPI void
1874 elm_list_item_show(Elm_Object_Item *it)
1875 {
1876    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1877    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1878    if (!wd) return;
1879    Evas_Coord bx, by, bw, bh;
1880    Evas_Coord x, y, w, h;
1881
1882    evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1883    evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1884    x -= bx;
1885    y -= by;
1886    if (wd->scr) elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
1887 }
1888
1889 EAPI void
1890 elm_list_item_bring_in(Elm_Object_Item *it)
1891 {
1892    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1893    Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1894    if (!wd) return;
1895    Evas_Coord bx, by, bw, bh;
1896    Evas_Coord x, y, w, h;
1897
1898    evas_object_geometry_get(wd->box, &bx, &by, &bw, &bh);
1899    evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1900    x -= bx;
1901    y -= by;
1902    if (wd->scr) elm_smart_scroller_region_bring_in(wd->scr, x, y, w, h);
1903 }
1904
1905 EAPI void
1906 elm_list_item_del(Elm_Object_Item *it)
1907 {
1908    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
1909    Evas_Object *obj = WIDGET(it);
1910    Elm_List_Item *item = (Elm_List_Item *) it;
1911    Widget_Data *wd = elm_widget_data_get(obj);
1912    if (!wd) return;
1913
1914    if (item->selected) _item_unselect(item);
1915
1916    if (wd->walking > 0)
1917      {
1918         if (item->deleted) return;
1919         item->deleted = EINA_TRUE;
1920         wd->to_delete = eina_list_append(wd->to_delete, item);
1921         return;
1922      }
1923
1924    wd->items = eina_list_remove_list(wd->items, item->node);
1925
1926    evas_object_ref(obj);
1927    _elm_list_walk(wd);
1928
1929    elm_widget_item_pre_notify_del(item);
1930    _elm_list_item_free(item);
1931
1932    _elm_list_unwalk(wd);
1933    evas_object_unref(obj);
1934 }
1935
1936 EAPI Evas_Object *
1937 elm_list_item_object_get(const Elm_Object_Item *it)
1938 {
1939    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1940    return VIEW(it);
1941 }
1942
1943 EAPI Elm_Object_Item *
1944 elm_list_item_prev(const Elm_Object_Item *it)
1945 {
1946    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1947    Elm_List_Item *item = (Elm_List_Item *) it;
1948    if (item->node->prev) return item->node->prev->data;
1949    else return NULL;
1950 }
1951
1952 EAPI Elm_Object_Item *
1953 elm_list_item_next(const Elm_Object_Item *it)
1954 {
1955    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
1956    Elm_List_Item *item = (Elm_List_Item *) it;
1957    if (item->node->next) return item->node->next->data;
1958    else return NULL;
1959 }
1960
1961 EINA_DEPRECATED EAPI Evas_Object *
1962 elm_list_item_base_get(const Elm_Object_Item *it)
1963 {
1964    return elm_list_item_object_get(it);
1965 }
1966
1967 EINA_DEPRECATED EAPI void
1968 elm_list_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1969 {
1970    elm_object_item_disabled_set(it, disabled);
1971 }
1972
1973 EINA_DEPRECATED EAPI Eina_Bool
1974 elm_list_item_disabled_get(const Elm_Object_Item *it)
1975 {
1976    return elm_object_item_disabled_get(it);
1977 }
1978
1979 EINA_DEPRECATED EAPI void
1980 elm_list_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1981 {
1982    elm_object_item_del_cb_set(it, func);
1983 }
1984
1985 EINA_DEPRECATED EAPI void *
1986 elm_list_item_data_get(const Elm_Object_Item *it)
1987 {
1988    return elm_object_item_data_get(it);
1989 }
1990
1991 EINA_DEPRECATED EAPI Evas_Object *
1992 elm_list_item_icon_get(const Elm_Object_Item *it)
1993 {
1994    return _item_content_get(it, NULL);
1995 }
1996
1997 EINA_DEPRECATED EAPI void
1998 elm_list_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1999 {
2000    _item_content_set(it, NULL, icon);
2001 }
2002
2003 EINA_DEPRECATED EAPI Evas_Object *
2004 elm_list_item_end_get(const Elm_Object_Item *it)
2005 {
2006    return _item_content_get(it, "end");
2007 }
2008
2009 EINA_DEPRECATED EAPI void
2010 elm_list_item_end_set(Elm_Object_Item *it, Evas_Object *end)
2011 {
2012    _item_content_set(it, "end", end);
2013 }
2014
2015 EINA_DEPRECATED EAPI const char *
2016 elm_list_item_label_get(const Elm_Object_Item *it)
2017 {
2018    return _item_text_get(it, NULL);
2019 }
2020
2021 EINA_DEPRECATED EAPI void
2022 elm_list_item_label_set(Elm_Object_Item *it, const char *text)
2023 {
2024    _item_text_set(it, NULL, text);
2025 }
2026
2027 // XXX: all the below - make elm_object_item*() calls to do these
2028 EAPI void
2029 elm_list_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
2030 {
2031    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2032    elm_widget_item_tooltip_text_set(it, text);
2033 }
2034
2035 EAPI void
2036 elm_list_item_tooltip_content_cb_set(Elm_Object_Item *it, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
2037 {
2038    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2039    elm_widget_item_tooltip_content_cb_set(it, func, data, del_cb);
2040 }
2041
2042 EAPI void
2043 elm_list_item_tooltip_unset(Elm_Object_Item *it)
2044 {
2045    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2046    elm_widget_item_tooltip_unset(it);
2047 }
2048
2049 EAPI Eina_Bool
2050 elm_list_item_tooltip_window_mode_set(Elm_Object_Item *it, Eina_Bool disable)
2051 {
2052    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
2053    return elm_widget_item_tooltip_window_mode_set(it, disable);
2054 }
2055
2056 EAPI Eina_Bool
2057 elm_list_item_tooltip_window_mode_get(const Elm_Object_Item *it)
2058 {
2059    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
2060    return elm_widget_item_tooltip_window_mode_get(it);
2061 }
2062
2063 EAPI void
2064 elm_list_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
2065 {
2066    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2067    elm_widget_item_tooltip_style_set(it, style);
2068 }
2069
2070 EAPI const char *
2071 elm_list_item_tooltip_style_get(const Elm_Object_Item *it)
2072 {
2073    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2074    return elm_widget_item_tooltip_style_get(it);
2075 }
2076
2077 EAPI void
2078 elm_list_item_cursor_set(Elm_Object_Item *it, const char *cursor)
2079 {
2080    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2081    elm_widget_item_cursor_set(it, cursor);
2082 }
2083
2084 EAPI const char *
2085 elm_list_item_cursor_get(const Elm_Object_Item *it)
2086 {
2087    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2088    return elm_widget_item_cursor_get(it);
2089 }
2090
2091 EAPI void
2092 elm_list_item_cursor_unset(Elm_Object_Item *it)
2093 {
2094    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2095    elm_widget_item_cursor_unset(it);
2096 }
2097
2098 EAPI void
2099 elm_list_item_cursor_style_set(Elm_Object_Item *it, const char *style)
2100 {
2101    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2102    elm_widget_item_cursor_style_set(it, style);
2103 }
2104
2105 EAPI const char *
2106 elm_list_item_cursor_style_get(const Elm_Object_Item *it)
2107 {
2108    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, NULL);
2109    return elm_widget_item_cursor_style_get(it);
2110 }
2111
2112 EAPI void
2113 elm_list_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
2114 {
2115    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it);
2116    elm_widget_item_cursor_engine_only_set(it, engine_only);
2117 }
2118
2119 EAPI Eina_Bool
2120 elm_list_item_cursor_engine_only_get(const Elm_Object_Item *it)
2121 {
2122    ELM_LIST_ITEM_CHECK_DELETED_RETURN(it, EINA_FALSE);
2123    return elm_widget_item_cursor_engine_only_get(it);
2124 }