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