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