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