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