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