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