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