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