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