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