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