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