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