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