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