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