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