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