seems 1 frereze+thaw causes slowdown... thanks dan! :)
[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 // FIXME: why does a freeze then thaw here cause some genlist
3254 // elm_genlist_item_append() to be much much slower?
3255 //   evas_event_freeze(evas_object_evas_get(wd->obj));
3256    while ((wd->queue) && ((!wd->blocks) || (!wd->blocks->next)))
3257      {
3258         if (wd->queue_idle_enterer)
3259           {
3260              ecore_idle_enterer_del(wd->queue_idle_enterer);
3261              wd->queue_idle_enterer = NULL;
3262           }
3263         _queue_process(wd);
3264      }
3265 //   evas_event_thaw(evas_object_evas_get(wd->obj));
3266 //   evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3267    if (!wd->queue_idle_enterer)
3268       wd->queue_idle_enterer = ecore_idle_enterer_add(_item_idle_enterer, wd);
3269 }
3270
3271 static int
3272 _elm_genlist_item_compare(const void *data, const void *data1)
3273 {
3274    Elm_Genlist_Item *item, *item1;
3275    item = ELM_GENLIST_ITEM_FROM_INLIST(data);
3276    item1 = ELM_GENLIST_ITEM_FROM_INLIST(data1);
3277    return _elm_genlist_item_compare_cb(item->base.data, item1->base.data);
3278 }
3279
3280 /**
3281  * Append item to the end of the genlist
3282  *
3283  * This appends the given item to the end of the list or the end of
3284  * the children if the parent is given.
3285  *
3286  * @param obj The genlist object
3287  * @param itc The item class for the item
3288  * @param data The item data
3289  * @param parent The parent item, or NULL if none
3290  * @param flags Item flags
3291  * @param func Convenience function called when item selected
3292  * @param func_data Data passed to @p func above.
3293  * @return A handle to the item added or NULL if not possible
3294  *
3295  * @ingroup Genlist
3296  */
3297 EAPI Elm_Genlist_Item *
3298 elm_genlist_item_append(Evas_Object                  *obj,
3299                         const Elm_Genlist_Item_Class *itc,
3300                         const void                   *data,
3301                         Elm_Genlist_Item             *parent,
3302                         Elm_Genlist_Item_Flags        flags,
3303                         Evas_Smart_Cb                 func,
3304                         const void                   *func_data)
3305 {
3306    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3307    Widget_Data *wd = elm_widget_data_get(obj);
3308    if (!wd) return NULL;
3309    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3310                                     func_data);
3311    if (!it) return NULL;
3312    if (!it->parent)
3313      {
3314         if (flags & ELM_GENLIST_ITEM_GROUP)
3315           wd->group_items = eina_list_append(wd->group_items, it);
3316         wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
3317         it->rel = NULL;
3318      }
3319    else
3320      {
3321         Elm_Genlist_Item *it2 = NULL;
3322         Eina_List *ll = eina_list_last(it->parent->items);
3323         if (ll) it2 = ll->data;
3324         it->parent->items = eina_list_append(it->parent->items, it);
3325         if (!it2) it2 = it->parent;
3326         wd->items =
3327            eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3328                                        EINA_INLIST_GET(it2));
3329         it->rel = it2;
3330         it->rel->relcount++;
3331
3332         if (it->parent->flags & ELM_GENLIST_ITEM_GROUP)
3333           it->group_item = parent;
3334         else if (it->parent->group_item)
3335           it->group_item = it->parent->group_item;
3336      }
3337    it->before = EINA_FALSE;
3338    _item_queue(wd, it);
3339    return it;
3340 }
3341
3342 /**
3343  * Prepend item at start of the genlist
3344  *
3345  * This adds an item to the beginning of the list or beginning of the
3346  * children of the parent if given.
3347  *
3348  * @param obj The genlist object
3349  * @param itc The item class for the item
3350  * @param data The item data
3351  * @param parent The parent item, or NULL if none
3352  * @param flags Item flags
3353  * @param func Convenience function called when item selected
3354  * @param func_data Data passed to @p func above.
3355  * @return A handle to the item added or NULL if not possible
3356  *
3357  * @ingroup Genlist
3358  */
3359 EAPI Elm_Genlist_Item *
3360 elm_genlist_item_prepend(Evas_Object                  *obj,
3361                          const Elm_Genlist_Item_Class *itc,
3362                          const void                   *data,
3363                          Elm_Genlist_Item             *parent,
3364                          Elm_Genlist_Item_Flags        flags,
3365                          Evas_Smart_Cb                 func,
3366                          const void                   *func_data)
3367 {
3368    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3369    Widget_Data *wd = elm_widget_data_get(obj);
3370    if (!wd) return NULL;
3371    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3372                                     func_data);
3373    if (!it) return NULL;
3374    if (!it->parent)
3375      {
3376         if (flags & ELM_GENLIST_ITEM_GROUP)
3377           wd->group_items = eina_list_prepend(wd->group_items, it);
3378         wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
3379         it->rel = NULL;
3380      }
3381    else
3382      {
3383         Elm_Genlist_Item *it2 = NULL;
3384         Eina_List *ll = it->parent->items;
3385         if (ll) it2 = ll->data;
3386         it->parent->items = eina_list_prepend(it->parent->items, it);
3387         if (!it2) it2 = it->parent;
3388         wd->items =
3389           eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3390                                        EINA_INLIST_GET(it2));
3391         it->rel = it2;
3392         it->rel->relcount++;
3393      }
3394    it->before = EINA_TRUE;
3395    _item_queue(wd, it);
3396    return it;
3397 }
3398
3399 /**
3400  * Insert item before another in the genlist
3401  *
3402  * This inserts an item before another in the list. It will be in the
3403  * same tree level or group as the item it is inseted before.
3404  *
3405  * @param obj The genlist object
3406  * @param itc The item class for the item
3407  * @param data The item data
3408  * @param before The item to insert before
3409  * @param flags Item flags
3410  * @param func Convenience function called when item selected
3411  * @param func_data Data passed to @p func above.
3412  * @return A handle to the item added or NULL if not possible
3413  *
3414  * @ingroup Genlist
3415  */
3416 EAPI Elm_Genlist_Item *
3417 elm_genlist_item_insert_before(Evas_Object                  *obj,
3418                                const Elm_Genlist_Item_Class *itc,
3419                                const void                   *data,
3420                                Elm_Genlist_Item             *parent,
3421                                Elm_Genlist_Item             *before,
3422                                Elm_Genlist_Item_Flags        flags,
3423                                Evas_Smart_Cb                 func,
3424                                const void                   *func_data)
3425 {
3426    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3427    EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
3428    Widget_Data *wd = elm_widget_data_get(obj);
3429    if (!wd) return NULL;
3430    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3431                                     func_data);
3432    if (!it) return NULL;
3433    if (it->parent)
3434      {
3435         it->parent->items = eina_list_prepend_relative(it->parent->items, it,
3436                                                        before);
3437      }
3438    wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3439                                             EINA_INLIST_GET(before));
3440    it->rel = before;
3441    it->rel->relcount++;
3442    it->before = EINA_TRUE;
3443    _item_queue(wd, it);
3444    return it;
3445 }
3446
3447 /**
3448  * Insert a new item into the sorted genlist object
3449  *
3450  * @param obj The genlist object
3451  * @param itc The item class for the item
3452  * @param data The item data
3453  * @param parent The parent item, or NULL if none
3454  * @param flags Item flags
3455  * @param comp The function called for the sort
3456  * @param func Convenience function called when item selected
3457  * @param func_data Data passed to @p func above.
3458  * @return A handle to the item added or NULL if not possible
3459  *
3460  * @ingroup Genlist
3461  */
3462 EAPI Elm_Genlist_Item *
3463 elm_genlist_item_sorted_insert(Evas_Object                  *obj,
3464                                const Elm_Genlist_Item_Class *itc,
3465                                const void                   *data,
3466                                Elm_Genlist_Item             *parent,
3467                                Elm_Genlist_Item_Flags        flags,
3468                                Eina_Compare_Cb               comp,
3469                                Evas_Smart_Cb                 func,
3470                                const void                   *func_data)
3471 {
3472    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3473    Widget_Data *wd = elm_widget_data_get(obj);
3474    if (!wd) return NULL;
3475    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3476                                     func_data);
3477    if (!it) return NULL;
3478
3479    _elm_genlist_item_compare_cb = comp;
3480    if (it->parent)
3481      {
3482         it->parent->items =
3483            eina_list_sorted_insert(it->parent->items, comp, it);
3484      }
3485    wd->items = eina_inlist_sorted_insert(wd->items, EINA_INLIST_GET(it),
3486                                          _elm_genlist_item_compare);
3487    if (EINA_INLIST_GET(it)->next)
3488      {
3489         it->rel = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3490         it->rel->relcount++;
3491         it->before = EINA_TRUE;
3492      }
3493    else if (EINA_INLIST_GET(it)->prev)
3494      {
3495         it->rel = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3496         it->rel->relcount++;
3497         it->before = EINA_FALSE;
3498      }
3499    _item_queue(wd, it);
3500
3501    return it;
3502 }
3503
3504 /**
3505  * Insert an item after another in the genlst
3506  *
3507  * This inserts an item after another in the list. It will be in the
3508  * same tree level or group as the item it is inseted after.
3509  *
3510  * @param obj The genlist object
3511  * @param itc The item class for the item
3512  * @param data The item data
3513  * @param after The item to insert after
3514  * @param flags Item flags
3515  * @param func Convenience function called when item selected
3516  * @param func_data Data passed to @p func above.
3517  * @return A handle to the item added or NULL if not possible
3518  *
3519  * @ingroup Genlist
3520  */
3521 EAPI Elm_Genlist_Item *
3522 elm_genlist_item_insert_after(Evas_Object                  *obj,
3523                               const Elm_Genlist_Item_Class *itc,
3524                               const void                   *data,
3525                               Elm_Genlist_Item             *parent,
3526                               Elm_Genlist_Item             *after,
3527                               Elm_Genlist_Item_Flags        flags,
3528                               Evas_Smart_Cb                 func,
3529                               const void                   *func_data)
3530 {
3531    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3532    EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
3533    Widget_Data *wd = elm_widget_data_get(obj);
3534    if (!wd) return NULL;
3535    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3536                                     func_data);
3537    if (!it) return NULL;
3538    wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3539                                            EINA_INLIST_GET(after));
3540    if (it->parent)
3541      {
3542         it->parent->items = eina_list_append_relative(it->parent->items, it,
3543                                                       after);
3544      }
3545    it->rel = after;
3546    it->rel->relcount++;
3547    it->before = EINA_FALSE;
3548    _item_queue(wd, it);
3549    return it;
3550 }
3551
3552 /**
3553  * Clear the genlist
3554  *
3555  * This clears all items in the list, leaving it empty.
3556  *
3557  * @param obj The genlist object
3558  *
3559  * @ingroup Genlist
3560  */
3561 EAPI void
3562 elm_genlist_clear(Evas_Object *obj)
3563 {
3564    ELM_CHECK_WIDTYPE(obj, widtype);
3565    Widget_Data *wd = elm_widget_data_get(obj);
3566    if (!wd) return;
3567    if (wd->walking > 0)
3568      {
3569         Elm_Genlist_Item *it;
3570
3571         wd->clear_me = EINA_TRUE;
3572         EINA_INLIST_FOREACH(wd->items, it)
3573           {
3574              it->delete_me = EINA_TRUE;
3575           }
3576         return;
3577      }
3578    evas_event_freeze(evas_object_evas_get(wd->obj));
3579    while (wd->items)
3580      {
3581         Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3582
3583         if (wd->anchor_item == it)
3584           {
3585              wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3586              if (!wd->anchor_item)
3587                wd->anchor_item =
3588                  ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3589           }
3590         wd->items = eina_inlist_remove(wd->items, wd->items);
3591         if (it->flags & ELM_GENLIST_ITEM_GROUP)
3592           it->wd->group_items = eina_list_remove(it->wd->group_items, it);
3593         elm_widget_item_pre_notify_del(it);
3594         if (it->realized) _item_unrealize(it, EINA_FALSE);
3595         if (((wd->clear_me) || (!it->delete_me)) && (it->itc->func.del))
3596           it->itc->func.del((void *)it->base.data, it->base.widget);
3597         if (it->long_timer) ecore_timer_del(it->long_timer);
3598         if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
3599         elm_widget_item_del(it);
3600      }
3601    wd->clear_me = EINA_FALSE;
3602    wd->anchor_item = NULL;
3603    while (wd->blocks)
3604      {
3605         Item_Block *itb = (Item_Block *)(wd->blocks);
3606
3607         wd->blocks = eina_inlist_remove(wd->blocks, wd->blocks);
3608         if (itb->items) eina_list_free(itb->items);
3609         free(itb);
3610      }
3611    if (wd->calc_job)
3612      {
3613         ecore_job_del(wd->calc_job);
3614         wd->calc_job = NULL;
3615      }
3616    if (wd->queue_idle_enterer)
3617      {
3618         ecore_idle_enterer_del(wd->queue_idle_enterer);
3619         wd->queue_idle_enterer = NULL;
3620      }
3621    if (wd->must_recalc_idler)
3622      {
3623         ecore_idler_del(wd->must_recalc_idler);
3624         wd->must_recalc_idler = NULL;
3625      }
3626    if (wd->queue)
3627      {
3628         eina_list_free(wd->queue);
3629         wd->queue = NULL;
3630      }
3631    if (wd->selected)
3632      {
3633         eina_list_free(wd->selected);
3634         wd->selected = NULL;
3635      }
3636    wd->show_item = NULL;
3637    wd->pan_x = 0;
3638    wd->pan_y = 0;
3639    wd->minw = 0;
3640    wd->minh = 0;
3641    if (wd->pan_smart)
3642      {
3643         evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
3644         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
3645      }
3646    _sizing_eval(obj);
3647    evas_event_thaw(evas_object_evas_get(wd->obj));
3648    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
3649 }
3650
3651 /**
3652  * Enable or disable multi-select in the genlist
3653  *
3654  * This enables (EINA_TRUE) or disables (EINA_FALSE) multi-select in
3655  * the list. This allows more than 1 item to be selected.
3656  *
3657  * @param obj The genlist object
3658  * @param multi Multi-select enable/disable
3659  *
3660  * @ingroup Genlist
3661  */
3662 EAPI void
3663 elm_genlist_multi_select_set(Evas_Object *obj,
3664                              Eina_Bool    multi)
3665 {
3666    ELM_CHECK_WIDTYPE(obj, widtype);
3667    Widget_Data *wd = elm_widget_data_get(obj);
3668    if (!wd) return;
3669    wd->multi = multi;
3670 }
3671
3672 /**
3673  * Gets if multi-select in genlist is enable or disable
3674  *
3675  * @param obj The genlist object
3676  * @return Multi-select enable/disable
3677  * (EINA_TRUE = enabled/EINA_FALSE = disabled)
3678  *
3679  * @ingroup Genlist
3680  */
3681 EAPI Eina_Bool
3682 elm_genlist_multi_select_get(const Evas_Object *obj)
3683 {
3684    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3685    Widget_Data *wd = elm_widget_data_get(obj);
3686    if (!wd) return EINA_FALSE;
3687    return wd->multi;
3688 }
3689
3690 /**
3691  * Get the selectd item in the genlist
3692  *
3693  * This gets the selected item in the list (if multi-select is enabled
3694  * only the first item in the list is selected - which is not very
3695  * useful, so see elm_genlist_selected_items_get() for when
3696  * multi-select is used).
3697  *
3698  * If no item is selected, NULL is returned.
3699  *
3700  * @param obj The genlist object
3701  * @return The selected item, or NULL if none.
3702  *
3703  * @ingroup Genlist
3704  */
3705 EAPI Elm_Genlist_Item *
3706 elm_genlist_selected_item_get(const Evas_Object *obj)
3707 {
3708    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3709    Widget_Data *wd = elm_widget_data_get(obj);
3710    if (!wd) return NULL;
3711    if (wd->selected) return wd->selected->data;
3712    return NULL;
3713 }
3714
3715 /**
3716  * Get a list of selected items in the genlist
3717  *
3718  * This returns a list of the selected items. This list pointer is
3719  * only valid so long as no items are selected or unselected (or
3720  * unselected implicitly by deletion). The list contains
3721  * Elm_Genlist_Item pointers.
3722  *
3723  * @param obj The genlist object
3724  * @return The list of selected items, nor NULL if none are selected.
3725  *
3726  * @ingroup Genlist
3727  */
3728 EAPI const Eina_List *
3729 elm_genlist_selected_items_get(const Evas_Object *obj)
3730 {
3731    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3732    Widget_Data *wd = elm_widget_data_get(obj);
3733    if (!wd) return NULL;
3734    return wd->selected;
3735 }
3736
3737 /**
3738  * Get a list of realized items in genlist
3739  *
3740  * This returns a list of the realized items in the genlist. The list
3741  * contains Elm_Genlist_Item pointers. The list must be freed by the
3742  * caller when done with eina_list_free(). The item pointers in the
3743  * list are only valid so long as those items are not deleted or the
3744  * genlist is not deleted.
3745  *
3746  * @param obj The genlist object
3747  * @return The list of realized items, nor NULL if none are realized.
3748  *
3749  * @ingroup Genlist
3750  */
3751 EAPI Eina_List *
3752 elm_genlist_realized_items_get(const Evas_Object *obj)
3753 {
3754    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3755    Widget_Data *wd = elm_widget_data_get(obj);
3756    Eina_List *list = NULL;
3757    Item_Block *itb;
3758    Eina_Bool done = EINA_FALSE;
3759    if (!wd) return NULL;
3760    EINA_INLIST_FOREACH(wd->blocks, itb)
3761      {
3762         if (itb->realized)
3763           {
3764              Eina_List *l;
3765              Elm_Genlist_Item *it;
3766
3767              done = 1;
3768              EINA_LIST_FOREACH(itb->items, l, it)
3769                {
3770                   if (it->realized) list = eina_list_append(list, it);
3771                }
3772           }
3773         else
3774           {
3775              if (done) break;
3776           }
3777      }
3778    return list;
3779 }
3780
3781 /**
3782  * Get the item that is at the x, y canvas coords
3783  *
3784  * This returns the item at the given coordinates (which are canvas
3785  * relative not object-relative). If an item is at that coordinate,
3786  * that item handle is returned, and if @p posret is not NULL, the
3787  * integer pointed to is set to a value of -1, 0 or 1, depending if
3788  * the coordinate is on the upper portion of that item (-1), on the
3789  * middle section (0) or on the lower part (1). If NULL is returned as
3790  * an item (no item found there), then posret may indicate -1 or 1
3791  * based if the coordinate is above or below all items respectively in
3792  * the genlist.
3793  *
3794  * @param it The item
3795  * @param x The input x coordinate
3796  * @param y The input y coordinate
3797  * @param posret The position relative to the item returned here
3798  * @return The item at the coordinates or NULL if none
3799  *
3800  * @ingroup Genlist
3801  */
3802 EAPI Elm_Genlist_Item *
3803 elm_genlist_at_xy_item_get(const Evas_Object *obj,
3804                            Evas_Coord         x,
3805                            Evas_Coord         y,
3806                            int               *posret)
3807 {
3808    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3809    Widget_Data *wd = elm_widget_data_get(obj);
3810    Evas_Coord ox, oy, ow, oh;
3811    Item_Block *itb;
3812    Evas_Coord lasty;
3813    if (!wd) return NULL;
3814    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
3815    lasty = oy;
3816    EINA_INLIST_FOREACH(wd->blocks, itb)
3817      {
3818         Eina_List *l;
3819         Elm_Genlist_Item *it;
3820
3821         if (!ELM_RECTS_INTERSECT(ox + itb->x - itb->wd->pan_x,
3822                                  oy + itb->y - itb->wd->pan_y,
3823                                  itb->w, itb->h, x, y, 1, 1))
3824           continue;
3825         EINA_LIST_FOREACH(itb->items, l, it)
3826           {
3827              Evas_Coord itx, ity;
3828
3829              itx = ox + itb->x + it->x - itb->wd->pan_x;
3830              ity = oy + itb->y + it->y - itb->wd->pan_y;
3831              if (ELM_RECTS_INTERSECT(itx, ity, it->w, it->h, x, y, 1, 1))
3832                {
3833                   if (posret)
3834                     {
3835                        if (y <= (ity + (it->h / 4))) *posret = -1;
3836                        else if (y >= (ity + it->h - (it->h / 4)))
3837                          *posret = 1;
3838                        else *posret = 0;
3839                     }
3840                   return it;
3841                }
3842              lasty = ity + it->h;
3843           }
3844      }
3845    if (posret)
3846      {
3847         if (y > lasty) *posret = 1;
3848         else *posret = -1;
3849      }
3850    return NULL;
3851 }
3852
3853 /**
3854  * Get the first item in the genlist
3855  *
3856  * This returns the first item in the list.
3857  *
3858  * @param obj The genlist object
3859  * @return The first item, or NULL if none
3860  *
3861  * @ingroup Genlist
3862  */
3863 EAPI Elm_Genlist_Item *
3864 elm_genlist_first_item_get(const Evas_Object *obj)
3865 {
3866    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3867    Widget_Data *wd = elm_widget_data_get(obj);
3868    if (!wd) return NULL;
3869    if (!wd->items) return NULL;
3870    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3871    while ((it) && (it->delete_me))
3872      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3873    return it;
3874 }
3875
3876 /**
3877  * Get the last item in the genlist
3878  *
3879  * This returns the last item in the list.
3880  *
3881  * @return The last item, or NULL if none
3882  *
3883  * @ingroup Genlist
3884  */
3885 EAPI Elm_Genlist_Item *
3886 elm_genlist_last_item_get(const Evas_Object *obj)
3887 {
3888    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3889    Widget_Data *wd = elm_widget_data_get(obj);
3890    if (!wd) return NULL;
3891    if (!wd->items) return NULL;
3892    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items->last);
3893    while ((it) && (it->delete_me))
3894      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3895    return it;
3896 }
3897
3898 /**
3899  * Get the next item in the genlist
3900  *
3901  * This returns the item after the item @p it.
3902  *
3903  * @param it The item
3904  * @return The item after @p it, or NULL if none
3905  *
3906  * @ingroup Genlist
3907  */
3908 EAPI Elm_Genlist_Item *
3909 elm_genlist_item_next_get(const Elm_Genlist_Item *it)
3910 {
3911    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3912    while (it)
3913      {
3914         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3915         if ((it) && (!it->delete_me)) break;
3916      }
3917    return (Elm_Genlist_Item *)it;
3918 }
3919
3920 /**
3921  * Get the previous item in the genlist
3922  *
3923  * This returns the item before the item @p it.
3924  *
3925  * @param it The item
3926  * @return The item before @p it, or NULL if none
3927  *
3928  * @ingroup Genlist
3929  */
3930 EAPI Elm_Genlist_Item *
3931 elm_genlist_item_prev_get(const Elm_Genlist_Item *it)
3932 {
3933    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3934    while (it)
3935      {
3936         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3937         if ((it) && (!it->delete_me)) break;
3938      }
3939    return (Elm_Genlist_Item *)it;
3940 }
3941
3942 /**
3943  * Get the genlist object from an item
3944  *
3945  * This returns the genlist object itself that an item belongs to.
3946  *
3947  * @param it The item
3948  * @return The genlist object
3949  *
3950  * @ingroup Genlist
3951  */
3952 EAPI Evas_Object *
3953 elm_genlist_item_genlist_get(const Elm_Genlist_Item *it)
3954 {
3955    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3956    return it->base.widget;
3957 }
3958
3959 /**
3960  * Get the parent item of the given item
3961  *
3962  * This returns the parent item of the item @p it given.
3963  *
3964  * @param it The item
3965  * @return The parent of the item or NULL if none
3966  *
3967  * @ingroup Genlist
3968  */
3969 EAPI Elm_Genlist_Item *
3970 elm_genlist_item_parent_get(const Elm_Genlist_Item *it)
3971 {
3972    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3973    return it->parent;
3974 }
3975
3976 /**
3977  * Clear all sub-items (children) of the given item
3978  *
3979  * This clears all items that are children (or their descendants) of the
3980  * given item @p it.
3981  *
3982  * @param it The item
3983  *
3984  * @ingroup Genlist
3985  */
3986 EAPI void
3987 elm_genlist_item_subitems_clear(Elm_Genlist_Item *it)
3988 {
3989    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3990    Eina_List *tl = NULL, *l;
3991    Elm_Genlist_Item *it2;
3992
3993    EINA_LIST_FOREACH(it->items, l, it2)
3994      tl = eina_list_append(tl, it2);
3995    EINA_LIST_FREE(tl, it2)
3996      elm_genlist_item_del(it2);
3997 }
3998
3999 /**
4000  * Set the selected state of an item
4001  *
4002  * This sets the selected state (1 selected, 0 not selected) of the given
4003  * item @p it.
4004  *
4005  * @param it The item
4006  * @param selected The selected state
4007  *
4008  * @ingroup Genlist
4009  */
4010 EAPI void
4011 elm_genlist_item_selected_set(Elm_Genlist_Item *it,
4012                               Eina_Bool         selected)
4013 {
4014    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4015    Widget_Data *wd = elm_widget_data_get(it->base.widget);
4016    if (!wd) return;
4017    if ((it->delete_me) || (it->disabled)) return;
4018    selected = !!selected;
4019    if (it->selected == selected) return;
4020
4021    if (selected)
4022      {
4023         if (!wd->multi)
4024           {
4025              while (wd->selected)
4026                {
4027                   _item_unhighlight(wd->selected->data);
4028                   _item_unselect(wd->selected->data);
4029                }
4030           }
4031         _item_highlight(it);
4032         _item_select(it);
4033      }
4034    else
4035      {
4036         _item_unhighlight(it);
4037         _item_unselect(it);
4038      }
4039 }
4040
4041 /**
4042  * Get the selected state of an item
4043  *
4044  * This gets the selected state of an item (1 selected, 0 not selected).
4045  *
4046  * @param it The item
4047  * @return The selected state
4048  *
4049  * @ingroup Genlist
4050  */
4051 EAPI Eina_Bool
4052 elm_genlist_item_selected_get(const Elm_Genlist_Item *it)
4053 {
4054    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4055    return it->selected;
4056 }
4057
4058 /**
4059  * Sets the expanded state of an item (if it's a parent)
4060  *
4061  * This expands or contracts a parent item (thus showing or hiding the
4062  * children).
4063  *
4064  * @param it The item
4065  * @param expanded The expanded state (1 expanded, 0 not expanded).
4066  *
4067  * @ingroup Genlist
4068  */
4069 EAPI void
4070 elm_genlist_item_expanded_set(Elm_Genlist_Item *it,
4071                               Eina_Bool         expanded)
4072 {
4073    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4074    if (it->expanded == expanded) return;
4075    it->expanded = expanded;
4076    if (it->expanded)
4077      {
4078         if (it->realized)
4079           edje_object_signal_emit(it->base.view, "elm,state,expanded", "elm");
4080         evas_object_smart_callback_call(it->base.widget, SIG_EXPANDED, it);
4081      }
4082    else
4083      {
4084         if (it->realized)
4085           edje_object_signal_emit(it->base.view, "elm,state,contracted", "elm");
4086         evas_object_smart_callback_call(it->base.widget, SIG_CONTRACTED, it);
4087      }
4088 }
4089
4090 /**
4091  * Get the expanded state of an item
4092  *
4093  * This gets the expanded state of an item
4094  *
4095  * @param it The item
4096  * @return Thre expanded state
4097  *
4098  * @ingroup Genlist
4099  */
4100 EAPI Eina_Bool
4101 elm_genlist_item_expanded_get(const Elm_Genlist_Item *it)
4102 {
4103    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4104    return it->expanded;
4105 }
4106
4107 /**
4108  * Get the depth of expanded item
4109  *
4110  * @param it The genlist item object
4111  * @return The depth of expanded item
4112  *
4113  * @ingroup Genlist
4114  */
4115 EAPI int
4116 elm_genlist_item_expanded_depth_get(const Elm_Genlist_Item *it)
4117 {
4118    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, 0);
4119    return it->expanded_depth;
4120 }
4121
4122 /**
4123  * Sets the disabled state of an item.
4124  *
4125  * A disabled item cannot be selected or unselected. It will also
4126  * change appearance to appear disabled. This sets the disabled state
4127  * (1 disabled, 0 not disabled).
4128  *
4129  * @param it The item
4130  * @param disabled The disabled state
4131  *
4132  * @ingroup Genlist
4133  */
4134 EAPI void
4135 elm_genlist_item_disabled_set(Elm_Genlist_Item *it,
4136                               Eina_Bool         disabled)
4137 {
4138    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4139    Eina_List *l;
4140    Evas_Object *obj;
4141    if (it->disabled == disabled) return;
4142    if (it->delete_me) return;
4143    it->disabled = !!disabled;
4144    if (it->selected)
4145      elm_genlist_item_selected_set(it, EINA_FALSE);
4146    if (it->realized)
4147      {
4148         if (it->disabled)
4149           edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
4150         else
4151           edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
4152         EINA_LIST_FOREACH(it->icon_objs, l, obj)
4153           elm_widget_disabled_set(obj, disabled);
4154      }
4155 }
4156
4157 /**
4158  * Get the disabled state of an item
4159  *
4160  * This gets the disabled state of the given item.
4161  *
4162  * @param it The item
4163  * @return The disabled state
4164  *
4165  * @ingroup Genlist
4166  */
4167 EAPI Eina_Bool
4168 elm_genlist_item_disabled_get(const Elm_Genlist_Item *it)
4169 {
4170    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4171    if (it->delete_me) return EINA_FALSE;
4172    return it->disabled;
4173 }
4174
4175 /**
4176  * Sets the display only state of an item.
4177  *
4178  * A display only item cannot be selected or unselected. It is for
4179  * display only and not selecting or otherwise clicking, dragging
4180  * etc. by the user, thus finger size rules will not be applied to
4181  * this item.
4182  *
4183  * @param it The item
4184  * @param display_only The display only state
4185  *
4186  * @ingroup Genlist
4187  */
4188 EAPI void
4189 elm_genlist_item_display_only_set(Elm_Genlist_Item *it,
4190                                   Eina_Bool         display_only)
4191 {
4192    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4193    if (it->display_only == display_only) return;
4194    if (it->delete_me) return;
4195    it->display_only = display_only;
4196    it->mincalcd = EINA_FALSE;
4197    it->updateme = EINA_TRUE;
4198    if (it->block) it->block->updateme = EINA_TRUE;
4199    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4200    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4201 }
4202
4203 /**
4204  * Get the display only state of an item
4205  *
4206  * This gets the display only state of the given item.
4207  *
4208  * @param it The item
4209  * @return The display only state
4210  *
4211  * @ingroup Genlist
4212  */
4213 EAPI Eina_Bool
4214 elm_genlist_item_display_only_get(const Elm_Genlist_Item *it)
4215 {
4216    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4217    if (it->delete_me) return EINA_FALSE;
4218    return it->display_only;
4219 }
4220
4221 /**
4222  * Show the given item
4223  *
4224  * This causes genlist to jump to the given item @p it and show it (by
4225  * scrolling), if it is not fully visible.
4226  *
4227  * @param it The item
4228  *
4229  * @ingroup Genlist
4230  */
4231 EAPI void
4232 elm_genlist_item_show(Elm_Genlist_Item *it)
4233 {
4234    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4235    Evas_Coord gith = 0;
4236    if (it->delete_me) return;
4237    if ((it->queued) || (!it->mincalcd))
4238      {
4239         it->wd->show_item = it;
4240         it->wd->bring_in = EINA_TRUE;
4241         it->showme = EINA_TRUE;
4242         return;
4243      }
4244    if (it->wd->show_item)
4245      {
4246         it->wd->show_item->showme = EINA_FALSE;
4247         it->wd->show_item = NULL;
4248      }
4249    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4250      gith = it->group_item->h;
4251    elm_smart_scroller_child_region_show(it->wd->scr,
4252                                         it->x + it->block->x,
4253                                         it->y + it->block->y - gith,
4254                                         it->block->w, it->h);
4255 }
4256
4257 /**
4258  * Bring in the given item
4259  *
4260  * This causes genlist to jump to the given item @p it and show it (by
4261  * scrolling), if it is not fully visible. This may use animation to
4262  * do so and take a period of time
4263  *
4264  * @param it The item
4265  *
4266  * @ingroup Genlist
4267  */
4268 EAPI void
4269 elm_genlist_item_bring_in(Elm_Genlist_Item *it)
4270 {
4271    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4272    Evas_Coord gith = 0;
4273    if (it->delete_me) return;
4274    if ((it->queued) || (!it->mincalcd))
4275      {
4276         it->wd->show_item = it;
4277         it->wd->bring_in = EINA_TRUE;
4278         it->showme = EINA_TRUE;
4279         return;
4280      }
4281    if (it->wd->show_item)
4282      {
4283         it->wd->show_item->showme = EINA_FALSE;
4284         it->wd->show_item = NULL;
4285      }
4286    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4287      gith = it->group_item->h;
4288    elm_smart_scroller_region_bring_in(it->wd->scr,
4289                                       it->x + it->block->x,
4290                                       it->y + it->block->y - gith,
4291                                       it->block->w, it->h);
4292 }
4293
4294 /**
4295  * Show the given item at the top
4296  *
4297  * This causes genlist to jump to the given item @p it and show it (by
4298  * scrolling), if it is not fully visible.
4299  *
4300  * @param it The item
4301  *
4302  * @ingroup Genlist
4303  */
4304 EAPI void
4305 elm_genlist_item_top_show(Elm_Genlist_Item *it)
4306 {
4307    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4308    Evas_Coord ow, oh;
4309    Evas_Coord gith = 0;
4310
4311    if (it->delete_me) return;
4312    if ((it->queued) || (!it->mincalcd))
4313      {
4314         it->wd->show_item = it;
4315         it->wd->bring_in = EINA_TRUE;
4316         it->showme = EINA_TRUE;
4317         return;
4318      }
4319    if (it->wd->show_item)
4320      {
4321         it->wd->show_item->showme = EINA_FALSE;
4322         it->wd->show_item = NULL;
4323      }
4324    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4325    if (it->group_item) gith = it->group_item->h;
4326    elm_smart_scroller_child_region_show(it->wd->scr,
4327                                         it->x + it->block->x,
4328                                         it->y + it->block->y - gith,
4329                                         it->block->w, oh);
4330 }
4331
4332 /**
4333  * Bring in the given item at the top
4334  *
4335  * This causes genlist to jump to the given item @p it and show it (by
4336  * scrolling), if it is not fully visible. This may use animation to
4337  * do so and take a period of time
4338  *
4339  * @param it The item
4340  *
4341  * @ingroup Genlist
4342  */
4343 EAPI void
4344 elm_genlist_item_top_bring_in(Elm_Genlist_Item *it)
4345 {
4346    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4347    Evas_Coord ow, oh;
4348    Evas_Coord gith = 0;
4349
4350    if (it->delete_me) return;
4351    if ((it->queued) || (!it->mincalcd))
4352      {
4353         it->wd->show_item = it;
4354         it->wd->bring_in = EINA_TRUE;
4355         it->showme = EINA_TRUE;
4356         return;
4357      }
4358    if (it->wd->show_item)
4359      {
4360         it->wd->show_item->showme = EINA_FALSE;
4361         it->wd->show_item = NULL;
4362      }
4363    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4364    if (it->group_item) gith = it->group_item->h;
4365    elm_smart_scroller_region_bring_in(it->wd->scr,
4366                                       it->x + it->block->x,
4367                                       it->y + it->block->y - gith,
4368                                       it->block->w, oh);
4369 }
4370
4371 /**
4372  * Show the given item at the middle
4373  *
4374  * This causes genlist to jump to the given item @p it and show it (by
4375  * scrolling), if it is not fully visible.
4376  *
4377  * @param it The item
4378  *
4379  * @ingroup Genlist
4380  */
4381 EAPI void
4382 elm_genlist_item_middle_show(Elm_Genlist_Item *it)
4383 {
4384    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4385    Evas_Coord ow, oh;
4386
4387    if (it->delete_me) return;
4388    if ((it->queued) || (!it->mincalcd))
4389      {
4390         it->wd->show_item = it;
4391         it->wd->bring_in = EINA_TRUE;
4392         it->showme = EINA_TRUE;
4393         return;
4394      }
4395    if (it->wd->show_item)
4396      {
4397         it->wd->show_item->showme = EINA_FALSE;
4398         it->wd->show_item = NULL;
4399      }
4400    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4401    elm_smart_scroller_child_region_show(it->wd->scr,
4402                                         it->x + it->block->x,
4403                                         it->y + it->block->y - oh / 2 +
4404                                         it->h / 2, it->block->w, oh);
4405 }
4406
4407 /**
4408  * Bring in the given item at the middle
4409  *
4410  * This causes genlist to jump to the given item @p it and show it (by
4411  * scrolling), if it is not fully visible. This may use animation to
4412  * do so and take a period of time
4413  *
4414  * @param it The item
4415  *
4416  * @ingroup Genlist
4417  */
4418 EAPI void
4419 elm_genlist_item_middle_bring_in(Elm_Genlist_Item *it)
4420 {
4421    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4422    Evas_Coord ow, oh;
4423
4424    if (it->delete_me) return;
4425    if ((it->queued) || (!it->mincalcd))
4426      {
4427         it->wd->show_item = it;
4428         it->wd->bring_in = EINA_TRUE;
4429         it->showme = EINA_TRUE;
4430         return;
4431      }
4432    if (it->wd->show_item)
4433      {
4434         it->wd->show_item->showme = EINA_FALSE;
4435         it->wd->show_item = NULL;
4436      }
4437    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4438    elm_smart_scroller_region_bring_in(it->wd->scr,
4439                                       it->x + it->block->x,
4440                                       it->y + it->block->y - oh / 2 + it->h / 2,
4441                                       it->block->w, oh);
4442 }
4443
4444 /**
4445  * Delete a given item
4446  *
4447  * This deletes the item from genlist and calls the genlist item del
4448  * class callback defined in the item class, if it is set. This clears all
4449  * subitems if it is a tree.
4450  *
4451  * @param it The item
4452  *
4453  * @ingroup Genlist
4454  */
4455 EAPI void
4456 elm_genlist_item_del(Elm_Genlist_Item *it)
4457 {
4458    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4459    if ((it->relcount > 0) || (it->walking > 0))
4460      {
4461         elm_widget_item_pre_notify_del(it);
4462         elm_genlist_item_subitems_clear(it);
4463         it->delete_me = EINA_TRUE;
4464         if (it->wd->show_item == it) it->wd->show_item = NULL;
4465         if (it->selected)
4466           it->wd->selected = eina_list_remove(it->wd->selected,
4467                                               it);
4468         if (it->block)
4469           {
4470              if (it->realized) _item_unrealize(it, EINA_FALSE);
4471              it->block->changed = EINA_TRUE;
4472              if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
4473              it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
4474           }
4475         if (it->itc->func.del)
4476           it->itc->func.del((void *)it->base.data, it->base.widget);
4477         return;
4478      }
4479    _item_del(it);
4480 }
4481
4482 /**
4483  * Set the data item from the genlist item
4484  *
4485  * This set the data value passed on the elm_genlist_item_append() and
4486  * related item addition calls. This function will also call
4487  * elm_genlist_item_update() so the item will be updated to reflect the
4488  * new data.
4489  *
4490  * @param it The item
4491  * @param data The new data pointer to set
4492  *
4493  * @ingroup Genlist
4494  */
4495 EAPI void
4496 elm_genlist_item_data_set(Elm_Genlist_Item *it,
4497                           const void       *data)
4498 {
4499    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4500    elm_widget_item_data_set(it, data);
4501    elm_genlist_item_update(it);
4502 }
4503
4504 /**
4505  * Get the data item from the genlist item
4506  *
4507  * This returns the data value passed on the elm_genlist_item_append()
4508  * and related item addition calls and elm_genlist_item_data_set().
4509  *
4510  * @param it The item
4511  * @return The data pointer provided when created
4512  *
4513  * @ingroup Genlist
4514  */
4515 EAPI void *
4516 elm_genlist_item_data_get(const Elm_Genlist_Item *it)
4517 {
4518    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4519    return elm_widget_item_data_get(it);
4520 }
4521
4522 /**
4523  * Tells genlist to "orphan" icons fetchs by the item class
4524  *
4525  * This instructs genlist to release references to icons in the item,
4526  * meaning that they will no longer be managed by genlist and are
4527  * floating "orphans" that can be re-used elsewhere if the user wants
4528  * to.
4529  *
4530  * @param it The item
4531  *
4532  * @ingroup Genlist
4533  */
4534 EAPI void
4535 elm_genlist_item_icons_orphan(Elm_Genlist_Item *it)
4536 {
4537    Evas_Object *icon;
4538    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4539    EINA_LIST_FREE(it->icon_objs, icon)
4540      {
4541         elm_widget_sub_object_del(it->base.widget, icon);
4542         evas_object_smart_member_del(icon);
4543         evas_object_hide(icon);
4544      }
4545 }
4546
4547 /**
4548  * Get the real evas object of the genlist item
4549  *
4550  * This returns the actual evas object used for the specified genlist
4551  * item. This may be NULL as it may not be created, and may be deleted
4552  * at any time by genlist. Do not modify this object (move, resize,
4553  * show, hide etc.) as genlist is controlling it. This function is for
4554  * querying, emitting custom signals or hooking lower level callbacks
4555  * for events. Do not delete this object under any circumstances.
4556  *
4557  * @param it The item
4558  * @return The object pointer
4559  *
4560  * @ingroup Genlist
4561  */
4562 EAPI const Evas_Object *
4563 elm_genlist_item_object_get(const Elm_Genlist_Item *it)
4564 {
4565    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4566    return it->base.view;
4567 }
4568
4569 /**
4570  * Update the contents of an item
4571  *
4572  * This updates an item by calling all the item class functions again
4573  * to get the icons, labels and states. Use this when the original
4574  * item data has changed and the changes are desired to be reflected.
4575  *
4576  * @param it The item
4577  *
4578  * @ingroup Genlist
4579  */
4580 EAPI void
4581 elm_genlist_item_update(Elm_Genlist_Item *it)
4582 {
4583    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4584    if (!it->block) return;
4585    if (it->delete_me) return;
4586    it->mincalcd = EINA_FALSE;
4587    it->updateme = EINA_TRUE;
4588    it->block->updateme = EINA_TRUE;
4589    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4590    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4591 }
4592
4593 /**
4594  * Update the item class of an item
4595  *
4596  * @param it The item
4597  * @parem itc The item class for the item
4598  *
4599  * @ingroup Genlist
4600  */
4601 EAPI void
4602 elm_genlist_item_item_class_update(Elm_Genlist_Item             *it,
4603                                    const Elm_Genlist_Item_Class *itc)
4604 {
4605    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4606    if (!it->block) return;
4607    EINA_SAFETY_ON_NULL_RETURN(itc);
4608    if (it->delete_me) return;
4609    it->itc = itc;
4610    it->nocache = EINA_TRUE;
4611    elm_genlist_item_update(it);
4612 }
4613
4614 static Evas_Object *
4615 _elm_genlist_item_label_create(void        *data,
4616                                Evas_Object *obj,
4617                                void        *item __UNUSED__)
4618 {
4619    Evas_Object *label = elm_label_add(obj);
4620    if (!label)
4621      return NULL;
4622    elm_object_style_set(label, "tooltip");
4623    elm_label_label_set(label, data);
4624    return label;
4625 }
4626
4627 static void
4628 _elm_genlist_item_label_del_cb(void        *data,
4629                                Evas_Object *obj __UNUSED__,
4630                                void        *event_info __UNUSED__)
4631 {
4632    eina_stringshare_del(data);
4633 }
4634
4635 /**
4636  * Set the text to be shown in the genlist item.
4637  *
4638  * @param item Target item
4639  * @param text The text to set in the content
4640  *
4641  * Setup the text as tooltip to object. The item can have only one
4642  * tooltip, so any previous tooltip data is removed.
4643  *
4644  * @ingroup Genlist
4645  */
4646 EAPI void
4647 elm_genlist_item_tooltip_text_set(Elm_Genlist_Item *item,
4648                                   const char       *text)
4649 {
4650    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4651    text = eina_stringshare_add(text);
4652    elm_genlist_item_tooltip_content_cb_set(item, _elm_genlist_item_label_create,
4653                                            text,
4654                                            _elm_genlist_item_label_del_cb);
4655 }
4656
4657 /**
4658  * Set the content to be shown in the tooltip item
4659  *
4660  * Setup the tooltip to item. The item can have only one tooltip, so
4661  * any previous tooltip data is removed. @p func(with @p data) will be
4662  * called every time that need to show the tooltip and it should return a
4663  * valid Evas_Object. This object is then managed fully by tooltip
4664  * system and is deleted when the tooltip is gone.
4665  *
4666  * @param item the genlist item being attached by a tooltip.
4667  * @param func the function used to create the tooltip contents.
4668  * @param data what to provide to @a func as callback data/context.
4669  * @param del_cb called when data is not needed anymore, either when
4670  *        another callback replaces @func, the tooltip is unset with
4671  *        elm_genlist_item_tooltip_unset() or the owner @a item
4672  *        dies. This callback receives as the first parameter the
4673  *        given @a data, and @c event_info is the item.
4674  *
4675  * @ingroup Genlist
4676  */
4677 EAPI void
4678 elm_genlist_item_tooltip_content_cb_set(Elm_Genlist_Item           *item,
4679                                         Elm_Tooltip_Item_Content_Cb func,
4680                                         const void                 *data,
4681                                         Evas_Smart_Cb               del_cb)
4682 {
4683    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
4684
4685    if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
4686      return;
4687
4688    if (item->tooltip.del_cb)
4689      item->tooltip.del_cb((void *)item->tooltip.data,
4690                           item->base.widget, item);
4691
4692    item->tooltip.content_cb = func;
4693    item->tooltip.data = data;
4694    item->tooltip.del_cb = del_cb;
4695
4696    if (item->base.view)
4697      {
4698         elm_widget_item_tooltip_content_cb_set(item,
4699                                                item->tooltip.content_cb,
4700                                                item->tooltip.data, NULL);
4701         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
4702      }
4703
4704    return;
4705
4706 error:
4707    if (del_cb) del_cb((void *)data, NULL, NULL);
4708 }
4709
4710 /**
4711  * Unset tooltip from item
4712  *
4713  * @param item genlist item to remove previously set tooltip.
4714  *
4715  * Remove tooltip from item. The callback provided as del_cb to
4716  * elm_genlist_item_tooltip_content_cb_set() will be called to notify
4717  * it is not used anymore.
4718  *
4719  * @see elm_genlist_item_tooltip_content_cb_set()
4720  *
4721  * @ingroup Genlist
4722  */
4723 EAPI void
4724 elm_genlist_item_tooltip_unset(Elm_Genlist_Item *item)
4725 {
4726    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4727    if ((item->base.view) && (item->tooltip.content_cb))
4728      elm_widget_item_tooltip_unset(item);
4729
4730    if (item->tooltip.del_cb)
4731      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
4732    item->tooltip.del_cb = NULL;
4733    item->tooltip.content_cb = NULL;
4734    item->tooltip.data = NULL;
4735    if (item->tooltip.style)
4736      elm_genlist_item_tooltip_style_set(item, NULL);
4737 }
4738
4739 /**
4740  * Sets a different style for this item tooltip.
4741  *
4742  * @note before you set a style you should define a tooltip with
4743  *       elm_genlist_item_tooltip_content_cb_set() or
4744  *       elm_genlist_item_tooltip_text_set()
4745  *
4746  * @param item genlist item with tooltip already set.
4747  * @param style the theme style to use (default, transparent, ...)
4748  *
4749  * @ingroup Genlist
4750  */
4751 EAPI void
4752 elm_genlist_item_tooltip_style_set(Elm_Genlist_Item *item,
4753                                    const char       *style)
4754 {
4755    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4756    eina_stringshare_replace(&item->tooltip.style, style);
4757    if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
4758 }
4759
4760 /**
4761  * Get the style for this item tooltip.
4762  *
4763  * @param item genlist item with tooltip already set.
4764  * @return style the theme style in use, defaults to "default". If the
4765  *         object does not have a tooltip set, then NULL is returned.
4766  *
4767  * @ingroup Genlist
4768  */
4769 EAPI const char *
4770 elm_genlist_item_tooltip_style_get(const Elm_Genlist_Item *item)
4771 {
4772    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4773    return item->tooltip.style;
4774 }
4775
4776 /**
4777  * Set the cursor to be shown when mouse is over the genlist item
4778  *
4779  * @param item Target item
4780  * @param cursor the cursor name to be used.
4781  *
4782  * @see elm_object_cursor_set()
4783  * @ingroup Genlist
4784  */
4785 EAPI void
4786 elm_genlist_item_cursor_set(Elm_Genlist_Item *item,
4787                             const char       *cursor)
4788 {
4789    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4790    eina_stringshare_replace(&item->mouse_cursor, cursor);
4791    if (item->base.view) elm_widget_item_cursor_set(item, cursor);
4792 }
4793
4794 /**
4795  * Get the cursor to be shown when mouse is over the genlist item
4796  *
4797  * @param item genlist item with cursor already set.
4798  * @return the cursor name.
4799  *
4800  * @ingroup Genlist
4801  */
4802 EAPI const char *
4803 elm_genlist_item_cursor_get(const Elm_Genlist_Item *item)
4804 {
4805    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4806    return elm_widget_item_cursor_get(item);
4807 }
4808
4809 /**
4810  * Unset the cursor to be shown when mouse is over the genlist item
4811  *
4812  * @param item Target item
4813  *
4814  * @see elm_object_cursor_unset()
4815  * @ingroup Genlist
4816  */
4817 EAPI void
4818 elm_genlist_item_cursor_unset(Elm_Genlist_Item *item)
4819 {
4820    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4821    if (!item->mouse_cursor)
4822      return;
4823
4824    if (item->base.view)
4825      elm_widget_item_cursor_unset(item);
4826
4827    eina_stringshare_del(item->mouse_cursor);
4828    item->mouse_cursor = NULL;
4829 }
4830
4831 /**
4832  * Sets a different style for this item cursor.
4833  *
4834  * @note before you set a style you should define a cursor with
4835  *       elm_genlist_item_cursor_set()
4836  *
4837  * @param item genlist item with cursor already set.
4838  * @param style the theme style to use (default, transparent, ...)
4839  *
4840  * @ingroup Genlist
4841  */
4842 EAPI void
4843 elm_genlist_item_cursor_style_set(Elm_Genlist_Item *item,
4844                                   const char       *style)
4845 {
4846    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4847    elm_widget_item_cursor_style_set(item, style);
4848 }
4849
4850 /**
4851  * Get the style for this item cursor.
4852  *
4853  * @param item genlist item with cursor already set.
4854  * @return style the theme style in use, defaults to "default". If the
4855  *         object does not have a cursor set, then NULL is returned.
4856  *
4857  * @ingroup Genlist
4858  */
4859 EAPI const char *
4860 elm_genlist_item_cursor_style_get(const Elm_Genlist_Item *item)
4861 {
4862    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4863    return elm_widget_item_cursor_style_get(item);
4864 }
4865
4866 /**
4867  * Set if the cursor set should be searched on the theme or should use
4868  * the provided by the engine, only.
4869  *
4870  * @note before you set if should look on theme you should define a
4871  * cursor with elm_object_cursor_set(). By default it will only look
4872  * for cursors provided by the engine.
4873  *
4874  * @param item widget item with cursor already set.
4875  * @param engine_only boolean to define it cursors should be looked
4876  * only between the provided by the engine or searched on widget's
4877  * theme as well.
4878  *
4879  * @ingroup Genlist
4880  */
4881 EAPI void
4882 elm_genlist_item_cursor_engine_only_set(Elm_Genlist_Item *item,
4883                                         Eina_Bool         engine_only)
4884 {
4885    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4886    elm_widget_item_cursor_engine_only_set(item, engine_only);
4887 }
4888
4889 /**
4890  * Get the cursor engine only usage for this item cursor.
4891  *
4892  * @param item widget item with cursor already set.
4893  * @return engine_only boolean to define it cursors should be looked
4894  * only between the provided by the engine or searched on widget's
4895  * theme as well. If the object does not have a cursor set, then
4896  * EINA_FALSE is returned.
4897  *
4898  * @ingroup Genlist
4899  */
4900 EAPI Eina_Bool
4901 elm_genlist_item_cursor_engine_only_get(const Elm_Genlist_Item *item)
4902 {
4903    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
4904    return elm_widget_item_cursor_engine_only_get(item);
4905 }
4906
4907 /**
4908  * This sets the horizontal stretching mode
4909  *
4910  * This sets the mode used for sizing items horizontally. Valid modes
4911  * are ELM_LIST_LIMIT and ELM_LIST_SCROLL. The default is
4912  * ELM_LIST_SCROLL. This mode means that if items are too wide to fit,
4913  * the scroller will scroll horizontally. Otherwise items are expanded
4914  * to fill the width of the viewport of the scroller. If it is
4915  * ELM_LIST_LIMIT, Items will be expanded to the viewport width and
4916  * limited to that size.
4917  *
4918  * @param obj The genlist object
4919  * @param mode The mode to use
4920  *
4921  * @ingroup Genlist
4922  */
4923 EAPI void
4924 elm_genlist_horizontal_mode_set(Evas_Object  *obj,
4925                                 Elm_List_Mode mode)
4926 {
4927    ELM_CHECK_WIDTYPE(obj, widtype);
4928    Widget_Data *wd = elm_widget_data_get(obj);
4929    if (!wd) return;
4930    if (wd->mode == mode) return;
4931    wd->mode = mode;
4932    _sizing_eval(obj);
4933 }
4934
4935 /**
4936  * Gets the horizontal stretching mode
4937  *
4938  * @param obj The genlist object
4939  * @return The mode to use
4940  * (ELM_LIST_LIMIT, ELM_LIST_SCROLL)
4941  *
4942  * @ingroup Genlist
4943  */
4944 EAPI Elm_List_Mode
4945 elm_genlist_horizontal_mode_get(const Evas_Object *obj)
4946 {
4947    ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
4948    Widget_Data *wd = elm_widget_data_get(obj);
4949    if (!wd) return ELM_LIST_LAST;
4950    return wd->mode;
4951 }
4952
4953 /**
4954  * Set the always select mode.
4955  *
4956  * Items will only call their selection func and callback when first
4957  * becoming selected. Any further clicks will do nothing, unless you
4958  * enable always select with elm_genlist_always_select_mode_set().
4959  * This means even if selected, every click will make the selected
4960  * callbacks be called.
4961  *
4962  * @param obj The genlist object
4963  * @param always_select The always select mode
4964  * (EINA_TRUE = on, EINA_FALSE = off)
4965  *
4966  * @ingroup Genlist
4967  */
4968 EAPI void
4969 elm_genlist_always_select_mode_set(Evas_Object *obj,
4970                                    Eina_Bool    always_select)
4971 {
4972    ELM_CHECK_WIDTYPE(obj, widtype);
4973    Widget_Data *wd = elm_widget_data_get(obj);
4974    if (!wd) return;
4975    wd->always_select = always_select;
4976 }
4977
4978 /**
4979  * Get the always select mode.
4980  *
4981  * @param obj The genlist object
4982  * @return The always select mode
4983  * (EINA_TRUE = on, EINA_FALSE = off)
4984  *
4985  * @ingroup Genlist
4986  */
4987 EAPI Eina_Bool
4988 elm_genlist_always_select_mode_get(const Evas_Object *obj)
4989 {
4990    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4991    Widget_Data *wd = elm_widget_data_get(obj);
4992    if (!wd) return EINA_FALSE;
4993    return wd->always_select;
4994 }
4995
4996 /**
4997  * Set no select mode
4998  *
4999  * This will turn off the ability to select items entirely and they
5000  * will neither appear selected nor call selected callback functions.
5001  *
5002  * @param obj The genlist object
5003  * @param no_select The no select mode
5004  * (EINA_TRUE = on, EINA_FALSE = off)
5005  *
5006  * @ingroup Genlist
5007  */
5008 EAPI void
5009 elm_genlist_no_select_mode_set(Evas_Object *obj,
5010                                Eina_Bool    no_select)
5011 {
5012    ELM_CHECK_WIDTYPE(obj, widtype);
5013    Widget_Data *wd = elm_widget_data_get(obj);
5014    if (!wd) return;
5015    wd->no_select = no_select;
5016 }
5017
5018 /**
5019  * Gets no select mode
5020  *
5021  * @param obj The genlist object
5022  * @return The no select mode
5023  * (EINA_TRUE = on, EINA_FALSE = off)
5024  *
5025  * @ingroup Genlist
5026  */
5027 EAPI Eina_Bool
5028 elm_genlist_no_select_mode_get(const Evas_Object *obj)
5029 {
5030    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5031    Widget_Data *wd = elm_widget_data_get(obj);
5032    if (!wd) return EINA_FALSE;
5033    return wd->no_select;
5034 }
5035
5036 /**
5037  * Set compress mode
5038  *
5039  * This will enable the compress mode where items are "compressed"
5040  * horizontally to fit the genlist scrollable viewport width. This is
5041  * special for genlist.  Do not rely on
5042  * elm_genlist_horizontal_mode_set() being set to ELM_LIST_COMPRESS to
5043  * work as genlist needs to handle it specially.
5044  *
5045  * @param obj The genlist object
5046  * @param compress The compress mode
5047  * (EINA_TRUE = on, EINA_FALSE = off)
5048  *
5049  * @ingroup Genlist
5050  */
5051 EAPI void
5052 elm_genlist_compress_mode_set(Evas_Object *obj,
5053                               Eina_Bool    compress)
5054 {
5055    ELM_CHECK_WIDTYPE(obj, widtype);
5056    Widget_Data *wd = elm_widget_data_get(obj);
5057    if (!wd) return;
5058    wd->compress = compress;
5059    if (!compress) elm_genlist_homogeneous_set(obj, EINA_FALSE);
5060 }
5061
5062 /**
5063  * Get the compress mode
5064  *
5065  * @param obj The genlist object
5066  * @return The compress mode
5067  * (EINA_TRUE = on, EINA_FALSE = off)
5068  *
5069  * @ingroup Genlist
5070  */
5071 EAPI Eina_Bool
5072 elm_genlist_compress_mode_get(const Evas_Object *obj)
5073 {
5074    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5075    Widget_Data *wd = elm_widget_data_get(obj);
5076    if (!wd) return EINA_FALSE;
5077    return wd->compress;
5078 }
5079
5080 /**
5081  * Set height-for-width mode
5082  *
5083  * With height-for-width mode the item width will be fixed (restricted
5084  * to a minimum of) to the list width when calculating its size in
5085  * order to allow the height to be calculated based on it. This allows,
5086  * for instance, text block to wrap lines if the Edje part is
5087  * configured with "text.min: 0 1".
5088  *
5089  * @note This mode will make list resize slower as it will have to
5090  *       recalculate every item height again whenever the list width
5091  *       changes!
5092  *
5093  * @note When height-for-width mode is enabled, it also enables
5094  *       compress mode (see elm_genlist_compress_mode_set()) and
5095  *       disables homogeneous (see elm_genlist_homogeneous_set()).
5096  *
5097  * @param obj The genlist object
5098  * @param setting The height-for-width mode (EINA_TRUE = on,
5099  * EINA_FALSE = off)
5100  *
5101  * @ingroup Genlist
5102  */
5103 EAPI void
5104 elm_genlist_height_for_width_mode_set(Evas_Object *obj,
5105                                       Eina_Bool    height_for_width)
5106 {
5107    ELM_CHECK_WIDTYPE(obj, widtype);
5108    Widget_Data *wd = elm_widget_data_get(obj);
5109    if (!wd) return;
5110    wd->height_for_width = !!height_for_width;
5111    if (wd->height_for_width)
5112      {
5113         elm_genlist_homogeneous_set(obj, EINA_FALSE);
5114         elm_genlist_compress_mode_set(obj, EINA_TRUE);
5115      }
5116 }
5117
5118 /**
5119  * Get the height-for-width mode
5120  *
5121  * @param obj The genlist object
5122  * @return The height-for-width mode (EINA_TRUE = on, EINA_FALSE =
5123  * off)
5124  *
5125  * @ingroup Genlist
5126  */
5127 EAPI Eina_Bool
5128 elm_genlist_height_for_width_mode_get(const Evas_Object *obj)
5129 {
5130    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5131    Widget_Data *wd = elm_widget_data_get(obj);
5132    if (!wd) return EINA_FALSE;
5133    return wd->height_for_width;
5134 }
5135
5136 /**
5137  * Set bounce mode
5138  *
5139  * This will enable or disable the scroller bounce mode for the
5140  * genlist. See elm_scroller_bounce_set() for details
5141  *
5142  * @param obj The genlist object
5143  * @param h_bounce Allow bounce horizontally
5144  * @param v_bounce Allow bounce vertically
5145  *
5146  * @ingroup Genlist
5147  */
5148 EAPI void
5149 elm_genlist_bounce_set(Evas_Object *obj,
5150                        Eina_Bool    h_bounce,
5151                        Eina_Bool    v_bounce)
5152 {
5153    ELM_CHECK_WIDTYPE(obj, widtype);
5154    Widget_Data *wd = elm_widget_data_get(obj);
5155    if (!wd) return;
5156    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
5157 }
5158
5159 /**
5160  * Get the bounce mode
5161  *
5162  * @param obj The genlist object
5163  * @param h_bounce Allow bounce horizontally
5164  * @param v_bounce Allow bounce vertically
5165  *
5166  * @ingroup Genlist
5167  */
5168 EAPI void
5169 elm_genlist_bounce_get(const Evas_Object *obj,
5170                        Eina_Bool         *h_bounce,
5171                        Eina_Bool         *v_bounce)
5172 {
5173    ELM_CHECK_WIDTYPE(obj, widtype);
5174    Widget_Data *wd = elm_widget_data_get(obj);
5175    if (!wd) return;
5176    elm_smart_scroller_bounce_allow_get(obj, h_bounce, v_bounce);
5177 }
5178
5179 /**
5180  * Set homogenous mode
5181  *
5182  * This will enable the homogeneous mode where items are of the same
5183  * height and width so that genlist may do the lazy-loading at its
5184  * maximum. This implies 'compressed' mode.
5185  *
5186  * @param obj The genlist object
5187  * @param homogeneous Assume the items within the genlist are of the
5188  * same height and width (EINA_TRUE = on, EINA_FALSE = off)
5189  *
5190  * @ingroup Genlist
5191  */
5192 EAPI void
5193 elm_genlist_homogeneous_set(Evas_Object *obj,
5194                             Eina_Bool    homogeneous)
5195 {
5196    ELM_CHECK_WIDTYPE(obj, widtype);
5197    Widget_Data *wd = elm_widget_data_get(obj);
5198    if (!wd) return;
5199    if (homogeneous) elm_genlist_compress_mode_set(obj, EINA_TRUE);
5200    wd->homogeneous = homogeneous;
5201 }
5202
5203 /**
5204  * Get the homogenous mode
5205  *
5206  * @param obj The genlist object
5207  * @return Assume the items within the genlist are of the same height
5208  * and width (EINA_TRUE = on, EINA_FALSE = off)
5209  *
5210  * @ingroup Genlist
5211  */
5212 EAPI Eina_Bool
5213 elm_genlist_homogeneous_get(const Evas_Object *obj)
5214 {
5215    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5216    Widget_Data *wd = elm_widget_data_get(obj);
5217    if (!wd) return EINA_FALSE;
5218    return wd->homogeneous;
5219 }
5220
5221 /**
5222  * Set the maximum number of items within an item block
5223  *
5224  * This will configure the block count to tune to the target with
5225  * particular performance matrix.
5226  *
5227  * @param obj The genlist object
5228  * @param n   Maximum number of items within an item block
5229  *
5230  * @ingroup Genlist
5231  */
5232 EAPI void
5233 elm_genlist_block_count_set(Evas_Object *obj,
5234                             int          n)
5235 {
5236    ELM_CHECK_WIDTYPE(obj, widtype);
5237    Widget_Data *wd = elm_widget_data_get(obj);
5238    if (!wd) return;
5239    wd->max_items_per_block = n;
5240    wd->item_cache_max = wd->max_items_per_block * 2;
5241    _item_cache_clean(wd);
5242 }
5243
5244 /**
5245  * Get the maximum number of items within an item block
5246  *
5247  * @param obj The genlist object
5248  * @return Maximum number of items within an item block
5249  *
5250  * @ingroup Genlist
5251  */
5252 EAPI int
5253 elm_genlist_block_count_get(const Evas_Object *obj)
5254 {
5255    ELM_CHECK_WIDTYPE(obj, widtype) 0;
5256    Widget_Data *wd = elm_widget_data_get(obj);
5257    if (!wd) return 0;
5258    return wd->max_items_per_block;
5259 }
5260
5261 /**
5262  * Set the timeout in seconds for the longpress event
5263  *
5264  * @param obj The genlist object
5265  * @param timeout timeout in seconds
5266  *
5267  * @ingroup Genlist
5268  */
5269 EAPI void
5270 elm_genlist_longpress_timeout_set(Evas_Object *obj,
5271                                   double       timeout)
5272 {
5273    ELM_CHECK_WIDTYPE(obj, widtype);
5274    Widget_Data *wd = elm_widget_data_get(obj);
5275    if (!wd) return;
5276    wd->longpress_timeout = timeout;
5277 }
5278
5279 /**
5280  * Get the timeout in seconds for the longpress event
5281  *
5282  * @param obj The genlist object
5283  * @return timeout in seconds
5284  *
5285  * @ingroup Genlist
5286  */
5287 EAPI double
5288 elm_genlist_longpress_timeout_get(const Evas_Object *obj)
5289 {
5290    ELM_CHECK_WIDTYPE(obj, widtype) 0;
5291    Widget_Data *wd = elm_widget_data_get(obj);
5292    if (!wd) return 0;
5293    return wd->longpress_timeout;
5294 }
5295
5296 /**
5297  * Set the scrollbar policy
5298  *
5299  * This sets the scrollbar visibility policy for the given genlist
5300  * scroller. ELM_SMART_SCROLLER_POLICY_AUTO means the scrollbar is
5301  * made visible if it is needed, and otherwise kept hidden.
5302  * ELM_SMART_SCROLLER_POLICY_ON turns it on all the time, and
5303  * ELM_SMART_SCROLLER_POLICY_OFF always keeps it off. This applies
5304  * respectively for the horizontal and vertical scrollbars.
5305  *
5306  * @param obj The genlist object
5307  * @param policy_h Horizontal scrollbar policy
5308  * @param policy_v Vertical scrollbar policy
5309  *
5310  * @ingroup Genlist
5311  */
5312 EAPI void
5313 elm_genlist_scroller_policy_set(Evas_Object        *obj,
5314                                 Elm_Scroller_Policy policy_h,
5315                                 Elm_Scroller_Policy policy_v)
5316 {
5317    ELM_CHECK_WIDTYPE(obj, widtype);
5318    Widget_Data *wd = elm_widget_data_get(obj);
5319    if (!wd) return;
5320    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
5321        (policy_v >= ELM_SCROLLER_POLICY_LAST))
5322      return;
5323    if (wd->scr)
5324      elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
5325 }
5326
5327 /**
5328  * Get the scrollbar policy
5329  *
5330  * @param obj The genlist object
5331  * @param policy_h Horizontal scrollbar policy
5332  * @param policy_v Vertical scrollbar policy
5333  *
5334  * @ingroup Genlist
5335  */
5336 EAPI void
5337 elm_genlist_scroller_policy_get(const Evas_Object   *obj,
5338                                 Elm_Scroller_Policy *policy_h,
5339                                 Elm_Scroller_Policy *policy_v)
5340 {
5341    ELM_CHECK_WIDTYPE(obj, widtype);
5342    Widget_Data *wd = elm_widget_data_get(obj);
5343    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
5344    if ((!wd) || (!wd->scr)) return;
5345    elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
5346    if (policy_h) *policy_h = (Elm_Scroller_Policy)s_policy_h;
5347    if (policy_v) *policy_v = (Elm_Scroller_Policy)s_policy_v;
5348 }
5349
5350 /**
5351  * Update the contents of all realized items
5352  *
5353  * This updates all realized items by calling all the item class functions again
5354  * to get the icons, labels and states. Use this when the original
5355  * item data has changed and the changes are desired to be reflected.
5356  *
5357  * @param it The item
5358  *
5359  * @ingroup Genlist
5360  */
5361 EAPI void
5362 elm_genlist_realized_items_update(Evas_Object *obj)
5363 {
5364    ELM_CHECK_WIDTYPE(obj, widtype);
5365
5366    Eina_List *list, *l;
5367    Elm_Genlist_Item *it;
5368
5369    list = elm_genlist_realized_items_get(obj);
5370    EINA_LIST_FOREACH(list, l, it)
5371      elm_genlist_item_update(it);
5372 }
5373
5374 /**
5375  * Set genlist item mode
5376  *
5377  * @param item The genlist item
5378  * @param mode Mode name
5379  * @param mode_set Boolean to define set or unset mode.
5380  *
5381  * @ingroup Genlist
5382  */
5383 EAPI void
5384 elm_genlist_item_mode_set(Elm_Genlist_Item *it,
5385                           const char       *mode_type,
5386                           Eina_Bool         mode_set)
5387 {
5388    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
5389    Widget_Data *wd = it->wd;
5390    Eina_List *l;
5391    Elm_Genlist_Item *it2;
5392
5393    if (!wd) return;
5394    if (!mode_type) return;
5395    if ((it->delete_me) || (it->disabled)) return;
5396
5397    if ((wd->mode_item == it) &&
5398        (!strcmp(mode_type, wd->mode_type)) &&
5399        (mode_set))
5400       return;
5401    if (!it->itc->mode_item_style) return;
5402
5403    if (wd->multi)
5404      {
5405         EINA_LIST_FOREACH(wd->selected, l, it2)
5406           if (it2->realized)
5407             elm_genlist_item_selected_set(it2, EINA_FALSE);
5408      }
5409    else
5410      {
5411         it2 = elm_genlist_selected_item_get(wd->obj);
5412         if ((it2) && (it2->realized))
5413           elm_genlist_item_selected_set(it2, EINA_FALSE);
5414      }
5415
5416    if (((wd->mode_type) && (strcmp(mode_type, wd->mode_type))) ||
5417        (mode_set) ||
5418        ((it == wd->mode_item) && (!mode_set)))
5419      _item_mode_unset(wd);
5420
5421    eina_stringshare_replace(&wd->mode_type, mode_type);
5422    if (mode_set) _item_mode_set(it);
5423 }
5424
5425 /**
5426  * Get active genlist mode type
5427  *
5428  * @param obj The genlist object
5429  *
5430  * @ingroup Genlist
5431  */
5432 EAPI const char *
5433 elm_genlist_mode_get(const Evas_Object *obj)
5434 {
5435    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5436    Widget_Data *wd = elm_widget_data_get(obj);
5437    if (!wd) return NULL;
5438    return wd->mode_type;
5439 }
5440
5441 /**
5442  * Get active genlist mode item
5443  *
5444  * @param obj The genlist object
5445  *
5446  * @ingroup Genlist
5447  */
5448 EAPI const Elm_Genlist_Item *
5449 elm_genlist_mode_item_get(const Evas_Object *obj)
5450 {
5451    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5452    Widget_Data *wd = elm_widget_data_get(obj);
5453    if (!wd) return NULL;
5454    return wd->mode_item;
5455 }