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