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