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