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