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