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