Merge "[entry_cnp]CQ:H0100128428 copy text's item tag remove when entry textonly...
[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    Eina_Bool         pan_changed : 1;
84    int               edit_mode;
85    Ecore_Animator   *item_moving_effect_timer;
86    Evas_Object      *alpha_bg;
87    Evas_Coord        expand_item_end;
88    Evas_Coord        expand_item_gap;
89    int               move_effect_mode;
90    Ecore_Job        *changed_job;
91    Elm_Genlist_Item *rename_it;
92 };
93
94 struct _Item_Block
95 {
96    EINA_INLIST;
97    int          count;
98    int          num;
99    int          reorder_offset;
100    Widget_Data *wd;
101    Eina_List   *items;
102    Evas_Coord   x, y, w, h, minw, minh;
103    Eina_Bool    want_unrealize : 1;
104    Eina_Bool    realized : 1;
105    Eina_Bool    changed : 1;
106    Eina_Bool    updateme : 1;
107    Eina_Bool    changeme : 1;
108    Eina_Bool    showme : 1;
109    Eina_Bool    must_recalc : 1;
110 };
111
112 struct _Elm_Genlist_Item
113 {
114    Elm_Widget_Item               base;
115    EINA_INLIST;
116    Widget_Data                  *wd;
117    Item_Block                   *block;
118    Eina_List                    *items;
119    Evas_Coord                    x, y, w, h, minw, minh;
120    const Elm_Genlist_Item_Class *itc;
121    Elm_Genlist_Item             *parent;
122    Elm_Genlist_Item             *group_item;
123    Elm_Genlist_Item_Flags        flags;
124    struct
125    {
126       Evas_Smart_Cb func;
127       const void   *data;
128    } func;
129
130    Evas_Object                  *spacer;
131    Eina_List                    *labels, *icons, *states, *icon_objs;
132    Eina_List                    *mode_labels, *mode_icons, *mode_states, *mode_icon_objs;
133    Ecore_Timer                  *long_timer;
134    Ecore_Timer                  *swipe_timer;
135    Evas_Coord                    dx, dy;
136    Evas_Coord                    scrl_x, scrl_y;
137
138    Elm_Genlist_Item             *rel;
139    Evas_Object                  *mode_view;
140
141    struct
142    {
143       const void                 *data;
144       Elm_Tooltip_Item_Content_Cb content_cb;
145       Evas_Smart_Cb               del_cb;
146       const char                 *style;
147    } tooltip;
148
149    const char                   *mouse_cursor;
150
151    int                           relcount;
152    int                           walking;
153    int                           expanded_depth;
154    int                           order_num_in;
155
156    Eina_Bool                     before : 1;
157
158    Eina_Bool                     want_unrealize : 1;
159    Eina_Bool                     want_realize : 1;
160    Eina_Bool                     realized : 1;
161    Eina_Bool                     selected : 1;
162    Eina_Bool                     highlighted : 1;
163    Eina_Bool                     expanded : 1;
164    Eina_Bool                     disabled : 1;
165    Eina_Bool                     display_only : 1;
166    Eina_Bool                     mincalcd : 1;
167    Eina_Bool                     queued : 1;
168    Eina_Bool                     showme : 1;
169    Eina_Bool                     delete_me : 1;
170    Eina_Bool                     down : 1;
171    Eina_Bool                     dragging : 1;
172    Eina_Bool                     updateme : 1;
173    Eina_Bool                     nocache : 1;
174    Eina_Bool                     move_effect_enabled : 1;
175    Eina_Bool                     defer_unrealize : 1;
176
177    // TODO: refactoring
178    Eina_Bool   effect_done : 1;
179    Eina_Bool   reordering : 1;
180    Eina_Bool   renamed : 1;
181    Eina_Bool   effect_item_realized : 1;
182    Eina_List  *edit_icon_objs;
183    Evas_Object *edit_obj;
184    int         num;
185    Ecore_Animator *item_moving_effect_timer;
186    Evas_Coord  old_scrl_y;
187 };
188
189 struct _Item_Cache
190 {
191    EINA_INLIST;
192
193    Evas_Object *base_view, *spacer;
194
195    const char  *item_style; // it->itc->item_style
196    Eina_Bool    tree : 1; // it->flags & ELM_GENLIST_ITEM_SUBITEMS
197    Eina_Bool    compress : 1; // it->wd->compress
198    Eina_Bool    odd : 1; // in & 0x1
199
200    Eina_Bool    selected : 1; // it->selected
201    Eina_Bool    disabled : 1; // it->disabled
202    Eina_Bool    expanded : 1; // it->expanded
203 };
204
205 #define ELM_GENLIST_ITEM_FROM_INLIST(item) \
206   ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Genlist_Item) : NULL)
207
208 struct _Pan
209 {
210    Evas_Object_Smart_Clipped_Data __clipped_data;
211    Widget_Data                   *wd;
212    Ecore_Job                     *resize_job;
213 };
214
215 static const char *widtype = NULL;
216 static void      _item_cache_zero(Widget_Data *wd);
217 static void      _del_hook(Evas_Object *obj);
218 static void      _mirrored_set(Evas_Object *obj,
219                                Eina_Bool    rtl);
220 static void      _theme_hook(Evas_Object *obj);
221 static void      _show_region_hook(void        *data,
222                                    Evas_Object *obj);
223 static void      _sizing_eval(Evas_Object *obj);
224 static void      _item_realize(Elm_Genlist_Item *it,
225                                int               in,
226                                Eina_Bool         calc);
227 static void      _item_unrealize(Elm_Genlist_Item *it,
228                                  Eina_Bool         calc);
229 static void      _item_block_unrealize(Item_Block *itb);
230 static void      _calc_job(void *data);
231 static void      _on_focus_hook(void        *data,
232                                 Evas_Object *obj);
233 static void      _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
234 static void      _changed_job(void *data);
235 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
236 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
237 static Eina_Bool _item_single_select_up(Widget_Data *wd);
238 static Eina_Bool _item_single_select_down(Widget_Data *wd);
239 static Eina_Bool _event_hook(Evas_Object       *obj,
240                              Evas_Object       *src,
241                              Evas_Callback_Type type,
242                              void              *event_info);
243 static void      _signal_emit_hook(Evas_Object *obj,
244                                    const char *emission,
245                                    const char *source);
246 static Eina_Bool _deselect_all_items(Widget_Data *wd);
247 static void      _pan_calculate(Evas_Object *obj);
248 static void      _pan_max_get(Evas_Object *obj,
249                               Evas_Coord  *x,
250                               Evas_Coord  *y);
251 static void      _item_position(Elm_Genlist_Item *it,
252                                 Evas_Object      *obj,
253                                 Evas_Coord        it_x,
254                                 Evas_Coord        it_y);
255 static void      _mode_item_realize(Elm_Genlist_Item *it);
256 static void      _mode_item_unrealize(Elm_Genlist_Item *it);
257 static void      _item_mode_set(Elm_Genlist_Item *it);
258 static void      _item_mode_unset(Widget_Data *wd);
259 static void      _group_items_recalc(void *data);
260 static void      _item_move_after(Elm_Genlist_Item *it,
261                                   Elm_Genlist_Item *after);
262 static void      _item_move_before(Elm_Genlist_Item *it,
263                                    Elm_Genlist_Item *before);
264
265 // TODO : refactoring
266 static Evas_Object* _create_tray_alpha_bg(const Evas_Object *obj);
267 static unsigned int current_time_get();
268 static Eina_Bool _item_moving_effect_timer_cb(void *data);
269 static int _item_flip_effect_show(Elm_Genlist_Item *it);
270 static void _effect_item_controls(Elm_Genlist_Item *it, int itx, int ity);
271 static void _effect_item_realize(Elm_Genlist_Item *it, Eina_Bool effect_on);
272 static void _effect_item_unrealize(Elm_Genlist_Item *it);
273 static void _item_auto_scroll(void *data);
274
275 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
276
277 static const char SIG_ACTIVATED[] = "activated";
278 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
279 static const char SIG_SELECTED[] = "selected";
280 static const char SIG_UNSELECTED[] = "unselected";
281 static const char SIG_EXPANDED[] = "expanded";
282 static const char SIG_CONTRACTED[] = "contracted";
283 static const char SIG_EXPAND_REQUEST[] = "expand,request";
284 static const char SIG_CONTRACT_REQUEST[] = "contract,request";
285 static const char SIG_REALIZED[] = "realized";
286 static const char SIG_UNREALIZED[] = "unrealized";
287 static const char SIG_DRAG_START_UP[] = "drag,start,up";
288 static const char SIG_DRAG_START_DOWN[] = "drag,start,down";
289 static const char SIG_DRAG_START_LEFT[] = "drag,start,left";
290 static const char SIG_DRAG_START_RIGHT[] = "drag,start,right";
291 static const char SIG_DRAG_STOP[] = "drag,stop";
292 static const char SIG_DRAG[] = "drag";
293 static const char SIG_LONGPRESSED[] = "longpressed";
294 static const char SIG_SCROLL_EDGE_TOP[] = "scroll,edge,top";
295 static const char SIG_SCROLL_EDGE_BOTTOM[] = "scroll,edge,bottom";
296 static const char SIG_SCROLL_EDGE_LEFT[] = "scroll,edge,left";
297 static const char SIG_SCROLL_EDGE_RIGHT[] = "scroll,edge,right";
298 static const char SIG_MULTI_SWIPE_LEFT[] = "multi,swipe,left";
299 static const char SIG_MULTI_SWIPE_RIGHT[] = "multi,swipe,right";
300 static const char SIG_MULTI_SWIPE_UP[] = "multi,swipe,up";
301 static const char SIG_MULTI_SWIPE_DOWN[] = "multi,swipe,down";
302 static const char SIG_MULTI_PINCH_OUT[] = "multi,pinch,out";
303 static const char SIG_MULTI_PINCH_IN[] = "multi,pinch,in";
304 static const char SIG_SWIPE[] = "swipe";
305
306 static const Evas_Smart_Cb_Description _signals[] = {
307    {SIG_CLICKED_DOUBLE, ""},
308    {SIG_ACTIVATED, ""},
309    {SIG_SELECTED, ""},
310    {SIG_UNSELECTED, ""},
311    {SIG_EXPANDED, ""},
312    {SIG_CONTRACTED, ""},
313    {SIG_EXPAND_REQUEST, ""},
314    {SIG_CONTRACT_REQUEST, ""},
315    {SIG_REALIZED, ""},
316    {SIG_UNREALIZED, ""},
317    {SIG_DRAG_START_UP, ""},
318    {SIG_DRAG_START_DOWN, ""},
319    {SIG_DRAG_START_LEFT, ""},
320    {SIG_DRAG_START_RIGHT, ""},
321    {SIG_DRAG_STOP, ""},
322    {SIG_DRAG, ""},
323    {SIG_LONGPRESSED, ""},
324    {SIG_SCROLL_EDGE_TOP, ""},
325    {SIG_SCROLL_EDGE_BOTTOM, ""},
326    {SIG_SCROLL_EDGE_LEFT, ""},
327    {SIG_SCROLL_EDGE_RIGHT, ""},
328    {SIG_MULTI_SWIPE_LEFT, ""},
329    {SIG_MULTI_SWIPE_RIGHT, ""},
330    {SIG_MULTI_SWIPE_UP, ""},
331    {SIG_MULTI_SWIPE_DOWN, ""},
332    {SIG_MULTI_PINCH_OUT, ""},
333    {SIG_MULTI_PINCH_IN, ""},
334    {SIG_SWIPE, ""},
335    {NULL, NULL}
336 };
337
338 static Eina_Bool
339 _event_hook(Evas_Object       *obj,
340             Evas_Object       *src __UNUSED__,
341             Evas_Callback_Type type,
342             void              *event_info)
343 {
344    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
345    Evas_Event_Key_Down *ev = event_info;
346    Widget_Data *wd = elm_widget_data_get(obj);
347    Evas_Coord pan_max_x = 0, pan_max_y = 0;
348    if (!wd) return EINA_FALSE;
349    if (!wd->items) return EINA_FALSE;
350    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
351    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
352
353    Elm_Genlist_Item *it = NULL;
354    Evas_Coord x = 0;
355    Evas_Coord y = 0;
356    Evas_Coord step_x = 0;
357    Evas_Coord step_y = 0;
358    Evas_Coord v_w = 0;
359    Evas_Coord v_h = 0;
360    Evas_Coord page_x = 0;
361    Evas_Coord page_y = 0;
362
363    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
364    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
365    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
366    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
367
368    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
369      {
370         x -= step_x;
371      }
372    else if ((!strcmp(ev->keyname, "Right")) ||
373             (!strcmp(ev->keyname, "KP_Right")))
374      {
375         x += step_x;
376      }
377    else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
378      {
379         if (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
380              (_item_multi_select_up(wd)))
381             || (_item_single_select_up(wd)))
382           {
383              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
384              return EINA_TRUE;
385           }
386         else
387           y -= step_y;
388      }
389    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
390      {
391         if (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
392              (_item_multi_select_down(wd)))
393             || (_item_single_select_down(wd)))
394           {
395              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
396              return EINA_TRUE;
397           }
398         else
399           y += step_y;
400      }
401    else if ((!strcmp(ev->keyname, "Home")) ||
402             (!strcmp(ev->keyname, "KP_Home")))
403      {
404         it = elm_genlist_first_item_get(obj);
405         elm_genlist_item_bring_in(it);
406         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
407         return EINA_TRUE;
408      }
409    else if ((!strcmp(ev->keyname, "End")) ||
410             (!strcmp(ev->keyname, "KP_End")))
411      {
412         it = elm_genlist_last_item_get(obj);
413         elm_genlist_item_bring_in(it);
414         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
415         return EINA_TRUE;
416      }
417    else if ((!strcmp(ev->keyname, "Prior")) ||
418             (!strcmp(ev->keyname, "KP_Prior")))
419      {
420         if (page_y < 0)
421           y -= -(page_y * v_h) / 100;
422         else
423           y -= page_y;
424      }
425    else if ((!strcmp(ev->keyname, "Next")) ||
426             (!strcmp(ev->keyname, "KP_Next")))
427      {
428         if (page_y < 0)
429           y += -(page_y * v_h) / 100;
430         else
431           y += page_y;
432      }
433    else if (((!strcmp(ev->keyname, "Return")) ||
434             (!strcmp(ev->keyname, "KP_Enter")) ||
435             (!strcmp(ev->keyname, "space")))
436            && (!wd->multi) && (wd->selected))
437      {
438         it = elm_genlist_selected_item_get(obj);
439         elm_genlist_item_expanded_set(it,
440                                       !elm_genlist_item_expanded_get(it));
441         evas_object_smart_callback_call(it->base.widget, SIG_ACTIVATED, it);
442      }
443    else if (!strcmp(ev->keyname, "Escape"))
444      {
445         if (!_deselect_all_items(wd)) return EINA_FALSE;
446         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
447         return EINA_TRUE;
448      }
449    else return EINA_FALSE;
450
451    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
452    _pan_max_get(wd->pan_smart, &pan_max_x, &pan_max_y);
453    if (x < 0) x = 0;
454    if (x > pan_max_x) x = pan_max_x;
455    if (y < 0) y = 0;
456    if (y > pan_max_y) y = pan_max_y;
457    elm_smart_scroller_child_pos_set(wd->scr, x, y);
458    return EINA_TRUE;
459 }
460
461 static Eina_Bool
462 _deselect_all_items(Widget_Data *wd)
463 {
464    if (!wd->selected) return EINA_FALSE;
465    while (wd->selected)
466      elm_genlist_item_selected_set(wd->selected->data, EINA_FALSE);
467
468    return EINA_TRUE;
469 }
470
471 static Eina_Bool
472 _item_multi_select_up(Widget_Data *wd)
473 {
474    if (!wd->selected) return EINA_FALSE;
475    if (!wd->multi) return EINA_FALSE;
476
477    Elm_Genlist_Item *prev = elm_genlist_item_prev_get(wd->last_selected_item);
478    if (!prev) return EINA_TRUE;
479
480    if (elm_genlist_item_selected_get(prev))
481      {
482         elm_genlist_item_selected_set(wd->last_selected_item, EINA_FALSE);
483         wd->last_selected_item = prev;
484         elm_genlist_item_show(wd->last_selected_item);
485      }
486    else
487      {
488         elm_genlist_item_selected_set(prev, EINA_TRUE);
489         elm_genlist_item_show(prev);
490      }
491    return EINA_TRUE;
492 }
493
494 static Eina_Bool
495 _item_multi_select_down(Widget_Data *wd)
496 {
497    if (!wd->selected) return EINA_FALSE;
498    if (!wd->multi) return EINA_FALSE;
499
500    Elm_Genlist_Item *next = elm_genlist_item_next_get(wd->last_selected_item);
501    if (!next) return EINA_TRUE;
502
503    if (elm_genlist_item_selected_get(next))
504      {
505         elm_genlist_item_selected_set(wd->last_selected_item, EINA_FALSE);
506         wd->last_selected_item = next;
507         elm_genlist_item_show(wd->last_selected_item);
508      }
509    else
510      {
511         elm_genlist_item_selected_set(next, EINA_TRUE);
512         elm_genlist_item_show(next);
513      }
514    return EINA_TRUE;
515 }
516
517 static Eina_Bool
518 _item_single_select_up(Widget_Data *wd)
519 {
520    Elm_Genlist_Item *prev;
521    if (!wd->selected)
522      {
523         prev = ELM_GENLIST_ITEM_FROM_INLIST(wd->items->last);
524         while ((prev) && (prev->delete_me))
525           prev = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
526      }
527    else prev = elm_genlist_item_prev_get(wd->last_selected_item);
528
529    if (!prev) return EINA_FALSE;
530
531    _deselect_all_items(wd);
532
533    elm_genlist_item_selected_set(prev, EINA_TRUE);
534    elm_genlist_item_show(prev);
535    return EINA_TRUE;
536 }
537
538 static Eina_Bool
539 _item_single_select_down(Widget_Data *wd)
540 {
541    Elm_Genlist_Item *next;
542    if (!wd->selected)
543      {
544         next = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
545         while ((next) && (next->delete_me))
546           next = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
547      }
548    else next = elm_genlist_item_next_get(wd->last_selected_item);
549
550    if (!next) return EINA_FALSE;
551
552    _deselect_all_items(wd);
553
554    elm_genlist_item_selected_set(next, EINA_TRUE);
555    elm_genlist_item_show(next);
556    return EINA_TRUE;
557 }
558
559 static void
560 _on_focus_hook(void        *data __UNUSED__,
561                Evas_Object *obj)
562 {
563    Widget_Data *wd = elm_widget_data_get(obj);
564    if (!wd) return;
565    if (elm_widget_focus_get(obj))
566      {
567         elm_object_signal_emit(wd->obj, "elm,action,focus", "elm");
568         evas_object_focus_set(wd->obj, EINA_TRUE);
569         if ((wd->selected) && (!wd->last_selected_item))
570           wd->last_selected_item = eina_list_data_get(wd->selected);
571      }
572    else
573      {
574         elm_object_signal_emit(wd->obj, "elm,action,unfocus", "elm");
575         evas_object_focus_set(wd->obj, EINA_FALSE);
576      }
577 }
578
579 static void
580 _del_hook(Evas_Object *obj)
581 {
582    Widget_Data *wd = elm_widget_data_get(obj);
583    if (!wd) return;
584    _item_cache_zero(wd);
585    if (wd->calc_job) ecore_job_del(wd->calc_job);
586    if (wd->update_job) ecore_job_del(wd->update_job);
587    if (wd->queue_idle_enterer) ecore_idle_enterer_del(wd->queue_idle_enterer);
588    if (wd->changed_job) ecore_job_del(wd->changed_job);
589    if (wd->must_recalc_idler) ecore_idler_del(wd->must_recalc_idler);
590    if (wd->multi_timer) ecore_timer_del(wd->multi_timer);
591    if (wd->mode_type) eina_stringshare_del(wd->mode_type);
592    if (wd->scr_hold_timer) ecore_timer_del(wd->scr_hold_timer);
593    free(wd);
594 }
595
596 static void
597 _del_pre_hook(Evas_Object *obj)
598 {
599    Widget_Data *wd = elm_widget_data_get(obj);
600    if (!wd) return;
601    if (wd->edit_mode) elm_genlist_edit_mode_set(wd->obj, EINA_FALSE);
602    elm_genlist_clear(obj);
603    evas_object_del(wd->pan_smart);
604    wd->pan_smart = NULL;
605 }
606
607 static void
608 _mirrored_set(Evas_Object *obj,
609               Eina_Bool    rtl)
610 {
611    Widget_Data *wd = elm_widget_data_get(obj);
612    if (!wd) return;
613    _item_cache_zero(wd);
614    elm_smart_scroller_mirrored_set(wd->scr, rtl);
615 }
616
617 static void
618 _theme_hook(Evas_Object *obj)
619 {
620    Widget_Data *wd = elm_widget_data_get(obj);
621    Item_Block *itb;
622    if (!wd) return;
623    evas_event_freeze(evas_object_evas_get(wd->obj));
624    _item_cache_zero(wd);
625    _elm_widget_mirrored_reload(obj);
626    _mirrored_set(obj, elm_widget_mirrored_get(obj));
627    elm_smart_scroller_object_theme_set(obj, wd->scr, "genlist", "base",
628                                        elm_widget_style_get(obj));
629    //   edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
630    wd->item_width = wd->item_height = 0;
631    wd->group_item_width = wd->group_item_height = 0;
632    wd->minw = wd->minh = wd->realminw = 0;
633    EINA_INLIST_FOREACH(wd->blocks, itb)
634      {
635         Eina_List *l;
636         Elm_Genlist_Item *it;
637
638         if (itb->realized) _item_block_unrealize(itb);
639         EINA_LIST_FOREACH(itb->items, l, it)
640           it->mincalcd = EINA_FALSE;
641
642         itb->changed = EINA_TRUE;
643      }
644    if (wd->calc_job) ecore_job_del(wd->calc_job);
645    wd->calc_job = ecore_job_add(_calc_job, wd);
646    _sizing_eval(obj);
647    evas_event_thaw(evas_object_evas_get(wd->obj));
648    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
649 }
650
651 static void
652 _show_region_hook(void        *data,
653                   Evas_Object *obj)
654 {
655    Widget_Data *wd = elm_widget_data_get(data);
656    Evas_Coord x, y, w, h;
657    if (!wd) return;
658    elm_widget_show_region_get(obj, &x, &y, &w, &h);
659    //x & y are screen coordinates, Add with pan coordinates
660    x += wd->pan_x;
661    y += wd->pan_y;
662    elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
663 }
664
665 static void
666 _sizing_eval(Evas_Object *obj)
667 {
668    Widget_Data *wd = elm_widget_data_get(obj);
669    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
670    if (!wd) return;
671    evas_object_size_hint_min_get(wd->scr, &minw, &minh);
672    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
673    minh = -1;
674    if (wd->height_for_width)
675      {
676         Evas_Coord vw, vh;
677
678         elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
679         if ((vw != 0) && (vw != wd->prev_viewport_w))
680           {
681              Item_Block *itb;
682
683              wd->prev_viewport_w = vw;
684              EINA_INLIST_FOREACH(wd->blocks, itb)
685                {
686                   itb->must_recalc = EINA_TRUE;
687                }
688              if (wd->calc_job) ecore_job_del(wd->calc_job);
689              wd->calc_job = ecore_job_add(_calc_job, wd);
690           }
691      }
692    if (wd->mode == ELM_LIST_LIMIT)
693      {
694         Evas_Coord vmw, vmh, vw, vh;
695
696         minw = wd->realminw;
697         maxw = -1;
698         elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
699         if ((minw > 0) && (vw < minw)) vw = minw;
700         else if ((maxw > 0) && (vw > maxw))
701           vw = maxw;
702         edje_object_size_min_calc
703           (elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
704         minw = vmw + minw;
705      }
706    else
707      {
708         Evas_Coord vmw, vmh;
709
710         edje_object_size_min_calc
711           (elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
712         minw = vmw;
713         minh = vmh;
714      }
715    evas_object_size_hint_min_set(obj, minw, minh);
716    evas_object_size_hint_max_set(obj, maxw, maxh);
717 }
718
719 static void
720 _signal_emit_hook(Evas_Object *obj,
721                   const char  *emission,
722                   const char  *source)
723 {
724    Widget_Data *wd = elm_widget_data_get(obj);
725    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
726                            emission, source);
727 }
728
729 static void
730 _item_highlight(Elm_Genlist_Item *it)
731 {
732    const char *selectraise;
733    if ((it->wd->no_select) || (it->delete_me) || (it->highlighted) ||
734        (it->disabled) || (it->display_only) || (it->mode_view))
735      return;
736    edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
737    if (it->edit_obj) edje_object_signal_emit(it->edit_obj, "elm,state,selected", "elm");
738    selectraise = edje_object_data_get(it->base.view, "selectraise");
739    if ((selectraise) && (!strcmp(selectraise, "on")))
740      {
741         if (it->edit_obj) evas_object_raise(it->edit_obj);
742         else evas_object_raise(it->base.view);
743         if ((it->group_item) && (it->group_item->realized))
744           evas_object_raise(it->group_item->base.view);
745      }
746    it->highlighted = EINA_TRUE;
747 }
748
749 static void
750 _item_block_del(Elm_Genlist_Item *it)
751 {
752    Eina_Inlist *il;
753    Item_Block *itb = it->block;
754
755    itb->items = eina_list_remove(itb->items, it);
756    itb->count--;
757    itb->changed = EINA_TRUE;
758    if (!it->wd->reorder_deleted)
759      {
760         if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
761         it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
762      }
763    if (itb->count < 1)
764      {
765         il = EINA_INLIST_GET(itb);
766         Item_Block *itbn = (Item_Block *)(il->next);
767         if (it->parent)
768           it->parent->items = eina_list_remove(it->parent->items, it);
769         else
770           it->wd->blocks = eina_inlist_remove(it->wd->blocks, il);
771         free(itb);
772         if (itbn) itbn->changed = EINA_TRUE;
773      }
774    else
775      {
776         if (itb->count < itb->wd->max_items_per_block/2)
777           {
778              il = EINA_INLIST_GET(itb);
779              Item_Block *itbp = (Item_Block *)(il->prev);
780              Item_Block *itbn = (Item_Block *)(il->next);
781              if ((itbp) && ((itbp->count + itb->count) < itb->wd->max_items_per_block + itb->wd->max_items_per_block/2))
782                {
783                   Elm_Genlist_Item *it2;
784
785                   EINA_LIST_FREE(itb->items, it2)
786                     {
787                        it2->block = itbp;
788                        itbp->items = eina_list_append(itbp->items, it2);
789                        itbp->count++;
790                        itbp->changed = EINA_TRUE;
791                     }
792                   it->wd->blocks = eina_inlist_remove(it->wd->blocks,
793                                                       EINA_INLIST_GET(itb));
794                   free(itb);
795                }
796              else if ((itbn) && ((itbn->count + itb->count) < itb->wd->max_items_per_block + itb->wd->max_items_per_block/2))
797                {
798                   while (itb->items)
799                     {
800                        Eina_List *last = eina_list_last(itb->items);
801                        Elm_Genlist_Item *it2 = last->data;
802
803                        it2->block = itbn;
804                        itb->items = eina_list_remove_list(itb->items, last);
805                        itbn->items = eina_list_prepend(itbn->items, it2);
806                        itbn->count++;
807                        itbn->changed = EINA_TRUE;
808                     }
809                   it->wd->blocks =
810                     eina_inlist_remove(it->wd->blocks, EINA_INLIST_GET(itb));
811                   free(itb);
812                }
813           }
814      }
815 }
816
817 static void
818 _item_subitems_clear(Elm_Genlist_Item *it)
819 {
820    if (!it) return;
821    Eina_List *tl = NULL, *l;
822    Elm_Genlist_Item *it2;
823
824    EINA_LIST_FOREACH(it->items, l, it2)
825       tl = eina_list_append(tl, it2);
826
827    EINA_LIST_FREE(tl, it2)
828      elm_genlist_item_del(it2);
829 }
830
831 static void
832 _item_del(Elm_Genlist_Item *it)
833 {
834    Evas_Object *tob = it->wd->obj;
835
836    evas_event_freeze(evas_object_evas_get(tob));
837    elm_widget_item_pre_notify_del(it);
838    elm_genlist_item_subitems_clear(it);
839    it->wd->walking -= it->walking;
840    if (it->wd->show_item == it) it->wd->show_item = NULL;
841    if (it->selected) it->wd->selected = eina_list_remove(it->wd->selected, it);
842    if (it->realized) _item_unrealize(it, EINA_FALSE);
843    if (it->effect_item_realized) _effect_item_unrealize(it);
844    if (it->block) _item_block_del(it);
845    if ((!it->delete_me) && (it->itc->func.del))
846      it->itc->func.del((void *)it->base.data, it->base.widget);
847    it->delete_me = EINA_TRUE;
848    if (it->queued)
849      it->wd->queue = eina_list_remove(it->wd->queue, it);
850 #ifdef ANCHOR_ITEM
851    if (it->wd->anchor_item == it)
852      {
853         it->wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
854         if (!it->wd->anchor_item)
855           it->wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
856      }
857 #endif
858    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
859    if (it->parent)
860      it->parent->items = eina_list_remove(it->parent->items, it);
861    if (it->flags & ELM_GENLIST_ITEM_GROUP)
862      it->wd->group_items = eina_list_remove(it->wd->group_items, it);
863    if (it->long_timer) ecore_timer_del(it->long_timer);
864    if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
865
866    if (it->tooltip.del_cb)
867      it->tooltip.del_cb((void *)it->tooltip.data, it->base.widget, it);
868
869    evas_event_thaw(evas_object_evas_get(tob));
870    evas_event_thaw_eval(evas_object_evas_get(tob));
871
872    elm_widget_item_del(it);
873 }
874
875 static void
876 _item_select(Elm_Genlist_Item *it)
877 {
878    if ((it->wd->no_select) || (it->delete_me) || (it->mode_view)) return;
879    if (it->selected)
880      {
881         if (it->wd->always_select) goto call;
882         return;
883      }
884    it->selected = EINA_TRUE;
885    it->wd->selected = eina_list_append(it->wd->selected, it);
886 call:
887    evas_object_ref(it->base.widget);
888    it->walking++;
889    it->wd->walking++;
890    if (it->func.func) it->func.func((void *)it->func.data, it->base.widget, it);
891    if (!it->delete_me)
892      evas_object_smart_callback_call(it->base.widget, SIG_SELECTED, it);
893    it->walking--;
894    it->wd->walking--;
895    if ((it->wd->clear_me) && (!it->wd->walking))
896      {
897         elm_genlist_clear(it->base.widget);
898         return;
899      }
900    else
901      {
902         if ((!it->walking) && (it->delete_me))
903           {
904              if (!it->relcount) _item_del(it);
905           }
906      }
907    if (it && it->wd) it->wd->last_selected_item = it; // TODO: Remove 'if'?
908    evas_object_unref(it->base.widget);
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 || ((it->wd->height_for_width) && (it->w != it->minw)))
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 && !it->updateme) 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                   if (itb->realized) _item_block_unrealize(itb);
2494                }
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                   if (it->realized)
2619                     {
2620                        _item_unrealize(it, EINA_FALSE);
2621                        _item_realize(it, num, EINA_FALSE);
2622                        position = EINA_TRUE;
2623                     }
2624                   else
2625                     {
2626                        _item_realize(it, num, EINA_TRUE);
2627                        _item_unrealize(it, EINA_TRUE);
2628                     }
2629                   if ((it->minw != itminw) || (it->minh != itminh))
2630                     recalc = EINA_TRUE;
2631                   it->updateme = EINA_FALSE;
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    sd->wd->pan_changed = EINA_TRUE;
2894    evas_object_smart_changed(obj);
2895    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2896    sd->wd->calc_job = NULL;
2897 }
2898
2899 static void
2900 _pan_calculate(Evas_Object *obj)
2901 {
2902    Pan *sd = evas_object_smart_data_get(obj);
2903    Item_Block *itb;
2904    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh;
2905    int in = 0;
2906    Elm_Genlist_Item *git;
2907    Eina_List *l;
2908
2909    if (!sd) return;
2910    evas_event_freeze(evas_object_evas_get(obj));
2911
2912    if (sd->wd->pan_changed)
2913      {
2914         _calc_job(sd->wd);
2915         sd->wd->pan_changed = EINA_FALSE;
2916      }
2917
2918    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2919    sd->wd->prev_viewport_w = ow;
2920    evas_output_viewport_get(evas_object_evas_get(obj), &cvx, &cvy, &cvw, &cvh);
2921    EINA_LIST_FOREACH(sd->wd->group_items, l, git)
2922      {
2923         git->want_realize = EINA_FALSE;
2924      }
2925    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2926      {
2927         itb->w = sd->wd->minw;
2928         if (ELM_RECTS_INTERSECT(itb->x - sd->wd->pan_x + ox,
2929                                 itb->y - sd->wd->pan_y + oy,
2930                                 itb->w, itb->h,
2931                                 cvx, cvy, cvw, cvh))
2932           {
2933              if ((!itb->realized) || (itb->changed))
2934                _item_block_realize(itb, in, 0);
2935              _item_block_position(itb, in);
2936           }
2937         else
2938           {
2939              if (itb->realized) _item_block_unrealize(itb);
2940           }
2941         in += itb->count;
2942      }
2943    if ((!sd->wd->reorder_it) || (sd->wd->reorder_pan_move))
2944       _group_items_recalc(sd->wd);
2945
2946    if ((sd->wd->reorder_mode) && (sd->wd->reorder_it))
2947      {
2948         if (sd->wd->pan_y != sd->wd->old_pan_y)
2949           sd->wd->reorder_pan_move = EINA_TRUE;
2950         else sd->wd->reorder_pan_move = EINA_FALSE;
2951         evas_object_raise(sd->wd->reorder_it->edit_obj);
2952         sd->wd->old_pan_y = sd->wd->pan_y;
2953         sd->wd->start_time = ecore_loop_time_get();
2954      }
2955
2956       if (sd->wd->effect_mode &&
2957           ((sd->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND) ||
2958            (sd->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT) ||
2959            (sd->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE)))
2960         {
2961            if (!sd->wd->item_moving_effect_timer)
2962              {
2963                 if (sd->wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE)
2964                    _item_flip_effect_show(sd->wd->expand_item);
2965
2966                 evas_object_raise(sd->wd->alpha_bg);
2967                 evas_object_show(sd->wd->alpha_bg);
2968                 elm_smart_scroller_bounce_animator_disabled_set(sd->wd->scr, EINA_TRUE);
2969                 sd->wd->start_time = current_time_get();
2970                 sd->wd->item_moving_effect_timer = ecore_animator_add(_item_moving_effect_timer_cb, sd->wd);
2971              }
2972         }
2973       else _item_auto_scroll(sd->wd);
2974    sd->wd->pan_resize = EINA_FALSE;
2975    evas_event_thaw(evas_object_evas_get(obj));
2976    evas_event_thaw_eval(evas_object_evas_get(obj));
2977 }
2978
2979 static void
2980 _pan_move(Evas_Object *obj,
2981           Evas_Coord   x __UNUSED__,
2982           Evas_Coord   y __UNUSED__)
2983 {
2984    Pan *sd = evas_object_smart_data_get(obj);
2985
2986    if (!sd) return;
2987
2988    sd->wd->pan_changed = EINA_TRUE;
2989    evas_object_smart_changed(obj);
2990    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2991    sd->wd->calc_job = NULL;
2992 }
2993
2994 static void
2995 _hold_on(void        *data __UNUSED__,
2996          Evas_Object *obj,
2997          void        *event_info __UNUSED__)
2998 {
2999    Widget_Data *wd = elm_widget_data_get(obj);
3000    if (!wd) return;
3001    elm_smart_scroller_hold_set(wd->scr, 1);
3002 }
3003
3004 static void
3005 _hold_off(void        *data __UNUSED__,
3006           Evas_Object *obj,
3007           void        *event_info __UNUSED__)
3008 {
3009    Widget_Data *wd = elm_widget_data_get(obj);
3010    if (!wd) return;
3011    elm_smart_scroller_hold_set(wd->scr, 0);
3012 }
3013
3014 static void
3015 _freeze_on(void        *data __UNUSED__,
3016            Evas_Object *obj,
3017            void        *event_info __UNUSED__)
3018 {
3019    Widget_Data *wd = elm_widget_data_get(obj);
3020    if (!wd) return;
3021    elm_smart_scroller_freeze_set(wd->scr, 1);
3022 }
3023
3024 static void
3025 _freeze_off(void        *data __UNUSED__,
3026             Evas_Object *obj,
3027             void        *event_info __UNUSED__)
3028 {
3029    Widget_Data *wd = elm_widget_data_get(obj);
3030    if (!wd) return;
3031    elm_smart_scroller_freeze_set(wd->scr, 0);
3032 }
3033
3034 static void
3035 _scroll_edge_left(void        *data,
3036                   Evas_Object *scr __UNUSED__,
3037                   void        *event_info __UNUSED__)
3038 {
3039    Evas_Object *obj = data;
3040    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_LEFT, NULL);
3041 }
3042
3043 static void
3044 _scroll_edge_right(void        *data,
3045                    Evas_Object *scr __UNUSED__,
3046                    void        *event_info __UNUSED__)
3047 {
3048    Evas_Object *obj = data;
3049    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_RIGHT, NULL);
3050 }
3051
3052 static void
3053 _scroll_edge_top(void        *data,
3054                  Evas_Object *scr __UNUSED__,
3055                  void        *event_info __UNUSED__)
3056 {
3057    Evas_Object *obj = data;
3058    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_TOP, NULL);
3059 }
3060
3061 static void
3062 _scroll_edge_bottom(void        *data,
3063                     Evas_Object *scr __UNUSED__,
3064                     void        *event_info __UNUSED__)
3065 {
3066    Evas_Object *obj = data;
3067    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_BOTTOM, NULL);
3068 }
3069
3070 static void
3071 _mode_item_realize(Elm_Genlist_Item *it)
3072 {
3073    char buf[1024];
3074
3075    if ((it->mode_view) || (it->delete_me)) return;
3076
3077    evas_event_freeze(evas_object_evas_get(it->wd->obj));
3078    it->mode_view = edje_object_add(evas_object_evas_get(it->base.widget));
3079    edje_object_scale_set(it->mode_view,
3080                          elm_widget_scale_get(it->base.widget) *
3081                          _elm_config->scale);
3082    evas_object_smart_member_add(it->mode_view, it->wd->pan_smart);
3083    elm_widget_sub_object_add(it->base.widget, it->mode_view);
3084
3085    strncpy(buf, "item", sizeof(buf));
3086    if (it->wd->compress)
3087      strncat(buf, "_compress", sizeof(buf) - strlen(buf));
3088
3089    if (it->order_num_in & 0x1) strncat(buf, "_odd", sizeof(buf) - strlen(buf));
3090    strncat(buf, "/", sizeof(buf) - strlen(buf));
3091    strncat(buf, it->itc->mode_item_style, sizeof(buf) - strlen(buf));
3092
3093    _elm_theme_object_set(it->base.widget, it->mode_view, "genlist", buf,
3094                          elm_widget_style_get(it->base.widget));
3095    edje_object_mirrored_set(it->mode_view,
3096                             elm_widget_mirrored_get(it->base.widget));
3097
3098    /* signal callback add */
3099    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_DOWN,
3100                                   _mouse_down, it);
3101    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_UP,
3102                                   _mouse_up, it);
3103    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_MOVE,
3104                                   _mouse_move, it);
3105
3106    /* label_get, icon_get, state_get */
3107    if (it->itc->func.label_get)
3108      {
3109         const Eina_List *l;
3110         const char *key;
3111
3112         it->mode_labels =
3113            elm_widget_stringlist_get(edje_object_data_get(it->mode_view,
3114                                                           "labels"));
3115         EINA_LIST_FOREACH(it->mode_labels, l, key)
3116           {
3117              char *s = it->itc->func.label_get
3118                 ((void *)it->base.data, it->base.widget, l->data);
3119
3120              if (s)
3121                {
3122                   edje_object_part_text_set(it->mode_view, l->data, s);
3123                   free(s);
3124                }
3125           }
3126      }
3127    if (it->itc->func.icon_get)
3128      {
3129         const Eina_List *l;
3130         const char *key;
3131
3132         it->mode_icons =
3133            elm_widget_stringlist_get(edje_object_data_get(it->mode_view,
3134                                                           "icons"));
3135         EINA_LIST_FOREACH(it->mode_icons, l, key)
3136          {
3137            Evas_Object *ic = it->itc->func.icon_get
3138                 ((void *)it->base.data, it->base.widget, l->data);
3139
3140              if (ic)
3141                {
3142                   it->mode_icon_objs = eina_list_append(it->mode_icon_objs, ic);
3143                   edje_object_part_swallow(it->mode_view, key, ic);
3144                   evas_object_show(ic);
3145                   elm_widget_sub_object_add(it->base.widget, ic);
3146                   if (it->disabled)
3147                     elm_widget_disabled_set(ic, EINA_TRUE);
3148                }
3149           }
3150      }
3151    if (it->itc->func.state_get)
3152      {
3153         const Eina_List *l;
3154         const char *key;
3155
3156         it->mode_states =
3157            elm_widget_stringlist_get(edje_object_data_get(it->mode_view,
3158                                                           "states"));
3159         EINA_LIST_FOREACH(it->mode_states, l, key)
3160           {
3161              Eina_Bool on = it->itc->func.state_get
3162                 ((void *)it->base.data, it->base.widget, l->data);
3163
3164              if (on)
3165                {
3166                   snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
3167                   edje_object_signal_emit(it->mode_view, buf, "elm");
3168                }
3169           }
3170      }
3171
3172    edje_object_part_swallow(it->mode_view,
3173                             edje_object_data_get(it->mode_view, "mode_part"),
3174                             it->base.view);
3175
3176    it->want_unrealize = EINA_FALSE;
3177    evas_event_thaw(evas_object_evas_get(it->wd->obj));
3178    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
3179 }
3180
3181 static void
3182 _mode_item_unrealize(Elm_Genlist_Item *it)
3183 {
3184    Widget_Data *wd = it->wd;
3185    Evas_Object *icon;
3186    if (!it->mode_view) return;
3187
3188    evas_event_freeze(evas_object_evas_get(it->wd->obj));
3189    elm_widget_stringlist_free(it->mode_labels);
3190    it->mode_labels = NULL;
3191    elm_widget_stringlist_free(it->mode_icons);
3192    it->mode_icons = NULL;
3193    elm_widget_stringlist_free(it->mode_states);
3194
3195    EINA_LIST_FREE(it->mode_icon_objs, icon)
3196      evas_object_del(icon);
3197
3198    edje_object_part_unswallow(it->mode_view, it->base.view);
3199    evas_object_smart_member_add(it->base.view, wd->pan_smart);
3200    evas_object_del(it->mode_view);
3201    it->mode_view = NULL;
3202
3203    if (wd->mode_item == it)
3204      wd->mode_item = NULL;
3205    evas_event_thaw(evas_object_evas_get(it->wd->obj));
3206    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
3207 }
3208
3209 static void
3210 _item_mode_set(Elm_Genlist_Item *it)
3211 {
3212    if (!it) return;
3213    Widget_Data *wd = it->wd;
3214    if (!wd) return;
3215    char buf[1024];
3216
3217    wd->mode_item = it;
3218    it->nocache = EINA_TRUE;
3219
3220    if (wd->scr_hold_timer)
3221      {
3222         ecore_timer_del(wd->scr_hold_timer);
3223         wd->scr_hold_timer = NULL;
3224      }
3225    elm_smart_scroller_hold_set(wd->scr, EINA_TRUE);
3226    wd->scr_hold_timer = ecore_timer_add(0.1, _scr_hold_timer_cb, wd);
3227
3228    evas_event_freeze(evas_object_evas_get(it->wd->obj));
3229    _mode_item_realize(it);
3230    _item_position(it, it->mode_view, it->scrl_x, it->scrl_y);
3231    evas_event_thaw(evas_object_evas_get(it->wd->obj));
3232    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
3233
3234    snprintf(buf, sizeof(buf), "elm,state,%s,active", wd->mode_type);
3235    edje_object_signal_emit(it->mode_view, buf, "elm");
3236 }
3237
3238 static void
3239 _item_mode_unset(Widget_Data *wd)
3240 {
3241    if (!wd) return;
3242    if (!wd->mode_item) return;
3243    char buf[1024], buf2[1024];
3244    Elm_Genlist_Item *it;
3245
3246    it = wd->mode_item;
3247    it->nocache = EINA_TRUE;
3248
3249    snprintf(buf, sizeof(buf), "elm,state,%s,passive", wd->mode_type);
3250    snprintf(buf2, sizeof(buf2), "elm,state,%s,passive,finished", wd->mode_type);
3251
3252    edje_object_signal_emit(it->mode_view, buf, "elm");
3253    edje_object_signal_callback_add(it->mode_view, buf2, "elm", _mode_finished_signal_cb, it);
3254
3255    wd->mode_item = NULL;
3256 }
3257
3258 EAPI Evas_Object *
3259 elm_genlist_add(Evas_Object *parent)
3260 {
3261    Evas_Object *obj;
3262    Evas *e;
3263    Widget_Data *wd;
3264    Evas_Coord minw, minh;
3265    static Evas_Smart *smart = NULL;
3266
3267    if (!smart)
3268      {
3269         static Evas_Smart_Class sc;
3270
3271         evas_object_smart_clipped_smart_set(&_pan_sc);
3272         sc = _pan_sc;
3273         sc.name = "elm_genlist_pan";
3274         sc.version = EVAS_SMART_CLASS_VERSION;
3275         sc.add = _pan_add;
3276         sc.del = _pan_del;
3277         sc.resize = _pan_resize;
3278         sc.move = _pan_move;
3279         sc.calculate = _pan_calculate;
3280         if (!(smart = evas_smart_class_new(&sc))) return NULL;
3281      }
3282
3283    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
3284
3285    ELM_SET_WIDTYPE(widtype, "genlist");
3286    elm_widget_type_set(obj, "genlist");
3287    elm_widget_sub_object_add(parent, obj);
3288    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
3289    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
3290    elm_widget_data_set(obj, wd);
3291    elm_widget_del_hook_set(obj, _del_hook);
3292    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
3293    elm_widget_theme_hook_set(obj, _theme_hook);
3294    elm_widget_can_focus_set(obj, EINA_TRUE);
3295    elm_widget_event_hook_set(obj, _event_hook);
3296    elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
3297
3298    wd->scr = elm_smart_scroller_add(e);
3299    elm_smart_scroller_widget_set(wd->scr, obj);
3300    elm_smart_scroller_object_theme_set(obj, wd->scr, "genlist", "base",
3301                                        elm_widget_style_get(obj));
3302    elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
3303                                        _elm_config->thumbscroll_bounce_enable);
3304    elm_widget_resize_object_set(obj, wd->scr);
3305
3306    evas_object_smart_callback_add(wd->scr, "edge,left", _scroll_edge_left, obj);
3307    evas_object_smart_callback_add(wd->scr, "edge,right", _scroll_edge_right,
3308                                   obj);
3309    evas_object_smart_callback_add(wd->scr, "edge,top", _scroll_edge_top, obj);
3310    evas_object_smart_callback_add(wd->scr, "edge,bottom", _scroll_edge_bottom,
3311                                   obj);
3312
3313    wd->obj = obj;
3314    wd->mode = ELM_LIST_SCROLL;
3315    wd->max_items_per_block = MAX_ITEMS_PER_BLOCK;
3316    wd->item_cache_max = wd->max_items_per_block * 2;
3317    wd->longpress_timeout = _elm_config->longpress_timeout;
3318    wd->effect_mode = _elm_config->effect_enable;
3319
3320    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
3321    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
3322    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
3323    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
3324
3325    wd->pan_smart = evas_object_smart_add(e, smart);
3326    wd->pan = evas_object_smart_data_get(wd->pan_smart);
3327    wd->pan->wd = wd;
3328
3329    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
3330                                      _pan_set, _pan_get, _pan_max_get,
3331                                      _pan_min_get, _pan_child_size_get);
3332
3333    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
3334                              &minw, &minh);
3335    evas_object_size_hint_min_set(obj, minw, minh);
3336
3337    evas_object_smart_callbacks_descriptions_set(obj, _signals);
3338    _mirrored_set(obj, elm_widget_mirrored_get(obj));
3339    _sizing_eval(obj);
3340    return obj;
3341 }
3342
3343 static Elm_Genlist_Item *
3344 _item_new(Widget_Data                  *wd,
3345           const Elm_Genlist_Item_Class *itc,
3346           const void                   *data,
3347           Elm_Genlist_Item             *parent,
3348           Elm_Genlist_Item_Flags        flags,
3349           Evas_Smart_Cb                 func,
3350           const void                   *func_data)
3351 {
3352    Elm_Genlist_Item *it;
3353
3354    it = elm_widget_item_new(wd->obj, Elm_Genlist_Item);
3355    if (!it) return NULL;
3356    it->wd = wd;
3357    it->itc = itc;
3358    it->base.data = data;
3359    it->parent = parent;
3360    it->flags = flags;
3361    it->func.func = func;
3362    it->func.data = func_data;
3363    it->mouse_cursor = NULL;
3364    it->expanded_depth = 0;
3365
3366    if (it->parent)
3367      {
3368         if (it->parent->flags & ELM_GENLIST_ITEM_GROUP)
3369           it->group_item = parent;
3370         else if (it->parent->group_item)
3371           it->group_item = it->parent->group_item;
3372      }
3373    return it;
3374 }
3375
3376 static void
3377 _item_block_add(Widget_Data      *wd,
3378                 Elm_Genlist_Item *it)
3379 {
3380    Item_Block *itb = NULL;
3381
3382    if (!it->rel)
3383      {
3384 newblock:
3385         if (it->rel)
3386           {
3387              itb = calloc(1, sizeof(Item_Block));
3388              if (!itb) return;
3389              itb->wd = wd;
3390              if (!it->rel->block)
3391                {
3392                   wd->blocks =
3393                     eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
3394                   itb->items = eina_list_append(itb->items, it);
3395                }
3396              else
3397                {
3398                   if (it->before)
3399                     {
3400                        wd->blocks = eina_inlist_prepend_relative
3401                            (wd->blocks, EINA_INLIST_GET(itb),
3402                            EINA_INLIST_GET(it->rel->block));
3403                        itb->items =
3404                          eina_list_prepend_relative(itb->items, it, it->rel);
3405                     }
3406                   else
3407                     {
3408                        wd->blocks = eina_inlist_append_relative
3409                            (wd->blocks, EINA_INLIST_GET(itb),
3410                            EINA_INLIST_GET(it->rel->block));
3411                        itb->items =
3412                          eina_list_append_relative(itb->items, it, it->rel);
3413                     }
3414                }
3415           }
3416         else
3417           {
3418              if (it->before)
3419                {
3420                   if (wd->blocks)
3421                     {
3422                        itb = (Item_Block *)(wd->blocks);
3423                        if (itb->count >= wd->max_items_per_block)
3424                          {
3425                             itb = calloc(1, sizeof(Item_Block));
3426                             if (!itb) return;
3427                             itb->wd = wd;
3428                             wd->blocks =
3429                               eina_inlist_prepend(wd->blocks,
3430                                                   EINA_INLIST_GET(itb));
3431                          }
3432                     }
3433                   else
3434                     {
3435                        itb = calloc(1, sizeof(Item_Block));
3436                        if (!itb) return;
3437                        itb->wd = wd;
3438                        wd->blocks =
3439                          eina_inlist_prepend(wd->blocks, EINA_INLIST_GET(itb));
3440                     }
3441                   itb->items = eina_list_prepend(itb->items, it);
3442                }
3443              else
3444                {
3445                   if (wd->blocks)
3446                     {
3447                        itb = (Item_Block *)(wd->blocks->last);
3448                        if (itb->count >= wd->max_items_per_block)
3449                          {
3450                             itb = calloc(1, sizeof(Item_Block));
3451                             if (!itb) return;
3452                             itb->wd = wd;
3453                             wd->blocks =
3454                               eina_inlist_append(wd->blocks,
3455                                                  EINA_INLIST_GET(itb));
3456                          }
3457                     }
3458                   else
3459                     {
3460                        itb = calloc(1, sizeof(Item_Block));
3461                        if (!itb) return;
3462                        itb->wd = wd;
3463                        wd->blocks =
3464                          eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
3465                     }
3466                   itb->items = eina_list_append(itb->items, it);
3467                }
3468           }
3469      }
3470    else
3471      {
3472         itb = it->rel->block;
3473         if (!itb) goto newblock;
3474         if (it->before)
3475           itb->items = eina_list_prepend_relative(itb->items, it, it->rel);
3476         else
3477           itb->items = eina_list_append_relative(itb->items, it, it->rel);
3478      }
3479    itb->count++;
3480    itb->changed = EINA_TRUE;
3481    it->block = itb;
3482    if (itb->wd->calc_job) ecore_job_del(itb->wd->calc_job);
3483    itb->wd->calc_job = ecore_job_add(_calc_job, itb->wd);
3484    if (it->rel)
3485      {
3486         it->rel->relcount--;
3487         if ((it->rel->delete_me) && (!it->rel->relcount))
3488           _item_del(it->rel);
3489         it->rel = NULL;
3490      }
3491    if (itb->count > itb->wd->max_items_per_block)
3492      {
3493         int newc;
3494         Item_Block *itb2;
3495         Elm_Genlist_Item *it2;
3496
3497         newc = itb->count / 2;
3498         itb2 = calloc(1, sizeof(Item_Block));
3499         if (!itb2) return;
3500         itb2->wd = wd;
3501         wd->blocks =
3502           eina_inlist_append_relative(wd->blocks, EINA_INLIST_GET(itb2),
3503                                       EINA_INLIST_GET(itb));
3504         itb2->changed = EINA_TRUE;
3505         while ((itb->count > newc) && (itb->items))
3506           {
3507              Eina_List *l;
3508
3509              l = eina_list_last(itb->items);
3510              it2 = l->data;
3511              itb->items = eina_list_remove_list(itb->items, l);
3512              itb->count--;
3513
3514              itb2->items = eina_list_prepend(itb2->items, it2);
3515              it2->block = itb2;
3516              itb2->count++;
3517           }
3518      }
3519 }
3520
3521 static int
3522 _queue_process(Widget_Data *wd)
3523 {
3524    int n;
3525    Eina_Bool showme = EINA_FALSE;
3526    double t0, t;
3527
3528    t0 = ecore_time_get();
3529    //evas_event_freeze(evas_object_evas_get(wd->obj));
3530    for (n = 0; (wd->queue) && (n < 128); n++)
3531      {
3532         Elm_Genlist_Item *it;
3533
3534         it = wd->queue->data;
3535         wd->queue = eina_list_remove_list(wd->queue, wd->queue);
3536         it->queued = EINA_FALSE;
3537         _item_block_add(wd, it);
3538         t = ecore_time_get();
3539         if (it->block->changed)
3540           {
3541              showme = _item_block_recalc(it->block, it->block->num, EINA_TRUE);
3542              it->block->changed = 0;
3543           }
3544         if (showme) it->block->showme = EINA_TRUE;
3545         if (eina_inlist_count(wd->blocks) > 1)
3546           {
3547              if ((t - t0) > (ecore_animator_frametime_get())) break;
3548           }
3549      }
3550    //evas_event_thaw(evas_object_evas_get(wd->obj));
3551    //evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3552    return n;
3553 }
3554
3555 static Eina_Bool
3556 _idle_process(void *data, Eina_Bool *wakeup)
3557 {
3558    Widget_Data *wd = data;
3559
3560    //xxx
3561    //static double q_start = 0.0;
3562    //if (q_start == 0.0) q_start = ecore_time_get();
3563    //xxx
3564    if (_queue_process(wd) > 0) *wakeup = EINA_TRUE;
3565    if (!wd->queue)
3566      {
3567         //xxx
3568         //printf("PROCESS TIME: %3.3f\n", ecore_time_get() - q_start);
3569         //xxx
3570         return ECORE_CALLBACK_CANCEL;
3571      }
3572    return ECORE_CALLBACK_RENEW;
3573 }
3574
3575 static Eina_Bool
3576 _item_idle_enterer(void *data)
3577 {
3578    Widget_Data *wd = data;
3579    Eina_Bool wakeup = EINA_FALSE;
3580    Eina_Bool ok = _idle_process(data, &wakeup);
3581
3582    if (wakeup)
3583      {
3584         // wake up mainloop
3585         if (wd->calc_job) ecore_job_del(wd->calc_job);
3586         wd->calc_job = ecore_job_add(_calc_job, wd);
3587      }
3588    if (ok == ECORE_CALLBACK_CANCEL) wd->queue_idle_enterer = NULL;
3589    return ok;
3590 }
3591
3592 static void
3593 _item_queue(Widget_Data      *wd,
3594             Elm_Genlist_Item *it)
3595 {
3596    if (it->queued) return;
3597    it->queued = EINA_TRUE;
3598    wd->queue = eina_list_append(wd->queue, it);
3599 // FIXME: why does a freeze then thaw here cause some genlist
3600 // elm_genlist_item_append() to be much much slower?
3601 //   evas_event_freeze(evas_object_evas_get(wd->obj));
3602    while ((wd->queue) && ((!wd->blocks) || (!wd->blocks->next)))
3603      {
3604         if (wd->queue_idle_enterer)
3605           {
3606              ecore_idle_enterer_del(wd->queue_idle_enterer);
3607              wd->queue_idle_enterer = NULL;
3608           }
3609         _queue_process(wd);
3610      }
3611 //   evas_event_thaw(evas_object_evas_get(wd->obj));
3612 //   evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3613    if (!wd->queue_idle_enterer)
3614      wd->queue_idle_enterer = ecore_idle_enterer_add(_item_idle_enterer, wd);
3615 }
3616
3617 static void
3618 _item_move_after(Elm_Genlist_Item *it, Elm_Genlist_Item *after)
3619 {
3620    if (!it) return;
3621    if (!after) return;
3622
3623    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
3624    it->wd->reorder_deleted = EINA_TRUE;
3625    _item_block_del(it);
3626
3627    it->wd->items = eina_inlist_append_relative(it->wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(after));
3628    it->rel = after;
3629    it->rel->relcount++;
3630    it->before = EINA_FALSE;
3631    if (after->group_item) it->group_item = after->group_item;
3632    _item_queue(it->wd, it);
3633
3634    // TODO: change this to smart callback
3635    if (it->itc->func.moved)
3636      it->itc->func.moved(it->base.widget, it, after, EINA_TRUE);
3637 }
3638
3639 static void
3640 _item_move_before(Elm_Genlist_Item *it, Elm_Genlist_Item *before)
3641 {
3642    if (!it) return;
3643    if (!before) return;
3644
3645    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
3646    it->wd->reorder_deleted = EINA_TRUE;
3647    _item_block_del(it);
3648    it->wd->items = eina_inlist_prepend_relative(it->wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(before));
3649    it->rel = before;
3650    it->rel->relcount++;
3651    it->before = EINA_TRUE;
3652    if (before->group_item) it->group_item = before->group_item;
3653    _item_queue(it->wd, it);
3654
3655    // TODO: change this to smart callback
3656    if (it->itc->func.moved)
3657      it->itc->func.moved(it->base.widget, it, before, EINA_FALSE);
3658 }
3659
3660 EAPI Elm_Genlist_Item *
3661 elm_genlist_item_append(Evas_Object                  *obj,
3662                         const Elm_Genlist_Item_Class *itc,
3663                         const void                   *data,
3664                         Elm_Genlist_Item             *parent,
3665                         Elm_Genlist_Item_Flags        flags,
3666                         Evas_Smart_Cb                 func,
3667                         const void                   *func_data)
3668 {
3669    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3670    Widget_Data *wd = elm_widget_data_get(obj);
3671    if (!wd) return NULL;
3672    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3673                                     func_data);
3674    if (!it) return NULL;
3675    if (!it->parent)
3676      {
3677         if (flags & ELM_GENLIST_ITEM_GROUP)
3678           wd->group_items = eina_list_append(wd->group_items, it);
3679         wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
3680         it->rel = NULL;
3681      }
3682    else
3683      {
3684         Elm_Genlist_Item *it2 = NULL;
3685         Eina_List *ll = eina_list_last(it->parent->items);
3686         if (ll) it2 = ll->data;
3687         it->parent->items = eina_list_append(it->parent->items, it);
3688         if (!it2) it2 = it->parent;
3689         if (it2->delete_me)
3690            it2 = elm_genlist_item_prev_get(it2);
3691         wd->items =
3692           eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3693                                       EINA_INLIST_GET(it2));
3694         it->rel = it2;
3695         it->rel->relcount++;
3696      }
3697    it->before = EINA_FALSE;
3698    _item_queue(wd, it);
3699    return it;
3700 }
3701
3702 EAPI Elm_Genlist_Item *
3703 elm_genlist_item_prepend(Evas_Object                  *obj,
3704                          const Elm_Genlist_Item_Class *itc,
3705                          const void                   *data,
3706                          Elm_Genlist_Item             *parent,
3707                          Elm_Genlist_Item_Flags        flags,
3708                          Evas_Smart_Cb                 func,
3709                          const void                   *func_data)
3710 {
3711    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3712    Widget_Data *wd = elm_widget_data_get(obj);
3713    if (!wd) return NULL;
3714    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3715                                     func_data);
3716    if (!it) return NULL;
3717    if (!it->parent)
3718      {
3719         if (flags & ELM_GENLIST_ITEM_GROUP)
3720           wd->group_items = eina_list_prepend(wd->group_items, it);
3721         wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
3722         it->rel = NULL;
3723      }
3724    else
3725      {
3726         Elm_Genlist_Item *it2 = NULL;
3727         Eina_List *ll = it->parent->items;
3728         if (ll) it2 = ll->data;
3729         it->parent->items = eina_list_prepend(it->parent->items, it);
3730         if (!it2) it2 = it->parent;
3731         if (it2->delete_me)
3732            it2 = elm_genlist_item_next_get(it2);
3733         wd->items =
3734           eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3735                                        EINA_INLIST_GET(it2));
3736         it->rel = it2;
3737         it->rel->relcount++;
3738      }
3739    it->before = EINA_TRUE;
3740    _item_queue(wd, it);
3741    return it;
3742 }
3743
3744 EAPI Elm_Genlist_Item *
3745 elm_genlist_item_insert_after(Evas_Object                  *obj,
3746                               const Elm_Genlist_Item_Class *itc,
3747                               const void                   *data,
3748                               Elm_Genlist_Item             *parent,
3749                               Elm_Genlist_Item             *after,
3750                               Elm_Genlist_Item_Flags        flags,
3751                               Evas_Smart_Cb                 func,
3752                               const void                   *func_data)
3753 {
3754    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3755    EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
3756    Widget_Data *wd = elm_widget_data_get(obj);
3757    if (!wd) return NULL;
3758    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3759                                     func_data);
3760    if (!it) return NULL;
3761    /* It makes no sense to insert after in an empty list with after != NULL, something really bad is happening in your app. */
3762    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->items, NULL);
3763
3764    if (!it->parent)
3765      {
3766         if ((flags & ELM_GENLIST_ITEM_GROUP) &&
3767             (after->flags & ELM_GENLIST_ITEM_GROUP))
3768           wd->group_items = eina_list_append_relative(wd->group_items, it,
3769                                                       after);
3770      }
3771    else
3772      {
3773         it->parent->items = eina_list_append_relative(it->parent->items, it,
3774                                                       after);
3775      }
3776    wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3777                                            EINA_INLIST_GET(after));
3778    it->rel = after;
3779    it->rel->relcount++;
3780    it->before = EINA_FALSE;
3781    _item_queue(wd, it);
3782    return it;
3783 }
3784
3785 EAPI Elm_Genlist_Item *
3786 elm_genlist_item_insert_before(Evas_Object                  *obj,
3787                                const Elm_Genlist_Item_Class *itc,
3788                                const void                   *data,
3789                                Elm_Genlist_Item             *parent,
3790                                Elm_Genlist_Item             *before,
3791                                Elm_Genlist_Item_Flags        flags,
3792                                Evas_Smart_Cb                 func,
3793                                const void                   *func_data)
3794 {
3795    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3796    EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
3797    Widget_Data *wd = elm_widget_data_get(obj);
3798    if (!wd) return NULL;
3799    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3800                                     func_data);
3801    if (!it) return NULL;
3802    /* It makes no sense to insert before in an empty list with before != NULL, something really bad is happening in your app. */
3803    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->items, NULL);
3804
3805    if (!it->parent)
3806      {
3807         if ((flags & ELM_GENLIST_ITEM_GROUP) &&
3808             (before->flags & ELM_GENLIST_ITEM_GROUP))
3809           wd->group_items = eina_list_prepend_relative(wd->group_items, it,
3810                                                        before);
3811      }
3812    else
3813      {
3814         it->parent->items = eina_list_prepend_relative(it->parent->items, it,
3815                                                        before);
3816      }
3817    wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3818                                             EINA_INLIST_GET(before));
3819    it->rel = before;
3820    it->rel->relcount++;
3821    it->before = EINA_TRUE;
3822    _item_queue(wd, it);
3823    return it;
3824 }
3825
3826 EAPI void
3827 elm_genlist_clear(Evas_Object *obj)
3828 {
3829    ELM_CHECK_WIDTYPE(obj, widtype);
3830    Widget_Data *wd = elm_widget_data_get(obj);
3831    if (!wd) return;
3832    if (wd->walking > 0)
3833      {
3834         Elm_Genlist_Item *it;
3835
3836         wd->clear_me = EINA_TRUE;
3837         EINA_INLIST_FOREACH(wd->items, it)
3838           {
3839              it->delete_me = EINA_TRUE;
3840           }
3841         return;
3842      }
3843    evas_event_freeze(evas_object_evas_get(wd->obj));
3844    while (wd->items)
3845      {
3846         Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3847         it->nocache = EINA_TRUE;
3848         it->highlighted = EINA_FALSE;
3849 #ifdef ANCHOR_ITEM
3850         if (wd->anchor_item == it)
3851           {
3852              wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3853              if (!wd->anchor_item)
3854                wd->anchor_item =
3855                  ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3856           }
3857 #endif
3858         wd->items = eina_inlist_remove(wd->items, wd->items);
3859         if (it->flags & ELM_GENLIST_ITEM_GROUP)
3860           it->wd->group_items = eina_list_remove(it->wd->group_items, it);
3861         elm_widget_item_pre_notify_del(it);
3862         if (it->realized) _item_unrealize(it, EINA_FALSE);
3863         if (((wd->clear_me) || (!it->delete_me)) && (it->itc->func.del))
3864           it->itc->func.del((void *)it->base.data, it->base.widget);
3865         if (it->long_timer) ecore_timer_del(it->long_timer);
3866         if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
3867         elm_widget_item_del(it);
3868      }
3869    wd->clear_me = EINA_FALSE;
3870    wd->anchor_item = NULL;
3871    while (wd->blocks)
3872      {
3873         Item_Block *itb = (Item_Block *)(wd->blocks);
3874
3875         wd->blocks = eina_inlist_remove(wd->blocks, wd->blocks);
3876         if (itb->items) eina_list_free(itb->items);
3877         free(itb);
3878      }
3879    if (wd->calc_job)
3880      {
3881         ecore_job_del(wd->calc_job);
3882         wd->calc_job = NULL;
3883      }
3884    if (wd->queue_idle_enterer)
3885      {
3886         ecore_idle_enterer_del(wd->queue_idle_enterer);
3887         wd->queue_idle_enterer = NULL;
3888      }
3889    if (wd->must_recalc_idler)
3890      {
3891         ecore_idler_del(wd->must_recalc_idler);
3892         wd->must_recalc_idler = NULL;
3893      }
3894    if (wd->queue)
3895      {
3896         eina_list_free(wd->queue);
3897         wd->queue = NULL;
3898      }
3899    if (wd->selected)
3900      {
3901         eina_list_free(wd->selected);
3902         wd->selected = NULL;
3903      }
3904    if (wd->reorder_move_animator)
3905      {
3906         ecore_animator_del(wd->reorder_move_animator);
3907         wd->reorder_move_animator = NULL;
3908      }
3909    wd->show_item = NULL;
3910    wd->pan_x = 0;
3911    wd->pan_y = 0;
3912    wd->old_pan_y = 0;
3913    wd->minw = 0;
3914    wd->minh = 0;
3915
3916    if (wd->alpha_bg)
3917       evas_object_del(wd->alpha_bg);
3918    wd->alpha_bg = NULL;
3919
3920    if (wd->pan_smart)
3921      {
3922         evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
3923         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
3924      }
3925    _sizing_eval(obj);
3926    elm_smart_scroller_child_region_show(wd->scr, 0, 0, 0, 0);
3927    evas_event_thaw(evas_object_evas_get(wd->obj));
3928    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3929 }
3930
3931 EAPI void
3932 elm_genlist_multi_select_set(Evas_Object *obj,
3933                              Eina_Bool    multi)
3934 {
3935    ELM_CHECK_WIDTYPE(obj, widtype);
3936    Widget_Data *wd = elm_widget_data_get(obj);
3937    if (!wd) return;
3938    wd->multi = multi;
3939 }
3940
3941 EAPI Eina_Bool
3942 elm_genlist_multi_select_get(const Evas_Object *obj)
3943 {
3944    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3945    Widget_Data *wd = elm_widget_data_get(obj);
3946    if (!wd) return EINA_FALSE;
3947    return wd->multi;
3948 }
3949
3950 EAPI Elm_Genlist_Item *
3951 elm_genlist_selected_item_get(const Evas_Object *obj)
3952 {
3953    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3954    Widget_Data *wd = elm_widget_data_get(obj);
3955    if (!wd) return NULL;
3956    if (wd->selected) return wd->selected->data;
3957    return NULL;
3958 }
3959
3960 EAPI const Eina_List *
3961 elm_genlist_selected_items_get(const Evas_Object *obj)
3962 {
3963    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3964    Widget_Data *wd = elm_widget_data_get(obj);
3965    if (!wd) return NULL;
3966    return wd->selected;
3967 }
3968
3969 EAPI Eina_List *
3970 elm_genlist_realized_items_get(const Evas_Object *obj)
3971 {
3972    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3973    Widget_Data *wd = elm_widget_data_get(obj);
3974    Eina_List *list = NULL;
3975    Item_Block *itb;
3976    Eina_Bool done = EINA_FALSE;
3977    if (!wd) return NULL;
3978    EINA_INLIST_FOREACH(wd->blocks, itb)
3979      {
3980         if (itb->realized)
3981           {
3982              Eina_List *l;
3983              Elm_Genlist_Item *it;
3984
3985              done = 1;
3986              EINA_LIST_FOREACH(itb->items, l, it)
3987                {
3988                   if (it->realized) list = eina_list_append(list, it);
3989                }
3990           }
3991         else
3992           {
3993              if (done) break;
3994           }
3995      }
3996    return list;
3997 }
3998
3999 EAPI Elm_Genlist_Item *
4000 elm_genlist_at_xy_item_get(const Evas_Object *obj,
4001                            Evas_Coord         x,
4002                            Evas_Coord         y,
4003                            int               *posret)
4004 {
4005    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4006    Widget_Data *wd = elm_widget_data_get(obj);
4007    Evas_Coord ox, oy, ow, oh;
4008    Item_Block *itb;
4009    Evas_Coord lasty;
4010    if (!wd) return NULL;
4011    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
4012    lasty = oy;
4013    EINA_INLIST_FOREACH(wd->blocks, itb)
4014      {
4015         Eina_List *l;
4016         Elm_Genlist_Item *it;
4017
4018         if (!ELM_RECTS_INTERSECT(ox + itb->x - itb->wd->pan_x,
4019                                  oy + itb->y - itb->wd->pan_y,
4020                                  itb->w, itb->h, x, y, 1, 1))
4021           continue;
4022         EINA_LIST_FOREACH(itb->items, l, it)
4023           {
4024              Evas_Coord itx, ity;
4025
4026              itx = ox + itb->x + it->x - itb->wd->pan_x;
4027              ity = oy + itb->y + it->y - itb->wd->pan_y;
4028              if (ELM_RECTS_INTERSECT(itx, ity, it->w, it->h, x, y, 1, 1))
4029                {
4030                   if (posret)
4031                     {
4032                        if (y <= (ity + (it->h / 4))) *posret = -1;
4033                        else if (y >= (ity + it->h - (it->h / 4)))
4034                          *posret = 1;
4035                        else *posret = 0;
4036                     }
4037                   return it;
4038                }
4039              lasty = ity + it->h;
4040           }
4041      }
4042    if (posret)
4043      {
4044         if (y > lasty) *posret = 1;
4045         else *posret = -1;
4046      }
4047    return NULL;
4048 }
4049
4050 EAPI Elm_Genlist_Item *
4051 elm_genlist_first_item_get(const Evas_Object *obj)
4052 {
4053    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4054    Widget_Data *wd = elm_widget_data_get(obj);
4055    if (!wd) return NULL;
4056    if (!wd->items) return NULL;
4057    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
4058    while ((it) && (it->delete_me))
4059      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
4060    return it;
4061 }
4062
4063 EAPI Elm_Genlist_Item *
4064 elm_genlist_last_item_get(const Evas_Object *obj)
4065 {
4066    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4067    Widget_Data *wd = elm_widget_data_get(obj);
4068    if (!wd) return NULL;
4069    if (!wd->items) return NULL;
4070    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items->last);
4071    while ((it) && (it->delete_me))
4072      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
4073    return it;
4074 }
4075
4076 EAPI Elm_Genlist_Item *
4077 elm_genlist_item_next_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)->next);
4083         if ((it) && (!it->delete_me)) break;
4084      }
4085    return (Elm_Genlist_Item *)it;
4086 }
4087
4088 EAPI Elm_Genlist_Item *
4089 elm_genlist_item_prev_get(const Elm_Genlist_Item *it)
4090 {
4091    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4092    while (it)
4093      {
4094         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
4095         if ((it) && (!it->delete_me)) break;
4096      }
4097    return (Elm_Genlist_Item *)it;
4098 }
4099
4100 EAPI Evas_Object *
4101 elm_genlist_item_genlist_get(const Elm_Genlist_Item *it)
4102 {
4103    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4104    return it->base.widget;
4105 }
4106
4107 EAPI Elm_Genlist_Item *
4108 elm_genlist_item_parent_get(const Elm_Genlist_Item *it)
4109 {
4110    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4111    return it->parent;
4112 }
4113
4114 EAPI void
4115 elm_genlist_item_subitems_clear(Elm_Genlist_Item *it)
4116 {
4117    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4118    Elm_Genlist_Item *it2;
4119    Evas_Coord y, h;
4120
4121    if (!it->wd->effect_mode || !it->wd->move_effect_mode)
4122       _item_subitems_clear(it);
4123    else
4124      {
4125         if ((!it->wd->item_moving_effect_timer) && (it->flags != ELM_GENLIST_ITEM_GROUP) &&
4126              it->wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE    )
4127           {
4128              it->wd->expand_item = it;
4129              _item_flip_effect_show(it);
4130              evas_object_geometry_get(it->base.view, NULL, &y, NULL, &h);
4131              it->wd->expand_item_end = y + h;
4132
4133               it2= it;
4134              do {
4135                   it2 = elm_genlist_item_next_get(it2);
4136                   if (!it2) break;
4137              } while (it2->expanded_depth > it->expanded_depth);
4138              if (it2)
4139                 it->wd->expand_item_gap = it->wd->expand_item_end - it2->old_scrl_y;
4140              else
4141                 it->wd->expand_item_gap = 0;
4142
4143              evas_object_raise(it->wd->alpha_bg);
4144              evas_object_show(it->wd->alpha_bg);
4145
4146              it->wd->start_time = current_time_get();
4147              it->wd->item_moving_effect_timer = ecore_animator_add(_item_moving_effect_timer_cb, it->wd);
4148           }
4149         else
4150            _item_subitems_clear(it);
4151      }
4152 }
4153
4154 EAPI void
4155 elm_genlist_item_selected_set(Elm_Genlist_Item *it,
4156                               Eina_Bool         selected)
4157 {
4158    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4159    Widget_Data *wd = elm_widget_data_get(it->base.widget);
4160    if (!wd) return;
4161    if ((it->delete_me) || (it->disabled)) return;
4162    selected = !!selected;
4163    if (it->selected == selected) return;
4164
4165    if (selected)
4166      {
4167         if (!wd->multi)
4168           {
4169              while (wd->selected)
4170                _item_unselect(wd->selected->data);
4171           }
4172         _item_highlight(it);
4173         _item_select(it);
4174      }
4175    else
4176      _item_unselect(it);
4177 }
4178
4179 EAPI Eina_Bool
4180 elm_genlist_item_selected_get(const Elm_Genlist_Item *it)
4181 {
4182    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4183    return it->selected;
4184 }
4185
4186 EAPI void
4187 elm_genlist_item_expanded_set(Elm_Genlist_Item *it,
4188                               Eina_Bool         expanded)
4189 {
4190    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4191    if (it->flags != ELM_GENLIST_ITEM_SUBITEMS) return;
4192    if (it->expanded == expanded) return;
4193    it->expanded = expanded;
4194    it->wd->expand_item = it;
4195
4196    if (it->wd->effect_mode && !it->wd->alpha_bg)
4197       it->wd->alpha_bg = _create_tray_alpha_bg(it->base.widget);
4198
4199    if (it->expanded)
4200      {
4201         it->wd->auto_scrolled = EINA_FALSE;
4202         it->wd->move_effect_mode = ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND;
4203         if (it->realized)
4204           edje_object_signal_emit(it->base.view, "elm,state,expanded", "elm");
4205         evas_object_smart_callback_call(it->base.widget, "expanded", it);
4206      }
4207    else
4208      {
4209         it->wd->move_effect_mode = ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT;
4210         if (it->realized)
4211           edje_object_signal_emit(it->base.view, "elm,state,contracted", "elm");
4212         evas_object_smart_callback_call(it->base.widget, "contracted", it);
4213      }
4214 }
4215
4216 EAPI Eina_Bool
4217 elm_genlist_item_expanded_get(const Elm_Genlist_Item *it)
4218 {
4219    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4220    return it->expanded;
4221 }
4222
4223 EAPI int
4224 elm_genlist_item_expanded_depth_get(const Elm_Genlist_Item *it)
4225 {
4226    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, 0);
4227    return it->expanded_depth;
4228 }
4229
4230 EAPI void
4231 elm_genlist_item_disabled_set(Elm_Genlist_Item *it,
4232                               Eina_Bool         disabled)
4233 {
4234    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4235    Eina_List *l;
4236    Evas_Object *obj;
4237    if (it->disabled == disabled) return;
4238    if (it->delete_me) return;
4239    it->disabled = disabled;
4240    if (it->selected)
4241      elm_genlist_item_selected_set(it, EINA_FALSE);
4242    if (it->realized)
4243      {
4244         if (it->disabled)
4245           {
4246              edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
4247              if (it->edit_obj)
4248                edje_object_signal_emit(it->edit_obj, "elm,state,disabled", "elm");
4249           }
4250         else
4251           {
4252              edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
4253              if (it->edit_obj)
4254                edje_object_signal_emit(it->edit_obj, "elm,state,enabled", "elm");
4255           }
4256         EINA_LIST_FOREACH(it->icon_objs, l, obj)
4257            elm_widget_disabled_set(obj, disabled);
4258      }
4259 }
4260
4261 EAPI Eina_Bool
4262 elm_genlist_item_disabled_get(const Elm_Genlist_Item *it)
4263 {
4264    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4265    if (it->delete_me) return EINA_FALSE;
4266    return it->disabled;
4267 }
4268
4269 EAPI void
4270 elm_genlist_item_display_only_set(Elm_Genlist_Item *it,
4271                                   Eina_Bool         display_only)
4272 {
4273    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4274    if (it->display_only == display_only) return;
4275    if (it->delete_me) return;
4276    it->display_only = display_only;
4277    it->mincalcd = EINA_FALSE;
4278    it->updateme = EINA_TRUE;
4279    if (it->block) it->block->updateme = EINA_TRUE;
4280    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4281    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4282 }
4283
4284 EAPI Eina_Bool
4285 elm_genlist_item_display_only_get(const Elm_Genlist_Item *it)
4286 {
4287    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4288    if (it->delete_me) return EINA_FALSE;
4289    return it->display_only;
4290 }
4291
4292 EAPI void
4293 elm_genlist_item_show(Elm_Genlist_Item *it)
4294 {
4295    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4296    Evas_Coord gith = 0;
4297    if (it->delete_me) return;
4298    if ((it->queued) || (!it->mincalcd))
4299      {
4300         it->wd->show_item = it;
4301         it->wd->bring_in = EINA_TRUE;
4302         it->showme = EINA_TRUE;
4303         return;
4304      }
4305    if (it->wd->show_item)
4306      {
4307         it->wd->show_item->showme = EINA_FALSE;
4308         it->wd->show_item = NULL;
4309      }
4310    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4311      gith = it->group_item->h;
4312    elm_smart_scroller_child_region_show(it->wd->scr,
4313                                         it->x + it->block->x,
4314                                         it->y + it->block->y - gith,
4315                                         it->block->w, it->h);
4316 }
4317
4318 EAPI void
4319 elm_genlist_item_bring_in(Elm_Genlist_Item *it)
4320 {
4321    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4322    Evas_Coord gith = 0;
4323    if (it->delete_me) return;
4324    if ((it->queued) || (!it->mincalcd))
4325      {
4326         it->wd->show_item = it;
4327         it->wd->bring_in = EINA_TRUE;
4328         it->showme = EINA_TRUE;
4329         return;
4330      }
4331    if (it->wd->show_item)
4332      {
4333         it->wd->show_item->showme = EINA_FALSE;
4334         it->wd->show_item = NULL;
4335      }
4336    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4337      gith = it->group_item->h;
4338    elm_smart_scroller_region_bring_in(it->wd->scr,
4339                                       it->x + it->block->x,
4340                                       it->y + it->block->y - gith,
4341                                       it->block->w, it->h);
4342 }
4343
4344 EAPI void
4345 elm_genlist_item_top_show(Elm_Genlist_Item *it)
4346 {
4347    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4348    Evas_Coord ow, oh;
4349    Evas_Coord gith = 0;
4350
4351    if (it->delete_me) return;
4352    if ((it->queued) || (!it->mincalcd))
4353      {
4354         it->wd->show_item = it;
4355         it->wd->bring_in = EINA_TRUE;
4356         it->showme = EINA_TRUE;
4357         return;
4358      }
4359    if (it->wd->show_item)
4360      {
4361         it->wd->show_item->showme = EINA_FALSE;
4362         it->wd->show_item = NULL;
4363      }
4364    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4365    if (it->group_item) gith = it->group_item->h;
4366    elm_smart_scroller_child_region_show(it->wd->scr,
4367                                         it->x + it->block->x,
4368                                         it->y + it->block->y - gith,
4369                                         it->block->w, oh);
4370 }
4371
4372 EAPI void
4373 elm_genlist_item_top_bring_in(Elm_Genlist_Item *it)
4374 {
4375    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4376    Evas_Coord ow, oh;
4377    Evas_Coord gith = 0;
4378
4379    if (it->delete_me) return;
4380    if ((it->queued) || (!it->mincalcd))
4381      {
4382         it->wd->show_item = it;
4383         it->wd->bring_in = EINA_TRUE;
4384         it->showme = EINA_TRUE;
4385         return;
4386      }
4387    if (it->wd->show_item)
4388      {
4389         it->wd->show_item->showme = EINA_FALSE;
4390         it->wd->show_item = NULL;
4391      }
4392    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4393    if (it->group_item) gith = it->group_item->h;
4394    elm_smart_scroller_region_bring_in(it->wd->scr,
4395                                       it->x + it->block->x,
4396                                       it->y + it->block->y - gith,
4397                                       it->block->w, oh);
4398 }
4399
4400 EAPI void
4401 elm_genlist_item_middle_show(Elm_Genlist_Item *it)
4402 {
4403    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4404    Evas_Coord ow, oh;
4405
4406    if (it->delete_me) return;
4407    if ((it->queued) || (!it->mincalcd))
4408      {
4409         it->wd->show_item = it;
4410         it->wd->bring_in = EINA_TRUE;
4411         it->showme = EINA_TRUE;
4412         return;
4413      }
4414    if (it->wd->show_item)
4415      {
4416         it->wd->show_item->showme = EINA_FALSE;
4417         it->wd->show_item = NULL;
4418      }
4419    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4420    elm_smart_scroller_child_region_show(it->wd->scr,
4421                                         it->x + it->block->x,
4422                                         it->y + it->block->y - oh / 2 +
4423                                         it->h / 2, it->block->w, oh);
4424 }
4425
4426 EAPI void
4427 elm_genlist_item_middle_bring_in(Elm_Genlist_Item *it)
4428 {
4429    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4430    Evas_Coord ow, oh;
4431
4432    if (it->delete_me) return;
4433    if ((it->queued) || (!it->mincalcd))
4434      {
4435         it->wd->show_item = it;
4436         it->wd->bring_in = EINA_TRUE;
4437         it->showme = EINA_TRUE;
4438         return;
4439      }
4440    if (it->wd->show_item)
4441      {
4442         it->wd->show_item->showme = EINA_FALSE;
4443         it->wd->show_item = NULL;
4444      }
4445    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4446    elm_smart_scroller_region_bring_in(it->wd->scr,
4447                                       it->x + it->block->x,
4448                                       it->y + it->block->y - oh / 2 + it->h / 2,
4449                                       it->block->w, oh);
4450 }
4451
4452 EAPI void
4453 elm_genlist_item_del(Elm_Genlist_Item *it)
4454 {
4455    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4456    if ((it->relcount > 0) || (it->walking > 0))
4457      {
4458         elm_widget_item_pre_notify_del(it);
4459         elm_genlist_item_subitems_clear(it);
4460         it->delete_me = EINA_TRUE;
4461         if (it->wd->show_item == it) it->wd->show_item = NULL;
4462         if (it->selected)
4463           it->wd->selected = eina_list_remove(it->wd->selected,
4464                                               it);
4465         if (it->block)
4466           {
4467              if (it->realized) _item_unrealize(it, EINA_FALSE);
4468              it->block->changed = EINA_TRUE;
4469              if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
4470              it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
4471           }
4472         if (it->itc->func.del)
4473           it->itc->func.del((void *)it->base.data, it->base.widget);
4474         return;
4475      }
4476    _item_del(it);
4477 }
4478
4479 EAPI void
4480 elm_genlist_item_data_set(Elm_Genlist_Item *it,
4481                           const void       *data)
4482 {
4483    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4484    elm_widget_item_data_set(it, data);
4485    elm_genlist_item_update(it);
4486 }
4487
4488 EAPI void *
4489 elm_genlist_item_data_get(const Elm_Genlist_Item *it)
4490 {
4491    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4492    return elm_widget_item_data_get(it);
4493 }
4494
4495 EAPI void
4496 elm_genlist_item_icons_orphan(Elm_Genlist_Item *it)
4497 {
4498    Evas_Object *icon;
4499    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4500    EINA_LIST_FREE(it->icon_objs, icon)
4501      {
4502         elm_widget_sub_object_del(it->base.widget, icon);
4503         evas_object_smart_member_del(icon);
4504         evas_object_hide(icon);
4505      }
4506 }
4507
4508 EAPI const Evas_Object *
4509 elm_genlist_item_object_get(const Elm_Genlist_Item *it)
4510 {
4511    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4512    return it->base.view;
4513 }
4514
4515 EAPI void
4516 elm_genlist_item_update(Elm_Genlist_Item *it)
4517 {
4518    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4519    if (!it->block) return;
4520    if (it->delete_me) return;
4521    it->mincalcd = EINA_FALSE;
4522    it->updateme = EINA_TRUE;
4523    it->block->updateme = EINA_TRUE;
4524    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4525    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4526    it->defer_unrealize = EINA_FALSE;
4527 }
4528
4529 EAPI void
4530 elm_genlist_item_item_class_update(Elm_Genlist_Item             *it,
4531                                    const Elm_Genlist_Item_Class *itc)
4532 {
4533    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4534    if (!it->block) return;
4535    EINA_SAFETY_ON_NULL_RETURN(itc);
4536    if (it->delete_me) return;
4537    it->itc = itc;
4538    it->nocache = EINA_TRUE;
4539    elm_genlist_item_update(it);
4540 }
4541
4542 EAPI const Elm_Genlist_Item_Class *
4543 elm_genlist_item_item_class_get(const Elm_Genlist_Item *it)
4544 {
4545    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4546    if (it->delete_me) return NULL;
4547    return it->itc;
4548 }
4549 static Evas_Object *
4550 _elm_genlist_item_label_create(void        *data,
4551                                Evas_Object *obj,
4552                                void        *item __UNUSED__)
4553 {
4554    Evas_Object *label = elm_label_add(obj);
4555    if (!label)
4556      return NULL;
4557    elm_object_style_set(label, "tooltip");
4558    elm_object_text_set(label, data);
4559    return label;
4560 }
4561
4562 static void
4563 _elm_genlist_item_label_del_cb(void        *data,
4564                                Evas_Object *obj __UNUSED__,
4565                                void        *event_info __UNUSED__)
4566 {
4567    eina_stringshare_del(data);
4568 }
4569
4570 EAPI void
4571 elm_genlist_item_tooltip_text_set(Elm_Genlist_Item *item,
4572                                   const char       *text)
4573 {
4574    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4575    text = eina_stringshare_add(text);
4576    elm_genlist_item_tooltip_content_cb_set(item, _elm_genlist_item_label_create,
4577                                            text,
4578                                            _elm_genlist_item_label_del_cb);
4579 }
4580
4581 EAPI void
4582 elm_genlist_item_tooltip_content_cb_set(Elm_Genlist_Item           *item,
4583                                         Elm_Tooltip_Item_Content_Cb func,
4584                                         const void                 *data,
4585                                         Evas_Smart_Cb               del_cb)
4586 {
4587    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
4588
4589    if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
4590      return;
4591
4592    if (item->tooltip.del_cb)
4593      item->tooltip.del_cb((void *)item->tooltip.data,
4594                           item->base.widget, item);
4595
4596    item->tooltip.content_cb = func;
4597    item->tooltip.data = data;
4598    item->tooltip.del_cb = del_cb;
4599
4600    if (item->base.view)
4601      {
4602         elm_widget_item_tooltip_content_cb_set(item,
4603                                                item->tooltip.content_cb,
4604                                                item->tooltip.data, NULL);
4605         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
4606      }
4607
4608    return;
4609
4610 error:
4611    if (del_cb) del_cb((void *)data, NULL, NULL);
4612 }
4613
4614 EAPI void
4615 elm_genlist_item_tooltip_unset(Elm_Genlist_Item *item)
4616 {
4617    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4618    if ((item->base.view) && (item->tooltip.content_cb))
4619      elm_widget_item_tooltip_unset(item);
4620
4621    if (item->tooltip.del_cb)
4622      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
4623    item->tooltip.del_cb = NULL;
4624    item->tooltip.content_cb = NULL;
4625    item->tooltip.data = NULL;
4626    if (item->tooltip.style)
4627      elm_genlist_item_tooltip_style_set(item, NULL);
4628 }
4629
4630 EAPI void
4631 elm_genlist_item_tooltip_style_set(Elm_Genlist_Item *item,
4632                                    const char       *style)
4633 {
4634    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4635    eina_stringshare_replace(&item->tooltip.style, style);
4636    if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
4637 }
4638
4639 EAPI const char *
4640 elm_genlist_item_tooltip_style_get(const Elm_Genlist_Item *item)
4641 {
4642    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4643    return item->tooltip.style;
4644 }
4645
4646 EAPI void
4647 elm_genlist_item_cursor_set(Elm_Genlist_Item *item,
4648                             const char       *cursor)
4649 {
4650    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4651    eina_stringshare_replace(&item->mouse_cursor, cursor);
4652    if (item->base.view) elm_widget_item_cursor_set(item, cursor);
4653 }
4654
4655 EAPI const char *
4656 elm_genlist_item_cursor_get(const Elm_Genlist_Item *item)
4657 {
4658    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4659    return elm_widget_item_cursor_get(item);
4660 }
4661
4662 EAPI void
4663 elm_genlist_item_cursor_unset(Elm_Genlist_Item *item)
4664 {
4665    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4666    if (!item->mouse_cursor)
4667      return;
4668
4669    if (item->base.view)
4670      elm_widget_item_cursor_unset(item);
4671
4672    eina_stringshare_del(item->mouse_cursor);
4673    item->mouse_cursor = NULL;
4674 }
4675
4676 EAPI void
4677 elm_genlist_item_cursor_style_set(Elm_Genlist_Item *item,
4678                                   const char       *style)
4679 {
4680    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4681    elm_widget_item_cursor_style_set(item, style);
4682 }
4683
4684 EAPI const char *
4685 elm_genlist_item_cursor_style_get(const Elm_Genlist_Item *item)
4686 {
4687    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4688    return elm_widget_item_cursor_style_get(item);
4689 }
4690
4691 EAPI void
4692 elm_genlist_item_cursor_engine_only_set(Elm_Genlist_Item *item,
4693                                         Eina_Bool         engine_only)
4694 {
4695    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4696    elm_widget_item_cursor_engine_only_set(item, engine_only);
4697 }
4698
4699 EAPI Eina_Bool
4700 elm_genlist_item_cursor_engine_only_get(const Elm_Genlist_Item *item)
4701 {
4702    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
4703    return elm_widget_item_cursor_engine_only_get(item);
4704 }
4705
4706 EAPI void
4707 elm_genlist_horizontal_mode_set(Evas_Object  *obj,
4708                                 Elm_List_Mode mode)
4709 {
4710    ELM_CHECK_WIDTYPE(obj, widtype);
4711    Widget_Data *wd = elm_widget_data_get(obj);
4712    if (!wd) return;
4713    if (wd->mode == mode) return;
4714    wd->mode = mode;
4715    _sizing_eval(obj);
4716 }
4717
4718 EAPI Elm_List_Mode
4719 elm_genlist_horizontal_mode_get(const Evas_Object *obj)
4720 {
4721    ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
4722    Widget_Data *wd = elm_widget_data_get(obj);
4723    if (!wd) return ELM_LIST_LAST;
4724    return wd->mode;
4725 }
4726
4727 EAPI void
4728 elm_genlist_always_select_mode_set(Evas_Object *obj,
4729                                    Eina_Bool    always_select)
4730 {
4731    ELM_CHECK_WIDTYPE(obj, widtype);
4732    Widget_Data *wd = elm_widget_data_get(obj);
4733    if (!wd) return;
4734    wd->always_select = always_select;
4735 }
4736
4737 EAPI Eina_Bool
4738 elm_genlist_always_select_mode_get(const Evas_Object *obj)
4739 {
4740    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4741    Widget_Data *wd = elm_widget_data_get(obj);
4742    if (!wd) return EINA_FALSE;
4743    return wd->always_select;
4744 }
4745
4746 EAPI void
4747 elm_genlist_no_select_mode_set(Evas_Object *obj,
4748                                Eina_Bool    no_select)
4749 {
4750    ELM_CHECK_WIDTYPE(obj, widtype);
4751    Widget_Data *wd = elm_widget_data_get(obj);
4752    if (!wd) return;
4753    wd->no_select = no_select;
4754 }
4755
4756 EAPI Eina_Bool
4757 elm_genlist_no_select_mode_get(const Evas_Object *obj)
4758 {
4759    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4760    Widget_Data *wd = elm_widget_data_get(obj);
4761    if (!wd) return EINA_FALSE;
4762    return wd->no_select;
4763 }
4764
4765 EAPI void
4766 elm_genlist_compress_mode_set(Evas_Object *obj,
4767                               Eina_Bool    compress)
4768 {
4769    ELM_CHECK_WIDTYPE(obj, widtype);
4770    Widget_Data *wd = elm_widget_data_get(obj);
4771    if (!wd) return;
4772    wd->compress = compress;
4773 }
4774
4775 EAPI Eina_Bool
4776 elm_genlist_compress_mode_get(const Evas_Object *obj)
4777 {
4778    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4779    Widget_Data *wd = elm_widget_data_get(obj);
4780    if (!wd) return EINA_FALSE;
4781    return wd->compress;
4782 }
4783
4784 EAPI void
4785 elm_genlist_height_for_width_mode_set(Evas_Object *obj,
4786                                       Eina_Bool    height_for_width)
4787 {
4788    ELM_CHECK_WIDTYPE(obj, widtype);
4789    Widget_Data *wd = elm_widget_data_get(obj);
4790    if (!wd) return;
4791    wd->height_for_width = !!height_for_width;
4792    if (wd->height_for_width)
4793      {
4794         elm_genlist_homogeneous_set(obj, EINA_FALSE);
4795         elm_genlist_compress_mode_set(obj, EINA_TRUE);
4796      }
4797 }
4798
4799 EAPI Eina_Bool
4800 elm_genlist_height_for_width_mode_get(const Evas_Object *obj)
4801 {
4802    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4803    Widget_Data *wd = elm_widget_data_get(obj);
4804    if (!wd) return EINA_FALSE;
4805    return wd->height_for_width;
4806 }
4807
4808 EAPI void
4809 elm_genlist_bounce_set(Evas_Object *obj,
4810                        Eina_Bool    h_bounce,
4811                        Eina_Bool    v_bounce)
4812 {
4813    ELM_CHECK_WIDTYPE(obj, widtype);
4814    Widget_Data *wd = elm_widget_data_get(obj);
4815    if (!wd) return;
4816    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
4817 }
4818
4819 EAPI void
4820 elm_genlist_bounce_get(const Evas_Object *obj,
4821                        Eina_Bool         *h_bounce,
4822                        Eina_Bool         *v_bounce)
4823 {
4824    ELM_CHECK_WIDTYPE(obj, widtype);
4825    Widget_Data *wd = elm_widget_data_get(obj);
4826    if (!wd) return;
4827    elm_smart_scroller_bounce_allow_get(obj, h_bounce, v_bounce);
4828 }
4829
4830 EAPI void
4831 elm_genlist_homogeneous_set(Evas_Object *obj,
4832                             Eina_Bool    homogeneous)
4833 {
4834    ELM_CHECK_WIDTYPE(obj, widtype);
4835    Widget_Data *wd = elm_widget_data_get(obj);
4836    if (!wd) return;
4837    if (homogeneous) elm_genlist_compress_mode_set(obj, EINA_TRUE);
4838    wd->homogeneous = homogeneous;
4839 }
4840
4841 EAPI Eina_Bool
4842 elm_genlist_homogeneous_get(const Evas_Object *obj)
4843 {
4844    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4845    Widget_Data *wd = elm_widget_data_get(obj);
4846    if (!wd) return EINA_FALSE;
4847    return wd->homogeneous;
4848 }
4849
4850 EAPI void
4851 elm_genlist_block_count_set(Evas_Object *obj,
4852                             int          n)
4853 {
4854    ELM_CHECK_WIDTYPE(obj, widtype);
4855    Widget_Data *wd = elm_widget_data_get(obj);
4856    if (!wd) return;
4857    wd->max_items_per_block = n;
4858    wd->item_cache_max = wd->max_items_per_block * 2;
4859    _item_cache_clean(wd);
4860 }
4861
4862 EAPI int
4863 elm_genlist_block_count_get(const Evas_Object *obj)
4864 {
4865    ELM_CHECK_WIDTYPE(obj, widtype) 0;
4866    Widget_Data *wd = elm_widget_data_get(obj);
4867    if (!wd) return 0;
4868    return wd->max_items_per_block;
4869 }
4870
4871 EAPI void
4872 elm_genlist_longpress_timeout_set(Evas_Object *obj,
4873                                   double       timeout)
4874 {
4875    ELM_CHECK_WIDTYPE(obj, widtype);
4876    Widget_Data *wd = elm_widget_data_get(obj);
4877    if (!wd) return;
4878    wd->longpress_timeout = timeout;
4879 }
4880
4881 EAPI double
4882 elm_genlist_longpress_timeout_get(const Evas_Object *obj)
4883 {
4884    ELM_CHECK_WIDTYPE(obj, widtype) 0;
4885    Widget_Data *wd = elm_widget_data_get(obj);
4886    if (!wd) return 0;
4887    return wd->longpress_timeout;
4888 }
4889
4890 EAPI void
4891 elm_genlist_scroller_policy_set(Evas_Object        *obj,
4892                                 Elm_Scroller_Policy policy_h,
4893                                 Elm_Scroller_Policy policy_v)
4894 {
4895    ELM_CHECK_WIDTYPE(obj, widtype);
4896    Widget_Data *wd = elm_widget_data_get(obj);
4897    if (!wd) return;
4898    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
4899        (policy_v >= ELM_SCROLLER_POLICY_LAST))
4900      return;
4901    if (wd->scr)
4902      elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
4903 }
4904
4905 EAPI void
4906 elm_genlist_scroller_policy_get(const Evas_Object   *obj,
4907                                 Elm_Scroller_Policy *policy_h,
4908                                 Elm_Scroller_Policy *policy_v)
4909 {
4910    ELM_CHECK_WIDTYPE(obj, widtype);
4911    Widget_Data *wd = elm_widget_data_get(obj);
4912    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
4913    if ((!wd) || (!wd->scr)) return;
4914    elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
4915    if (policy_h) *policy_h = (Elm_Scroller_Policy)s_policy_h;
4916    if (policy_v) *policy_v = (Elm_Scroller_Policy)s_policy_v;
4917 }
4918
4919 EAPI void
4920 elm_genlist_realized_items_update(Evas_Object *obj)
4921 {
4922    ELM_CHECK_WIDTYPE(obj, widtype);
4923
4924    Eina_List *list, *l;
4925    Elm_Genlist_Item *it;
4926
4927    list = elm_genlist_realized_items_get(obj);
4928    EINA_LIST_FOREACH(list, l, it)
4929      elm_genlist_item_update(it);
4930 }
4931
4932 /**
4933  * Set genlist item mode
4934  *
4935  * @param item The genlist item
4936  * @param mode Mode name
4937  * @param mode_set Boolean to define set or unset mode.
4938  *
4939  * @ingroup Genlist
4940  */
4941 EAPI void
4942 elm_genlist_item_mode_set(Elm_Genlist_Item *it,
4943                           const char       *mode_type,
4944                           Eina_Bool         mode_set)
4945 {
4946    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4947    Widget_Data *wd = it->wd;
4948    Eina_List *l;
4949    Elm_Genlist_Item *it2;
4950
4951    if (!wd) return;
4952    if (!mode_type) return;
4953    if ((it->delete_me) || (it->disabled)) return;
4954    if (wd->edit_mode) return;
4955
4956    if ((wd->mode_item == it) &&
4957        (!strcmp(mode_type, wd->mode_type)) &&
4958        (mode_set))
4959       return;
4960    if (!it->itc->mode_item_style) return;
4961
4962    if (wd->multi)
4963      {
4964         EINA_LIST_FOREACH(wd->selected, l, it2)
4965           if (it2->realized)
4966             elm_genlist_item_selected_set(it2, EINA_FALSE);
4967      }
4968    else
4969      {
4970         it2 = elm_genlist_selected_item_get(wd->obj);
4971         if ((it2) && (it2->realized))
4972           elm_genlist_item_selected_set(it2, EINA_FALSE);
4973      }
4974
4975    if (((wd->mode_type) && (strcmp(mode_type, wd->mode_type))) ||
4976        (mode_set) ||
4977        ((it == wd->mode_item) && (!mode_set)))
4978      _item_mode_unset(wd);
4979
4980    eina_stringshare_replace(&wd->mode_type, mode_type);
4981    if (mode_set) _item_mode_set(it);
4982 }
4983
4984 /**
4985  * Get active genlist mode type
4986  *
4987  * @param obj The genlist object
4988  *
4989  * @ingroup Genlist
4990  */
4991 EAPI const char *
4992 elm_genlist_mode_get(const Evas_Object *obj)
4993 {
4994    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4995    Widget_Data *wd = elm_widget_data_get(obj);
4996    if (!wd) return NULL;
4997    return wd->mode_type;
4998 }
4999
5000 /**
5001  * Get active genlist mode item
5002  *
5003  * @param obj The genlist object
5004  *
5005  * @ingroup Genlist
5006  */
5007 EAPI const Elm_Genlist_Item *
5008 elm_genlist_mode_item_get(const Evas_Object *obj)
5009 {
5010    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5011    Widget_Data *wd = elm_widget_data_get(obj);
5012    if (!wd) return NULL;
5013    return wd->mode_item;
5014 }
5015
5016 EAPI void
5017 elm_genlist_reorder_mode_set(Evas_Object *obj,
5018                              Eina_Bool    reorder_mode)
5019 {
5020    ELM_CHECK_WIDTYPE(obj, widtype);
5021    Widget_Data *wd = elm_widget_data_get(obj);
5022    if (!wd) return;
5023    wd->reorder_mode = reorder_mode;
5024 }
5025
5026 EAPI Eina_Bool
5027 elm_genlist_reorder_mode_get(const Evas_Object *obj)
5028 {
5029    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5030    Widget_Data *wd = elm_widget_data_get(obj);
5031    if (!wd) return EINA_FALSE;
5032    return wd->reorder_mode;
5033 }
5034
5035 EAPI void
5036 elm_genlist_item_move_after(Elm_Genlist_Item *it __UNUSED__, Elm_Genlist_Item *after __UNUSED__)
5037 {
5038    return;
5039 }
5040
5041 EAPI void
5042 elm_genlist_item_move_before(Elm_Genlist_Item *it __UNUSED__, Elm_Genlist_Item *before __UNUSED__)
5043 {
5044    return;
5045 }
5046
5047 EAPI void
5048 elm_genlist_effect_set(const Evas_Object *obj, Eina_Bool emode)
5049 {
5050    ELM_CHECK_WIDTYPE(obj, widtype);
5051    Widget_Data *wd = elm_widget_data_get(obj);
5052    if (!wd) return;
5053    wd->effect_mode = emode;
5054    //   wd->point_rect = evas_object_rectangle_add(evas_object_evas_get(wd->obj));
5055    //   evas_object_resize(wd->point_rect, 10, 25);
5056    //   evas_object_color_set(wd->point_rect, 255, 0, 0, 130);
5057    //   evas_object_show(wd->point_rect);
5058    //   evas_object_hide(wd->point_rect);
5059 }
5060
5061 static Evas_Object*
5062 _create_tray_alpha_bg(const Evas_Object *obj)
5063 {
5064    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5065    Widget_Data *wd = elm_widget_data_get(obj);
5066    if (!wd) return NULL;
5067
5068    Evas_Object *bg = NULL;
5069    Evas_Coord ox, oy, ow, oh;
5070
5071    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
5072    bg  =  evas_object_rectangle_add(evas_object_evas_get(wd->obj));
5073    evas_object_color_set(bg,0,0,0,0);
5074    evas_object_resize(bg , ow, oh);
5075    evas_object_move(bg , ox, oy);
5076    evas_object_show(bg);
5077    evas_object_hide(bg);
5078    return bg ;
5079 }
5080
5081 static unsigned int
5082 current_time_get()
5083 {
5084    struct timeval timev;
5085
5086    gettimeofday(&timev, NULL);
5087    return ((timev.tv_sec * 1000) + ((timev.tv_usec) / 1000));
5088 }
5089
5090 // added for item moving animation.
5091 static Eina_Bool
5092 _item_moving_effect_timer_cb(void *data)
5093 {
5094    Widget_Data *wd = data;
5095    if (!wd) return EINA_FALSE;
5096    Item_Block *itb;
5097    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh;
5098    Elm_Genlist_Item *it = NULL, *it2;
5099    const Eina_List *l;
5100    double time = 0.3, t;
5101    int y, dy;
5102    Eina_Bool check, end = EINA_FALSE;
5103    int in = 0;
5104
5105    t = ((0.0 > (t = current_time_get() - wd->start_time)) ? 0.0 : t) / 1000;
5106
5107    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
5108    evas_output_viewport_get(evas_object_evas_get(wd->pan_smart), &cvx, &cvy, &cvw, &cvh);
5109    if (t > time) end = EINA_TRUE;
5110
5111    it2 = elm_genlist_item_next_get(wd->expand_item);
5112    while (it2)
5113      {
5114         if (wd->expand_item->expanded_depth >= it2->expanded_depth) break;
5115         it2 = elm_genlist_item_next_get(it2);
5116      }
5117    dy = 0;
5118    if (it2)
5119      {
5120         if (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND)
5121           dy = it2->scrl_y - it2->old_scrl_y;
5122         else if (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT)
5123           dy = wd->expand_item_gap;
5124
5125         if (t <= time)
5126           {
5127              y = ((1 - (1 - (t / time)) * (1 - (t /time))) * dy);
5128           }
5129         else
5130           {
5131              end = EINA_TRUE;
5132              y = dy;
5133           }
5134
5135         check = EINA_FALSE;
5136         EINA_INLIST_FOREACH(wd->blocks, itb)
5137           {
5138              itb->w = wd->minw;
5139              if (ELM_RECTS_INTERSECT(itb->x - wd->pan_x + ox,
5140                                      itb->y - wd->pan_y + oy,
5141                                      itb->w, itb->h,
5142                                      cvx, cvy, cvw, cvh))
5143                {
5144                   EINA_LIST_FOREACH(itb->items, l, it)
5145                     {
5146                        if (it == it2) check = EINA_TRUE;
5147                        if (!check) continue;
5148
5149                        if (!it->old_scrl_y)
5150                          it->old_scrl_y  = it->scrl_y;
5151                        if (it->old_scrl_y + y < oy + oh)
5152                          {
5153                             if (!it->realized) _item_realize(it, in, 0);
5154                          }
5155                        if (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE && it->old_scrl_y + y < it->scrl_y)
5156                          it->old_scrl_y = it->scrl_y - y;
5157                        in++;
5158
5159                        if (wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE ||
5160                            (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE && it->old_scrl_y + y >= it->scrl_y))
5161                          {
5162                             if (wd->edit_mode) _effect_item_controls(it, it->scrl_x, it->old_scrl_y + y);
5163                             else
5164                               {
5165                                  evas_object_resize(it->base.view, it->w, it->h);
5166                                  evas_object_move(it->base.view, it->scrl_x, it->old_scrl_y + y);
5167                                  evas_object_show(it->base.view);
5168                                  evas_object_raise(it->base.view);
5169                               }
5170
5171                             if (it->group_item) evas_object_raise(it->group_item->base.view);
5172                          }
5173                     }
5174                }
5175           }
5176
5177         if (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND)
5178           {
5179              it = elm_genlist_item_prev_get(it2);
5180              while (it)
5181                {
5182                   if (it->expanded_depth <= it2->expanded_depth) break;
5183                   if ((it->scrl_y < it2->old_scrl_y + y) && (it->expanded_depth > it2->expanded_depth))
5184                     {
5185                        if (!it->effect_done)
5186                          {
5187                             edje_object_signal_emit(it->base.view, "flip_item", "");
5188                             evas_object_show(it->base.view);
5189                             it->effect_done = EINA_TRUE;
5190                          }
5191                     }
5192                   it = elm_genlist_item_prev_get(it);
5193                }
5194           }
5195         else if (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT)
5196           {
5197              it = elm_genlist_item_prev_get(it2);
5198              while (it)
5199                {
5200                   if ((it->scrl_y > it2->old_scrl_y + y) && (it->expanded_depth > it2->expanded_depth))
5201                     {
5202                        if (!it->effect_done)
5203                          {
5204                             edje_object_signal_emit(it->base.view, "elm,state,hide", "");
5205                             it->effect_done = EINA_TRUE;
5206                          }
5207                     }
5208                   else
5209                     break;
5210                   it = elm_genlist_item_prev_get(it);
5211                }
5212           }
5213      }
5214    else
5215      {
5216         int expand_num = 0;
5217         int expand_order = 0;
5218         if (wd->expand_item) it = elm_genlist_item_next_get(wd->expand_item);
5219         while (it)
5220           {
5221              expand_num++;
5222              it = elm_genlist_item_next_get(it);
5223           }
5224         if (wd->expand_item) it = elm_genlist_item_next_get(wd->expand_item);
5225         while (it)
5226           {
5227              expand_order++;
5228              if (wd->expand_item->expanded_depth >= it->expanded_depth) break;
5229              if (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND)
5230                {
5231                   if (!it->effect_done)
5232                     {
5233                        if (t >= (((expand_order - 1) * time) / expand_num))
5234                          {
5235                             edje_object_signal_emit(it->base.view, "flip_item", "");
5236                             evas_object_show(it->base.view);
5237                             it->effect_done = EINA_TRUE;
5238                          }
5239                     }
5240                }
5241              it = elm_genlist_item_next_get(it);
5242           }
5243      }
5244
5245    if (end)
5246      {
5247         if (wd->item_moving_effect_timer)
5248           {
5249              if (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT)
5250                 _item_subitems_clear(wd->expand_item);
5251              EINA_INLIST_FOREACH(wd->blocks, itb)
5252                {
5253                   EINA_LIST_FOREACH(itb->items, l, it)
5254                     {
5255                        it->effect_done = EINA_TRUE;
5256                        it->old_scrl_y = it->scrl_y;
5257                     }
5258                }
5259           }
5260         wd->item_moving_effect_timer = NULL;
5261
5262         _item_auto_scroll(wd);
5263         evas_object_lower(wd->alpha_bg);
5264         evas_object_hide(wd->alpha_bg);
5265         if (wd->calc_job) ecore_job_del(wd->calc_job);
5266         wd->calc_job = ecore_job_add(_calc_job, wd);
5267         elm_smart_scroller_bounce_animator_disabled_set(wd->scr, EINA_FALSE);
5268         wd->move_effect_mode = ELM_GENLIST_ITEM_MOVE_EFFECT_NONE;
5269
5270         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
5271         evas_object_smart_callback_call(wd->obj, "effect_done", NULL);
5272         return ECORE_CALLBACK_CANCEL;
5273      }
5274    return ECORE_CALLBACK_RENEW;
5275 }
5276
5277 static void
5278 _emit_contract(Elm_Genlist_Item *it)
5279 {
5280    Elm_Genlist_Item *it2;
5281    Eina_List *l;
5282
5283    //   printf("%p is emited contract\n", it);
5284    edje_object_signal_emit(it->base.view, "elm,state,contract_flip", "");
5285    it->effect_done = EINA_FALSE;
5286
5287    EINA_LIST_FOREACH(it->items, l, it2)
5288       if (it2)
5289          _emit_contract(it2);
5290 }
5291
5292 // added for item moving animation.
5293 static int
5294 _item_flip_effect_show(Elm_Genlist_Item *it)
5295 {
5296    Elm_Genlist_Item *it2;
5297    Eina_List *l;
5298    Widget_Data *wd = it->wd;
5299    Eina_Bool check = EINA_FALSE;
5300
5301    it2 = elm_genlist_item_next_get(it);
5302    while (it2)
5303      {
5304         if (it2->expanded_depth <= it->expanded_depth) check = EINA_TRUE;
5305         it2 = elm_genlist_item_next_get(it2);
5306      }
5307    EINA_LIST_FOREACH(it->items, l, it2)
5308      {
5309         if (it2->parent && it == it2->parent)
5310           {
5311              if (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND)
5312                edje_object_signal_emit(it2->base.view, "elm,state,hide", "");
5313              else if (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT)
5314                _emit_contract(it2);
5315           }
5316      }
5317
5318    return ECORE_CALLBACK_CANCEL;
5319 }
5320
5321 /*
5322 static void
5323 _elm_genlist_pinch_zoom_execute(Evas_Object *obj, Eina_Bool emode)
5324 {
5325    printf("!!! NOW FIXING \n");
5326 }
5327 */
5328
5329 /**
5330  * Set pinch zoom mode
5331  *
5332  * @param obj The genlist object
5333  * @param emode
5334  * (EINA_TRUE = pinch contract (zoom in), EINA_FALSE = pinch expand (zoom out)
5335  *
5336  * @ingroup Genlist
5337  */
5338 EAPI void
5339 elm_genlist_pinch_zoom_mode_set(Evas_Object *obj __UNUSED__, Eina_Bool emode __UNUSED__)
5340 {
5341    printf("!!! NOW FIXING \n");
5342 }
5343
5344 /**
5345  * Get pinch zoom mode
5346  *
5347  * @param obj The genlist object
5348  * @return The pinch mode
5349  * (EINA_TRUE = pinch contract (zoom in), EINA_FALSE = pinch expand (zoom out)
5350  *
5351  * @ingroup Genlist
5352  */
5353 EAPI Eina_Bool
5354 elm_genlist_pinch_zoom_mode_get(const Evas_Object *obj __UNUSED__)
5355 {
5356    printf("!!! NOW FIXING \n");
5357    return EINA_FALSE;
5358 }
5359
5360 EAPI void
5361 elm_genlist_pinch_zoom_set(Evas_Object *obj __UNUSED__, Eina_Bool emode __UNUSED__)
5362 {
5363    printf("!!! NOW FIXING \n");
5364 }
5365
5366
5367 ////////////////////////////////////////////////////////////////////////
5368 //  EDIT  MODE
5369 ////////////////////////////////////////////////////////////////////////
5370
5371 static void
5372 _effect_item_controls(Elm_Genlist_Item *it, int itx, int ity)
5373 {
5374    if (!it->wd->edit_mode) return;
5375    evas_object_resize(it->edit_obj,it->w, it->h);
5376    evas_object_move(it->edit_obj, itx, ity);
5377 }
5378
5379 static void
5380 _effect_item_realize(Elm_Genlist_Item *it, Eina_Bool effect_on)
5381 {
5382    if ((it->effect_item_realized) || (it->delete_me)) return;
5383    char buf[1024];
5384
5385    if (it->mode_view)
5386      _mode_finished_signal_cb(it, (Evas_Object *)elm_genlist_item_object_get(it), NULL, NULL);
5387
5388    it->edit_obj = edje_object_add(evas_object_evas_get(it->base.widget));
5389    edje_object_scale_set(it->edit_obj, elm_widget_scale_get(it->base.widget) *
5390                          _elm_config->scale);
5391    evas_object_smart_member_add(it->edit_obj, it->wd->pan_smart);
5392    elm_widget_sub_object_add(it->base.widget, it->edit_obj);
5393
5394    if (it->flags & ELM_GENLIST_ITEM_SUBITEMS) strncpy(buf, "tree", sizeof(buf));
5395    else strncpy(buf, "item", sizeof(buf));
5396    if (it->wd->compress) strncat(buf, "_compress", sizeof(buf) - strlen(buf));
5397
5398    strncat(buf, "/", sizeof(buf) - strlen(buf));
5399
5400    if (it->itc->edit_item_style && strcmp(it->itc->edit_item_style, "default"))
5401      {
5402         strncat(buf, it->itc->edit_item_style, sizeof(buf) - strlen(buf));
5403         _elm_theme_object_set(it->base.widget, it->edit_obj, "genlist", buf, elm_widget_style_get(it->base.widget));
5404      }
5405    else
5406      {
5407         _elm_theme_object_set(it->base.widget, it->edit_obj, "genlist", "item/edit_default", elm_widget_style_get(it->base.widget));
5408      }
5409
5410    if (it->wd->reorder_mode)
5411      {
5412         if (effect_on) edje_object_signal_emit(it->edit_obj, "elm,state,reorder_enabled_effect", "elm");
5413         else edje_object_signal_emit(it->edit_obj, "elm,state,reorder_enabled", "elm");
5414      }
5415    if (effect_on) edje_object_signal_emit(it->edit_obj, "elm,state,emode_enabled_effect", "elm");
5416    else edje_object_signal_emit(it->edit_obj, "elm,state,emode_enabled", "elm");
5417
5418    if (it->disabled) edje_object_signal_emit(it->edit_obj, "elm,state,disabled", "elm");
5419    else edje_object_signal_emit(it->edit_obj, "elm,state,enabled", "elm");
5420
5421
5422    if ((it->wd->edit_mode))
5423      {
5424         if (it->itc->func.icon_get)
5425           {
5426              const Eina_List *l;
5427              const char *key;
5428
5429              it->icons = elm_widget_stringlist_get(edje_object_data_get(it->edit_obj, "edit_icons"));
5430              EINA_LIST_FOREACH(it->icons, l, key)
5431                {
5432                   Evas_Object *ic = it->itc->func.icon_get
5433                      ((void *)it->base.data, it->base.widget, l->data);
5434
5435                   if (ic)
5436                     {
5437                        it->edit_icon_objs = eina_list_append(it->edit_icon_objs, ic);
5438                        edje_object_part_swallow(it->edit_obj, key, ic);
5439                        evas_object_show(ic);
5440                        elm_widget_sub_object_add(it->base.widget, ic);
5441                        if (it->disabled)
5442                          elm_widget_disabled_set(ic, EINA_TRUE);
5443                     }
5444                }
5445           }
5446      }
5447    edje_object_part_swallow(it->edit_obj, "original_edc", it->base.view);
5448    _effect_item_controls(it,it->scrl_x, it->scrl_y);
5449    evas_object_show(it->edit_obj);
5450
5451    it->effect_item_realized = EINA_TRUE;
5452    it->want_unrealize = EINA_FALSE;
5453 }
5454
5455 static void
5456 _effect_item_unrealize(Elm_Genlist_Item *it)
5457 {
5458    Evas_Object *icon;
5459
5460    if (!it->effect_item_realized) return;
5461    if (it->wd->reorder_it && it->wd->reorder_it == it) return;
5462
5463    edje_object_signal_emit(it->edit_obj, "elm,state,reorder_disable_effect", "elm");
5464    edje_object_signal_emit(it->edit_obj, "elm,state,sel,disable", "elm");
5465    edje_object_message_signal_process(it->edit_obj);
5466    edje_object_part_unswallow(it->edit_obj, it->base.view);
5467    evas_object_smart_member_add(it->base.view, it->wd->pan_smart);
5468    elm_widget_sub_object_add(it->base.widget, it->base.view);
5469    //   evas_object_smart_callback_call(it->edit_obj, "unrealized", it);
5470    //   _item_cache_add(it);
5471    evas_object_del(it->edit_obj);
5472    it->edit_obj = NULL;
5473    EINA_LIST_FREE(it->edit_icon_objs, icon)
5474       evas_object_del(icon);
5475
5476 //   edje_object_signal_emit(it->edit_obj, "elm,state,edit_end,disable", "elm");
5477    it->effect_item_realized = EINA_FALSE;
5478 }
5479
5480 /**
5481  * Get Genlist edit mode
5482  *
5483  * @param obj The genlist object
5484  * @return The edit mode status
5485  * (EINA_TRUE = edit mode, EINA_FALSE = normal mode
5486  *
5487  * @ingroup Genlist
5488  */
5489 EAPI Eina_Bool
5490 elm_genlist_edit_mode_get(const Evas_Object *obj)
5491 {
5492    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5493    Widget_Data *wd = elm_widget_data_get(obj);
5494    if (!wd) return EINA_FALSE;
5495
5496    if (wd->edit_mode) return EINA_TRUE;
5497    else return EINA_FALSE;
5498 }
5499
5500 /**
5501  * Set Genlist edit mode
5502  *
5503  * This sets Genlist edit mode.
5504  *
5505  * @param obj The Genlist object
5506  * @param emode ELM_GENLIST_EDIT_MODE_{NONE & REORDER & INSERT & DELETE & SELECT & SELECT_ALL}
5507  * @param edit_class Genlist edit class (Elm_Genlist_Edit_Class structure)
5508  *
5509  * @ingroup Genlist
5510  */
5511 EAPI void
5512 elm_genlist_edit_mode_set(Evas_Object *obj, Eina_Bool edit_mode)
5513 {
5514    ELM_CHECK_WIDTYPE(obj, widtype);
5515
5516    Item_Block *itb;
5517    Eina_List *l;
5518    Elm_Genlist_Item *it;
5519
5520    Widget_Data *wd = elm_widget_data_get(obj);
5521    if (!wd) return;
5522    if (wd->edit_mode == edit_mode) return;
5523
5524    wd->edit_mode = edit_mode;
5525    if (!wd->edit_mode)
5526      {
5527         EINA_INLIST_FOREACH(wd->blocks, itb)
5528           {
5529              if (itb->realized)
5530                {
5531                   EINA_LIST_FOREACH(itb->items, l, it)
5532                     {
5533                        if (it->flags != ELM_GENLIST_ITEM_GROUP && it->realized)
5534                          {
5535                             _effect_item_unrealize(it);
5536                          }
5537                     }
5538                }
5539           }
5540         _item_cache_zero(wd);
5541      }
5542    else
5543      {
5544
5545         EINA_INLIST_FOREACH(wd->blocks, itb)
5546           {
5547              if (itb->realized)
5548                {
5549                   EINA_LIST_FOREACH(itb->items, l, it)
5550                     {
5551                        if (it->flags != ELM_GENLIST_ITEM_GROUP && it->realized)
5552                          {
5553                             if(it->selected) _item_unselect(it);
5554                             if (it->itc->edit_item_style) _effect_item_realize(it, EINA_TRUE);
5555                          }
5556                     }
5557                 }
5558            }
5559       }
5560
5561    if (wd->calc_job) ecore_job_del(wd->calc_job);
5562    wd->calc_job = ecore_job_add(_calc_job, wd);
5563 }
5564
5565 /**
5566  * Set a given item's rename mode
5567  *
5568  * This renames the item's label from genlist
5569  *
5570  * @param it The item
5571  * @param renamed set if emode is EINA_TRUE, unset if emode is EINA_FALSE
5572  *
5573  * @ingroup Genlist
5574  */
5575 EAPI void
5576 elm_genlist_item_rename_mode_set(Elm_Genlist_Item *it, Eina_Bool renamed)
5577 {
5578    if (!it) return;
5579
5580    if (renamed)
5581      {
5582         _item_unrealize(it, EINA_FALSE);
5583         it->renamed = EINA_TRUE;
5584         it->wd->rename_it = it;
5585         it->nocache = EINA_TRUE;
5586         if (it->selected)  _item_unselect(it);
5587
5588         if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
5589         it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
5590      }
5591    else
5592      {
5593         if (it->renamed)
5594           {
5595              it->renamed = EINA_FALSE;
5596              it->nocache = EINA_TRUE;
5597              it->wd->rename_it = NULL;
5598              _item_cache_zero(it->wd);
5599              elm_genlist_item_update(it);
5600           }
5601      }
5602 }
5603
5604 EAPI Eina_Bool
5605 elm_genlist_item_rename_mode_get(Elm_Genlist_Item *item)
5606 {
5607    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
5608    return item->renamed;
5609 }
5610
5611 static void
5612 _item_auto_scroll(void *data)
5613 {
5614    Widget_Data *wd = data;
5615    if (!wd) return;
5616
5617    if ((wd->expand_item) && (!wd->auto_scrolled))
5618      {
5619         Elm_Genlist_Item  *it;
5620         Eina_List *l;
5621         Evas_Coord ox, oy, ow, oh;
5622         evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
5623
5624         wd->auto_scrolled = EINA_TRUE;
5625         if (wd->expand_item->scrl_y > (oh + oy) / 2)
5626           {
5627             EINA_LIST_FOREACH(wd->expand_item->items, l, it)
5628               {
5629                  elm_genlist_item_bring_in(it);
5630               }
5631           }
5632      }
5633 }