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