Elementary lib: Removed trailing whitespaces except for flip.
[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
1557    evas_event_freeze(evas_object_evas_get(obj));
1558    it->nocache = EINA_FALSE;
1559    _mode_item_unrealize(it);
1560    snprintf(buf, sizeof(buf), "elm,state,%s,passive,finished", it->wd->mode_type);
1561    edje_object_signal_callback_del_full(obj, buf, "elm", _mode_finished_signal_cb, it);
1562    evas_event_thaw(evas_object_evas_get(obj));
1563    evas_event_thaw_eval(evas_object_evas_get(obj));
1564 }
1565
1566 static void
1567 _item_cache_clean(Widget_Data *wd)
1568 {
1569    evas_event_freeze(evas_object_evas_get(wd->obj));
1570    while ((wd->item_cache) && (wd->item_cache_count > wd->item_cache_max))
1571      {
1572         Item_Cache *itc;
1573
1574         itc = EINA_INLIST_CONTAINER_GET(wd->item_cache->last, Item_Cache);
1575         wd->item_cache = eina_inlist_remove(wd->item_cache,
1576                                             wd->item_cache->last);
1577         wd->item_cache_count--;
1578         if (itc->spacer) evas_object_del(itc->spacer);
1579         if (itc->base_view) evas_object_del(itc->base_view);
1580         if (itc->item_style) eina_stringshare_del(itc->item_style);
1581         free(itc);
1582      }
1583    evas_event_thaw(evas_object_evas_get(wd->obj));
1584    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
1585 }
1586
1587 static void
1588 _item_cache_zero(Widget_Data *wd)
1589 {
1590    int pmax = wd->item_cache_max;
1591    wd->item_cache_max = 0;
1592    _item_cache_clean(wd);
1593    wd->item_cache_max = pmax;
1594 }
1595
1596 static void
1597 _item_cache_add(Elm_Genlist_Item *it)
1598 {
1599    Item_Cache *itc;
1600
1601    evas_event_freeze(evas_object_evas_get(it->wd->obj));
1602    if (it->wd->item_cache_max <= 0)
1603      {
1604         evas_object_del(it->base.view);
1605         it->base.view = NULL;
1606         evas_object_del(it->spacer);
1607         it->spacer = NULL;
1608         evas_event_thaw(evas_object_evas_get(it->wd->obj));
1609         evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
1610         return;
1611      }
1612
1613    it->wd->item_cache_count++;
1614    itc = calloc(1, sizeof(Item_Cache));
1615    it->wd->item_cache = eina_inlist_prepend(it->wd->item_cache,
1616                                             EINA_INLIST_GET(itc));
1617    itc->spacer = it->spacer;
1618    it->spacer = NULL;
1619    itc->base_view = it->base.view;
1620    it->base.view = NULL;
1621    evas_object_hide(itc->base_view);
1622    evas_object_move(itc->base_view, -9999, -9999);
1623    itc->item_style = eina_stringshare_add(it->itc->item_style);
1624    if (it->flags & ELM_GENLIST_ITEM_SUBITEMS) itc->tree = 1;
1625    itc->compress = (it->wd->compress);
1626    itc->selected = it->selected;
1627    itc->disabled = it->disabled;
1628    itc->expanded = it->expanded;
1629    if (it->long_timer)
1630      {
1631         ecore_timer_del(it->long_timer);
1632         it->long_timer = NULL;
1633      }
1634    if (it->swipe_timer)
1635      {
1636         ecore_timer_del(it->swipe_timer);
1637         it->swipe_timer = NULL;
1638      }
1639    // FIXME: other callbacks?
1640    edje_object_signal_callback_del_full(itc->base_view,
1641                                         "elm,action,expand,toggle",
1642                                         "elm", _signal_expand_toggle, it);
1643    edje_object_signal_callback_del_full(itc->base_view, "elm,action,expand",
1644                                         "elm",
1645                                         _signal_expand, it);
1646    edje_object_signal_callback_del_full(itc->base_view, "elm,action,contract",
1647                                         "elm", _signal_contract, it);
1648    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MOUSE_DOWN,
1649                                        _mouse_down, it);
1650    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MOUSE_UP,
1651                                        _mouse_up, it);
1652    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MOUSE_MOVE,
1653                                        _mouse_move, it);
1654    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MULTI_DOWN,
1655                                        _multi_down, it);
1656    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MULTI_UP,
1657                                        _multi_up, it);
1658    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MULTI_MOVE,
1659                                        _multi_move, it);
1660    _item_cache_clean(it->wd);
1661    evas_event_thaw(evas_object_evas_get(it->wd->obj));
1662    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
1663 }
1664
1665 static Item_Cache *
1666 _item_cache_find(Elm_Genlist_Item *it)
1667 {
1668    Item_Cache *itc;
1669    Eina_Bool tree = 0;
1670
1671    if (it->flags & ELM_GENLIST_ITEM_SUBITEMS) tree = 1;
1672    EINA_INLIST_FOREACH(it->wd->item_cache, itc)
1673      {
1674         if ((itc->selected) || (itc->disabled) || (itc->expanded))
1675           continue;
1676         if ((itc->tree == tree) &&
1677             (itc->compress == it->wd->compress) &&
1678             (!strcmp(it->itc->item_style, itc->item_style)))
1679           {
1680              it->wd->item_cache = eina_inlist_remove(it->wd->item_cache,
1681                                                      EINA_INLIST_GET(itc));
1682              it->wd->item_cache_count--;
1683              return itc;
1684           }
1685      }
1686    return NULL;
1687 }
1688
1689 static void
1690 _elm_genlist_item_odd_even_update(Elm_Genlist_Item *it)
1691 {
1692    if (!it->nostacking)
1693      {
1694         if ((it->order_num_in & 0x1) ^ it->stacking_even)
1695           evas_object_lower(it->base.view);
1696         else
1697           evas_object_raise(it->base.view);
1698      }
1699
1700    if (it->order_num_in & 0x1)
1701      edje_object_signal_emit(it->base.view, "elm,state,odd", "elm");
1702    else
1703      edje_object_signal_emit(it->base.view, "elm,state,even", "elm");
1704 }
1705
1706 static void
1707 _elm_genlist_item_state_update(Elm_Genlist_Item *it, Item_Cache *itc)
1708 {
1709    if (itc)
1710      {
1711         if (it->selected != itc->selected)
1712           {
1713              if (it->selected)
1714                edje_object_signal_emit(it->base.view,
1715                                        "elm,state,selected", "elm");
1716           }
1717         if (it->disabled != itc->disabled)
1718           {
1719              if (it->disabled)
1720                edje_object_signal_emit(it->base.view,
1721                                        "elm,state,disabled", "elm");
1722           }
1723         if (it->expanded != itc->expanded)
1724           {
1725              if (it->expanded)
1726                edje_object_signal_emit(it->base.view,
1727                                        "elm,state,expanded", "elm");
1728           }
1729      }
1730    else
1731      {
1732         if (it->selected)
1733           edje_object_signal_emit(it->base.view,
1734                                   "elm,state,selected", "elm");
1735         if (it->disabled)
1736           edje_object_signal_emit(it->base.view,
1737                                   "elm,state,disabled", "elm");
1738         if (it->expanded)
1739           edje_object_signal_emit(it->base.view,
1740                                   "elm,state,expanded", "elm");
1741      }
1742 }
1743
1744 static void
1745 _item_cache_free(Item_Cache *itc)
1746 {
1747    if (itc->spacer) evas_object_del(itc->spacer);
1748    if (itc->base_view) evas_object_del(itc->base_view);
1749    if (itc->item_style) eina_stringshare_del(itc->item_style);
1750    free(itc);
1751 }
1752
1753 static void
1754 _item_label_realize(Elm_Genlist_Item *it,
1755                     Evas_Object *target,
1756                     Eina_List **source)
1757 {
1758    if (it->itc->func.label_get)
1759      {
1760         const Eina_List *l;
1761         const char *key;
1762
1763         *source = elm_widget_stringlist_get(edje_object_data_get(target, "labels"));
1764         EINA_LIST_FOREACH(*source, l, key)
1765           {
1766              char *s = it->itc->func.label_get
1767                 ((void *)it->base.data, it->base.widget, key);
1768
1769              if (s)
1770                {
1771                   edje_object_part_text_set(target, key, s);
1772                   free(s);
1773                }
1774              else
1775                {
1776                   edje_object_part_text_set(target, key, "");
1777                }
1778           }
1779      }
1780 }
1781
1782 static Eina_List *
1783 _item_icon_realize(Elm_Genlist_Item *it,
1784                    Evas_Object *target,
1785                    Eina_List **source)
1786 {
1787    Eina_List *res = NULL;
1788
1789    if (it->itc->func.icon_get)
1790      {
1791         const Eina_List *l;
1792         const char *key;
1793
1794         *source = elm_widget_stringlist_get(edje_object_data_get(target, "icons"));
1795         EINA_LIST_FOREACH(*source, l, key)
1796           {
1797              Evas_Object *ic = it->itc->func.icon_get
1798                 ((void *)it->base.data, it->base.widget, key);
1799
1800              if (ic)
1801                {
1802                   res = eina_list_append(res, ic);
1803                   edje_object_part_swallow(target, key, ic);
1804                   evas_object_show(ic);
1805                   elm_widget_sub_object_add(it->base.widget, ic);
1806                   if (it->disabled)
1807                     elm_widget_disabled_set(ic, EINA_TRUE);
1808                }
1809           }
1810      }
1811
1812    return res;
1813 }
1814
1815 static void
1816 _item_state_realize(Elm_Genlist_Item *it,
1817                     Evas_Object *target,
1818                     Eina_List **source)
1819 {
1820    if (it->itc->func.state_get)
1821      {
1822         const Eina_List *l;
1823         const char *key;
1824         char buf[4096];
1825
1826         *source = elm_widget_stringlist_get(edje_object_data_get(target, "states"));
1827         EINA_LIST_FOREACH(*source, l, key)
1828           {
1829              Eina_Bool on = it->itc->func.state_get
1830                 ((void *)it->base.data, it->base.widget, key);
1831
1832              if (on)
1833                {
1834                   snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1835                   edje_object_signal_emit(target, buf, "elm");
1836                }
1837              else
1838                {
1839                   snprintf(buf, sizeof(buf), "elm,state,%s,passive", key);
1840                   edje_object_signal_emit(target, buf, "elm");
1841                }
1842           }
1843      }
1844 }
1845
1846 static void
1847 _item_realize(Elm_Genlist_Item *it,
1848               int               in,
1849               Eina_Bool         calc)
1850 {
1851    Elm_Genlist_Item *it2;
1852    const char *treesize;
1853    char buf[1024];
1854    int depth, tsize = 20;
1855    Item_Cache *itc = NULL;
1856
1857    if (it->delete_me) return;
1858    evas_event_freeze(evas_object_evas_get(it->wd->obj));
1859    if (it->realized)
1860      {
1861         if (it->order_num_in != in)
1862           {
1863              it->order_num_in = in;
1864              _elm_genlist_item_odd_even_update(it);
1865              _elm_genlist_item_state_update(it, NULL);
1866           }
1867         evas_event_thaw(evas_object_evas_get(it->wd->obj));
1868         evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
1869         return;
1870      }
1871    it->order_num_in = in;
1872
1873    if (it->nocache)
1874      it->nocache = EINA_FALSE;
1875    else
1876      itc = _item_cache_find(it);
1877    if (itc)
1878      {
1879         it->base.view = itc->base_view;
1880         itc->base_view = NULL;
1881         it->spacer = itc->spacer;
1882         itc->spacer = NULL;
1883      }
1884    else
1885      {
1886         const char *stacking_even;
1887         const char *stacking;
1888
1889         it->base.view = edje_object_add(evas_object_evas_get(it->base.widget));
1890         edje_object_scale_set(it->base.view,
1891                               elm_widget_scale_get(it->base.widget) *
1892                               _elm_config->scale);
1893         evas_object_smart_member_add(it->base.view, it->wd->pan_smart);
1894         elm_widget_sub_object_add(it->base.widget, it->base.view);
1895
1896         if (it->flags & ELM_GENLIST_ITEM_SUBITEMS)
1897           strncpy(buf, "tree", sizeof(buf));
1898         else strncpy(buf, "item", sizeof(buf));
1899         if (it->wd->compress)
1900           strncat(buf, "_compress", sizeof(buf) - strlen(buf));
1901
1902         strncat(buf, "/", sizeof(buf) - strlen(buf));
1903         strncat(buf, it->itc->item_style, sizeof(buf) - strlen(buf));
1904
1905         _elm_theme_object_set(it->base.widget, it->base.view, "genlist", buf,
1906                               elm_widget_style_get(it->base.widget));
1907
1908         stacking_even = edje_object_data_get(it->base.view, "stacking_even");
1909         if (!stacking_even) stacking_even = "above";
1910         it->stacking_even = !!strcmp("above", stacking_even);
1911
1912         stacking = edje_object_data_get(it->base.view, "stacking");
1913         if (!stacking) stacking = "yes";
1914         it->nostacking = !!strcmp("yes", stacking);
1915
1916         edje_object_mirrored_set(it->base.view,
1917                                  elm_widget_mirrored_get(it->base.widget));
1918         it->spacer =
1919           evas_object_rectangle_add(evas_object_evas_get(it->base.widget));
1920         evas_object_color_set(it->spacer, 0, 0, 0, 0);
1921         elm_widget_sub_object_add(it->base.widget, it->spacer);
1922      }
1923
1924    _elm_genlist_item_odd_even_update(it);
1925
1926    for (it2 = it, depth = 0; it2->parent; it2 = it2->parent)
1927      {
1928         if (it2->parent->flags != ELM_GENLIST_ITEM_GROUP) depth += 1;
1929      }
1930    it->expanded_depth = depth;
1931    treesize = edje_object_data_get(it->base.view, "treesize");
1932    if (treesize) tsize = atoi(treesize);
1933    evas_object_size_hint_min_set(it->spacer,
1934                                  (depth * tsize) * _elm_config->scale, 1);
1935    edje_object_part_swallow(it->base.view, "elm.swallow.pad", it->spacer);
1936    if (!calc)
1937      {
1938         edje_object_signal_callback_add(it->base.view,
1939                                         "elm,action,expand,toggle",
1940                                         "elm", _signal_expand_toggle, it);
1941         edje_object_signal_callback_add(it->base.view, "elm,action,expand",
1942                                         "elm", _signal_expand, it);
1943         edje_object_signal_callback_add(it->base.view, "elm,action,contract",
1944                                         "elm", _signal_contract, it);
1945         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_DOWN,
1946                                        _mouse_down, it);
1947         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_UP,
1948                                        _mouse_up, it);
1949         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_MOVE,
1950                                        _mouse_move, it);
1951         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_DOWN,
1952                                        _multi_down, it);
1953         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_UP,
1954                                        _multi_up, it);
1955         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_MOVE,
1956                                        _multi_move, it);
1957
1958         _elm_genlist_item_state_update(it, itc);
1959      }
1960
1961    if ((calc) && (it->wd->homogeneous) && ((it->wd->item_width) || ((it->wd->item_width) && (it->wd->group_item_width))))
1962      {
1963         /* homogenous genlist shortcut */
1964         if (!it->mincalcd)
1965           {
1966              if (it->flags & ELM_GENLIST_ITEM_GROUP)
1967                {
1968                   it->w = it->minw = it->wd->group_item_width;
1969                   it->h = it->minh = it->wd->group_item_height;
1970                }
1971              else
1972                {
1973                   it->w = it->minw = it->wd->item_width;
1974                   it->h = it->minh = it->wd->item_height;
1975                }
1976              it->mincalcd = EINA_TRUE;
1977           }
1978      }
1979    else
1980      {
1981         /* FIXME: If you see that assert, please notify us and we
1982            will clean our mess */
1983         assert(eina_list_count(it->icon_objs) == 0);
1984
1985         _item_label_realize(it, it->base.view, &it->labels);
1986         it->icon_objs = _item_icon_realize(it, it->base.view, &it->icons);
1987         _item_state_realize(it, it->base.view, &it->states);
1988
1989         if (!it->mincalcd)
1990           {
1991              Evas_Coord mw = -1, mh = -1;
1992
1993              if (!it->display_only)
1994                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1995              if (it->wd->height_for_width) mw = it->wd->prev_viewport_w;
1996              edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw,
1997                                                   mh);
1998              if (!it->display_only)
1999                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
2000              it->w = it->minw = mw;
2001              it->h = it->minh = mh;
2002              it->mincalcd = EINA_TRUE;
2003
2004              if ((!it->wd->group_item_width) && (it->flags == ELM_GENLIST_ITEM_GROUP))
2005                {
2006                   it->wd->group_item_width = mw;
2007                   it->wd->group_item_height = mh;
2008                }
2009              else if ((!it->wd->item_width) && (it->flags == ELM_GENLIST_ITEM_NONE))
2010                {
2011                   it->wd->item_width = mw;
2012                   it->wd->item_height = mh;
2013                }
2014           }
2015         if (!calc) evas_object_show(it->base.view);
2016      }
2017
2018    if (it->tooltip.content_cb)
2019      {
2020         elm_widget_item_tooltip_content_cb_set(it,
2021                                                it->tooltip.content_cb,
2022                                                it->tooltip.data, NULL);
2023         elm_widget_item_tooltip_style_set(it, it->tooltip.style);
2024      }
2025
2026    if (it->mouse_cursor)
2027      elm_widget_item_cursor_set(it, it->mouse_cursor);
2028
2029    it->realized = EINA_TRUE;
2030    it->want_unrealize = EINA_FALSE;
2031
2032    if (itc) _item_cache_free(itc);
2033    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2034    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2035    if (!calc) evas_object_smart_callback_call(it->base.widget, SIG_REALIZED, it);
2036 }
2037
2038 static void
2039 _item_unrealize(Elm_Genlist_Item *it, Eina_Bool calc)
2040 {
2041    Evas_Object *icon;
2042
2043    if (!it->realized) return;
2044    evas_event_freeze(evas_object_evas_get(it->wd->obj));
2045    if (!calc) evas_object_smart_callback_call(it->base.widget, SIG_UNREALIZED, it);
2046    if (it->long_timer)
2047      {
2048         ecore_timer_del(it->long_timer);
2049         it->long_timer = NULL;
2050      }
2051    if (it->nocache)
2052      {
2053         evas_object_del(it->base.view);
2054         it->base.view = NULL;
2055         evas_object_del(it->spacer);
2056         it->spacer = NULL;
2057      }
2058    else
2059      {
2060         edje_object_mirrored_set(it->base.view, elm_widget_mirrored_get(it->base.widget));
2061         edje_object_scale_set(it->base.view, elm_widget_scale_get(it->base.widget) * _elm_config->scale);
2062         _item_cache_add(it);
2063      }
2064    elm_widget_stringlist_free(it->labels);
2065    it->labels = NULL;
2066    elm_widget_stringlist_free(it->icons);
2067    it->icons = NULL;
2068    elm_widget_stringlist_free(it->states);
2069
2070    EINA_LIST_FREE(it->icon_objs, icon)
2071      evas_object_del(icon);
2072
2073    _mode_item_unrealize(it);
2074    it->states = NULL;
2075    it->realized = EINA_FALSE;
2076    it->want_unrealize = EINA_FALSE;
2077    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2078    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2079 }
2080
2081 static Eina_Bool
2082 _item_block_recalc(Item_Block *itb,
2083                    int         in,
2084                    int         qadd)
2085 {
2086    const Eina_List *l;
2087    Elm_Genlist_Item *it;
2088    Evas_Coord minw = 0, minh = 0;
2089    Eina_Bool showme = EINA_FALSE, changed = EINA_FALSE;
2090    Evas_Coord y = 0;
2091
2092    evas_event_freeze(evas_object_evas_get(itb->wd->obj));
2093    itb->num = in;
2094    EINA_LIST_FOREACH(itb->items, l, it)
2095      {
2096         if (it->delete_me) continue;
2097         showme |= it->showme;
2098         if (!itb->realized)
2099           {
2100              if (qadd)
2101                {
2102                   if (!it->mincalcd) changed = EINA_TRUE;
2103                   if (changed)
2104                     {
2105                        _item_realize(it, in, EINA_TRUE);
2106                        _item_unrealize(it, EINA_TRUE);
2107                     }
2108                }
2109              else
2110                {
2111                   _item_realize(it, in, EINA_TRUE);
2112                   _item_unrealize(it, EINA_TRUE);
2113                }
2114           }
2115         else
2116           _item_realize(it, in, EINA_FALSE);
2117         minh += it->minh;
2118         if (minw < it->minw) minw = it->minw;
2119         in++;
2120         it->x = 0;
2121         it->y = y;
2122         y += it->h;
2123      }
2124    itb->minw = minw;
2125    itb->minh = minh;
2126    itb->changed = EINA_FALSE;
2127    evas_event_thaw(evas_object_evas_get(itb->wd->obj));
2128    evas_event_thaw_eval(evas_object_evas_get(itb->wd->obj));
2129    return showme;
2130 }
2131
2132 static void
2133 _item_block_realize(Item_Block *itb,
2134                     int         in,
2135                     int         full)
2136 {
2137    const Eina_List *l;
2138    Elm_Genlist_Item *it;
2139
2140    if (itb->realized) return;
2141    evas_event_freeze(evas_object_evas_get(itb->wd->obj));
2142    EINA_LIST_FOREACH(itb->items, l, it)
2143      {
2144         if (it->delete_me) continue;
2145         if (full) _item_realize(it, in, EINA_FALSE);
2146         in++;
2147      }
2148    itb->realized = EINA_TRUE;
2149    itb->want_unrealize = EINA_FALSE;
2150    evas_event_thaw(evas_object_evas_get(itb->wd->obj));
2151    evas_event_thaw_eval(evas_object_evas_get(itb->wd->obj));
2152 }
2153
2154 static void
2155 _item_block_unrealize(Item_Block *itb)
2156 {
2157    const Eina_List *l;
2158    Elm_Genlist_Item *it;
2159    Eina_Bool dragging = EINA_FALSE;
2160
2161    if (!itb->realized) return;
2162    evas_event_freeze(evas_object_evas_get(itb->wd->obj));
2163    EINA_LIST_FOREACH(itb->items, l, it)
2164      {
2165         if (it->flags != ELM_GENLIST_ITEM_GROUP)
2166           {
2167              if (it->dragging)
2168                {
2169                   dragging = EINA_TRUE;
2170                   it->want_unrealize = EINA_TRUE;
2171                }
2172              else
2173                _item_unrealize(it, EINA_FALSE);
2174           }
2175      }
2176    if (!dragging)
2177      {
2178         itb->realized = EINA_FALSE;
2179         itb->want_unrealize = EINA_TRUE;
2180      }
2181    else
2182      itb->want_unrealize = EINA_FALSE;
2183    evas_event_thaw(evas_object_evas_get(itb->wd->obj));
2184    evas_event_thaw_eval(evas_object_evas_get(itb->wd->obj));
2185 }
2186
2187 static void
2188 _item_position(Elm_Genlist_Item *it, Evas_Object *view)
2189 {
2190    if (!it) return;
2191    if (!view) return;
2192
2193    evas_event_freeze(evas_object_evas_get(it->wd->obj));
2194    evas_object_resize(view, it->w, it->h);
2195    evas_object_move(view, it->scrl_x, it->scrl_y);
2196    evas_object_show(view);
2197    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2198    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2199 }
2200
2201 static void
2202 _item_block_position(Item_Block *itb,
2203                      int         in)
2204 {
2205    const Eina_List *l;
2206    Elm_Genlist_Item *it;
2207    Elm_Genlist_Item *git;
2208    Evas_Coord y = 0, ox, oy, ow, oh, cvx, cvy, cvw, cvh;
2209    int vis;
2210
2211    evas_event_freeze(evas_object_evas_get(itb->wd->obj));
2212    evas_object_geometry_get(itb->wd->pan_smart, &ox, &oy, &ow, &oh);
2213    evas_output_viewport_get(evas_object_evas_get(itb->wd->obj), &cvx, &cvy,
2214                             &cvw, &cvh);
2215    EINA_LIST_FOREACH(itb->items, l, it)
2216      {
2217         if (it->delete_me) continue;
2218         it->x = 0;
2219         it->y = y;
2220         it->w = itb->w;
2221         it->scrl_x = itb->x + it->x - it->wd->pan_x + ox;
2222         it->scrl_y = itb->y + it->y - it->wd->pan_y + oy;
2223
2224         vis = (ELM_RECTS_INTERSECT(it->scrl_x, it->scrl_y, it->w, it->h,
2225                                    cvx, cvy, cvw, cvh));
2226         if (it->flags != ELM_GENLIST_ITEM_GROUP)
2227           {
2228              if ((itb->realized) && (!it->realized))
2229                {
2230                   if (vis) _item_realize(it, in, EINA_FALSE);
2231                }
2232              if (it->realized)
2233                {
2234                   if (vis)
2235                     {
2236                        git = it->group_item;
2237                        if (git)
2238                          {
2239                             if (git->scrl_y < oy)
2240                               git->scrl_y = oy;
2241                             if ((git->scrl_y + git->h) > (it->scrl_y + it->h))
2242                               git->scrl_y = (it->scrl_y + it->h) - git->h;
2243                             git->want_realize = EINA_TRUE;
2244                          }
2245                        if (it->mode_view)
2246                           _item_position(it, it->mode_view);
2247                        else
2248                           _item_position(it, it->base.view);
2249                     }
2250                   else
2251                     {
2252                        if (!it->dragging) _item_unrealize(it, EINA_FALSE);
2253                     }
2254                }
2255              in++;
2256           }
2257         else
2258           {
2259              if (vis) it->want_realize = EINA_TRUE;
2260           }
2261         y += it->h;
2262      }
2263    evas_event_thaw(evas_object_evas_get(itb->wd->obj));
2264    evas_event_thaw_eval(evas_object_evas_get(itb->wd->obj));
2265 }
2266
2267 static void
2268 _group_items_recalc(void *data)
2269 {
2270    Widget_Data *wd = data;
2271    Eina_List *l;
2272    Elm_Genlist_Item *git;
2273
2274    evas_event_freeze(evas_object_evas_get(wd->obj));
2275    EINA_LIST_FOREACH(wd->group_items, l, git)
2276      {
2277         if (git->want_realize)
2278           {
2279              if (!git->realized)
2280                _item_realize(git, 0, EINA_FALSE);
2281              evas_object_resize(git->base.view, wd->minw, git->h);
2282              evas_object_move(git->base.view, git->scrl_x, git->scrl_y);
2283              evas_object_show(git->base.view);
2284              evas_object_raise(git->base.view);
2285           }
2286         else if (!git->want_realize && git->realized)
2287           {
2288              if (!git->dragging)
2289                _item_unrealize(git, EINA_FALSE);
2290           }
2291      }
2292    evas_event_thaw(evas_object_evas_get(wd->obj));
2293    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
2294 }
2295
2296 static Eina_Bool
2297 _must_recalc_idler(void *data)
2298 {
2299    Widget_Data *wd = data;
2300    if (wd->calc_job) ecore_job_del(wd->calc_job);
2301    wd->calc_job = ecore_job_add(_calc_job, wd);
2302    wd->must_recalc_idler = NULL;
2303    return ECORE_CALLBACK_CANCEL;
2304 }
2305
2306 static void
2307 _calc_job(void *data)
2308 {
2309    Widget_Data *wd = data;
2310    Item_Block *itb;
2311    Evas_Coord minw = -1, minh = 0, y = 0, ow;
2312    Item_Block *chb = NULL;
2313    int in = 0, minw_change = 0;
2314    Eina_Bool changed = EINA_FALSE;
2315    double t0, t;
2316    Eina_Bool did_must_recalc = EINA_FALSE;
2317    if (!wd) return;
2318
2319    t0 = ecore_time_get();
2320    evas_object_geometry_get(wd->pan_smart, NULL, NULL, &ow, &wd->h);
2321    if (wd->w != ow)
2322      wd->w = ow;
2323
2324    evas_event_freeze(evas_object_evas_get(wd->obj));
2325    EINA_INLIST_FOREACH(wd->blocks, itb)
2326      {
2327         Eina_Bool showme = EINA_FALSE;
2328
2329         itb->num = in;
2330         showme = itb->showme;
2331         itb->showme = EINA_FALSE;
2332         if (chb)
2333           {
2334              if (itb->realized) _item_block_unrealize(itb);
2335           }
2336         if ((itb->changed) || (changed) ||
2337             ((itb->must_recalc) && (!did_must_recalc)))
2338           {
2339              if ((changed) || (itb->must_recalc))
2340                {
2341                   Eina_List *l;
2342                   Elm_Genlist_Item *it;
2343                   EINA_LIST_FOREACH(itb->items, l, it)
2344                     if (it->mincalcd) it->mincalcd = EINA_FALSE;
2345                   itb->changed = EINA_TRUE;
2346                   if (itb->must_recalc) did_must_recalc = EINA_TRUE;
2347                   itb->must_recalc = EINA_FALSE;
2348                }
2349              if (itb->realized) _item_block_unrealize(itb);
2350              showme = _item_block_recalc(itb, in, 0);
2351              chb = itb;
2352           }
2353         itb->y = y;
2354         itb->x = 0;
2355         minh += itb->minh;
2356         if (minw == -1) minw = itb->minw;
2357         else if ((!itb->must_recalc) && (minw < itb->minw))
2358           {
2359              minw = itb->minw;
2360              minw_change = 1;
2361           }
2362         itb->w = minw;
2363         itb->h = itb->minh;
2364         y += itb->h;
2365         in += itb->count;
2366         if ((showme) && (wd->show_item) && (!wd->show_item->queued))
2367           {
2368              wd->show_item->showme = EINA_FALSE;
2369              if (wd->bring_in)
2370                elm_smart_scroller_region_bring_in(wd->scr,
2371                                                   wd->show_item->x +
2372                                                   wd->show_item->block->x,
2373                                                   wd->show_item->y +
2374                                                   wd->show_item->block->y,
2375                                                   wd->show_item->block->w,
2376                                                   wd->show_item->h);
2377              else
2378                elm_smart_scroller_child_region_show(wd->scr,
2379                                                     wd->show_item->x +
2380                                                     wd->show_item->block->x,
2381                                                     wd->show_item->y +
2382                                                     wd->show_item->block->y,
2383                                                     wd->show_item->block->w,
2384                                                     wd->show_item->h);
2385              wd->show_item = NULL;
2386           }
2387      }
2388    if (minw_change)
2389      {
2390         EINA_INLIST_FOREACH(wd->blocks, itb)
2391           {
2392              itb->minw = minw;
2393              itb->w = itb->minw;
2394           }
2395      }
2396    if ((chb) && (EINA_INLIST_GET(chb)->next))
2397      {
2398         EINA_INLIST_FOREACH(EINA_INLIST_GET(chb)->next, itb)
2399           {
2400              if (itb->realized) _item_block_unrealize(itb);
2401           }
2402      }
2403    wd->realminw = minw;
2404    if (minw < wd->w) minw = wd->w;
2405    if ((minw != wd->minw) || (minh != wd->minh))
2406      {
2407         wd->minw = minw;
2408         wd->minh = minh;
2409         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2410         _sizing_eval(wd->obj);
2411         if ((wd->anchor_item) && (wd->anchor_item->block))
2412           {
2413              Elm_Genlist_Item *it;
2414              Evas_Coord it_y;
2415
2416              it = wd->anchor_item;
2417              it_y = wd->anchor_y;
2418              elm_smart_scroller_child_pos_set(wd->scr, wd->pan_x,
2419                                               it->block->y + it->y + it_y);
2420              wd->anchor_item = it;
2421              wd->anchor_y = it_y;
2422           }
2423      }
2424    t = ecore_time_get();
2425    if (did_must_recalc)
2426      {
2427         if (!wd->must_recalc_idler)
2428           wd->must_recalc_idler = ecore_idler_add(_must_recalc_idler, wd);
2429      }
2430    wd->calc_job = NULL;
2431    evas_object_smart_changed(wd->pan_smart);
2432    evas_event_thaw(evas_object_evas_get(wd->obj));
2433    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
2434 }
2435
2436 static void
2437 _update_job(void *data)
2438 {
2439    Widget_Data *wd = data;
2440    Eina_List *l2;
2441    Item_Block *itb;
2442    int num, num0, position = 0, recalc = 0;
2443    if (!wd) return;
2444    wd->update_job = NULL;
2445    num = 0;
2446
2447    evas_event_freeze(evas_object_evas_get(wd->obj));
2448    EINA_INLIST_FOREACH(wd->blocks, itb)
2449      {
2450         Evas_Coord itminw, itminh;
2451         Elm_Genlist_Item *it;
2452
2453         if (!itb->updateme)
2454           {
2455              num += itb->count;
2456              if (position)
2457                _item_block_position(itb, num);
2458              continue;
2459           }
2460         num0 = num;
2461         recalc = 0;
2462         EINA_LIST_FOREACH(itb->items, l2, it)
2463           {
2464              if (it->updateme)
2465                {
2466                   itminw = it->minw;
2467                   itminh = it->minh;
2468
2469                   it->updateme = EINA_FALSE;
2470                   if (it->realized)
2471                     {
2472                        _item_unrealize(it, EINA_FALSE);
2473                        _item_realize(it, num, EINA_FALSE);
2474                        position = 1;
2475                     }
2476                   else
2477                     {
2478                        _item_realize(it, num, EINA_TRUE);
2479                        _item_unrealize(it, EINA_TRUE);
2480                     }
2481                   if ((it->minw != itminw) || (it->minh != itminh))
2482                     recalc = 1;
2483                }
2484              num++;
2485           }
2486         itb->updateme = EINA_FALSE;
2487         if (recalc)
2488           {
2489              position = 1;
2490              itb->changed = EINA_TRUE;
2491              _item_block_recalc(itb, num0, 0);
2492              _item_block_position(itb, num0);
2493           }
2494      }
2495    if (position)
2496      {
2497         if (wd->calc_job) ecore_job_del(wd->calc_job);
2498         wd->calc_job = ecore_job_add(_calc_job, wd);
2499      }
2500    evas_event_thaw(evas_object_evas_get(wd->obj));
2501    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
2502 }
2503
2504 static void
2505 _pan_set(Evas_Object *obj,
2506          Evas_Coord   x,
2507          Evas_Coord   y)
2508 {
2509    Pan *sd = evas_object_smart_data_get(obj);
2510    Item_Block *itb;
2511
2512    //   Evas_Coord ow, oh;
2513    //   evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2514    //   ow = sd->wd->minw - ow;
2515    //   if (ow < 0) ow = 0;
2516    //   oh = sd->wd->minh - oh;
2517    //   if (oh < 0) oh = 0;
2518    //   if (x < 0) x = 0;
2519    //   if (y < 0) y = 0;
2520    //   if (x > ow) x = ow;
2521    //   if (y > oh) y = oh;
2522    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2523    sd->wd->pan_x = x;
2524    sd->wd->pan_y = y;
2525
2526    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2527      {
2528         if ((itb->y + itb->h) > y)
2529           {
2530              Elm_Genlist_Item *it;
2531              Eina_List *l2;
2532
2533              EINA_LIST_FOREACH(itb->items, l2, it)
2534                {
2535                   if ((itb->y + it->y) >= y)
2536                     {
2537                        sd->wd->anchor_item = it;
2538                        sd->wd->anchor_y = -(itb->y + it->y - y);
2539                        goto done;
2540                     }
2541                }
2542           }
2543      }
2544 done:
2545    evas_object_smart_changed(obj);
2546 }
2547
2548 static void
2549 _pan_get(Evas_Object *obj,
2550          Evas_Coord  *x,
2551          Evas_Coord  *y)
2552 {
2553    Pan *sd = evas_object_smart_data_get(obj);
2554
2555    if (x) *x = sd->wd->pan_x;
2556    if (y) *y = sd->wd->pan_y;
2557 }
2558
2559 static void
2560 _pan_max_get(Evas_Object *obj,
2561              Evas_Coord  *x,
2562              Evas_Coord  *y)
2563 {
2564    Pan *sd = evas_object_smart_data_get(obj);
2565    Evas_Coord ow, oh;
2566
2567    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2568    ow = sd->wd->minw - ow;
2569    if (ow < 0) ow = 0;
2570    oh = sd->wd->minh - oh;
2571    if (oh < 0) oh = 0;
2572    if (x) *x = ow;
2573    if (y) *y = oh;
2574 }
2575
2576 static void
2577 _pan_min_get(Evas_Object *obj __UNUSED__,
2578              Evas_Coord  *x,
2579              Evas_Coord  *y)
2580 {
2581    if (x) *x = 0;
2582    if (y) *y = 0;
2583 }
2584
2585 static void
2586 _pan_child_size_get(Evas_Object *obj,
2587                     Evas_Coord  *w,
2588                     Evas_Coord  *h)
2589 {
2590    Pan *sd = evas_object_smart_data_get(obj);
2591
2592    if (w) *w = sd->wd->minw;
2593    if (h) *h = sd->wd->minh;
2594 }
2595
2596 static void
2597 _pan_add(Evas_Object *obj)
2598 {
2599    Pan *sd;
2600    Evas_Object_Smart_Clipped_Data *cd;
2601
2602    _pan_sc.add(obj);
2603    cd = evas_object_smart_data_get(obj);
2604    sd = ELM_NEW(Pan);
2605    if (!sd) return;
2606    sd->__clipped_data = *cd;
2607    free(cd);
2608    evas_object_smart_data_set(obj, sd);
2609 }
2610
2611 static void
2612 _pan_del(Evas_Object *obj)
2613 {
2614    Pan *sd = evas_object_smart_data_get(obj);
2615
2616    if (!sd) return;
2617    if (sd->resize_job)
2618      {
2619         ecore_job_del(sd->resize_job);
2620         sd->resize_job = NULL;
2621      }
2622    _pan_sc.del(obj);
2623 }
2624
2625 static void
2626 _pan_resize_job(void *data)
2627 {
2628    Pan *sd = data;
2629    _sizing_eval(sd->wd->obj);
2630    sd->resize_job = NULL;
2631 }
2632
2633 static void
2634 _pan_resize(Evas_Object *obj,
2635             Evas_Coord   w,
2636             Evas_Coord   h)
2637 {
2638    Pan *sd = evas_object_smart_data_get(obj);
2639    Evas_Coord ow, oh;
2640
2641    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2642    if ((ow == w) && (oh == h)) return;
2643    if ((sd->wd->height_for_width) && (ow != w))
2644      {
2645         if (sd->resize_job) ecore_job_del(sd->resize_job);
2646         sd->resize_job = ecore_job_add(_pan_resize_job, sd);
2647      }
2648    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2649    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2650 }
2651
2652 static void
2653 _pan_calculate(Evas_Object *obj)
2654 {
2655    Pan *sd = evas_object_smart_data_get(obj);
2656    Item_Block *itb;
2657    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh;
2658    int in = 0;
2659    Elm_Genlist_Item *git;
2660    Eina_List *l;
2661
2662    evas_event_freeze(evas_object_evas_get(obj));
2663    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2664    evas_output_viewport_get(evas_object_evas_get(obj), &cvx, &cvy, &cvw, &cvh);
2665    EINA_LIST_FOREACH(sd->wd->group_items, l, git)
2666      {
2667         git->want_realize = EINA_FALSE;
2668      }
2669    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2670      {
2671         itb->w = sd->wd->minw;
2672         if (ELM_RECTS_INTERSECT(itb->x - sd->wd->pan_x + ox,
2673                                 itb->y - sd->wd->pan_y + oy,
2674                                 itb->w, itb->h,
2675                                 cvx, cvy, cvw, cvh))
2676           {
2677              if ((!itb->realized) || (itb->changed))
2678                _item_block_realize(itb, in, 0);
2679              _item_block_position(itb, in);
2680           }
2681         else
2682           {
2683              if (itb->realized) _item_block_unrealize(itb);
2684           }
2685         in += itb->count;
2686      }
2687    _group_items_recalc(sd->wd);
2688    evas_event_thaw(evas_object_evas_get(obj));
2689    evas_event_thaw_eval(evas_object_evas_get(obj));
2690 }
2691
2692 static void
2693 _pan_move(Evas_Object *obj,
2694           Evas_Coord   x __UNUSED__,
2695           Evas_Coord   y __UNUSED__)
2696 {
2697    Pan *sd = evas_object_smart_data_get(obj);
2698
2699    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2700    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2701 }
2702
2703 static void
2704 _hold_on(void        *data __UNUSED__,
2705          Evas_Object *obj,
2706          void        *event_info __UNUSED__)
2707 {
2708    Widget_Data *wd = elm_widget_data_get(obj);
2709    if (!wd) return;
2710    elm_smart_scroller_hold_set(wd->scr, 1);
2711 }
2712
2713 static void
2714 _hold_off(void        *data __UNUSED__,
2715           Evas_Object *obj,
2716           void        *event_info __UNUSED__)
2717 {
2718    Widget_Data *wd = elm_widget_data_get(obj);
2719    if (!wd) return;
2720    elm_smart_scroller_hold_set(wd->scr, 0);
2721 }
2722
2723 static void
2724 _freeze_on(void        *data __UNUSED__,
2725            Evas_Object *obj,
2726            void        *event_info __UNUSED__)
2727 {
2728    Widget_Data *wd = elm_widget_data_get(obj);
2729    if (!wd) return;
2730    elm_smart_scroller_freeze_set(wd->scr, 1);
2731 }
2732
2733 static void
2734 _freeze_off(void        *data __UNUSED__,
2735             Evas_Object *obj,
2736             void        *event_info __UNUSED__)
2737 {
2738    Widget_Data *wd = elm_widget_data_get(obj);
2739    if (!wd) return;
2740    elm_smart_scroller_freeze_set(wd->scr, 0);
2741 }
2742
2743 static void
2744 _scroll_edge_left(void        *data,
2745                   Evas_Object *scr __UNUSED__,
2746                   void        *event_info __UNUSED__)
2747 {
2748    Evas_Object *obj = data;
2749    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_LEFT, NULL);
2750 }
2751
2752 static void
2753 _scroll_edge_right(void        *data,
2754                    Evas_Object *scr __UNUSED__,
2755                    void        *event_info __UNUSED__)
2756 {
2757    Evas_Object *obj = data;
2758    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_RIGHT, NULL);
2759 }
2760
2761 static void
2762 _scroll_edge_top(void        *data,
2763                  Evas_Object *scr __UNUSED__,
2764                  void        *event_info __UNUSED__)
2765 {
2766    Evas_Object *obj = data;
2767    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_TOP, NULL);
2768 }
2769
2770 static void
2771 _scroll_edge_bottom(void        *data,
2772                     Evas_Object *scr __UNUSED__,
2773                     void        *event_info __UNUSED__)
2774 {
2775    Evas_Object *obj = data;
2776    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_BOTTOM, NULL);
2777 }
2778
2779 static void
2780 _mode_item_realize(Elm_Genlist_Item *it)
2781 {
2782    char buf[1024];
2783
2784    if ((it->mode_view) || (it->delete_me)) return;
2785
2786    evas_event_freeze(evas_object_evas_get(it->wd->obj));
2787    it->mode_view = edje_object_add(evas_object_evas_get(it->base.widget));
2788    edje_object_scale_set(it->mode_view,
2789                          elm_widget_scale_get(it->base.widget) *
2790                          _elm_config->scale);
2791    evas_object_smart_member_add(it->mode_view, it->wd->pan_smart);
2792    elm_widget_sub_object_add(it->base.widget, it->mode_view);
2793
2794    strncpy(buf, "item", sizeof(buf));
2795    if (it->wd->compress)
2796      strncat(buf, "_compress", sizeof(buf) - strlen(buf));
2797
2798    if (it->order_num_in & 0x1) strncat(buf, "_odd", sizeof(buf) - strlen(buf));
2799    strncat(buf, "/", sizeof(buf) - strlen(buf));
2800    strncat(buf, it->itc->mode_item_style, sizeof(buf) - strlen(buf));
2801
2802    _elm_theme_object_set(it->base.widget, it->mode_view, "genlist", buf,
2803                          elm_widget_style_get(it->base.widget));
2804    edje_object_mirrored_set(it->mode_view,
2805                             elm_widget_mirrored_get(it->base.widget));
2806
2807    /* signal callback add */
2808    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_DOWN,
2809                                   _mouse_down, it);
2810    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_UP,
2811                                   _mouse_up, it);
2812    evas_object_event_callback_add(it->mode_view, EVAS_CALLBACK_MOUSE_MOVE,
2813                                   _mouse_move, it);
2814
2815    /* label_get, icon_get, state_get */
2816    /* FIXME: If you see that assert, please notify us and we
2817       will clean our mess */
2818    assert(eina_list_count(it->mode_icon_objs) == 0);
2819
2820    _item_label_realize(it, it->mode_view, &it->mode_labels);
2821    it->mode_icon_objs = _item_icon_realize(it,
2822                                            it->mode_view,
2823                                            &it->mode_icons);
2824    _item_state_realize(it, it->mode_view, &it->mode_states);
2825
2826    edje_object_part_swallow(it->mode_view,
2827                             edje_object_data_get(it->mode_view, "mode_part"),
2828                             it->base.view);
2829
2830    it->want_unrealize = EINA_FALSE;
2831    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2832    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2833 }
2834
2835 static void
2836 _mode_item_unrealize(Elm_Genlist_Item *it)
2837 {
2838    Widget_Data *wd = it->wd;
2839    Evas_Object *icon;
2840    if (!it->mode_view) return;
2841
2842    evas_event_freeze(evas_object_evas_get(it->wd->obj));
2843    elm_widget_stringlist_free(it->mode_labels);
2844    it->mode_labels = NULL;
2845    elm_widget_stringlist_free(it->mode_icons);
2846    it->mode_icons = NULL;
2847    elm_widget_stringlist_free(it->mode_states);
2848
2849    EINA_LIST_FREE(it->mode_icon_objs, icon)
2850      evas_object_del(icon);
2851
2852    edje_object_part_unswallow(it->mode_view, it->base.view);
2853    evas_object_smart_member_add(it->base.view, wd->pan_smart);
2854    evas_object_del(it->mode_view);
2855    it->mode_view = NULL;
2856
2857    if (wd->mode_item == it)
2858      wd->mode_item = NULL;
2859    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2860    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2861 }
2862
2863 static void
2864 _item_mode_set(Elm_Genlist_Item *it)
2865 {
2866    if (!it) return;
2867    Widget_Data *wd = it->wd;
2868    if (!wd) return;
2869    char buf[1024];
2870
2871    wd->mode_item = it;
2872    it->nocache = EINA_TRUE;
2873
2874    if (wd->scr_hold_timer)
2875      {
2876         ecore_timer_del(wd->scr_hold_timer);
2877         wd->scr_hold_timer = NULL;
2878      }
2879    elm_smart_scroller_hold_set(wd->scr, EINA_TRUE);
2880    wd->scr_hold_timer = ecore_timer_add(0.1, _scr_hold_timer_cb, wd);
2881
2882    evas_event_freeze(evas_object_evas_get(it->wd->obj));
2883    _mode_item_realize(it);
2884    _item_position(it, it->mode_view);
2885    evas_event_thaw(evas_object_evas_get(it->wd->obj));
2886    evas_event_thaw_eval(evas_object_evas_get(it->wd->obj));
2887
2888    snprintf(buf, sizeof(buf), "elm,state,%s,active", wd->mode_type);
2889    edje_object_signal_emit(it->mode_view, buf, "elm");
2890 }
2891
2892 static void
2893 _item_mode_unset(Widget_Data *wd)
2894 {
2895    if (!wd) return;
2896    if (!wd->mode_item) return;
2897    char buf[1024], buf2[1024];
2898    Elm_Genlist_Item *it;
2899
2900    it = wd->mode_item;
2901    it->nocache = EINA_TRUE;
2902
2903    snprintf(buf, sizeof(buf), "elm,state,%s,passive", wd->mode_type);
2904    snprintf(buf2, sizeof(buf2), "elm,state,%s,passive,finished", wd->mode_type);
2905
2906    edje_object_signal_emit(it->mode_view, buf, "elm");
2907    edje_object_signal_callback_add(it->mode_view, buf2, "elm", _mode_finished_signal_cb, it);
2908
2909    wd->mode_item = NULL;
2910 }
2911
2912 /**
2913  * Add a new Genlist object
2914  *
2915  * @param parent The parent object
2916  * @return The new object or NULL if it cannot be created
2917  *
2918  * @ingroup Genlist
2919  */
2920 EAPI Evas_Object *
2921 elm_genlist_add(Evas_Object *parent)
2922 {
2923    Evas_Object *obj;
2924    Evas *e;
2925    Widget_Data *wd;
2926    Evas_Coord minw, minh;
2927    static Evas_Smart *smart = NULL;
2928
2929    if (!smart)
2930      {
2931         static Evas_Smart_Class sc;
2932
2933         evas_object_smart_clipped_smart_set(&_pan_sc);
2934         sc = _pan_sc;
2935         sc.name = "elm_genlist_pan";
2936         sc.version = EVAS_SMART_CLASS_VERSION;
2937         sc.add = _pan_add;
2938         sc.del = _pan_del;
2939         sc.resize = _pan_resize;
2940         sc.move = _pan_move;
2941         sc.calculate = _pan_calculate;
2942         if (!(smart = evas_smart_class_new(&sc))) return NULL;
2943      }
2944
2945    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2946
2947    ELM_SET_WIDTYPE(widtype, "genlist");
2948    elm_widget_type_set(obj, "genlist");
2949    elm_widget_sub_object_add(parent, obj);
2950    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2951    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2952    elm_widget_data_set(obj, wd);
2953    elm_widget_del_hook_set(obj, _del_hook);
2954    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2955    elm_widget_theme_hook_set(obj, _theme_hook);
2956    elm_widget_can_focus_set(obj, EINA_TRUE);
2957    elm_widget_event_hook_set(obj, _event_hook);
2958    elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
2959
2960    wd->scr = elm_smart_scroller_add(e);
2961    elm_smart_scroller_widget_set(wd->scr, obj);
2962    elm_smart_scroller_object_theme_set(obj, wd->scr, "genlist", "base",
2963                                        elm_widget_style_get(obj));
2964    elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
2965                                        _elm_config->thumbscroll_bounce_enable);
2966    elm_widget_resize_object_set(obj, wd->scr);
2967
2968    evas_object_smart_callback_add(wd->scr, "edge,left", _scroll_edge_left, obj);
2969    evas_object_smart_callback_add(wd->scr, "edge,right", _scroll_edge_right,
2970                                   obj);
2971    evas_object_smart_callback_add(wd->scr, "edge,top", _scroll_edge_top, obj);
2972    evas_object_smart_callback_add(wd->scr, "edge,bottom", _scroll_edge_bottom,
2973                                   obj);
2974
2975    wd->obj = obj;
2976    wd->mode = ELM_LIST_SCROLL;
2977    wd->max_items_per_block = MAX_ITEMS_PER_BLOCK;
2978    wd->item_cache_max = wd->max_items_per_block * 2;
2979    wd->longpress_timeout = _elm_config->longpress_timeout;
2980
2981    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
2982    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
2983    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
2984    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
2985
2986    wd->pan_smart = evas_object_smart_add(e, smart);
2987    wd->pan = evas_object_smart_data_get(wd->pan_smart);
2988    wd->pan->wd = wd;
2989
2990    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
2991                                      _pan_set, _pan_get, _pan_max_get,
2992                                      _pan_min_get, _pan_child_size_get);
2993
2994    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
2995                              &minw, &minh);
2996    evas_object_size_hint_min_set(obj, minw, minh);
2997
2998    evas_object_smart_callbacks_descriptions_set(obj, _signals);
2999
3000    _mirrored_set(obj, elm_widget_mirrored_get(obj));
3001    _sizing_eval(obj);
3002    return obj;
3003 }
3004
3005 static Elm_Genlist_Item *
3006 _item_new(Widget_Data                  *wd,
3007           const Elm_Genlist_Item_Class *itc,
3008           const void                   *data,
3009           Elm_Genlist_Item             *parent,
3010           Elm_Genlist_Item_Flags        flags,
3011           Evas_Smart_Cb                 func,
3012           const void                   *func_data)
3013 {
3014    Elm_Genlist_Item *it;
3015
3016    it = elm_widget_item_new(wd->obj, Elm_Genlist_Item);
3017    if (!it) return NULL;
3018    it->wd = wd;
3019    it->itc = itc;
3020    it->base.data = data;
3021    it->parent = parent;
3022    it->flags = flags;
3023    it->func.func = func;
3024    it->func.data = func_data;
3025    it->mouse_cursor = NULL;
3026    it->expanded_depth = 0;
3027    return it;
3028 }
3029
3030 static void
3031 _item_block_add(Widget_Data      *wd,
3032                 Elm_Genlist_Item *it)
3033 {
3034    Item_Block *itb = NULL;
3035
3036    if (!it->rel)
3037      {
3038 newblock:
3039         if (it->rel)
3040           {
3041              itb = calloc(1, sizeof(Item_Block));
3042              if (!itb) return;
3043              itb->wd = wd;
3044              if (!it->rel->block)
3045                {
3046                   wd->blocks =
3047                     eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
3048                   itb->items = eina_list_append(itb->items, it);
3049                }
3050              else
3051                {
3052                   if (it->before)
3053                     {
3054                        wd->blocks = eina_inlist_prepend_relative
3055                            (wd->blocks, EINA_INLIST_GET(itb),
3056                            EINA_INLIST_GET(it->rel->block));
3057                        itb->items =
3058                          eina_list_prepend_relative(itb->items, it, it->rel);
3059                     }
3060                   else
3061                     {
3062                        wd->blocks = eina_inlist_append_relative
3063                            (wd->blocks, EINA_INLIST_GET(itb),
3064                            EINA_INLIST_GET(it->rel->block));
3065                        itb->items =
3066                          eina_list_append_relative(itb->items, it, it->rel);
3067                     }
3068                }
3069           }
3070         else
3071           {
3072              if (it->before)
3073                {
3074                   if (wd->blocks)
3075                     {
3076                        itb = (Item_Block *)(wd->blocks);
3077                        if (itb->count >= wd->max_items_per_block)
3078                          {
3079                             itb = calloc(1, sizeof(Item_Block));
3080                             if (!itb) return;
3081                             itb->wd = wd;
3082                             wd->blocks =
3083                               eina_inlist_prepend(wd->blocks,
3084                                                   EINA_INLIST_GET(itb));
3085                          }
3086                     }
3087                   else
3088                     {
3089                        itb = calloc(1, sizeof(Item_Block));
3090                        if (!itb) return;
3091                        itb->wd = wd;
3092                        wd->blocks =
3093                          eina_inlist_prepend(wd->blocks, EINA_INLIST_GET(itb));
3094                     }
3095                   itb->items = eina_list_prepend(itb->items, it);
3096                }
3097              else
3098                {
3099                   if (wd->blocks)
3100                     {
3101                        itb = (Item_Block *)(wd->blocks->last);
3102                        if (itb->count >= wd->max_items_per_block)
3103                          {
3104                             itb = calloc(1, sizeof(Item_Block));
3105                             if (!itb) return;
3106                             itb->wd = wd;
3107                             wd->blocks =
3108                               eina_inlist_append(wd->blocks,
3109                                                  EINA_INLIST_GET(itb));
3110                          }
3111                     }
3112                   else
3113                     {
3114                        itb = calloc(1, sizeof(Item_Block));
3115                        if (!itb) return;
3116                        itb->wd = wd;
3117                        wd->blocks =
3118                          eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
3119                     }
3120                   itb->items = eina_list_append(itb->items, it);
3121                }
3122           }
3123      }
3124    else
3125      {
3126         itb = it->rel->block;
3127         if (!itb) goto newblock;
3128         if (it->before)
3129           itb->items = eina_list_prepend_relative(itb->items, it, it->rel);
3130         else
3131           itb->items = eina_list_append_relative(itb->items, it, it->rel);
3132      }
3133    itb->count++;
3134    itb->changed = EINA_TRUE;
3135    it->block = itb;
3136    if (itb->wd->calc_job) ecore_job_del(itb->wd->calc_job);
3137    itb->wd->calc_job = ecore_job_add(_calc_job, itb->wd);
3138    if (it->rel)
3139      {
3140         it->rel->relcount--;
3141         if ((it->rel->delete_me) && (!it->rel->relcount))
3142           _item_del(it->rel);
3143         it->rel = NULL;
3144      }
3145    if (itb->count > itb->wd->max_items_per_block)
3146      {
3147         int newc;
3148         Item_Block *itb2;
3149         Elm_Genlist_Item *it2;
3150
3151         newc = itb->count / 2;
3152         itb2 = calloc(1, sizeof(Item_Block));
3153         if (!itb2) return;
3154         itb2->wd = wd;
3155         wd->blocks =
3156           eina_inlist_append_relative(wd->blocks, EINA_INLIST_GET(itb2),
3157                                       EINA_INLIST_GET(itb));
3158         itb2->changed = EINA_TRUE;
3159         while ((itb->count > newc) && (itb->items))
3160           {
3161              Eina_List *l;
3162
3163              l = eina_list_last(itb->items);
3164              it2 = l->data;
3165              itb->items = eina_list_remove_list(itb->items, l);
3166              itb->count--;
3167
3168              itb2->items = eina_list_prepend(itb2->items, it2);
3169              it2->block = itb2;
3170              itb2->count++;
3171           }
3172      }
3173 }
3174
3175 static int
3176 _queue_process(Widget_Data *wd)
3177 {
3178    int n;
3179    Eina_Bool showme = EINA_FALSE;
3180    double t0, t;
3181
3182    t0 = ecore_time_get();
3183    evas_event_freeze(evas_object_evas_get(wd->obj));
3184    for (n = 0; (wd->queue) && (n < 128); n++)
3185      {
3186         Elm_Genlist_Item *it;
3187
3188         it = wd->queue->data;
3189         wd->queue = eina_list_remove_list(wd->queue, wd->queue);
3190         it->queued = EINA_FALSE;
3191         _item_block_add(wd, it);
3192         t = ecore_time_get();
3193         if (it->block->changed)
3194           {
3195              showme = _item_block_recalc(it->block, it->block->num, 1);
3196              it->block->changed = 0;
3197           }
3198         if (showme) it->block->showme = EINA_TRUE;
3199         if (eina_inlist_count(wd->blocks) > 1)
3200           {
3201              if ((t - t0) > (ecore_animator_frametime_get())) break;
3202           }
3203      }
3204    evas_event_thaw(evas_object_evas_get(wd->obj));
3205    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3206    return n;
3207 }
3208
3209 static Eina_Bool
3210 _idle_process(void *data, Eina_Bool *wakeup)
3211 {
3212    Widget_Data *wd = data;
3213
3214    //xxx
3215    //static double q_start = 0.0;
3216    //if (q_start == 0.0) q_start = ecore_time_get();
3217    //xxx
3218    if (_queue_process(wd) > 0) *wakeup = EINA_TRUE;
3219    if (!wd->queue)
3220      {
3221         //xxx
3222         //printf("PROCESS TIME: %3.3f\n", ecore_time_get() - q_start);
3223         //xxx
3224         return ECORE_CALLBACK_CANCEL;
3225      }
3226    return ECORE_CALLBACK_RENEW;
3227 }
3228
3229 static Eina_Bool
3230 _item_idle_enterer(void *data)
3231 {
3232    Widget_Data *wd = data;
3233    Eina_Bool wakeup = EINA_FALSE;
3234    Eina_Bool ok = _idle_process(data, &wakeup);
3235
3236    if (wakeup)
3237      {
3238         // wake up mainloop
3239         if (wd->calc_job) ecore_job_del(wd->calc_job);
3240         wd->calc_job = ecore_job_add(_calc_job, wd);
3241      }
3242    if (ok == ECORE_CALLBACK_CANCEL) wd->queue_idle_enterer = NULL;
3243    return ok;
3244 }
3245
3246 static void
3247 _item_queue(Widget_Data      *wd,
3248             Elm_Genlist_Item *it)
3249 {
3250    if (it->queued) return;
3251    it->queued = EINA_TRUE;
3252    wd->queue = eina_list_append(wd->queue, it);
3253    evas_event_freeze(evas_object_evas_get(wd->obj));
3254    while ((wd->queue) && ((!wd->blocks) || (!wd->blocks->next)))
3255      {
3256         if (wd->queue_idle_enterer)
3257           {
3258              ecore_idle_enterer_del(wd->queue_idle_enterer);
3259              wd->queue_idle_enterer = NULL;
3260           }
3261         _queue_process(wd);
3262      }
3263    evas_event_thaw(evas_object_evas_get(wd->obj));
3264    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3265    if (!wd->queue_idle_enterer)
3266       wd->queue_idle_enterer = ecore_idle_enterer_add(_item_idle_enterer, wd);
3267 }
3268
3269 static int
3270 _elm_genlist_item_compare(const void *data, const void *data1)
3271 {
3272    Elm_Genlist_Item *item, *item1;
3273    item = ELM_GENLIST_ITEM_FROM_INLIST(data);
3274    item1 = ELM_GENLIST_ITEM_FROM_INLIST(data1);
3275    return _elm_genlist_item_compare_cb(item->base.data, item1->base.data);
3276 }
3277
3278 /**
3279  * Append item to the end of the genlist
3280  *
3281  * This appends the given item to the end of the list or the end of
3282  * the children if the parent is given.
3283  *
3284  * @param obj The genlist object
3285  * @param itc The item class for the item
3286  * @param data The item data
3287  * @param parent The parent item, or NULL if none
3288  * @param flags Item flags
3289  * @param func Convenience function called when item selected
3290  * @param func_data Data passed to @p func above.
3291  * @return A handle to the item added or NULL if not possible
3292  *
3293  * @ingroup Genlist
3294  */
3295 EAPI Elm_Genlist_Item *
3296 elm_genlist_item_append(Evas_Object                  *obj,
3297                         const Elm_Genlist_Item_Class *itc,
3298                         const void                   *data,
3299                         Elm_Genlist_Item             *parent,
3300                         Elm_Genlist_Item_Flags        flags,
3301                         Evas_Smart_Cb                 func,
3302                         const void                   *func_data)
3303 {
3304    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3305    Widget_Data *wd = elm_widget_data_get(obj);
3306    if (!wd) return NULL;
3307    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3308                                     func_data);
3309    if (!it) return NULL;
3310    if (!it->parent)
3311      {
3312         if (flags & ELM_GENLIST_ITEM_GROUP)
3313           wd->group_items = eina_list_append(wd->group_items, it);
3314         wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
3315         it->rel = NULL;
3316      }
3317    else
3318      {
3319         Elm_Genlist_Item *it2 = NULL;
3320         Eina_List *ll = eina_list_last(it->parent->items);
3321         if (ll) it2 = ll->data;
3322         it->parent->items = eina_list_append(it->parent->items, it);
3323         if (!it2) it2 = it->parent;
3324         wd->items =
3325            eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3326                                        EINA_INLIST_GET(it2));
3327         it->rel = it2;
3328         it->rel->relcount++;
3329
3330         if (it->parent->flags & ELM_GENLIST_ITEM_GROUP)
3331           it->group_item = parent;
3332         else if (it->parent->group_item)
3333           it->group_item = it->parent->group_item;
3334      }
3335    it->before = EINA_FALSE;
3336    _item_queue(wd, it);
3337    return it;
3338 }
3339
3340 /**
3341  * Prepend item at start of the genlist
3342  *
3343  * This adds an item to the beginning of the list or beginning of the
3344  * children of the parent if given.
3345  *
3346  * @param obj The genlist object
3347  * @param itc The item class for the item
3348  * @param data The item data
3349  * @param parent The parent item, or NULL if none
3350  * @param flags Item flags
3351  * @param func Convenience function called when item selected
3352  * @param func_data Data passed to @p func above.
3353  * @return A handle to the item added or NULL if not possible
3354  *
3355  * @ingroup Genlist
3356  */
3357 EAPI Elm_Genlist_Item *
3358 elm_genlist_item_prepend(Evas_Object                  *obj,
3359                          const Elm_Genlist_Item_Class *itc,
3360                          const void                   *data,
3361                          Elm_Genlist_Item             *parent,
3362                          Elm_Genlist_Item_Flags        flags,
3363                          Evas_Smart_Cb                 func,
3364                          const void                   *func_data)
3365 {
3366    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3367    Widget_Data *wd = elm_widget_data_get(obj);
3368    if (!wd) return NULL;
3369    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3370                                     func_data);
3371    if (!it) return NULL;
3372    if (!it->parent)
3373      {
3374         if (flags & ELM_GENLIST_ITEM_GROUP)
3375           wd->group_items = eina_list_prepend(wd->group_items, it);
3376         wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
3377         it->rel = NULL;
3378      }
3379    else
3380      {
3381         Elm_Genlist_Item *it2 = NULL;
3382         Eina_List *ll = it->parent->items;
3383         if (ll) it2 = ll->data;
3384         it->parent->items = eina_list_prepend(it->parent->items, it);
3385         if (!it2) it2 = it->parent;
3386         wd->items =
3387           eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3388                                        EINA_INLIST_GET(it2));
3389         it->rel = it2;
3390         it->rel->relcount++;
3391      }
3392    it->before = EINA_TRUE;
3393    _item_queue(wd, it);
3394    return it;
3395 }
3396
3397 /**
3398  * Insert item before another in the genlist
3399  *
3400  * This inserts an item before another in the list. It will be in the
3401  * same tree level or group as the item it is inseted before.
3402  *
3403  * @param obj The genlist object
3404  * @param itc The item class for the item
3405  * @param data The item data
3406  * @param before The item to insert before
3407  * @param flags Item flags
3408  * @param func Convenience function called when item selected
3409  * @param func_data Data passed to @p func above.
3410  * @return A handle to the item added or NULL if not possible
3411  *
3412  * @ingroup Genlist
3413  */
3414 EAPI Elm_Genlist_Item *
3415 elm_genlist_item_insert_before(Evas_Object                  *obj,
3416                                const Elm_Genlist_Item_Class *itc,
3417                                const void                   *data,
3418                                Elm_Genlist_Item             *parent,
3419                                Elm_Genlist_Item             *before,
3420                                Elm_Genlist_Item_Flags        flags,
3421                                Evas_Smart_Cb                 func,
3422                                const void                   *func_data)
3423 {
3424    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3425    EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
3426    Widget_Data *wd = elm_widget_data_get(obj);
3427    if (!wd) return NULL;
3428    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3429                                     func_data);
3430    if (!it) return NULL;
3431    if (it->parent)
3432      {
3433         it->parent->items = eina_list_prepend_relative(it->parent->items, it,
3434                                                        before);
3435      }
3436    wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3437                                             EINA_INLIST_GET(before));
3438    it->rel = before;
3439    it->rel->relcount++;
3440    it->before = EINA_TRUE;
3441    _item_queue(wd, it);
3442    return it;
3443 }
3444
3445 /**
3446  * Insert a new item into the sorted genlist object
3447  *
3448  * @param obj The genlist object
3449  * @param itc The item class for the item
3450  * @param data The item data
3451  * @param parent The parent item, or NULL if none
3452  * @param flags Item flags
3453  * @param comp The function called for the sort
3454  * @param func Convenience function called when item selected
3455  * @param func_data Data passed to @p func above.
3456  * @return A handle to the item added or NULL if not possible
3457  *
3458  * @ingroup Genlist
3459  */
3460 EAPI Elm_Genlist_Item *
3461 elm_genlist_item_sorted_insert(Evas_Object                  *obj,
3462                                const Elm_Genlist_Item_Class *itc,
3463                                const void                   *data,
3464                                Elm_Genlist_Item             *parent,
3465                                Elm_Genlist_Item_Flags        flags,
3466                                Eina_Compare_Cb               comp,
3467                                Evas_Smart_Cb                 func,
3468                                const void                   *func_data)
3469 {
3470    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3471    Widget_Data *wd = elm_widget_data_get(obj);
3472    if (!wd) return NULL;
3473    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3474                                     func_data);
3475    if (!it) return NULL;
3476
3477    _elm_genlist_item_compare_cb = comp;
3478    if (it->parent)
3479      {
3480         it->parent->items =
3481            eina_list_sorted_insert(it->parent->items, comp, it);
3482      }
3483    wd->items = eina_inlist_sorted_insert(wd->items, EINA_INLIST_GET(it),
3484                                          _elm_genlist_item_compare);
3485    if (EINA_INLIST_GET(it)->next)
3486      {
3487         it->rel = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3488         it->rel->relcount++;
3489         it->before = EINA_TRUE;
3490      }
3491    else if (EINA_INLIST_GET(it)->prev)
3492      {
3493         it->rel = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3494         it->rel->relcount++;
3495         it->before = EINA_FALSE;
3496      }
3497    _item_queue(wd, it);
3498
3499    return it;
3500 }
3501
3502 /**
3503  * Insert an item after another in the genlst
3504  *
3505  * This inserts an item after another in the list. It will be in the
3506  * same tree level or group as the item it is inseted after.
3507  *
3508  * @param obj The genlist object
3509  * @param itc The item class for the item
3510  * @param data The item data
3511  * @param after The item to insert after
3512  * @param flags Item flags
3513  * @param func Convenience function called when item selected
3514  * @param func_data Data passed to @p func above.
3515  * @return A handle to the item added or NULL if not possible
3516  *
3517  * @ingroup Genlist
3518  */
3519 EAPI Elm_Genlist_Item *
3520 elm_genlist_item_insert_after(Evas_Object                  *obj,
3521                               const Elm_Genlist_Item_Class *itc,
3522                               const void                   *data,
3523                               Elm_Genlist_Item             *parent,
3524                               Elm_Genlist_Item             *after,
3525                               Elm_Genlist_Item_Flags        flags,
3526                               Evas_Smart_Cb                 func,
3527                               const void                   *func_data)
3528 {
3529    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3530    EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
3531    Widget_Data *wd = elm_widget_data_get(obj);
3532    if (!wd) return NULL;
3533    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3534                                     func_data);
3535    if (!it) return NULL;
3536    wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3537                                            EINA_INLIST_GET(after));
3538    if (it->parent)
3539      {
3540         it->parent->items = eina_list_append_relative(it->parent->items, it,
3541                                                       after);
3542      }
3543    it->rel = after;
3544    it->rel->relcount++;
3545    it->before = EINA_FALSE;
3546    _item_queue(wd, it);
3547    return it;
3548 }
3549
3550 /**
3551  * Clear the genlist
3552  *
3553  * This clears all items in the list, leaving it empty.
3554  *
3555  * @param obj The genlist object
3556  *
3557  * @ingroup Genlist
3558  */
3559 EAPI void
3560 elm_genlist_clear(Evas_Object *obj)
3561 {
3562    ELM_CHECK_WIDTYPE(obj, widtype);
3563    Widget_Data *wd = elm_widget_data_get(obj);
3564    if (!wd) return;
3565    if (wd->walking > 0)
3566      {
3567         Elm_Genlist_Item *it;
3568
3569         wd->clear_me = EINA_TRUE;
3570         EINA_INLIST_FOREACH(wd->items, it)
3571           {
3572              it->delete_me = EINA_TRUE;
3573           }
3574         return;
3575      }
3576    evas_event_freeze(evas_object_evas_get(wd->obj));
3577    while (wd->items)
3578      {
3579         Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3580
3581         if (wd->anchor_item == it)
3582           {
3583              wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3584              if (!wd->anchor_item)
3585                wd->anchor_item =
3586                  ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3587           }
3588         wd->items = eina_inlist_remove(wd->items, wd->items);
3589         if (it->flags & ELM_GENLIST_ITEM_GROUP)
3590           it->wd->group_items = eina_list_remove(it->wd->group_items, it);
3591         elm_widget_item_pre_notify_del(it);
3592         if (it->realized) _item_unrealize(it, EINA_FALSE);
3593         if (((wd->clear_me) || (!it->delete_me)) && (it->itc->func.del))
3594           it->itc->func.del((void *)it->base.data, it->base.widget);
3595         if (it->long_timer) ecore_timer_del(it->long_timer);
3596         if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
3597         elm_widget_item_del(it);
3598      }
3599    wd->clear_me = EINA_FALSE;
3600    wd->anchor_item = NULL;
3601    while (wd->blocks)
3602      {
3603         Item_Block *itb = (Item_Block *)(wd->blocks);
3604
3605         wd->blocks = eina_inlist_remove(wd->blocks, wd->blocks);
3606         if (itb->items) eina_list_free(itb->items);
3607         free(itb);
3608      }
3609    if (wd->calc_job)
3610      {
3611         ecore_job_del(wd->calc_job);
3612         wd->calc_job = NULL;
3613      }
3614    if (wd->queue_idle_enterer)
3615      {
3616         ecore_idle_enterer_del(wd->queue_idle_enterer);
3617         wd->queue_idle_enterer = NULL;
3618      }
3619    if (wd->must_recalc_idler)
3620      {
3621         ecore_idler_del(wd->must_recalc_idler);
3622         wd->must_recalc_idler = NULL;
3623      }
3624    if (wd->queue)
3625      {
3626         eina_list_free(wd->queue);
3627         wd->queue = NULL;
3628      }
3629    if (wd->selected)
3630      {
3631         eina_list_free(wd->selected);
3632         wd->selected = NULL;
3633      }
3634    wd->show_item = NULL;
3635    wd->pan_x = 0;
3636    wd->pan_y = 0;
3637    wd->minw = 0;
3638    wd->minh = 0;
3639    if (wd->pan_smart)
3640      {
3641         evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
3642         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
3643      }
3644    _sizing_eval(obj);
3645    evas_event_thaw(evas_object_evas_get(wd->obj));
3646    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3647 }
3648
3649 /**
3650  * Enable or disable multi-select in the genlist
3651  *
3652  * This enables (EINA_TRUE) or disables (EINA_FALSE) multi-select in
3653  * the list. This allows more than 1 item to be selected.
3654  *
3655  * @param obj The genlist object
3656  * @param multi Multi-select enable/disable
3657  *
3658  * @ingroup Genlist
3659  */
3660 EAPI void
3661 elm_genlist_multi_select_set(Evas_Object *obj,
3662                              Eina_Bool    multi)
3663 {
3664    ELM_CHECK_WIDTYPE(obj, widtype);
3665    Widget_Data *wd = elm_widget_data_get(obj);
3666    if (!wd) return;
3667    wd->multi = multi;
3668 }
3669
3670 /**
3671  * Gets if multi-select in genlist is enable or disable
3672  *
3673  * @param obj The genlist object
3674  * @return Multi-select enable/disable
3675  * (EINA_TRUE = enabled/EINA_FALSE = disabled)
3676  *
3677  * @ingroup Genlist
3678  */
3679 EAPI Eina_Bool
3680 elm_genlist_multi_select_get(const Evas_Object *obj)
3681 {
3682    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3683    Widget_Data *wd = elm_widget_data_get(obj);
3684    if (!wd) return EINA_FALSE;
3685    return wd->multi;
3686 }
3687
3688 /**
3689  * Get the selectd item in the genlist
3690  *
3691  * This gets the selected item in the list (if multi-select is enabled
3692  * only the first item in the list is selected - which is not very
3693  * useful, so see elm_genlist_selected_items_get() for when
3694  * multi-select is used).
3695  *
3696  * If no item is selected, NULL is returned.
3697  *
3698  * @param obj The genlist object
3699  * @return The selected item, or NULL if none.
3700  *
3701  * @ingroup Genlist
3702  */
3703 EAPI Elm_Genlist_Item *
3704 elm_genlist_selected_item_get(const Evas_Object *obj)
3705 {
3706    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3707    Widget_Data *wd = elm_widget_data_get(obj);
3708    if (!wd) return NULL;
3709    if (wd->selected) return wd->selected->data;
3710    return NULL;
3711 }
3712
3713 /**
3714  * Get a list of selected items in the genlist
3715  *
3716  * This returns a list of the selected items. This list pointer is
3717  * only valid so long as no items are selected or unselected (or
3718  * unselected implicitly by deletion). The list contains
3719  * Elm_Genlist_Item pointers.
3720  *
3721  * @param obj The genlist object
3722  * @return The list of selected items, nor NULL if none are selected.
3723  *
3724  * @ingroup Genlist
3725  */
3726 EAPI const Eina_List *
3727 elm_genlist_selected_items_get(const Evas_Object *obj)
3728 {
3729    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3730    Widget_Data *wd = elm_widget_data_get(obj);
3731    if (!wd) return NULL;
3732    return wd->selected;
3733 }
3734
3735 /**
3736  * Get a list of realized items in genlist
3737  *
3738  * This returns a list of the realized items in the genlist. The list
3739  * contains Elm_Genlist_Item pointers. The list must be freed by the
3740  * caller when done with eina_list_free(). The item pointers in the
3741  * list are only valid so long as those items are not deleted or the
3742  * genlist is not deleted.
3743  *
3744  * @param obj The genlist object
3745  * @return The list of realized items, nor NULL if none are realized.
3746  *
3747  * @ingroup Genlist
3748  */
3749 EAPI Eina_List *
3750 elm_genlist_realized_items_get(const Evas_Object *obj)
3751 {
3752    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3753    Widget_Data *wd = elm_widget_data_get(obj);
3754    Eina_List *list = NULL;
3755    Item_Block *itb;
3756    Eina_Bool done = EINA_FALSE;
3757    if (!wd) return NULL;
3758    EINA_INLIST_FOREACH(wd->blocks, itb)
3759      {
3760         if (itb->realized)
3761           {
3762              Eina_List *l;
3763              Elm_Genlist_Item *it;
3764
3765              done = 1;
3766              EINA_LIST_FOREACH(itb->items, l, it)
3767                {
3768                   if (it->realized) list = eina_list_append(list, it);
3769                }
3770           }
3771         else
3772           {
3773              if (done) break;
3774           }
3775      }
3776    return list;
3777 }
3778
3779 /**
3780  * Get the item that is at the x, y canvas coords
3781  *
3782  * This returns the item at the given coordinates (which are canvas
3783  * relative not object-relative). If an item is at that coordinate,
3784  * that item handle is returned, and if @p posret is not NULL, the
3785  * integer pointed to is set to a value of -1, 0 or 1, depending if
3786  * the coordinate is on the upper portion of that item (-1), on the
3787  * middle section (0) or on the lower part (1). If NULL is returned as
3788  * an item (no item found there), then posret may indicate -1 or 1
3789  * based if the coordinate is above or below all items respectively in
3790  * the genlist.
3791  *
3792  * @param it The item
3793  * @param x The input x coordinate
3794  * @param y The input y coordinate
3795  * @param posret The position relative to the item returned here
3796  * @return The item at the coordinates or NULL if none
3797  *
3798  * @ingroup Genlist
3799  */
3800 EAPI Elm_Genlist_Item *
3801 elm_genlist_at_xy_item_get(const Evas_Object *obj,
3802                            Evas_Coord         x,
3803                            Evas_Coord         y,
3804                            int               *posret)
3805 {
3806    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3807    Widget_Data *wd = elm_widget_data_get(obj);
3808    Evas_Coord ox, oy, ow, oh;
3809    Item_Block *itb;
3810    Evas_Coord lasty;
3811    if (!wd) return NULL;
3812    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
3813    lasty = oy;
3814    EINA_INLIST_FOREACH(wd->blocks, itb)
3815      {
3816         Eina_List *l;
3817         Elm_Genlist_Item *it;
3818
3819         if (!ELM_RECTS_INTERSECT(ox + itb->x - itb->wd->pan_x,
3820                                  oy + itb->y - itb->wd->pan_y,
3821                                  itb->w, itb->h, x, y, 1, 1))
3822           continue;
3823         EINA_LIST_FOREACH(itb->items, l, it)
3824           {
3825              Evas_Coord itx, ity;
3826
3827              itx = ox + itb->x + it->x - itb->wd->pan_x;
3828              ity = oy + itb->y + it->y - itb->wd->pan_y;
3829              if (ELM_RECTS_INTERSECT(itx, ity, it->w, it->h, x, y, 1, 1))
3830                {
3831                   if (posret)
3832                     {
3833                        if (y <= (ity + (it->h / 4))) *posret = -1;
3834                        else if (y >= (ity + it->h - (it->h / 4)))
3835                          *posret = 1;
3836                        else *posret = 0;
3837                     }
3838                   return it;
3839                }
3840              lasty = ity + it->h;
3841           }
3842      }
3843    if (posret)
3844      {
3845         if (y > lasty) *posret = 1;
3846         else *posret = -1;
3847      }
3848    return NULL;
3849 }
3850
3851 /**
3852  * Get the first item in the genlist
3853  *
3854  * This returns the first item in the list.
3855  *
3856  * @param obj The genlist object
3857  * @return The first item, or NULL if none
3858  *
3859  * @ingroup Genlist
3860  */
3861 EAPI Elm_Genlist_Item *
3862 elm_genlist_first_item_get(const Evas_Object *obj)
3863 {
3864    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3865    Widget_Data *wd = elm_widget_data_get(obj);
3866    if (!wd) return NULL;
3867    if (!wd->items) return NULL;
3868    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3869    while ((it) && (it->delete_me))
3870      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3871    return it;
3872 }
3873
3874 /**
3875  * Get the last item in the genlist
3876  *
3877  * This returns the last item in the list.
3878  *
3879  * @return The last item, or NULL if none
3880  *
3881  * @ingroup Genlist
3882  */
3883 EAPI Elm_Genlist_Item *
3884 elm_genlist_last_item_get(const Evas_Object *obj)
3885 {
3886    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3887    Widget_Data *wd = elm_widget_data_get(obj);
3888    if (!wd) return NULL;
3889    if (!wd->items) return NULL;
3890    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items->last);
3891    while ((it) && (it->delete_me))
3892      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3893    return it;
3894 }
3895
3896 /**
3897  * Get the next item in the genlist
3898  *
3899  * This returns the item after the item @p it.
3900  *
3901  * @param it The item
3902  * @return The item after @p it, or NULL if none
3903  *
3904  * @ingroup Genlist
3905  */
3906 EAPI Elm_Genlist_Item *
3907 elm_genlist_item_next_get(const Elm_Genlist_Item *it)
3908 {
3909    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3910    while (it)
3911      {
3912         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3913         if ((it) && (!it->delete_me)) break;
3914      }
3915    return (Elm_Genlist_Item *)it;
3916 }
3917
3918 /**
3919  * Get the previous item in the genlist
3920  *
3921  * This returns the item before the item @p it.
3922  *
3923  * @param it The item
3924  * @return The item before @p it, or NULL if none
3925  *
3926  * @ingroup Genlist
3927  */
3928 EAPI Elm_Genlist_Item *
3929 elm_genlist_item_prev_get(const Elm_Genlist_Item *it)
3930 {
3931    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3932    while (it)
3933      {
3934         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3935         if ((it) && (!it->delete_me)) break;
3936      }
3937    return (Elm_Genlist_Item *)it;
3938 }
3939
3940 /**
3941  * Get the genlist object from an item
3942  *
3943  * This returns the genlist object itself that an item belongs to.
3944  *
3945  * @param it The item
3946  * @return The genlist object
3947  *
3948  * @ingroup Genlist
3949  */
3950 EAPI Evas_Object *
3951 elm_genlist_item_genlist_get(const Elm_Genlist_Item *it)
3952 {
3953    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3954    return it->base.widget;
3955 }
3956
3957 /**
3958  * Get the parent item of the given item
3959  *
3960  * This returns the parent item of the item @p it given.
3961  *
3962  * @param it The item
3963  * @return The parent of the item or NULL if none
3964  *
3965  * @ingroup Genlist
3966  */
3967 EAPI Elm_Genlist_Item *
3968 elm_genlist_item_parent_get(const Elm_Genlist_Item *it)
3969 {
3970    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3971    return it->parent;
3972 }
3973
3974 /**
3975  * Clear all sub-items (children) of the given item
3976  *
3977  * This clears all items that are children (or their descendants) of the
3978  * given item @p it.
3979  *
3980  * @param it The item
3981  *
3982  * @ingroup Genlist
3983  */
3984 EAPI void
3985 elm_genlist_item_subitems_clear(Elm_Genlist_Item *it)
3986 {
3987    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3988    Eina_List *tl = NULL, *l;
3989    Elm_Genlist_Item *it2;
3990
3991    EINA_LIST_FOREACH(it->items, l, it2)
3992      tl = eina_list_append(tl, it2);
3993    EINA_LIST_FREE(tl, it2)
3994      elm_genlist_item_del(it2);
3995 }
3996
3997 /**
3998  * Set the selected state of an item
3999  *
4000  * This sets the selected state (1 selected, 0 not selected) of the given
4001  * item @p it.
4002  *
4003  * @param it The item
4004  * @param selected The selected state
4005  *
4006  * @ingroup Genlist
4007  */
4008 EAPI void
4009 elm_genlist_item_selected_set(Elm_Genlist_Item *it,
4010                               Eina_Bool         selected)
4011 {
4012    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4013    Widget_Data *wd = elm_widget_data_get(it->base.widget);
4014    if (!wd) return;
4015    if ((it->delete_me) || (it->disabled)) return;
4016    selected = !!selected;
4017    if (it->selected == selected) return;
4018
4019    if (selected)
4020      {
4021         if (!wd->multi)
4022           {
4023              while (wd->selected)
4024                {
4025                   _item_unhighlight(wd->selected->data);
4026                   _item_unselect(wd->selected->data);
4027                }
4028           }
4029         _item_highlight(it);
4030         _item_select(it);
4031      }
4032    else
4033      {
4034         _item_unhighlight(it);
4035         _item_unselect(it);
4036      }
4037 }
4038
4039 /**
4040  * Get the selected state of an item
4041  *
4042  * This gets the selected state of an item (1 selected, 0 not selected).
4043  *
4044  * @param it The item
4045  * @return The selected state
4046  *
4047  * @ingroup Genlist
4048  */
4049 EAPI Eina_Bool
4050 elm_genlist_item_selected_get(const Elm_Genlist_Item *it)
4051 {
4052    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4053    return it->selected;
4054 }
4055
4056 /**
4057  * Sets the expanded state of an item (if it's a parent)
4058  *
4059  * This expands or contracts a parent item (thus showing or hiding the
4060  * children).
4061  *
4062  * @param it The item
4063  * @param expanded The expanded state (1 expanded, 0 not expanded).
4064  *
4065  * @ingroup Genlist
4066  */
4067 EAPI void
4068 elm_genlist_item_expanded_set(Elm_Genlist_Item *it,
4069                               Eina_Bool         expanded)
4070 {
4071    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4072    if (it->expanded == expanded) return;
4073    it->expanded = expanded;
4074    if (it->expanded)
4075      {
4076         if (it->realized)
4077           edje_object_signal_emit(it->base.view, "elm,state,expanded", "elm");
4078         evas_object_smart_callback_call(it->base.widget, SIG_EXPANDED, it);
4079      }
4080    else
4081      {
4082         if (it->realized)
4083           edje_object_signal_emit(it->base.view, "elm,state,contracted", "elm");
4084         evas_object_smart_callback_call(it->base.widget, SIG_CONTRACTED, it);
4085      }
4086 }
4087
4088 /**
4089  * Get the expanded state of an item
4090  *
4091  * This gets the expanded state of an item
4092  *
4093  * @param it The item
4094  * @return Thre expanded state
4095  *
4096  * @ingroup Genlist
4097  */
4098 EAPI Eina_Bool
4099 elm_genlist_item_expanded_get(const Elm_Genlist_Item *it)
4100 {
4101    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4102    return it->expanded;
4103 }
4104
4105 /**
4106  * Get the depth of expanded item
4107  *
4108  * @param it The genlist item object
4109  * @return The depth of expanded item
4110  *
4111  * @ingroup Genlist
4112  */
4113 EAPI int
4114 elm_genlist_item_expanded_depth_get(const Elm_Genlist_Item *it)
4115 {
4116    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, 0);
4117    return it->expanded_depth;
4118 }
4119
4120 /**
4121  * Sets the disabled state of an item.
4122  *
4123  * A disabled item cannot be selected or unselected. It will also
4124  * change appearance to appear disabled. This sets the disabled state
4125  * (1 disabled, 0 not disabled).
4126  *
4127  * @param it The item
4128  * @param disabled The disabled state
4129  *
4130  * @ingroup Genlist
4131  */
4132 EAPI void
4133 elm_genlist_item_disabled_set(Elm_Genlist_Item *it,
4134                               Eina_Bool         disabled)
4135 {
4136    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4137    Eina_List *l;
4138    Evas_Object *obj;
4139    if (it->disabled == disabled) return;
4140    if (it->delete_me) return;
4141    it->disabled = !!disabled;
4142    if (it->selected)
4143      elm_genlist_item_selected_set(it, EINA_FALSE);
4144    if (it->realized)
4145      {
4146         if (it->disabled)
4147           edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
4148         else
4149           edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
4150         EINA_LIST_FOREACH(it->icon_objs, l, obj)
4151           elm_widget_disabled_set(obj, disabled);
4152      }
4153 }
4154
4155 /**
4156  * Get the disabled state of an item
4157  *
4158  * This gets the disabled state of the given item.
4159  *
4160  * @param it The item
4161  * @return The disabled state
4162  *
4163  * @ingroup Genlist
4164  */
4165 EAPI Eina_Bool
4166 elm_genlist_item_disabled_get(const Elm_Genlist_Item *it)
4167 {
4168    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4169    if (it->delete_me) return EINA_FALSE;
4170    return it->disabled;
4171 }
4172
4173 /**
4174  * Sets the display only state of an item.
4175  *
4176  * A display only item cannot be selected or unselected. It is for
4177  * display only and not selecting or otherwise clicking, dragging
4178  * etc. by the user, thus finger size rules will not be applied to
4179  * this item.
4180  *
4181  * @param it The item
4182  * @param display_only The display only state
4183  *
4184  * @ingroup Genlist
4185  */
4186 EAPI void
4187 elm_genlist_item_display_only_set(Elm_Genlist_Item *it,
4188                                   Eina_Bool         display_only)
4189 {
4190    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4191    if (it->display_only == display_only) return;
4192    if (it->delete_me) return;
4193    it->display_only = display_only;
4194    it->mincalcd = EINA_FALSE;
4195    it->updateme = EINA_TRUE;
4196    if (it->block) it->block->updateme = EINA_TRUE;
4197    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4198    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4199 }
4200
4201 /**
4202  * Get the display only state of an item
4203  *
4204  * This gets the display only state of the given item.
4205  *
4206  * @param it The item
4207  * @return The display only state
4208  *
4209  * @ingroup Genlist
4210  */
4211 EAPI Eina_Bool
4212 elm_genlist_item_display_only_get(const Elm_Genlist_Item *it)
4213 {
4214    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4215    if (it->delete_me) return EINA_FALSE;
4216    return it->display_only;
4217 }
4218
4219 /**
4220  * Show the given item
4221  *
4222  * This causes genlist to jump to the given item @p it and show it (by
4223  * scrolling), if it is not fully visible.
4224  *
4225  * @param it The item
4226  *
4227  * @ingroup Genlist
4228  */
4229 EAPI void
4230 elm_genlist_item_show(Elm_Genlist_Item *it)
4231 {
4232    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4233    Evas_Coord gith = 0;
4234    if (it->delete_me) return;
4235    if ((it->queued) || (!it->mincalcd))
4236      {
4237         it->wd->show_item = it;
4238         it->wd->bring_in = EINA_TRUE;
4239         it->showme = EINA_TRUE;
4240         return;
4241      }
4242    if (it->wd->show_item)
4243      {
4244         it->wd->show_item->showme = EINA_FALSE;
4245         it->wd->show_item = NULL;
4246      }
4247    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4248      gith = it->group_item->h;
4249    elm_smart_scroller_child_region_show(it->wd->scr,
4250                                         it->x + it->block->x,
4251                                         it->y + it->block->y - gith,
4252                                         it->block->w, it->h);
4253 }
4254
4255 /**
4256  * Bring in the given item
4257  *
4258  * This causes genlist to jump to the given item @p it and show it (by
4259  * scrolling), if it is not fully visible. This may use animation to
4260  * do so and take a period of time
4261  *
4262  * @param it The item
4263  *
4264  * @ingroup Genlist
4265  */
4266 EAPI void
4267 elm_genlist_item_bring_in(Elm_Genlist_Item *it)
4268 {
4269    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4270    Evas_Coord gith = 0;
4271    if (it->delete_me) return;
4272    if ((it->queued) || (!it->mincalcd))
4273      {
4274         it->wd->show_item = it;
4275         it->wd->bring_in = EINA_TRUE;
4276         it->showme = EINA_TRUE;
4277         return;
4278      }
4279    if (it->wd->show_item)
4280      {
4281         it->wd->show_item->showme = EINA_FALSE;
4282         it->wd->show_item = NULL;
4283      }
4284    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4285      gith = it->group_item->h;
4286    elm_smart_scroller_region_bring_in(it->wd->scr,
4287                                       it->x + it->block->x,
4288                                       it->y + it->block->y - gith,
4289                                       it->block->w, it->h);
4290 }
4291
4292 /**
4293  * Show the given item at the top
4294  *
4295  * This causes genlist to jump to the given item @p it and show it (by
4296  * scrolling), if it is not fully visible.
4297  *
4298  * @param it The item
4299  *
4300  * @ingroup Genlist
4301  */
4302 EAPI void
4303 elm_genlist_item_top_show(Elm_Genlist_Item *it)
4304 {
4305    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4306    Evas_Coord ow, oh;
4307    Evas_Coord gith = 0;
4308
4309    if (it->delete_me) return;
4310    if ((it->queued) || (!it->mincalcd))
4311      {
4312         it->wd->show_item = it;
4313         it->wd->bring_in = EINA_TRUE;
4314         it->showme = EINA_TRUE;
4315         return;
4316      }
4317    if (it->wd->show_item)
4318      {
4319         it->wd->show_item->showme = EINA_FALSE;
4320         it->wd->show_item = NULL;
4321      }
4322    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4323    if (it->group_item) gith = it->group_item->h;
4324    elm_smart_scroller_child_region_show(it->wd->scr,
4325                                         it->x + it->block->x,
4326                                         it->y + it->block->y - gith,
4327                                         it->block->w, oh);
4328 }
4329
4330 /**
4331  * Bring in the given item at the top
4332  *
4333  * This causes genlist to jump to the given item @p it and show it (by
4334  * scrolling), if it is not fully visible. This may use animation to
4335  * do so and take a period of time
4336  *
4337  * @param it The item
4338  *
4339  * @ingroup Genlist
4340  */
4341 EAPI void
4342 elm_genlist_item_top_bring_in(Elm_Genlist_Item *it)
4343 {
4344    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4345    Evas_Coord ow, oh;
4346    Evas_Coord gith = 0;
4347
4348    if (it->delete_me) return;
4349    if ((it->queued) || (!it->mincalcd))
4350      {
4351         it->wd->show_item = it;
4352         it->wd->bring_in = EINA_TRUE;
4353         it->showme = EINA_TRUE;
4354         return;
4355      }
4356    if (it->wd->show_item)
4357      {
4358         it->wd->show_item->showme = EINA_FALSE;
4359         it->wd->show_item = NULL;
4360      }
4361    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4362    if (it->group_item) gith = it->group_item->h;
4363    elm_smart_scroller_region_bring_in(it->wd->scr,
4364                                       it->x + it->block->x,
4365                                       it->y + it->block->y - gith,
4366                                       it->block->w, oh);
4367 }
4368
4369 /**
4370  * Show the given item at the middle
4371  *
4372  * This causes genlist to jump to the given item @p it and show it (by
4373  * scrolling), if it is not fully visible.
4374  *
4375  * @param it The item
4376  *
4377  * @ingroup Genlist
4378  */
4379 EAPI void
4380 elm_genlist_item_middle_show(Elm_Genlist_Item *it)
4381 {
4382    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4383    Evas_Coord ow, oh;
4384
4385    if (it->delete_me) return;
4386    if ((it->queued) || (!it->mincalcd))
4387      {
4388         it->wd->show_item = it;
4389         it->wd->bring_in = EINA_TRUE;
4390         it->showme = EINA_TRUE;
4391         return;
4392      }
4393    if (it->wd->show_item)
4394      {
4395         it->wd->show_item->showme = EINA_FALSE;
4396         it->wd->show_item = NULL;
4397      }
4398    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4399    elm_smart_scroller_child_region_show(it->wd->scr,
4400                                         it->x + it->block->x,
4401                                         it->y + it->block->y - oh / 2 +
4402                                         it->h / 2, it->block->w, oh);
4403 }
4404
4405 /**
4406  * Bring in the given item at the middle
4407  *
4408  * This causes genlist to jump to the given item @p it and show it (by
4409  * scrolling), if it is not fully visible. This may use animation to
4410  * do so and take a period of time
4411  *
4412  * @param it The item
4413  *
4414  * @ingroup Genlist
4415  */
4416 EAPI void
4417 elm_genlist_item_middle_bring_in(Elm_Genlist_Item *it)
4418 {
4419    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4420    Evas_Coord ow, oh;
4421
4422    if (it->delete_me) return;
4423    if ((it->queued) || (!it->mincalcd))
4424      {
4425         it->wd->show_item = it;
4426         it->wd->bring_in = EINA_TRUE;
4427         it->showme = EINA_TRUE;
4428         return;
4429      }
4430    if (it->wd->show_item)
4431      {
4432         it->wd->show_item->showme = EINA_FALSE;
4433         it->wd->show_item = NULL;
4434      }
4435    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4436    elm_smart_scroller_region_bring_in(it->wd->scr,
4437                                       it->x + it->block->x,
4438                                       it->y + it->block->y - oh / 2 + it->h / 2,
4439                                       it->block->w, oh);
4440 }
4441
4442 /**
4443  * Delete a given item
4444  *
4445  * This deletes the item from genlist and calls the genlist item del
4446  * class callback defined in the item class, if it is set. This clears all
4447  * subitems if it is a tree.
4448  *
4449  * @param it The item
4450  *
4451  * @ingroup Genlist
4452  */
4453 EAPI void
4454 elm_genlist_item_del(Elm_Genlist_Item *it)
4455 {
4456    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4457    if ((it->relcount > 0) || (it->walking > 0))
4458      {
4459         elm_widget_item_pre_notify_del(it);
4460         elm_genlist_item_subitems_clear(it);
4461         it->delete_me = EINA_TRUE;
4462         if (it->wd->show_item == it) it->wd->show_item = NULL;
4463         if (it->selected)
4464           it->wd->selected = eina_list_remove(it->wd->selected,
4465                                               it);
4466         if (it->block)
4467           {
4468              if (it->realized) _item_unrealize(it, EINA_FALSE);
4469              it->block->changed = EINA_TRUE;
4470              if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
4471              it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
4472           }
4473         if (it->itc->func.del)
4474           it->itc->func.del((void *)it->base.data, it->base.widget);
4475         return;
4476      }
4477    _item_del(it);
4478 }
4479
4480 /**
4481  * Set the data item from the genlist item
4482  *
4483  * This set the data value passed on the elm_genlist_item_append() and
4484  * related item addition calls. This function will also call
4485  * elm_genlist_item_update() so the item will be updated to reflect the
4486  * new data.
4487  *
4488  * @param it The item
4489  * @param data The new data pointer to set
4490  *
4491  * @ingroup Genlist
4492  */
4493 EAPI void
4494 elm_genlist_item_data_set(Elm_Genlist_Item *it,
4495                           const void       *data)
4496 {
4497    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4498    elm_widget_item_data_set(it, data);
4499    elm_genlist_item_update(it);
4500 }
4501
4502 /**
4503  * Get the data item from the genlist item
4504  *
4505  * This returns the data value passed on the elm_genlist_item_append()
4506  * and related item addition calls and elm_genlist_item_data_set().
4507  *
4508  * @param it The item
4509  * @return The data pointer provided when created
4510  *
4511  * @ingroup Genlist
4512  */
4513 EAPI void *
4514 elm_genlist_item_data_get(const Elm_Genlist_Item *it)
4515 {
4516    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4517    return elm_widget_item_data_get(it);
4518 }
4519
4520 /**
4521  * Tells genlist to "orphan" icons fetchs by the item class
4522  *
4523  * This instructs genlist to release references to icons in the item,
4524  * meaning that they will no longer be managed by genlist and are
4525  * floating "orphans" that can be re-used elsewhere if the user wants
4526  * to.
4527  *
4528  * @param it The item
4529  *
4530  * @ingroup Genlist
4531  */
4532 EAPI void
4533 elm_genlist_item_icons_orphan(Elm_Genlist_Item *it)
4534 {
4535    Evas_Object *icon;
4536    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4537    EINA_LIST_FREE(it->icon_objs, icon)
4538      {
4539         elm_widget_sub_object_del(it->base.widget, icon);
4540         evas_object_smart_member_del(icon);
4541         evas_object_hide(icon);
4542      }
4543 }
4544
4545 /**
4546  * Get the real evas object of the genlist item
4547  *
4548  * This returns the actual evas object used for the specified genlist
4549  * item. This may be NULL as it may not be created, and may be deleted
4550  * at any time by genlist. Do not modify this object (move, resize,
4551  * show, hide etc.) as genlist is controlling it. This function is for
4552  * querying, emitting custom signals or hooking lower level callbacks
4553  * for events. Do not delete this object under any circumstances.
4554  *
4555  * @param it The item
4556  * @return The object pointer
4557  *
4558  * @ingroup Genlist
4559  */
4560 EAPI const Evas_Object *
4561 elm_genlist_item_object_get(const Elm_Genlist_Item *it)
4562 {
4563    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4564    return it->base.view;
4565 }
4566
4567 /**
4568  * Update the contents of an item
4569  *
4570  * This updates an item by calling all the item class functions again
4571  * to get the icons, labels and states. Use this when the original
4572  * item data has changed and the changes are desired to be reflected.
4573  *
4574  * @param it The item
4575  *
4576  * @ingroup Genlist
4577  */
4578 EAPI void
4579 elm_genlist_item_update(Elm_Genlist_Item *it)
4580 {
4581    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4582    if (!it->block) return;
4583    if (it->delete_me) return;
4584    it->mincalcd = EINA_FALSE;
4585    it->updateme = EINA_TRUE;
4586    it->block->updateme = EINA_TRUE;
4587    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4588    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4589 }
4590
4591 /**
4592  * Update the item class of an item
4593  *
4594  * @param it The item
4595  * @parem itc The item class for the item
4596  *
4597  * @ingroup Genlist
4598  */
4599 EAPI void
4600 elm_genlist_item_item_class_update(Elm_Genlist_Item             *it,
4601                                    const Elm_Genlist_Item_Class *itc)
4602 {
4603    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4604    if (!it->block) return;
4605    EINA_SAFETY_ON_NULL_RETURN(itc);
4606    if (it->delete_me) return;
4607    it->itc = itc;
4608    it->nocache = EINA_TRUE;
4609    elm_genlist_item_update(it);
4610 }
4611
4612 static Evas_Object *
4613 _elm_genlist_item_label_create(void        *data,
4614                                Evas_Object *obj,
4615                                void        *item __UNUSED__)
4616 {
4617    Evas_Object *label = elm_label_add(obj);
4618    if (!label)
4619      return NULL;
4620    elm_object_style_set(label, "tooltip");
4621    elm_label_label_set(label, data);
4622    return label;
4623 }
4624
4625 static void
4626 _elm_genlist_item_label_del_cb(void        *data,
4627                                Evas_Object *obj __UNUSED__,
4628                                void        *event_info __UNUSED__)
4629 {
4630    eina_stringshare_del(data);
4631 }
4632
4633 /**
4634  * Set the text to be shown in the genlist item.
4635  *
4636  * @param item Target item
4637  * @param text The text to set in the content
4638  *
4639  * Setup the text as tooltip to object. The item can have only one
4640  * tooltip, so any previous tooltip data is removed.
4641  *
4642  * @ingroup Genlist
4643  */
4644 EAPI void
4645 elm_genlist_item_tooltip_text_set(Elm_Genlist_Item *item,
4646                                   const char       *text)
4647 {
4648    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4649    text = eina_stringshare_add(text);
4650    elm_genlist_item_tooltip_content_cb_set(item, _elm_genlist_item_label_create,
4651                                            text,
4652                                            _elm_genlist_item_label_del_cb);
4653 }
4654
4655 /**
4656  * Set the content to be shown in the tooltip item
4657  *
4658  * Setup the tooltip to item. The item can have only one tooltip, so
4659  * any previous tooltip data is removed. @p func(with @p data) will be
4660  * called every time that need to show the tooltip and it should return a
4661  * valid Evas_Object. This object is then managed fully by tooltip
4662  * system and is deleted when the tooltip is gone.
4663  *
4664  * @param item the genlist item being attached by a tooltip.
4665  * @param func the function used to create the tooltip contents.
4666  * @param data what to provide to @a func as callback data/context.
4667  * @param del_cb called when data is not needed anymore, either when
4668  *        another callback replaces @func, the tooltip is unset with
4669  *        elm_genlist_item_tooltip_unset() or the owner @a item
4670  *        dies. This callback receives as the first parameter the
4671  *        given @a data, and @c event_info is the item.
4672  *
4673  * @ingroup Genlist
4674  */
4675 EAPI void
4676 elm_genlist_item_tooltip_content_cb_set(Elm_Genlist_Item           *item,
4677                                         Elm_Tooltip_Item_Content_Cb func,
4678                                         const void                 *data,
4679                                         Evas_Smart_Cb               del_cb)
4680 {
4681    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
4682
4683    if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
4684      return;
4685
4686    if (item->tooltip.del_cb)
4687      item->tooltip.del_cb((void *)item->tooltip.data,
4688                           item->base.widget, item);
4689
4690    item->tooltip.content_cb = func;
4691    item->tooltip.data = data;
4692    item->tooltip.del_cb = del_cb;
4693
4694    if (item->base.view)
4695      {
4696         elm_widget_item_tooltip_content_cb_set(item,
4697                                                item->tooltip.content_cb,
4698                                                item->tooltip.data, NULL);
4699         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
4700      }
4701
4702    return;
4703
4704 error:
4705    if (del_cb) del_cb((void *)data, NULL, NULL);
4706 }
4707
4708 /**
4709  * Unset tooltip from item
4710  *
4711  * @param item genlist item to remove previously set tooltip.
4712  *
4713  * Remove tooltip from item. The callback provided as del_cb to
4714  * elm_genlist_item_tooltip_content_cb_set() will be called to notify
4715  * it is not used anymore.
4716  *
4717  * @see elm_genlist_item_tooltip_content_cb_set()
4718  *
4719  * @ingroup Genlist
4720  */
4721 EAPI void
4722 elm_genlist_item_tooltip_unset(Elm_Genlist_Item *item)
4723 {
4724    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4725    if ((item->base.view) && (item->tooltip.content_cb))
4726      elm_widget_item_tooltip_unset(item);
4727
4728    if (item->tooltip.del_cb)
4729      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
4730    item->tooltip.del_cb = NULL;
4731    item->tooltip.content_cb = NULL;
4732    item->tooltip.data = NULL;
4733    if (item->tooltip.style)
4734      elm_genlist_item_tooltip_style_set(item, NULL);
4735 }
4736
4737 /**
4738  * Sets a different style for this item tooltip.
4739  *
4740  * @note before you set a style you should define a tooltip with
4741  *       elm_genlist_item_tooltip_content_cb_set() or
4742  *       elm_genlist_item_tooltip_text_set()
4743  *
4744  * @param item genlist item with tooltip already set.
4745  * @param style the theme style to use (default, transparent, ...)
4746  *
4747  * @ingroup Genlist
4748  */
4749 EAPI void
4750 elm_genlist_item_tooltip_style_set(Elm_Genlist_Item *item,
4751                                    const char       *style)
4752 {
4753    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4754    eina_stringshare_replace(&item->tooltip.style, style);
4755    if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
4756 }
4757
4758 /**
4759  * Get the style for this item tooltip.
4760  *
4761  * @param item genlist item with tooltip already set.
4762  * @return style the theme style in use, defaults to "default". If the
4763  *         object does not have a tooltip set, then NULL is returned.
4764  *
4765  * @ingroup Genlist
4766  */
4767 EAPI const char *
4768 elm_genlist_item_tooltip_style_get(const Elm_Genlist_Item *item)
4769 {
4770    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4771    return item->tooltip.style;
4772 }
4773
4774 /**
4775  * Set the cursor to be shown when mouse is over the genlist item
4776  *
4777  * @param item Target item
4778  * @param cursor the cursor name to be used.
4779  *
4780  * @see elm_object_cursor_set()
4781  * @ingroup Genlist
4782  */
4783 EAPI void
4784 elm_genlist_item_cursor_set(Elm_Genlist_Item *item,
4785                             const char       *cursor)
4786 {
4787    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4788    eina_stringshare_replace(&item->mouse_cursor, cursor);
4789    if (item->base.view) elm_widget_item_cursor_set(item, cursor);
4790 }
4791
4792 /**
4793  * Get the cursor to be shown when mouse is over the genlist item
4794  *
4795  * @param item genlist item with cursor already set.
4796  * @return the cursor name.
4797  *
4798  * @ingroup Genlist
4799  */
4800 EAPI const char *
4801 elm_genlist_item_cursor_get(const Elm_Genlist_Item *item)
4802 {
4803    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4804    return elm_widget_item_cursor_get(item);
4805 }
4806
4807 /**
4808  * Unset the cursor to be shown when mouse is over the genlist item
4809  *
4810  * @param item Target item
4811  *
4812  * @see elm_object_cursor_unset()
4813  * @ingroup Genlist
4814  */
4815 EAPI void
4816 elm_genlist_item_cursor_unset(Elm_Genlist_Item *item)
4817 {
4818    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4819    if (!item->mouse_cursor)
4820      return;
4821
4822    if (item->base.view)
4823      elm_widget_item_cursor_unset(item);
4824
4825    eina_stringshare_del(item->mouse_cursor);
4826    item->mouse_cursor = NULL;
4827 }
4828
4829 /**
4830  * Sets a different style for this item cursor.
4831  *
4832  * @note before you set a style you should define a cursor with
4833  *       elm_genlist_item_cursor_set()
4834  *
4835  * @param item genlist item with cursor already set.
4836  * @param style the theme style to use (default, transparent, ...)
4837  *
4838  * @ingroup Genlist
4839  */
4840 EAPI void
4841 elm_genlist_item_cursor_style_set(Elm_Genlist_Item *item,
4842                                   const char       *style)
4843 {
4844    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4845    elm_widget_item_cursor_style_set(item, style);
4846 }
4847
4848 /**
4849  * Get the style for this item cursor.
4850  *
4851  * @param item genlist item with cursor already set.
4852  * @return style the theme style in use, defaults to "default". If the
4853  *         object does not have a cursor set, then NULL is returned.
4854  *
4855  * @ingroup Genlist
4856  */
4857 EAPI const char *
4858 elm_genlist_item_cursor_style_get(const Elm_Genlist_Item *item)
4859 {
4860    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4861    return elm_widget_item_cursor_style_get(item);
4862 }
4863
4864 /**
4865  * Set if the cursor set should be searched on the theme or should use
4866  * the provided by the engine, only.
4867  *
4868  * @note before you set if should look on theme you should define a
4869  * cursor with elm_object_cursor_set(). By default it will only look
4870  * for cursors provided by the engine.
4871  *
4872  * @param item widget item with cursor already set.
4873  * @param engine_only boolean to define it cursors should be looked
4874  * only between the provided by the engine or searched on widget's
4875  * theme as well.
4876  *
4877  * @ingroup Genlist
4878  */
4879 EAPI void
4880 elm_genlist_item_cursor_engine_only_set(Elm_Genlist_Item *item,
4881                                         Eina_Bool         engine_only)
4882 {
4883    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4884    elm_widget_item_cursor_engine_only_set(item, engine_only);
4885 }
4886
4887 /**
4888  * Get the cursor engine only usage for this item cursor.
4889  *
4890  * @param item widget item with cursor already set.
4891  * @return engine_only boolean to define it cursors should be looked
4892  * only between the provided by the engine or searched on widget's
4893  * theme as well. If the object does not have a cursor set, then
4894  * EINA_FALSE is returned.
4895  *
4896  * @ingroup Genlist
4897  */
4898 EAPI Eina_Bool
4899 elm_genlist_item_cursor_engine_only_get(const Elm_Genlist_Item *item)
4900 {
4901    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
4902    return elm_widget_item_cursor_engine_only_get(item);
4903 }
4904
4905 /**
4906  * This sets the horizontal stretching mode
4907  *
4908  * This sets the mode used for sizing items horizontally. Valid modes
4909  * are ELM_LIST_LIMIT and ELM_LIST_SCROLL. The default is
4910  * ELM_LIST_SCROLL. This mode means that if items are too wide to fit,
4911  * the scroller will scroll horizontally. Otherwise items are expanded
4912  * to fill the width of the viewport of the scroller. If it is
4913  * ELM_LIST_LIMIT, Items will be expanded to the viewport width and
4914  * limited to that size.
4915  *
4916  * @param obj The genlist object
4917  * @param mode The mode to use
4918  *
4919  * @ingroup Genlist
4920  */
4921 EAPI void
4922 elm_genlist_horizontal_mode_set(Evas_Object  *obj,
4923                                 Elm_List_Mode mode)
4924 {
4925    ELM_CHECK_WIDTYPE(obj, widtype);
4926    Widget_Data *wd = elm_widget_data_get(obj);
4927    if (!wd) return;
4928    if (wd->mode == mode) return;
4929    wd->mode = mode;
4930    _sizing_eval(obj);
4931 }
4932
4933 /**
4934  * Gets the horizontal stretching mode
4935  *
4936  * @param obj The genlist object
4937  * @return The mode to use
4938  * (ELM_LIST_LIMIT, ELM_LIST_SCROLL)
4939  *
4940  * @ingroup Genlist
4941  */
4942 EAPI Elm_List_Mode
4943 elm_genlist_horizontal_mode_get(const Evas_Object *obj)
4944 {
4945    ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
4946    Widget_Data *wd = elm_widget_data_get(obj);
4947    if (!wd) return ELM_LIST_LAST;
4948    return wd->mode;
4949 }
4950
4951 /**
4952  * Set the always select mode.
4953  *
4954  * Items will only call their selection func and callback when first
4955  * becoming selected. Any further clicks will do nothing, unless you
4956  * enable always select with elm_genlist_always_select_mode_set().
4957  * This means even if selected, every click will make the selected
4958  * callbacks be called.
4959  *
4960  * @param obj The genlist object
4961  * @param always_select The always select mode
4962  * (EINA_TRUE = on, EINA_FALSE = off)
4963  *
4964  * @ingroup Genlist
4965  */
4966 EAPI void
4967 elm_genlist_always_select_mode_set(Evas_Object *obj,
4968                                    Eina_Bool    always_select)
4969 {
4970    ELM_CHECK_WIDTYPE(obj, widtype);
4971    Widget_Data *wd = elm_widget_data_get(obj);
4972    if (!wd) return;
4973    wd->always_select = always_select;
4974 }
4975
4976 /**
4977  * Get the always select mode.
4978  *
4979  * @param obj The genlist object
4980  * @return The always select mode
4981  * (EINA_TRUE = on, EINA_FALSE = off)
4982  *
4983  * @ingroup Genlist
4984  */
4985 EAPI Eina_Bool
4986 elm_genlist_always_select_mode_get(const Evas_Object *obj)
4987 {
4988    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4989    Widget_Data *wd = elm_widget_data_get(obj);
4990    if (!wd) return EINA_FALSE;
4991    return wd->always_select;
4992 }
4993
4994 /**
4995  * Set no select mode
4996  *
4997  * This will turn off the ability to select items entirely and they
4998  * will neither appear selected nor call selected callback functions.
4999  *
5000  * @param obj The genlist object
5001  * @param no_select The no select mode
5002  * (EINA_TRUE = on, EINA_FALSE = off)
5003  *
5004  * @ingroup Genlist
5005  */
5006 EAPI void
5007 elm_genlist_no_select_mode_set(Evas_Object *obj,
5008                                Eina_Bool    no_select)
5009 {
5010    ELM_CHECK_WIDTYPE(obj, widtype);
5011    Widget_Data *wd = elm_widget_data_get(obj);
5012    if (!wd) return;
5013    wd->no_select = no_select;
5014 }
5015
5016 /**
5017  * Gets no select mode
5018  *
5019  * @param obj The genlist object
5020  * @return The no select mode
5021  * (EINA_TRUE = on, EINA_FALSE = off)
5022  *
5023  * @ingroup Genlist
5024  */
5025 EAPI Eina_Bool
5026 elm_genlist_no_select_mode_get(const Evas_Object *obj)
5027 {
5028    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5029    Widget_Data *wd = elm_widget_data_get(obj);
5030    if (!wd) return EINA_FALSE;
5031    return wd->no_select;
5032 }
5033
5034 /**
5035  * Set compress mode
5036  *
5037  * This will enable the compress mode where items are "compressed"
5038  * horizontally to fit the genlist scrollable viewport width. This is
5039  * special for genlist.  Do not rely on
5040  * elm_genlist_horizontal_mode_set() being set to ELM_LIST_COMPRESS to
5041  * work as genlist needs to handle it specially.
5042  *
5043  * @param obj The genlist object
5044  * @param compress The compress mode
5045  * (EINA_TRUE = on, EINA_FALSE = off)
5046  *
5047  * @ingroup Genlist
5048  */
5049 EAPI void
5050 elm_genlist_compress_mode_set(Evas_Object *obj,
5051                               Eina_Bool    compress)
5052 {
5053    ELM_CHECK_WIDTYPE(obj, widtype);
5054    Widget_Data *wd = elm_widget_data_get(obj);
5055    if (!wd) return;
5056    wd->compress = compress;
5057    if (!compress) elm_genlist_homogeneous_set(obj, EINA_FALSE);
5058 }
5059
5060 /**
5061  * Get the compress mode
5062  *
5063  * @param obj The genlist object
5064  * @return The compress mode
5065  * (EINA_TRUE = on, EINA_FALSE = off)
5066  *
5067  * @ingroup Genlist
5068  */
5069 EAPI Eina_Bool
5070 elm_genlist_compress_mode_get(const Evas_Object *obj)
5071 {
5072    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5073    Widget_Data *wd = elm_widget_data_get(obj);
5074    if (!wd) return EINA_FALSE;
5075    return wd->compress;
5076 }
5077
5078 /**
5079  * Set height-for-width mode
5080  *
5081  * With height-for-width mode the item width will be fixed (restricted
5082  * to a minimum of) to the list width when calculating its size in
5083  * order to allow the height to be calculated based on it. This allows,
5084  * for instance, text block to wrap lines if the Edje part is
5085  * configured with "text.min: 0 1".
5086  *
5087  * @note This mode will make list resize slower as it will have to
5088  *       recalculate every item height again whenever the list width
5089  *       changes!
5090  *
5091  * @note When height-for-width mode is enabled, it also enables
5092  *       compress mode (see elm_genlist_compress_mode_set()) and
5093  *       disables homogeneous (see elm_genlist_homogeneous_set()).
5094  *
5095  * @param obj The genlist object
5096  * @param setting The height-for-width mode (EINA_TRUE = on,
5097  * EINA_FALSE = off)
5098  *
5099  * @ingroup Genlist
5100  */
5101 EAPI void
5102 elm_genlist_height_for_width_mode_set(Evas_Object *obj,
5103                                       Eina_Bool    height_for_width)
5104 {
5105    ELM_CHECK_WIDTYPE(obj, widtype);
5106    Widget_Data *wd = elm_widget_data_get(obj);
5107    if (!wd) return;
5108    wd->height_for_width = !!height_for_width;
5109    if (wd->height_for_width)
5110      {
5111         elm_genlist_homogeneous_set(obj, EINA_FALSE);
5112         elm_genlist_compress_mode_set(obj, EINA_TRUE);
5113      }
5114 }
5115
5116 /**
5117  * Get the height-for-width mode
5118  *
5119  * @param obj The genlist object
5120  * @return The height-for-width mode (EINA_TRUE = on, EINA_FALSE =
5121  * off)
5122  *
5123  * @ingroup Genlist
5124  */
5125 EAPI Eina_Bool
5126 elm_genlist_height_for_width_mode_get(const Evas_Object *obj)
5127 {
5128    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5129    Widget_Data *wd = elm_widget_data_get(obj);
5130    if (!wd) return EINA_FALSE;
5131    return wd->height_for_width;
5132 }
5133
5134 /**
5135  * Set bounce mode
5136  *
5137  * This will enable or disable the scroller bounce mode for the
5138  * genlist. See elm_scroller_bounce_set() for details
5139  *
5140  * @param obj The genlist object
5141  * @param h_bounce Allow bounce horizontally
5142  * @param v_bounce Allow bounce vertically
5143  *
5144  * @ingroup Genlist
5145  */
5146 EAPI void
5147 elm_genlist_bounce_set(Evas_Object *obj,
5148                        Eina_Bool    h_bounce,
5149                        Eina_Bool    v_bounce)
5150 {
5151    ELM_CHECK_WIDTYPE(obj, widtype);
5152    Widget_Data *wd = elm_widget_data_get(obj);
5153    if (!wd) return;
5154    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
5155 }
5156
5157 /**
5158  * Get the bounce mode
5159  *
5160  * @param obj The genlist object
5161  * @param h_bounce Allow bounce horizontally
5162  * @param v_bounce Allow bounce vertically
5163  *
5164  * @ingroup Genlist
5165  */
5166 EAPI void
5167 elm_genlist_bounce_get(const Evas_Object *obj,
5168                        Eina_Bool         *h_bounce,
5169                        Eina_Bool         *v_bounce)
5170 {
5171    ELM_CHECK_WIDTYPE(obj, widtype);
5172    Widget_Data *wd = elm_widget_data_get(obj);
5173    if (!wd) return;
5174    elm_smart_scroller_bounce_allow_get(obj, h_bounce, v_bounce);
5175 }
5176
5177 /**
5178  * Set homogenous mode
5179  *
5180  * This will enable the homogeneous mode where items are of the same
5181  * height and width so that genlist may do the lazy-loading at its
5182  * maximum. This implies 'compressed' mode.
5183  *
5184  * @param obj The genlist object
5185  * @param homogeneous Assume the items within the genlist are of the
5186  * same height and width (EINA_TRUE = on, EINA_FALSE = off)
5187  *
5188  * @ingroup Genlist
5189  */
5190 EAPI void
5191 elm_genlist_homogeneous_set(Evas_Object *obj,
5192                             Eina_Bool    homogeneous)
5193 {
5194    ELM_CHECK_WIDTYPE(obj, widtype);
5195    Widget_Data *wd = elm_widget_data_get(obj);
5196    if (!wd) return;
5197    if (homogeneous) elm_genlist_compress_mode_set(obj, EINA_TRUE);
5198    wd->homogeneous = homogeneous;
5199 }
5200
5201 /**
5202  * Get the homogenous mode
5203  *
5204  * @param obj The genlist object
5205  * @return Assume the items within the genlist are of the same height
5206  * and width (EINA_TRUE = on, EINA_FALSE = off)
5207  *
5208  * @ingroup Genlist
5209  */
5210 EAPI Eina_Bool
5211 elm_genlist_homogeneous_get(const Evas_Object *obj)
5212 {
5213    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5214    Widget_Data *wd = elm_widget_data_get(obj);
5215    if (!wd) return EINA_FALSE;
5216    return wd->homogeneous;
5217 }
5218
5219 /**
5220  * Set the maximum number of items within an item block
5221  *
5222  * This will configure the block count to tune to the target with
5223  * particular performance matrix.
5224  *
5225  * @param obj The genlist object
5226  * @param n   Maximum number of items within an item block
5227  *
5228  * @ingroup Genlist
5229  */
5230 EAPI void
5231 elm_genlist_block_count_set(Evas_Object *obj,
5232                             int          n)
5233 {
5234    ELM_CHECK_WIDTYPE(obj, widtype);
5235    Widget_Data *wd = elm_widget_data_get(obj);
5236    if (!wd) return;
5237    wd->max_items_per_block = n;
5238    wd->item_cache_max = wd->max_items_per_block * 2;
5239    _item_cache_clean(wd);
5240 }
5241
5242 /**
5243  * Get the maximum number of items within an item block
5244  *
5245  * @param obj The genlist object
5246  * @return Maximum number of items within an item block
5247  *
5248  * @ingroup Genlist
5249  */
5250 EAPI int
5251 elm_genlist_block_count_get(const Evas_Object *obj)
5252 {
5253    ELM_CHECK_WIDTYPE(obj, widtype) 0;
5254    Widget_Data *wd = elm_widget_data_get(obj);
5255    if (!wd) return 0;
5256    return wd->max_items_per_block;
5257 }
5258
5259 /**
5260  * Set the timeout in seconds for the longpress event
5261  *
5262  * @param obj The genlist object
5263  * @param timeout timeout in seconds
5264  *
5265  * @ingroup Genlist
5266  */
5267 EAPI void
5268 elm_genlist_longpress_timeout_set(Evas_Object *obj,
5269                                   double       timeout)
5270 {
5271    ELM_CHECK_WIDTYPE(obj, widtype);
5272    Widget_Data *wd = elm_widget_data_get(obj);
5273    if (!wd) return;
5274    wd->longpress_timeout = timeout;
5275 }
5276
5277 /**
5278  * Get the timeout in seconds for the longpress event
5279  *
5280  * @param obj The genlist object
5281  * @return timeout in seconds
5282  *
5283  * @ingroup Genlist
5284  */
5285 EAPI double
5286 elm_genlist_longpress_timeout_get(const Evas_Object *obj)
5287 {
5288    ELM_CHECK_WIDTYPE(obj, widtype) 0;
5289    Widget_Data *wd = elm_widget_data_get(obj);
5290    if (!wd) return 0;
5291    return wd->longpress_timeout;
5292 }
5293
5294 /**
5295  * Set the scrollbar policy
5296  *
5297  * This sets the scrollbar visibility policy for the given genlist
5298  * scroller. ELM_SMART_SCROLLER_POLICY_AUTO means the scrollbar is
5299  * made visible if it is needed, and otherwise kept hidden.
5300  * ELM_SMART_SCROLLER_POLICY_ON turns it on all the time, and
5301  * ELM_SMART_SCROLLER_POLICY_OFF always keeps it off. This applies
5302  * respectively for the horizontal and vertical scrollbars.
5303  *
5304  * @param obj The genlist object
5305  * @param policy_h Horizontal scrollbar policy
5306  * @param policy_v Vertical scrollbar policy
5307  *
5308  * @ingroup Genlist
5309  */
5310 EAPI void
5311 elm_genlist_scroller_policy_set(Evas_Object        *obj,
5312                                 Elm_Scroller_Policy policy_h,
5313                                 Elm_Scroller_Policy policy_v)
5314 {
5315    ELM_CHECK_WIDTYPE(obj, widtype);
5316    Widget_Data *wd = elm_widget_data_get(obj);
5317    if (!wd) return;
5318    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
5319        (policy_v >= ELM_SCROLLER_POLICY_LAST))
5320      return;
5321    if (wd->scr)
5322      elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
5323 }
5324
5325 /**
5326  * Get the scrollbar policy
5327  *
5328  * @param obj The genlist object
5329  * @param policy_h Horizontal scrollbar policy
5330  * @param policy_v Vertical scrollbar policy
5331  *
5332  * @ingroup Genlist
5333  */
5334 EAPI void
5335 elm_genlist_scroller_policy_get(const Evas_Object   *obj,
5336                                 Elm_Scroller_Policy *policy_h,
5337                                 Elm_Scroller_Policy *policy_v)
5338 {
5339    ELM_CHECK_WIDTYPE(obj, widtype);
5340    Widget_Data *wd = elm_widget_data_get(obj);
5341    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
5342    if ((!wd) || (!wd->scr)) return;
5343    elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
5344    if (policy_h) *policy_h = (Elm_Scroller_Policy)s_policy_h;
5345    if (policy_v) *policy_v = (Elm_Scroller_Policy)s_policy_v;
5346 }
5347
5348 /**
5349  * Update the contents of all realized items
5350  *
5351  * This updates all realized items by calling all the item class functions again
5352  * to get the icons, labels and states. Use this when the original
5353  * item data has changed and the changes are desired to be reflected.
5354  *
5355  * @param it The item
5356  *
5357  * @ingroup Genlist
5358  */
5359 EAPI void
5360 elm_genlist_realized_items_update(Evas_Object *obj)
5361 {
5362    ELM_CHECK_WIDTYPE(obj, widtype);
5363
5364    Eina_List *list, *l;
5365    Elm_Genlist_Item *it;
5366
5367    list = elm_genlist_realized_items_get(obj);
5368    EINA_LIST_FOREACH(list, l, it)
5369      elm_genlist_item_update(it);
5370 }
5371
5372 /**
5373  * Set genlist item mode
5374  *
5375  * @param item The genlist item
5376  * @param mode Mode name
5377  * @param mode_set Boolean to define set or unset mode.
5378  *
5379  * @ingroup Genlist
5380  */
5381 EAPI void
5382 elm_genlist_item_mode_set(Elm_Genlist_Item *it,
5383                           const char       *mode_type,
5384                           Eina_Bool         mode_set)
5385 {
5386    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
5387    Widget_Data *wd = it->wd;
5388    Eina_List *l;
5389    Elm_Genlist_Item *it2;
5390
5391    if (!wd) return;
5392    if (!mode_type) return;
5393    if ((it->delete_me) || (it->disabled)) return;
5394
5395    if ((wd->mode_item == it) &&
5396        (!strcmp(mode_type, wd->mode_type)) &&
5397        (mode_set))
5398       return;
5399    if (!it->itc->mode_item_style) return;
5400
5401    if (wd->multi)
5402      {
5403         EINA_LIST_FOREACH(wd->selected, l, it2)
5404           if (it2->realized)
5405             elm_genlist_item_selected_set(it2, EINA_FALSE);
5406      }
5407    else
5408      {
5409         it2 = elm_genlist_selected_item_get(wd->obj);
5410         if ((it2) && (it2->realized))
5411           elm_genlist_item_selected_set(it2, EINA_FALSE);
5412      }
5413
5414    if (((wd->mode_type) && (strcmp(mode_type, wd->mode_type))) ||
5415        (mode_set) ||
5416        ((it == wd->mode_item) && (!mode_set)))
5417      _item_mode_unset(wd);
5418
5419    eina_stringshare_replace(&wd->mode_type, mode_type);
5420    if (mode_set) _item_mode_set(it);
5421 }
5422
5423 /**
5424  * Get active genlist mode type
5425  *
5426  * @param obj The genlist object
5427  *
5428  * @ingroup Genlist
5429  */
5430 EAPI const char *
5431 elm_genlist_mode_get(const Evas_Object *obj)
5432 {
5433    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5434    Widget_Data *wd = elm_widget_data_get(obj);
5435    if (!wd) return NULL;
5436    return wd->mode_type;
5437 }
5438
5439 /**
5440  * Get active genlist mode item
5441  *
5442  * @param obj The genlist object
5443  *
5444  * @ingroup Genlist
5445  */
5446 EAPI const Elm_Genlist_Item *
5447 elm_genlist_mode_item_get(const Evas_Object *obj)
5448 {
5449    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5450    Widget_Data *wd = elm_widget_data_get(obj);
5451    if (!wd) return NULL;
5452    return wd->mode_item;
5453 }