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