elementary/genlist - Moving and improving docs of genlist functions.
[framework/uifw/elementary.git] / src / lib / elm_genlist.c
1 #include <assert.h>
2
3 #include <Elementary.h>
4 #include <Elementary_Cursor.h>
5 #include "elm_priv.h"
6
7 #define SWIPE_MOVES         12
8 #define MAX_ITEMS_PER_BLOCK 32
9 #define REORDER_EFFECT_TIME 0.5
10
11 typedef struct _Widget_Data Widget_Data;
12 typedef struct _Item_Block  Item_Block;
13 typedef struct _Pan         Pan;
14 typedef struct _Item_Cache  Item_Cache;
15
16 struct _Widget_Data
17 {
18    Evas_Object      *obj, *scr, *pan_smart;
19    Eina_Inlist      *items, *blocks;
20    Eina_List        *group_items;
21    Pan              *pan;
22    Evas_Coord        pan_x, pan_y, old_pan_y, w, h, minw, minh, realminw, prev_viewport_w;
23    Ecore_Job        *calc_job, *update_job;
24    Ecore_Idle_Enterer *queue_idle_enterer;
25    Ecore_Idler        *must_recalc_idler;
26    Eina_List        *queue, *selected;
27    Elm_Genlist_Item *show_item, *last_selected_item, *anchor_item, *mode_item, *reorder_it, *reorder_rel, *expanded_item;
28    Eina_Inlist      *item_cache;
29    Evas_Coord        anchor_y, reorder_start_y;
30    Elm_List_Mode     mode;
31    Ecore_Timer      *multi_timer, *scr_hold_timer;
32    Ecore_Animator   *reorder_move_animator;
33    const char       *mode_type;
34    unsigned int      start_time;
35    Evas_Coord        prev_x, prev_y, prev_mx, prev_my;
36    Evas_Coord        cur_x, cur_y, cur_mx, cur_my;
37    Eina_Bool         mouse_down : 1;
38    Eina_Bool         multi_down : 1;
39    Eina_Bool         multi_timeout : 1;
40    Eina_Bool         multitouched : 1;
41    Eina_Bool         on_hold : 1;
42    Eina_Bool         multi : 1;
43    Eina_Bool         always_select : 1;
44    Eina_Bool         longpressed : 1;
45    Eina_Bool         wasselected : 1;
46    Eina_Bool         no_select : 1;
47    Eina_Bool         bring_in : 1;
48    Eina_Bool         compress : 1;
49    Eina_Bool         height_for_width : 1;
50    Eina_Bool         homogeneous : 1;
51    Eina_Bool         clear_me : 1;
52    Eina_Bool         swipe : 1;
53    Eina_Bool         reorder_mode : 1;
54    Eina_Bool         reorder_pan_move : 1;
55    Eina_Bool         auto_scroll_enabled : 1;
56    struct
57    {
58       Evas_Coord x, y;
59    } history[SWIPE_MOVES];
60    int               multi_device;
61    int               item_cache_count;
62    int               item_cache_max;
63    int               movements;
64    int               walking;
65    int               item_width;
66    int               item_height;
67    int               group_item_width;
68    int               group_item_height;
69    int               max_items_per_block;
70    double            longpress_timeout;
71 };
72
73 struct _Item_Block
74 {
75    EINA_INLIST;
76    int          count;
77    int          num;
78    int          reorder_offset;
79    Widget_Data *wd;
80    Eina_List   *items;
81    Evas_Coord   x, y, w, h, minw, minh;
82    Eina_Bool    want_unrealize : 1;
83    Eina_Bool    realized : 1;
84    Eina_Bool    changed : 1;
85    Eina_Bool    updateme : 1;
86    Eina_Bool    showme : 1;
87    Eina_Bool    must_recalc : 1;
88 };
89
90 struct _Elm_Genlist_Item
91 {
92    Elm_Widget_Item               base;
93    EINA_INLIST;
94    Widget_Data                  *wd;
95    Item_Block                   *block;
96    Eina_List                    *items;
97    Evas_Coord                    x, y, w, h, minw, minh;
98    const Elm_Genlist_Item_Class *itc;
99    Elm_Genlist_Item             *parent;
100    Elm_Genlist_Item             *group_item;
101    Elm_Genlist_Item_Flags        flags;
102    struct
103    {
104       Evas_Smart_Cb func;
105       const void   *data;
106    } func;
107
108    Evas_Object                  *spacer;
109    Eina_List                    *labels, *icons, *states, *icon_objs;
110    Eina_List                    *mode_labels, *mode_icons, *mode_states, *mode_icon_objs;
111    Ecore_Timer                  *long_timer;
112    Ecore_Timer                  *swipe_timer;
113    Evas_Coord                    dx, dy;
114    Evas_Coord                    scrl_x, scrl_y, old_scrl_y;
115
116    Elm_Genlist_Item             *rel;
117    Evas_Object                  *mode_view;
118
119    struct
120    {
121       const void                 *data;
122       Elm_Tooltip_Item_Content_Cb content_cb;
123       Evas_Smart_Cb               del_cb;
124       const char                 *style;
125    } tooltip;
126
127    const char                   *mouse_cursor;
128
129    int                           relcount;
130    int                           walking;
131    int                           expanded_depth;
132    int                           order_num_in;
133
134    Eina_Bool                     before : 1;
135
136    Eina_Bool                     want_unrealize : 1;
137    Eina_Bool                     want_realize : 1;
138    Eina_Bool                     realized : 1;
139    Eina_Bool                     selected : 1;
140    Eina_Bool                     highlighted : 1;
141    Eina_Bool                     expanded : 1;
142    Eina_Bool                     disabled : 1;
143    Eina_Bool                     display_only : 1;
144    Eina_Bool                     mincalcd : 1;
145    Eina_Bool                     queued : 1;
146    Eina_Bool                     showme : 1;
147    Eina_Bool                     delete_me : 1;
148    Eina_Bool                     down : 1;
149    Eina_Bool                     dragging : 1;
150    Eina_Bool                     updateme : 1;
151    Eina_Bool                     nocache : 1;
152    Eina_Bool                     stacking_even : 1;
153    Eina_Bool                     nostacking : 1;
154    Eina_Bool                     move_effect_enabled : 1;
155 };
156
157 struct _Item_Cache
158 {
159    EINA_INLIST;
160
161    Evas_Object *base_view, *spacer;
162
163    const char  *item_style; // it->itc->item_style
164    Eina_Bool    tree : 1; // it->flags & ELM_GENLIST_ITEM_SUBITEMS
165    Eina_Bool    compress : 1; // it->wd->compress
166
167    Eina_Bool    selected : 1; // it->selected
168    Eina_Bool    disabled : 1; // it->disabled
169    Eina_Bool    expanded : 1; // it->expanded
170 };
171
172 #define ELM_GENLIST_ITEM_FROM_INLIST(item) \
173   ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Genlist_Item) : NULL)
174
175 struct _Pan
176 {
177    Evas_Object_Smart_Clipped_Data __clipped_data;
178    Widget_Data                   *wd;
179    Ecore_Job                     *resize_job;
180 };
181
182 static const char *widtype = NULL;
183 static void      _item_cache_zero(Widget_Data *wd);
184 static void      _del_hook(Evas_Object *obj);
185 static void      _mirrored_set(Evas_Object *obj,
186                                Eina_Bool    rtl);
187 static void      _theme_hook(Evas_Object *obj);
188 static void      _show_region_hook(void        *data,
189                                    Evas_Object *obj);
190 static void      _sizing_eval(Evas_Object *obj);
191 static void      _item_realize(Elm_Genlist_Item *it,
192                                int               in,
193                                Eina_Bool         calc);
194 static void      _item_unrealize(Elm_Genlist_Item *it,
195                                  Eina_Bool         calc);
196 static void      _item_block_unrealize(Item_Block *itb);
197 static void      _calc_job(void *data);
198 static void      _on_focus_hook(void        *data,
199                                 Evas_Object *obj);
200 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
201 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
202 static Eina_Bool _item_single_select_up(Widget_Data *wd);
203 static Eina_Bool _item_single_select_down(Widget_Data *wd);
204 static Eina_Bool _event_hook(Evas_Object       *obj,
205                              Evas_Object       *src,
206                              Evas_Callback_Type type,
207                              void              *event_info);
208 static void      _signal_emit_hook(Evas_Object *obj,
209                                    const char *emission,
210                                    const char *source);
211 static Eina_Bool _deselect_all_items(Widget_Data *wd);
212 static void      _pan_calculate(Evas_Object *obj);
213 static void      _item_position(Elm_Genlist_Item *it,
214                                 Evas_Object      *obj,
215                                 Evas_Coord        it_x,
216                                 Evas_Coord        it_y);
217 static void      _mode_item_realize(Elm_Genlist_Item *it);
218 static void      _mode_item_unrealize(Elm_Genlist_Item *it);
219 static void      _item_mode_set(Elm_Genlist_Item *it);
220 static void      _item_mode_unset(Widget_Data *wd);
221 static void      _group_items_recalc(void *data);
222 static void      _item_move_after(Elm_Genlist_Item *it,
223                                   Elm_Genlist_Item *after);
224 static void      _item_move_before(Elm_Genlist_Item *it,
225                                    Elm_Genlist_Item *before);
226 static void      _item_auto_scroll(Widget_Data *wd);
227
228 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
229
230 static const char SIG_ACTIVATED[] = "activated";
231 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
232 static const char SIG_SELECTED[] = "selected";
233 static const char SIG_UNSELECTED[] = "unselected";
234 static const char SIG_EXPANDED[] = "expanded";
235 static const char SIG_CONTRACTED[] = "contracted";
236 static const char SIG_EXPAND_REQUEST[] = "expand,request";
237 static const char SIG_CONTRACT_REQUEST[] = "contract,request";
238 static const char SIG_REALIZED[] = "realized";
239 static const char SIG_UNREALIZED[] = "unrealized";
240 static const char SIG_DRAG_START_UP[] = "drag,start,up";
241 static const char SIG_DRAG_START_DOWN[] = "drag,start,down";
242 static const char SIG_DRAG_START_LEFT[] = "drag,start,left";
243 static const char SIG_DRAG_START_RIGHT[] = "drag,start,right";
244 static const char SIG_DRAG_STOP[] = "drag,stop";
245 static const char SIG_DRAG[] = "drag";
246 static const char SIG_LONGPRESSED[] = "longpressed";
247 static const char SIG_SCROLL_EDGE_TOP[] = "scroll,edge,top";
248 static const char SIG_SCROLL_EDGE_BOTTOM[] = "scroll,edge,bottom";
249 static const char SIG_SCROLL_EDGE_LEFT[] = "scroll,edge,left";
250 static const char SIG_SCROLL_EDGE_RIGHT[] = "scroll,edge,right";
251 static const char SIG_MULTI_SWIPE_LEFT[] = "multi,swipe,left";
252 static const char SIG_MULTI_SWIPE_RIGHT[] = "multi,swipe,right";
253 static const char SIG_MULTI_SWIPE_UP[] = "multi,swipe,up";
254 static const char SIG_MULTI_SWIPE_DOWN[] = "multi,swipe,down";
255 static const char SIG_MULTI_PINCH_OUT[] = "multi,pinch,out";
256 static const char SIG_MULTI_PINCH_IN[] = "multi,pinch,in";
257 static const char SIG_SWIPE[] = "swipe";
258
259 static const Evas_Smart_Cb_Description _signals[] = {
260    {SIG_CLICKED_DOUBLE, ""},
261    {SIG_ACTIVATED, ""},
262    {SIG_SELECTED, ""},
263    {SIG_UNSELECTED, ""},
264    {SIG_EXPANDED, ""},
265    {SIG_CONTRACTED, ""},
266    {SIG_EXPAND_REQUEST, ""},
267    {SIG_CONTRACT_REQUEST, ""},
268    {SIG_REALIZED, ""},
269    {SIG_UNREALIZED, ""},
270    {SIG_DRAG_START_UP, ""},
271    {SIG_DRAG_START_DOWN, ""},
272    {SIG_DRAG_START_LEFT, ""},
273    {SIG_DRAG_START_RIGHT, ""},
274    {SIG_DRAG_STOP, ""},
275    {SIG_DRAG, ""},
276    {SIG_LONGPRESSED, ""},
277    {SIG_SCROLL_EDGE_TOP, ""},
278    {SIG_SCROLL_EDGE_BOTTOM, ""},
279    {SIG_SCROLL_EDGE_LEFT, ""},
280    {SIG_SCROLL_EDGE_RIGHT, ""},
281    {SIG_MULTI_SWIPE_LEFT, ""},
282    {SIG_MULTI_SWIPE_RIGHT, ""},
283    {SIG_MULTI_SWIPE_UP, ""},
284    {SIG_MULTI_SWIPE_DOWN, ""},
285    {SIG_MULTI_PINCH_OUT, ""},
286    {SIG_MULTI_PINCH_IN, ""},
287    {SIG_SWIPE, ""},
288    {NULL, NULL}
289 };
290
291 static Eina_Compare_Cb _elm_genlist_item_compare_cb;
292 static Eina_Compare_Cb _elm_genlist_item_compare_data_cb;
293
294 static Eina_Bool
295 _event_hook(Evas_Object       *obj,
296             Evas_Object       *src __UNUSED__,
297             Evas_Callback_Type type,
298             void              *event_info)
299 {
300    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
301    Evas_Event_Key_Down *ev = event_info;
302    Widget_Data *wd = elm_widget_data_get(obj);
303    if (!wd) return EINA_FALSE;
304    if (!wd->items) return EINA_FALSE;
305    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
306    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
307
308    Elm_Genlist_Item *it = NULL;
309    Evas_Coord x = 0;
310    Evas_Coord y = 0;
311    Evas_Coord step_x = 0;
312    Evas_Coord step_y = 0;
313    Evas_Coord v_w = 0;
314    Evas_Coord v_h = 0;
315    Evas_Coord page_x = 0;
316    Evas_Coord page_y = 0;
317
318    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
319    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
320    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
321    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
322
323    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
324      {
325         x -= step_x;
326      }
327    else if ((!strcmp(ev->keyname, "Right")) ||
328             (!strcmp(ev->keyname, "KP_Right")))
329      {
330         x += step_x;
331      }
332    else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
333      {
334         if (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
335              (_item_multi_select_up(wd)))
336             || (_item_single_select_up(wd)))
337           {
338              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
339              return EINA_TRUE;
340           }
341         else
342           y -= step_y;
343      }
344    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
345      {
346         if (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
347              (_item_multi_select_down(wd)))
348             || (_item_single_select_down(wd)))
349           {
350              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
351              return EINA_TRUE;
352           }
353         else
354           y += step_y;
355      }
356    else if ((!strcmp(ev->keyname, "Home")) ||
357             (!strcmp(ev->keyname, "KP_Home")))
358      {
359         it = elm_genlist_first_item_get(obj);
360         elm_genlist_item_bring_in(it);
361         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
362         return EINA_TRUE;
363      }
364    else if ((!strcmp(ev->keyname, "End")) ||
365             (!strcmp(ev->keyname, "KP_End")))
366      {
367         it = elm_genlist_last_item_get(obj);
368         elm_genlist_item_bring_in(it);
369         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
370         return EINA_TRUE;
371      }
372    else if ((!strcmp(ev->keyname, "Prior")) ||
373             (!strcmp(ev->keyname, "KP_Prior")))
374      {
375         if (page_y < 0)
376           y -= -(page_y * v_h) / 100;
377         else
378           y -= page_y;
379      }
380    else if ((!strcmp(ev->keyname, "Next")) ||
381             (!strcmp(ev->keyname, "KP_Next")))
382      {
383         if (page_y < 0)
384           y += -(page_y * v_h) / 100;
385         else
386           y += page_y;
387      }
388    else if (((!strcmp(ev->keyname, "Return")) ||
389             (!strcmp(ev->keyname, "KP_Enter")) ||
390             (!strcmp(ev->keyname, "space")))
391            && (!wd->multi) && (wd->selected))
392      {
393         it = elm_genlist_selected_item_get(obj);
394         elm_genlist_item_expanded_set(it,
395                                       !elm_genlist_item_expanded_get(it));
396         evas_object_smart_callback_call(it->base.widget, SIG_ACTIVATED, it);
397      }
398    else if (!strcmp(ev->keyname, "Escape"))
399      {
400         if (!_deselect_all_items(wd)) return EINA_FALSE;
401         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
402         return EINA_TRUE;
403      }
404    else return EINA_FALSE;
405
406    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
407    elm_smart_scroller_child_pos_set(wd->scr, x, y);
408    return EINA_TRUE;
409 }
410
411 static Eina_Bool
412 _deselect_all_items(Widget_Data *wd)
413 {
414    if (!wd->selected) return EINA_FALSE;
415    while (wd->selected)
416      elm_genlist_item_selected_set(wd->selected->data, EINA_FALSE);
417
418    return EINA_TRUE;
419 }
420
421 static Eina_Bool
422 _item_multi_select_up(Widget_Data *wd)
423 {
424    if (!wd->selected) return EINA_FALSE;
425    if (!wd->multi) return EINA_FALSE;
426
427    Elm_Genlist_Item *prev = elm_genlist_item_prev_get(wd->last_selected_item);
428    if (!prev) return EINA_TRUE;
429
430    if (elm_genlist_item_selected_get(prev))
431      {
432         elm_genlist_item_selected_set(wd->last_selected_item, EINA_FALSE);
433         wd->last_selected_item = prev;
434         elm_genlist_item_show(wd->last_selected_item);
435      }
436    else
437      {
438         elm_genlist_item_selected_set(prev, EINA_TRUE);
439         elm_genlist_item_show(prev);
440      }
441    return EINA_TRUE;
442 }
443
444 static Eina_Bool
445 _item_multi_select_down(Widget_Data *wd)
446 {
447    if (!wd->selected) return EINA_FALSE;
448    if (!wd->multi) return EINA_FALSE;
449
450    Elm_Genlist_Item *next = elm_genlist_item_next_get(wd->last_selected_item);
451    if (!next) return EINA_TRUE;
452
453    if (elm_genlist_item_selected_get(next))
454      {
455         elm_genlist_item_selected_set(wd->last_selected_item, EINA_FALSE);
456         wd->last_selected_item = next;
457         elm_genlist_item_show(wd->last_selected_item);
458      }
459    else
460      {
461         elm_genlist_item_selected_set(next, EINA_TRUE);
462         elm_genlist_item_show(next);
463      }
464    return EINA_TRUE;
465 }
466
467 static Eina_Bool
468 _item_single_select_up(Widget_Data *wd)
469 {
470    Elm_Genlist_Item *prev;
471    if (!wd->selected)
472      {
473         prev = ELM_GENLIST_ITEM_FROM_INLIST(wd->items->last);
474         while ((prev) && (prev->delete_me))
475           prev = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
476      }
477    else prev = elm_genlist_item_prev_get(wd->last_selected_item);
478
479    if (!prev) return EINA_FALSE;
480
481    _deselect_all_items(wd);
482
483    elm_genlist_item_selected_set(prev, EINA_TRUE);
484    elm_genlist_item_show(prev);
485    return EINA_TRUE;
486 }
487
488 static Eina_Bool
489 _item_single_select_down(Widget_Data *wd)
490 {
491    Elm_Genlist_Item *next;
492    if (!wd->selected)
493      {
494         next = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
495         while ((next) && (next->delete_me))
496           next = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
497      }
498    else next = elm_genlist_item_next_get(wd->last_selected_item);
499
500    if (!next) return EINA_FALSE;
501
502    _deselect_all_items(wd);
503
504    elm_genlist_item_selected_set(next, EINA_TRUE);
505    elm_genlist_item_show(next);
506    return EINA_TRUE;
507 }
508
509 static void
510 _on_focus_hook(void        *data __UNUSED__,
511                Evas_Object *obj)
512 {
513    Widget_Data *wd = elm_widget_data_get(obj);
514    if (!wd) return;
515    if (elm_widget_focus_get(obj))
516      {
517         elm_object_signal_emit(wd->obj, "elm,action,focus", "elm");
518         evas_object_focus_set(wd->obj, EINA_TRUE);
519         if ((wd->selected) && (!wd->last_selected_item))
520           wd->last_selected_item = eina_list_data_get(wd->selected);
521      }
522    else
523      {
524         elm_object_signal_emit(wd->obj, "elm,action,unfocus", "elm");
525         evas_object_focus_set(wd->obj, EINA_FALSE);
526      }
527 }
528
529 static void
530 _del_hook(Evas_Object *obj)
531 {
532    Widget_Data *wd = elm_widget_data_get(obj);
533    if (!wd) return;
534    _item_cache_zero(wd);
535    if (wd->calc_job) ecore_job_del(wd->calc_job);
536    if (wd->update_job) ecore_job_del(wd->update_job);
537    if (wd->queue_idle_enterer) ecore_idle_enterer_del(wd->queue_idle_enterer);
538    if (wd->must_recalc_idler) ecore_idler_del(wd->must_recalc_idler);
539    if (wd->multi_timer) ecore_timer_del(wd->multi_timer);
540    if (wd->mode_type) eina_stringshare_del(wd->mode_type);
541    if (wd->scr_hold_timer) ecore_timer_del(wd->scr_hold_timer);
542    free(wd);
543 }
544
545 static void
546 _del_pre_hook(Evas_Object *obj)
547 {
548    Widget_Data *wd = elm_widget_data_get(obj);
549    if (!wd) return;
550    evas_object_del(wd->pan_smart);
551    wd->pan_smart = NULL;
552    elm_genlist_clear(obj);
553 }
554
555 static void
556 _mirrored_set(Evas_Object *obj,
557               Eina_Bool    rtl)
558 {
559    Widget_Data *wd = elm_widget_data_get(obj);
560    if (!wd) return;
561    _item_cache_zero(wd);
562    elm_smart_scroller_mirrored_set(wd->scr, rtl);
563 }
564
565 static void
566 _theme_hook(Evas_Object *obj)
567 {
568    Widget_Data *wd = elm_widget_data_get(obj);
569    Item_Block *itb;
570    if (!wd) return;
571    evas_event_freeze(evas_object_evas_get(wd->obj));
572    _item_cache_zero(wd);
573    _elm_widget_mirrored_reload(obj);
574    _mirrored_set(obj, elm_widget_mirrored_get(obj));
575    elm_smart_scroller_object_theme_set(obj, wd->scr, "genlist", "base",
576                                        elm_widget_style_get(obj));
577    edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
578    wd->item_width = wd->item_height = 0;
579    wd->group_item_width = wd->group_item_height = 0;
580    wd->minw = wd->minh = wd->realminw = 0;
581    EINA_INLIST_FOREACH(wd->blocks, itb)
582      {
583         Eina_List *l;
584         Elm_Genlist_Item *it;
585
586         if (itb->realized) _item_block_unrealize(itb);
587         EINA_LIST_FOREACH(itb->items, l, it)
588           it->mincalcd = EINA_FALSE;
589
590         itb->changed = EINA_TRUE;
591      }
592    if (wd->calc_job) ecore_job_del(wd->calc_job);
593    wd->calc_job = ecore_job_add(_calc_job, wd);
594    _sizing_eval(obj);
595    evas_event_thaw(evas_object_evas_get(wd->obj));
596    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
597 }
598
599 static void
600 _show_region_hook(void        *data,
601                   Evas_Object *obj)
602 {
603    Widget_Data *wd = elm_widget_data_get(data);
604    Evas_Coord x, y, w, h;
605    if (!wd) return;
606    elm_widget_show_region_get(obj, &x, &y, &w, &h);
607    //x & y are screen coordinates, Add with pan coordinates
608    x += wd->pan_x;
609    y += wd->pan_y;
610    elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
611 }
612
613 static void
614 _sizing_eval(Evas_Object *obj)
615 {
616    Widget_Data *wd = elm_widget_data_get(obj);
617    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
618    if (!wd) return;
619    evas_object_size_hint_min_get(wd->scr, &minw, &minh);
620    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
621    minh = -1;
622    if (wd->height_for_width)
623      {
624         Evas_Coord vw, vh;
625
626         elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
627         if ((vw != 0) && (vw != wd->prev_viewport_w))
628           {
629              Item_Block *itb;
630
631              wd->prev_viewport_w = vw;
632              EINA_INLIST_FOREACH(wd->blocks, itb)
633                {
634                   itb->must_recalc = EINA_TRUE;
635                }
636              if (wd->calc_job) ecore_job_del(wd->calc_job);
637              wd->calc_job = ecore_job_add(_calc_job, wd);
638           }
639      }
640    if (wd->mode == ELM_LIST_LIMIT)
641      {
642         Evas_Coord vmw, vmh, vw, vh;
643
644         minw = wd->realminw;
645         maxw = -1;
646         elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
647         if ((minw > 0) && (vw < minw)) vw = minw;
648         else if ((maxw > 0) && (vw > maxw))
649           vw = maxw;
650         edje_object_size_min_calc
651           (elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
652         minw = vmw + minw;
653      }
654    else
655      {
656         Evas_Coord vmw, vmh;
657
658         edje_object_size_min_calc
659           (elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
660         minw = vmw;
661         minh = vmh;
662      }
663    evas_object_size_hint_min_set(obj, minw, minh);
664    evas_object_size_hint_max_set(obj, maxw, maxh);
665 }
666
667 static void
668 _signal_emit_hook(Evas_Object *obj,
669                   const char  *emission,
670                   const char  *source)
671 {
672    Widget_Data *wd = elm_widget_data_get(obj);
673    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
674                            emission, source);
675 }
676
677 static void
678 _item_highlight(Elm_Genlist_Item *it)
679 {
680    const char *selectraise;
681    if ((it->wd->no_select) || (it->delete_me) || (it->highlighted) ||
682        (it->disabled) || (it->display_only) || (it->mode_view))
683      return;
684    edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
685    selectraise = edje_object_data_get(it->base.view, "selectraise");
686    if ((selectraise) && (!strcmp(selectraise, "on")))
687      {
688         evas_object_raise(it->base.view);
689         if ((it->group_item) && (it->group_item->realized))
690           evas_object_raise(it->group_item->base.view);
691      }
692    it->highlighted = EINA_TRUE;
693 }
694
695 static void
696 _item_unhighlight(Elm_Genlist_Item *it)
697 {
698    const char *stacking, *selectraise;
699    if ((it->delete_me) || (!it->highlighted)) return;
700    edje_object_signal_emit(it->base.view, "elm,state,unselected", "elm");
701    stacking = edje_object_data_get(it->base.view, "stacking");
702    selectraise = edje_object_data_get(it->base.view, "selectraise");
703    if (!it->nostacking)
704      {
705        if ((it->order_num_in & 0x1) ^ it->stacking_even) evas_object_lower(it->base.view);
706        else evas_object_raise(it->base.view);
707      }
708    it->highlighted = EINA_FALSE;
709 }
710
711 static void
712 _item_block_del(Elm_Genlist_Item *it)
713 {
714    Eina_Inlist *il;
715    Item_Block *itb = it->block;
716
717    itb->items = eina_list_remove(itb->items, it);
718    itb->count--;
719    itb->changed = EINA_TRUE;
720    if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
721    it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
722    if (itb->count < 1)
723      {
724         il = EINA_INLIST_GET(itb);
725         Item_Block *itbn = (Item_Block *)(il->next);
726         if (it->parent)
727           it->parent->items = eina_list_remove(it->parent->items, it);
728         else
729           it->wd->blocks = eina_inlist_remove(it->wd->blocks, il);
730         free(itb);
731         if (itbn) itbn->changed = EINA_TRUE;
732      }
733    else
734      {
735         if (itb->count < itb->wd->max_items_per_block/2)
736           {
737              il = EINA_INLIST_GET(itb);
738              Item_Block *itbp = (Item_Block *)(il->prev);
739              Item_Block *itbn = (Item_Block *)(il->next);
740              if ((itbp) && ((itbp->count + itb->count) < itb->wd->max_items_per_block + itb->wd->max_items_per_block/2))
741                {
742                   Elm_Genlist_Item *it2;
743
744                   EINA_LIST_FREE(itb->items, it2)
745                     {
746                        it2->block = itbp;
747                        itbp->items = eina_list_append(itbp->items, it2);
748                        itbp->count++;
749                        itbp->changed = EINA_TRUE;
750                     }
751                   it->wd->blocks = eina_inlist_remove(it->wd->blocks,
752                                                       EINA_INLIST_GET(itb));
753                   free(itb);
754                }
755              else if ((itbn) && ((itbn->count + itb->count) < itb->wd->max_items_per_block + itb->wd->max_items_per_block/2))
756                {
757                   while (itb->items)
758                     {
759                        Eina_List *last = eina_list_last(itb->items);
760                        Elm_Genlist_Item *it2 = last->data;
761
762                        it2->block = itbn;
763                        itb->items = eina_list_remove_list(itb->items, last);
764                        itbn->items = eina_list_prepend(itbn->items, it2);
765                        itbn->count++;
766                        itbn->changed = EINA_TRUE;
767                     }
768                   it->wd->blocks =
769                     eina_inlist_remove(it->wd->blocks, EINA_INLIST_GET(itb));
770                   free(itb);
771                }
772           }
773      }
774 }
775
776 static void
777 _item_del(Elm_Genlist_Item *it)
778 {
779    Evas_Object *tob = it->wd->obj;
780
781    evas_event_freeze(evas_object_evas_get(tob));
782    elm_widget_item_pre_notify_del(it);
783    elm_genlist_item_subitems_clear(it);
784    it->wd->walking -= it->walking;
785    if (it->wd->show_item == it) it->wd->show_item = NULL;
786    if (it->selected) it->wd->selected = eina_list_remove(it->wd->selected, it);
787    if (it->realized) _item_unrealize(it, EINA_FALSE);
788    if (it->block) _item_block_del(it);
789    if ((!it->delete_me) && (it->itc->func.del))
790      it->itc->func.del((void *)it->base.data, it->base.widget);
791    it->delete_me = EINA_TRUE;
792    if (it->queued)
793      it->wd->queue = eina_list_remove(it->wd->queue, it);
794    if (it->wd->anchor_item == it)
795      {
796         it->wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
797         if (!it->wd->anchor_item)
798           it->wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
799      }
800    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
801    if (it->parent)
802      it->parent->items = eina_list_remove(it->parent->items, it);
803    if (it->flags & ELM_GENLIST_ITEM_GROUP)
804      it->wd->group_items = eina_list_remove(it->wd->group_items, it);
805    if (it->long_timer) ecore_timer_del(it->long_timer);
806    if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
807
808    if (it->tooltip.del_cb)
809      it->tooltip.del_cb((void *)it->tooltip.data, it->base.widget, it);
810
811    evas_event_thaw(evas_object_evas_get(tob));
812    evas_event_thaw_eval(evas_object_evas_get(tob));
813
814    elm_widget_item_del(it);
815 }
816
817 static void
818 _item_select(Elm_Genlist_Item *it)
819 {
820    if ((it->wd->no_select) || (it->delete_me) || (it->mode_view)) return;
821    if (it->selected)
822      {
823         if (it->wd->always_select) goto call;
824         return;
825      }
826    it->selected = EINA_TRUE;
827    it->wd->selected = eina_list_append(it->wd->selected, it);
828 call:
829    it->walking++;
830    it->wd->walking++;
831    if (it->func.func) it->func.func((void *)it->func.data, it->base.widget, it);
832    if (!it->delete_me)
833      evas_object_smart_callback_call(it->base.widget, SIG_SELECTED, it);
834    it->walking--;
835    it->wd->walking--;
836    if ((it->wd->clear_me) && (!it->wd->walking))
837      elm_genlist_clear(it->base.widget);
838    else
839      {
840         if ((!it->walking) && (it->delete_me))
841           {
842              if (!it->relcount) _item_del(it);
843           }
844      }
845    it->wd->last_selected_item = it;
846 }
847
848 static void
849 _item_unselect(Elm_Genlist_Item *it)
850 {
851    if ((it->delete_me) || (!it->selected)) return;
852    it->selected = EINA_FALSE;
853    it->wd->selected = eina_list_remove(it->wd->selected, it);
854    evas_object_smart_callback_call(it->base.widget, SIG_UNSELECTED, it);
855 }
856
857 static void
858 _mouse_move(void        *data,
859             Evas        *evas __UNUSED__,
860             Evas_Object *obj,
861             void        *event_info)
862 {
863    Elm_Genlist_Item *it = data;
864    Evas_Event_Mouse_Move *ev = event_info;
865    Evas_Coord minw = 0, minh = 0, x, y, dx, dy, adx, ady;
866    Evas_Coord ox, oy, ow, oh, it_scrl_y, y_pos;
867
868    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
869      {
870         if (!it->wd->on_hold)
871           {
872              it->wd->on_hold = EINA_TRUE;
873              if (!it->wd->wasselected)
874                {
875                   _item_unhighlight(it);
876                   _item_unselect(it);
877                }
878           }
879      }
880    if (it->wd->multitouched)
881      {
882         it->wd->cur_x = ev->cur.canvas.x;
883         it->wd->cur_y = ev->cur.canvas.y;
884         return;
885      }
886    if ((it->dragging) && (it->down))
887      {
888         if (it->wd->movements == SWIPE_MOVES) it->wd->swipe = EINA_TRUE;
889         else
890           {
891              it->wd->history[it->wd->movements].x = ev->cur.canvas.x;
892              it->wd->history[it->wd->movements].y = ev->cur.canvas.y;
893              if (abs((it->wd->history[it->wd->movements].x -
894                       it->wd->history[0].x)) > 40)
895                it->wd->swipe = EINA_TRUE;
896              else
897                it->wd->movements++;
898           }
899         if (it->long_timer)
900           {
901              ecore_timer_del(it->long_timer);
902              it->long_timer = NULL;
903           }
904         evas_object_smart_callback_call(it->base.widget, SIG_DRAG, it);
905         return;
906      }
907    if ((!it->down) /* || (it->wd->on_hold)*/ || (it->wd->longpressed))
908      {
909         if (it->long_timer)
910           {
911              ecore_timer_del(it->long_timer);
912              it->long_timer = NULL;
913           }
914         if ((it->wd->reorder_mode) && (it->wd->reorder_it))
915           {
916              evas_object_geometry_get(it->wd->pan_smart, &ox, &oy, &ow, &oh);
917              it_scrl_y = ev->cur.canvas.y - it->wd->reorder_it->dy;
918
919              if (!it->wd->reorder_start_y)
920                it->wd->reorder_start_y = it->block->y + it->y;
921
922              if (it_scrl_y < oy) y_pos = oy;
923              else if (it_scrl_y + it->wd->reorder_it->h > oy+oh)
924                 y_pos = oy + oh - it->wd->reorder_it->h;
925              else y_pos = it_scrl_y;
926
927              _item_position(it, it->base.view, it->scrl_x, y_pos);
928
929              if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
930              it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
931           }
932         return;
933      }
934    if (!it->display_only)
935      elm_coords_finger_size_adjust(1, &minw, 1, &minh);
936    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
937    x = ev->cur.canvas.x - x;
938    y = ev->cur.canvas.y - y;
939    dx = x - it->dx;
940    adx = dx;
941    if (adx < 0) adx = -dx;
942    dy = y - it->dy;
943    ady = dy;
944    if (ady < 0) ady = -dy;
945    minw /= 2;
946    minh /= 2;
947    if ((adx > minw) || (ady > minh))
948      {
949         it->dragging = EINA_TRUE;
950         if (it->long_timer)
951           {
952              ecore_timer_del(it->long_timer);
953              it->long_timer = NULL;
954           }
955         if (!it->wd->wasselected)
956           {
957              _item_unhighlight(it);
958              _item_unselect(it);
959           }
960         if (dy < 0)
961           {
962              if (ady > adx)
963                evas_object_smart_callback_call(it->base.widget,
964                                                SIG_DRAG_START_UP, it);
965              else
966                {
967                   if (dx < 0)
968                     evas_object_smart_callback_call(it->base.widget,
969                                                     SIG_DRAG_START_LEFT, it);
970                   else
971                     evas_object_smart_callback_call(it->base.widget,
972                                                     SIG_DRAG_START_RIGHT, it);
973                }
974           }
975         else
976           {
977              if (ady > adx)
978                evas_object_smart_callback_call(it->base.widget,
979                                                SIG_DRAG_START_DOWN, it);
980              else
981                {
982                   if (dx < 0)
983                     evas_object_smart_callback_call(it->base.widget,
984                                                     SIG_DRAG_START_LEFT, it);
985                   else
986                     evas_object_smart_callback_call(it->base.widget,
987                                                     SIG_DRAG_START_RIGHT, it);
988                }
989           }
990      }
991 }
992
993 static Eina_Bool
994 _long_press(void *data)
995 {
996    Elm_Genlist_Item *it = data, *it_tmp;
997    Eina_List *list, *l;
998
999    it->long_timer = NULL;
1000    if ((it->disabled) || (it->dragging) || (it->display_only))
1001      return ECORE_CALLBACK_CANCEL;
1002    it->wd->longpressed = EINA_TRUE;
1003    evas_object_smart_callback_call(it->base.widget, SIG_LONGPRESSED, it);
1004    if ((it->wd->reorder_mode) && (it->flags != ELM_GENLIST_ITEM_GROUP))
1005      {
1006         it->wd->reorder_it = it;
1007         it->wd->reorder_start_y = 0;
1008
1009         evas_object_raise(it->base.view);
1010         elm_smart_scroller_hold_set(it->wd->scr, EINA_TRUE);
1011
1012         list = elm_genlist_realized_items_get(it->wd->obj);
1013         EINA_LIST_FOREACH(list, l, it_tmp)
1014           {
1015              if (it != it_tmp) _item_unselect(it_tmp);
1016           }
1017         if (elm_genlist_item_expanded_get(it))
1018           {
1019              elm_genlist_item_expanded_set(it, EINA_FALSE);
1020              return ECORE_CALLBACK_RENEW;
1021           }
1022         edje_object_signal_emit(it->base.view, "elm,state,reorder,enabled", "elm");
1023      }
1024    return ECORE_CALLBACK_CANCEL;
1025 }
1026
1027 static void
1028 _swipe(Elm_Genlist_Item *it)
1029 {
1030    int i, sum = 0;
1031
1032    if (!it) return;
1033    if ((it->display_only) || (it->disabled)) return;
1034    it->wd->swipe = EINA_FALSE;
1035    for (i = 0; i < it->wd->movements; i++)
1036      {
1037         sum += it->wd->history[i].x;
1038         if (abs(it->wd->history[0].y - it->wd->history[i].y) > 10) return;
1039      }
1040
1041    sum /= it->wd->movements;
1042    if (abs(sum - it->wd->history[0].x) <= 10) return;
1043    evas_object_smart_callback_call(it->base.widget, SIG_SWIPE, it);
1044 }
1045
1046 static Eina_Bool
1047 _swipe_cancel(void *data)
1048 {
1049    Elm_Genlist_Item *it = data;
1050
1051    if (!it) return ECORE_CALLBACK_CANCEL;
1052    it->wd->swipe = EINA_FALSE;
1053    it->wd->movements = 0;
1054    return ECORE_CALLBACK_RENEW;
1055 }
1056
1057 static Eina_Bool
1058 _multi_cancel(void *data)
1059 {
1060    Widget_Data *wd = data;
1061
1062    if (!wd) return ECORE_CALLBACK_CANCEL;
1063    wd->multi_timeout = EINA_TRUE;
1064    return ECORE_CALLBACK_RENEW;
1065 }
1066
1067 static void
1068 _multi_touch_gesture_eval(void *data)
1069 {
1070    Elm_Genlist_Item *it = data;
1071
1072    it->wd->multitouched = EINA_FALSE;
1073    if (it->wd->multi_timer)
1074      {
1075         ecore_timer_del(it->wd->multi_timer);
1076         it->wd->multi_timer = NULL;
1077      }
1078    if (it->wd->multi_timeout)
1079      {
1080         it->wd->multi_timeout = EINA_FALSE;
1081         return;
1082      }
1083
1084    Evas_Coord minw = 0, minh = 0;
1085    Evas_Coord off_x, off_y, off_mx, off_my;
1086
1087    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
1088    off_x = abs(it->wd->cur_x - it->wd->prev_x);
1089    off_y = abs(it->wd->cur_y - it->wd->prev_y);
1090    off_mx = abs(it->wd->cur_mx - it->wd->prev_mx);
1091    off_my = abs(it->wd->cur_my - it->wd->prev_my);
1092
1093    if (((off_x > minw) || (off_y > minh)) && ((off_mx > minw) || (off_my > minh)))
1094      {
1095         if ((off_x + off_mx) > (off_y + off_my))
1096           {
1097              if ((it->wd->cur_x > it->wd->prev_x) && (it->wd->cur_mx > it->wd->prev_mx))
1098                evas_object_smart_callback_call(it->base.widget,
1099                                                SIG_MULTI_SWIPE_RIGHT, it);
1100              else if ((it->wd->cur_x < it->wd->prev_x) && (it->wd->cur_mx < it->wd->prev_mx))
1101                evas_object_smart_callback_call(it->base.widget,
1102                                                SIG_MULTI_SWIPE_LEFT, it);
1103              else if (abs(it->wd->cur_x - it->wd->cur_mx) > abs(it->wd->prev_x - it->wd->prev_mx))
1104                evas_object_smart_callback_call(it->base.widget,
1105                                                SIG_MULTI_PINCH_OUT, it);
1106              else
1107                evas_object_smart_callback_call(it->base.widget,
1108                                                SIG_MULTI_PINCH_IN, it);
1109           }
1110         else
1111           {
1112              if ((it->wd->cur_y > it->wd->prev_y) && (it->wd->cur_my > it->wd->prev_my))
1113                evas_object_smart_callback_call(it->base.widget,
1114                                                SIG_MULTI_SWIPE_DOWN, it);
1115              else if ((it->wd->cur_y < it->wd->prev_y) && (it->wd->cur_my < it->wd->prev_my))
1116                evas_object_smart_callback_call(it->base.widget,
1117                                                SIG_MULTI_SWIPE_UP, it);
1118              else if (abs(it->wd->cur_y - it->wd->cur_my) > abs(it->wd->prev_y - it->wd->prev_my))
1119                evas_object_smart_callback_call(it->base.widget,
1120                                                SIG_MULTI_PINCH_OUT, it);
1121              else
1122                evas_object_smart_callback_call(it->base.widget,
1123                                                SIG_MULTI_PINCH_IN, it);
1124           }
1125      }
1126    it->wd->multi_timeout = EINA_FALSE;
1127 }
1128
1129 static void
1130 _multi_down(void        *data,
1131             Evas        *evas __UNUSED__,
1132             Evas_Object *obj __UNUSED__,
1133             void        *event_info)
1134 {
1135    Elm_Genlist_Item *it = data;
1136    Evas_Event_Multi_Down *ev = event_info;
1137
1138    if ((it->wd->multi_device != 0) || (it->wd->multitouched) || (it->wd->multi_timeout)) return;
1139    it->wd->multi_device = ev->device;
1140    it->wd->multi_down = EINA_TRUE;
1141    it->wd->multitouched = EINA_TRUE;
1142    it->wd->prev_mx = ev->canvas.x;
1143    it->wd->prev_my = ev->canvas.y;
1144    if (!it->wd->wasselected)
1145      {
1146         _item_unhighlight(it);
1147         _item_unselect(it);
1148      }
1149    it->wd->wasselected = EINA_FALSE;
1150    it->wd->longpressed = EINA_FALSE;
1151    if (it->long_timer)
1152      {
1153         ecore_timer_del(it->long_timer);
1154         it->long_timer = NULL;
1155      }
1156    if (it->dragging)
1157      {
1158         it->dragging = EINA_FALSE;
1159         evas_object_smart_callback_call(it->base.widget, SIG_DRAG_STOP, it);
1160      }
1161    if (it->swipe_timer)
1162      {
1163         ecore_timer_del(it->swipe_timer);
1164         it->swipe_timer = NULL;
1165      }
1166    if (it->wd->on_hold)
1167      {
1168         it->wd->swipe = EINA_FALSE;
1169         it->wd->movements = 0;
1170         it->wd->on_hold = EINA_FALSE;
1171      }
1172 }
1173
1174 static void
1175 _multi_up(void        *data,
1176           Evas        *evas __UNUSED__,
1177           Evas_Object *obj __UNUSED__,
1178           void        *event_info)
1179 {
1180    Elm_Genlist_Item *it = data;
1181    Evas_Event_Multi_Up *ev = event_info;
1182
1183    if (it->wd->multi_device != ev->device) return;
1184    it->wd->multi_device = 0;
1185    it->wd->multi_down = EINA_FALSE;
1186    if (it->wd->mouse_down) return;
1187    _multi_touch_gesture_eval(data);
1188 }
1189
1190 static void
1191 _multi_move(void        *data,
1192             Evas        *evas __UNUSED__,
1193             Evas_Object *obj __UNUSED__,
1194             void        *event_info)
1195 {
1196    Elm_Genlist_Item *it = data;
1197    Evas_Event_Multi_Move *ev = event_info;
1198
1199    if (it->wd->multi_device != ev->device) return;
1200    it->wd->cur_mx = ev->cur.canvas.x;
1201    it->wd->cur_my = ev->cur.canvas.y;
1202 }
1203
1204 static void
1205 _mouse_down(void        *data,
1206             Evas        *evas __UNUSED__,
1207             Evas_Object *obj,
1208             void        *event_info)
1209 {
1210    Elm_Genlist_Item *it = data;
1211    Evas_Event_Mouse_Down *ev = event_info;
1212    Evas_Coord x, y;
1213
1214    if (ev->button != 1) return;
1215    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1216      {
1217         it->wd->on_hold = EINA_TRUE;
1218      }
1219
1220    it->down = EINA_TRUE;
1221    it->dragging = EINA_FALSE;
1222    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
1223    it->dx = ev->canvas.x - x;
1224    it->dy = ev->canvas.y - y;
1225    it->wd->mouse_down = EINA_TRUE;
1226    if (!it->wd->multitouched)
1227      {
1228         it->wd->prev_x = ev->canvas.x;
1229         it->wd->prev_y = ev->canvas.y;
1230         it->wd->multi_timeout = EINA_FALSE;
1231         if (it->wd->multi_timer) ecore_timer_del(it->wd->multi_timer);
1232         it->wd->multi_timer = ecore_timer_add(1, _multi_cancel, it->wd);
1233      }
1234    it->wd->longpressed = EINA_FALSE;
1235    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) it->wd->on_hold = EINA_TRUE;
1236    else it->wd->on_hold = EINA_FALSE;
1237    if (it->wd->on_hold) return;
1238    it->wd->wasselected = it->selected;
1239    _item_highlight(it);
1240    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1241      if ((!it->disabled) && (!it->display_only))
1242        {
1243           evas_object_smart_callback_call(it->base.widget, SIG_CLICKED_DOUBLE, it);
1244           evas_object_smart_callback_call(it->base.widget, SIG_ACTIVATED, it);
1245        }
1246    if (it->long_timer) ecore_timer_del(it->long_timer);
1247    if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
1248    it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
1249    if (it->realized)
1250      it->long_timer = ecore_timer_add(it->wd->longpress_timeout, _long_press,
1251                                       it);
1252    else
1253      it->long_timer = NULL;
1254    it->wd->swipe = EINA_FALSE;
1255    it->wd->movements = 0;
1256 }
1257
1258 static void
1259 _mouse_up(void        *data,
1260           Evas        *evas __UNUSED__,
1261           Evas_Object *obj __UNUSED__,
1262           void        *event_info)
1263 {
1264    Elm_Genlist_Item *it = data;
1265    Evas_Event_Mouse_Up *ev = event_info;
1266    Eina_Bool dragged = EINA_FALSE;
1267
1268    if (ev->button != 1) return;
1269    it->down = EINA_FALSE;
1270    it->wd->mouse_down = EINA_FALSE;
1271    if (it->wd->multitouched)
1272      {
1273         if ((!it->wd->multi) && (!it->selected) && (it->highlighted)) _item_unhighlight(it);
1274         if (it->wd->multi_down) return;
1275         _multi_touch_gesture_eval(data);
1276         return;
1277      }
1278    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) it->wd->on_hold = EINA_TRUE;
1279    else it->wd->on_hold = EINA_FALSE;
1280    if (it->long_timer)
1281      {
1282         ecore_timer_del(it->long_timer);
1283         it->long_timer = NULL;
1284      }
1285    if (it->dragging)
1286      {
1287         it->dragging = EINA_FALSE;
1288         evas_object_smart_callback_call(it->base.widget, SIG_DRAG_STOP, it);
1289         dragged = 1;
1290      }
1291    if (it->swipe_timer)
1292      {
1293         ecore_timer_del(it->swipe_timer);
1294         it->swipe_timer = NULL;
1295      }
1296    if (it->wd->multi_timer)
1297      {
1298         ecore_timer_del(it->wd->multi_timer);
1299         it->wd->multi_timer = NULL;
1300         it->wd->multi_timeout = EINA_FALSE;
1301      }
1302    if (it->wd->on_hold)
1303      {
1304         if (it->wd->swipe) _swipe(data);
1305         it->wd->longpressed = EINA_FALSE;
1306         it->wd->on_hold = EINA_FALSE;
1307         return;
1308      }
1309    if ((it->wd->reorder_mode) && (it->wd->reorder_it))
1310      {
1311         Evas_Coord it_scrl_y = ev->canvas.y - it->wd->reorder_it->dy;
1312
1313         if (it->wd->reorder_rel)
1314           {
1315              if (it->wd->reorder_it->parent == it->wd->reorder_rel->parent)
1316                {
1317                   if (it_scrl_y <= it->wd->reorder_rel->scrl_y)
1318                      _item_move_before(it->wd->reorder_it, it->wd->reorder_rel);
1319                   else
1320                      _item_move_after(it->wd->reorder_it, it->wd->reorder_rel);
1321                }
1322              else
1323                {
1324                   if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
1325                   it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
1326                }
1327           }
1328         edje_object_signal_emit(it->base.view, "elm,state,reorder,disabled", "elm");
1329         it->wd->reorder_it = it->wd->reorder_rel = NULL;
1330         elm_smart_scroller_hold_set(it->wd->scr, EINA_FALSE);
1331      }
1332    if (it->wd->longpressed)
1333      {
1334         it->wd->longpressed = EINA_FALSE;
1335         if (!it->wd->wasselected)
1336           {
1337              _item_unhighlight(it);
1338              _item_unselect(it);
1339           }
1340         it->wd->wasselected = EINA_FALSE;
1341         return;
1342      }
1343    if (dragged)
1344      {
1345         if (it->want_unrealize)
1346           {
1347              _item_unrealize(it, EINA_FALSE);
1348              if (it->block->want_unrealize)
1349                _item_block_unrealize(it->block);
1350           }
1351      }
1352    if ((it->disabled) || (dragged) || (it->display_only)) return;
1353    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1354    if (it->wd->multi)
1355      {
1356         if (!it->selected)
1357           {
1358              _item_highlight(it);
1359              _item_select(it);
1360           }
1361         else
1362           {
1363              _item_unhighlight(it);
1364              _item_unselect(it);
1365           }
1366      }
1367    else
1368      {
1369         if (!it->selected)
1370           {
1371              Widget_Data *wd = it->wd;
1372              if (wd)
1373                {
1374                   while (wd->selected)
1375                     {
1376                        _item_unhighlight(wd->selected->data);
1377                        _item_unselect(wd->selected->data);
1378                     }
1379                }
1380           }
1381         else
1382           {
1383              const Eina_List *l, *l_next;
1384              Elm_Genlist_Item *it2;
1385
1386              EINA_LIST_FOREACH_SAFE(it->wd->selected, l, l_next, it2)
1387                 if (it2 != it)
1388                   {
1389                      _item_unhighlight(it2);
1390                      _item_unselect(it2);
1391                   }
1392              //_item_highlight(it);
1393              //_item_select(it);
1394           }
1395         _item_highlight(it);
1396         _item_select(it);
1397      }
1398 }
1399
1400 static void
1401 _signal_expand_toggle(void        *data,
1402                       Evas_Object *obj __UNUSED__,
1403                       const char  *emission __UNUSED__,
1404                       const char  *source __UNUSED__)
1405 {
1406    Elm_Genlist_Item *it = data;
1407
1408    if (it->expanded)
1409      evas_object_smart_callback_call(it->base.widget, SIG_CONTRACT_REQUEST, it);
1410    else
1411      evas_object_smart_callback_call(it->base.widget, SIG_EXPAND_REQUEST, it);
1412 }
1413
1414 static void
1415 _signal_expand(void        *data,
1416                Evas_Object *obj __UNUSED__,
1417                const char  *emission __UNUSED__,
1418                const char  *source __UNUSED__)
1419 {
1420    Elm_Genlist_Item *it = data;
1421
1422    if (!it->expanded)
1423      evas_object_smart_callback_call(it->base.widget, SIG_EXPAND_REQUEST, it);
1424 }
1425
1426 static void
1427 _signal_contract(void        *data,
1428                  Evas_Object *obj __UNUSED__,
1429                  const char  *emission __UNUSED__,
1430                  const char  *source __UNUSED__)
1431 {
1432    Elm_Genlist_Item *it = data;
1433
1434    if (it->expanded)
1435      evas_object_smart_callback_call(it->base.widget, SIG_CONTRACT_REQUEST, it);
1436 }
1437
1438 static Eina_Bool
1439 _scr_hold_timer_cb(void *data)
1440 {
1441    if (!data) return ECORE_CALLBACK_CANCEL;
1442    Widget_Data *wd = data;
1443    elm_smart_scroller_hold_set(wd->scr, EINA_FALSE);
1444    wd->scr_hold_timer = NULL;
1445    return ECORE_CALLBACK_CANCEL;
1446 }
1447
1448 static void
1449 _mode_finished_signal_cb(void        *data,
1450                          Evas_Object *obj,
1451                          const char  *emission __UNUSED__,
1452                          const char  *source __UNUSED__)
1453 {
1454    if (!data) return;
1455    if (!obj) return;
1456    Elm_Genlist_Item *it = data;
1457    if ((it->delete_me) || (!it->realized) || (!it->mode_view)) return;
1458    char buf[1024];
1459    Evas *te = evas_object_evas_get(obj);
1460
1461    evas_event_freeze(te);
1462    it->nocache = EINA_FALSE;
1463    _mode_item_unrealize(it);
1464    snprintf(buf, sizeof(buf), "elm,state,%s,passive,finished", it->wd->mode_type);
1465    edje_object_signal_callback_del_full(obj, buf, "elm", _mode_finished_signal_cb, it);
1466    evas_event_thaw(te);
1467    evas_event_thaw_eval(te);
1468 }
1469
1470 static void
1471 _item_cache_clean(Widget_Data *wd)
1472 {
1473    evas_event_freeze(evas_object_evas_get(wd->obj));
1474    while ((wd->item_cache) && (wd->item_cache_count > wd->item_cache_max))
1475      {
1476         Item_Cache *itc;
1477
1478         itc = EINA_INLIST_CONTAINER_GET(wd->item_cache->last, Item_Cache);
1479         wd->item_cache = eina_inlist_remove(wd->item_cache,
1480                                             wd->item_cache->last);
1481         wd->item_cache_count--;
1482         if (itc->spacer) evas_object_del(itc->spacer);
1483         if (itc->base_view) evas_object_del(itc->base_view);
1484         if (itc->item_style) eina_stringshare_del(itc->item_style);
1485         free(itc);
1486      }
1487    evas_event_thaw(evas_object_evas_get(wd->obj));
1488    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
1489 }
1490
1491 static void
1492 _item_cache_zero(Widget_Data *wd)
1493 {
1494    int pmax = wd->item_cache_max;
1495    wd->item_cache_max = 0;
1496    _item_cache_clean(wd);
1497    wd->item_cache_max = pmax;
1498 }
1499
1500 static void
1501 _item_cache_add(Elm_Genlist_Item *it)
1502 {
1503    Item_Cache *itc;
1504
1505    evas_event_freeze(evas_object_evas_get(it->wd->obj));
1506    if (it->wd->item_cache_max <= 0)
1507      {
1508         evas_object_del(it->base.view);
1509         it->base.view = NULL;
1510         evas_object_del(it->spacer);
1511         it->spacer = NULL;
1512         evas_event_thaw(evas_object_evas_get(it->wd->obj));
1513         evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
1514         return;
1515      }
1516
1517    it->wd->item_cache_count++;
1518    itc = calloc(1, sizeof(Item_Cache));
1519    it->wd->item_cache = eina_inlist_prepend(it->wd->item_cache,
1520                                             EINA_INLIST_GET(itc));
1521    itc->spacer = it->spacer;
1522    it->spacer = NULL;
1523    itc->base_view = it->base.view;
1524    it->base.view = NULL;
1525    evas_object_hide(itc->base_view);
1526    evas_object_move(itc->base_view, -9999, -9999);
1527    itc->item_style = eina_stringshare_add(it->itc->item_style);
1528    if (it->flags & ELM_GENLIST_ITEM_SUBITEMS) itc->tree = 1;
1529    itc->compress = (it->wd->compress);
1530    itc->selected = it->selected;
1531    itc->disabled = it->disabled;
1532    itc->expanded = it->expanded;
1533    if (it->long_timer)
1534      {
1535         ecore_timer_del(it->long_timer);
1536         it->long_timer = NULL;
1537      }
1538    if (it->swipe_timer)
1539      {
1540         ecore_timer_del(it->swipe_timer);
1541         it->swipe_timer = NULL;
1542      }
1543    // FIXME: other callbacks?
1544    edje_object_signal_callback_del_full(itc->base_view,
1545                                         "elm,action,expand,toggle",
1546                                         "elm", _signal_expand_toggle, it);
1547    edje_object_signal_callback_del_full(itc->base_view, "elm,action,expand",
1548                                         "elm",
1549                                         _signal_expand, it);
1550    edje_object_signal_callback_del_full(itc->base_view, "elm,action,contract",
1551                                         "elm", _signal_contract, it);
1552    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MOUSE_DOWN,
1553                                        _mouse_down, it);
1554    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MOUSE_UP,
1555                                        _mouse_up, it);
1556    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MOUSE_MOVE,
1557                                        _mouse_move, it);
1558    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MULTI_DOWN,
1559                                        _multi_down, it);
1560    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MULTI_UP,
1561                                        _multi_up, it);
1562    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MULTI_MOVE,
1563                                        _multi_move, it);
1564    _item_cache_clean(it->wd);
1565    evas_event_thaw(evas_object_evas_get(it->wd->obj));
1566    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
1567 }
1568
1569 static Item_Cache *
1570 _item_cache_find(Elm_Genlist_Item *it)
1571 {
1572    Item_Cache *itc;
1573    Eina_Bool tree = 0;
1574
1575    if (it->flags & ELM_GENLIST_ITEM_SUBITEMS) tree = 1;
1576    EINA_INLIST_FOREACH(it->wd->item_cache, itc)
1577      {
1578         if ((itc->selected) || (itc->disabled) || (itc->expanded))
1579           continue;
1580         if ((itc->tree == tree) &&
1581             (itc->compress == it->wd->compress) &&
1582             (!strcmp(it->itc->item_style, itc->item_style)))
1583           {
1584              it->wd->item_cache = eina_inlist_remove(it->wd->item_cache,
1585                                                      EINA_INLIST_GET(itc));
1586              it->wd->item_cache_count--;
1587              return itc;
1588           }
1589      }
1590    return NULL;
1591 }
1592
1593 static void
1594 _elm_genlist_item_odd_even_update(Elm_Genlist_Item *it)
1595 {
1596    if (!it->nostacking)
1597      {
1598         if ((it->order_num_in & 0x1) ^ it->stacking_even)
1599           evas_object_lower(it->base.view);
1600         else
1601           evas_object_raise(it->base.view);
1602      }
1603
1604    if (it->order_num_in & 0x1)
1605      edje_object_signal_emit(it->base.view, "elm,state,odd", "elm");
1606    else
1607      edje_object_signal_emit(it->base.view, "elm,state,even", "elm");
1608 }
1609
1610 static void
1611 _elm_genlist_item_state_update(Elm_Genlist_Item *it, Item_Cache *itc)
1612 {
1613    if (itc)
1614      {
1615         if (it->selected != itc->selected)
1616           {
1617              if (it->selected)
1618                edje_object_signal_emit(it->base.view,
1619                                        "elm,state,selected", "elm");
1620           }
1621         if (it->disabled != itc->disabled)
1622           {
1623              if (it->disabled)
1624                edje_object_signal_emit(it->base.view,
1625                                        "elm,state,disabled", "elm");
1626           }
1627         if (it->expanded != itc->expanded)
1628           {
1629              if (it->expanded)
1630                edje_object_signal_emit(it->base.view,
1631                                        "elm,state,expanded", "elm");
1632           }
1633      }
1634    else
1635      {
1636         if (it->selected)
1637           edje_object_signal_emit(it->base.view,
1638                                   "elm,state,selected", "elm");
1639         if (it->disabled)
1640           edje_object_signal_emit(it->base.view,
1641                                   "elm,state,disabled", "elm");
1642         if (it->expanded)
1643           edje_object_signal_emit(it->base.view,
1644                                   "elm,state,expanded", "elm");
1645      }
1646 }
1647
1648 static void
1649 _item_cache_free(Item_Cache *itc)
1650 {
1651    if (itc->spacer) evas_object_del(itc->spacer);
1652    if (itc->base_view) evas_object_del(itc->base_view);
1653    if (itc->item_style) eina_stringshare_del(itc->item_style);
1654    free(itc);
1655 }
1656
1657 static void
1658 _item_label_realize(Elm_Genlist_Item *it,
1659                     Evas_Object *target,
1660                     Eina_List **source)
1661 {
1662    if (it->itc->func.label_get)
1663      {
1664         const Eina_List *l;
1665         const char *key;
1666
1667         *source = elm_widget_stringlist_get(edje_object_data_get(target, "labels"));
1668         EINA_LIST_FOREACH(*source, l, key)
1669           {
1670              char *s = it->itc->func.label_get
1671                 ((void *)it->base.data, it->base.widget, key);
1672
1673              if (s)
1674                {
1675                   edje_object_part_text_set(target, key, s);
1676                   free(s);
1677                }
1678              else
1679                {
1680                   edje_object_part_text_set(target, key, "");
1681                }
1682           }
1683      }
1684 }
1685
1686 static Eina_List *
1687 _item_icon_realize(Elm_Genlist_Item *it,
1688                    Evas_Object *target,
1689                    Eina_List **source)
1690 {
1691    Eina_List *res = NULL;
1692
1693    if (it->itc->func.icon_get)
1694      {
1695         const Eina_List *l;
1696         const char *key;
1697
1698         *source = elm_widget_stringlist_get(edje_object_data_get(target, "icons"));
1699         EINA_LIST_FOREACH(*source, l, key)
1700           {
1701              Evas_Object *ic = it->itc->func.icon_get
1702                 ((void *)it->base.data, it->base.widget, key);
1703
1704              if (ic)
1705                {
1706                   res = eina_list_append(res, ic);
1707                   edje_object_part_swallow(target, key, ic);
1708                   evas_object_show(ic);
1709                   elm_widget_sub_object_add(it->base.widget, ic);
1710                   if (it->disabled)
1711                     elm_widget_disabled_set(ic, EINA_TRUE);
1712                }
1713           }
1714      }
1715
1716    return res;
1717 }
1718
1719 static void
1720 _item_state_realize(Elm_Genlist_Item *it,
1721                     Evas_Object *target,
1722                     Eina_List **source)
1723 {
1724    if (it->itc->func.state_get)
1725      {
1726         const Eina_List *l;
1727         const char *key;
1728         char buf[4096];
1729
1730         *source = elm_widget_stringlist_get(edje_object_data_get(target, "states"));
1731         EINA_LIST_FOREACH(*source, l, key)
1732           {
1733              Eina_Bool on = it->itc->func.state_get
1734                 ((void *)it->base.data, it->base.widget, key);
1735
1736              if (on)
1737                {
1738                   snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1739                   edje_object_signal_emit(target, buf, "elm");
1740                }
1741              else
1742                {
1743                   snprintf(buf, sizeof(buf), "elm,state,%s,passive", key);
1744                   edje_object_signal_emit(target, buf, "elm");
1745                }
1746           }
1747      }
1748 }
1749
1750 static void
1751 _item_realize(Elm_Genlist_Item *it,
1752               int               in,
1753               Eina_Bool         calc)
1754 {
1755    Elm_Genlist_Item *it2;
1756    const char *treesize;
1757    char buf[1024];
1758    int depth, tsize = 20;
1759    Item_Cache *itc = NULL;
1760
1761    if (it->delete_me) return;
1762    //evas_event_freeze(evas_object_evas_get(it->wd->obj));
1763    if (it->realized)
1764      {
1765         if (it->order_num_in != in)
1766           {
1767              it->order_num_in = in;
1768              _elm_genlist_item_odd_even_update(it);
1769              _elm_genlist_item_state_update(it, NULL);
1770           }
1771         //evas_event_thaw(evas_object_evas_get(it->wd->obj));
1772         //evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
1773         return;
1774      }
1775    it->order_num_in = in;
1776
1777    if (it->nocache)
1778      it->nocache = EINA_FALSE;
1779    else
1780      itc = _item_cache_find(it);
1781    if (itc)
1782      {
1783         it->base.view = itc->base_view;
1784         itc->base_view = NULL;
1785         it->spacer = itc->spacer;
1786         itc->spacer = NULL;
1787      }
1788    else
1789      {
1790         const char *stacking_even;
1791         const char *stacking;
1792
1793         it->base.view = edje_object_add(evas_object_evas_get(it->base.widget));
1794         edje_object_scale_set(it->base.view,
1795                               elm_widget_scale_get(it->base.widget) *
1796                               _elm_config->scale);
1797         evas_object_smart_member_add(it->base.view, it->wd->pan_smart);
1798         elm_widget_sub_object_add(it->base.widget, it->base.view);
1799
1800         if (it->flags & ELM_GENLIST_ITEM_SUBITEMS)
1801           strncpy(buf, "tree", sizeof(buf));
1802         else strncpy(buf, "item", sizeof(buf));
1803         if (it->wd->compress)
1804           strncat(buf, "_compress", sizeof(buf) - strlen(buf));
1805
1806         strncat(buf, "/", sizeof(buf) - strlen(buf));
1807         strncat(buf, it->itc->item_style, sizeof(buf) - strlen(buf));
1808
1809         _elm_theme_object_set(it->base.widget, it->base.view, "genlist", buf,
1810                               elm_widget_style_get(it->base.widget));
1811
1812         stacking_even = edje_object_data_get(it->base.view, "stacking_even");
1813         if (!stacking_even) stacking_even = "above";
1814         it->stacking_even = !!strcmp("above", stacking_even);
1815
1816         stacking = edje_object_data_get(it->base.view, "stacking");
1817         if (!stacking) stacking = "yes";
1818         it->nostacking = !!strcmp("yes", stacking);
1819
1820         edje_object_mirrored_set(it->base.view,
1821                                  elm_widget_mirrored_get(it->base.widget));
1822         it->spacer =
1823           evas_object_rectangle_add(evas_object_evas_get(it->base.widget));
1824         evas_object_color_set(it->spacer, 0, 0, 0, 0);
1825         elm_widget_sub_object_add(it->base.widget, it->spacer);
1826      }
1827
1828    _elm_genlist_item_odd_even_update(it);
1829
1830    for (it2 = it, depth = 0; it2->parent; it2 = it2->parent)
1831      {
1832         if (it2->parent->flags != ELM_GENLIST_ITEM_GROUP) depth += 1;
1833      }
1834    it->expanded_depth = depth;
1835    treesize = edje_object_data_get(it->base.view, "treesize");
1836    if (treesize) tsize = atoi(treesize);
1837    evas_object_size_hint_min_set(it->spacer,
1838                                  (depth * tsize) * _elm_config->scale, 1);
1839    edje_object_part_swallow(it->base.view, "elm.swallow.pad", it->spacer);
1840    if (!calc)
1841      {
1842         edje_object_signal_callback_add(it->base.view,
1843                                         "elm,action,expand,toggle",
1844                                         "elm", _signal_expand_toggle, it);
1845         edje_object_signal_callback_add(it->base.view, "elm,action,expand",
1846                                         "elm", _signal_expand, it);
1847         edje_object_signal_callback_add(it->base.view, "elm,action,contract",
1848                                         "elm", _signal_contract, it);
1849         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_DOWN,
1850                                        _mouse_down, it);
1851         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_UP,
1852                                        _mouse_up, it);
1853         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_MOVE,
1854                                        _mouse_move, it);
1855         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_DOWN,
1856                                        _multi_down, it);
1857         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_UP,
1858                                        _multi_up, it);
1859         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_MOVE,
1860                                        _multi_move, it);
1861
1862         _elm_genlist_item_state_update(it, itc);
1863      }
1864
1865    if ((calc) && (it->wd->homogeneous) &&
1866        ((it->wd->item_width) ||
1867         ((it->wd->item_width) && (it->wd->group_item_width))))
1868      {
1869         /* homogenous genlist shortcut */
1870         if (!it->mincalcd)
1871           {
1872              if (it->flags & ELM_GENLIST_ITEM_GROUP)
1873                {
1874                   it->w = it->minw = it->wd->group_item_width;
1875                   it->h = it->minh = it->wd->group_item_height;
1876                }
1877              else
1878                {
1879                   it->w = it->minw = it->wd->item_width;
1880                   it->h = it->minh = it->wd->item_height;
1881                }
1882              it->mincalcd = EINA_TRUE;
1883           }
1884      }
1885    else
1886      {
1887         /* FIXME: If you see that assert, please notify us and we
1888            will clean our mess */
1889         assert(eina_list_count(it->icon_objs) == 0);
1890
1891         _item_label_realize(it, it->base.view, &it->labels);
1892         it->icon_objs = _item_icon_realize(it, it->base.view, &it->icons);
1893         _item_state_realize(it, it->base.view, &it->states);
1894
1895         if (!it->mincalcd)
1896           {
1897              Evas_Coord mw = -1, mh = -1;
1898
1899              if (!it->display_only)
1900                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1901              if (it->wd->height_for_width) mw = it->wd->prev_viewport_w;
1902              edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw,
1903                                                   mh);
1904              if (!it->display_only)
1905                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1906              it->w = it->minw = mw;
1907              it->h = it->minh = mh;
1908              it->mincalcd = EINA_TRUE;
1909
1910              if ((!it->wd->group_item_width) && (it->flags == ELM_GENLIST_ITEM_GROUP))
1911                {
1912                   it->wd->group_item_width = mw;
1913                   it->wd->group_item_height = mh;
1914                }
1915              else if ((!it->wd->item_width) && (it->flags == ELM_GENLIST_ITEM_NONE))
1916                {
1917                   it->wd->item_width = mw;
1918                   it->wd->item_height = mh;
1919                }
1920           }
1921         if (!calc) evas_object_show(it->base.view);
1922      }
1923
1924    if (it->tooltip.content_cb)
1925      {
1926         elm_widget_item_tooltip_content_cb_set(it,
1927                                                it->tooltip.content_cb,
1928                                                it->tooltip.data, NULL);
1929         elm_widget_item_tooltip_style_set(it, it->tooltip.style);
1930      }
1931
1932    if (it->mouse_cursor)
1933      elm_widget_item_cursor_set(it, it->mouse_cursor);
1934
1935    it->realized = EINA_TRUE;
1936    it->want_unrealize = EINA_FALSE;
1937
1938    if (itc) _item_cache_free(itc);
1939    //evas_event_thaw(evas_object_evas_get(it->wd->obj));
1940    //evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
1941    if (!calc)
1942      evas_object_smart_callback_call(it->base.widget, SIG_REALIZED, it);
1943    edje_object_message_signal_process(it->base.view);
1944 }
1945
1946 static void
1947 _item_unrealize(Elm_Genlist_Item *it,
1948                 Eina_Bool         calc)
1949 {
1950    Evas_Object *icon;
1951
1952    if (!it->realized) return;
1953    if (it->wd->reorder_it == it) return;
1954    evas_event_freeze(evas_object_evas_get(it->wd->obj));
1955    if (!calc)
1956      evas_object_smart_callback_call(it->base.widget, SIG_UNREALIZED, it);
1957    if (it->long_timer)
1958      {
1959         ecore_timer_del(it->long_timer);
1960         it->long_timer = NULL;
1961      }
1962    if (it->nocache)
1963      {
1964         evas_object_del(it->base.view);
1965         it->base.view = NULL;
1966         evas_object_del(it->spacer);
1967         it->spacer = NULL;
1968      }
1969    else
1970      {
1971         edje_object_mirrored_set(it->base.view,
1972                                  elm_widget_mirrored_get(it->base.widget));
1973         edje_object_scale_set(it->base.view,
1974                               elm_widget_scale_get(it->base.widget)
1975                               * _elm_config->scale);
1976         _item_cache_add(it);
1977      }
1978    elm_widget_stringlist_free(it->labels);
1979    it->labels = NULL;
1980    elm_widget_stringlist_free(it->icons);
1981    it->icons = NULL;
1982    elm_widget_stringlist_free(it->states);
1983
1984    EINA_LIST_FREE(it->icon_objs, icon)
1985      evas_object_del(icon);
1986
1987    _mode_item_unrealize(it);
1988    it->states = NULL;
1989    it->realized = EINA_FALSE;
1990    it->want_unrealize = EINA_FALSE;
1991    evas_event_thaw(evas_object_evas_get(it->wd->obj));
1992    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
1993 }
1994
1995 static Eina_Bool
1996 _item_block_recalc(Item_Block *itb,
1997                    int         in,
1998                    Eina_Bool   qadd)
1999 {
2000    const Eina_List *l;
2001    Elm_Genlist_Item *it;
2002    Evas_Coord minw = 0, minh = 0;
2003    Eina_Bool showme = EINA_FALSE, changed = EINA_FALSE;
2004    Evas_Coord y = 0;
2005
2006    //evas_event_freeze(evas_object_evas_get(itb->wd->obj));
2007    itb->num = in;
2008    EINA_LIST_FOREACH(itb->items, l, it)
2009      {
2010         if (it->delete_me) continue;
2011         showme |= it->showme;
2012         if (!itb->realized)
2013           {
2014              if (qadd)
2015                {
2016                   if (!it->mincalcd) changed = EINA_TRUE;
2017                   if (changed)
2018                     {
2019                        _item_realize(it, in, EINA_TRUE);
2020                        _item_unrealize(it, EINA_TRUE);
2021                     }
2022                }
2023              else
2024                {
2025                   _item_realize(it, in, EINA_TRUE);
2026                   _item_unrealize(it, EINA_TRUE);
2027                }
2028           }
2029         else
2030           _item_realize(it, in, EINA_FALSE);
2031         minh += it->minh;
2032         if (minw < it->minw) minw = it->minw;
2033         in++;
2034         it->x = 0;
2035         it->y = y;
2036         y += it->h;
2037      }
2038    itb->minw = minw;
2039    itb->minh = minh;
2040    itb->changed = EINA_FALSE;
2041    //evas_event_thaw(evas_object_evas_get(itb->wd->obj));
2042    //evas_event_thaw_eval(evas_object_evas_get(itb->wd->obj));
2043    return showme;
2044 }
2045
2046 static void
2047 _item_block_realize(Item_Block *itb)
2048 {
2049    if (itb->realized) return;
2050    itb->realized = EINA_TRUE;
2051    itb->want_unrealize = EINA_FALSE;
2052 }
2053
2054 static void
2055 _item_block_unrealize(Item_Block *itb)
2056 {
2057    const Eina_List *l;
2058    Elm_Genlist_Item *it;
2059    Eina_Bool dragging = EINA_FALSE;
2060
2061    if (!itb->realized) return;
2062    evas_event_freeze(evas_object_evas_get(itb->wd->obj));
2063    EINA_LIST_FOREACH(itb->items, l, it)
2064      {
2065         if (it->flags != ELM_GENLIST_ITEM_GROUP)
2066           {
2067              if (it->dragging)
2068                {
2069                   dragging = EINA_TRUE;
2070                   it->want_unrealize = EINA_TRUE;
2071                }
2072              else
2073                _item_unrealize(it, EINA_FALSE);
2074           }
2075      }
2076    if (!dragging)
2077      {
2078         itb->realized = EINA_FALSE;
2079         itb->want_unrealize = EINA_TRUE;
2080      }
2081    else
2082      itb->want_unrealize = EINA_FALSE;
2083    evas_event_thaw(evas_object_evas_get(itb->wd->obj));
2084    evas_event_thaw_eval(evas_object_evas_get(itb->wd->obj));
2085 }
2086
2087 static int
2088 _get_space_for_reorder_item(Elm_Genlist_Item *it)
2089 {
2090    Evas_Coord rox, roy, row, roh, oy, oh;
2091    Eina_Bool top = EINA_FALSE;
2092    Elm_Genlist_Item *reorder_it = it->wd->reorder_it;
2093    if (!reorder_it) return 0;
2094
2095    evas_object_geometry_get(it->wd->pan_smart, NULL, &oy, NULL, &oh);
2096    evas_object_geometry_get(it->wd->reorder_it->base.view, &rox, &roy, &row, &roh);
2097
2098    if ((it->wd->reorder_start_y < it->block->y) &&
2099        (roy - oy + (roh / 2) >= it->block->y - it->wd->pan_y))
2100      {
2101         it->block->reorder_offset = it->wd->reorder_it->h * -1;
2102         if (it->block->count == 1)
2103            it->wd->reorder_rel = it;
2104      }
2105    else if ((it->wd->reorder_start_y >= it->block->y) &&
2106             (roy - oy + (roh / 2) <= it->block->y - it->wd->pan_y))
2107      {
2108         it->block->reorder_offset = it->wd->reorder_it->h;
2109      }
2110    else
2111      it->block->reorder_offset = 0;
2112
2113    it->scrl_y += it->block->reorder_offset;
2114
2115    top = (ELM_RECTS_INTERSECT(it->scrl_x, it->scrl_y, it->w, it->h,
2116                               rox, roy + (roh / 2), row, 1));
2117    if (top)
2118      {
2119         it->wd->reorder_rel = it;
2120         it->scrl_y += it->wd->reorder_it->h;
2121         return it->wd->reorder_it->h;
2122      }
2123    else
2124      return 0;
2125 }
2126
2127 static Eina_Bool
2128 _reorder_move_animator_cb(void *data)
2129 {
2130    Elm_Genlist_Item *it = data;
2131    Eina_Bool down = EINA_FALSE;
2132    double t;
2133    int y, dy = it->h / 10 * _elm_config->scale, diff;
2134
2135    t = ((0.0 > (t = ecore_loop_time_get()-it->wd->start_time)) ? 0.0 : t);
2136
2137    if (t <= REORDER_EFFECT_TIME) y = (1 * sin((t / REORDER_EFFECT_TIME) * (M_PI / 2)) * dy);
2138    else y = dy;
2139
2140    diff = abs(it->old_scrl_y - it->scrl_y);
2141    if (diff > it->h) y = diff / 2;
2142
2143    if (it->old_scrl_y < it->scrl_y)
2144      {
2145         it->old_scrl_y += y;
2146         down = EINA_TRUE;
2147      }
2148    else if (it->old_scrl_y > it->scrl_y)
2149      {
2150         it->old_scrl_y -= y;
2151         down = EINA_FALSE;
2152      }
2153    _item_position(it, it->base.view, it->scrl_x, it->old_scrl_y);
2154    _group_items_recalc(it->wd);
2155
2156    if ((it->wd->reorder_pan_move) ||
2157        (down && it->old_scrl_y >= it->scrl_y) ||
2158        (!down && it->old_scrl_y <= it->scrl_y))
2159      {
2160         it->old_scrl_y = it->scrl_y;
2161         it->move_effect_enabled = EINA_FALSE;
2162         it->wd->reorder_move_animator = NULL;
2163         return ECORE_CALLBACK_CANCEL;
2164      }
2165    return ECORE_CALLBACK_RENEW;
2166 }
2167
2168 static void
2169 _item_position(Elm_Genlist_Item *it,
2170                Evas_Object      *view,
2171                Evas_Coord        it_x,
2172                Evas_Coord        it_y)
2173 {
2174    if (!it) return;
2175    if (!view) return;
2176
2177    evas_event_freeze(evas_object_evas_get(it->wd->obj));
2178    evas_object_resize(view, it->w, it->h);
2179    evas_object_move(view, it_x, it_y);
2180    evas_object_show(view);
2181    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2182    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2183 }
2184
2185 static void
2186 _item_block_position(Item_Block *itb,
2187                      int         in)
2188 {
2189    const Eina_List *l;
2190    Elm_Genlist_Item *it;
2191    Elm_Genlist_Item *git;
2192    Evas_Coord y = 0, ox, oy, ow, oh, cvx, cvy, cvw, cvh;
2193    int vis;
2194
2195    evas_event_freeze(evas_object_evas_get(itb->wd->obj));
2196    evas_object_geometry_get(itb->wd->pan_smart, &ox, &oy, &ow, &oh);
2197    evas_output_viewport_get(evas_object_evas_get(itb->wd->obj), &cvx, &cvy,
2198                             &cvw, &cvh);
2199    EINA_LIST_FOREACH(itb->items, l, it)
2200      {
2201         if (it->delete_me) continue;
2202         else if (it->wd->reorder_it == it) continue;
2203         it->x = 0;
2204         it->y = y;
2205         it->w = itb->w;
2206         it->scrl_x = itb->x + it->x - it->wd->pan_x + ox;
2207         it->scrl_y = itb->y + it->y - it->wd->pan_y + oy;
2208
2209         vis = (ELM_RECTS_INTERSECT(it->scrl_x, it->scrl_y, it->w, it->h,
2210                                    cvx, cvy, cvw, cvh));
2211         if (it->flags != ELM_GENLIST_ITEM_GROUP)
2212           {
2213              if ((itb->realized) && (!it->realized))
2214                {
2215                   if (vis) _item_realize(it, in, EINA_FALSE);
2216                }
2217              if (it->realized)
2218                {
2219                   if (vis)
2220                     {
2221                        if (it->wd->reorder_mode)
2222                           y += _get_space_for_reorder_item(it);
2223                        git = it->group_item;
2224                        if (git)
2225                          {
2226                             if (git->scrl_y < oy)
2227                               git->scrl_y = oy;
2228                             if ((git->scrl_y + git->h) > (it->scrl_y + it->h))
2229                               git->scrl_y = (it->scrl_y + it->h) - git->h;
2230                             git->want_realize = EINA_TRUE;
2231                          }
2232                        if ((it->wd->reorder_it) && (it->old_scrl_y != it->scrl_y))
2233                          {
2234                             if (!it->move_effect_enabled)
2235                               {
2236                                  it->move_effect_enabled = EINA_TRUE;
2237                                  it->wd->reorder_move_animator =
2238                                     ecore_animator_add(
2239                                        _reorder_move_animator_cb, it);
2240                               }
2241                          }
2242                        if (!it->move_effect_enabled)
2243                          {
2244                               {
2245                                  if (it->mode_view)
2246                                    _item_position(it, it->mode_view, it->scrl_x,
2247                                                   it->scrl_y);
2248                                  else
2249                                    _item_position(it, it->base.view, it->scrl_x,
2250                                                   it->scrl_y);
2251                               }
2252                             it->old_scrl_y = it->scrl_y;
2253                          }
2254                     }
2255                   else
2256                     {
2257                        if (!it->dragging) _item_unrealize(it, EINA_FALSE);
2258                     }
2259                }
2260              in++;
2261           }
2262         else
2263           {
2264              if (vis) it->want_realize = EINA_TRUE;
2265           }
2266         y += it->h;
2267      }
2268    evas_event_thaw(evas_object_evas_get(itb->wd->obj));
2269    evas_event_thaw_eval(evas_object_evas_get(itb->wd->obj));
2270 }
2271
2272 static void
2273 _group_items_recalc(void *data)
2274 {
2275    Widget_Data *wd = data;
2276    Eina_List *l;
2277    Elm_Genlist_Item *git;
2278
2279    evas_event_freeze(evas_object_evas_get(wd->obj));
2280    EINA_LIST_FOREACH(wd->group_items, l, git)
2281      {
2282         if (git->want_realize)
2283           {
2284              if (!git->realized)
2285                _item_realize(git, 0, EINA_FALSE);
2286              evas_object_resize(git->base.view, wd->minw, git->h);
2287              evas_object_move(git->base.view, git->scrl_x, git->scrl_y);
2288              evas_object_show(git->base.view);
2289              evas_object_raise(git->base.view);
2290           }
2291         else if (!git->want_realize && git->realized)
2292           {
2293              if (!git->dragging)
2294                _item_unrealize(git, EINA_FALSE);
2295           }
2296      }
2297    evas_event_thaw(evas_object_evas_get(wd->obj));
2298    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
2299 }
2300
2301 static Eina_Bool
2302 _must_recalc_idler(void *data)
2303 {
2304    Widget_Data *wd = data;
2305    if (wd->calc_job) ecore_job_del(wd->calc_job);
2306    wd->calc_job = ecore_job_add(_calc_job, wd);
2307    wd->must_recalc_idler = NULL;
2308    return ECORE_CALLBACK_CANCEL;
2309 }
2310
2311 static void
2312 _calc_job(void *data)
2313 {
2314    Widget_Data *wd = data;
2315    Item_Block *itb, *chb = NULL;
2316    Evas_Coord minw = -1, minh = 0, y = 0, ow;
2317    int in = 0;
2318    double t0, t;
2319    Eina_Bool minw_change = EINA_FALSE, changed = EINA_FALSE;
2320    Eina_Bool did_must_recalc = EINA_FALSE;
2321    if (!wd) return;
2322
2323    t0 = ecore_time_get();
2324    evas_object_geometry_get(wd->pan_smart, NULL, NULL, &ow, &wd->h);
2325    if (wd->w != ow)
2326      wd->w = ow;
2327
2328    evas_event_freeze(evas_object_evas_get(wd->obj));
2329    EINA_INLIST_FOREACH(wd->blocks, itb)
2330      {
2331         Eina_Bool showme = EINA_FALSE;
2332
2333         itb->num = in;
2334         showme = itb->showme;
2335         itb->showme = EINA_FALSE;
2336         if (chb)
2337           {
2338              if (itb->realized) _item_block_unrealize(itb);
2339           }
2340         if ((itb->changed) || (changed) ||
2341             ((itb->must_recalc) && (!did_must_recalc)))
2342           {
2343              if ((changed) || (itb->must_recalc))
2344                {
2345                   Eina_List *l;
2346                   Elm_Genlist_Item *it;
2347                   EINA_LIST_FOREACH(itb->items, l, it)
2348                     if (it->mincalcd) it->mincalcd = EINA_FALSE;
2349                   itb->changed = EINA_TRUE;
2350                   if (itb->must_recalc) did_must_recalc = EINA_TRUE;
2351                   itb->must_recalc = EINA_FALSE;
2352                }
2353              if (itb->realized) _item_block_unrealize(itb);
2354              showme = _item_block_recalc(itb, in, EINA_FALSE);
2355              chb = itb;
2356           }
2357         itb->y = y;
2358         itb->x = 0;
2359         minh += itb->minh;
2360         if (minw == -1) minw = itb->minw;
2361         else if ((!itb->must_recalc) && (minw < itb->minw))
2362           {
2363              minw = itb->minw;
2364              minw_change = EINA_TRUE;
2365           }
2366         itb->w = minw;
2367         itb->h = itb->minh;
2368         y += itb->h;
2369         in += itb->count;
2370         if ((showme) && (wd->show_item) && (!wd->show_item->queued))
2371           {
2372              wd->show_item->showme = EINA_FALSE;
2373              if (wd->bring_in)
2374                elm_smart_scroller_region_bring_in(wd->scr,
2375                                                   wd->show_item->x +
2376                                                   wd->show_item->block->x,
2377                                                   wd->show_item->y +
2378                                                   wd->show_item->block->y,
2379                                                   wd->show_item->block->w,
2380                                                   wd->show_item->h);
2381              else
2382                elm_smart_scroller_child_region_show(wd->scr,
2383                                                     wd->show_item->x +
2384                                                     wd->show_item->block->x,
2385                                                     wd->show_item->y +
2386                                                     wd->show_item->block->y,
2387                                                     wd->show_item->block->w,
2388                                                     wd->show_item->h);
2389              wd->show_item = NULL;
2390           }
2391      }
2392    if (minw_change)
2393      {
2394         EINA_INLIST_FOREACH(wd->blocks, itb)
2395           {
2396              itb->minw = minw;
2397              itb->w = itb->minw;
2398           }
2399      }
2400    if ((chb) && (EINA_INLIST_GET(chb)->next))
2401      {
2402         EINA_INLIST_FOREACH(EINA_INLIST_GET(chb)->next, itb)
2403           {
2404              if (itb->realized) _item_block_unrealize(itb);
2405           }
2406      }
2407    wd->realminw = minw;
2408    if (minw < wd->w) minw = wd->w;
2409    if ((minw != wd->minw) || (minh != wd->minh))
2410      {
2411         wd->minw = minw;
2412         wd->minh = minh;
2413         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2414         _sizing_eval(wd->obj);
2415         if ((wd->anchor_item) && (wd->anchor_item->block) && (!wd->auto_scroll_enabled))
2416           {
2417              Elm_Genlist_Item *it;
2418              Evas_Coord it_y;
2419
2420              it = wd->anchor_item;
2421              it_y = wd->anchor_y;
2422              elm_smart_scroller_child_pos_set(wd->scr, wd->pan_x,
2423                                               it->block->y + it->y + it_y);
2424              wd->anchor_item = it;
2425              wd->anchor_y = it_y;
2426           }
2427      }
2428    t = ecore_time_get();
2429    if (did_must_recalc)
2430      {
2431         if (!wd->must_recalc_idler)
2432           wd->must_recalc_idler = ecore_idler_add(_must_recalc_idler, wd);
2433      }
2434    wd->calc_job = NULL;
2435    evas_object_smart_changed(wd->pan_smart);
2436    evas_event_thaw(evas_object_evas_get(wd->obj));
2437    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
2438 }
2439
2440 static void
2441 _update_job(void *data)
2442 {
2443    Widget_Data *wd = data;
2444    Eina_List *l2;
2445    Item_Block *itb;
2446    int num, num0;
2447    Eina_Bool position = EINA_FALSE, recalc = EINA_FALSE;
2448    if (!wd) return;
2449    wd->update_job = NULL;
2450    num = 0;
2451
2452    evas_event_freeze(evas_object_evas_get(wd->obj));
2453    EINA_INLIST_FOREACH(wd->blocks, itb)
2454      {
2455         Evas_Coord itminw, itminh;
2456         Elm_Genlist_Item *it;
2457
2458         if (!itb->updateme)
2459           {
2460              num += itb->count;
2461              if (position)
2462                _item_block_position(itb, num);
2463              continue;
2464           }
2465         num0 = num;
2466         recalc = EINA_FALSE;
2467         EINA_LIST_FOREACH(itb->items, l2, it)
2468           {
2469              if (it->updateme)
2470                {
2471                   itminw = it->minw;
2472                   itminh = it->minh;
2473
2474                   it->updateme = EINA_FALSE;
2475                   if (it->realized)
2476                     {
2477                        _item_unrealize(it, EINA_FALSE);
2478                        _item_realize(it, num, EINA_FALSE);
2479                        position = EINA_TRUE;
2480                     }
2481                   else
2482                     {
2483                        _item_realize(it, num, EINA_TRUE);
2484                        _item_unrealize(it, EINA_TRUE);
2485                     }
2486                   if ((it->minw != itminw) || (it->minh != itminh))
2487                     recalc = EINA_TRUE;
2488                }
2489              num++;
2490           }
2491         itb->updateme = EINA_FALSE;
2492         if (recalc)
2493           {
2494              position = EINA_TRUE;
2495              itb->changed = EINA_TRUE;
2496              _item_block_recalc(itb, num0, EINA_FALSE);
2497              _item_block_position(itb, num0);
2498           }
2499      }
2500    if (position)
2501      {
2502         if (wd->calc_job) ecore_job_del(wd->calc_job);
2503         wd->calc_job = ecore_job_add(_calc_job, wd);
2504      }
2505    evas_event_thaw(evas_object_evas_get(wd->obj));
2506    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
2507 }
2508
2509 static void
2510 _pan_set(Evas_Object *obj,
2511          Evas_Coord   x,
2512          Evas_Coord   y)
2513 {
2514    Pan *sd = evas_object_smart_data_get(obj);
2515    Item_Block *itb;
2516
2517    //   Evas_Coord ow, oh;
2518    //   evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2519    //   ow = sd->wd->minw - ow;
2520    //   if (ow < 0) ow = 0;
2521    //   oh = sd->wd->minh - oh;
2522    //   if (oh < 0) oh = 0;
2523    //   if (x < 0) x = 0;
2524    //   if (y < 0) y = 0;
2525    //   if (x > ow) x = ow;
2526    //   if (y > oh) y = oh;
2527    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2528    sd->wd->pan_x = x;
2529    sd->wd->pan_y = y;
2530
2531    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2532      {
2533         if ((itb->y + itb->h) > y)
2534           {
2535              Elm_Genlist_Item *it;
2536              Eina_List *l2;
2537
2538              EINA_LIST_FOREACH(itb->items, l2, it)
2539                {
2540                   if ((itb->y + it->y) >= y)
2541                     {
2542                        sd->wd->anchor_item = it;
2543                        sd->wd->anchor_y = -(itb->y + it->y - y);
2544                        goto done;
2545                     }
2546                }
2547           }
2548      }
2549 done:
2550    if (!sd->wd->reorder_move_animator) evas_object_smart_changed(obj);
2551 }
2552
2553 static void
2554 _pan_get(Evas_Object *obj,
2555          Evas_Coord  *x,
2556          Evas_Coord  *y)
2557 {
2558    Pan *sd = evas_object_smart_data_get(obj);
2559
2560    if (x) *x = sd->wd->pan_x;
2561    if (y) *y = sd->wd->pan_y;
2562 }
2563
2564 static void
2565 _pan_max_get(Evas_Object *obj,
2566              Evas_Coord  *x,
2567              Evas_Coord  *y)
2568 {
2569    Pan *sd = evas_object_smart_data_get(obj);
2570    Evas_Coord ow, oh;
2571
2572    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2573    ow = sd->wd->minw - ow;
2574    if (ow < 0) ow = 0;
2575    oh = sd->wd->minh - oh;
2576    if (oh < 0) oh = 0;
2577    if (x) *x = ow;
2578    if (y) *y = oh;
2579 }
2580
2581 static void
2582 _pan_min_get(Evas_Object *obj __UNUSED__,
2583              Evas_Coord  *x,
2584              Evas_Coord  *y)
2585 {
2586    if (x) *x = 0;
2587    if (y) *y = 0;
2588 }
2589
2590 static void
2591 _pan_child_size_get(Evas_Object *obj,
2592                     Evas_Coord  *w,
2593                     Evas_Coord  *h)
2594 {
2595    Pan *sd = evas_object_smart_data_get(obj);
2596
2597    if (w) *w = sd->wd->minw;
2598    if (h) *h = sd->wd->minh;
2599 }
2600
2601 static void
2602 _pan_add(Evas_Object *obj)
2603 {
2604    Pan *sd;
2605    Evas_Object_Smart_Clipped_Data *cd;
2606
2607    _pan_sc.add(obj);
2608    cd = evas_object_smart_data_get(obj);
2609    sd = ELM_NEW(Pan);
2610    if (!sd) return;
2611    sd->__clipped_data = *cd;
2612    free(cd);
2613    evas_object_smart_data_set(obj, sd);
2614 }
2615
2616 static void
2617 _pan_del(Evas_Object *obj)
2618 {
2619    Pan *sd = evas_object_smart_data_get(obj);
2620
2621    if (!sd) return;
2622    if (sd->resize_job)
2623      {
2624         ecore_job_del(sd->resize_job);
2625         sd->resize_job = NULL;
2626      }
2627    _pan_sc.del(obj);
2628 }
2629
2630 static void
2631 _pan_resize_job(void *data)
2632 {
2633    Pan *sd = data;
2634    _sizing_eval(sd->wd->obj);
2635    sd->resize_job = NULL;
2636 }
2637
2638 static void
2639 _pan_resize(Evas_Object *obj,
2640             Evas_Coord   w,
2641             Evas_Coord   h)
2642 {
2643    Pan *sd = evas_object_smart_data_get(obj);
2644    Evas_Coord ow, oh;
2645
2646    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2647    if ((ow == w) && (oh == h)) return;
2648    if ((sd->wd->height_for_width) && (ow != w))
2649      {
2650         if (sd->resize_job) ecore_job_del(sd->resize_job);
2651         sd->resize_job = ecore_job_add(_pan_resize_job, sd);
2652      }
2653    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2654    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2655 }
2656
2657 static void
2658 _pan_calculate(Evas_Object *obj)
2659 {
2660    Pan *sd = evas_object_smart_data_get(obj);
2661    Item_Block *itb;
2662    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh;
2663    int in = 0;
2664    Elm_Genlist_Item *git;
2665    Eina_List *l;
2666
2667    evas_event_freeze(evas_object_evas_get(obj));
2668    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2669    evas_output_viewport_get(evas_object_evas_get(obj), &cvx, &cvy, &cvw, &cvh);
2670    EINA_LIST_FOREACH(sd->wd->group_items, l, git)
2671      {
2672         git->want_realize = EINA_FALSE;
2673      }
2674    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2675      {
2676         itb->w = sd->wd->minw;
2677         if (ELM_RECTS_INTERSECT(itb->x - sd->wd->pan_x + ox,
2678                                 itb->y - sd->wd->pan_y + oy,
2679                                 itb->w, itb->h,
2680                                 cvx, cvy, cvw, cvh))
2681           {
2682              if ((!itb->realized) || (itb->changed))
2683                _item_block_realize(itb);
2684              _item_block_position(itb, in);
2685           }
2686         else
2687           {
2688              if (itb->realized) _item_block_unrealize(itb);
2689           }
2690         in += itb->count;
2691      }
2692    if ((!sd->wd->reorder_it) || (sd->wd->reorder_pan_move))
2693       _group_items_recalc(sd->wd);
2694    if ((sd->wd->reorder_mode) && (sd->wd->reorder_it))
2695      {
2696         if (sd->wd->pan_y != sd->wd->old_pan_y)
2697            sd->wd->reorder_pan_move = EINA_TRUE;
2698         else sd->wd->reorder_pan_move = EINA_FALSE;
2699         evas_object_raise(sd->wd->reorder_it->base.view);
2700         sd->wd->old_pan_y = sd->wd->pan_y;
2701         sd->wd->start_time = ecore_loop_time_get();
2702      }
2703    _item_auto_scroll(sd->wd);
2704    evas_event_thaw(evas_object_evas_get(obj));
2705    evas_event_thaw_eval(evas_object_evas_get(obj));
2706 }
2707
2708 static void
2709 _pan_move(Evas_Object *obj,
2710           Evas_Coord   x __UNUSED__,
2711           Evas_Coord   y __UNUSED__)
2712 {
2713    Pan *sd = evas_object_smart_data_get(obj);
2714
2715    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2716    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2717 }
2718
2719 static void
2720 _hold_on(void        *data __UNUSED__,
2721          Evas_Object *obj,
2722          void        *event_info __UNUSED__)
2723 {
2724    Widget_Data *wd = elm_widget_data_get(obj);
2725    if (!wd) return;
2726    elm_smart_scroller_hold_set(wd->scr, 1);
2727 }
2728
2729 static void
2730 _hold_off(void        *data __UNUSED__,
2731           Evas_Object *obj,
2732           void        *event_info __UNUSED__)
2733 {
2734    Widget_Data *wd = elm_widget_data_get(obj);
2735    if (!wd) return;
2736    elm_smart_scroller_hold_set(wd->scr, 0);
2737 }
2738
2739 static void
2740 _freeze_on(void        *data __UNUSED__,
2741            Evas_Object *obj,
2742            void        *event_info __UNUSED__)
2743 {
2744    Widget_Data *wd = elm_widget_data_get(obj);
2745    if (!wd) return;
2746    elm_smart_scroller_freeze_set(wd->scr, 1);
2747 }
2748
2749 static void
2750 _freeze_off(void        *data __UNUSED__,
2751             Evas_Object *obj,
2752             void        *event_info __UNUSED__)
2753 {
2754    Widget_Data *wd = elm_widget_data_get(obj);
2755    if (!wd) return;
2756    elm_smart_scroller_freeze_set(wd->scr, 0);
2757 }
2758
2759 static void
2760 _scroll_edge_left(void        *data,
2761                   Evas_Object *scr __UNUSED__,
2762                   void        *event_info __UNUSED__)
2763 {
2764    Evas_Object *obj = data;
2765    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_LEFT, NULL);
2766 }
2767
2768 static void
2769 _scroll_edge_right(void        *data,
2770                    Evas_Object *scr __UNUSED__,
2771                    void        *event_info __UNUSED__)
2772 {
2773    Evas_Object *obj = data;
2774    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_RIGHT, NULL);
2775 }
2776
2777 static void
2778 _scroll_edge_top(void        *data,
2779                  Evas_Object *scr __UNUSED__,
2780                  void        *event_info __UNUSED__)
2781 {
2782    Evas_Object *obj = data;
2783    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_TOP, NULL);
2784 }
2785
2786 static void
2787 _scroll_edge_bottom(void        *data,
2788                     Evas_Object *scr __UNUSED__,
2789                     void        *event_info __UNUSED__)
2790 {
2791    Evas_Object *obj = data;
2792    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_BOTTOM, NULL);
2793 }
2794
2795 static void
2796 _mode_item_realize(Elm_Genlist_Item *it)
2797 {
2798    char buf[1024];
2799
2800    if ((it->mode_view) || (it->delete_me)) return;
2801
2802    evas_event_freeze(evas_object_evas_get(it->wd->obj));
2803    it->mode_view = edje_object_add(evas_object_evas_get(it->base.widget));
2804    edje_object_scale_set(it->mode_view,
2805                          elm_widget_scale_get(it->base.widget) *
2806                          _elm_config->scale);
2807    evas_object_smart_member_add(it->mode_view, it->wd->pan_smart);
2808    elm_widget_sub_object_add(it->base.widget, it->mode_view);
2809
2810    strncpy(buf, "item", sizeof(buf));
2811    if (it->wd->compress)
2812      strncat(buf, "_compress", sizeof(buf) - strlen(buf));
2813
2814    if (it->order_num_in & 0x1) strncat(buf, "_odd", sizeof(buf) - strlen(buf));
2815    strncat(buf, "/", sizeof(buf) - strlen(buf));
2816    strncat(buf, it->itc->mode_item_style, sizeof(buf) - strlen(buf));
2817
2818    _elm_theme_object_set(it->base.widget, it->mode_view, "genlist", buf,
2819                          elm_widget_style_get(it->base.widget));
2820    edje_object_mirrored_set(it->mode_view,
2821                             elm_widget_mirrored_get(it->base.widget));
2822
2823    /* signal callback add */
2824    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_DOWN,
2825                                   _mouse_down, it);
2826    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_UP,
2827                                   _mouse_up, it);
2828    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_MOVE,
2829                                   _mouse_move, it);
2830
2831    /* label_get, icon_get, state_get */
2832    /* FIXME: If you see that assert, please notify us and we
2833       will clean our mess */
2834    assert(eina_list_count(it->mode_icon_objs) == 0);
2835
2836    _item_label_realize(it, it->mode_view, &it->mode_labels);
2837    it->mode_icon_objs = _item_icon_realize(it,
2838                                            it->mode_view,
2839                                            &it->mode_icons);
2840    _item_state_realize(it, it->mode_view, &it->mode_states);
2841
2842    edje_object_part_swallow(it->mode_view,
2843                             edje_object_data_get(it->mode_view, "mode_part"),
2844                             it->base.view);
2845
2846    it->want_unrealize = EINA_FALSE;
2847    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2848    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2849 }
2850
2851 static void
2852 _mode_item_unrealize(Elm_Genlist_Item *it)
2853 {
2854    Widget_Data *wd = it->wd;
2855    Evas_Object *icon;
2856    if (!it->mode_view) return;
2857
2858    evas_event_freeze(evas_object_evas_get(it->wd->obj));
2859    elm_widget_stringlist_free(it->mode_labels);
2860    it->mode_labels = NULL;
2861    elm_widget_stringlist_free(it->mode_icons);
2862    it->mode_icons = NULL;
2863    elm_widget_stringlist_free(it->mode_states);
2864
2865    EINA_LIST_FREE(it->mode_icon_objs, icon)
2866      evas_object_del(icon);
2867
2868    edje_object_part_unswallow(it->mode_view, it->base.view);
2869    evas_object_smart_member_add(it->base.view, wd->pan_smart);
2870    evas_object_del(it->mode_view);
2871    it->mode_view = NULL;
2872
2873    if (wd->mode_item == it)
2874      wd->mode_item = NULL;
2875    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2876    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2877 }
2878
2879 static void
2880 _item_mode_set(Elm_Genlist_Item *it)
2881 {
2882    if (!it) return;
2883    Widget_Data *wd = it->wd;
2884    if (!wd) return;
2885    char buf[1024];
2886
2887    wd->mode_item = it;
2888    it->nocache = EINA_TRUE;
2889
2890    if (wd->scr_hold_timer)
2891      {
2892         ecore_timer_del(wd->scr_hold_timer);
2893         wd->scr_hold_timer = NULL;
2894      }
2895    elm_smart_scroller_hold_set(wd->scr, EINA_TRUE);
2896    wd->scr_hold_timer = ecore_timer_add(0.1, _scr_hold_timer_cb, wd);
2897
2898    evas_event_freeze(evas_object_evas_get(it->wd->obj));
2899    _mode_item_realize(it);
2900    _item_position(it, it->mode_view, it->scrl_x, it->scrl_y);
2901    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2902    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2903
2904    snprintf(buf, sizeof(buf), "elm,state,%s,active", wd->mode_type);
2905    edje_object_signal_emit(it->mode_view, buf, "elm");
2906 }
2907
2908 static void
2909 _item_mode_unset(Widget_Data *wd)
2910 {
2911    if (!wd) return;
2912    if (!wd->mode_item) return;
2913    char buf[1024], buf2[1024];
2914    Elm_Genlist_Item *it;
2915
2916    it = wd->mode_item;
2917    it->nocache = EINA_TRUE;
2918
2919    snprintf(buf, sizeof(buf), "elm,state,%s,passive", wd->mode_type);
2920    snprintf(buf2, sizeof(buf2), "elm,state,%s,passive,finished", wd->mode_type);
2921
2922    edje_object_signal_emit(it->mode_view, buf, "elm");
2923    edje_object_signal_callback_add(it->mode_view, buf2, "elm", _mode_finished_signal_cb, it);
2924
2925    wd->mode_item = NULL;
2926 }
2927
2928 static void
2929 _item_auto_scroll(Widget_Data *wd)
2930 {
2931    if (!wd) return;
2932    Elm_Genlist_Item  *it;
2933    Eina_List *l;
2934    Evas_Coord ox, oy, ow, oh;
2935
2936    if ((wd->expanded_item) && (wd->auto_scroll_enabled))
2937      {
2938         evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
2939         if (wd->expanded_item->scrl_y > (oh + oy) / 2)
2940           {
2941              EINA_LIST_FOREACH(wd->expanded_item->items, l, it)
2942                 elm_genlist_item_bring_in(it);
2943           }
2944         wd->auto_scroll_enabled = EINA_FALSE;
2945      }
2946 }
2947
2948 EAPI Evas_Object *
2949 elm_genlist_add(Evas_Object *parent)
2950 {
2951    Evas_Object *obj;
2952    Evas *e;
2953    Widget_Data *wd;
2954    Evas_Coord minw, minh;
2955    static Evas_Smart *smart = NULL;
2956
2957    if (!smart)
2958      {
2959         static Evas_Smart_Class sc;
2960
2961         evas_object_smart_clipped_smart_set(&_pan_sc);
2962         sc = _pan_sc;
2963         sc.name = "elm_genlist_pan";
2964         sc.version = EVAS_SMART_CLASS_VERSION;
2965         sc.add = _pan_add;
2966         sc.del = _pan_del;
2967         sc.resize = _pan_resize;
2968         sc.move = _pan_move;
2969         sc.calculate = _pan_calculate;
2970         if (!(smart = evas_smart_class_new(&sc))) return NULL;
2971      }
2972
2973    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2974
2975    ELM_SET_WIDTYPE(widtype, "genlist");
2976    elm_widget_type_set(obj, "genlist");
2977    elm_widget_sub_object_add(parent, obj);
2978    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2979    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2980    elm_widget_data_set(obj, wd);
2981    elm_widget_del_hook_set(obj, _del_hook);
2982    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2983    elm_widget_theme_hook_set(obj, _theme_hook);
2984    elm_widget_can_focus_set(obj, EINA_TRUE);
2985    elm_widget_event_hook_set(obj, _event_hook);
2986    elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
2987
2988    wd->scr = elm_smart_scroller_add(e);
2989    elm_smart_scroller_widget_set(wd->scr, obj);
2990    elm_smart_scroller_object_theme_set(obj, wd->scr, "genlist", "base",
2991                                        elm_widget_style_get(obj));
2992    elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
2993                                        _elm_config->thumbscroll_bounce_enable);
2994    elm_widget_resize_object_set(obj, wd->scr);
2995
2996    evas_object_smart_callback_add(wd->scr, "edge,left", _scroll_edge_left, obj);
2997    evas_object_smart_callback_add(wd->scr, "edge,right", _scroll_edge_right,
2998                                   obj);
2999    evas_object_smart_callback_add(wd->scr, "edge,top", _scroll_edge_top, obj);
3000    evas_object_smart_callback_add(wd->scr, "edge,bottom", _scroll_edge_bottom,
3001                                   obj);
3002
3003    wd->obj = obj;
3004    wd->mode = ELM_LIST_SCROLL;
3005    wd->max_items_per_block = MAX_ITEMS_PER_BLOCK;
3006    wd->item_cache_max = wd->max_items_per_block * 2;
3007    wd->longpress_timeout = _elm_config->longpress_timeout;
3008
3009    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
3010    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
3011    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
3012    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
3013
3014    wd->pan_smart = evas_object_smart_add(e, smart);
3015    wd->pan = evas_object_smart_data_get(wd->pan_smart);
3016    wd->pan->wd = wd;
3017
3018    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
3019                                      _pan_set, _pan_get, _pan_max_get,
3020                                      _pan_min_get, _pan_child_size_get);
3021
3022    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
3023                              &minw, &minh);
3024    evas_object_size_hint_min_set(obj, minw, minh);
3025
3026    evas_object_smart_callbacks_descriptions_set(obj, _signals);
3027
3028    _mirrored_set(obj, elm_widget_mirrored_get(obj));
3029    _sizing_eval(obj);
3030    return obj;
3031 }
3032
3033 static Elm_Genlist_Item *
3034 _item_new(Widget_Data                  *wd,
3035           const Elm_Genlist_Item_Class *itc,
3036           const void                   *data,
3037           Elm_Genlist_Item             *parent,
3038           Elm_Genlist_Item_Flags        flags,
3039           Evas_Smart_Cb                 func,
3040           const void                   *func_data)
3041 {
3042    Elm_Genlist_Item *it;
3043
3044    it = elm_widget_item_new(wd->obj, Elm_Genlist_Item);
3045    if (!it) return NULL;
3046    it->wd = wd;
3047    it->itc = itc;
3048    it->base.data = data;
3049    it->parent = parent;
3050    it->flags = flags;
3051    it->func.func = func;
3052    it->func.data = func_data;
3053    it->mouse_cursor = NULL;
3054    it->expanded_depth = 0;
3055    return it;
3056 }
3057
3058 static void
3059 _item_block_add(Widget_Data      *wd,
3060                 Elm_Genlist_Item *it)
3061 {
3062    Item_Block *itb = NULL;
3063
3064    if (!it->rel)
3065      {
3066 newblock:
3067         if (it->rel)
3068           {
3069              itb = calloc(1, sizeof(Item_Block));
3070              if (!itb) return;
3071              itb->wd = wd;
3072              if (!it->rel->block)
3073                {
3074                   wd->blocks =
3075                     eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
3076                   itb->items = eina_list_append(itb->items, it);
3077                }
3078              else
3079                {
3080                   if (it->before)
3081                     {
3082                        wd->blocks = eina_inlist_prepend_relative
3083                            (wd->blocks, EINA_INLIST_GET(itb),
3084                            EINA_INLIST_GET(it->rel->block));
3085                        itb->items =
3086                          eina_list_prepend_relative(itb->items, it, it->rel);
3087                     }
3088                   else
3089                     {
3090                        wd->blocks = eina_inlist_append_relative
3091                            (wd->blocks, EINA_INLIST_GET(itb),
3092                            EINA_INLIST_GET(it->rel->block));
3093                        itb->items =
3094                          eina_list_append_relative(itb->items, it, it->rel);
3095                     }
3096                }
3097           }
3098         else
3099           {
3100              if (it->before)
3101                {
3102                   if (wd->blocks)
3103                     {
3104                        itb = (Item_Block *)(wd->blocks);
3105                        if (itb->count >= wd->max_items_per_block)
3106                          {
3107                             itb = calloc(1, sizeof(Item_Block));
3108                             if (!itb) return;
3109                             itb->wd = wd;
3110                             wd->blocks =
3111                               eina_inlist_prepend(wd->blocks,
3112                                                   EINA_INLIST_GET(itb));
3113                          }
3114                     }
3115                   else
3116                     {
3117                        itb = calloc(1, sizeof(Item_Block));
3118                        if (!itb) return;
3119                        itb->wd = wd;
3120                        wd->blocks =
3121                          eina_inlist_prepend(wd->blocks, EINA_INLIST_GET(itb));
3122                     }
3123                   itb->items = eina_list_prepend(itb->items, it);
3124                }
3125              else
3126                {
3127                   if (wd->blocks)
3128                     {
3129                        itb = (Item_Block *)(wd->blocks->last);
3130                        if (itb->count >= wd->max_items_per_block)
3131                          {
3132                             itb = calloc(1, sizeof(Item_Block));
3133                             if (!itb) return;
3134                             itb->wd = wd;
3135                             wd->blocks =
3136                               eina_inlist_append(wd->blocks,
3137                                                  EINA_INLIST_GET(itb));
3138                          }
3139                     }
3140                   else
3141                     {
3142                        itb = calloc(1, sizeof(Item_Block));
3143                        if (!itb) return;
3144                        itb->wd = wd;
3145                        wd->blocks =
3146                          eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
3147                     }
3148                   itb->items = eina_list_append(itb->items, it);
3149                }
3150           }
3151      }
3152    else
3153      {
3154         itb = it->rel->block;
3155         if (!itb) goto newblock;
3156         if (it->before)
3157           itb->items = eina_list_prepend_relative(itb->items, it, it->rel);
3158         else
3159           itb->items = eina_list_append_relative(itb->items, it, it->rel);
3160      }
3161    itb->count++;
3162    itb->changed = EINA_TRUE;
3163    it->block = itb;
3164    if (itb->wd->calc_job) ecore_job_del(itb->wd->calc_job);
3165    itb->wd->calc_job = ecore_job_add(_calc_job, itb->wd);
3166    if (it->rel)
3167      {
3168         it->rel->relcount--;
3169         if ((it->rel->delete_me) && (!it->rel->relcount))
3170           _item_del(it->rel);
3171         it->rel = NULL;
3172      }
3173    if (itb->count > itb->wd->max_items_per_block)
3174      {
3175         int newc;
3176         Item_Block *itb2;
3177         Elm_Genlist_Item *it2;
3178
3179         newc = itb->count / 2;
3180         itb2 = calloc(1, sizeof(Item_Block));
3181         if (!itb2) return;
3182         itb2->wd = wd;
3183         wd->blocks =
3184           eina_inlist_append_relative(wd->blocks, EINA_INLIST_GET(itb2),
3185                                       EINA_INLIST_GET(itb));
3186         itb2->changed = EINA_TRUE;
3187         while ((itb->count > newc) && (itb->items))
3188           {
3189              Eina_List *l;
3190
3191              l = eina_list_last(itb->items);
3192              it2 = l->data;
3193              itb->items = eina_list_remove_list(itb->items, l);
3194              itb->count--;
3195
3196              itb2->items = eina_list_prepend(itb2->items, it2);
3197              it2->block = itb2;
3198              itb2->count++;
3199           }
3200      }
3201 }
3202
3203 static int
3204 _queue_process(Widget_Data *wd)
3205 {
3206    int n;
3207    Eina_Bool showme = EINA_FALSE;
3208    double t0, t;
3209
3210    t0 = ecore_time_get();
3211    //evas_event_freeze(evas_object_evas_get(wd->obj));
3212    for (n = 0; (wd->queue) && (n < 128); n++)
3213      {
3214         Elm_Genlist_Item *it;
3215
3216         it = wd->queue->data;
3217         wd->queue = eina_list_remove_list(wd->queue, wd->queue);
3218         it->queued = EINA_FALSE;
3219         _item_block_add(wd, it);
3220         t = ecore_time_get();
3221         if (it->block->changed)
3222           {
3223              showme = _item_block_recalc(it->block, it->block->num, EINA_TRUE);
3224              it->block->changed = 0;
3225           }
3226         if (showme) it->block->showme = EINA_TRUE;
3227         if (eina_inlist_count(wd->blocks) > 1)
3228           {
3229              if ((t - t0) > (ecore_animator_frametime_get())) break;
3230           }
3231      }
3232    //evas_event_thaw(evas_object_evas_get(wd->obj));
3233    //evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3234    return n;
3235 }
3236
3237 static Eina_Bool
3238 _idle_process(void *data, Eina_Bool *wakeup)
3239 {
3240    Widget_Data *wd = data;
3241
3242    //xxx
3243    //static double q_start = 0.0;
3244    //if (q_start == 0.0) q_start = ecore_time_get();
3245    //xxx
3246    if (_queue_process(wd) > 0) *wakeup = EINA_TRUE;
3247    if (!wd->queue)
3248      {
3249         //xxx
3250         //printf("PROCESS TIME: %3.3f\n", ecore_time_get() - q_start);
3251         //xxx
3252         return ECORE_CALLBACK_CANCEL;
3253      }
3254    return ECORE_CALLBACK_RENEW;
3255 }
3256
3257 static Eina_Bool
3258 _item_idle_enterer(void *data)
3259 {
3260    Widget_Data *wd = data;
3261    Eina_Bool wakeup = EINA_FALSE;
3262    Eina_Bool ok = _idle_process(data, &wakeup);
3263
3264    if (wakeup)
3265      {
3266         // wake up mainloop
3267         if (wd->calc_job) ecore_job_del(wd->calc_job);
3268         wd->calc_job = ecore_job_add(_calc_job, wd);
3269      }
3270    if (ok == ECORE_CALLBACK_CANCEL) wd->queue_idle_enterer = NULL;
3271    return ok;
3272 }
3273
3274 static void
3275 _item_queue(Widget_Data      *wd,
3276             Elm_Genlist_Item *it)
3277 {
3278    if (it->queued) return;
3279    it->queued = EINA_TRUE;
3280    wd->queue = eina_list_append(wd->queue, it);
3281 // FIXME: why does a freeze then thaw here cause some genlist
3282 // elm_genlist_item_append() to be much much slower?
3283 //   evas_event_freeze(evas_object_evas_get(wd->obj));
3284    while ((wd->queue) && ((!wd->blocks) || (!wd->blocks->next)))
3285      {
3286         if (wd->queue_idle_enterer)
3287           {
3288              ecore_idle_enterer_del(wd->queue_idle_enterer);
3289              wd->queue_idle_enterer = NULL;
3290           }
3291         _queue_process(wd);
3292      }
3293 //   evas_event_thaw(evas_object_evas_get(wd->obj));
3294 //   evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3295    if (!wd->queue_idle_enterer)
3296      wd->queue_idle_enterer = ecore_idle_enterer_add(_item_idle_enterer, wd);
3297 }
3298
3299 static int
3300 _elm_genlist_item_compare_data(const void *data, const void *data1)
3301 {
3302    const Elm_Genlist_Item *item = data;
3303    const Elm_Genlist_Item *item1 = data1;
3304
3305    return _elm_genlist_item_compare_data_cb(item->base.data, item1->base.data);
3306 }
3307
3308 static int
3309 _elm_genlist_item_compare(const void *data, const void *data1)
3310 {
3311    Elm_Genlist_Item *item, *item1;
3312    item = ELM_GENLIST_ITEM_FROM_INLIST(data);
3313    item1 = ELM_GENLIST_ITEM_FROM_INLIST(data1);
3314    return _elm_genlist_item_compare_cb(item, item1);
3315 }
3316
3317 static void
3318 _item_move_after(Elm_Genlist_Item *it, Elm_Genlist_Item *after)
3319 {
3320    if (!it) return;
3321    if (!after) return;
3322
3323    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
3324    _item_block_del(it);
3325
3326    it->wd->items = eina_inlist_append_relative(it->wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(after));
3327    it->rel = after;
3328    it->rel->relcount++;
3329    it->before = EINA_FALSE;
3330    if (after->group_item) it->group_item = after->group_item;
3331    _item_queue(it->wd, it);
3332
3333    // TODO: change this to smart callback
3334    if (it->itc->func.moved)
3335      it->itc->func.moved(it->base.widget, it, after, EINA_TRUE);
3336 }
3337
3338 static void
3339 _item_move_before(Elm_Genlist_Item *it, Elm_Genlist_Item *before)
3340 {
3341    if (!it) return;
3342    if (!before) return;
3343
3344    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
3345    _item_block_del(it);
3346    it->wd->items = eina_inlist_prepend_relative(it->wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(before));
3347    it->rel = before;
3348    it->rel->relcount++;
3349    it->before = EINA_TRUE;
3350    if (before->group_item) it->group_item = before->group_item;
3351    _item_queue(it->wd, it);
3352
3353    // TODO: change this to smart callback
3354    if (it->itc->func.moved)
3355      it->itc->func.moved(it->base.widget, it, before, EINA_FALSE);
3356 }
3357
3358 /**
3359  * Add item to the end of the genlist
3360  *
3361  * This adds the given item to the end of the list or the end of
3362  * the children if the parent is given.
3363  *
3364  * @param obj The genlist object
3365  * @param itc The item class for the item
3366  * @param data The item data
3367  * @param parent The parent item, or NULL if none
3368  * @param flags Item flags
3369  * @param func Convenience function called when item selected
3370  * @param func_data Data passed to @p func above.
3371  * @return A handle to the item added or NULL if not possible
3372  *
3373  * @ingroup Genlist
3374  */
3375 EAPI Elm_Genlist_Item *
3376 elm_genlist_item_append(Evas_Object                  *obj,
3377                         const Elm_Genlist_Item_Class *itc,
3378                         const void                   *data,
3379                         Elm_Genlist_Item             *parent,
3380                         Elm_Genlist_Item_Flags        flags,
3381                         Evas_Smart_Cb                 func,
3382                         const void                   *func_data)
3383 {
3384    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3385    Widget_Data *wd = elm_widget_data_get(obj);
3386    if (!wd) return NULL;
3387    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3388                                     func_data);
3389    if (!it) return NULL;
3390    if (!it->parent)
3391      {
3392         if (flags & ELM_GENLIST_ITEM_GROUP)
3393           wd->group_items = eina_list_append(wd->group_items, it);
3394         wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
3395         it->rel = NULL;
3396      }
3397    else
3398      {
3399         Elm_Genlist_Item *it2 = NULL;
3400         Eina_List *ll = eina_list_last(it->parent->items);
3401         if (ll) it2 = ll->data;
3402         it->parent->items = eina_list_append(it->parent->items, it);
3403         if (!it2) it2 = it->parent;
3404         wd->items =
3405           eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3406                                       EINA_INLIST_GET(it2));
3407         it->rel = it2;
3408         it->rel->relcount++;
3409
3410         if (it->parent->flags & ELM_GENLIST_ITEM_GROUP)
3411           it->group_item = parent;
3412         else if (it->parent->group_item)
3413           it->group_item = it->parent->group_item;
3414      }
3415    it->before = EINA_FALSE;
3416    _item_queue(wd, it);
3417    return it;
3418 }
3419
3420 /**
3421  * Add item at start of the genlist
3422  *
3423  * This adds an item to the beginning of the list or beginning of the
3424  * children of the parent if given.
3425  *
3426  * @param obj The genlist object
3427  * @param itc The item class for the item
3428  * @param data The item data
3429  * @param parent The parent item, or NULL if none
3430  * @param flags Item flags
3431  * @param func Convenience function called when item selected
3432  * @param func_data Data passed to @p func above.
3433  * @return A handle to the item added or NULL if not possible
3434  *
3435  * @ingroup Genlist
3436  */
3437 EAPI Elm_Genlist_Item *
3438 elm_genlist_item_prepend(Evas_Object                  *obj,
3439                          const Elm_Genlist_Item_Class *itc,
3440                          const void                   *data,
3441                          Elm_Genlist_Item             *parent,
3442                          Elm_Genlist_Item_Flags        flags,
3443                          Evas_Smart_Cb                 func,
3444                          const void                   *func_data)
3445 {
3446    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3447    Widget_Data *wd = elm_widget_data_get(obj);
3448    if (!wd) return NULL;
3449    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3450                                     func_data);
3451    if (!it) return NULL;
3452    if (!it->parent)
3453      {
3454         if (flags & ELM_GENLIST_ITEM_GROUP)
3455           wd->group_items = eina_list_prepend(wd->group_items, it);
3456         wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
3457         it->rel = NULL;
3458      }
3459    else
3460      {
3461         Elm_Genlist_Item *it2 = NULL;
3462         Eina_List *ll = it->parent->items;
3463         if (ll) it2 = ll->data;
3464         it->parent->items = eina_list_prepend(it->parent->items, it);
3465         if (!it2) it2 = it->parent;
3466         wd->items =
3467           eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3468                                        EINA_INLIST_GET(it2));
3469         it->rel = it2;
3470         it->rel->relcount++;
3471      }
3472    it->before = EINA_TRUE;
3473    _item_queue(wd, it);
3474    return it;
3475 }
3476
3477 /**
3478  * Insert item before another in the genlist
3479  *
3480  * This inserts an item before another in the list. It will be in the
3481  * same tree level or group as the item it is inseted before.
3482  *
3483  * @param obj The genlist object
3484  * @param itc The item class for the item
3485  * @param data The item data
3486  * @param before The item to insert before
3487  * @param flags Item flags
3488  * @param func Convenience function called when item selected
3489  * @param func_data Data passed to @p func above.
3490  * @return A handle to the item added or NULL if not possible
3491  *
3492  * @ingroup Genlist
3493  */
3494 EAPI Elm_Genlist_Item *
3495 elm_genlist_item_insert_before(Evas_Object                  *obj,
3496                                const Elm_Genlist_Item_Class *itc,
3497                                const void                   *data,
3498                                Elm_Genlist_Item             *parent,
3499                                Elm_Genlist_Item             *before,
3500                                Elm_Genlist_Item_Flags        flags,
3501                                Evas_Smart_Cb                 func,
3502                                const void                   *func_data)
3503 {
3504    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3505    EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
3506    Widget_Data *wd = elm_widget_data_get(obj);
3507    if (!wd) return NULL;
3508    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3509                                     func_data);
3510    if (!it) return NULL;
3511    if (it->parent)
3512      {
3513         it->parent->items = eina_list_prepend_relative(it->parent->items, it,
3514                                                        before);
3515      }
3516    wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3517                                             EINA_INLIST_GET(before));
3518    it->rel = before;
3519    it->rel->relcount++;
3520    it->before = EINA_TRUE;
3521    _item_queue(wd, it);
3522    return it;
3523 }
3524
3525 EAPI Elm_Genlist_Item *
3526 elm_genlist_item_direct_sorted_insert(Evas_Object                  *obj,
3527                                       const Elm_Genlist_Item_Class *itc,
3528                                       const void                   *data,
3529                                       Elm_Genlist_Item             *parent,
3530                                       Elm_Genlist_Item_Flags        flags,
3531                                       Eina_Compare_Cb               comp,
3532                                       Evas_Smart_Cb                 func,
3533                                       const void                   *func_data)
3534 {
3535    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3536    Widget_Data *wd = elm_widget_data_get(obj);
3537    if (!wd) return NULL;
3538    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3539                                     func_data);
3540    if (!it) return NULL;
3541
3542    _elm_genlist_item_compare_cb = comp;
3543
3544    if (it->parent)
3545      {
3546         it->parent->items =
3547           eina_list_sorted_insert(it->parent->items, _elm_genlist_item_compare, it);
3548      }
3549    wd->items = eina_inlist_sorted_insert(wd->items, EINA_INLIST_GET(it),
3550                                          _elm_genlist_item_compare);
3551    if (EINA_INLIST_GET(it)->next)
3552      {
3553         it->rel = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3554         it->rel->relcount++;
3555         it->before = EINA_TRUE;
3556      }
3557    else if (EINA_INLIST_GET(it)->prev)
3558      {
3559         it->rel = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3560         it->rel->relcount++;
3561         it->before = EINA_FALSE;
3562      }
3563    _item_queue(wd, it);
3564
3565    return it;
3566 }
3567
3568 /**
3569  * Insert a new item into the sorted genlist object
3570  *
3571  * @param obj The genlist object
3572  * @param itc The item class for the item
3573  * @param data The item data
3574  * @param parent The parent item, or NULL if none
3575  * @param flags Item flags
3576  * @param comp The function called for the sort
3577  * @param func Convenience function called when item selected
3578  * @param func_data Data passed to @p func above.
3579  * @return A handle to the item added or NULL if not possible
3580  *
3581  * @ingroup Genlist
3582  */
3583 EAPI Elm_Genlist_Item *
3584 elm_genlist_item_sorted_insert(Evas_Object                  *obj,
3585                                const Elm_Genlist_Item_Class *itc,
3586                                const void                   *data,
3587                                Elm_Genlist_Item             *parent,
3588                                Elm_Genlist_Item_Flags        flags,
3589                                Eina_Compare_Cb               comp,
3590                                Evas_Smart_Cb                 func,
3591                                const void                   *func_data)
3592 {
3593    _elm_genlist_item_compare_data_cb = comp;
3594
3595    return elm_genlist_item_direct_sorted_insert(obj, itc, data, parent, flags,
3596                                                 _elm_genlist_item_compare_data, func, func_data);
3597 }
3598
3599 /**
3600  * Insert an item after another in the genlst
3601  *
3602  * This inserts an item after another in the list. It will be in the
3603  * same tree level or group as the item it is inseted after.
3604  *
3605  * @param obj The genlist object
3606  * @param itc The item class for the item
3607  * @param data The item data
3608  * @param after The item to insert after
3609  * @param flags Item flags
3610  * @param func Convenience function called when item selected
3611  * @param func_data Data passed to @p func above.
3612  * @return A handle to the item added or NULL if not possible
3613  *
3614  * @ingroup Genlist
3615  */
3616 EAPI Elm_Genlist_Item *
3617 elm_genlist_item_insert_after(Evas_Object                  *obj,
3618                               const Elm_Genlist_Item_Class *itc,
3619                               const void                   *data,
3620                               Elm_Genlist_Item             *parent,
3621                               Elm_Genlist_Item             *after,
3622                               Elm_Genlist_Item_Flags        flags,
3623                               Evas_Smart_Cb                 func,
3624                               const void                   *func_data)
3625 {
3626    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3627    EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
3628    Widget_Data *wd = elm_widget_data_get(obj);
3629    if (!wd) return NULL;
3630    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3631                                     func_data);
3632    if (!it) return NULL;
3633    /* It make no sense to insert after in an empty list with after != NULL, something really bad is happening in your app. */
3634    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->items, NULL);
3635
3636    wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3637                                            EINA_INLIST_GET(after));
3638    if (it->parent)
3639      {
3640         it->parent->items = eina_list_append_relative(it->parent->items, it,
3641                                                       after);
3642      }
3643    it->rel = after;
3644    it->rel->relcount++;
3645    it->before = EINA_FALSE;
3646    _item_queue(wd, it);
3647    return it;
3648 }
3649
3650 EAPI void
3651 elm_genlist_clear(Evas_Object *obj)
3652 {
3653    ELM_CHECK_WIDTYPE(obj, widtype);
3654    Widget_Data *wd = elm_widget_data_get(obj);
3655    if (!wd) return;
3656    if (wd->walking > 0)
3657      {
3658         Elm_Genlist_Item *it;
3659
3660         wd->clear_me = EINA_TRUE;
3661         EINA_INLIST_FOREACH(wd->items, it)
3662           {
3663              it->delete_me = EINA_TRUE;
3664           }
3665         return;
3666      }
3667    evas_event_freeze(evas_object_evas_get(wd->obj));
3668    while (wd->items)
3669      {
3670         Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3671
3672         if (wd->anchor_item == it)
3673           {
3674              wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3675              if (!wd->anchor_item)
3676                wd->anchor_item =
3677                  ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3678           }
3679         wd->items = eina_inlist_remove(wd->items, wd->items);
3680         if (it->flags & ELM_GENLIST_ITEM_GROUP)
3681           it->wd->group_items = eina_list_remove(it->wd->group_items, it);
3682         elm_widget_item_pre_notify_del(it);
3683         if (it->realized) _item_unrealize(it, EINA_FALSE);
3684         if (((wd->clear_me) || (!it->delete_me)) && (it->itc->func.del))
3685           it->itc->func.del((void *)it->base.data, it->base.widget);
3686         if (it->long_timer) ecore_timer_del(it->long_timer);
3687         if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
3688         elm_widget_item_del(it);
3689      }
3690    wd->clear_me = EINA_FALSE;
3691    wd->anchor_item = NULL;
3692    while (wd->blocks)
3693      {
3694         Item_Block *itb = (Item_Block *)(wd->blocks);
3695
3696         wd->blocks = eina_inlist_remove(wd->blocks, wd->blocks);
3697         if (itb->items) eina_list_free(itb->items);
3698         free(itb);
3699      }
3700    if (wd->calc_job)
3701      {
3702         ecore_job_del(wd->calc_job);
3703         wd->calc_job = NULL;
3704      }
3705    if (wd->queue_idle_enterer)
3706      {
3707         ecore_idle_enterer_del(wd->queue_idle_enterer);
3708         wd->queue_idle_enterer = NULL;
3709      }
3710    if (wd->must_recalc_idler)
3711      {
3712         ecore_idler_del(wd->must_recalc_idler);
3713         wd->must_recalc_idler = NULL;
3714      }
3715    if (wd->queue)
3716      {
3717         eina_list_free(wd->queue);
3718         wd->queue = NULL;
3719      }
3720    if (wd->selected)
3721      {
3722         eina_list_free(wd->selected);
3723         wd->selected = NULL;
3724      }
3725    if (wd->reorder_move_animator)
3726      {
3727         ecore_animator_del(wd->reorder_move_animator);
3728         wd->reorder_move_animator = NULL;
3729      }
3730    wd->show_item = NULL;
3731    wd->pan_x = 0;
3732    wd->pan_y = 0;
3733    wd->old_pan_y = 0;
3734    wd->minw = 0;
3735    wd->minh = 0;
3736    if (wd->pan_smart)
3737      {
3738         evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
3739         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
3740      }
3741    _sizing_eval(obj);
3742    evas_event_thaw(evas_object_evas_get(wd->obj));
3743    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3744 }
3745
3746 EAPI void
3747 elm_genlist_multi_select_set(Evas_Object *obj,
3748                              Eina_Bool    multi)
3749 {
3750    ELM_CHECK_WIDTYPE(obj, widtype);
3751    Widget_Data *wd = elm_widget_data_get(obj);
3752    if (!wd) return;
3753    wd->multi = multi;
3754 }
3755
3756 EAPI Eina_Bool
3757 elm_genlist_multi_select_get(const Evas_Object *obj)
3758 {
3759    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3760    Widget_Data *wd = elm_widget_data_get(obj);
3761    if (!wd) return EINA_FALSE;
3762    return wd->multi;
3763 }
3764
3765 EAPI Elm_Genlist_Item *
3766 elm_genlist_selected_item_get(const Evas_Object *obj)
3767 {
3768    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3769    Widget_Data *wd = elm_widget_data_get(obj);
3770    if (!wd) return NULL;
3771    if (wd->selected) return wd->selected->data;
3772    return NULL;
3773 }
3774
3775 EAPI const Eina_List *
3776 elm_genlist_selected_items_get(const Evas_Object *obj)
3777 {
3778    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3779    Widget_Data *wd = elm_widget_data_get(obj);
3780    if (!wd) return NULL;
3781    return wd->selected;
3782 }
3783
3784 EAPI Eina_List *
3785 elm_genlist_realized_items_get(const Evas_Object *obj)
3786 {
3787    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3788    Widget_Data *wd = elm_widget_data_get(obj);
3789    Eina_List *list = NULL;
3790    Item_Block *itb;
3791    Eina_Bool done = EINA_FALSE;
3792    if (!wd) return NULL;
3793    EINA_INLIST_FOREACH(wd->blocks, itb)
3794      {
3795         if (itb->realized)
3796           {
3797              Eina_List *l;
3798              Elm_Genlist_Item *it;
3799
3800              done = 1;
3801              EINA_LIST_FOREACH(itb->items, l, it)
3802                {
3803                   if (it->realized) list = eina_list_append(list, it);
3804                }
3805           }
3806         else
3807           {
3808              if (done) break;
3809           }
3810      }
3811    return list;
3812 }
3813
3814 EAPI Elm_Genlist_Item *
3815 elm_genlist_at_xy_item_get(const Evas_Object *obj,
3816                            Evas_Coord         x,
3817                            Evas_Coord         y,
3818                            int               *posret)
3819 {
3820    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3821    Widget_Data *wd = elm_widget_data_get(obj);
3822    Evas_Coord ox, oy, ow, oh;
3823    Item_Block *itb;
3824    Evas_Coord lasty;
3825    if (!wd) return NULL;
3826    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
3827    lasty = oy;
3828    EINA_INLIST_FOREACH(wd->blocks, itb)
3829      {
3830         Eina_List *l;
3831         Elm_Genlist_Item *it;
3832
3833         if (!ELM_RECTS_INTERSECT(ox + itb->x - itb->wd->pan_x,
3834                                  oy + itb->y - itb->wd->pan_y,
3835                                  itb->w, itb->h, x, y, 1, 1))
3836           continue;
3837         EINA_LIST_FOREACH(itb->items, l, it)
3838           {
3839              Evas_Coord itx, ity;
3840
3841              itx = ox + itb->x + it->x - itb->wd->pan_x;
3842              ity = oy + itb->y + it->y - itb->wd->pan_y;
3843              if (ELM_RECTS_INTERSECT(itx, ity, it->w, it->h, x, y, 1, 1))
3844                {
3845                   if (posret)
3846                     {
3847                        if (y <= (ity + (it->h / 4))) *posret = -1;
3848                        else if (y >= (ity + it->h - (it->h / 4)))
3849                          *posret = 1;
3850                        else *posret = 0;
3851                     }
3852                   return it;
3853                }
3854              lasty = ity + it->h;
3855           }
3856      }
3857    if (posret)
3858      {
3859         if (y > lasty) *posret = 1;
3860         else *posret = -1;
3861      }
3862    return NULL;
3863 }
3864
3865 /**
3866  * Get the first item in the genlist
3867  *
3868  * This returns the first item in the list.
3869  *
3870  * @param obj The genlist object
3871  * @return The first item, or NULL if none
3872  *
3873  * @ingroup Genlist
3874  */
3875 EAPI Elm_Genlist_Item *
3876 elm_genlist_first_item_get(const Evas_Object *obj)
3877 {
3878    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3879    Widget_Data *wd = elm_widget_data_get(obj);
3880    if (!wd) return NULL;
3881    if (!wd->items) return NULL;
3882    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3883    while ((it) && (it->delete_me))
3884      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3885    return it;
3886 }
3887
3888 /**
3889  * Get the last item in the genlist
3890  *
3891  * This returns the last item in the list.
3892  *
3893  * @return The last item, or NULL if none
3894  *
3895  * @ingroup Genlist
3896  */
3897 EAPI Elm_Genlist_Item *
3898 elm_genlist_last_item_get(const Evas_Object *obj)
3899 {
3900    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3901    Widget_Data *wd = elm_widget_data_get(obj);
3902    if (!wd) return NULL;
3903    if (!wd->items) return NULL;
3904    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items->last);
3905    while ((it) && (it->delete_me))
3906      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3907    return it;
3908 }
3909
3910 /**
3911  * Get the next item in the genlist
3912  *
3913  * This returns the item after the item @p it.
3914  *
3915  * @param it The item
3916  * @return The item after @p it, or NULL if none
3917  *
3918  * @ingroup Genlist
3919  */
3920 EAPI Elm_Genlist_Item *
3921 elm_genlist_item_next_get(const Elm_Genlist_Item *it)
3922 {
3923    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3924    while (it)
3925      {
3926         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3927         if ((it) && (!it->delete_me)) break;
3928      }
3929    return (Elm_Genlist_Item *)it;
3930 }
3931
3932 /**
3933  * Get the previous item in the genlist
3934  *
3935  * This returns the item before the item @p it.
3936  *
3937  * @param it The item
3938  * @return The item before @p it, or NULL if none
3939  *
3940  * @ingroup Genlist
3941  */
3942 EAPI Elm_Genlist_Item *
3943 elm_genlist_item_prev_get(const Elm_Genlist_Item *it)
3944 {
3945    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3946    while (it)
3947      {
3948         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3949         if ((it) && (!it->delete_me)) break;
3950      }
3951    return (Elm_Genlist_Item *)it;
3952 }
3953
3954 /**
3955  * Get the genlist object from an item
3956  *
3957  * This returns the genlist object itself that an item belongs to.
3958  *
3959  * @param it The item
3960  * @return The genlist object
3961  *
3962  * @ingroup Genlist
3963  */
3964 EAPI Evas_Object *
3965 elm_genlist_item_genlist_get(const Elm_Genlist_Item *it)
3966 {
3967    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3968    return it->base.widget;
3969 }
3970
3971 /**
3972  * Get the parent item of the given item
3973  *
3974  * This returns the parent item of the item @p it given.
3975  *
3976  * @param it The item
3977  * @return The parent of the item or NULL if none
3978  *
3979  * @ingroup Genlist
3980  */
3981 EAPI Elm_Genlist_Item *
3982 elm_genlist_item_parent_get(const Elm_Genlist_Item *it)
3983 {
3984    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3985    return it->parent;
3986 }
3987
3988 /**
3989  * Clear all sub-items (children) of the given item
3990  *
3991  * This clears all items that are children (or their descendants) of the
3992  * given item @p it.
3993  *
3994  * @param it The item
3995  *
3996  * @ingroup Genlist
3997  */
3998 EAPI void
3999 elm_genlist_item_subitems_clear(Elm_Genlist_Item *it)
4000 {
4001    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4002    Eina_List *tl = NULL, *l;
4003    Elm_Genlist_Item *it2;
4004
4005    EINA_LIST_FOREACH(it->items, l, it2)
4006      tl = eina_list_append(tl, it2);
4007    EINA_LIST_FREE(tl, it2)
4008      elm_genlist_item_del(it2);
4009 }
4010
4011 /**
4012  * Set the selected state of an item
4013  *
4014  * This sets the selected state (1 selected, 0 not selected) of the given
4015  * item @p it.
4016  *
4017  * @param it The item
4018  * @param selected The selected state
4019  *
4020  * @ingroup Genlist
4021  */
4022 EAPI void
4023 elm_genlist_item_selected_set(Elm_Genlist_Item *it,
4024                               Eina_Bool         selected)
4025 {
4026    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4027    Widget_Data *wd = elm_widget_data_get(it->base.widget);
4028    if (!wd) return;
4029    if ((it->delete_me) || (it->disabled)) return;
4030    selected = !!selected;
4031    if (it->selected == selected) return;
4032
4033    if (selected)
4034      {
4035         if (!wd->multi)
4036           {
4037              while (wd->selected)
4038                {
4039                   _item_unhighlight(wd->selected->data);
4040                   _item_unselect(wd->selected->data);
4041                }
4042           }
4043         _item_highlight(it);
4044         _item_select(it);
4045      }
4046    else
4047      {
4048         _item_unhighlight(it);
4049         _item_unselect(it);
4050      }
4051 }
4052
4053 /**
4054  * Get the selected state of an item
4055  *
4056  * This gets the selected state of an item (1 selected, 0 not selected).
4057  *
4058  * @param it The item
4059  * @return The selected state
4060  *
4061  * @ingroup Genlist
4062  */
4063 EAPI Eina_Bool
4064 elm_genlist_item_selected_get(const Elm_Genlist_Item *it)
4065 {
4066    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4067    return it->selected;
4068 }
4069
4070 /**
4071  * Sets the expanded state of an item (if it's a parent)
4072  *
4073  * This expands or contracts a parent item (thus showing or hiding the
4074  * children).
4075  *
4076  * @param it The item
4077  * @param expanded The expanded state (1 expanded, 0 not expanded).
4078  *
4079  * @ingroup Genlist
4080  */
4081 EAPI void
4082 elm_genlist_item_expanded_set(Elm_Genlist_Item *it,
4083                               Eina_Bool         expanded)
4084 {
4085    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4086    if (it->expanded == expanded) return;
4087    it->expanded = expanded;
4088    it->wd->expanded_item = it;
4089    if (it->expanded)
4090      {
4091         if (it->realized)
4092           edje_object_signal_emit(it->base.view, "elm,state,expanded", "elm");
4093         evas_object_smart_callback_call(it->base.widget, SIG_EXPANDED, it);
4094         it->wd->auto_scroll_enabled = EINA_TRUE;
4095      }
4096    else
4097      {
4098         if (it->realized)
4099           edje_object_signal_emit(it->base.view, "elm,state,contracted", "elm");
4100         evas_object_smart_callback_call(it->base.widget, SIG_CONTRACTED, it);
4101         it->wd->auto_scroll_enabled = EINA_FALSE;
4102      }
4103 }
4104
4105 /**
4106  * Get the expanded state of an item
4107  *
4108  * This gets the expanded state of an item
4109  *
4110  * @param it The item
4111  * @return Thre expanded state
4112  *
4113  * @ingroup Genlist
4114  */
4115 EAPI Eina_Bool
4116 elm_genlist_item_expanded_get(const Elm_Genlist_Item *it)
4117 {
4118    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4119    return it->expanded;
4120 }
4121
4122 /**
4123  * Get the depth of expanded item
4124  *
4125  * @param it The genlist item object
4126  * @return The depth of expanded item
4127  *
4128  * @ingroup Genlist
4129  */
4130 EAPI int
4131 elm_genlist_item_expanded_depth_get(const Elm_Genlist_Item *it)
4132 {
4133    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, 0);
4134    return it->expanded_depth;
4135 }
4136
4137 /**
4138  * Sets the disabled state of an item.
4139  *
4140  * A disabled item cannot be selected or unselected. It will also
4141  * change appearance to appear disabled. This sets the disabled state
4142  * (1 disabled, 0 not disabled).
4143  *
4144  * @param it The item
4145  * @param disabled The disabled state
4146  *
4147  * @ingroup Genlist
4148  */
4149 EAPI void
4150 elm_genlist_item_disabled_set(Elm_Genlist_Item *it,
4151                               Eina_Bool         disabled)
4152 {
4153    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4154    Eina_List *l;
4155    Evas_Object *obj;
4156    if (it->disabled == disabled) return;
4157    if (it->delete_me) return;
4158    it->disabled = !!disabled;
4159    if (it->selected)
4160      elm_genlist_item_selected_set(it, EINA_FALSE);
4161    if (it->realized)
4162      {
4163         if (it->disabled)
4164           edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
4165         else
4166           edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
4167         EINA_LIST_FOREACH(it->icon_objs, l, obj)
4168           elm_widget_disabled_set(obj, disabled);
4169      }
4170 }
4171
4172 /**
4173  * Get the disabled state of an item
4174  *
4175  * This gets the disabled state of the given item.
4176  *
4177  * @param it The item
4178  * @return The disabled state
4179  *
4180  * @ingroup Genlist
4181  */
4182 EAPI Eina_Bool
4183 elm_genlist_item_disabled_get(const Elm_Genlist_Item *it)
4184 {
4185    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4186    if (it->delete_me) return EINA_FALSE;
4187    return it->disabled;
4188 }
4189
4190 /**
4191  * Sets the display only state of an item.
4192  *
4193  * A display only item cannot be selected or unselected. It is for
4194  * display only and not selecting or otherwise clicking, dragging
4195  * etc. by the user, thus finger size rules will not be applied to
4196  * this item.
4197  *
4198  * @param it The item
4199  * @param display_only The display only state
4200  *
4201  * @ingroup Genlist
4202  */
4203 EAPI void
4204 elm_genlist_item_display_only_set(Elm_Genlist_Item *it,
4205                                   Eina_Bool         display_only)
4206 {
4207    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4208    if (it->display_only == display_only) return;
4209    if (it->delete_me) return;
4210    it->display_only = display_only;
4211    it->mincalcd = EINA_FALSE;
4212    it->updateme = EINA_TRUE;
4213    if (it->block) it->block->updateme = EINA_TRUE;
4214    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4215    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4216 }
4217
4218 /**
4219  * Get the display only state of an item
4220  *
4221  * This gets the display only state of the given item.
4222  *
4223  * @param it The item
4224  * @return The display only state
4225  *
4226  * @ingroup Genlist
4227  */
4228 EAPI Eina_Bool
4229 elm_genlist_item_display_only_get(const Elm_Genlist_Item *it)
4230 {
4231    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4232    if (it->delete_me) return EINA_FALSE;
4233    return it->display_only;
4234 }
4235
4236 /**
4237  * Show the given item
4238  *
4239  * This causes genlist to jump to the given item @p it and show it (by
4240  * scrolling), if it is not fully visible.
4241  *
4242  * @param it The item
4243  *
4244  * @ingroup Genlist
4245  */
4246 EAPI void
4247 elm_genlist_item_show(Elm_Genlist_Item *it)
4248 {
4249    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4250    Evas_Coord gith = 0;
4251    if (it->delete_me) return;
4252    if ((it->queued) || (!it->mincalcd))
4253      {
4254         it->wd->show_item = it;
4255         it->wd->bring_in = EINA_TRUE;
4256         it->showme = EINA_TRUE;
4257         return;
4258      }
4259    if (it->wd->show_item)
4260      {
4261         it->wd->show_item->showme = EINA_FALSE;
4262         it->wd->show_item = NULL;
4263      }
4264    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4265      gith = it->group_item->h;
4266    elm_smart_scroller_child_region_show(it->wd->scr,
4267                                         it->x + it->block->x,
4268                                         it->y + it->block->y - gith,
4269                                         it->block->w, it->h);
4270 }
4271
4272 /**
4273  * Bring in the given item
4274  *
4275  * This causes genlist to jump to the given item @p it and show it (by
4276  * scrolling), if it is not fully visible. This may use animation to
4277  * do so and take a period of time
4278  *
4279  * @param it The item
4280  *
4281  * @ingroup Genlist
4282  */
4283 EAPI void
4284 elm_genlist_item_bring_in(Elm_Genlist_Item *it)
4285 {
4286    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4287    Evas_Coord gith = 0;
4288    if (it->delete_me) return;
4289    if ((it->queued) || (!it->mincalcd))
4290      {
4291         it->wd->show_item = it;
4292         it->wd->bring_in = EINA_TRUE;
4293         it->showme = EINA_TRUE;
4294         return;
4295      }
4296    if (it->wd->show_item)
4297      {
4298         it->wd->show_item->showme = EINA_FALSE;
4299         it->wd->show_item = NULL;
4300      }
4301    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4302      gith = it->group_item->h;
4303    elm_smart_scroller_region_bring_in(it->wd->scr,
4304                                       it->x + it->block->x,
4305                                       it->y + it->block->y - gith,
4306                                       it->block->w, it->h);
4307 }
4308
4309 /**
4310  * Show the given item at the top
4311  *
4312  * This causes genlist to jump to the given item @p it and show it (by
4313  * scrolling), if it is not fully visible.
4314  *
4315  * @param it The item
4316  *
4317  * @ingroup Genlist
4318  */
4319 EAPI void
4320 elm_genlist_item_top_show(Elm_Genlist_Item *it)
4321 {
4322    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4323    Evas_Coord ow, oh;
4324    Evas_Coord gith = 0;
4325
4326    if (it->delete_me) return;
4327    if ((it->queued) || (!it->mincalcd))
4328      {
4329         it->wd->show_item = it;
4330         it->wd->bring_in = EINA_TRUE;
4331         it->showme = EINA_TRUE;
4332         return;
4333      }
4334    if (it->wd->show_item)
4335      {
4336         it->wd->show_item->showme = EINA_FALSE;
4337         it->wd->show_item = NULL;
4338      }
4339    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4340    if (it->group_item) gith = it->group_item->h;
4341    elm_smart_scroller_child_region_show(it->wd->scr,
4342                                         it->x + it->block->x,
4343                                         it->y + it->block->y - gith,
4344                                         it->block->w, oh);
4345 }
4346
4347 /**
4348  * Bring in the given item at the top
4349  *
4350  * This causes genlist to jump to the given item @p it and show it (by
4351  * scrolling), if it is not fully visible. This may use animation to
4352  * do so and take a period of time
4353  *
4354  * @param it The item
4355  *
4356  * @ingroup Genlist
4357  */
4358 EAPI void
4359 elm_genlist_item_top_bring_in(Elm_Genlist_Item *it)
4360 {
4361    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4362    Evas_Coord ow, oh;
4363    Evas_Coord gith = 0;
4364
4365    if (it->delete_me) return;
4366    if ((it->queued) || (!it->mincalcd))
4367      {
4368         it->wd->show_item = it;
4369         it->wd->bring_in = EINA_TRUE;
4370         it->showme = EINA_TRUE;
4371         return;
4372      }
4373    if (it->wd->show_item)
4374      {
4375         it->wd->show_item->showme = EINA_FALSE;
4376         it->wd->show_item = NULL;
4377      }
4378    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4379    if (it->group_item) gith = it->group_item->h;
4380    elm_smart_scroller_region_bring_in(it->wd->scr,
4381                                       it->x + it->block->x,
4382                                       it->y + it->block->y - gith,
4383                                       it->block->w, oh);
4384 }
4385
4386 /**
4387  * Show the given item at the middle
4388  *
4389  * This causes genlist to jump to the given item @p it and show it (by
4390  * scrolling), if it is not fully visible.
4391  *
4392  * @param it The item
4393  *
4394  * @ingroup Genlist
4395  */
4396 EAPI void
4397 elm_genlist_item_middle_show(Elm_Genlist_Item *it)
4398 {
4399    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4400    Evas_Coord ow, oh;
4401
4402    if (it->delete_me) return;
4403    if ((it->queued) || (!it->mincalcd))
4404      {
4405         it->wd->show_item = it;
4406         it->wd->bring_in = EINA_TRUE;
4407         it->showme = EINA_TRUE;
4408         return;
4409      }
4410    if (it->wd->show_item)
4411      {
4412         it->wd->show_item->showme = EINA_FALSE;
4413         it->wd->show_item = NULL;
4414      }
4415    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4416    elm_smart_scroller_child_region_show(it->wd->scr,
4417                                         it->x + it->block->x,
4418                                         it->y + it->block->y - oh / 2 +
4419                                         it->h / 2, it->block->w, oh);
4420 }
4421
4422 /**
4423  * Bring in the given item at the middle
4424  *
4425  * This causes genlist to jump to the given item @p it and show it (by
4426  * scrolling), if it is not fully visible. This may use animation to
4427  * do so and take a period of time
4428  *
4429  * @param it The item
4430  *
4431  * @ingroup Genlist
4432  */
4433 EAPI void
4434 elm_genlist_item_middle_bring_in(Elm_Genlist_Item *it)
4435 {
4436    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4437    Evas_Coord ow, oh;
4438
4439    if (it->delete_me) return;
4440    if ((it->queued) || (!it->mincalcd))
4441      {
4442         it->wd->show_item = it;
4443         it->wd->bring_in = EINA_TRUE;
4444         it->showme = EINA_TRUE;
4445         return;
4446      }
4447    if (it->wd->show_item)
4448      {
4449         it->wd->show_item->showme = EINA_FALSE;
4450         it->wd->show_item = NULL;
4451      }
4452    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4453    elm_smart_scroller_region_bring_in(it->wd->scr,
4454                                       it->x + it->block->x,
4455                                       it->y + it->block->y - oh / 2 + it->h / 2,
4456                                       it->block->w, oh);
4457 }
4458
4459 /**
4460  * Delete a given item
4461  *
4462  * This deletes the item from genlist and calls the genlist item del
4463  * class callback defined in the item class, if it is set. This clears all
4464  * subitems if it is a tree.
4465  *
4466  * @param it The item
4467  *
4468  * @ingroup Genlist
4469  */
4470 EAPI void
4471 elm_genlist_item_del(Elm_Genlist_Item *it)
4472 {
4473    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4474    if ((it->relcount > 0) || (it->walking > 0))
4475      {
4476         elm_widget_item_pre_notify_del(it);
4477         elm_genlist_item_subitems_clear(it);
4478         it->delete_me = EINA_TRUE;
4479         if (it->wd->show_item == it) it->wd->show_item = NULL;
4480         if (it->selected)
4481           it->wd->selected = eina_list_remove(it->wd->selected,
4482                                               it);
4483         if (it->block)
4484           {
4485              if (it->realized) _item_unrealize(it, EINA_FALSE);
4486              it->block->changed = EINA_TRUE;
4487              if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
4488              it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
4489           }
4490         if (it->itc->func.del)
4491           it->itc->func.del((void *)it->base.data, it->base.widget);
4492         return;
4493      }
4494    _item_del(it);
4495 }
4496
4497 /**
4498  * Set the data item from the genlist item
4499  *
4500  * This sets the data value passed on the elm_genlist_item_append() and
4501  * related item addition calls. This function will not call
4502  * elm_genlist_item_update() anymore. So call elm_genlist_item_update()
4503  * manually only when it's needed.
4504  *
4505  * @param it The item
4506  * @param data The new data pointer to set
4507  *
4508  * @ingroup Genlist
4509  */
4510 EAPI void
4511 elm_genlist_item_data_set(Elm_Genlist_Item *it,
4512                           const void       *data)
4513 {
4514    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4515    elm_widget_item_data_set(it, data);
4516 }
4517
4518 /**
4519  * Get the data item from the genlist item
4520  *
4521  * This returns the data value passed on the elm_genlist_item_append()
4522  * and related item addition calls and elm_genlist_item_data_set().
4523  *
4524  * @param it The item
4525  * @return The data pointer provided when created
4526  *
4527  * @ingroup Genlist
4528  */
4529 EAPI void *
4530 elm_genlist_item_data_get(const Elm_Genlist_Item *it)
4531 {
4532    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4533    return elm_widget_item_data_get(it);
4534 }
4535
4536 /**
4537  * Tells genlist to "orphan" icons fetchs by the item class
4538  *
4539  * This instructs genlist to release references to icons in the item,
4540  * meaning that they will no longer be managed by genlist and are
4541  * floating "orphans" that can be re-used elsewhere if the user wants
4542  * to.
4543  *
4544  * @param it The item
4545  *
4546  * @ingroup Genlist
4547  */
4548 EAPI void
4549 elm_genlist_item_icons_orphan(Elm_Genlist_Item *it)
4550 {
4551    Evas_Object *icon;
4552    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4553    EINA_LIST_FREE(it->icon_objs, icon)
4554      {
4555         elm_widget_sub_object_del(it->base.widget, icon);
4556         evas_object_smart_member_del(icon);
4557         evas_object_hide(icon);
4558      }
4559 }
4560
4561 /**
4562  * Get the real evas object of the genlist item
4563  *
4564  * This returns the actual evas object used for the specified genlist
4565  * item. This may be NULL as it may not be created, and may be deleted
4566  * at any time by genlist. Do not modify this object (move, resize,
4567  * show, hide etc.) as genlist is controlling it. This function is for
4568  * querying, emitting custom signals or hooking lower level callbacks
4569  * for events. Do not delete this object under any circumstances.
4570  *
4571  * @param it The item
4572  * @return The object pointer
4573  *
4574  * @ingroup Genlist
4575  */
4576 EAPI const Evas_Object *
4577 elm_genlist_item_object_get(const Elm_Genlist_Item *it)
4578 {
4579    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4580    return it->base.view;
4581 }
4582
4583 /**
4584  * Update the contents of an item
4585  *
4586  * This updates an item by calling all the item class functions again
4587  * to get the icons, labels and states. Use this when the original
4588  * item data has changed and the changes are desired to be reflected.
4589  *
4590  * @param it The item
4591  *
4592  * @ingroup Genlist
4593  */
4594 EAPI void
4595 elm_genlist_item_update(Elm_Genlist_Item *it)
4596 {
4597    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4598    if (!it->block) return;
4599    if (it->delete_me) return;
4600    it->mincalcd = EINA_FALSE;
4601    it->updateme = EINA_TRUE;
4602    it->block->updateme = EINA_TRUE;
4603    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4604    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4605 }
4606
4607 /**
4608  * Update the item class of an item
4609  *
4610  * @param it The item
4611  * @parem itc The item class for the item
4612  *
4613  * @ingroup Genlist
4614  */
4615 EAPI void
4616 elm_genlist_item_item_class_update(Elm_Genlist_Item             *it,
4617                                    const Elm_Genlist_Item_Class *itc)
4618 {
4619    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4620    if (!it->block) return;
4621    EINA_SAFETY_ON_NULL_RETURN(itc);
4622    if (it->delete_me) return;
4623    it->itc = itc;
4624    it->nocache = EINA_TRUE;
4625    elm_genlist_item_update(it);
4626 }
4627
4628 EAPI const Elm_Genlist_Item_Class *
4629 elm_genlist_item_item_class_get(const Elm_Genlist_Item *it)
4630 {
4631    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4632    if (it->delete_me) return NULL;
4633    return it->itc;
4634 }
4635
4636 static Evas_Object *
4637 _elm_genlist_item_label_create(void        *data,
4638                                Evas_Object *obj __UNUSED__,
4639                                Evas_Object *tooltip,
4640                                void        *item __UNUSED__)
4641 {
4642    Evas_Object *label = elm_label_add(tooltip);
4643    if (!label)
4644      return NULL;
4645    elm_object_style_set(label, "tooltip");
4646    elm_object_text_set(label, data);
4647    return label;
4648 }
4649
4650 static void
4651 _elm_genlist_item_label_del_cb(void        *data,
4652                                Evas_Object *obj __UNUSED__,
4653                                void        *event_info __UNUSED__)
4654 {
4655    eina_stringshare_del(data);
4656 }
4657
4658 /**
4659  * Set the text to be shown in the genlist item.
4660  *
4661  * @param item Target item
4662  * @param text The text to set in the content
4663  *
4664  * Setup the text as tooltip to object. The item can have only one
4665  * tooltip, so any previous tooltip data is removed.
4666  *
4667  * @ingroup Genlist
4668  */
4669 EAPI void
4670 elm_genlist_item_tooltip_text_set(Elm_Genlist_Item *item,
4671                                   const char       *text)
4672 {
4673    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4674    text = eina_stringshare_add(text);
4675    elm_genlist_item_tooltip_content_cb_set(item, _elm_genlist_item_label_create,
4676                                            text,
4677                                            _elm_genlist_item_label_del_cb);
4678 }
4679
4680 /**
4681  * Set the content to be shown in the tooltip item
4682  *
4683  * Setup the tooltip to item. The item can have only one tooltip, so
4684  * any previous tooltip data is removed. @p func(with @p data) will be
4685  * called every time that need to show the tooltip and it should return a
4686  * valid Evas_Object. This object is then managed fully by tooltip
4687  * system and is deleted when the tooltip is gone.
4688  *
4689  * @param item the genlist item being attached by a tooltip.
4690  * @param func the function used to create the tooltip contents.
4691  * @param data what to provide to @a func as callback data/context.
4692  * @param del_cb called when data is not needed anymore, either when
4693  *        another callback replaces @func, the tooltip is unset with
4694  *        elm_genlist_item_tooltip_unset() or the owner @a item
4695  *        dies. This callback receives as the first parameter the
4696  *        given @a data, and @c event_info is the item.
4697  *
4698  * @ingroup Genlist
4699  */
4700 EAPI void
4701 elm_genlist_item_tooltip_content_cb_set(Elm_Genlist_Item           *item,
4702                                         Elm_Tooltip_Item_Content_Cb func,
4703                                         const void                 *data,
4704                                         Evas_Smart_Cb               del_cb)
4705 {
4706    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
4707
4708    if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
4709      return;
4710
4711    if (item->tooltip.del_cb)
4712      item->tooltip.del_cb((void *)item->tooltip.data,
4713                           item->base.widget, item);
4714
4715    item->tooltip.content_cb = func;
4716    item->tooltip.data = data;
4717    item->tooltip.del_cb = del_cb;
4718
4719    if (item->base.view)
4720      {
4721         elm_widget_item_tooltip_content_cb_set(item,
4722                                                item->tooltip.content_cb,
4723                                                item->tooltip.data, NULL);
4724         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
4725      }
4726
4727    return;
4728
4729 error:
4730    if (del_cb) del_cb((void *)data, NULL, NULL);
4731 }
4732
4733 /**
4734  * Unset tooltip from item
4735  *
4736  * @param item genlist item to remove previously set tooltip.
4737  *
4738  * Remove tooltip from item. The callback provided as del_cb to
4739  * elm_genlist_item_tooltip_content_cb_set() will be called to notify
4740  * it is not used anymore.
4741  *
4742  * @see elm_genlist_item_tooltip_content_cb_set()
4743  *
4744  * @ingroup Genlist
4745  */
4746 EAPI void
4747 elm_genlist_item_tooltip_unset(Elm_Genlist_Item *item)
4748 {
4749    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4750    if ((item->base.view) && (item->tooltip.content_cb))
4751      elm_widget_item_tooltip_unset(item);
4752
4753    if (item->tooltip.del_cb)
4754      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
4755    item->tooltip.del_cb = NULL;
4756    item->tooltip.content_cb = NULL;
4757    item->tooltip.data = NULL;
4758    if (item->tooltip.style)
4759      elm_genlist_item_tooltip_style_set(item, NULL);
4760 }
4761
4762 /**
4763  * Sets a different style for this item tooltip.
4764  *
4765  * @note before you set a style you should define a tooltip with
4766  *       elm_genlist_item_tooltip_content_cb_set() or
4767  *       elm_genlist_item_tooltip_text_set()
4768  *
4769  * @param item genlist item with tooltip already set.
4770  * @param style the theme style to use (default, transparent, ...)
4771  *
4772  * @ingroup Genlist
4773  */
4774 EAPI void
4775 elm_genlist_item_tooltip_style_set(Elm_Genlist_Item *item,
4776                                    const char       *style)
4777 {
4778    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4779    eina_stringshare_replace(&item->tooltip.style, style);
4780    if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
4781 }
4782
4783 /**
4784  * Get the style for this item tooltip.
4785  *
4786  * @param item genlist item with tooltip already set.
4787  * @return style the theme style in use, defaults to "default". If the
4788  *         object does not have a tooltip set, then NULL is returned.
4789  *
4790  * @ingroup Genlist
4791  */
4792 EAPI const char *
4793 elm_genlist_item_tooltip_style_get(const Elm_Genlist_Item *item)
4794 {
4795    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4796    return item->tooltip.style;
4797 }
4798
4799 EAPI Eina_Bool
4800 elm_genlist_item_tooltip_size_restrict_disable(Elm_Genlist_Item *item, Eina_Bool disable)
4801 {
4802    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
4803    return elm_widget_item_tooltip_size_restrict_disable(item, disable);
4804 }
4805
4806 EAPI Eina_Bool
4807 elm_genlist_item_tooltip_size_restrict_disabled_get(const Elm_Genlist_Item *item)
4808 {
4809    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
4810    return elm_widget_item_tooltip_size_restrict_disabled_get(item);
4811 }
4812
4813 /**
4814  * Set the cursor to be shown when mouse is over the genlist item
4815  *
4816  * @param item Target item
4817  * @param cursor the cursor name to be used.
4818  *
4819  * @see elm_object_cursor_set()
4820  * @ingroup Genlist
4821  */
4822 EAPI void
4823 elm_genlist_item_cursor_set(Elm_Genlist_Item *item,
4824                             const char       *cursor)
4825 {
4826    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4827    eina_stringshare_replace(&item->mouse_cursor, cursor);
4828    if (item->base.view) elm_widget_item_cursor_set(item, cursor);
4829 }
4830
4831 /**
4832  * Get the cursor to be shown when mouse is over the genlist item
4833  *
4834  * @param item genlist item with cursor already set.
4835  * @return the cursor name.
4836  *
4837  * @ingroup Genlist
4838  */
4839 EAPI const char *
4840 elm_genlist_item_cursor_get(const Elm_Genlist_Item *item)
4841 {
4842    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4843    return elm_widget_item_cursor_get(item);
4844 }
4845
4846 /**
4847  * Unset the cursor to be shown when mouse is over the genlist item
4848  *
4849  * @param item Target item
4850  *
4851  * @see elm_object_cursor_unset()
4852  * @ingroup Genlist
4853  */
4854 EAPI void
4855 elm_genlist_item_cursor_unset(Elm_Genlist_Item *item)
4856 {
4857    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4858    if (!item->mouse_cursor)
4859      return;
4860
4861    if (item->base.view)
4862      elm_widget_item_cursor_unset(item);
4863
4864    eina_stringshare_del(item->mouse_cursor);
4865    item->mouse_cursor = NULL;
4866 }
4867
4868 /**
4869  * Sets a different style for this item cursor.
4870  *
4871  * @note before you set a style you should define a cursor with
4872  *       elm_genlist_item_cursor_set()
4873  *
4874  * @param item genlist item with cursor already set.
4875  * @param style the theme style to use (default, transparent, ...)
4876  *
4877  * @ingroup Genlist
4878  */
4879 EAPI void
4880 elm_genlist_item_cursor_style_set(Elm_Genlist_Item *item,
4881                                   const char       *style)
4882 {
4883    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4884    elm_widget_item_cursor_style_set(item, style);
4885 }
4886
4887 /**
4888  * Get the style for this item cursor.
4889  *
4890  * @param item genlist item with cursor already set.
4891  * @return style the theme style in use, defaults to "default". If the
4892  *         object does not have a cursor set, then NULL is returned.
4893  *
4894  * @ingroup Genlist
4895  */
4896 EAPI const char *
4897 elm_genlist_item_cursor_style_get(const Elm_Genlist_Item *item)
4898 {
4899    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4900    return elm_widget_item_cursor_style_get(item);
4901 }
4902
4903 /**
4904  * Set if the cursor set should be searched on the theme or should use
4905  * the provided by the engine, only.
4906  *
4907  * @note before you set if should look on theme you should define a
4908  * cursor with elm_object_cursor_set(). By default it will only look
4909  * for cursors provided by the engine.
4910  *
4911  * @param item widget item with cursor already set.
4912  * @param engine_only boolean to define it cursors should be looked
4913  * only between the provided by the engine or searched on widget's
4914  * theme as well.
4915  *
4916  * @ingroup Genlist
4917  */
4918 EAPI void
4919 elm_genlist_item_cursor_engine_only_set(Elm_Genlist_Item *item,
4920                                         Eina_Bool         engine_only)
4921 {
4922    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4923    elm_widget_item_cursor_engine_only_set(item, engine_only);
4924 }
4925
4926 /**
4927  * Get the cursor engine only usage for this item cursor.
4928  *
4929  * @param item widget item with cursor already set.
4930  * @return engine_only boolean to define it cursors should be looked
4931  * only between the provided by the engine or searched on widget's
4932  * theme as well. If the object does not have a cursor set, then
4933  * EINA_FALSE is returned.
4934  *
4935  * @ingroup Genlist
4936  */
4937 EAPI Eina_Bool
4938 elm_genlist_item_cursor_engine_only_get(const Elm_Genlist_Item *item)
4939 {
4940    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
4941    return elm_widget_item_cursor_engine_only_get(item);
4942 }
4943
4944 EAPI void
4945 elm_genlist_horizontal_mode_set(Evas_Object  *obj,
4946                                 Elm_List_Mode mode)
4947 {
4948    ELM_CHECK_WIDTYPE(obj, widtype);
4949    Widget_Data *wd = elm_widget_data_get(obj);
4950    if (!wd) return;
4951    if (wd->mode == mode) return;
4952    wd->mode = mode;
4953    _sizing_eval(obj);
4954 }
4955
4956 EAPI Elm_List_Mode
4957 elm_genlist_horizontal_mode_get(const Evas_Object *obj)
4958 {
4959    ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
4960    Widget_Data *wd = elm_widget_data_get(obj);
4961    if (!wd) return ELM_LIST_LAST;
4962    return wd->mode;
4963 }
4964
4965 EAPI void
4966 elm_genlist_always_select_mode_set(Evas_Object *obj,
4967                                    Eina_Bool    always_select)
4968 {
4969    ELM_CHECK_WIDTYPE(obj, widtype);
4970    Widget_Data *wd = elm_widget_data_get(obj);
4971    if (!wd) return;
4972    wd->always_select = always_select;
4973 }
4974
4975 EAPI Eina_Bool
4976 elm_genlist_always_select_mode_get(const Evas_Object *obj)
4977 {
4978    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4979    Widget_Data *wd = elm_widget_data_get(obj);
4980    if (!wd) return EINA_FALSE;
4981    return wd->always_select;
4982 }
4983
4984 EAPI void
4985 elm_genlist_no_select_mode_set(Evas_Object *obj,
4986                                Eina_Bool    no_select)
4987 {
4988    ELM_CHECK_WIDTYPE(obj, widtype);
4989    Widget_Data *wd = elm_widget_data_get(obj);
4990    if (!wd) return;
4991    wd->no_select = no_select;
4992 }
4993
4994 EAPI Eina_Bool
4995 elm_genlist_no_select_mode_get(const Evas_Object *obj)
4996 {
4997    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4998    Widget_Data *wd = elm_widget_data_get(obj);
4999    if (!wd) return EINA_FALSE;
5000    return wd->no_select;
5001 }
5002
5003 EAPI void
5004 elm_genlist_compress_mode_set(Evas_Object *obj,
5005                               Eina_Bool    compress)
5006 {
5007    ELM_CHECK_WIDTYPE(obj, widtype);
5008    Widget_Data *wd = elm_widget_data_get(obj);
5009    if (!wd) return;
5010    wd->compress = compress;
5011    if (!compress) elm_genlist_homogeneous_set(obj, EINA_FALSE);
5012 }
5013
5014 EAPI Eina_Bool
5015 elm_genlist_compress_mode_get(const Evas_Object *obj)
5016 {
5017    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5018    Widget_Data *wd = elm_widget_data_get(obj);
5019    if (!wd) return EINA_FALSE;
5020    return wd->compress;
5021 }
5022
5023 EAPI void
5024 elm_genlist_height_for_width_mode_set(Evas_Object *obj,
5025                                       Eina_Bool    height_for_width)
5026 {
5027    ELM_CHECK_WIDTYPE(obj, widtype);
5028    Widget_Data *wd = elm_widget_data_get(obj);
5029    if (!wd) return;
5030    wd->height_for_width = !!height_for_width;
5031    if (wd->height_for_width)
5032      {
5033         elm_genlist_homogeneous_set(obj, EINA_FALSE);
5034         elm_genlist_compress_mode_set(obj, EINA_TRUE);
5035      }
5036 }
5037
5038 EAPI Eina_Bool
5039 elm_genlist_height_for_width_mode_get(const Evas_Object *obj)
5040 {
5041    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5042    Widget_Data *wd = elm_widget_data_get(obj);
5043    if (!wd) return EINA_FALSE;
5044    return wd->height_for_width;
5045 }
5046
5047 EAPI void
5048 elm_genlist_bounce_set(Evas_Object *obj,
5049                        Eina_Bool    h_bounce,
5050                        Eina_Bool    v_bounce)
5051 {
5052    ELM_CHECK_WIDTYPE(obj, widtype);
5053    Widget_Data *wd = elm_widget_data_get(obj);
5054    if (!wd) return;
5055    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
5056 }
5057
5058 EAPI void
5059 elm_genlist_bounce_get(const Evas_Object *obj,
5060                        Eina_Bool         *h_bounce,
5061                        Eina_Bool         *v_bounce)
5062 {
5063    ELM_CHECK_WIDTYPE(obj, widtype);
5064    Widget_Data *wd = elm_widget_data_get(obj);
5065    if (!wd) return;
5066    elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
5067 }
5068
5069 EAPI void
5070 elm_genlist_homogeneous_set(Evas_Object *obj,
5071                             Eina_Bool    homogeneous)
5072 {
5073    ELM_CHECK_WIDTYPE(obj, widtype);
5074    Widget_Data *wd = elm_widget_data_get(obj);
5075    if (!wd) return;
5076    if (homogeneous) elm_genlist_compress_mode_set(obj, EINA_TRUE);
5077    wd->homogeneous = homogeneous;
5078 }
5079
5080 EAPI Eina_Bool
5081 elm_genlist_homogeneous_get(const Evas_Object *obj)
5082 {
5083    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5084    Widget_Data *wd = elm_widget_data_get(obj);
5085    if (!wd) return EINA_FALSE;
5086    return wd->homogeneous;
5087 }
5088
5089 EAPI void
5090 elm_genlist_block_count_set(Evas_Object *obj,
5091                             int          n)
5092 {
5093    ELM_CHECK_WIDTYPE(obj, widtype);
5094    Widget_Data *wd = elm_widget_data_get(obj);
5095    if (!wd) return;
5096    wd->max_items_per_block = n;
5097    wd->item_cache_max = wd->max_items_per_block * 2;
5098    _item_cache_clean(wd);
5099 }
5100
5101 EAPI int
5102 elm_genlist_block_count_get(const Evas_Object *obj)
5103 {
5104    ELM_CHECK_WIDTYPE(obj, widtype) 0;
5105    Widget_Data *wd = elm_widget_data_get(obj);
5106    if (!wd) return 0;
5107    return wd->max_items_per_block;
5108 }
5109
5110 EAPI void
5111 elm_genlist_longpress_timeout_set(Evas_Object *obj,
5112                                   double       timeout)
5113 {
5114    ELM_CHECK_WIDTYPE(obj, widtype);
5115    Widget_Data *wd = elm_widget_data_get(obj);
5116    if (!wd) return;
5117    wd->longpress_timeout = timeout;
5118 }
5119
5120 EAPI double
5121 elm_genlist_longpress_timeout_get(const Evas_Object *obj)
5122 {
5123    ELM_CHECK_WIDTYPE(obj, widtype) 0;
5124    Widget_Data *wd = elm_widget_data_get(obj);
5125    if (!wd) return 0;
5126    return wd->longpress_timeout;
5127 }
5128
5129 EAPI void
5130 elm_genlist_scroller_policy_set(Evas_Object        *obj,
5131                                 Elm_Scroller_Policy policy_h,
5132                                 Elm_Scroller_Policy policy_v)
5133 {
5134    ELM_CHECK_WIDTYPE(obj, widtype);
5135    Widget_Data *wd = elm_widget_data_get(obj);
5136    if (!wd) return;
5137    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
5138        (policy_v >= ELM_SCROLLER_POLICY_LAST))
5139      return;
5140    if (wd->scr)
5141      elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
5142 }
5143
5144 EAPI void
5145 elm_genlist_scroller_policy_get(const Evas_Object   *obj,
5146                                 Elm_Scroller_Policy *policy_h,
5147                                 Elm_Scroller_Policy *policy_v)
5148 {
5149    ELM_CHECK_WIDTYPE(obj, widtype);
5150    Widget_Data *wd = elm_widget_data_get(obj);
5151    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
5152    if ((!wd) || (!wd->scr)) return;
5153    elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
5154    if (policy_h) *policy_h = (Elm_Scroller_Policy)s_policy_h;
5155    if (policy_v) *policy_v = (Elm_Scroller_Policy)s_policy_v;
5156 }
5157
5158 EAPI void
5159 elm_genlist_realized_items_update(Evas_Object *obj)
5160 {
5161    ELM_CHECK_WIDTYPE(obj, widtype);
5162
5163    Eina_List *list, *l;
5164    Elm_Genlist_Item *it;
5165
5166    list = elm_genlist_realized_items_get(obj);
5167    EINA_LIST_FOREACH(list, l, it)
5168      elm_genlist_item_update(it);
5169 }
5170
5171 /**
5172  * Set genlist item mode
5173  *
5174  * @param item The genlist item
5175  * @param mode Mode name
5176  * @param mode_set Boolean to define set or unset mode.
5177  *
5178  * @ingroup Genlist
5179  */
5180 EAPI void
5181 elm_genlist_item_mode_set(Elm_Genlist_Item *it,
5182                           const char       *mode_type,
5183                           Eina_Bool         mode_set)
5184 {
5185    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
5186    Widget_Data *wd = it->wd;
5187    Eina_List *l;
5188    Elm_Genlist_Item *it2;
5189
5190    if (!wd) return;
5191    if (!mode_type) return;
5192    if ((it->delete_me) || (it->disabled)) return;
5193
5194    if ((wd->mode_item == it) &&
5195        (!strcmp(mode_type, wd->mode_type)) &&
5196        (mode_set))
5197       return;
5198    if (!it->itc->mode_item_style) return;
5199
5200    if (wd->multi)
5201      {
5202         EINA_LIST_FOREACH(wd->selected, l, it2)
5203           if (it2->realized)
5204             elm_genlist_item_selected_set(it2, EINA_FALSE);
5205      }
5206    else
5207      {
5208         it2 = elm_genlist_selected_item_get(wd->obj);
5209         if ((it2) && (it2->realized))
5210           elm_genlist_item_selected_set(it2, EINA_FALSE);
5211      }
5212
5213    if (((wd->mode_type) && (strcmp(mode_type, wd->mode_type))) ||
5214        (mode_set) ||
5215        ((it == wd->mode_item) && (!mode_set)))
5216      _item_mode_unset(wd);
5217
5218    eina_stringshare_replace(&wd->mode_type, mode_type);
5219    if (mode_set) _item_mode_set(it);
5220 }
5221
5222 /**
5223  * Get active genlist mode type
5224  *
5225  * @param obj The genlist object
5226  *
5227  * @ingroup Genlist
5228  */
5229 EAPI const char *
5230 elm_genlist_mode_get(const Evas_Object *obj)
5231 {
5232    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5233    Widget_Data *wd = elm_widget_data_get(obj);
5234    if (!wd) return NULL;
5235    return wd->mode_type;
5236 }
5237
5238 /**
5239  * Get active genlist mode item
5240  *
5241  * @param obj The genlist object
5242  *
5243  * @ingroup Genlist
5244  */
5245 EAPI const Elm_Genlist_Item *
5246 elm_genlist_mode_item_get(const Evas_Object *obj)
5247 {
5248    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5249    Widget_Data *wd = elm_widget_data_get(obj);
5250    if (!wd) return NULL;
5251    return wd->mode_item;
5252 }
5253
5254 /**
5255  * Set reorder mode
5256  *
5257  * @param obj The genlist object
5258  * @param reorder_mode The reorder mode
5259  * (EINA_TRUE = on, EINA_FALSE = off)
5260  *
5261  * @ingroup Genlist
5262  */
5263 EAPI void
5264 elm_genlist_reorder_mode_set(Evas_Object *obj,
5265                              Eina_Bool    reorder_mode)
5266 {
5267    ELM_CHECK_WIDTYPE(obj, widtype);
5268    Widget_Data *wd = elm_widget_data_get(obj);
5269    if (!wd) return;
5270    wd->reorder_mode = reorder_mode;
5271 }
5272
5273 /**
5274  * Get the reorder mode
5275  *
5276  * @param obj The genlist object
5277  * @return The reorder mode
5278  * (EINA_TRUE = on, EINA_FALSE = off)
5279  *
5280  * @ingroup Genlist
5281  */
5282 EAPI Eina_Bool
5283 elm_genlist_reorder_mode_get(const Evas_Object *obj)
5284 {
5285    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5286    Widget_Data *wd = elm_widget_data_get(obj);
5287    if (!wd) return EINA_FALSE;
5288    return wd->reorder_mode;
5289 }