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