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