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