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