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