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