Merge "[Genlist] Fixed all genlist build warnings."
[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 static void
1722 _item_del_hook(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1723 {
1724    Elm_Genlist_Item *it = event_info;
1725    if (!it) return;
1726    if (it->wd->last_selected_item == it)
1727      it->wd->last_selected_item = NULL;
1728 }
1729
1730 static void
1731 _item_label_realize(Elm_Genlist_Item *it,
1732                     Evas_Object *target,
1733                     Eina_List **source)
1734 {
1735    if (it->itc->func.label_get)
1736      {
1737         const Eina_List *l;
1738         const char *key;
1739
1740         *source = elm_widget_stringlist_get(edje_object_data_get(target, "labels"));
1741         EINA_LIST_FOREACH(*source, l, key)
1742           {
1743              char *s = it->itc->func.label_get
1744                 ((void *)it->base.data, it->base.widget, key);
1745
1746              if (s)
1747                {
1748                   edje_object_part_text_set(target, key, s);
1749                   free(s);
1750                }
1751              else
1752                {
1753                   edje_object_part_text_set(target, key, "");
1754                }
1755           }
1756      }
1757 }
1758
1759 static Eina_List *
1760 _item_icon_realize(Elm_Genlist_Item *it,
1761                    Evas_Object *target,
1762                    Eina_List **source)
1763 {
1764    Eina_List *res = NULL;
1765
1766    if (it->itc->func.icon_get)
1767      {
1768         const Eina_List *l;
1769         const char *key;
1770
1771         *source = elm_widget_stringlist_get(edje_object_data_get(target, "icons"));
1772         EINA_LIST_FOREACH(*source, l, key)
1773           {
1774              Evas_Object *ic = it->itc->func.icon_get
1775                 ((void *)it->base.data, it->base.widget, key);
1776
1777              if (ic)
1778                {
1779                   res = eina_list_append(res, ic);
1780                   edje_object_part_swallow(target, key, ic);
1781                   evas_object_show(ic);
1782                   elm_widget_sub_object_add(it->base.widget, ic);
1783                   evas_object_event_callback_add(ic, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
1784                   if (it->disabled)
1785                     elm_widget_disabled_set(ic, EINA_TRUE);
1786                }
1787           }
1788      }
1789
1790    return res;
1791 }
1792
1793 static void
1794 _item_state_realize(Elm_Genlist_Item *it,
1795                     Evas_Object *target,
1796                     Eina_List **source)
1797 {
1798    if (it->itc->func.state_get)
1799      {
1800         const Eina_List *l;
1801         const char *key;
1802         char buf[4096];
1803
1804         *source = elm_widget_stringlist_get(edje_object_data_get(target, "states"));
1805         EINA_LIST_FOREACH(*source, l, key)
1806           {
1807              Eina_Bool on = it->itc->func.state_get
1808                 ((void *)it->base.data, it->base.widget, key);
1809
1810              if (on)
1811                {
1812                   snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1813                   edje_object_signal_emit(target, buf, "elm");
1814                }
1815              else
1816                {
1817                   snprintf(buf, sizeof(buf), "elm,state,%s,passive", key);
1818                   edje_object_signal_emit(target, buf, "elm");
1819                }
1820           }
1821      }
1822 }
1823
1824 static void
1825 _item_realize(Elm_Genlist_Item *it,
1826               int               in,
1827               Eina_Bool         calc)
1828 {
1829    Elm_Genlist_Item *it2;
1830    const char *stacking;
1831    const char *treesize;
1832    char buf[1024];
1833    int depth, tsize = 20;
1834    Item_Cache *itc = NULL;
1835
1836    if ((it->realized) || (it->delete_me)) return;
1837    evas_event_freeze(evas_object_evas_get(it->wd->obj));
1838    it->order_num_in = in;
1839    if (it->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE) calc = EINA_FALSE;
1840    if ((it->nocache) && (!it->renamed))
1841      it->nocache = EINA_FALSE;
1842    else
1843      itc = _item_cache_find(it);
1844    if (itc && (!it->wd->effect_mode))
1845      {
1846         it->base.view = itc->base_view;
1847         itc->base_view = NULL;
1848         it->spacer = itc->spacer;
1849         itc->spacer = NULL;
1850      }
1851    else
1852      {
1853         it->base.view = edje_object_add(evas_object_evas_get(it->base.widget));
1854         edje_object_scale_set(it->base.view,
1855                               elm_widget_scale_get(it->base.widget) *
1856                               _elm_config->scale);
1857         evas_object_smart_member_add(it->base.view, it->wd->pan_smart);
1858         elm_widget_sub_object_add(it->base.widget, it->base.view);
1859
1860         if (it->flags & ELM_GENLIST_ITEM_SUBITEMS)
1861           strncpy(buf, "tree", sizeof(buf));
1862         else strncpy(buf, "item", sizeof(buf));
1863         if (it->wd->compress)
1864           strncat(buf, "_compress", sizeof(buf) - strlen(buf));
1865
1866         if (in & 0x1) strncat(buf, "_odd", sizeof(buf) - strlen(buf));
1867         strncat(buf, "/", sizeof(buf) - strlen(buf));
1868         strncat(buf, it->itc->item_style, sizeof(buf) - strlen(buf));
1869
1870         _elm_theme_object_set(it->base.widget, it->base.view, "genlist", buf,
1871                               elm_widget_style_get(it->base.widget));
1872         edje_object_mirrored_set(it->base.view,
1873                                  elm_widget_mirrored_get(it->base.widget));
1874         it->spacer =
1875           evas_object_rectangle_add(evas_object_evas_get(it->base.widget));
1876         evas_object_color_set(it->spacer, 0, 0, 0, 0);
1877         elm_widget_sub_object_add(it->base.widget, it->spacer);
1878      }
1879    for (it2 = it, depth = 0; it2->parent; it2 = it2->parent)
1880      {
1881         if (it2->parent->flags != ELM_GENLIST_ITEM_GROUP) depth += 1;
1882      }
1883    it->expanded_depth = depth;
1884    treesize = edje_object_data_get(it->base.view, "treesize");
1885    if (treesize) tsize = atoi(treesize);
1886    evas_object_size_hint_min_set(it->spacer,
1887                                  (depth * tsize) * _elm_config->scale, 1);
1888    edje_object_part_swallow(it->base.view, "elm.swallow.pad", it->spacer);
1889    if (!calc)
1890      {
1891         edje_object_signal_callback_add(it->base.view,
1892                                         "elm,action,expand,toggle",
1893                                         "elm", _signal_expand_toggle, it);
1894         edje_object_signal_callback_add(it->base.view, "elm,action,expand",
1895                                         "elm", _signal_expand, it);
1896         edje_object_signal_callback_add(it->base.view, "elm,action,contract",
1897                                         "elm", _signal_contract, it);
1898         stacking = edje_object_data_get(it->base.view, "stacking");
1899         if (stacking)
1900           {
1901              if (!strcmp(stacking, "below")) evas_object_lower(it->base.view);
1902              else if (!strcmp(stacking, "above"))
1903                evas_object_raise(it->base.view);
1904           }
1905         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_DOWN,
1906                                        _mouse_down, it);
1907         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_UP,
1908                                        _mouse_up, it);
1909         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_MOVE,
1910                                        _mouse_move, it);
1911         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_DOWN,
1912                                        _multi_down, it);
1913         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_UP,
1914                                        _multi_up, it);
1915         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_MOVE,
1916                                        _multi_move, it);
1917
1918         if ((!it->edit_obj) &&(it->wd->edit_mode) &&
1919             (it->flags != ELM_GENLIST_ITEM_GROUP) && (it->itc->edit_item_style))
1920           _effect_item_realize(it, EINA_FALSE);
1921
1922         if (itc)
1923           {
1924              if ((it->selected) && (it->selected != itc->selected))
1925                {
1926                   edje_object_signal_emit(it->base.view,
1927                                           "elm,state,selected", "elm");
1928                   if (it->edit_obj)
1929                     edje_object_signal_emit(it->edit_obj,
1930                                             "elm,state,selected", "elm");
1931                }
1932              if ((it->disabled) && (it->disabled != itc->disabled))
1933                {
1934                   edje_object_signal_emit(it->base.view,
1935                                           "elm,state,disabled", "elm");
1936                   if (it->edit_obj)
1937                     edje_object_signal_emit(it->edit_obj,
1938                                             "elm,state,disabled", "elm");
1939                }
1940              if ((it->expanded) && (it->expanded != itc->expanded))
1941                {
1942                   edje_object_signal_emit(it->base.view,
1943                                           "elm,state,expanded", "elm");
1944                   if (it->edit_obj)
1945                     edje_object_signal_emit(it->edit_obj,
1946                                             "elm,state,expanded", "elm");
1947                }
1948           }
1949         else
1950           {
1951              if (it->selected)
1952                {
1953                   edje_object_signal_emit(it->base.view,
1954                                           "elm,state,selected", "elm");
1955                   if (it->edit_obj)
1956                     edje_object_signal_emit(it->edit_obj,
1957                                             "elm,state,selected", "elm");
1958                }
1959              if (it->disabled)
1960                {
1961                   edje_object_signal_emit(it->base.view,
1962                                           "elm,state,disabled", "elm");
1963                   if (it->edit_obj)
1964                     edje_object_signal_emit(it->edit_obj,
1965                                             "elm,state,disabled", "elm");
1966                }
1967              if (it->expanded)
1968                {
1969                   edje_object_signal_emit(it->base.view,
1970                                           "elm,state,expanded", "elm");
1971                   if (it->edit_obj)
1972                     edje_object_signal_emit(it->edit_obj,
1973                                             "elm,state,expanded", "elm");
1974                }
1975           }
1976      }
1977
1978    if ((calc) && (it->wd->homogeneous) &&
1979        ((it->wd->item_width) ||
1980         ((it->wd->item_width) && (it->wd->group_item_width))))
1981      {
1982         /* homogenous genlist shortcut */
1983         if (!it->mincalcd)
1984           {
1985              if (it->flags & ELM_GENLIST_ITEM_GROUP)
1986                {
1987                   it->w = it->minw = it->wd->group_item_width;
1988                   it->h = it->minh = it->wd->group_item_height;
1989                }
1990              else
1991                {
1992                   it->w = it->minw = it->wd->item_width;
1993                   it->h = it->minh = it->wd->item_height;
1994                }
1995              it->mincalcd = EINA_TRUE;
1996           }
1997      }
1998    else
1999      {
2000         _item_label_realize(it, it->base.view, &it->labels);
2001         it->icon_objs = _item_icon_realize(it, it->base.view, &it->icons);
2002         _item_state_realize(it, it->base.view, &it->states);
2003         if (it->itc->func.icon_get) // for rename mode
2004           {
2005              const Eina_List *l;
2006              const char *key;
2007              if (it->renamed)
2008                {
2009                   it->icons =
2010                      elm_widget_stringlist_get(edje_object_data_get(it->base.view, "renames"));
2011                   EINA_LIST_FOREACH(it->icons, l, key)
2012                     {
2013                        Evas_Object *ic = it->itc->func.icon_get
2014                           ((void *)it->base.data, it->base.widget, l->data);
2015                        if (ic)
2016                          {
2017                             it->icon_objs = eina_list_append(it->icon_objs, ic);
2018                             edje_object_part_swallow(it->base.view, key, ic);
2019                             evas_object_show(ic);
2020                             elm_widget_sub_object_add(it->base.widget, ic);
2021                             // FIXME: if entry calcuates its cursor position correctly and conformant works,
2022                             //        genlist does not need to handle this focus thing.
2023                             evas_object_smart_callback_add(ic, "focused", _icon_focused, it);
2024                             evas_object_smart_callback_add(ic, "unfocused", _icon_unfocused, it);
2025                          }
2026                     }
2027                }
2028           }
2029         if (!it->mincalcd || it->wd->pan_resize || ((it->wd->height_for_width) && (it->w != it->minw)))
2030           {
2031              Evas_Coord mw = -1, mh = -1;
2032
2033              if (it->wd->height_for_width) mw = it->wd->w; // TODO: Removed this. This was removed from upstream.
2034
2035              if (!it->display_only)
2036                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
2037              if (it->wd->height_for_width) mw = it->wd->prev_viewport_w;
2038              edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw,
2039                                                   mh);
2040              if (!it->display_only)
2041                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
2042              it->w = it->minw = mw;
2043              it->h = it->minh = mh;
2044              it->mincalcd = EINA_TRUE;
2045
2046              if ((!it->wd->group_item_width) && (it->flags == ELM_GENLIST_ITEM_GROUP))
2047                {
2048                   it->wd->group_item_width = mw;
2049                   it->wd->group_item_height = mh;
2050                }
2051              else if ((!it->wd->item_width) && (it->flags == ELM_GENLIST_ITEM_NONE))
2052                {
2053                   it->wd->item_width = mw;
2054                   it->wd->item_height = mh;
2055                }
2056           }
2057         if (!calc) evas_object_show(it->base.view);
2058      }
2059
2060    if (it->tooltip.content_cb)
2061      {
2062         elm_widget_item_tooltip_content_cb_set(it,
2063                                                it->tooltip.content_cb,
2064                                                it->tooltip.data, NULL);
2065         elm_widget_item_tooltip_style_set(it, it->tooltip.style);
2066      }
2067
2068    if (it->mouse_cursor)
2069      elm_widget_item_cursor_set(it, it->mouse_cursor);
2070
2071    it->realized = EINA_TRUE;
2072    it->want_unrealize = EINA_FALSE;
2073
2074    if (itc) _item_cache_free(itc);
2075    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2076    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2077    if (!calc)
2078      evas_object_smart_callback_call(it->base.widget, SIG_REALIZED, it);
2079    if ((!calc) && (it->wd->edit_mode) && (it->flags != ELM_GENLIST_ITEM_GROUP))
2080      {
2081         if (it->itc->edit_item_style)
2082           {
2083              if (!it->edit_obj) _effect_item_realize(it, EINA_FALSE);
2084              edje_object_message_signal_process(it->edit_obj);
2085           }
2086      }
2087    edje_object_message_signal_process(it->base.view);
2088 }
2089
2090 static void
2091 _item_unrealize(Elm_Genlist_Item *it,
2092                 Eina_Bool         calc)
2093 {
2094    Evas_Object *icon;
2095
2096    if (!it->realized) return;
2097    if (it->wd->reorder_it == it) return;
2098    if (it->defer_unrealize && !it->updateme) return;
2099    evas_event_freeze(evas_object_evas_get(it->wd->obj));
2100    if (!calc)
2101      evas_object_smart_callback_call(it->base.widget, SIG_UNREALIZED, it);
2102    if (it->long_timer)
2103      {
2104         ecore_timer_del(it->long_timer);
2105         it->long_timer = NULL;
2106      }
2107    if (it->nocache)
2108      {
2109         evas_object_del(it->base.view);
2110         it->base.view = NULL;
2111         evas_object_del(it->spacer);
2112         it->spacer = NULL;
2113      }
2114    else
2115      {
2116         edje_object_mirrored_set(it->base.view,
2117                                  elm_widget_mirrored_get(it->base.widget));
2118         edje_object_scale_set(it->base.view,
2119                               elm_widget_scale_get(it->base.widget)
2120                               * _elm_config->scale);
2121         _item_cache_add(it);
2122      }
2123    elm_widget_stringlist_free(it->labels);
2124    it->labels = NULL;
2125    elm_widget_stringlist_free(it->icons);
2126    it->icons = NULL;
2127    elm_widget_stringlist_free(it->states);
2128
2129    EINA_LIST_FREE(it->icon_objs, icon)
2130      evas_object_del(icon);
2131
2132    _mode_item_unrealize(it);
2133    it->states = NULL;
2134    it->realized = EINA_FALSE;
2135    it->want_unrealize = EINA_FALSE;
2136    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2137    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2138    if (it->wd->edit_mode) _effect_item_unrealize(it);
2139 }
2140
2141 static Eina_Bool
2142 _item_block_recalc(Item_Block *itb,
2143                    int         in,
2144                    Eina_Bool   qadd)
2145 {
2146    const Eina_List *l;
2147    Elm_Genlist_Item *it;
2148    Evas_Coord minw = 0, minh = 0;
2149    Eina_Bool showme = EINA_FALSE, changed = EINA_FALSE;
2150    Evas_Coord y = 0;
2151
2152    evas_event_freeze(evas_object_evas_get(itb->wd->obj));
2153    itb->num = in;
2154    EINA_LIST_FOREACH(itb->items, l, it)
2155      {
2156         if (it->delete_me) continue;
2157         showme |= it->showme;
2158         if (!itb->realized)
2159           {
2160              if (qadd)
2161                {
2162                   if (!it->mincalcd) changed = EINA_TRUE;
2163                   if (changed)
2164                     {
2165                        _item_realize(it, in, EINA_TRUE);
2166                        _item_unrealize(it, EINA_TRUE);
2167                     }
2168                }
2169              else
2170                {
2171                   _item_realize(it, in, EINA_TRUE);
2172                   _item_unrealize(it, EINA_TRUE);
2173                }
2174           }
2175         else
2176           _item_realize(it, in, EINA_FALSE);
2177         minh += it->minh;
2178         if (minw < it->minw) minw = it->minw;
2179         in++;
2180         it->x = 0;
2181         it->y = y;
2182         y += it->h;
2183      }
2184    itb->minw = minw;
2185    itb->minh = minh;
2186    itb->changed = EINA_FALSE;
2187    evas_event_thaw(evas_object_evas_get(itb->wd->obj));
2188    evas_event_thaw_eval(evas_object_evas_get(itb->wd->obj));
2189    return showme;
2190 }
2191
2192 static void
2193 _item_block_realize(Item_Block *itb)
2194 {
2195    if (itb->realized) return;
2196    itb->realized = EINA_TRUE;
2197    itb->want_unrealize = EINA_FALSE;
2198 }
2199
2200 static void
2201 _item_block_unrealize(Item_Block *itb)
2202 {
2203    const Eina_List *l;
2204    Elm_Genlist_Item *it;
2205    Eina_Bool dragging = EINA_FALSE;
2206
2207    if (!itb->realized) return;
2208    evas_event_freeze(evas_object_evas_get(itb->wd->obj));
2209    EINA_LIST_FOREACH(itb->items, l, it)
2210      {
2211         if (it->flags != ELM_GENLIST_ITEM_GROUP)
2212           {
2213              if (it->dragging)
2214                {
2215                   dragging = EINA_TRUE;
2216                   it->want_unrealize = EINA_TRUE;
2217                }
2218              else
2219                _item_unrealize(it, EINA_FALSE);
2220           }
2221      }
2222    if (!dragging)
2223      {
2224         itb->realized = EINA_FALSE;
2225         itb->want_unrealize = EINA_TRUE;
2226      }
2227    else
2228      itb->want_unrealize = EINA_FALSE;
2229    evas_event_thaw(evas_object_evas_get(itb->wd->obj));
2230    evas_event_thaw_eval(evas_object_evas_get(itb->wd->obj));
2231 }
2232
2233 static int
2234 _get_space_for_reorder_item(Elm_Genlist_Item *it)
2235 {
2236    Evas_Coord rox, roy, row, roh, oy, oh;
2237    Eina_Bool top = EINA_FALSE;
2238    Elm_Genlist_Item *reorder_it = it->wd->reorder_it;
2239    if (!reorder_it) return 0;
2240
2241    evas_object_geometry_get(it->wd->pan_smart, NULL, &oy, NULL, &oh);
2242    evas_object_geometry_get(it->wd->reorder_it->base.view, &rox, &roy, &row, &roh);
2243
2244    if ((it->wd->reorder_start_y < it->block->y) &&
2245        (roy - oy + (roh / 2) >= it->block->y - it->wd->pan_y))
2246      {
2247         it->block->reorder_offset = it->wd->reorder_it->h * -1;
2248         if (it->block->count == 1)
2249           it->wd->reorder_rel = it;
2250      }
2251    else if ((it->wd->reorder_start_y >= it->block->y) &&
2252             (roy - oy + (roh / 2) <= it->block->y - it->wd->pan_y))
2253      {
2254         it->block->reorder_offset = it->wd->reorder_it->h;
2255      }
2256    else
2257      it->block->reorder_offset = 0;
2258
2259    it->scrl_y += it->block->reorder_offset;
2260
2261    top = (ELM_RECTS_INTERSECT(it->scrl_x, it->scrl_y, it->w, it->h,
2262                               rox, roy + (roh / 2), row, 1));
2263    if (top)
2264      {
2265         it->wd->reorder_rel = it;
2266         it->scrl_y += it->wd->reorder_it->h;
2267         return it->wd->reorder_it->h;
2268      }
2269    else
2270      return 0;
2271 }
2272
2273 static Eina_Bool
2274 _reorder_move_animator_cb(void *data)
2275 {
2276    Elm_Genlist_Item *it = data;
2277    Eina_Bool down = EINA_FALSE;
2278    double t;
2279    int y, dy = it->h / 10 * _elm_config->scale, diff;
2280
2281    t = ((0.0 > (t = ecore_loop_time_get()-it->wd->start_time)) ? 0.0 : t);
2282
2283    if (t <= REORDER_EFFECT_TIME) y = (1 * sin((t / REORDER_EFFECT_TIME) * (M_PI / 2)) * dy);
2284    else y = dy;
2285
2286    diff = abs(it->old_scrl_y - it->scrl_y);
2287    if (diff > it->h) y = diff / 2;
2288    if (it->old_scrl_y < it->scrl_y)
2289      {
2290         it->old_scrl_y += y;
2291         down = EINA_TRUE;
2292      }
2293    else if (it->old_scrl_y > it->scrl_y)
2294      {
2295         it->old_scrl_y -= y;
2296         down = EINA_FALSE;
2297      }
2298
2299    if (it->edit_obj)
2300      _item_position(it, it->edit_obj, it->scrl_x, it->old_scrl_y);
2301    else
2302      _item_position(it, it->base.view, it->scrl_x, it->old_scrl_y);
2303    _group_items_recalc(it->wd);
2304    if ((it->wd->reorder_pan_move) ||
2305        (down && it->old_scrl_y >= it->scrl_y) ||
2306        (!down && it->old_scrl_y <= it->scrl_y))
2307      {
2308         it->old_scrl_y = it->scrl_y;
2309         it->move_effect_enabled = EINA_FALSE;
2310         it->wd->reorder_move_animator = NULL;
2311         return ECORE_CALLBACK_CANCEL;
2312      }
2313    return ECORE_CALLBACK_RENEW;
2314 }
2315
2316 static void
2317 _item_position(Elm_Genlist_Item *it,
2318                Evas_Object      *view,
2319                Evas_Coord        it_x,
2320                Evas_Coord        it_y)
2321 {
2322    if (!it) return;
2323    if (!view) return;
2324
2325    evas_event_freeze(evas_object_evas_get(it->wd->obj));
2326    evas_object_resize(view, it->w, it->h);
2327    evas_object_move(view, it_x, it_y);
2328    evas_object_show(view);
2329    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2330    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2331 }
2332
2333 static void
2334 _item_block_position(Item_Block *itb,
2335                      int         in)
2336 {
2337    const Eina_List *l;
2338    Elm_Genlist_Item *it;
2339    Elm_Genlist_Item *git;
2340    Evas_Coord y = 0, ox, oy, ow, oh, cvx, cvy, cvw, cvh;
2341    Evas_Coord minh = 0;
2342    int vis = 0;
2343
2344    evas_event_freeze(evas_object_evas_get(itb->wd->obj));
2345    evas_object_geometry_get(itb->wd->pan_smart, &ox, &oy, &ow, &oh);
2346    evas_output_viewport_get(evas_object_evas_get(itb->wd->obj), &cvx, &cvy,
2347                             &cvw, &cvh);
2348    EINA_LIST_FOREACH(itb->items, l, it)
2349      {
2350         if (it->delete_me) continue;
2351         else if (it->wd->reorder_it == it) continue;
2352
2353         it->x = 0;
2354         it->y = y;
2355         it->w = itb->w;
2356         it->scrl_x = itb->x + it->x - it->wd->pan_x + ox;
2357         it->scrl_y = itb->y + it->y - it->wd->pan_y + oy;
2358
2359         vis = (ELM_RECTS_INTERSECT(it->scrl_x, it->scrl_y, it->w, it->h,
2360                                    cvx, cvy, cvw, cvh));
2361         if (it->flags != ELM_GENLIST_ITEM_GROUP)
2362           {
2363              if ((itb->realized))
2364                {
2365                   if (vis)
2366                     {
2367                        if (!it->realized) _item_realize(it, in, EINA_FALSE);
2368                        if (it->renamed)
2369                          {
2370                             if (it->wd->edit_mode) edje_object_signal_emit(it->edit_obj, "elm,state,rename,enabled", "elm");
2371                             edje_object_signal_emit(it->base.view, "elm,state,rename,enabled", "elm");
2372                          }
2373                     }
2374                }
2375              if (it->realized)
2376                {
2377                   if (vis)
2378                     {
2379                        if (it->wd->reorder_mode)
2380                          y += _get_space_for_reorder_item(it);
2381                        git = it->group_item;
2382                        if (git)
2383                          {
2384                             git->scrl_x = it->scrl_x;
2385                             if (git->scrl_y < oy)
2386                               git->scrl_y = oy;
2387                             if ((git->scrl_y + git->h) > (it->scrl_y + it->h))
2388                               git->scrl_y = (it->scrl_y + it->h) - git->h;
2389                             git->want_realize = EINA_TRUE;
2390                          }
2391                        if ((it->wd->reorder_it) && (it->old_scrl_y != it->scrl_y))
2392                          {
2393                             if (!it->move_effect_enabled)
2394                               {
2395                                  it->move_effect_enabled = EINA_TRUE;
2396                                  it->wd->reorder_move_animator =
2397                                     ecore_animator_add(
2398                                        _reorder_move_animator_cb, it);
2399                               }
2400                          }
2401                        if (!it->move_effect_enabled)
2402                             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))
2403                             {
2404                               if (it->wd->edit_mode && it->itc->edit_item_style)
2405                                 {
2406                                    _item_position(it, it->edit_obj, it->scrl_x, it->scrl_y);
2407                                 }
2408                               else
2409                                {
2410                                   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)))
2411                                     {
2412                                        if (it->mode_view)
2413                                          _item_position(it, it->mode_view, it->scrl_x,
2414                                                         it->scrl_y);
2415                                        else
2416                                          _item_position(it, it->base.view, it->scrl_x,
2417                                                         it->scrl_y);
2418                                     }
2419                                   else
2420                                     {
2421                                        evas_object_resize(it->base.view, it->w, it->h);
2422                                        evas_object_move(it->base.view, it->scrl_x, it->scrl_y);
2423                                        evas_object_hide(it->base.view);
2424                                     }
2425                                }
2426                             }
2427                     }
2428                   else
2429                     {
2430                        if (!it->dragging && (!it->wd->item_moving_effect_timer)) _item_unrealize(it, EINA_FALSE);
2431                     }
2432                }
2433              in++;
2434           }
2435         else
2436           {
2437              if (vis) it->want_realize = EINA_TRUE;
2438           }
2439         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))
2440           {
2441              it->old_scrl_y = it->scrl_y;
2442           }
2443         y += it->h;
2444         minh += it->minh;
2445      }
2446    if (!itb->wd->reorder_it) itb->minh = minh;
2447    evas_event_thaw(evas_object_evas_get(itb->wd->obj));
2448    evas_event_thaw_eval(evas_object_evas_get(itb->wd->obj));
2449 }
2450
2451 static void
2452 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2453 {
2454    Elm_Genlist_Item *it = data;
2455    if (!it) return;
2456    it->mincalcd = EINA_FALSE;
2457    it->block->changeme = EINA_TRUE;
2458    if (it->wd->changed_job) ecore_job_del(it->wd->changed_job);
2459    it->wd->changed_job = ecore_job_add(_changed_job, it->wd);
2460 }
2461
2462 static void
2463 _group_items_recalc(void *data)
2464 {
2465    Widget_Data *wd = data;
2466    Eina_List *l;
2467    Elm_Genlist_Item *git;
2468
2469    evas_event_freeze(evas_object_evas_get(wd->obj));
2470    EINA_LIST_FOREACH(wd->group_items, l, git)
2471      {
2472         if (git->want_realize)
2473           {
2474              if (!git->realized)
2475                _item_realize(git, 0, EINA_FALSE);
2476              evas_object_resize(git->base.view, wd->minw, git->h);
2477              evas_object_move(git->base.view, git->scrl_x, git->scrl_y);
2478              evas_object_show(git->base.view);
2479              evas_object_raise(git->base.view);
2480           }
2481         else if (!git->want_realize && git->realized)
2482           {
2483              if (!git->dragging)
2484                _item_unrealize(git, EINA_FALSE);
2485           }
2486      }
2487    evas_event_thaw(evas_object_evas_get(wd->obj));
2488    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
2489 }
2490
2491 static Eina_Bool
2492 _must_recalc_idler(void *data)
2493 {
2494    Widget_Data *wd = data;
2495    if (wd->calc_job) ecore_job_del(wd->calc_job);
2496    wd->calc_job = ecore_job_add(_calc_job, wd);
2497    wd->must_recalc_idler = NULL;
2498    return ECORE_CALLBACK_CANCEL;
2499 }
2500
2501 static void
2502 _calc_job(void *data)
2503 {
2504    Widget_Data *wd = data;
2505    Item_Block *itb, *chb = NULL;
2506    Evas_Coord minw = -1, minh = 0, y = 0, ow;
2507    int in = 0;
2508    double t0, t;
2509    Eina_Bool minw_change = EINA_FALSE;
2510    Eina_Bool did_must_recalc = EINA_FALSE;
2511    if (!wd) return;
2512
2513    t0 = ecore_time_get();
2514    evas_object_geometry_get(wd->pan_smart, NULL, NULL, &ow, &wd->h);
2515    if (wd->w != ow)
2516      wd->w = ow;
2517
2518    evas_event_freeze(evas_object_evas_get(wd->obj));
2519    EINA_INLIST_FOREACH(wd->blocks, itb)
2520      {
2521         Eina_Bool showme = EINA_FALSE;
2522
2523         itb->num = in;
2524         showme = itb->showme;
2525         itb->showme = EINA_FALSE;
2526         if (chb)
2527           {
2528              if (itb->realized) _item_block_unrealize(itb);
2529           }
2530         if ((itb->changed) || ((itb->must_recalc) && (!did_must_recalc)))
2531           {
2532              if (itb->must_recalc)
2533                {
2534                   Eina_List *l;
2535                   Elm_Genlist_Item *it;
2536                   EINA_LIST_FOREACH(itb->items, l, it)
2537                     if (it->mincalcd) it->mincalcd = EINA_FALSE;
2538                   itb->changed = EINA_TRUE;
2539                   if (itb->must_recalc) did_must_recalc = EINA_TRUE;
2540                   itb->must_recalc = EINA_FALSE;
2541                   if (itb->realized) _item_block_unrealize(itb);
2542                }
2543              showme = _item_block_recalc(itb, in, EINA_FALSE);
2544              chb = itb;
2545           }
2546         itb->y = y;
2547         itb->x = 0;
2548         minh += itb->minh;
2549         if (minw == -1) minw = itb->minw;
2550         else if ((!itb->must_recalc) && (minw < itb->minw))
2551           {
2552              minw = itb->minw;
2553              minw_change = EINA_TRUE;
2554           }
2555         itb->w = minw;
2556         itb->h = itb->minh;
2557         y += itb->h;
2558         in += itb->count;
2559         if ((showme) && (wd->show_item) && (!wd->show_item->queued))
2560           {
2561              wd->show_item->showme = EINA_FALSE;
2562              if (wd->bring_in)
2563                elm_smart_scroller_region_bring_in(wd->scr,
2564                                                   wd->show_item->x +
2565                                                   wd->show_item->block->x,
2566                                                   wd->show_item->y +
2567                                                   wd->show_item->block->y,
2568                                                   wd->show_item->block->w,
2569                                                   wd->show_item->h);
2570              else
2571                elm_smart_scroller_child_region_show(wd->scr,
2572                                                     wd->show_item->x +
2573                                                     wd->show_item->block->x,
2574                                                     wd->show_item->y +
2575                                                     wd->show_item->block->y,
2576                                                     wd->show_item->block->w,
2577                                                     wd->show_item->h);
2578              wd->show_item = NULL;
2579           }
2580      }
2581    if (minw_change)
2582      {
2583         EINA_INLIST_FOREACH(wd->blocks, itb)
2584           {
2585              itb->minw = minw;
2586              itb->w = itb->minw;
2587           }
2588      }
2589    if ((chb) && (EINA_INLIST_GET(chb)->next))
2590      {
2591         EINA_INLIST_FOREACH(EINA_INLIST_GET(chb)->next, itb)
2592           {
2593              if (itb->realized) _item_block_unrealize(itb);
2594           }
2595      }
2596    wd->realminw = minw;
2597    if (minw < wd->w) minw = wd->w;
2598    if ((minw != wd->minw) || (minh != wd->minh))
2599      {
2600         wd->minw = minw;
2601         wd->minh = minh;
2602         if (wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE)
2603            evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2604         _sizing_eval(wd->obj);
2605 #ifdef ANCHOR_ITEM
2606         if ((wd->anchor_item) && (wd->anchor_item->block) && (!wd->auto_scrolled))
2607           {
2608              Elm_Genlist_Item *it;
2609              Evas_Coord it_y;
2610
2611              it = wd->anchor_item;
2612              it_y = wd->anchor_y;
2613              elm_smart_scroller_child_pos_set(wd->scr, wd->pan_x,
2614                                               it->block->y + it->y + it_y);
2615              wd->anchor_item = it;
2616              wd->anchor_y = it_y;
2617           }
2618 #endif
2619      }
2620    t = ecore_time_get();
2621    if (did_must_recalc)
2622      {
2623         if (!wd->must_recalc_idler)
2624           wd->must_recalc_idler = ecore_idler_add(_must_recalc_idler, wd);
2625      }
2626    wd->calc_job = NULL;
2627    evas_object_smart_changed(wd->pan_smart);
2628    evas_event_thaw(evas_object_evas_get(wd->obj));
2629    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
2630 }
2631
2632 static void
2633 _update_job(void *data)
2634 {
2635    Widget_Data *wd = data;
2636    Eina_List *l2;
2637    Item_Block *itb;
2638    int num, num0;
2639    Eina_Bool position = EINA_FALSE, recalc = EINA_FALSE;
2640    if (!wd) return;
2641    wd->update_job = NULL;
2642    num = 0;
2643
2644    evas_event_freeze(evas_object_evas_get(wd->obj));
2645    EINA_INLIST_FOREACH(wd->blocks, itb)
2646      {
2647         Evas_Coord itminw, itminh;
2648         Elm_Genlist_Item *it;
2649
2650         if (!itb->updateme)
2651           {
2652              num += itb->count;
2653              if (position)
2654                _item_block_position(itb, num);
2655              continue;
2656           }
2657         num0 = num;
2658         recalc = EINA_FALSE;
2659         EINA_LIST_FOREACH(itb->items, l2, it)
2660           {
2661              if (it->updateme)
2662                {
2663                   itminw = it->minw;
2664                   itminh = it->minh;
2665
2666                   if (it->realized)
2667                     {
2668                        _item_unrealize(it, EINA_FALSE);
2669                        _item_realize(it, num, EINA_FALSE);
2670                        position = EINA_TRUE;
2671                     }
2672                   else
2673                     {
2674                        _item_realize(it, num, EINA_TRUE);
2675                        _item_unrealize(it, EINA_TRUE);
2676                     }
2677                   if ((it->minw != itminw) || (it->minh != itminh))
2678                     recalc = EINA_TRUE;
2679                   it->updateme = EINA_FALSE;
2680                }
2681              num++;
2682           }
2683         itb->updateme = EINA_FALSE;
2684         if (recalc)
2685           {
2686              position = EINA_TRUE;
2687              itb->changed = EINA_TRUE;
2688              _item_block_recalc(itb, num0, EINA_FALSE);
2689              _item_block_position(itb, num0);
2690           }
2691      }
2692    if (position)
2693      {
2694         if (wd->calc_job) ecore_job_del(wd->calc_job);
2695         wd->calc_job = ecore_job_add(_calc_job, wd);
2696      }
2697    evas_event_thaw(evas_object_evas_get(wd->obj));
2698    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
2699 }
2700
2701 static void
2702 _changed_job(void *data)
2703 {
2704    Widget_Data *wd = data; Eina_List *l2;
2705    Item_Block *itb;
2706    int num, num0, position = 0;
2707    Eina_Bool width_changed = EINA_FALSE, height_changed = EINA_FALSE;
2708    if (!wd) return;
2709    wd->changed_job = NULL;
2710    num = 0;
2711    EINA_INLIST_FOREACH(wd->blocks, itb)
2712      {
2713         Evas_Coord itminw, itminh;
2714         Elm_Genlist_Item *it;
2715
2716         if (!itb->changeme)
2717           {
2718              num += itb->count;
2719              if (position)
2720                _item_block_position(itb, num);
2721              continue;
2722           }
2723         num0 = num;
2724         width_changed = height_changed = EINA_FALSE;
2725         EINA_LIST_FOREACH(itb->items, l2, it)
2726           {
2727              if ((!it->mincalcd) && (it->realized))
2728                {
2729                   Evas_Coord mw = -1, mh = -1;
2730                   itminw = it->minw;
2731                   itminh = it->minh;
2732
2733                   if (it->wd->height_for_width) mw = it->wd->w;
2734                   if (!it->display_only)
2735                     elm_coords_finger_size_adjust(1, &mw, 1, &mh);
2736                   if (it->wd->height_for_width) mw = it->wd->prev_viewport_w;
2737                   edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw, mh);
2738                   if (!it->display_only)
2739                     elm_coords_finger_size_adjust(1, &mw, 1, &mh);
2740                   it->w = it->minw = mw;
2741                   it->h = it->minh = mh;
2742                   it->mincalcd = EINA_TRUE;
2743
2744                   //if ((it->minw != itminw) || (it->minh != itminh))
2745                   //if ((it->minh != itminh))
2746                   //  recalc = 1;
2747                   if ((it->minw != itminw))
2748                     width_changed = EINA_TRUE;
2749                   if ((it->minh != itminh))
2750                     height_changed = EINA_TRUE;
2751
2752                   if ((!it->wd->group_item_width) && (it->flags == ELM_GENLIST_ITEM_GROUP))
2753                     {
2754                        it->wd->group_item_width = mw;
2755                        it->wd->group_item_height = mh;
2756                     }
2757                   else if ((!it->wd->item_width) && (it->flags == ELM_GENLIST_ITEM_NONE))
2758                     {
2759                        it->wd->item_width = mw;
2760                        it->wd->item_height = mh;
2761                     }
2762                }
2763              num++;
2764           }
2765         itb->changeme = EINA_FALSE;
2766         // TODO: why this is separated.
2767         if (height_changed)
2768           {
2769              position = 1;
2770              itb->changed = EINA_TRUE;
2771              _item_block_recalc(itb, num0, 0);
2772              _item_block_position(itb, num0);
2773           }
2774         else if (width_changed)
2775           {
2776              _item_block_position(itb, num0);
2777           }
2778      }
2779    if (position)
2780      {
2781         if (wd->calc_job) ecore_job_del(wd->calc_job);
2782         wd->calc_job = ecore_job_add(_calc_job, wd);
2783      }
2784 }
2785
2786 static void
2787 _pan_set(Evas_Object *obj,
2788          Evas_Coord   x,
2789          Evas_Coord   y)
2790 {
2791    Pan *sd = evas_object_smart_data_get(obj);
2792 #ifdef ANCHOR_ITEM
2793    Item_Block *itb;
2794 #endif
2795
2796    if (!sd) return;
2797    //   Evas_Coord ow, oh;
2798    //   evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2799    //   ow = sd->wd->minw - ow;
2800    //   if (ow < 0) ow = 0;
2801    //   oh = sd->wd->minh - oh;
2802    //   if (oh < 0) oh = 0;
2803    //   if (x < 0) x = 0;
2804    //   if (y < 0) y = 0;
2805    //   if (x > ow) x = ow;
2806    //   if (y > oh) y = oh;
2807    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2808    sd->wd->pan_x = x;
2809    sd->wd->pan_y = y;
2810
2811 #ifdef ANCHOR_ITEM
2812    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2813      {
2814         if ((itb->y + itb->h) > y)
2815           {
2816              Elm_Genlist_Item *it;
2817              Eina_List *l2;
2818
2819              EINA_LIST_FOREACH(itb->items, l2, it)
2820                {
2821                   if ((itb->y + it->y) >= y)
2822                     {
2823                        sd->wd->anchor_item = it;
2824                        sd->wd->anchor_y = -(itb->y + it->y - y);
2825                        goto done;
2826                     }
2827                }
2828           }
2829      }
2830 done:
2831 #endif
2832    if (!sd->wd->reorder_move_animator) evas_object_smart_changed(obj);
2833 }
2834
2835 static void
2836 _pan_get(Evas_Object *obj,
2837          Evas_Coord  *x,
2838          Evas_Coord  *y)
2839 {
2840    Pan *sd = evas_object_smart_data_get(obj);
2841
2842    if (!sd) return;
2843    if (x) *x = sd->wd->pan_x;
2844    if (y) *y = sd->wd->pan_y;
2845 }
2846
2847 static void
2848 _pan_max_get(Evas_Object *obj,
2849              Evas_Coord  *x,
2850              Evas_Coord  *y)
2851 {
2852    Pan *sd = evas_object_smart_data_get(obj);
2853    Evas_Coord ow, oh;
2854
2855    if (!sd) return;
2856    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2857    ow = sd->wd->minw - ow;
2858    if (ow < 0) ow = 0;
2859    oh = sd->wd->minh - oh;
2860    if (oh < 0) oh = 0;
2861    if (x) *x = ow;
2862    if (y) *y = oh;
2863 }
2864
2865 static void
2866 _pan_min_get(Evas_Object *obj __UNUSED__,
2867              Evas_Coord  *x,
2868              Evas_Coord  *y)
2869 {
2870    if (x) *x = 0;
2871    if (y) *y = 0;
2872 }
2873
2874 static void
2875 _pan_child_size_get(Evas_Object *obj,
2876                     Evas_Coord  *w,
2877                     Evas_Coord  *h)
2878 {
2879    Pan *sd = evas_object_smart_data_get(obj);
2880
2881    if (!sd) return;
2882    if (w) *w = sd->wd->minw;
2883    if (h) *h = sd->wd->minh;
2884 }
2885
2886 static void
2887 _pan_add(Evas_Object *obj)
2888 {
2889    Pan *sd;
2890    Evas_Object_Smart_Clipped_Data *cd;
2891
2892    _pan_sc.add(obj);
2893    cd = evas_object_smart_data_get(obj);
2894    sd = ELM_NEW(Pan);
2895    if (!sd) return;
2896    sd->__clipped_data = *cd;
2897    free(cd);
2898    evas_object_smart_data_set(obj, sd);
2899 }
2900
2901 static void
2902 _pan_del(Evas_Object *obj)
2903 {
2904    Pan *sd = evas_object_smart_data_get(obj);
2905
2906    if (!sd) return;
2907    if (sd->resize_job)
2908      {
2909         ecore_job_del(sd->resize_job);
2910         sd->resize_job = NULL;
2911      }
2912    _pan_sc.del(obj);
2913 }
2914
2915 static void
2916 _pan_resize_job(void *data)
2917 {
2918    Pan *sd = data;
2919    if (!sd) return;
2920    _sizing_eval(sd->wd->obj);
2921    sd->resize_job = NULL;
2922 }
2923
2924 static void
2925 _pan_resize(Evas_Object *obj,
2926             Evas_Coord   w,
2927             Evas_Coord   h)
2928 {
2929    Pan *sd = evas_object_smart_data_get(obj);
2930    Evas_Coord ow, oh;
2931
2932    if (!sd) return;
2933    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2934    if ((ow == w) && (oh == h)) return;
2935    if ((sd->wd->height_for_width) && (ow != w))
2936      {
2937         sd->wd->pan_resize = EINA_TRUE;
2938         if (sd->resize_job) ecore_job_del(sd->resize_job);
2939         sd->resize_job = ecore_job_add(_pan_resize_job, sd);
2940      }
2941    sd->wd->pan_changed = EINA_TRUE;
2942    evas_object_smart_changed(obj);
2943    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2944    sd->wd->calc_job = NULL;
2945 }
2946
2947 static void
2948 _pan_calculate(Evas_Object *obj)
2949 {
2950    Pan *sd = evas_object_smart_data_get(obj);
2951    Item_Block *itb;
2952    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh;
2953    int in = 0;
2954    Elm_Genlist_Item *git;
2955    Eina_List *l;
2956
2957    if (!sd) return;
2958    evas_event_freeze(evas_object_evas_get(obj));
2959
2960    if (sd->wd->pan_changed)
2961      {
2962         _calc_job(sd->wd);
2963         sd->wd->pan_changed = EINA_FALSE;
2964      }
2965
2966    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2967    sd->wd->prev_viewport_w = ow;
2968    evas_output_viewport_get(evas_object_evas_get(obj), &cvx, &cvy, &cvw, &cvh);
2969    EINA_LIST_FOREACH(sd->wd->group_items, l, git)
2970      {
2971         git->want_realize = EINA_FALSE;
2972      }
2973    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2974      {
2975         itb->w = sd->wd->minw;
2976         if (ELM_RECTS_INTERSECT(itb->x - sd->wd->pan_x + ox,
2977                                 itb->y - sd->wd->pan_y + oy,
2978                                 itb->w, itb->h,
2979                                 cvx, cvy, cvw, cvh))
2980           {
2981              if ((!itb->realized) || (itb->changed))
2982                _item_block_realize(itb);
2983              _item_block_position(itb, in);
2984           }
2985         else
2986           {
2987              if (itb->realized) _item_block_unrealize(itb);
2988           }
2989         in += itb->count;
2990      }
2991    if ((!sd->wd->reorder_it) || (sd->wd->reorder_pan_move))
2992       _group_items_recalc(sd->wd);
2993
2994    if ((sd->wd->reorder_mode) && (sd->wd->reorder_it))
2995      {
2996         if (sd->wd->pan_y != sd->wd->old_pan_y)
2997           sd->wd->reorder_pan_move = EINA_TRUE;
2998         else sd->wd->reorder_pan_move = EINA_FALSE;
2999         evas_object_raise(sd->wd->reorder_it->edit_obj);
3000         sd->wd->old_pan_y = sd->wd->pan_y;
3001         sd->wd->start_time = ecore_loop_time_get();
3002      }
3003
3004       if (sd->wd->effect_mode &&
3005           ((sd->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND) ||
3006            (sd->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT) ||
3007            (sd->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE)))
3008         {
3009            if (!sd->wd->item_moving_effect_timer)
3010              {
3011                 if (sd->wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE)
3012                    _item_flip_effect_show(sd->wd->expand_item);
3013
3014                 evas_object_raise(sd->wd->alpha_bg);
3015                 evas_object_show(sd->wd->alpha_bg);
3016                 elm_smart_scroller_bounce_animator_disabled_set(sd->wd->scr, EINA_TRUE);
3017                 sd->wd->start_time = current_time_get();
3018                 sd->wd->item_moving_effect_timer = ecore_animator_add(_item_moving_effect_timer_cb, sd->wd);
3019              }
3020         }
3021       else _item_auto_scroll(sd->wd);
3022    sd->wd->pan_resize = EINA_FALSE;
3023    evas_event_thaw(evas_object_evas_get(obj));
3024    evas_event_thaw_eval(evas_object_evas_get(obj));
3025 }
3026
3027 static void
3028 _pan_move(Evas_Object *obj,
3029           Evas_Coord   x __UNUSED__,
3030           Evas_Coord   y __UNUSED__)
3031 {
3032    Pan *sd = evas_object_smart_data_get(obj);
3033
3034    if (!sd) return;
3035
3036    sd->wd->pan_changed = EINA_TRUE;
3037    evas_object_smart_changed(obj);
3038    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
3039    sd->wd->calc_job = NULL;
3040 }
3041
3042 static void
3043 _hold_on(void        *data __UNUSED__,
3044          Evas_Object *obj,
3045          void        *event_info __UNUSED__)
3046 {
3047    Widget_Data *wd = elm_widget_data_get(obj);
3048    if (!wd) return;
3049    elm_smart_scroller_hold_set(wd->scr, 1);
3050 }
3051
3052 static void
3053 _hold_off(void        *data __UNUSED__,
3054           Evas_Object *obj,
3055           void        *event_info __UNUSED__)
3056 {
3057    Widget_Data *wd = elm_widget_data_get(obj);
3058    if (!wd) return;
3059    elm_smart_scroller_hold_set(wd->scr, 0);
3060 }
3061
3062 static void
3063 _freeze_on(void        *data __UNUSED__,
3064            Evas_Object *obj,
3065            void        *event_info __UNUSED__)
3066 {
3067    Widget_Data *wd = elm_widget_data_get(obj);
3068    if (!wd) return;
3069    elm_smart_scroller_freeze_set(wd->scr, 1);
3070 }
3071
3072 static void
3073 _freeze_off(void        *data __UNUSED__,
3074             Evas_Object *obj,
3075             void        *event_info __UNUSED__)
3076 {
3077    Widget_Data *wd = elm_widget_data_get(obj);
3078    if (!wd) return;
3079    elm_smart_scroller_freeze_set(wd->scr, 0);
3080 }
3081
3082 static void
3083 _scroll_edge_left(void        *data,
3084                   Evas_Object *scr __UNUSED__,
3085                   void        *event_info __UNUSED__)
3086 {
3087    Evas_Object *obj = data;
3088    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_LEFT, NULL);
3089 }
3090
3091 static void
3092 _scroll_edge_right(void        *data,
3093                    Evas_Object *scr __UNUSED__,
3094                    void        *event_info __UNUSED__)
3095 {
3096    Evas_Object *obj = data;
3097    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_RIGHT, NULL);
3098 }
3099
3100 static void
3101 _scroll_edge_top(void        *data,
3102                  Evas_Object *scr __UNUSED__,
3103                  void        *event_info __UNUSED__)
3104 {
3105    Evas_Object *obj = data;
3106    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_TOP, NULL);
3107 }
3108
3109 static void
3110 _scroll_edge_bottom(void        *data,
3111                     Evas_Object *scr __UNUSED__,
3112                     void        *event_info __UNUSED__)
3113 {
3114    Evas_Object *obj = data;
3115    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_BOTTOM, NULL);
3116 }
3117
3118 static void
3119 _mode_item_realize(Elm_Genlist_Item *it)
3120 {
3121    char buf[1024];
3122
3123    if ((it->mode_view) || (it->delete_me)) return;
3124
3125    evas_event_freeze(evas_object_evas_get(it->wd->obj));
3126    it->mode_view = edje_object_add(evas_object_evas_get(it->base.widget));
3127    edje_object_scale_set(it->mode_view,
3128                          elm_widget_scale_get(it->base.widget) *
3129                          _elm_config->scale);
3130    evas_object_smart_member_add(it->mode_view, it->wd->pan_smart);
3131    elm_widget_sub_object_add(it->base.widget, it->mode_view);
3132
3133    strncpy(buf, "item", sizeof(buf));
3134    if (it->wd->compress)
3135      strncat(buf, "_compress", sizeof(buf) - strlen(buf));
3136
3137    if (it->order_num_in & 0x1) strncat(buf, "_odd", sizeof(buf) - strlen(buf));
3138    strncat(buf, "/", sizeof(buf) - strlen(buf));
3139    strncat(buf, it->itc->mode_item_style, sizeof(buf) - strlen(buf));
3140
3141    _elm_theme_object_set(it->base.widget, it->mode_view, "genlist", buf,
3142                          elm_widget_style_get(it->base.widget));
3143    edje_object_mirrored_set(it->mode_view,
3144                             elm_widget_mirrored_get(it->base.widget));
3145
3146    /* signal callback add */
3147    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_DOWN,
3148                                   _mouse_down, it);
3149    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_UP,
3150                                   _mouse_up, it);
3151    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_MOVE,
3152                                   _mouse_move, it);
3153
3154    /* label_get, icon_get, state_get */
3155    _item_label_realize(it, it->mode_view, &it->mode_labels);
3156    if (it->itc->func.icon_get)
3157      {
3158         const Eina_List *l;
3159         const char *key;
3160
3161         it->mode_icons =
3162            elm_widget_stringlist_get(edje_object_data_get(it->mode_view,
3163                                                           "icons"));
3164         EINA_LIST_FOREACH(it->mode_icons, l, key)
3165          {
3166            Evas_Object *ic = it->itc->func.icon_get
3167                 ((void *)it->base.data, it->base.widget, l->data);
3168
3169              if (ic)
3170                {
3171                   it->mode_icon_objs = eina_list_append(it->mode_icon_objs, ic);
3172                   edje_object_part_swallow(it->mode_view, key, ic);
3173                   evas_object_show(ic);
3174                   elm_widget_sub_object_add(it->base.widget, ic);
3175                   if (it->disabled)
3176                     elm_widget_disabled_set(ic, EINA_TRUE);
3177                }
3178           }
3179      }
3180    _item_state_realize(it, it->mode_view, &it->mode_states);
3181    edje_object_part_swallow(it->mode_view,
3182                             edje_object_data_get(it->mode_view, "mode_part"),
3183                             it->base.view);
3184
3185    it->want_unrealize = EINA_FALSE;
3186    evas_event_thaw(evas_object_evas_get(it->wd->obj));
3187    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
3188 }
3189
3190 static void
3191 _mode_item_unrealize(Elm_Genlist_Item *it)
3192 {
3193    Widget_Data *wd = it->wd;
3194    Evas_Object *icon;
3195    if (!it->mode_view) return;
3196
3197    evas_event_freeze(evas_object_evas_get(it->wd->obj));
3198    elm_widget_stringlist_free(it->mode_labels);
3199    it->mode_labels = NULL;
3200    elm_widget_stringlist_free(it->mode_icons);
3201    it->mode_icons = NULL;
3202    elm_widget_stringlist_free(it->mode_states);
3203
3204    EINA_LIST_FREE(it->mode_icon_objs, icon)
3205      evas_object_del(icon);
3206
3207    edje_object_part_unswallow(it->mode_view, it->base.view);
3208    evas_object_smart_member_add(it->base.view, wd->pan_smart);
3209    evas_object_del(it->mode_view);
3210    it->mode_view = NULL;
3211
3212    if (wd->mode_item == it)
3213      wd->mode_item = NULL;
3214    evas_event_thaw(evas_object_evas_get(it->wd->obj));
3215    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
3216 }
3217
3218 static void
3219 _item_mode_set(Elm_Genlist_Item *it)
3220 {
3221    if (!it) return;
3222    Widget_Data *wd = it->wd;
3223    if (!wd) return;
3224    char buf[1024];
3225
3226    wd->mode_item = it;
3227    it->nocache = EINA_TRUE;
3228
3229    if (wd->scr_hold_timer)
3230      {
3231         ecore_timer_del(wd->scr_hold_timer);
3232         wd->scr_hold_timer = NULL;
3233      }
3234    elm_smart_scroller_hold_set(wd->scr, EINA_TRUE);
3235    wd->scr_hold_timer = ecore_timer_add(0.1, _scr_hold_timer_cb, wd);
3236
3237    evas_event_freeze(evas_object_evas_get(it->wd->obj));
3238    _mode_item_realize(it);
3239    if (it->group_item)
3240      evas_object_raise(it->group_item->base.view);
3241    _item_position(it, it->mode_view, it->scrl_x, it->scrl_y);
3242    evas_event_thaw(evas_object_evas_get(it->wd->obj));
3243    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
3244
3245    snprintf(buf, sizeof(buf), "elm,state,%s,active", wd->mode_type);
3246    edje_object_signal_emit(it->mode_view, buf, "elm");
3247 }
3248
3249 static void
3250 _item_mode_unset(Widget_Data *wd)
3251 {
3252    if (!wd) return;
3253    if (!wd->mode_item) return;
3254    char buf[1024], buf2[1024];
3255    Elm_Genlist_Item *it;
3256
3257    it = wd->mode_item;
3258    it->nocache = EINA_TRUE;
3259
3260    snprintf(buf, sizeof(buf), "elm,state,%s,passive", wd->mode_type);
3261    snprintf(buf2, sizeof(buf2), "elm,state,%s,passive,finished", wd->mode_type);
3262
3263    edje_object_signal_emit(it->mode_view, buf, "elm");
3264    edje_object_signal_callback_add(it->mode_view, buf2, "elm", _mode_finished_signal_cb, it);
3265
3266    wd->mode_item = NULL;
3267 }
3268
3269
3270 static void
3271 _item_auto_scroll(void *data)
3272 {
3273    Widget_Data *wd = data;
3274    if (!wd) return;
3275
3276    if ((wd->expand_item) && (!wd->auto_scrolled))
3277      {
3278         Elm_Genlist_Item  *it;
3279         Eina_List *l;
3280         Evas_Coord ox, oy, ow, oh;
3281         evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
3282
3283         wd->auto_scrolled = EINA_TRUE;
3284         if (wd->expand_item->scrl_y > (oh + oy) / 2)
3285           {
3286             EINA_LIST_FOREACH(wd->expand_item->items, l, it)
3287               {
3288                  elm_genlist_item_bring_in(it);
3289               }
3290           }
3291      }
3292 }
3293 EAPI Evas_Object *
3294 elm_genlist_add(Evas_Object *parent)
3295 {
3296    Evas_Object *obj;
3297    Evas *e;
3298    Widget_Data *wd;
3299    Evas_Coord minw, minh;
3300    static Evas_Smart *smart = NULL;
3301
3302    if (!smart)
3303      {
3304         static Evas_Smart_Class sc;
3305
3306         evas_object_smart_clipped_smart_set(&_pan_sc);
3307         sc = _pan_sc;
3308         sc.name = "elm_genlist_pan";
3309         sc.version = EVAS_SMART_CLASS_VERSION;
3310         sc.add = _pan_add;
3311         sc.del = _pan_del;
3312         sc.resize = _pan_resize;
3313         sc.move = _pan_move;
3314         sc.calculate = _pan_calculate;
3315         if (!(smart = evas_smart_class_new(&sc))) return NULL;
3316      }
3317
3318    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
3319
3320    ELM_SET_WIDTYPE(widtype, "genlist");
3321    elm_widget_type_set(obj, "genlist");
3322    elm_widget_sub_object_add(parent, obj);
3323    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
3324    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
3325    elm_widget_data_set(obj, wd);
3326    elm_widget_del_hook_set(obj, _del_hook);
3327    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
3328    elm_widget_theme_hook_set(obj, _theme_hook);
3329    elm_widget_can_focus_set(obj, EINA_TRUE);
3330    elm_widget_event_hook_set(obj, _event_hook);
3331    elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
3332
3333    wd->scr = elm_smart_scroller_add(e);
3334    elm_smart_scroller_widget_set(wd->scr, obj);
3335    elm_smart_scroller_object_theme_set(obj, wd->scr, "genlist", "base",
3336                                        elm_widget_style_get(obj));
3337    elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
3338                                        _elm_config->thumbscroll_bounce_enable);
3339    elm_widget_resize_object_set(obj, wd->scr);
3340
3341    evas_object_smart_callback_add(wd->scr, "edge,left", _scroll_edge_left, obj);
3342    evas_object_smart_callback_add(wd->scr, "edge,right", _scroll_edge_right,
3343                                   obj);
3344    evas_object_smart_callback_add(wd->scr, "edge,top", _scroll_edge_top, obj);
3345    evas_object_smart_callback_add(wd->scr, "edge,bottom", _scroll_edge_bottom,
3346                                   obj);
3347
3348    wd->obj = obj;
3349    wd->mode = ELM_LIST_SCROLL;
3350    wd->max_items_per_block = MAX_ITEMS_PER_BLOCK;
3351    wd->item_cache_max = wd->max_items_per_block * 2;
3352    wd->longpress_timeout = _elm_config->longpress_timeout;
3353    wd->effect_mode = _elm_config->effect_enable;
3354
3355    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
3356    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
3357    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
3358    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
3359
3360    wd->pan_smart = evas_object_smart_add(e, smart);
3361    wd->pan = evas_object_smart_data_get(wd->pan_smart);
3362    wd->pan->wd = wd;
3363
3364    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
3365                                      _pan_set, _pan_get, _pan_max_get,
3366                                      _pan_min_get, _pan_child_size_get);
3367
3368    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
3369                              &minw, &minh);
3370    evas_object_size_hint_min_set(obj, minw, minh);
3371
3372    evas_object_smart_callbacks_descriptions_set(obj, _signals);
3373    _mirrored_set(obj, elm_widget_mirrored_get(obj));
3374    _sizing_eval(obj);
3375    return obj;
3376 }
3377
3378 static Elm_Genlist_Item *
3379 _item_new(Widget_Data                  *wd,
3380           const Elm_Genlist_Item_Class *itc,
3381           const void                   *data,
3382           Elm_Genlist_Item             *parent,
3383           Elm_Genlist_Item_Flags        flags,
3384           Evas_Smart_Cb                 func,
3385           const void                   *func_data)
3386 {
3387    Elm_Genlist_Item *it;
3388
3389    it = elm_widget_item_new(wd->obj, Elm_Genlist_Item);
3390    if (!it) return NULL;
3391    it->wd = wd;
3392    it->itc = itc;
3393    it->base.data = data;
3394    it->parent = parent;
3395    it->flags = flags;
3396    it->func.func = func;
3397    it->func.data = func_data;
3398    it->mouse_cursor = NULL;
3399    it->expanded_depth = 0;
3400    elm_widget_item_text_get_hook_set(it, _item_label_hook);
3401    elm_widget_item_del_cb_set(it, _item_del_hook);
3402
3403    if (it->parent)
3404      {
3405         if (it->parent->flags & ELM_GENLIST_ITEM_GROUP)
3406           it->group_item = parent;
3407         else if (it->parent->group_item)
3408           it->group_item = it->parent->group_item;
3409      }
3410    return it;
3411 }
3412
3413 static void
3414 _item_block_add(Widget_Data      *wd,
3415                 Elm_Genlist_Item *it)
3416 {
3417    Item_Block *itb = NULL;
3418
3419    if (!it->rel)
3420      {
3421 newblock:
3422         if (it->rel)
3423           {
3424              itb = calloc(1, sizeof(Item_Block));
3425              if (!itb) return;
3426              itb->wd = wd;
3427              if (!it->rel->block)
3428                {
3429                   wd->blocks =
3430                     eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
3431                   itb->items = eina_list_append(itb->items, it);
3432                }
3433              else
3434                {
3435                   if (it->before)
3436                     {
3437                        wd->blocks = eina_inlist_prepend_relative
3438                            (wd->blocks, EINA_INLIST_GET(itb),
3439                            EINA_INLIST_GET(it->rel->block));
3440                        itb->items =
3441                          eina_list_prepend_relative(itb->items, it, it->rel);
3442                     }
3443                   else
3444                     {
3445                        wd->blocks = eina_inlist_append_relative
3446                            (wd->blocks, EINA_INLIST_GET(itb),
3447                            EINA_INLIST_GET(it->rel->block));
3448                        itb->items =
3449                          eina_list_append_relative(itb->items, it, it->rel);
3450                     }
3451                }
3452           }
3453         else
3454           {
3455              if (it->before)
3456                {
3457                   if (wd->blocks)
3458                     {
3459                        itb = (Item_Block *)(wd->blocks);
3460                        if (itb->count >= wd->max_items_per_block)
3461                          {
3462                             itb = calloc(1, sizeof(Item_Block));
3463                             if (!itb) return;
3464                             itb->wd = wd;
3465                             wd->blocks =
3466                               eina_inlist_prepend(wd->blocks,
3467                                                   EINA_INLIST_GET(itb));
3468                          }
3469                     }
3470                   else
3471                     {
3472                        itb = calloc(1, sizeof(Item_Block));
3473                        if (!itb) return;
3474                        itb->wd = wd;
3475                        wd->blocks =
3476                          eina_inlist_prepend(wd->blocks, EINA_INLIST_GET(itb));
3477                     }
3478                   itb->items = eina_list_prepend(itb->items, it);
3479                }
3480              else
3481                {
3482                   if (wd->blocks)
3483                     {
3484                        itb = (Item_Block *)(wd->blocks->last);
3485                        if (itb->count >= wd->max_items_per_block)
3486                          {
3487                             itb = calloc(1, sizeof(Item_Block));
3488                             if (!itb) return;
3489                             itb->wd = wd;
3490                             wd->blocks =
3491                               eina_inlist_append(wd->blocks,
3492                                                  EINA_INLIST_GET(itb));
3493                          }
3494                     }
3495                   else
3496                     {
3497                        itb = calloc(1, sizeof(Item_Block));
3498                        if (!itb) return;
3499                        itb->wd = wd;
3500                        wd->blocks =
3501                          eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
3502                     }
3503                   itb->items = eina_list_append(itb->items, it);
3504                }
3505           }
3506      }
3507    else
3508      {
3509         itb = it->rel->block;
3510         if (!itb) goto newblock;
3511         if (it->before)
3512           itb->items = eina_list_prepend_relative(itb->items, it, it->rel);
3513         else
3514           itb->items = eina_list_append_relative(itb->items, it, it->rel);
3515      }
3516    itb->count++;
3517    itb->changed = EINA_TRUE;
3518    it->block = itb;
3519    if (itb->wd->calc_job) ecore_job_del(itb->wd->calc_job);
3520    itb->wd->calc_job = ecore_job_add(_calc_job, itb->wd);
3521    if (it->rel)
3522      {
3523         it->rel->relcount--;
3524         if ((it->rel->delete_me) && (!it->rel->relcount))
3525           _item_del(it->rel);
3526         it->rel = NULL;
3527      }
3528    if (itb->count > itb->wd->max_items_per_block)
3529      {
3530         int newc;
3531         Item_Block *itb2;
3532         Elm_Genlist_Item *it2;
3533
3534         newc = itb->count / 2;
3535         itb2 = calloc(1, sizeof(Item_Block));
3536         if (!itb2) return;
3537         itb2->wd = wd;
3538         wd->blocks =
3539           eina_inlist_append_relative(wd->blocks, EINA_INLIST_GET(itb2),
3540                                       EINA_INLIST_GET(itb));
3541         itb2->changed = EINA_TRUE;
3542         while ((itb->count > newc) && (itb->items))
3543           {
3544              Eina_List *l;
3545
3546              l = eina_list_last(itb->items);
3547              it2 = l->data;
3548              itb->items = eina_list_remove_list(itb->items, l);
3549              itb->count--;
3550
3551              itb2->items = eina_list_prepend(itb2->items, it2);
3552              it2->block = itb2;
3553              itb2->count++;
3554           }
3555      }
3556 }
3557
3558 static int
3559 _queue_process(Widget_Data *wd)
3560 {
3561    int n;
3562    Eina_Bool showme = EINA_FALSE;
3563    double t0, t;
3564
3565    t0 = ecore_time_get();
3566    //evas_event_freeze(evas_object_evas_get(wd->obj));
3567    for (n = 0; (wd->queue) && (n < 128); n++)
3568      {
3569         Elm_Genlist_Item *it;
3570
3571         it = wd->queue->data;
3572         wd->queue = eina_list_remove_list(wd->queue, wd->queue);
3573         it->queued = EINA_FALSE;
3574         _item_block_add(wd, it);
3575         t = ecore_time_get();
3576         if (it->block->changed)
3577           {
3578              showme = _item_block_recalc(it->block, it->block->num, EINA_TRUE);
3579              it->block->changed = 0;
3580           }
3581         if (showme) it->block->showme = EINA_TRUE;
3582         if (eina_inlist_count(wd->blocks) > 1)
3583           {
3584              if ((t - t0) > (ecore_animator_frametime_get())) break;
3585           }
3586      }
3587    //evas_event_thaw(evas_object_evas_get(wd->obj));
3588    //evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3589    return n;
3590 }
3591
3592 static Eina_Bool
3593 _idle_process(void *data, Eina_Bool *wakeup)
3594 {
3595    Widget_Data *wd = data;
3596
3597    //xxx
3598    //static double q_start = 0.0;
3599    //if (q_start == 0.0) q_start = ecore_time_get();
3600    //xxx
3601    if (_queue_process(wd) > 0) *wakeup = EINA_TRUE;
3602    if (!wd->queue)
3603      {
3604         //xxx
3605         //printf("PROCESS TIME: %3.3f\n", ecore_time_get() - q_start);
3606         //xxx
3607         return ECORE_CALLBACK_CANCEL;
3608      }
3609    return ECORE_CALLBACK_RENEW;
3610 }
3611
3612 static Eina_Bool
3613 _item_idle_enterer(void *data)
3614 {
3615    Widget_Data *wd = data;
3616    Eina_Bool wakeup = EINA_FALSE;
3617    Eina_Bool ok = _idle_process(data, &wakeup);
3618
3619    if (wakeup)
3620      {
3621         // wake up mainloop
3622         if (wd->calc_job) ecore_job_del(wd->calc_job);
3623         wd->calc_job = ecore_job_add(_calc_job, wd);
3624      }
3625    if (ok == ECORE_CALLBACK_CANCEL) wd->queue_idle_enterer = NULL;
3626    return ok;
3627 }
3628
3629 static void
3630 _item_queue(Widget_Data      *wd,
3631             Elm_Genlist_Item *it)
3632 {
3633    if (it->queued) return;
3634    it->queued = EINA_TRUE;
3635    wd->queue = eina_list_append(wd->queue, it);
3636 // FIXME: why does a freeze then thaw here cause some genlist
3637 // elm_genlist_item_append() to be much much slower?
3638 //   evas_event_freeze(evas_object_evas_get(wd->obj));
3639    while ((wd->queue) && ((!wd->blocks) || (!wd->blocks->next)))
3640      {
3641         if (wd->queue_idle_enterer)
3642           {
3643              ecore_idle_enterer_del(wd->queue_idle_enterer);
3644              wd->queue_idle_enterer = NULL;
3645           }
3646         _queue_process(wd);
3647      }
3648 //   evas_event_thaw(evas_object_evas_get(wd->obj));
3649 //   evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3650    if (!wd->queue_idle_enterer)
3651      wd->queue_idle_enterer = ecore_idle_enterer_add(_item_idle_enterer, wd);
3652 }
3653
3654 static void
3655 _item_move_after(Elm_Genlist_Item *it, Elm_Genlist_Item *after)
3656 {
3657    if (!it) return;
3658    if (!after) return;
3659
3660    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
3661    it->wd->reorder_deleted = EINA_TRUE;
3662    _item_block_del(it);
3663
3664    it->wd->items = eina_inlist_append_relative(it->wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(after));
3665    it->rel = after;
3666    it->rel->relcount++;
3667    it->before = EINA_FALSE;
3668    if (after->group_item) it->group_item = after->group_item;
3669    _item_queue(it->wd, it);
3670
3671    // TODO: change this to smart callback
3672    if (it->itc->func.moved)
3673      it->itc->func.moved(it->base.widget, it, after, EINA_TRUE);
3674 }
3675
3676 static void
3677 _item_move_before(Elm_Genlist_Item *it, Elm_Genlist_Item *before)
3678 {
3679    if (!it) return;
3680    if (!before) return;
3681
3682    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
3683    it->wd->reorder_deleted = EINA_TRUE;
3684    _item_block_del(it);
3685    it->wd->items = eina_inlist_prepend_relative(it->wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(before));
3686    it->rel = before;
3687    it->rel->relcount++;
3688    it->before = EINA_TRUE;
3689    if (before->group_item) it->group_item = before->group_item;
3690    _item_queue(it->wd, it);
3691
3692    // TODO: change this to smart callback
3693    if (it->itc->func.moved)
3694      it->itc->func.moved(it->base.widget, it, before, EINA_FALSE);
3695 }
3696
3697 EAPI Elm_Genlist_Item *
3698 elm_genlist_item_append(Evas_Object                  *obj,
3699                         const Elm_Genlist_Item_Class *itc,
3700                         const void                   *data,
3701                         Elm_Genlist_Item             *parent,
3702                         Elm_Genlist_Item_Flags        flags,
3703                         Evas_Smart_Cb                 func,
3704                         const void                   *func_data)
3705 {
3706    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3707    Widget_Data *wd = elm_widget_data_get(obj);
3708    if (!wd) return NULL;
3709    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3710                                     func_data);
3711    if (!it) return NULL;
3712    if (!it->parent)
3713      {
3714         if (flags & ELM_GENLIST_ITEM_GROUP)
3715           wd->group_items = eina_list_append(wd->group_items, it);
3716         wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
3717         it->rel = NULL;
3718      }
3719    else
3720      {
3721         Elm_Genlist_Item *it2 = NULL;
3722         Eina_List *ll = eina_list_last(it->parent->items);
3723         if (ll) it2 = ll->data;
3724         it->parent->items = eina_list_append(it->parent->items, it);
3725         if (!it2) it2 = it->parent;
3726         if (it2->delete_me)
3727            it2 = elm_genlist_item_prev_get(it2);
3728         wd->items =
3729           eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3730                                       EINA_INLIST_GET(it2));
3731         it->rel = it2;
3732         it->rel->relcount++;
3733      }
3734    it->before = EINA_FALSE;
3735    _item_queue(wd, it);
3736    return it;
3737 }
3738
3739 EAPI Elm_Genlist_Item *
3740 elm_genlist_item_prepend(Evas_Object                  *obj,
3741                          const Elm_Genlist_Item_Class *itc,
3742                          const void                   *data,
3743                          Elm_Genlist_Item             *parent,
3744                          Elm_Genlist_Item_Flags        flags,
3745                          Evas_Smart_Cb                 func,
3746                          const void                   *func_data)
3747 {
3748    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3749    Widget_Data *wd = elm_widget_data_get(obj);
3750    if (!wd) return NULL;
3751    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3752                                     func_data);
3753    if (!it) return NULL;
3754    if (!it->parent)
3755      {
3756         if (flags & ELM_GENLIST_ITEM_GROUP)
3757           wd->group_items = eina_list_prepend(wd->group_items, it);
3758         wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
3759         it->rel = NULL;
3760      }
3761    else
3762      {
3763         Elm_Genlist_Item *it2 = NULL;
3764         Eina_List *ll = it->parent->items;
3765         if (ll) it2 = ll->data;
3766         it->parent->items = eina_list_prepend(it->parent->items, it);
3767         if (!it2) it2 = it->parent;
3768         if (it2->delete_me)
3769            it2 = elm_genlist_item_next_get(it2);
3770         wd->items =
3771           eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3772                                        EINA_INLIST_GET(it2));
3773         it->rel = it2;
3774         it->rel->relcount++;
3775      }
3776    it->before = EINA_TRUE;
3777    _item_queue(wd, it);
3778    return it;
3779 }
3780
3781 EAPI Elm_Genlist_Item *
3782 elm_genlist_item_insert_after(Evas_Object                  *obj,
3783                               const Elm_Genlist_Item_Class *itc,
3784                               const void                   *data,
3785                               Elm_Genlist_Item             *parent,
3786                               Elm_Genlist_Item             *after,
3787                               Elm_Genlist_Item_Flags        flags,
3788                               Evas_Smart_Cb                 func,
3789                               const void                   *func_data)
3790 {
3791    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3792    EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
3793    Widget_Data *wd = elm_widget_data_get(obj);
3794    if (!wd) return NULL;
3795    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3796                                     func_data);
3797    if (!it) return NULL;
3798    /* It makes no sense to insert after in an empty list with after != NULL, something really bad is happening in your app. */
3799    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->items, NULL);
3800
3801    if (!it->parent)
3802      {
3803         if ((flags & ELM_GENLIST_ITEM_GROUP) &&
3804             (after->flags & ELM_GENLIST_ITEM_GROUP))
3805           wd->group_items = eina_list_append_relative(wd->group_items, it,
3806                                                       after);
3807      }
3808    else
3809      {
3810         it->parent->items = eina_list_append_relative(it->parent->items, it,
3811                                                       after);
3812      }
3813    wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3814                                            EINA_INLIST_GET(after));
3815    it->rel = after;
3816    it->rel->relcount++;
3817    it->before = EINA_FALSE;
3818    _item_queue(wd, it);
3819    return it;
3820 }
3821
3822 EAPI Elm_Genlist_Item *
3823 elm_genlist_item_insert_before(Evas_Object                  *obj,
3824                                const Elm_Genlist_Item_Class *itc,
3825                                const void                   *data,
3826                                Elm_Genlist_Item             *parent,
3827                                Elm_Genlist_Item             *before,
3828                                Elm_Genlist_Item_Flags        flags,
3829                                Evas_Smart_Cb                 func,
3830                                const void                   *func_data)
3831 {
3832    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3833    EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
3834    Widget_Data *wd = elm_widget_data_get(obj);
3835    if (!wd) return NULL;
3836    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3837                                     func_data);
3838    if (!it) return NULL;
3839    /* It makes no sense to insert before in an empty list with before != NULL, something really bad is happening in your app. */
3840    EINA_SAFETY_ON_NULL_RETURN_VAL(wd->items, NULL);
3841
3842    if (!it->parent)
3843      {
3844         if ((flags & ELM_GENLIST_ITEM_GROUP) &&
3845             (before->flags & ELM_GENLIST_ITEM_GROUP))
3846           wd->group_items = eina_list_prepend_relative(wd->group_items, it,
3847                                                        before);
3848      }
3849    else
3850      {
3851         it->parent->items = eina_list_prepend_relative(it->parent->items, it,
3852                                                        before);
3853      }
3854    wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3855                                             EINA_INLIST_GET(before));
3856    it->rel = before;
3857    it->rel->relcount++;
3858    it->before = EINA_TRUE;
3859    _item_queue(wd, it);
3860    return it;
3861 }
3862
3863 EAPI void
3864 elm_genlist_clear(Evas_Object *obj)
3865 {
3866    ELM_CHECK_WIDTYPE(obj, widtype);
3867    Widget_Data *wd = elm_widget_data_get(obj);
3868    if (!wd) return;
3869    if (wd->walking > 0)
3870      {
3871         Elm_Genlist_Item *it;
3872
3873         wd->clear_me = EINA_TRUE;
3874         EINA_INLIST_FOREACH(wd->items, it)
3875           {
3876              it->delete_me = EINA_TRUE;
3877           }
3878         return;
3879      }
3880    evas_event_freeze(evas_object_evas_get(wd->obj));
3881    while (wd->items)
3882      {
3883         Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3884         it->nocache = EINA_TRUE;
3885         it->highlighted = EINA_FALSE;
3886 #ifdef ANCHOR_ITEM
3887         if (wd->anchor_item == it)
3888           {
3889              wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3890              if (!wd->anchor_item)
3891                wd->anchor_item =
3892                  ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3893           }
3894 #endif
3895         wd->items = eina_inlist_remove(wd->items, wd->items);
3896         if (it->flags & ELM_GENLIST_ITEM_GROUP)
3897           it->wd->group_items = eina_list_remove(it->wd->group_items, it);
3898         elm_widget_item_pre_notify_del(it);
3899         if (it->realized) _item_unrealize(it, EINA_FALSE);
3900         if (((wd->clear_me) || (!it->delete_me)) && (it->itc->func.del))
3901           it->itc->func.del((void *)it->base.data, it->base.widget);
3902         if (it->long_timer) ecore_timer_del(it->long_timer);
3903         if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
3904         elm_widget_item_del(it);
3905      }
3906    wd->clear_me = EINA_FALSE;
3907    wd->anchor_item = NULL;
3908    while (wd->blocks)
3909      {
3910         Item_Block *itb = (Item_Block *)(wd->blocks);
3911
3912         wd->blocks = eina_inlist_remove(wd->blocks, wd->blocks);
3913         if (itb->items) eina_list_free(itb->items);
3914         free(itb);
3915      }
3916    if (wd->calc_job)
3917      {
3918         ecore_job_del(wd->calc_job);
3919         wd->calc_job = NULL;
3920      }
3921    if (wd->queue_idle_enterer)
3922      {
3923         ecore_idle_enterer_del(wd->queue_idle_enterer);
3924         wd->queue_idle_enterer = NULL;
3925      }
3926    if (wd->must_recalc_idler)
3927      {
3928         ecore_idler_del(wd->must_recalc_idler);
3929         wd->must_recalc_idler = NULL;
3930      }
3931    if (wd->queue)
3932      {
3933         eina_list_free(wd->queue);
3934         wd->queue = NULL;
3935      }
3936    if (wd->selected)
3937      {
3938         eina_list_free(wd->selected);
3939         wd->selected = NULL;
3940      }
3941    if (wd->reorder_move_animator)
3942      {
3943         ecore_animator_del(wd->reorder_move_animator);
3944         wd->reorder_move_animator = NULL;
3945      }
3946    wd->show_item = NULL;
3947    wd->pan_x = 0;
3948    wd->pan_y = 0;
3949    wd->old_pan_y = 0;
3950    wd->minw = 0;
3951    wd->minh = 0;
3952
3953    if (wd->alpha_bg)
3954       evas_object_del(wd->alpha_bg);
3955    wd->alpha_bg = NULL;
3956
3957    if (wd->pan_smart)
3958      {
3959         evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
3960         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
3961      }
3962    _sizing_eval(obj);
3963    elm_smart_scroller_child_region_show(wd->scr, 0, 0, 0, 0);
3964    evas_event_thaw(evas_object_evas_get(wd->obj));
3965    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3966 }
3967
3968 EAPI void
3969 elm_genlist_multi_select_set(Evas_Object *obj,
3970                              Eina_Bool    multi)
3971 {
3972    ELM_CHECK_WIDTYPE(obj, widtype);
3973    Widget_Data *wd = elm_widget_data_get(obj);
3974    if (!wd) return;
3975    wd->multi = multi;
3976 }
3977
3978 EAPI Eina_Bool
3979 elm_genlist_multi_select_get(const Evas_Object *obj)
3980 {
3981    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3982    Widget_Data *wd = elm_widget_data_get(obj);
3983    if (!wd) return EINA_FALSE;
3984    return wd->multi;
3985 }
3986
3987 EAPI Elm_Genlist_Item *
3988 elm_genlist_selected_item_get(const Evas_Object *obj)
3989 {
3990    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3991    Widget_Data *wd = elm_widget_data_get(obj);
3992    if (!wd) return NULL;
3993    if (wd->selected) return wd->selected->data;
3994    return NULL;
3995 }
3996
3997 EAPI const Eina_List *
3998 elm_genlist_selected_items_get(const Evas_Object *obj)
3999 {
4000    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4001    Widget_Data *wd = elm_widget_data_get(obj);
4002    if (!wd) return NULL;
4003    return wd->selected;
4004 }
4005
4006 EAPI Eina_List *
4007 elm_genlist_realized_items_get(const Evas_Object *obj)
4008 {
4009    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4010    Widget_Data *wd = elm_widget_data_get(obj);
4011    Eina_List *list = NULL;
4012    Item_Block *itb;
4013    Eina_Bool done = EINA_FALSE;
4014    if (!wd) return NULL;
4015    EINA_INLIST_FOREACH(wd->blocks, itb)
4016      {
4017         if (itb->realized)
4018           {
4019              Eina_List *l;
4020              Elm_Genlist_Item *it;
4021
4022              done = 1;
4023              EINA_LIST_FOREACH(itb->items, l, it)
4024                {
4025                   if (it->realized) list = eina_list_append(list, it);
4026                }
4027           }
4028         else
4029           {
4030              if (done) break;
4031           }
4032      }
4033    return list;
4034 }
4035
4036 EAPI Elm_Genlist_Item *
4037 elm_genlist_at_xy_item_get(const Evas_Object *obj,
4038                            Evas_Coord         x,
4039                            Evas_Coord         y,
4040                            int               *posret)
4041 {
4042    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4043    Widget_Data *wd = elm_widget_data_get(obj);
4044    Evas_Coord ox, oy, ow, oh;
4045    Item_Block *itb;
4046    Evas_Coord lasty;
4047    if (!wd) return NULL;
4048    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
4049    lasty = oy;
4050    EINA_INLIST_FOREACH(wd->blocks, itb)
4051      {
4052         Eina_List *l;
4053         Elm_Genlist_Item *it;
4054
4055         if (!ELM_RECTS_INTERSECT(ox + itb->x - itb->wd->pan_x,
4056                                  oy + itb->y - itb->wd->pan_y,
4057                                  itb->w, itb->h, x, y, 1, 1))
4058           continue;
4059         EINA_LIST_FOREACH(itb->items, l, it)
4060           {
4061              Evas_Coord itx, ity;
4062
4063              itx = ox + itb->x + it->x - itb->wd->pan_x;
4064              ity = oy + itb->y + it->y - itb->wd->pan_y;
4065              if (ELM_RECTS_INTERSECT(itx, ity, it->w, it->h, x, y, 1, 1))
4066                {
4067                   if (posret)
4068                     {
4069                        if (y <= (ity + (it->h / 4))) *posret = -1;
4070                        else if (y >= (ity + it->h - (it->h / 4)))
4071                          *posret = 1;
4072                        else *posret = 0;
4073                     }
4074                   return it;
4075                }
4076              lasty = ity + it->h;
4077           }
4078      }
4079    if (posret)
4080      {
4081         if (y > lasty) *posret = 1;
4082         else *posret = -1;
4083      }
4084    return NULL;
4085 }
4086
4087 EAPI Elm_Genlist_Item *
4088 elm_genlist_first_item_get(const Evas_Object *obj)
4089 {
4090    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4091    Widget_Data *wd = elm_widget_data_get(obj);
4092    if (!wd) return NULL;
4093    if (!wd->items) return NULL;
4094    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
4095    while ((it) && (it->delete_me))
4096      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
4097    return it;
4098 }
4099
4100 EAPI Elm_Genlist_Item *
4101 elm_genlist_last_item_get(const Evas_Object *obj)
4102 {
4103    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4104    Widget_Data *wd = elm_widget_data_get(obj);
4105    if (!wd) return NULL;
4106    if (!wd->items) return NULL;
4107    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items->last);
4108    while ((it) && (it->delete_me))
4109      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
4110    return it;
4111 }
4112
4113 EAPI Elm_Genlist_Item *
4114 elm_genlist_item_next_get(const Elm_Genlist_Item *it)
4115 {
4116    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4117    while (it)
4118      {
4119         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
4120         if ((it) && (!it->delete_me)) break;
4121      }
4122    return (Elm_Genlist_Item *)it;
4123 }
4124
4125 EAPI Elm_Genlist_Item *
4126 elm_genlist_item_prev_get(const Elm_Genlist_Item *it)
4127 {
4128    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4129    while (it)
4130      {
4131         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
4132         if ((it) && (!it->delete_me)) break;
4133      }
4134    return (Elm_Genlist_Item *)it;
4135 }
4136
4137 EAPI Evas_Object *
4138 elm_genlist_item_genlist_get(const Elm_Genlist_Item *it)
4139 {
4140    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4141    return it->base.widget;
4142 }
4143
4144 EAPI Elm_Genlist_Item *
4145 elm_genlist_item_parent_get(const Elm_Genlist_Item *it)
4146 {
4147    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4148    return it->parent;
4149 }
4150
4151 EAPI void
4152 elm_genlist_item_subitems_clear(Elm_Genlist_Item *it)
4153 {
4154    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4155    Elm_Genlist_Item *it2;
4156    Evas_Coord y, h;
4157
4158    if (!it->wd->effect_mode || !it->wd->move_effect_mode)
4159       _item_subitems_clear(it);
4160    else
4161      {
4162         if ((!it->wd->item_moving_effect_timer) && (it->flags != ELM_GENLIST_ITEM_GROUP) &&
4163              it->wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE    )
4164           {
4165              it->wd->expand_item = it;
4166              _item_flip_effect_show(it);
4167              evas_object_geometry_get(it->base.view, NULL, &y, NULL, &h);
4168              it->wd->expand_item_end = y + h;
4169
4170               it2= it;
4171              do {
4172                   it2 = elm_genlist_item_next_get(it2);
4173                   if (!it2) break;
4174              } while (it2->expanded_depth > it->expanded_depth);
4175              if (it2)
4176                 it->wd->expand_item_gap = it->wd->expand_item_end - it2->old_scrl_y;
4177              else
4178                 it->wd->expand_item_gap = 0;
4179
4180              evas_object_raise(it->wd->alpha_bg);
4181              evas_object_show(it->wd->alpha_bg);
4182
4183              it->wd->start_time = current_time_get();
4184              it->wd->item_moving_effect_timer = ecore_animator_add(_item_moving_effect_timer_cb, it->wd);
4185           }
4186         else
4187            _item_subitems_clear(it);
4188      }
4189 }
4190
4191 EAPI void
4192 elm_genlist_item_selected_set(Elm_Genlist_Item *it,
4193                               Eina_Bool         selected)
4194 {
4195    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4196    Widget_Data *wd = elm_widget_data_get(it->base.widget);
4197    if (!wd) return;
4198    if ((it->delete_me) || (it->disabled)) return;
4199    selected = !!selected;
4200    if (it->selected == selected) return;
4201
4202    if (selected)
4203      {
4204         if (!wd->multi)
4205           {
4206              while (wd->selected)
4207                _item_unselect(wd->selected->data);
4208           }
4209         _item_highlight(it);
4210         _item_select(it);
4211      }
4212    else
4213      _item_unselect(it);
4214 }
4215
4216 EAPI Eina_Bool
4217 elm_genlist_item_selected_get(const Elm_Genlist_Item *it)
4218 {
4219    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4220    return it->selected;
4221 }
4222
4223 EAPI void
4224 elm_genlist_item_expanded_set(Elm_Genlist_Item *it,
4225                               Eina_Bool         expanded)
4226 {
4227    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4228    if (it->flags != ELM_GENLIST_ITEM_SUBITEMS) return;
4229    if (it->expanded == expanded) return;
4230    it->expanded = expanded;
4231    it->wd->expand_item = it;
4232
4233    if (it->wd->effect_mode && !it->wd->alpha_bg)
4234       it->wd->alpha_bg = _create_tray_alpha_bg(it->base.widget);
4235
4236    if (it->expanded)
4237      {
4238         it->wd->auto_scrolled = EINA_FALSE;
4239         it->wd->move_effect_mode = ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND;
4240         if (it->realized)
4241           edje_object_signal_emit(it->base.view, "elm,state,expanded", "elm");
4242         evas_object_smart_callback_call(it->base.widget, "expanded", it);
4243      }
4244    else
4245      {
4246         it->wd->move_effect_mode = ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT;
4247         if (it->realized)
4248           edje_object_signal_emit(it->base.view, "elm,state,contracted", "elm");
4249         evas_object_smart_callback_call(it->base.widget, "contracted", it);
4250      }
4251 }
4252
4253 EAPI Eina_Bool
4254 elm_genlist_item_expanded_get(const Elm_Genlist_Item *it)
4255 {
4256    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4257    return it->expanded;
4258 }
4259
4260 EAPI int
4261 elm_genlist_item_expanded_depth_get(const Elm_Genlist_Item *it)
4262 {
4263    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, 0);
4264    return it->expanded_depth;
4265 }
4266
4267 EAPI void
4268 elm_genlist_item_disabled_set(Elm_Genlist_Item *it,
4269                               Eina_Bool         disabled)
4270 {
4271    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4272    Eina_List *l;
4273    Evas_Object *obj;
4274    if (it->disabled == disabled) return;
4275    if (it->delete_me) return;
4276    it->disabled = !!disabled;
4277    if (it->selected)
4278      elm_genlist_item_selected_set(it, EINA_FALSE);
4279    if (it->realized)
4280      {
4281         if (it->disabled)
4282           {
4283              edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
4284              if (it->edit_obj)
4285                edje_object_signal_emit(it->edit_obj, "elm,state,disabled", "elm");
4286           }
4287         else
4288           {
4289              edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
4290              if (it->edit_obj)
4291                edje_object_signal_emit(it->edit_obj, "elm,state,enabled", "elm");
4292           }
4293         EINA_LIST_FOREACH(it->icon_objs, l, obj)
4294            elm_widget_disabled_set(obj, disabled);
4295      }
4296 }
4297
4298 EAPI Eina_Bool
4299 elm_genlist_item_disabled_get(const Elm_Genlist_Item *it)
4300 {
4301    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4302    if (it->delete_me) return EINA_FALSE;
4303    return it->disabled;
4304 }
4305
4306 EAPI void
4307 elm_genlist_item_display_only_set(Elm_Genlist_Item *it,
4308                                   Eina_Bool         display_only)
4309 {
4310    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4311    if (it->display_only == display_only) return;
4312    if (it->delete_me) return;
4313    it->display_only = display_only;
4314    it->mincalcd = EINA_FALSE;
4315    it->updateme = EINA_TRUE;
4316    if (it->block) it->block->updateme = EINA_TRUE;
4317    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4318    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4319 }
4320
4321 EAPI Eina_Bool
4322 elm_genlist_item_display_only_get(const Elm_Genlist_Item *it)
4323 {
4324    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4325    if (it->delete_me) return EINA_FALSE;
4326    return it->display_only;
4327 }
4328
4329 EAPI void
4330 elm_genlist_item_show(Elm_Genlist_Item *it)
4331 {
4332    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4333    Evas_Coord gith = 0;
4334    if (it->delete_me) return;
4335    if ((it->queued) || (!it->mincalcd))
4336      {
4337         it->wd->show_item = it;
4338         it->wd->bring_in = EINA_TRUE;
4339         it->showme = EINA_TRUE;
4340         return;
4341      }
4342    if (it->wd->show_item)
4343      {
4344         it->wd->show_item->showme = EINA_FALSE;
4345         it->wd->show_item = NULL;
4346      }
4347    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4348      gith = it->group_item->h;
4349    elm_smart_scroller_child_region_show(it->wd->scr,
4350                                         it->x + it->block->x,
4351                                         it->y + it->block->y - gith,
4352                                         it->block->w, it->h);
4353 }
4354
4355 EAPI void
4356 elm_genlist_item_bring_in(Elm_Genlist_Item *it)
4357 {
4358    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4359    Evas_Coord gith = 0;
4360    if (it->delete_me) return;
4361    if ((it->queued) || (!it->mincalcd))
4362      {
4363         it->wd->show_item = it;
4364         it->wd->bring_in = EINA_TRUE;
4365         it->showme = EINA_TRUE;
4366         return;
4367      }
4368    if (it->wd->show_item)
4369      {
4370         it->wd->show_item->showme = EINA_FALSE;
4371         it->wd->show_item = NULL;
4372      }
4373    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4374      gith = it->group_item->h;
4375    elm_smart_scroller_region_bring_in(it->wd->scr,
4376                                       it->x + it->block->x,
4377                                       it->y + it->block->y - gith,
4378                                       it->block->w, it->h);
4379 }
4380
4381 EAPI void
4382 elm_genlist_item_top_show(Elm_Genlist_Item *it)
4383 {
4384    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4385    Evas_Coord ow, oh;
4386    Evas_Coord gith = 0;
4387
4388    if (it->delete_me) return;
4389    if ((it->queued) || (!it->mincalcd))
4390      {
4391         it->wd->show_item = it;
4392         it->wd->bring_in = EINA_TRUE;
4393         it->showme = EINA_TRUE;
4394         return;
4395      }
4396    if (it->wd->show_item)
4397      {
4398         it->wd->show_item->showme = EINA_FALSE;
4399         it->wd->show_item = NULL;
4400      }
4401    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4402    if (it->group_item) gith = it->group_item->h;
4403    elm_smart_scroller_child_region_show(it->wd->scr,
4404                                         it->x + it->block->x,
4405                                         it->y + it->block->y - gith,
4406                                         it->block->w, oh);
4407 }
4408
4409 EAPI void
4410 elm_genlist_item_top_bring_in(Elm_Genlist_Item *it)
4411 {
4412    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4413    Evas_Coord ow, oh;
4414    Evas_Coord gith = 0;
4415
4416    if (it->delete_me) return;
4417    if ((it->queued) || (!it->mincalcd))
4418      {
4419         it->wd->show_item = it;
4420         it->wd->bring_in = EINA_TRUE;
4421         it->showme = EINA_TRUE;
4422         return;
4423      }
4424    if (it->wd->show_item)
4425      {
4426         it->wd->show_item->showme = EINA_FALSE;
4427         it->wd->show_item = NULL;
4428      }
4429    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4430    if (it->group_item) gith = it->group_item->h;
4431    elm_smart_scroller_region_bring_in(it->wd->scr,
4432                                       it->x + it->block->x,
4433                                       it->y + it->block->y - gith,
4434                                       it->block->w, oh);
4435 }
4436
4437 EAPI void
4438 elm_genlist_item_middle_show(Elm_Genlist_Item *it)
4439 {
4440    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4441    Evas_Coord ow, oh;
4442
4443    if (it->delete_me) return;
4444    if ((it->queued) || (!it->mincalcd))
4445      {
4446         it->wd->show_item = it;
4447         it->wd->bring_in = EINA_TRUE;
4448         it->showme = EINA_TRUE;
4449         return;
4450      }
4451    if (it->wd->show_item)
4452      {
4453         it->wd->show_item->showme = EINA_FALSE;
4454         it->wd->show_item = NULL;
4455      }
4456    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4457    elm_smart_scroller_child_region_show(it->wd->scr,
4458                                         it->x + it->block->x,
4459                                         it->y + it->block->y - oh / 2 +
4460                                         it->h / 2, it->block->w, oh);
4461 }
4462
4463 EAPI void
4464 elm_genlist_item_middle_bring_in(Elm_Genlist_Item *it)
4465 {
4466    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4467    Evas_Coord ow, oh;
4468
4469    if (it->delete_me) return;
4470    if ((it->queued) || (!it->mincalcd))
4471      {
4472         it->wd->show_item = it;
4473         it->wd->bring_in = EINA_TRUE;
4474         it->showme = EINA_TRUE;
4475         return;
4476      }
4477    if (it->wd->show_item)
4478      {
4479         it->wd->show_item->showme = EINA_FALSE;
4480         it->wd->show_item = NULL;
4481      }
4482    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4483    elm_smart_scroller_region_bring_in(it->wd->scr,
4484                                       it->x + it->block->x,
4485                                       it->y + it->block->y - oh / 2 + it->h / 2,
4486                                       it->block->w, oh);
4487 }
4488
4489 EAPI void
4490 elm_genlist_item_del(Elm_Genlist_Item *it)
4491 {
4492    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4493    if ((it->relcount > 0) || (it->walking > 0))
4494      {
4495         elm_widget_item_pre_notify_del(it);
4496         elm_genlist_item_subitems_clear(it);
4497         it->delete_me = EINA_TRUE;
4498         if (it->wd->show_item == it) it->wd->show_item = NULL;
4499         if (it->selected)
4500           it->wd->selected = eina_list_remove(it->wd->selected,
4501                                               it);
4502         if (it->block)
4503           {
4504              if (it->realized) _item_unrealize(it, EINA_FALSE);
4505              it->block->changed = EINA_TRUE;
4506              if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
4507              it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
4508           }
4509         if (it->itc->func.del)
4510           it->itc->func.del((void *)it->base.data, it->base.widget);
4511         return;
4512      }
4513    _item_del(it);
4514 }
4515
4516 EAPI void
4517 elm_genlist_item_data_set(Elm_Genlist_Item *it,
4518                           const void       *data)
4519 {
4520    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4521    elm_widget_item_data_set(it, data);
4522    elm_genlist_item_update(it);
4523 }
4524
4525 EAPI void *
4526 elm_genlist_item_data_get(const Elm_Genlist_Item *it)
4527 {
4528    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4529    return elm_widget_item_data_get(it);
4530 }
4531
4532 EAPI void
4533 elm_genlist_item_icons_orphan(Elm_Genlist_Item *it)
4534 {
4535    Evas_Object *icon;
4536    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4537    EINA_LIST_FREE(it->icon_objs, icon)
4538      {
4539         elm_widget_sub_object_del(it->base.widget, icon);
4540         evas_object_smart_member_del(icon);
4541         evas_object_hide(icon);
4542      }
4543 }
4544
4545 EAPI const Evas_Object *
4546 elm_genlist_item_object_get(const Elm_Genlist_Item *it)
4547 {
4548    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4549    return it->base.view;
4550 }
4551
4552 EAPI void
4553 elm_genlist_item_update(Elm_Genlist_Item *it)
4554 {
4555    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4556    if (!it->block) return;
4557    if (it->delete_me) return;
4558    it->mincalcd = EINA_FALSE;
4559    it->updateme = EINA_TRUE;
4560    it->block->updateme = EINA_TRUE;
4561    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4562    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4563    it->defer_unrealize = EINA_FALSE;
4564 }
4565
4566 EAPI void
4567 elm_genlist_item_item_class_update(Elm_Genlist_Item             *it,
4568                                    const Elm_Genlist_Item_Class *itc)
4569 {
4570    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4571    if (!it->block) return;
4572    EINA_SAFETY_ON_NULL_RETURN(itc);
4573    if (it->delete_me) return;
4574    it->itc = itc;
4575    it->nocache = EINA_TRUE;
4576    elm_genlist_item_update(it);
4577 }
4578
4579 EAPI const Elm_Genlist_Item_Class *
4580 elm_genlist_item_item_class_get(const Elm_Genlist_Item *it)
4581 {
4582    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4583    if (it->delete_me) return NULL;
4584    return it->itc;
4585 }
4586 static Evas_Object *
4587 _elm_genlist_item_label_create(void        *data,
4588                                Evas_Object *obj,
4589                                void        *item __UNUSED__)
4590 {
4591    Evas_Object *label = elm_label_add(obj);
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 }