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