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