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