elementary: fix some parental issue with genlist.
[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 /**
3369  * Add item to the end of the genlist
3370  *
3371  * This adds the given item to the end of the list or the end of
3372  * the children if the parent is given.
3373  *
3374  * @param obj The genlist object
3375  * @param itc The item class for the item
3376  * @param data The item data
3377  * @param parent The parent item, or NULL if none
3378  * @param flags Item flags
3379  * @param func Convenience function called when item selected
3380  * @param func_data Data passed to @p func above.
3381  * @return A handle to the item added or NULL if not possible
3382  *
3383  * @ingroup Genlist
3384  */
3385 EAPI Elm_Genlist_Item *
3386 elm_genlist_item_append(Evas_Object                  *obj,
3387                         const Elm_Genlist_Item_Class *itc,
3388                         const void                   *data,
3389                         Elm_Genlist_Item             *parent,
3390                         Elm_Genlist_Item_Flags        flags,
3391                         Evas_Smart_Cb                 func,
3392                         const void                   *func_data)
3393 {
3394    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3395    Widget_Data *wd = elm_widget_data_get(obj);
3396    if (!wd) return NULL;
3397    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3398                                     func_data);
3399    if (!it) return NULL;
3400    if (!it->parent)
3401      {
3402         if (flags & ELM_GENLIST_ITEM_GROUP)
3403           wd->group_items = eina_list_append(wd->group_items, it);
3404         wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
3405         it->rel = NULL;
3406      }
3407    else
3408      {
3409         Elm_Genlist_Item *it2 = NULL;
3410         Eina_List *ll = eina_list_last(it->parent->items);
3411         if (ll) it2 = ll->data;
3412         it->parent->items = eina_list_append(it->parent->items, it);
3413         if (!it2) it2 = it->parent;
3414         wd->items =
3415           eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3416                                       EINA_INLIST_GET(it2));
3417         it->rel = it2;
3418         it->rel->relcount++;
3419
3420         if (it->parent->flags & ELM_GENLIST_ITEM_GROUP)
3421           it->group_item = parent;
3422         else if (it->parent->group_item)
3423           it->group_item = it->parent->group_item;
3424      }
3425    it->before = EINA_FALSE;
3426    _item_queue(wd, it);
3427    return it;
3428 }
3429
3430 /**
3431  * Add item at start of the genlist
3432  *
3433  * This adds an item to the beginning of the list or beginning of the
3434  * children of the parent if given.
3435  *
3436  * @param obj The genlist object
3437  * @param itc The item class for the item
3438  * @param data The item data
3439  * @param parent The parent item, or NULL if none
3440  * @param flags Item flags
3441  * @param func Convenience function called when item selected
3442  * @param func_data Data passed to @p func above.
3443  * @return A handle to the item added or NULL if not possible
3444  *
3445  * @ingroup Genlist
3446  */
3447 EAPI Elm_Genlist_Item *
3448 elm_genlist_item_prepend(Evas_Object                  *obj,
3449                          const Elm_Genlist_Item_Class *itc,
3450                          const void                   *data,
3451                          Elm_Genlist_Item             *parent,
3452                          Elm_Genlist_Item_Flags        flags,
3453                          Evas_Smart_Cb                 func,
3454                          const void                   *func_data)
3455 {
3456    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3457    Widget_Data *wd = elm_widget_data_get(obj);
3458    if (!wd) return NULL;
3459    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3460                                     func_data);
3461    if (!it) return NULL;
3462    if (!it->parent)
3463      {
3464         if (flags & ELM_GENLIST_ITEM_GROUP)
3465           wd->group_items = eina_list_prepend(wd->group_items, it);
3466         wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
3467         it->rel = NULL;
3468      }
3469    else
3470      {
3471         Elm_Genlist_Item *it2 = NULL;
3472         Eina_List *ll = it->parent->items;
3473         if (ll) it2 = ll->data;
3474         it->parent->items = eina_list_prepend(it->parent->items, it);
3475         if (!it2) it2 = it->parent;
3476         wd->items =
3477           eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3478                                        EINA_INLIST_GET(it2));
3479         it->rel = it2;
3480         it->rel->relcount++;
3481      }
3482    it->before = EINA_TRUE;
3483    _item_queue(wd, it);
3484    return it;
3485 }
3486
3487 /**
3488  * Insert item before another in the genlist
3489  *
3490  * This inserts an item before another in the list. It will be in the
3491  * same tree level or group as the item it is inseted before.
3492  *
3493  * @param obj The genlist object
3494  * @param itc The item class for the item
3495  * @param data The item data
3496  * @param before The item to insert before
3497  * @param flags Item flags
3498  * @param func Convenience function called when item selected
3499  * @param func_data Data passed to @p func above.
3500  * @return A handle to the item added or NULL if not possible
3501  *
3502  * @ingroup Genlist
3503  */
3504 EAPI Elm_Genlist_Item *
3505 elm_genlist_item_insert_before(Evas_Object                  *obj,
3506                                const Elm_Genlist_Item_Class *itc,
3507                                const void                   *data,
3508                                Elm_Genlist_Item             *parent,
3509                                Elm_Genlist_Item             *before,
3510                                Elm_Genlist_Item_Flags        flags,
3511                                Evas_Smart_Cb                 func,
3512                                const void                   *func_data)
3513 {
3514    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3515    EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
3516    Widget_Data *wd = elm_widget_data_get(obj);
3517    if (!wd) return NULL;
3518    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3519                                     func_data);
3520    if (!it) return NULL;
3521    if (it->parent)
3522      {
3523         it->parent->items = eina_list_prepend_relative(it->parent->items, it,
3524                                                        before);
3525      }
3526    wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3527                                             EINA_INLIST_GET(before));
3528    it->rel = before;
3529    it->rel->relcount++;
3530    it->before = EINA_TRUE;
3531    _item_queue(wd, it);
3532    return it;
3533 }
3534
3535 EAPI Elm_Genlist_Item *
3536 elm_genlist_item_direct_sorted_insert(Evas_Object                  *obj,
3537                                       const Elm_Genlist_Item_Class *itc,
3538                                       const void                   *data,
3539                                       Elm_Genlist_Item             *parent,
3540                                       Elm_Genlist_Item_Flags        flags,
3541                                       Eina_Compare_Cb               comp,
3542                                       Evas_Smart_Cb                 func,
3543                                       const void                   *func_data)
3544 {
3545    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3546    Widget_Data *wd = elm_widget_data_get(obj);
3547    if (!wd) return NULL;
3548    Elm_Genlist_Item *rel = NULL;
3549    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3550                                     func_data);
3551    if (!it) return NULL;
3552
3553    _elm_genlist_item_compare_cb = comp;
3554
3555    if (it->parent)
3556      {
3557         Eina_List *l;
3558         int cmp_result;
3559
3560         l = eina_list_search_sorted_near_list(it->parent->items,
3561                                               _elm_genlist_item_list_compare, it,
3562                                               &cmp_result);
3563         if (l)
3564           rel = eina_list_data_get(l);
3565         else
3566           rel = it->parent;
3567
3568         if (cmp_result > 0)
3569           {
3570              it->parent->items = eina_list_prepend_relative_list(it->parent->items, it, l);
3571              wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(rel));
3572              it->before = EINA_FALSE;
3573           }
3574         else if (cmp_result < 0)
3575           {
3576              it->parent->items = eina_list_append_relative_list(it->parent->items, it, l);
3577              wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(rel));
3578              it->before = EINA_TRUE;
3579           }
3580
3581         if (it->parent->flags & ELM_GENLIST_ITEM_GROUP)
3582           it->group_item = parent;
3583         else if (it->parent->group_item)
3584           it->group_item = it->parent->group_item;
3585      }
3586    else
3587      {
3588         if (flags & ELM_GENLIST_ITEM_GROUP)
3589           wd->group_items = eina_list_append(wd->group_items, it);
3590
3591         wd->items = eina_inlist_sorted_insert(wd->items, EINA_INLIST_GET(it),
3592                                               _elm_genlist_item_compare);
3593
3594         if (EINA_INLIST_GET(it)->next)
3595           {
3596              rel = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3597              it->before = EINA_TRUE;
3598           }
3599         else if (EINA_INLIST_GET(it)->prev)
3600           {
3601              rel = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3602              it->before = EINA_FALSE;
3603           }
3604      }
3605
3606    if (rel)
3607      {
3608         it->rel = rel;
3609         it->rel->relcount++;
3610      }
3611
3612    _item_queue(wd, it);
3613
3614    return it;
3615 }
3616
3617 /**
3618  * Insert a new item into the sorted genlist object
3619  *
3620  * @param obj The genlist object
3621  * @param itc The item class for the item
3622  * @param data The item data
3623  * @param parent The parent item, or NULL if none
3624  * @param flags Item flags
3625  * @param comp The function called for the sort
3626  * @param func Convenience function called when item selected
3627  * @param func_data Data passed to @p func above.
3628  * @return A handle to the item added or NULL if not possible
3629  *
3630  * @ingroup Genlist
3631  */
3632 EAPI Elm_Genlist_Item *
3633 elm_genlist_item_sorted_insert(Evas_Object                  *obj,
3634                                const Elm_Genlist_Item_Class *itc,
3635                                const void                   *data,
3636                                Elm_Genlist_Item             *parent,
3637                                Elm_Genlist_Item_Flags        flags,
3638                                Eina_Compare_Cb               comp,
3639                                Evas_Smart_Cb                 func,
3640                                const void                   *func_data)
3641 {
3642    _elm_genlist_item_compare_data_cb = comp;
3643
3644    return elm_genlist_item_direct_sorted_insert(obj, itc, data, parent, flags,
3645                                                 _elm_genlist_item_compare_data, func, func_data);
3646 }
3647
3648 /**
3649  * Insert an item after another in the genlst
3650  *
3651  * This inserts an item after another in the list. It will be in the
3652  * same tree level or group as the item it is inseted after.
3653  *
3654  * @param obj The genlist object
3655  * @param itc The item class for the item
3656  * @param data The item data
3657  * @param after The item to insert after
3658  * @param flags Item flags
3659  * @param func Convenience function called when item selected
3660  * @param func_data Data passed to @p func above.
3661  * @return A handle to the item added or NULL if not possible
3662  *
3663  * @ingroup Genlist
3664  */
3665 EAPI Elm_Genlist_Item *
3666 elm_genlist_item_insert_after(Evas_Object                  *obj,
3667                               const Elm_Genlist_Item_Class *itc,
3668                               const void                   *data,
3669                               Elm_Genlist_Item             *parent,
3670                               Elm_Genlist_Item             *after,
3671                               Elm_Genlist_Item_Flags        flags,
3672                               Evas_Smart_Cb                 func,
3673                               const void                   *func_data)
3674 {
3675    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3676    EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
3677    Widget_Data *wd = elm_widget_data_get(obj);
3678    if (!wd) return NULL;
3679    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3680                                     func_data);
3681    if (!it) return NULL;
3682    /* It make no sense to insert after in an empty list with after != NULL, something really bad is happening in your app. */
3683    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->items, NULL);
3684
3685    wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3686                                            EINA_INLIST_GET(after));
3687    if (it->parent)
3688      {
3689         it->parent->items = eina_list_append_relative(it->parent->items, it,
3690                                                       after);
3691      }
3692    it->rel = after;
3693    it->rel->relcount++;
3694    it->before = EINA_FALSE;
3695    _item_queue(wd, it);
3696    return it;
3697 }
3698
3699 EAPI void
3700 elm_genlist_clear(Evas_Object *obj)
3701 {
3702    ELM_CHECK_WIDTYPE(obj, widtype);
3703    Widget_Data *wd = elm_widget_data_get(obj);
3704    if (!wd) return;
3705    if (wd->walking > 0)
3706      {
3707         Elm_Genlist_Item *it;
3708
3709         wd->clear_me = EINA_TRUE;
3710         EINA_INLIST_FOREACH(wd->items, it)
3711           {
3712              it->delete_me = EINA_TRUE;
3713           }
3714         return;
3715      }
3716    evas_event_freeze(evas_object_evas_get(wd->obj));
3717    while (wd->items)
3718      {
3719         Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3720
3721         if (wd->anchor_item == it)
3722           {
3723              wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3724              if (!wd->anchor_item)
3725                wd->anchor_item =
3726                  ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3727           }
3728         wd->items = eina_inlist_remove(wd->items, wd->items);
3729         if (it->flags & ELM_GENLIST_ITEM_GROUP)
3730           it->wd->group_items = eina_list_remove(it->wd->group_items, it);
3731         elm_widget_item_pre_notify_del(it);
3732         if (it->realized) _item_unrealize(it, EINA_FALSE);
3733         if (((wd->clear_me) || (!it->delete_me)) && (it->itc->func.del))
3734           it->itc->func.del((void *)it->base.data, it->base.widget);
3735         if (it->long_timer) ecore_timer_del(it->long_timer);
3736         if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
3737         elm_widget_item_del(it);
3738      }
3739    wd->clear_me = EINA_FALSE;
3740    wd->anchor_item = NULL;
3741    while (wd->blocks)
3742      {
3743         Item_Block *itb = (Item_Block *)(wd->blocks);
3744
3745         wd->blocks = eina_inlist_remove(wd->blocks, wd->blocks);
3746         if (itb->items) eina_list_free(itb->items);
3747         free(itb);
3748      }
3749    if (wd->calc_job)
3750      {
3751         ecore_job_del(wd->calc_job);
3752         wd->calc_job = NULL;
3753      }
3754    if (wd->queue_idle_enterer)
3755      {
3756         ecore_idle_enterer_del(wd->queue_idle_enterer);
3757         wd->queue_idle_enterer = NULL;
3758      }
3759    if (wd->must_recalc_idler)
3760      {
3761         ecore_idler_del(wd->must_recalc_idler);
3762         wd->must_recalc_idler = NULL;
3763      }
3764    if (wd->queue)
3765      {
3766         eina_list_free(wd->queue);
3767         wd->queue = NULL;
3768      }
3769    if (wd->selected)
3770      {
3771         eina_list_free(wd->selected);
3772         wd->selected = NULL;
3773      }
3774    if (wd->reorder_move_animator)
3775      {
3776         ecore_animator_del(wd->reorder_move_animator);
3777         wd->reorder_move_animator = NULL;
3778      }
3779    wd->show_item = NULL;
3780    wd->pan_x = 0;
3781    wd->pan_y = 0;
3782    wd->old_pan_y = 0;
3783    wd->minw = 0;
3784    wd->minh = 0;
3785    if (wd->pan_smart)
3786      {
3787         evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
3788         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
3789      }
3790    _sizing_eval(obj);
3791    evas_event_thaw(evas_object_evas_get(wd->obj));
3792    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3793 }
3794
3795 EAPI void
3796 elm_genlist_multi_select_set(Evas_Object *obj,
3797                              Eina_Bool    multi)
3798 {
3799    ELM_CHECK_WIDTYPE(obj, widtype);
3800    Widget_Data *wd = elm_widget_data_get(obj);
3801    if (!wd) return;
3802    wd->multi = multi;
3803 }
3804
3805 EAPI Eina_Bool
3806 elm_genlist_multi_select_get(const Evas_Object *obj)
3807 {
3808    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3809    Widget_Data *wd = elm_widget_data_get(obj);
3810    if (!wd) return EINA_FALSE;
3811    return wd->multi;
3812 }
3813
3814 EAPI Elm_Genlist_Item *
3815 elm_genlist_selected_item_get(const Evas_Object *obj)
3816 {
3817    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3818    Widget_Data *wd = elm_widget_data_get(obj);
3819    if (!wd) return NULL;
3820    if (wd->selected) return wd->selected->data;
3821    return NULL;
3822 }
3823
3824 EAPI const Eina_List *
3825 elm_genlist_selected_items_get(const Evas_Object *obj)
3826 {
3827    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3828    Widget_Data *wd = elm_widget_data_get(obj);
3829    if (!wd) return NULL;
3830    return wd->selected;
3831 }
3832
3833 EAPI Eina_List *
3834 elm_genlist_realized_items_get(const Evas_Object *obj)
3835 {
3836    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3837    Widget_Data *wd = elm_widget_data_get(obj);
3838    Eina_List *list = NULL;
3839    Item_Block *itb;
3840    Eina_Bool done = EINA_FALSE;
3841    if (!wd) return NULL;
3842    EINA_INLIST_FOREACH(wd->blocks, itb)
3843      {
3844         if (itb->realized)
3845           {
3846              Eina_List *l;
3847              Elm_Genlist_Item *it;
3848
3849              done = 1;
3850              EINA_LIST_FOREACH(itb->items, l, it)
3851                {
3852                   if (it->realized) list = eina_list_append(list, it);
3853                }
3854           }
3855         else
3856           {
3857              if (done) break;
3858           }
3859      }
3860    return list;
3861 }
3862
3863 EAPI Elm_Genlist_Item *
3864 elm_genlist_at_xy_item_get(const Evas_Object *obj,
3865                            Evas_Coord         x,
3866                            Evas_Coord         y,
3867                            int               *posret)
3868 {
3869    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3870    Widget_Data *wd = elm_widget_data_get(obj);
3871    Evas_Coord ox, oy, ow, oh;
3872    Item_Block *itb;
3873    Evas_Coord lasty;
3874    if (!wd) return NULL;
3875    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
3876    lasty = oy;
3877    EINA_INLIST_FOREACH(wd->blocks, itb)
3878      {
3879         Eina_List *l;
3880         Elm_Genlist_Item *it;
3881
3882         if (!ELM_RECTS_INTERSECT(ox + itb->x - itb->wd->pan_x,
3883                                  oy + itb->y - itb->wd->pan_y,
3884                                  itb->w, itb->h, x, y, 1, 1))
3885           continue;
3886         EINA_LIST_FOREACH(itb->items, l, it)
3887           {
3888              Evas_Coord itx, ity;
3889
3890              itx = ox + itb->x + it->x - itb->wd->pan_x;
3891              ity = oy + itb->y + it->y - itb->wd->pan_y;
3892              if (ELM_RECTS_INTERSECT(itx, ity, it->w, it->h, x, y, 1, 1))
3893                {
3894                   if (posret)
3895                     {
3896                        if (y <= (ity + (it->h / 4))) *posret = -1;
3897                        else if (y >= (ity + it->h - (it->h / 4)))
3898                          *posret = 1;
3899                        else *posret = 0;
3900                     }
3901                   return it;
3902                }
3903              lasty = ity + it->h;
3904           }
3905      }
3906    if (posret)
3907      {
3908         if (y > lasty) *posret = 1;
3909         else *posret = -1;
3910      }
3911    return NULL;
3912 }
3913
3914 /**
3915  * Get the first item in the genlist
3916  *
3917  * This returns the first item in the list.
3918  *
3919  * @param obj The genlist object
3920  * @return The first item, or NULL if none
3921  *
3922  * @ingroup Genlist
3923  */
3924 EAPI Elm_Genlist_Item *
3925 elm_genlist_first_item_get(const Evas_Object *obj)
3926 {
3927    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3928    Widget_Data *wd = elm_widget_data_get(obj);
3929    if (!wd) return NULL;
3930    if (!wd->items) return NULL;
3931    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3932    while ((it) && (it->delete_me))
3933      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3934    return it;
3935 }
3936
3937 /**
3938  * Get the last item in the genlist
3939  *
3940  * This returns the last item in the list.
3941  *
3942  * @return The last item, or NULL if none
3943  *
3944  * @ingroup Genlist
3945  */
3946 EAPI Elm_Genlist_Item *
3947 elm_genlist_last_item_get(const Evas_Object *obj)
3948 {
3949    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3950    Widget_Data *wd = elm_widget_data_get(obj);
3951    if (!wd) return NULL;
3952    if (!wd->items) return NULL;
3953    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items->last);
3954    while ((it) && (it->delete_me))
3955      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3956    return it;
3957 }
3958
3959 /**
3960  * Get the next item in the genlist
3961  *
3962  * This returns the item after the item @p it.
3963  *
3964  * @param it The item
3965  * @return The item after @p it, or NULL if none
3966  *
3967  * @ingroup Genlist
3968  */
3969 EAPI Elm_Genlist_Item *
3970 elm_genlist_item_next_get(const Elm_Genlist_Item *it)
3971 {
3972    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3973    while (it)
3974      {
3975         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3976         if ((it) && (!it->delete_me)) break;
3977      }
3978    return (Elm_Genlist_Item *)it;
3979 }
3980
3981 /**
3982  * Get the previous item in the genlist
3983  *
3984  * This returns the item before the item @p it.
3985  *
3986  * @param it The item
3987  * @return The item before @p it, or NULL if none
3988  *
3989  * @ingroup Genlist
3990  */
3991 EAPI Elm_Genlist_Item *
3992 elm_genlist_item_prev_get(const Elm_Genlist_Item *it)
3993 {
3994    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3995    while (it)
3996      {
3997         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3998         if ((it) && (!it->delete_me)) break;
3999      }
4000    return (Elm_Genlist_Item *)it;
4001 }
4002
4003 /**
4004  * Get the genlist object from an item
4005  *
4006  * This returns the genlist object itself that an item belongs to.
4007  *
4008  * @param it The item
4009  * @return The genlist object
4010  *
4011  * @ingroup Genlist
4012  */
4013 EAPI Evas_Object *
4014 elm_genlist_item_genlist_get(const Elm_Genlist_Item *it)
4015 {
4016    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4017    return it->base.widget;
4018 }
4019
4020 /**
4021  * Get the parent item of the given item
4022  *
4023  * This returns the parent item of the item @p it given.
4024  *
4025  * @param it The item
4026  * @return The parent of the item or NULL if none
4027  *
4028  * @ingroup Genlist
4029  */
4030 EAPI Elm_Genlist_Item *
4031 elm_genlist_item_parent_get(const Elm_Genlist_Item *it)
4032 {
4033    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4034    return it->parent;
4035 }
4036
4037 /**
4038  * Clear all sub-items (children) of the given item
4039  *
4040  * This clears all items that are children (or their descendants) of the
4041  * given item @p it.
4042  *
4043  * @param it The item
4044  *
4045  * @ingroup Genlist
4046  */
4047 EAPI void
4048 elm_genlist_item_subitems_clear(Elm_Genlist_Item *it)
4049 {
4050    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4051    Eina_List *tl = NULL, *l;
4052    Elm_Genlist_Item *it2;
4053
4054    EINA_LIST_FOREACH(it->items, l, it2)
4055      tl = eina_list_append(tl, it2);
4056    EINA_LIST_FREE(tl, it2)
4057      elm_genlist_item_del(it2);
4058 }
4059
4060 /**
4061  * Set the selected state of an item
4062  *
4063  * This sets the selected state (1 selected, 0 not selected) of the given
4064  * item @p it.
4065  *
4066  * @param it The item
4067  * @param selected The selected state
4068  *
4069  * @ingroup Genlist
4070  */
4071 EAPI void
4072 elm_genlist_item_selected_set(Elm_Genlist_Item *it,
4073                               Eina_Bool         selected)
4074 {
4075    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4076    Widget_Data *wd = elm_widget_data_get(it->base.widget);
4077    if (!wd) return;
4078    if ((it->delete_me) || (it->disabled)) return;
4079    selected = !!selected;
4080    if (it->selected == selected) return;
4081
4082    if (selected)
4083      {
4084         if (!wd->multi)
4085           {
4086              while (wd->selected)
4087                {
4088                   _item_unhighlight(wd->selected->data);
4089                   _item_unselect(wd->selected->data);
4090                }
4091           }
4092         _item_highlight(it);
4093         _item_select(it);
4094      }
4095    else
4096      {
4097         _item_unhighlight(it);
4098         _item_unselect(it);
4099      }
4100 }
4101
4102 /**
4103  * Get the selected state of an item
4104  *
4105  * This gets the selected state of an item (1 selected, 0 not selected).
4106  *
4107  * @param it The item
4108  * @return The selected state
4109  *
4110  * @ingroup Genlist
4111  */
4112 EAPI Eina_Bool
4113 elm_genlist_item_selected_get(const Elm_Genlist_Item *it)
4114 {
4115    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4116    return it->selected;
4117 }
4118
4119 /**
4120  * Sets the expanded state of an item (if it's a parent)
4121  *
4122  * This expands or contracts a parent item (thus showing or hiding the
4123  * children).
4124  *
4125  * @param it The item
4126  * @param expanded The expanded state (1 expanded, 0 not expanded).
4127  *
4128  * @ingroup Genlist
4129  */
4130 EAPI void
4131 elm_genlist_item_expanded_set(Elm_Genlist_Item *it,
4132                               Eina_Bool         expanded)
4133 {
4134    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4135    if (it->expanded == expanded) return;
4136    it->expanded = expanded;
4137    it->wd->expanded_item = it;
4138    if (it->expanded)
4139      {
4140         if (it->realized)
4141           edje_object_signal_emit(it->base.view, "elm,state,expanded", "elm");
4142         evas_object_smart_callback_call(it->base.widget, SIG_EXPANDED, it);
4143         it->wd->auto_scroll_enabled = EINA_TRUE;
4144      }
4145    else
4146      {
4147         if (it->realized)
4148           edje_object_signal_emit(it->base.view, "elm,state,contracted", "elm");
4149         evas_object_smart_callback_call(it->base.widget, SIG_CONTRACTED, it);
4150         it->wd->auto_scroll_enabled = EINA_FALSE;
4151      }
4152 }
4153
4154 /**
4155  * Get the expanded state of an item
4156  *
4157  * This gets the expanded state of an item
4158  *
4159  * @param it The item
4160  * @return Thre expanded state
4161  *
4162  * @ingroup Genlist
4163  */
4164 EAPI Eina_Bool
4165 elm_genlist_item_expanded_get(const Elm_Genlist_Item *it)
4166 {
4167    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4168    return it->expanded;
4169 }
4170
4171 /**
4172  * Get the depth of expanded item
4173  *
4174  * @param it The genlist item object
4175  * @return The depth of expanded item
4176  *
4177  * @ingroup Genlist
4178  */
4179 EAPI int
4180 elm_genlist_item_expanded_depth_get(const Elm_Genlist_Item *it)
4181 {
4182    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, 0);
4183    return it->expanded_depth;
4184 }
4185
4186 /**
4187  * Sets the disabled state of an item.
4188  *
4189  * A disabled item cannot be selected or unselected. It will also
4190  * change appearance to appear disabled. This sets the disabled state
4191  * (1 disabled, 0 not disabled).
4192  *
4193  * @param it The item
4194  * @param disabled The disabled state
4195  *
4196  * @ingroup Genlist
4197  */
4198 EAPI void
4199 elm_genlist_item_disabled_set(Elm_Genlist_Item *it,
4200                               Eina_Bool         disabled)
4201 {
4202    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4203    Eina_List *l;
4204    Evas_Object *obj;
4205    if (it->disabled == disabled) return;
4206    if (it->delete_me) return;
4207    it->disabled = !!disabled;
4208    if (it->selected)
4209      elm_genlist_item_selected_set(it, EINA_FALSE);
4210    if (it->realized)
4211      {
4212         if (it->disabled)
4213           edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
4214         else
4215           edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
4216         EINA_LIST_FOREACH(it->icon_objs, l, obj)
4217           elm_widget_disabled_set(obj, disabled);
4218      }
4219 }
4220
4221 /**
4222  * Get the disabled state of an item
4223  *
4224  * This gets the disabled state of the given item.
4225  *
4226  * @param it The item
4227  * @return The disabled state
4228  *
4229  * @ingroup Genlist
4230  */
4231 EAPI Eina_Bool
4232 elm_genlist_item_disabled_get(const Elm_Genlist_Item *it)
4233 {
4234    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4235    if (it->delete_me) return EINA_FALSE;
4236    return it->disabled;
4237 }
4238
4239 /**
4240  * Sets the display only state of an item.
4241  *
4242  * A display only item cannot be selected or unselected. It is for
4243  * display only and not selecting or otherwise clicking, dragging
4244  * etc. by the user, thus finger size rules will not be applied to
4245  * this item.
4246  *
4247  * @param it The item
4248  * @param display_only The display only state
4249  *
4250  * @ingroup Genlist
4251  */
4252 EAPI void
4253 elm_genlist_item_display_only_set(Elm_Genlist_Item *it,
4254                                   Eina_Bool         display_only)
4255 {
4256    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4257    if (it->display_only == display_only) return;
4258    if (it->delete_me) return;
4259    it->display_only = display_only;
4260    it->mincalcd = EINA_FALSE;
4261    it->updateme = EINA_TRUE;
4262    if (it->block) it->block->updateme = EINA_TRUE;
4263    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4264    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4265 }
4266
4267 /**
4268  * Get the display only state of an item
4269  *
4270  * This gets the display only state of the given item.
4271  *
4272  * @param it The item
4273  * @return The display only state
4274  *
4275  * @ingroup Genlist
4276  */
4277 EAPI Eina_Bool
4278 elm_genlist_item_display_only_get(const Elm_Genlist_Item *it)
4279 {
4280    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4281    if (it->delete_me) return EINA_FALSE;
4282    return it->display_only;
4283 }
4284
4285 /**
4286  * Show the given item
4287  *
4288  * This causes genlist to jump to the given item @p it and show it (by
4289  * scrolling), if it is not fully visible.
4290  *
4291  * @param it The item
4292  *
4293  * @ingroup Genlist
4294  */
4295 EAPI void
4296 elm_genlist_item_show(Elm_Genlist_Item *it)
4297 {
4298    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4299    Evas_Coord gith = 0;
4300    if (it->delete_me) return;
4301    if ((it->queued) || (!it->mincalcd))
4302      {
4303         it->wd->show_item = it;
4304         it->wd->bring_in = EINA_TRUE;
4305         it->showme = EINA_TRUE;
4306         return;
4307      }
4308    if (it->wd->show_item)
4309      {
4310         it->wd->show_item->showme = EINA_FALSE;
4311         it->wd->show_item = NULL;
4312      }
4313    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4314      gith = it->group_item->h;
4315    elm_smart_scroller_child_region_show(it->wd->scr,
4316                                         it->x + it->block->x,
4317                                         it->y + it->block->y - gith,
4318                                         it->block->w, it->h);
4319 }
4320
4321 /**
4322  * Bring in the given item
4323  *
4324  * This causes genlist to jump to the given item @p it and show it (by
4325  * scrolling), if it is not fully visible. This may use animation to
4326  * do so and take a period of time
4327  *
4328  * @param it The item
4329  *
4330  * @ingroup Genlist
4331  */
4332 EAPI void
4333 elm_genlist_item_bring_in(Elm_Genlist_Item *it)
4334 {
4335    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4336    Evas_Coord gith = 0;
4337    if (it->delete_me) return;
4338    if ((it->queued) || (!it->mincalcd))
4339      {
4340         it->wd->show_item = it;
4341         it->wd->bring_in = EINA_TRUE;
4342         it->showme = EINA_TRUE;
4343         return;
4344      }
4345    if (it->wd->show_item)
4346      {
4347         it->wd->show_item->showme = EINA_FALSE;
4348         it->wd->show_item = NULL;
4349      }
4350    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4351      gith = it->group_item->h;
4352    elm_smart_scroller_region_bring_in(it->wd->scr,
4353                                       it->x + it->block->x,
4354                                       it->y + it->block->y - gith,
4355                                       it->block->w, it->h);
4356 }
4357
4358 /**
4359  * Show the given item at the top
4360  *
4361  * This causes genlist to jump to the given item @p it and show it (by
4362  * scrolling), if it is not fully visible.
4363  *
4364  * @param it The item
4365  *
4366  * @ingroup Genlist
4367  */
4368 EAPI void
4369 elm_genlist_item_top_show(Elm_Genlist_Item *it)
4370 {
4371    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4372    Evas_Coord ow, oh;
4373    Evas_Coord gith = 0;
4374
4375    if (it->delete_me) return;
4376    if ((it->queued) || (!it->mincalcd))
4377      {
4378         it->wd->show_item = it;
4379         it->wd->bring_in = EINA_TRUE;
4380         it->showme = EINA_TRUE;
4381         return;
4382      }
4383    if (it->wd->show_item)
4384      {
4385         it->wd->show_item->showme = EINA_FALSE;
4386         it->wd->show_item = NULL;
4387      }
4388    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4389    if (it->group_item) gith = it->group_item->h;
4390    elm_smart_scroller_child_region_show(it->wd->scr,
4391                                         it->x + it->block->x,
4392                                         it->y + it->block->y - gith,
4393                                         it->block->w, oh);
4394 }
4395
4396 /**
4397  * Bring in the given item at the top
4398  *
4399  * This causes genlist to jump to the given item @p it and show it (by
4400  * scrolling), if it is not fully visible. This may use animation to
4401  * do so and take a period of time
4402  *
4403  * @param it The item
4404  *
4405  * @ingroup Genlist
4406  */
4407 EAPI void
4408 elm_genlist_item_top_bring_in(Elm_Genlist_Item *it)
4409 {
4410    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4411    Evas_Coord ow, oh;
4412    Evas_Coord gith = 0;
4413
4414    if (it->delete_me) return;
4415    if ((it->queued) || (!it->mincalcd))
4416      {
4417         it->wd->show_item = it;
4418         it->wd->bring_in = EINA_TRUE;
4419         it->showme = EINA_TRUE;
4420         return;
4421      }
4422    if (it->wd->show_item)
4423      {
4424         it->wd->show_item->showme = EINA_FALSE;
4425         it->wd->show_item = NULL;
4426      }
4427    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4428    if (it->group_item) gith = it->group_item->h;
4429    elm_smart_scroller_region_bring_in(it->wd->scr,
4430                                       it->x + it->block->x,
4431                                       it->y + it->block->y - gith,
4432                                       it->block->w, oh);
4433 }
4434
4435 /**
4436  * Show the given item at the middle
4437  *
4438  * This causes genlist to jump to the given item @p it and show it (by
4439  * scrolling), if it is not fully visible.
4440  *
4441  * @param it The item
4442  *
4443  * @ingroup Genlist
4444  */
4445 EAPI void
4446 elm_genlist_item_middle_show(Elm_Genlist_Item *it)
4447 {
4448    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4449    Evas_Coord ow, oh;
4450
4451    if (it->delete_me) return;
4452    if ((it->queued) || (!it->mincalcd))
4453      {
4454         it->wd->show_item = it;
4455         it->wd->bring_in = EINA_TRUE;
4456         it->showme = EINA_TRUE;
4457         return;
4458      }
4459    if (it->wd->show_item)
4460      {
4461         it->wd->show_item->showme = EINA_FALSE;
4462         it->wd->show_item = NULL;
4463      }
4464    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4465    elm_smart_scroller_child_region_show(it->wd->scr,
4466                                         it->x + it->block->x,
4467                                         it->y + it->block->y - oh / 2 +
4468                                         it->h / 2, it->block->w, oh);
4469 }
4470
4471 /**
4472  * Bring in the given item at the middle
4473  *
4474  * This causes genlist to jump to the given item @p it and show it (by
4475  * scrolling), if it is not fully visible. This may use animation to
4476  * do so and take a period of time
4477  *
4478  * @param it The item
4479  *
4480  * @ingroup Genlist
4481  */
4482 EAPI void
4483 elm_genlist_item_middle_bring_in(Elm_Genlist_Item *it)
4484 {
4485    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4486    Evas_Coord ow, oh;
4487
4488    if (it->delete_me) return;
4489    if ((it->queued) || (!it->mincalcd))
4490      {
4491         it->wd->show_item = it;
4492         it->wd->bring_in = EINA_TRUE;
4493         it->showme = EINA_TRUE;
4494         return;
4495      }
4496    if (it->wd->show_item)
4497      {
4498         it->wd->show_item->showme = EINA_FALSE;
4499         it->wd->show_item = NULL;
4500      }
4501    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4502    elm_smart_scroller_region_bring_in(it->wd->scr,
4503                                       it->x + it->block->x,
4504                                       it->y + it->block->y - oh / 2 + it->h / 2,
4505                                       it->block->w, oh);
4506 }
4507
4508 /**
4509  * Delete a given item
4510  *
4511  * This deletes the item from genlist and calls the genlist item del
4512  * class callback defined in the item class, if it is set. This clears all
4513  * subitems if it is a tree.
4514  *
4515  * @param it The item
4516  *
4517  * @ingroup Genlist
4518  */
4519 EAPI void
4520 elm_genlist_item_del(Elm_Genlist_Item *it)
4521 {
4522    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4523    if ((it->relcount > 0) || (it->walking > 0))
4524      {
4525         elm_widget_item_pre_notify_del(it);
4526         elm_genlist_item_subitems_clear(it);
4527         it->delete_me = EINA_TRUE;
4528         if (it->wd->show_item == it) it->wd->show_item = NULL;
4529         if (it->selected)
4530           it->wd->selected = eina_list_remove(it->wd->selected,
4531                                               it);
4532         if (it->block)
4533           {
4534              if (it->realized) _item_unrealize(it, EINA_FALSE);
4535              it->block->changed = EINA_TRUE;
4536              if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
4537              it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
4538           }
4539         if (it->itc->func.del)
4540           it->itc->func.del((void *)it->base.data, it->base.widget);
4541         return;
4542      }
4543    _item_del(it);
4544 }
4545
4546 /**
4547  * Set the data item from the genlist item
4548  *
4549  * This sets the data value passed on the elm_genlist_item_append() and
4550  * related item addition calls. This function will not call
4551  * elm_genlist_item_update() anymore. So call elm_genlist_item_update()
4552  * manually only when it's needed.
4553  *
4554  * @param it The item
4555  * @param data The new data pointer to set
4556  *
4557  * @ingroup Genlist
4558  */
4559 EAPI void
4560 elm_genlist_item_data_set(Elm_Genlist_Item *it,
4561                           const void       *data)
4562 {
4563    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4564    elm_widget_item_data_set(it, data);
4565 }
4566
4567 /**
4568  * Get the data item from the genlist item
4569  *
4570  * This returns the data value passed on the elm_genlist_item_append()
4571  * and related item addition calls and elm_genlist_item_data_set().
4572  *
4573  * @param it The item
4574  * @return The data pointer provided when created
4575  *
4576  * @ingroup Genlist
4577  */
4578 EAPI void *
4579 elm_genlist_item_data_get(const Elm_Genlist_Item *it)
4580 {
4581    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4582    return elm_widget_item_data_get(it);
4583 }
4584
4585 /**
4586  * Tells genlist to "orphan" icons fetchs by the item class
4587  *
4588  * This instructs genlist to release references to icons in the item,
4589  * meaning that they will no longer be managed by genlist and are
4590  * floating "orphans" that can be re-used elsewhere if the user wants
4591  * to.
4592  *
4593  * @param it The item
4594  *
4595  * @ingroup Genlist
4596  */
4597 EAPI void
4598 elm_genlist_item_icons_orphan(Elm_Genlist_Item *it)
4599 {
4600    Evas_Object *icon;
4601    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4602    EINA_LIST_FREE(it->icon_objs, icon)
4603      {
4604         elm_widget_sub_object_del(it->base.widget, icon);
4605         evas_object_smart_member_del(icon);
4606         evas_object_hide(icon);
4607      }
4608 }
4609
4610 /**
4611  * Get the real evas object of the genlist item
4612  *
4613  * This returns the actual evas object used for the specified genlist
4614  * item. This may be NULL as it may not be created, and may be deleted
4615  * at any time by genlist. Do not modify this object (move, resize,
4616  * show, hide etc.) as genlist is controlling it. This function is for
4617  * querying, emitting custom signals or hooking lower level callbacks
4618  * for events. Do not delete this object under any circumstances.
4619  *
4620  * @param it The item
4621  * @return The object pointer
4622  *
4623  * @ingroup Genlist
4624  */
4625 EAPI const Evas_Object *
4626 elm_genlist_item_object_get(const Elm_Genlist_Item *it)
4627 {
4628    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4629    return it->base.view;
4630 }
4631
4632 /**
4633  * Update the contents of an item
4634  *
4635  * This updates an item by calling all the item class functions again
4636  * to get the icons, labels and states. Use this when the original
4637  * item data has changed and the changes are desired to be reflected.
4638  *
4639  * @param it The item
4640  *
4641  * @ingroup Genlist
4642  */
4643 EAPI void
4644 elm_genlist_item_update(Elm_Genlist_Item *it)
4645 {
4646    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4647    if (!it->block) return;
4648    if (it->delete_me) return;
4649    it->mincalcd = EINA_FALSE;
4650    it->updateme = EINA_TRUE;
4651    it->block->updateme = EINA_TRUE;
4652    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4653    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4654 }
4655
4656 /**
4657  * Update the item class of an item
4658  *
4659  * @param it The item
4660  * @parem itc The item class for the item
4661  *
4662  * @ingroup Genlist
4663  */
4664 EAPI void
4665 elm_genlist_item_item_class_update(Elm_Genlist_Item             *it,
4666                                    const Elm_Genlist_Item_Class *itc)
4667 {
4668    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4669    if (!it->block) return;
4670    EINA_SAFETY_ON_NULL_RETURN(itc);
4671    if (it->delete_me) return;
4672    it->itc = itc;
4673    it->nocache = EINA_TRUE;
4674    elm_genlist_item_update(it);
4675 }
4676
4677 EAPI const Elm_Genlist_Item_Class *
4678 elm_genlist_item_item_class_get(const Elm_Genlist_Item *it)
4679 {
4680    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4681    if (it->delete_me) return NULL;
4682    return it->itc;
4683 }
4684
4685 static Evas_Object *
4686 _elm_genlist_item_label_create(void        *data,
4687                                Evas_Object *obj __UNUSED__,
4688                                Evas_Object *tooltip,
4689                                void        *item __UNUSED__)
4690 {
4691    Evas_Object *label = elm_label_add(tooltip);
4692    if (!label)
4693      return NULL;
4694    elm_object_style_set(label, "tooltip");
4695    elm_object_text_set(label, data);
4696    return label;
4697 }
4698
4699 static void
4700 _elm_genlist_item_label_del_cb(void        *data,
4701                                Evas_Object *obj __UNUSED__,
4702                                void        *event_info __UNUSED__)
4703 {
4704    eina_stringshare_del(data);
4705 }
4706
4707 /**
4708  * Set the text to be shown in the genlist item.
4709  *
4710  * @param item Target item
4711  * @param text The text to set in the content
4712  *
4713  * Setup the text as tooltip to object. The item can have only one
4714  * tooltip, so any previous tooltip data is removed.
4715  *
4716  * @ingroup Genlist
4717  */
4718 EAPI void
4719 elm_genlist_item_tooltip_text_set(Elm_Genlist_Item *item,
4720                                   const char       *text)
4721 {
4722    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4723    text = eina_stringshare_add(text);
4724    elm_genlist_item_tooltip_content_cb_set(item, _elm_genlist_item_label_create,
4725                                            text,
4726                                            _elm_genlist_item_label_del_cb);
4727 }
4728
4729 /**
4730  * Set the content to be shown in the tooltip item
4731  *
4732  * Setup the tooltip to item. The item can have only one tooltip, so
4733  * any previous tooltip data is removed. @p func(with @p data) will be
4734  * called every time that need to show the tooltip and it should return a
4735  * valid Evas_Object. This object is then managed fully by tooltip
4736  * system and is deleted when the tooltip is gone.
4737  *
4738  * @param item the genlist item being attached by a tooltip.
4739  * @param func the function used to create the tooltip contents.
4740  * @param data what to provide to @a func as callback data/context.
4741  * @param del_cb called when data is not needed anymore, either when
4742  *        another callback replaces @func, the tooltip is unset with
4743  *        elm_genlist_item_tooltip_unset() or the owner @a item
4744  *        dies. This callback receives as the first parameter the
4745  *        given @a data, and @c event_info is the item.
4746  *
4747  * @ingroup Genlist
4748  */
4749 EAPI void
4750 elm_genlist_item_tooltip_content_cb_set(Elm_Genlist_Item           *item,
4751                                         Elm_Tooltip_Item_Content_Cb func,
4752                                         const void                 *data,
4753                                         Evas_Smart_Cb               del_cb)
4754 {
4755    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
4756
4757    if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
4758      return;
4759
4760    if (item->tooltip.del_cb)
4761      item->tooltip.del_cb((void *)item->tooltip.data,
4762                           item->base.widget, item);
4763
4764    item->tooltip.content_cb = func;
4765    item->tooltip.data = data;
4766    item->tooltip.del_cb = del_cb;
4767
4768    if (item->base.view)
4769      {
4770         elm_widget_item_tooltip_content_cb_set(item,
4771                                                item->tooltip.content_cb,
4772                                                item->tooltip.data, NULL);
4773         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
4774         elm_widget_item_tooltip_size_restrict_disable(item, item->tooltip.free_size);
4775      }
4776
4777    return;
4778
4779 error:
4780    if (del_cb) del_cb((void *)data, NULL, NULL);
4781 }
4782
4783 /**
4784  * Unset tooltip from item
4785  *
4786  * @param item genlist item to remove previously set tooltip.
4787  *
4788  * Remove tooltip from item. The callback provided as del_cb to
4789  * elm_genlist_item_tooltip_content_cb_set() will be called to notify
4790  * it is not used anymore.
4791  *
4792  * @see elm_genlist_item_tooltip_content_cb_set()
4793  *
4794  * @ingroup Genlist
4795  */
4796 EAPI void
4797 elm_genlist_item_tooltip_unset(Elm_Genlist_Item *item)
4798 {
4799    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4800    if ((item->base.view) && (item->tooltip.content_cb))
4801      elm_widget_item_tooltip_unset(item);
4802
4803    if (item->tooltip.del_cb)
4804      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
4805    item->tooltip.del_cb = NULL;
4806    item->tooltip.content_cb = NULL;
4807    item->tooltip.data = NULL;
4808    item->tooltip.free_size = EINA_FALSE;
4809    if (item->tooltip.style)
4810      elm_genlist_item_tooltip_style_set(item, NULL);
4811 }
4812
4813 /**
4814  * Sets a different style for this item tooltip.
4815  *
4816  * @note before you set a style you should define a tooltip with
4817  *       elm_genlist_item_tooltip_content_cb_set() or
4818  *       elm_genlist_item_tooltip_text_set()
4819  *
4820  * @param item genlist item with tooltip already set.
4821  * @param style the theme style to use (default, transparent, ...)
4822  *
4823  * @ingroup Genlist
4824  */
4825 EAPI void
4826 elm_genlist_item_tooltip_style_set(Elm_Genlist_Item *item,
4827                                    const char       *style)
4828 {
4829    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4830    eina_stringshare_replace(&item->tooltip.style, style);
4831    if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
4832 }
4833
4834 /**
4835  * Get the style for this item tooltip.
4836  *
4837  * @param item genlist item with tooltip already set.
4838  * @return style the theme style in use, defaults to "default". If the
4839  *         object does not have a tooltip set, then NULL is returned.
4840  *
4841  * @ingroup Genlist
4842  */
4843 EAPI const char *
4844 elm_genlist_item_tooltip_style_get(const Elm_Genlist_Item *item)
4845 {
4846    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4847    return item->tooltip.style;
4848 }
4849
4850 EAPI Eina_Bool
4851 elm_genlist_item_tooltip_size_restrict_disable(Elm_Genlist_Item *item, Eina_Bool disable)
4852 {
4853    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
4854    item->tooltip.free_size = disable;
4855    if (item->base.view) return elm_widget_item_tooltip_size_restrict_disable(item, disable);
4856    return EINA_TRUE;
4857 }
4858
4859 EAPI Eina_Bool
4860 elm_genlist_item_tooltip_size_restrict_disabled_get(const Elm_Genlist_Item *item)
4861 {
4862    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
4863    return item->tooltip.free_size;
4864 }
4865
4866 /**
4867  * Set the cursor to be shown when mouse is over the genlist item
4868  *
4869  * @param item Target item
4870  * @param cursor the cursor name to be used.
4871  *
4872  * @see elm_object_cursor_set()
4873  * @ingroup Genlist
4874  */
4875 EAPI void
4876 elm_genlist_item_cursor_set(Elm_Genlist_Item *item,
4877                             const char       *cursor)
4878 {
4879    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4880    eina_stringshare_replace(&item->mouse_cursor, cursor);
4881    if (item->base.view) elm_widget_item_cursor_set(item, cursor);
4882 }
4883
4884 /**
4885  * Get the cursor to be shown when mouse is over the genlist item
4886  *
4887  * @param item genlist item with cursor already set.
4888  * @return the cursor name.
4889  *
4890  * @ingroup Genlist
4891  */
4892 EAPI const char *
4893 elm_genlist_item_cursor_get(const Elm_Genlist_Item *item)
4894 {
4895    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4896    return elm_widget_item_cursor_get(item);
4897 }
4898
4899 /**
4900  * Unset the cursor to be shown when mouse is over the genlist item
4901  *
4902  * @param item Target item
4903  *
4904  * @see elm_object_cursor_unset()
4905  * @ingroup Genlist
4906  */
4907 EAPI void
4908 elm_genlist_item_cursor_unset(Elm_Genlist_Item *item)
4909 {
4910    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4911    if (!item->mouse_cursor)
4912      return;
4913
4914    if (item->base.view)
4915      elm_widget_item_cursor_unset(item);
4916
4917    eina_stringshare_del(item->mouse_cursor);
4918    item->mouse_cursor = NULL;
4919 }
4920
4921 /**
4922  * Sets a different style for this item cursor.
4923  *
4924  * @note before you set a style you should define a cursor with
4925  *       elm_genlist_item_cursor_set()
4926  *
4927  * @param item genlist item with cursor already set.
4928  * @param style the theme style to use (default, transparent, ...)
4929  *
4930  * @ingroup Genlist
4931  */
4932 EAPI void
4933 elm_genlist_item_cursor_style_set(Elm_Genlist_Item *item,
4934                                   const char       *style)
4935 {
4936    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4937    elm_widget_item_cursor_style_set(item, style);
4938 }
4939
4940 /**
4941  * Get the style for this item cursor.
4942  *
4943  * @param item genlist item with cursor already set.
4944  * @return style the theme style in use, defaults to "default". If the
4945  *         object does not have a cursor set, then NULL is returned.
4946  *
4947  * @ingroup Genlist
4948  */
4949 EAPI const char *
4950 elm_genlist_item_cursor_style_get(const Elm_Genlist_Item *item)
4951 {
4952    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4953    return elm_widget_item_cursor_style_get(item);
4954 }
4955
4956 /**
4957  * Set if the cursor set should be searched on the theme or should use
4958  * the provided by the engine, only.
4959  *
4960  * @note before you set if should look on theme you should define a
4961  * cursor with elm_object_cursor_set(). By default it will only look
4962  * for cursors provided by the engine.
4963  *
4964  * @param item widget item with cursor already set.
4965  * @param engine_only boolean to define it cursors should be looked
4966  * only between the provided by the engine or searched on widget's
4967  * theme as well.
4968  *
4969  * @ingroup Genlist
4970  */
4971 EAPI void
4972 elm_genlist_item_cursor_engine_only_set(Elm_Genlist_Item *item,
4973                                         Eina_Bool         engine_only)
4974 {
4975    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4976    elm_widget_item_cursor_engine_only_set(item, engine_only);
4977 }
4978
4979 /**
4980  * Get the cursor engine only usage for this item cursor.
4981  *
4982  * @param item widget item with cursor already set.
4983  * @return engine_only boolean to define it cursors should be looked
4984  * only between the provided by the engine or searched on widget's
4985  * theme as well. If the object does not have a cursor set, then
4986  * EINA_FALSE is returned.
4987  *
4988  * @ingroup Genlist
4989  */
4990 EAPI Eina_Bool
4991 elm_genlist_item_cursor_engine_only_get(const Elm_Genlist_Item *item)
4992 {
4993    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
4994    return elm_widget_item_cursor_engine_only_get(item);
4995 }
4996
4997 EAPI void
4998 elm_genlist_horizontal_mode_set(Evas_Object  *obj,
4999                                 Elm_List_Mode mode)
5000 {
5001    ELM_CHECK_WIDTYPE(obj, widtype);
5002    Widget_Data *wd = elm_widget_data_get(obj);
5003    if (!wd) return;
5004    if (wd->mode == mode) return;
5005    wd->mode = mode;
5006    _sizing_eval(obj);
5007 }
5008
5009 EAPI Elm_List_Mode
5010 elm_genlist_horizontal_mode_get(const Evas_Object *obj)
5011 {
5012    ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
5013    Widget_Data *wd = elm_widget_data_get(obj);
5014    if (!wd) return ELM_LIST_LAST;
5015    return wd->mode;
5016 }
5017
5018 EAPI void
5019 elm_genlist_always_select_mode_set(Evas_Object *obj,
5020                                    Eina_Bool    always_select)
5021 {
5022    ELM_CHECK_WIDTYPE(obj, widtype);
5023    Widget_Data *wd = elm_widget_data_get(obj);
5024    if (!wd) return;
5025    wd->always_select = always_select;
5026 }
5027
5028 EAPI Eina_Bool
5029 elm_genlist_always_select_mode_get(const Evas_Object *obj)
5030 {
5031    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5032    Widget_Data *wd = elm_widget_data_get(obj);
5033    if (!wd) return EINA_FALSE;
5034    return wd->always_select;
5035 }
5036
5037 EAPI void
5038 elm_genlist_no_select_mode_set(Evas_Object *obj,
5039                                Eina_Bool    no_select)
5040 {
5041    ELM_CHECK_WIDTYPE(obj, widtype);
5042    Widget_Data *wd = elm_widget_data_get(obj);
5043    if (!wd) return;
5044    wd->no_select = no_select;
5045 }
5046
5047 EAPI Eina_Bool
5048 elm_genlist_no_select_mode_get(const Evas_Object *obj)
5049 {
5050    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5051    Widget_Data *wd = elm_widget_data_get(obj);
5052    if (!wd) return EINA_FALSE;
5053    return wd->no_select;
5054 }
5055
5056 EAPI void
5057 elm_genlist_compress_mode_set(Evas_Object *obj,
5058                               Eina_Bool    compress)
5059 {
5060    ELM_CHECK_WIDTYPE(obj, widtype);
5061    Widget_Data *wd = elm_widget_data_get(obj);
5062    if (!wd) return;
5063    wd->compress = compress;
5064    if (!compress) elm_genlist_homogeneous_set(obj, EINA_FALSE);
5065 }
5066
5067 EAPI Eina_Bool
5068 elm_genlist_compress_mode_get(const Evas_Object *obj)
5069 {
5070    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5071    Widget_Data *wd = elm_widget_data_get(obj);
5072    if (!wd) return EINA_FALSE;
5073    return wd->compress;
5074 }
5075
5076 EAPI void
5077 elm_genlist_height_for_width_mode_set(Evas_Object *obj,
5078                                       Eina_Bool    height_for_width)
5079 {
5080    ELM_CHECK_WIDTYPE(obj, widtype);
5081    Widget_Data *wd = elm_widget_data_get(obj);
5082    if (!wd) return;
5083    wd->height_for_width = !!height_for_width;
5084    if (wd->height_for_width)
5085      {
5086         elm_genlist_homogeneous_set(obj, EINA_FALSE);
5087         elm_genlist_compress_mode_set(obj, EINA_TRUE);
5088      }
5089 }
5090
5091 EAPI Eina_Bool
5092 elm_genlist_height_for_width_mode_get(const Evas_Object *obj)
5093 {
5094    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5095    Widget_Data *wd = elm_widget_data_get(obj);
5096    if (!wd) return EINA_FALSE;
5097    return wd->height_for_width;
5098 }
5099
5100 EAPI void
5101 elm_genlist_bounce_set(Evas_Object *obj,
5102                        Eina_Bool    h_bounce,
5103                        Eina_Bool    v_bounce)
5104 {
5105    ELM_CHECK_WIDTYPE(obj, widtype);
5106    Widget_Data *wd = elm_widget_data_get(obj);
5107    if (!wd) return;
5108    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
5109 }
5110
5111 EAPI void
5112 elm_genlist_bounce_get(const Evas_Object *obj,
5113                        Eina_Bool         *h_bounce,
5114                        Eina_Bool         *v_bounce)
5115 {
5116    ELM_CHECK_WIDTYPE(obj, widtype);
5117    Widget_Data *wd = elm_widget_data_get(obj);
5118    if (!wd) return;
5119    elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
5120 }
5121
5122 EAPI void
5123 elm_genlist_homogeneous_set(Evas_Object *obj,
5124                             Eina_Bool    homogeneous)
5125 {
5126    ELM_CHECK_WIDTYPE(obj, widtype);
5127    Widget_Data *wd = elm_widget_data_get(obj);
5128    if (!wd) return;
5129    if (homogeneous) elm_genlist_compress_mode_set(obj, EINA_TRUE);
5130    wd->homogeneous = homogeneous;
5131 }
5132
5133 EAPI Eina_Bool
5134 elm_genlist_homogeneous_get(const Evas_Object *obj)
5135 {
5136    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5137    Widget_Data *wd = elm_widget_data_get(obj);
5138    if (!wd) return EINA_FALSE;
5139    return wd->homogeneous;
5140 }
5141
5142 EAPI void
5143 elm_genlist_block_count_set(Evas_Object *obj,
5144                             int          n)
5145 {
5146    ELM_CHECK_WIDTYPE(obj, widtype);
5147    Widget_Data *wd = elm_widget_data_get(obj);
5148    if (!wd) return;
5149    wd->max_items_per_block = n;
5150    wd->item_cache_max = wd->max_items_per_block * 2;
5151    _item_cache_clean(wd);
5152 }
5153
5154 EAPI int
5155 elm_genlist_block_count_get(const Evas_Object *obj)
5156 {
5157    ELM_CHECK_WIDTYPE(obj, widtype) 0;
5158    Widget_Data *wd = elm_widget_data_get(obj);
5159    if (!wd) return 0;
5160    return wd->max_items_per_block;
5161 }
5162
5163 EAPI void
5164 elm_genlist_longpress_timeout_set(Evas_Object *obj,
5165                                   double       timeout)
5166 {
5167    ELM_CHECK_WIDTYPE(obj, widtype);
5168    Widget_Data *wd = elm_widget_data_get(obj);
5169    if (!wd) return;
5170    wd->longpress_timeout = timeout;
5171 }
5172
5173 EAPI double
5174 elm_genlist_longpress_timeout_get(const Evas_Object *obj)
5175 {
5176    ELM_CHECK_WIDTYPE(obj, widtype) 0;
5177    Widget_Data *wd = elm_widget_data_get(obj);
5178    if (!wd) return 0;
5179    return wd->longpress_timeout;
5180 }
5181
5182 EAPI void
5183 elm_genlist_scroller_policy_set(Evas_Object        *obj,
5184                                 Elm_Scroller_Policy policy_h,
5185                                 Elm_Scroller_Policy policy_v)
5186 {
5187    ELM_CHECK_WIDTYPE(obj, widtype);
5188    Widget_Data *wd = elm_widget_data_get(obj);
5189    if (!wd) return;
5190    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
5191        (policy_v >= ELM_SCROLLER_POLICY_LAST))
5192      return;
5193    if (wd->scr)
5194      elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
5195 }
5196
5197 EAPI void
5198 elm_genlist_scroller_policy_get(const Evas_Object   *obj,
5199                                 Elm_Scroller_Policy *policy_h,
5200                                 Elm_Scroller_Policy *policy_v)
5201 {
5202    ELM_CHECK_WIDTYPE(obj, widtype);
5203    Widget_Data *wd = elm_widget_data_get(obj);
5204    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
5205    if ((!wd) || (!wd->scr)) return;
5206    elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
5207    if (policy_h) *policy_h = (Elm_Scroller_Policy)s_policy_h;
5208    if (policy_v) *policy_v = (Elm_Scroller_Policy)s_policy_v;
5209 }
5210
5211 EAPI void
5212 elm_genlist_realized_items_update(Evas_Object *obj)
5213 {
5214    ELM_CHECK_WIDTYPE(obj, widtype);
5215
5216    Eina_List *list, *l;
5217    Elm_Genlist_Item *it;
5218
5219    list = elm_genlist_realized_items_get(obj);
5220    EINA_LIST_FOREACH(list, l, it)
5221      elm_genlist_item_update(it);
5222 }
5223
5224 /**
5225  * Set genlist item mode
5226  *
5227  * @param item The genlist item
5228  * @param mode Mode name
5229  * @param mode_set Boolean to define set or unset mode.
5230  *
5231  * @ingroup Genlist
5232  */
5233 EAPI void
5234 elm_genlist_item_mode_set(Elm_Genlist_Item *it,
5235                           const char       *mode_type,
5236                           Eina_Bool         mode_set)
5237 {
5238    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
5239    Widget_Data *wd = it->wd;
5240    Eina_List *l;
5241    Elm_Genlist_Item *it2;
5242
5243    if (!wd) return;
5244    if (!mode_type) return;
5245    if ((it->delete_me) || (it->disabled)) return;
5246
5247    if ((wd->mode_item == it) &&
5248        (!strcmp(mode_type, wd->mode_type)) &&
5249        (mode_set))
5250       return;
5251    if (!it->itc->mode_item_style) return;
5252
5253    if (wd->multi)
5254      {
5255         EINA_LIST_FOREACH(wd->selected, l, it2)
5256           if (it2->realized)
5257             elm_genlist_item_selected_set(it2, EINA_FALSE);
5258      }
5259    else
5260      {
5261         it2 = elm_genlist_selected_item_get(wd->obj);
5262         if ((it2) && (it2->realized))
5263           elm_genlist_item_selected_set(it2, EINA_FALSE);
5264      }
5265
5266    if (((wd->mode_type) && (strcmp(mode_type, wd->mode_type))) ||
5267        (mode_set) ||
5268        ((it == wd->mode_item) && (!mode_set)))
5269      _item_mode_unset(wd);
5270
5271    eina_stringshare_replace(&wd->mode_type, mode_type);
5272    if (mode_set) _item_mode_set(it);
5273 }
5274
5275 /**
5276  * Get active genlist mode type
5277  *
5278  * @param obj The genlist object
5279  *
5280  * @ingroup Genlist
5281  */
5282 EAPI const char *
5283 elm_genlist_mode_get(const Evas_Object *obj)
5284 {
5285    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5286    Widget_Data *wd = elm_widget_data_get(obj);
5287    if (!wd) return NULL;
5288    return wd->mode_type;
5289 }
5290
5291 /**
5292  * Get active genlist mode item
5293  *
5294  * @param obj The genlist object
5295  *
5296  * @ingroup Genlist
5297  */
5298 EAPI const Elm_Genlist_Item *
5299 elm_genlist_mode_item_get(const Evas_Object *obj)
5300 {
5301    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5302    Widget_Data *wd = elm_widget_data_get(obj);
5303    if (!wd) return NULL;
5304    return wd->mode_item;
5305 }
5306
5307 /**
5308  * Set reorder mode
5309  *
5310  * @param obj The genlist object
5311  * @param reorder_mode The reorder mode
5312  * (EINA_TRUE = on, EINA_FALSE = off)
5313  *
5314  * @ingroup Genlist
5315  */
5316 EAPI void
5317 elm_genlist_reorder_mode_set(Evas_Object *obj,
5318                              Eina_Bool    reorder_mode)
5319 {
5320    ELM_CHECK_WIDTYPE(obj, widtype);
5321    Widget_Data *wd = elm_widget_data_get(obj);
5322    if (!wd) return;
5323    wd->reorder_mode = reorder_mode;
5324 }
5325
5326 /**
5327  * Get the reorder mode
5328  *
5329  * @param obj The genlist object
5330  * @return The reorder mode
5331  * (EINA_TRUE = on, EINA_FALSE = off)
5332  *
5333  * @ingroup Genlist
5334  */
5335 EAPI Eina_Bool
5336 elm_genlist_reorder_mode_get(const Evas_Object *obj)
5337 {
5338    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5339    Widget_Data *wd = elm_widget_data_get(obj);
5340    if (!wd) return EINA_FALSE;
5341    return wd->reorder_mode;
5342 }