Elementary getlist: Fix places that weren't using ELM_GENLIST_ITEM_FROM_INLIST. Patch...
[framework/uifw/elementary.git] / src / lib / elm_genlist.c
1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
3 #include "elm_priv.h"
4
5 #define SWIPE_MOVES         12
6 #define MAX_ITEMS_PER_BLOCK 32
7
8 /**
9  * @defgroup Genlist Genlist
10  *
11  * The aim was to have more expansive list than the simple list in
12  * Elementary that could have more flexible items and allow many more entries
13  * while still being fast and low on memory usage. At the same time it was
14  * also made to be able to do tree structures. But the price to pay is more
15  * complex when it comes to usage. If all you want is a simple list with
16  * icons and a single label, use the normal List object.
17  *
18  * Signals that you can add callbacks for are:
19  *
20  * clicked - This is called when a user has double-clicked an item. The
21  * event_info parameter is the genlist item that was double-clicked.
22  *
23  * selected - This is called when a user has made an item selected. The
24  * event_info parameter is the genlist item that was selected.
25  *
26  * unselected - This is called when a user has made an item unselected. The
27  * event_info parameter is the genlist item that was unselected.
28  *
29  * expanded - This is called when elm_genlist_item_expanded_set() is called
30  * and the item is now meant to be expanded. The event_info parameter is the
31  * genlist item that was indicated to expand. It is the job of this callback
32  * to then fill in the child items.
33  *
34  * contracted - This is called when elm_genlist_item_expanded_set() is called
35  * and the item is now meant to be contracted. The event_info parameter is
36  * the genlist item that was indicated to contract. It is the job of this
37  * callback to then delete the child items.
38  *
39  * expand,request - This is called when a user has indicated they want to
40  * expand a tree branch item. The callback should decide if the item can
41  * expand (has any children) and then call elm_genlist_item_expanded_set()
42  * appropriately to set the state. The event_info parameter is the genlist
43  * item that was indicated to expand.
44  *
45  * contract,request - This is called when a user has indicated they want to
46  * contract a tree branch item. The callback should decide if the item can
47  * contract (has any children) and then call elm_genlist_item_expanded_set()
48  * appropriately to set the state. The event_info parameter is the genlist
49  * item that was indicated to contract.
50  *
51  * realized - This is called when the item in the list is created as a real
52  * evas object. event_info parameter is the genlist item that was created.
53  * The object may be deleted at any time, so it is up to the caller to
54  * not use the object pointer from elm_genlist_item_object_get() in a way
55  * where it may point to freed objects.
56  *
57  * unrealized - This is called just before an item is unrealized. After
58  * this call icon objects provided will be deleted and the item object
59  * itself delete or be put into a floating cache.
60  *
61  * drag,start,up - This is called when the item in the list has been dragged
62  * (not scrolled) up.
63  *
64  * drag,start,down - This is called when the item in the list has been dragged
65  * (not scrolled) down.
66  *
67  * drag,start,left - This is called when the item in the list has been dragged
68  * (not scrolled) left.
69  *
70  * drag,start,right - This is called when the item in the list has been dragged
71  * (not scrolled) right.
72  *
73  * drag,stop - This is called when the item in the list has stopped being
74  * dragged.
75  *
76  * drag - This is called when the item in the list is being dragged.
77  *
78  * longpressed - This is called when the item is pressed for a certain amount
79  * of time. By default it's 1 second.
80  *
81  * scroll,edge,top - This is called when the genlist is scrolled until the top
82  * edge.
83  *
84  * scroll,edge,bottom - This is called when the genlist is scrolled until the
85  * bottom edge.
86  *
87  * scroll,edge,left - This is called when the genlist is scrolled until the
88  * left edge.
89  *
90  * scroll,edge,right - This is called when the genlist is scrolled until the
91  * right edge.
92  *
93  * multi,swipe,left - This is called when the genlist is multi-touch swiped
94  * left.
95  *
96  * multi,swipe,right - This is called when the genlist is multi-touch swiped
97  * right.
98  *
99  * multi,swipe,up - This is called when the genlist is multi-touch swiped
100  * up.
101  *
102  * multi,swipe,down - This is called when the genlist is multi-touch swiped
103  * down.
104  *
105  * multi,pinch,out - This is called when the genlist is multi-touch pinched
106  * out.
107  *
108  * multi,pinch,in - This is called when the genlist is multi-touch pinched
109  * in.
110  *
111  * Genlist has a fairly large API, mostly because it's relatively complex,
112  * trying to be both expansive, powerful and efficient. First we will begin
113  * an overview on the theory behind genlist.
114  *
115  * Evas tracks every object you create. Every time it processes an event
116  * (mouse move, down, up etc.) it needs to walk through objects and find out
117  * what event that affects. Even worse every time it renders display updates,
118  * in order to just calculate what to re-draw, it needs to walk through many
119  * many many objects. Thus, the more objects you keep active, the more
120  * overhead Evas has in just doing its work. It is advisable to keep your
121  * active objects to the minimum working set you need. Also remember that
122  * object creation and deletion carries an overhead, so there is a
123  * middle-ground, which is not easily determined. But don't keep massive lists
124  * of objects you can't see or use. Genlist does this with list objects. It
125  * creates and destroys them dynamically as you scroll around. It groups them
126  * into blocks so it can determine the visibility etc. of a whole block at
127  * once as opposed to having to walk the whole list. This 2-level list allows
128  * for very large numbers of items to be in the list (tests have used up to
129  * 2,000,000 items). Also genlist employs a queue for adding items. As items
130  * may be different sizes, every item added needs to be calculated as to its
131  * size and thus this presents a lot of overhead on populating the list, this
132  * genlist employs a queue. Any item added is queued and spooled off over
133  * time, actually appearing some time later, so if your list has many members
134  * you may find it takes a while for them to all appear, with your process
135  * consuming a lot of CPU while it is busy spooling.
136  *
137  * Genlist also implements a tree structure, but it does so with callbacks to
138  * the application, with the application filling in tree structures when
139  * requested (allowing for efficient building of a very deep tree that could
140  * even be used for file-management). See the above smart signal callbacks for
141  * details.
142  *
143  * An item in the genlist world can have 0 or more text labels (they can be
144  * regular text or textblock – that's up to the style to determine), 0 or
145  * more icons (which are simply objects swallowed into the genlist item) and
146  * 0 or more boolean states that can be used for check, radio or other
147  * indicators by the edje theme style. An item may be one of several styles
148  * (Elementary provides 4 by default - “default”, “double_label”, "group_index"
149  * and "icon_top_text_bottom", but this can be extended by system or
150  * application custom themes/overlays/extensions).
151  *
152  * In order to implement the ability to add and delete items on the fly,
153  * Genlist implements a class/callback system where the application provides
154  * a structure with information about that type of item (genlist may contain
155  * multiple different items with different classes, states and styles).
156  * Genlist will call the functions in this struct (methods) when an item is
157  * “realized” (that is created dynamically while scrolling). All objects will
158  * simply be deleted  when no longer needed with evas_object_del(). The
159  * Elm_Genlist_Item_Class structure contains the following members:
160  *
161  * item_style - This is a constant string and simply defines the name of the
162  * item style. It must be specified and the default should be “default”.
163  *
164  * func.label_get - This function is called when an actual item object is
165  * created. The data parameter is the data parameter passed to
166  * elm_genlist_item_append() and related item creation functions. The obj
167  * parameter is the genlist object and the part parameter is the string name
168  * of the text part in the edje design that is listed as one of the possible
169  * labels that can be set. This function must return a strudup()'ed string as
170  * the caller will free() it when done.
171  *
172  * func.icon_get - This function is called when an actual item object is
173  * created. The data parameter is the data parameter passed to
174  * elm_genlist_item_append() and related item creation functions. The obj
175  * parameter is the genlist object and the part parameter is the string name
176  * of the icon part in the edje design that is listed as one of the possible
177  * icons that can be set. This must return NULL for no object or a valid
178  * object. The object will be deleted by genlist on shutdown or when the item
179  * is unrealized.
180  *
181  * func.state_get - This function is called when an actual item object is
182  * created. The data parameter is the data parameter passed to
183  * elm_genlist_item_append() and related item creation functions. The obj
184  * parameter is the genlist object and the part parameter is the string name
185  * of the state part in the edje design that is listed as one of the possible
186  * states that can be set. Return 0 for false or 1 for true. Genlist will
187  * emit a signal to the edje object with “elm,state,XXX,active” “elm” when
188  * true (the default is false), where XXX is the name of the part.
189  *
190  * func.del - This is called when elm_genlist_item_del() is called on an
191  * item, elm_genlist_clear() is called on the genlist, or
192  * elm_genlist_item_subitems_clear() is called to clear sub-items. This is
193  * intended for use when actual genlist items are deleted, so any backing
194  * data attached to the item (e.g. its data parameter on creation) can be
195  * deleted.
196  *
197  * Items can be added by several calls. All of them return a Elm_Genlist_Item
198  * handle that is an internal member inside the genlist. They all take a data
199  * parameter that is meant to be used for a handle to the applications
200  * internal data (eg the struct with the original item data). The parent
201  * parameter is the parent genlist item this belongs to if it is a tree or 
202  * an indexed group, and NULL if there is no parent. The flags can be a bitmask
203  * of ELM_GENLIST_ITEM_NONE, ELM_GENLIST_ITEM_SUBITEMS and
204  * ELM_GENLIST_ITEM_GROUP. If ELM_GENLIST_ITEM_SUBITEMS is set then this item
205  * is displayed as an item that is able to expand and have child items.
206  * If ELM_GENLIST_ITEM_GROUP is set then this item is group idex item that is
207  * displayed at the top until the next group comes. The func parameter is a
208  * convenience callback that is called when the item is selected and the data
209  * parameter will be the func_data parameter, obj be the genlist object and
210  * event_info will be the genlist item.
211  *
212  * elm_genlist_item_append() appends an item to the end of the list, or if
213  * there is a parent, to the end of all the child items of the parent.
214  * elm_genlist_item_prepend() is the same but prepends to the beginning of
215  * the list or children list. elm_genlist_item_insert_before() inserts at
216  * item before another item and elm_genlist_item_insert_after() inserts after
217  * the indicated item.
218  *
219  * The application can clear the list with elm_genlist_clear() which deletes
220  * all the items in the list and elm_genlist_item_del() will delete a specific
221  * item. elm_genlist_item_subitems_clear() will clear all items that are
222  * children of the indicated parent item.
223  *
224  * If the application wants multiple items to be able to be selected,
225  * elm_genlist_multi_select_set() can enable this. If the list is
226  * single-selection only (the default), then elm_genlist_selected_item_get()
227  * will return the selected item, if any, or NULL I none is selected. If the
228  * list is multi-select then elm_genlist_selected_items_get() will return a
229  * list (that is only valid as long as no items are modified (added, deleted,
230  * selected or unselected)).
231  *
232  * To help inspect list items you can jump to the item at the top of the list
233  * with elm_genlist_first_item_get() which will return the item pointer, and
234  * similarly elm_genlist_last_item_get() gets the item at the end of the list.
235  * elm_genlist_item_next_get() and elm_genlist_item_prev_get() get the next
236  * and previous items respectively relative to the indicated item. Using
237  * these calls you can walk the entire item list/tree. Note that as a tree
238  * the items are flattened in the list, so elm_genlist_item_parent_get() will
239  * let you know which item is the parent (and thus know how to skip them if
240  * wanted).
241  *
242  * There are also convenience functions. elm_genlist_item_genlist_get() will
243  * return the genlist object the item belongs to. elm_genlist_item_show()
244  * will make the scroller scroll to show that specific item so its visible.
245  * elm_genlist_item_data_get() returns the data pointer set by the item
246  * creation functions.
247  *
248  * If an item changes (state of boolean changes, label or icons change),
249  * then use elm_genlist_item_update() to have genlist update the item with
250  * the new state. Genlist will re-realize the item thus call the functions
251  * in the _Elm_Genlist_Item_Class for that item.
252  *
253  * To programmatically (un)select an item use elm_genlist_item_selected_set().
254  * To get its selected state use elm_genlist_item_selected_get(). Similarly
255  * to expand/contract an item and get its expanded state, use
256  * elm_genlist_item_expanded_set() and elm_genlist_item_expanded_get(). And
257  * again to make an item disabled (unable to be selected and appear
258  * differently) use elm_genlist_item_disabled_set() to set this and
259  * elm_genlist_item_disabled_get() to get the disabled state.
260  *
261  * In general to indicate how the genlist should expand items horizontally to
262  * fill the list area, use elm_genlist_horizontal_mode_set(). Valid modes are
263  * ELM_LIST_LIMIT and ELM_LIST_SCROLL . The default is ELM_LIST_SCROLL. This
264  * mode means that if items are too wide to fit, the scroller will scroll
265  * horizontally. Otherwise items are expanded to fill the width of the
266  * viewport of the scroller. If it is ELM_LIST_LIMIT, items will be expanded
267  * to the viewport width and limited to that size. This can be combined with
268  * a different style that uses edjes' ellipsis feature (cutting text off like
269  * this: “tex...”).
270  *
271  * Items will only call their selection func and callback when first becoming
272  * selected. Any further clicks will do nothing, unless you enable always
273  * select with elm_genlist_always_select_mode_set(). This means even if
274  * selected, every click will make the selected callbacks be called.
275  * elm_genlist_no_select_mode_set() will turn off the ability to select
276  * items entirely and they will neither appear selected nor call selected
277  * callback functions.
278  *
279  * Remember that you can create new styles and add your own theme augmentation
280  * per application with elm_theme_extension_add(). If you absolutely must
281  * have a specific style that overrides any theme the user or system sets up
282  * you can use elm_theme_overlay_add() to add such a file.
283  */
284
285 typedef struct _Widget_Data Widget_Data;
286 typedef struct _Item_Block  Item_Block;
287 typedef struct _Pan         Pan;
288 typedef struct _Item_Cache  Item_Cache;
289
290 struct _Widget_Data
291 {
292    Evas_Object      *obj, *scr, *pan_smart;
293    Eina_Inlist      *items, *blocks;
294    Eina_List        *group_items;
295    Pan              *pan;
296    Evas_Coord        pan_x, pan_y, w, h, minw, minh, realminw, prev_viewport_w;
297    Ecore_Job        *calc_job, *update_job;
298    Ecore_Idler      *queue_idler;
299    Ecore_Idler      *must_recalc_idler;
300    Eina_List        *queue, *selected;
301    Elm_Genlist_Item *show_item;
302    Elm_Genlist_Item *last_selected_item;
303    Eina_Inlist      *item_cache;
304    Elm_Genlist_Item *anchor_item;
305    Evas_Coord        anchor_y;
306    Elm_List_Mode     mode;
307    Ecore_Timer      *multi_timer;
308    Evas_Coord        prev_x, prev_y, prev_mx, prev_my;
309    Evas_Coord        cur_x, cur_y, cur_mx, cur_my;
310    Eina_Bool         mouse_down : 1;
311    Eina_Bool         multi_down : 1;
312    Eina_Bool         multi_timeout : 1;
313    Eina_Bool         multitouched : 1;
314    Eina_Bool         on_hold : 1;
315    Eina_Bool         multi : 1;
316    Eina_Bool         always_select : 1;
317    Eina_Bool         longpressed : 1;
318    Eina_Bool         wasselected : 1;
319    Eina_Bool         no_select : 1;
320    Eina_Bool         bring_in : 1;
321    Eina_Bool         compress : 1;
322    Eina_Bool         height_for_width : 1;
323    Eina_Bool         homogeneous : 1;
324    Eina_Bool         clear_me : 1;
325    Eina_Bool         swipe : 1;
326    struct
327    {
328       Evas_Coord x, y;
329    } history[SWIPE_MOVES];
330    int               multi_device;
331    int               item_cache_count;
332    int               item_cache_max;
333    int               movements;
334    int               walking;
335    int               item_width;
336    int               item_height;
337    int               max_items_per_block;
338    double            longpress_timeout;
339 };
340
341 struct _Item_Block
342 {
343    EINA_INLIST;
344    int          count;
345    int          num;
346    Widget_Data *wd;
347    Eina_List   *items;
348    Evas_Coord   x, y, w, h, minw, minh;
349    Eina_Bool    want_unrealize : 1;
350    Eina_Bool    realized : 1;
351    Eina_Bool    changed : 1;
352    Eina_Bool    updateme : 1;
353    Eina_Bool    showme : 1;
354    Eina_Bool    must_recalc : 1;
355 };
356
357 struct _Elm_Genlist_Item
358 {
359    Elm_Widget_Item               base;
360    EINA_INLIST;
361    Widget_Data                  *wd;
362    Item_Block                   *block;
363    Eina_List                    *items;
364    Evas_Coord                    x, y, w, h, minw, minh;
365    const Elm_Genlist_Item_Class *itc;
366    Elm_Genlist_Item             *parent;
367    Elm_Genlist_Item             *group_item;
368    Elm_Genlist_Item_Flags        flags;
369    struct
370    {
371       Evas_Smart_Cb func;
372       const void   *data;
373    } func;
374
375    Evas_Object      *spacer;
376    Eina_List        *labels, *icons, *states, *icon_objs;
377    Ecore_Timer      *long_timer;
378    Ecore_Timer      *swipe_timer;
379    Evas_Coord        dx, dy;
380    Evas_Coord        scrl_x, scrl_y;
381
382    Elm_Genlist_Item *rel;
383
384    struct
385    {
386       const void                 *data;
387       Elm_Tooltip_Item_Content_Cb content_cb;
388       Evas_Smart_Cb               del_cb;
389       const char                 *style;
390    } tooltip;
391
392    const char *mouse_cursor;
393
394    int         relcount;
395    int         walking;
396    int         expanded_depth;
397    int         order_num_in;
398
399    Eina_Bool   before : 1;
400
401    Eina_Bool   want_unrealize : 1;
402    Eina_Bool   want_realize : 1;
403    Eina_Bool   realized : 1;
404    Eina_Bool   selected : 1;
405    Eina_Bool   hilighted : 1;
406    Eina_Bool   expanded : 1;
407    Eina_Bool   disabled : 1;
408    Eina_Bool   display_only : 1;
409    Eina_Bool   mincalcd : 1;
410    Eina_Bool   queued : 1;
411    Eina_Bool   showme : 1;
412    Eina_Bool   delete_me : 1;
413    Eina_Bool   down : 1;
414    Eina_Bool   dragging : 1;
415    Eina_Bool   updateme : 1;
416    Eina_Bool   nocache : 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_FROM_INLIST(EINA_INLIST_GET(it)->next);
919         if (!it->wd->anchor_item)
920           it->wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(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 = NULL;
1615
1616    if ((it->realized) || (it->delete_me)) return;
1617    it->order_num_in = in;
1618
1619    if (it->nocache)
1620       it->nocache = EINA_FALSE;
1621    else
1622       itc = _item_cache_find(it);
1623    if (itc)
1624      {
1625         it->base.view = itc->base_view;
1626         itc->base_view = NULL;
1627         it->spacer = itc->spacer;
1628         itc->spacer = NULL;
1629      }
1630    else
1631      {
1632         it->base.view = edje_object_add(evas_object_evas_get(it->base.widget));
1633         edje_object_scale_set(it->base.view,
1634                               elm_widget_scale_get(it->base.widget) *
1635                               _elm_config->scale);
1636         evas_object_smart_member_add(it->base.view, it->wd->pan_smart);
1637         elm_widget_sub_object_add(it->base.widget, it->base.view);
1638
1639         if (it->flags & ELM_GENLIST_ITEM_SUBITEMS)
1640           strncpy(buf, "tree", sizeof(buf));
1641         else strncpy(buf, "item", sizeof(buf));
1642         if (it->wd->compress)
1643           strncat(buf, "_compress", sizeof(buf) - strlen(buf));
1644
1645         if (in & 0x1) strncat(buf, "_odd", sizeof(buf) - strlen(buf));
1646         strncat(buf, "/", sizeof(buf) - strlen(buf));
1647         strncat(buf, it->itc->item_style, sizeof(buf) - strlen(buf));
1648
1649         _elm_theme_object_set(it->base.widget, it->base.view, "genlist", buf,
1650                               elm_widget_style_get(it->base.widget));
1651         it->spacer =
1652           evas_object_rectangle_add(evas_object_evas_get(it->base.widget));
1653         evas_object_color_set(it->spacer, 0, 0, 0, 0);
1654         elm_widget_sub_object_add(it->base.widget, it->spacer);
1655      }
1656    for (it2 = it, depth = 0; it2->parent; it2 = it2->parent)
1657      {
1658         if (it2->parent->flags != ELM_GENLIST_ITEM_GROUP) depth += 1;
1659      }
1660    it->expanded_depth = depth;
1661    treesize = edje_object_data_get(it->base.view, "treesize");
1662    if (treesize) tsize = atoi(treesize);
1663    evas_object_size_hint_min_set(it->spacer,
1664                                  (depth * tsize) * _elm_config->scale, 1);
1665    edje_object_part_swallow(it->base.view, "elm.swallow.pad", it->spacer);
1666    if (!calc)
1667      {
1668         edje_object_signal_callback_add(it->base.view,
1669                                         "elm,action,expand,toggle",
1670                                         "elm", _signal_expand_toggle, it);
1671         edje_object_signal_callback_add(it->base.view, "elm,action,expand",
1672                                         "elm", _signal_expand, it);
1673         edje_object_signal_callback_add(it->base.view, "elm,action,contract",
1674                                         "elm", _signal_contract, it);
1675         stacking = edje_object_data_get(it->base.view, "stacking");
1676         if (stacking)
1677           {
1678              if (!strcmp(stacking, "below")) evas_object_lower(it->base.view);
1679              else if (!strcmp(stacking, "above"))
1680                evas_object_raise(it->base.view);
1681           }
1682         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_DOWN,
1683                                        _mouse_down, it);
1684         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_UP,
1685                                        _mouse_up, it);
1686         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_MOVE,
1687                                        _mouse_move, it);
1688         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_DOWN,
1689                                        _multi_down, it);
1690         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_UP,
1691                                        _multi_up, it);
1692         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_MOVE,
1693                                        _multi_move, it);
1694         if (itc)
1695           {
1696              if (it->selected != itc->selected)
1697                {
1698                   if (it->selected)
1699                     edje_object_signal_emit(it->base.view,
1700                                             "elm,state,selected", "elm");
1701                }
1702              if (it->disabled != itc->disabled)
1703                {
1704                   if (it->disabled)
1705                     edje_object_signal_emit(it->base.view,
1706                                             "elm,state,disabled", "elm");
1707                }
1708              if (it->expanded != itc->expanded)
1709                {
1710                   if (it->expanded)
1711                     edje_object_signal_emit(it->base.view,
1712                                             "elm,state,expanded", "elm");
1713                }
1714           }
1715         else
1716           {
1717              if (it->selected)
1718                edje_object_signal_emit(it->base.view,
1719                                        "elm,state,selected", "elm");
1720              if (it->disabled)
1721                edje_object_signal_emit(it->base.view,
1722                                        "elm,state,disabled", "elm");
1723              if (it->expanded)
1724                edje_object_signal_emit(it->base.view,
1725                                        "elm,state,expanded", "elm");
1726           }
1727      }
1728
1729    if ((calc) && (it->wd->homogeneous) && (it->wd->item_width))
1730      {
1731         /* homogenous genlist shortcut */
1732          if (!it->mincalcd)
1733            {
1734               it->w = it->minw = it->wd->item_width;
1735               it->h = it->minh = it->wd->item_height;
1736               it->mincalcd = EINA_TRUE;
1737            }
1738      }
1739    else
1740      {
1741         if (it->itc->func.label_get)
1742           {
1743              const Eina_List *l;
1744              const char *key;
1745
1746              it->labels =
1747                elm_widget_stringlist_get(edje_object_data_get(it->base.view,
1748                                                               "labels"));
1749              EINA_LIST_FOREACH(it->labels, l, key)
1750                {
1751                   char *s = it->itc->func.label_get
1752                       ((void *)it->base.data, it->base.widget, l->data);
1753
1754                   if (s)
1755                     {
1756                        edje_object_part_text_set(it->base.view, l->data, s);
1757                        free(s);
1758                     }
1759                   else if (itc)
1760                     edje_object_part_text_set(it->base.view, l->data, "");
1761                }
1762           }
1763         if (it->itc->func.icon_get)
1764           {
1765              const Eina_List *l;
1766              const char *key;
1767
1768              it->icons =
1769                elm_widget_stringlist_get(edje_object_data_get(it->base.view,
1770                                                               "icons"));
1771              EINA_LIST_FOREACH(it->icons, l, key)
1772                {
1773                   Evas_Object *ic = it->itc->func.icon_get
1774                       ((void *)it->base.data, it->base.widget, l->data);
1775
1776                   if (ic)
1777                     {
1778                        it->icon_objs = eina_list_append(it->icon_objs, ic);
1779                        edje_object_part_swallow(it->base.view, key, ic);
1780                        evas_object_show(ic);
1781                        elm_widget_sub_object_add(it->base.widget, ic);
1782                     }
1783                }
1784           }
1785         if (it->itc->func.state_get)
1786           {
1787              const Eina_List *l;
1788              const char *key;
1789
1790              it->states =
1791                elm_widget_stringlist_get(edje_object_data_get(it->base.view,
1792                                                               "states"));
1793              EINA_LIST_FOREACH(it->states, l, key)
1794                {
1795                   Eina_Bool on = it->itc->func.state_get
1796                       ((void *)it->base.data, it->base.widget, l->data);
1797
1798                   if (on)
1799                     {
1800                        snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1801                        edje_object_signal_emit(it->base.view, buf, "elm");
1802                     }
1803                   else if (itc)
1804                     {
1805                        snprintf(buf, sizeof(buf), "elm,state,%s,passive", key);
1806                        edje_object_signal_emit(it->base.view, buf, "elm");
1807                     }
1808                }
1809           }
1810         if (!it->mincalcd)
1811           {
1812              Evas_Coord mw = -1, mh = -1;
1813
1814              if (it->wd->height_for_width) mw = it->wd->w;
1815
1816              if (!it->display_only)
1817                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1818              if (it->wd->height_for_width) mw = it->wd->prev_viewport_w;
1819              edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw,
1820                                                   mh);
1821              if (!it->display_only)
1822                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1823              it->w = it->minw = mw;
1824              it->h = it->minh = mh;
1825              it->mincalcd = EINA_TRUE;
1826
1827              if ((!in) && (it->wd->homogeneous))
1828                {
1829                   it->wd->item_width = mw;
1830                   it->wd->item_height = mh;
1831                }
1832           }
1833         if (!calc) evas_object_show(it->base.view);
1834      }
1835
1836    if (it->tooltip.content_cb)
1837      {
1838         elm_widget_item_tooltip_content_cb_set(it,
1839                                                it->tooltip.content_cb,
1840                                                it->tooltip.data, NULL);
1841         elm_widget_item_tooltip_style_set(it, it->tooltip.style);
1842      }
1843
1844    if (it->mouse_cursor)
1845      elm_widget_item_cursor_set(it, it->mouse_cursor);
1846
1847    it->realized = EINA_TRUE;
1848    it->want_unrealize = EINA_FALSE;
1849
1850    if (itc) _item_cache_free(itc);
1851    evas_object_smart_callback_call(it->base.widget, "realized", it);
1852 }
1853
1854 static void
1855 _item_unrealize(Elm_Genlist_Item *it)
1856 {
1857    Evas_Object *icon;
1858
1859    if (!it->realized) return;
1860    evas_object_smart_callback_call(it->base.widget, "unrealized", it);
1861    if (it->long_timer)
1862      {
1863         ecore_timer_del(it->long_timer);
1864         it->long_timer = NULL;
1865      }
1866    if (it->nocache)
1867      {
1868         evas_object_del(it->base.view);
1869         it->base.view = NULL;
1870         evas_object_del(it->spacer);
1871         it->spacer = NULL;
1872      }
1873    else
1874       _item_cache_add(it);
1875    elm_widget_stringlist_free(it->labels);
1876    it->labels = NULL;
1877    elm_widget_stringlist_free(it->icons);
1878    it->icons = NULL;
1879    elm_widget_stringlist_free(it->states);
1880
1881    EINA_LIST_FREE(it->icon_objs, icon)
1882      evas_object_del(icon);
1883
1884    it->states = NULL;
1885    it->realized = EINA_FALSE;
1886    it->want_unrealize = EINA_FALSE;
1887 }
1888
1889 static Eina_Bool 
1890 _item_block_recalc(Item_Block *itb,
1891                    int         in,
1892                    int         qadd,
1893                    int         norender)
1894 {
1895    const Eina_List *l;
1896    Elm_Genlist_Item *it;
1897    Evas_Coord minw = 0, minh = 0;
1898    Eina_Bool showme = EINA_FALSE, changed = EINA_FALSE;
1899    Evas_Coord y = 0;
1900
1901    itb->num = in;
1902    EINA_LIST_FOREACH(itb->items, l, it)
1903      {
1904         if (it->delete_me) continue;
1905         showme |= it->showme;
1906         if (!itb->realized)
1907           {
1908              if (qadd)
1909                {
1910                   if (!it->mincalcd) changed = EINA_TRUE;
1911                   if (changed)
1912                     {
1913                        _item_realize(it, in, 1);
1914                        _item_unrealize(it);
1915                     }
1916                }
1917              else
1918                {
1919                   _item_realize(it, in, 1);
1920                   _item_unrealize(it);
1921                }
1922           }
1923         else
1924           _item_realize(it, in, 0);
1925         minh += it->minh;
1926         if (minw < it->minw) minw = it->minw;
1927         in++;
1928         it->x = 0;
1929         it->y = y;
1930         y += it->h;
1931      }
1932    itb->minw = minw;
1933    itb->minh = minh;
1934    itb->changed = EINA_FALSE;
1935    /* force an evas norender to garbage collect deleted objects */
1936    if (norender) evas_norender(evas_object_evas_get(itb->wd->obj));
1937    return showme;
1938 }
1939
1940 static void
1941 _item_block_realize(Item_Block *itb,
1942                     int         in,
1943                     int         full)
1944 {
1945    const Eina_List *l;
1946    Elm_Genlist_Item *it;
1947
1948    if (itb->realized) return;
1949    EINA_LIST_FOREACH(itb->items, l, it)
1950      {
1951         if (it->delete_me) continue;
1952         if (full) _item_realize(it, in, 0);
1953         in++;
1954      }
1955    itb->realized = EINA_TRUE;
1956    itb->want_unrealize = EINA_FALSE;
1957 }
1958
1959 static void
1960 _item_block_unrealize(Item_Block *itb)
1961 {
1962    const Eina_List *l;
1963    Elm_Genlist_Item *it;
1964    Eina_Bool dragging = EINA_FALSE;
1965
1966    if (!itb->realized) return;
1967    EINA_LIST_FOREACH(itb->items, l, it)
1968      {
1969         if (it->flags != ELM_GENLIST_ITEM_GROUP)
1970           {
1971              if (it->dragging)
1972                {
1973                   dragging = EINA_TRUE;
1974                   it->want_unrealize = EINA_TRUE;
1975                }
1976              else
1977                 _item_unrealize(it);
1978           }
1979      }
1980    if (!dragging)
1981      {
1982         itb->realized = EINA_FALSE;
1983         itb->want_unrealize = EINA_TRUE;
1984      }
1985    else
1986      itb->want_unrealize = EINA_FALSE;
1987 }
1988
1989 static void
1990 _item_block_position(Item_Block *itb,
1991                      int         in)
1992 {
1993    const Eina_List *l;
1994    Elm_Genlist_Item *it;
1995    Elm_Genlist_Item *git;
1996    Evas_Coord y = 0, ox, oy, ow, oh, cvx, cvy, cvw, cvh;
1997    int vis;
1998
1999    evas_object_geometry_get(itb->wd->pan_smart, &ox, &oy, &ow, &oh);
2000    evas_output_viewport_get(evas_object_evas_get(itb->wd->obj), &cvx, &cvy,
2001                             &cvw, &cvh);
2002    EINA_LIST_FOREACH(itb->items, l, it)
2003      {
2004         if (it->delete_me) continue;
2005         it->x = 0;
2006         it->y = y;
2007         it->w = itb->w;
2008         it->scrl_x = itb->x + it->x - it->wd->pan_x + ox;
2009         it->scrl_y = itb->y + it->y - it->wd->pan_y + oy;
2010
2011         vis = (ELM_RECTS_INTERSECT(it->scrl_x, it->scrl_y, it->w, it->h,
2012                                    cvx, cvy, cvw, cvh));
2013         if (it->flags != ELM_GENLIST_ITEM_GROUP)
2014           {
2015              if ((itb->realized) && (!it->realized))
2016                {
2017                   if (vis) _item_realize(it, in, 0);
2018                }
2019              if (it->realized)
2020                {
2021                   if (vis)
2022                     {
2023                        git = it->group_item;
2024                        if (git)
2025                          {
2026                             if (git->scrl_y < oy)
2027                                git->scrl_y = oy;
2028                             if ((git->scrl_y + git->h) > (it->scrl_y + it->h))
2029                                git->scrl_y = (it->scrl_y + it->h) - git->h;
2030                             git->want_realize = EINA_TRUE;
2031                          }
2032                        evas_object_resize(it->base.view, it->w, it->h);
2033                        evas_object_move(it->base.view,
2034                                         it->scrl_x, it->scrl_y);
2035                        evas_object_show(it->base.view);
2036                     }
2037                   else
2038                     {
2039                        if (!it->dragging) _item_unrealize(it);
2040                     }
2041                }
2042              in++;
2043           }
2044         else
2045           {
2046             if (vis) it->want_realize = EINA_TRUE;
2047           }
2048         y += it->h;
2049      }
2050 }
2051
2052 static void
2053 _group_items_recalc(void *data)
2054 {
2055    Widget_Data *wd = data;
2056    Eina_List *l;
2057    Elm_Genlist_Item *git;
2058
2059    EINA_LIST_FOREACH(wd->group_items, l, git)
2060      {
2061         if (git->want_realize) 
2062           {
2063              if (!git->realized)
2064                 _item_realize(git, 0, 0);
2065              evas_object_resize(git->base.view, wd->minw, git->h);
2066              evas_object_move(git->base.view, git->scrl_x, git->scrl_y);
2067              evas_object_show(git->base.view);
2068              evas_object_raise(git->base.view);
2069           }
2070         else if (!git->want_realize && git->realized)
2071           {
2072              if (!git->dragging) 
2073                 _item_unrealize(git);
2074           }
2075      }
2076 }
2077
2078 static Eina_Bool
2079 _must_recalc_idler(void *data)
2080 {
2081    Widget_Data *wd = data;
2082    if (wd->calc_job) ecore_job_del(wd->calc_job);
2083    wd->calc_job = ecore_job_add(_calc_job, wd);
2084    wd->must_recalc_idler = NULL;
2085    return ECORE_CALLBACK_CANCEL;
2086 }
2087
2088 static void
2089 _calc_job(void *data)
2090 {
2091    Widget_Data *wd = data;
2092    Item_Block *itb;
2093    Evas_Coord minw = -1, minh = 0, y = 0, ow;
2094    Item_Block *chb = NULL;
2095    int in = 0, minw_change = 0;
2096    Eina_Bool changed = EINA_FALSE;
2097    double t0, t;
2098    Eina_Bool did_must_recalc = EINA_FALSE;
2099    if (!wd) return;
2100
2101    t0 = ecore_time_get();
2102    evas_object_geometry_get(wd->pan_smart, NULL, NULL, &ow, &wd->h);
2103    if (wd->w != ow)
2104      {
2105         wd->w = ow;
2106 //        if (wd->height_for_width) changed = EINA_TRUE;
2107      }
2108
2109    EINA_INLIST_FOREACH(wd->blocks, itb)
2110    {
2111       Eina_Bool showme = EINA_FALSE;
2112
2113       itb->num = in;
2114       showme = itb->showme;
2115       itb->showme = EINA_FALSE;
2116       if (chb)
2117         {
2118            if (itb->realized) _item_block_unrealize(itb);
2119         }
2120       if ((itb->changed) || (changed) ||
2121           ((itb->must_recalc) && (!did_must_recalc)))
2122         {
2123            if ((changed) || (itb->must_recalc))
2124              {
2125                 Eina_List *l;
2126                 Elm_Genlist_Item *it;
2127                 EINA_LIST_FOREACH(itb->items, l, it)
2128                   if (it->mincalcd) it->mincalcd = EINA_FALSE;
2129                 itb->changed = EINA_TRUE;
2130                 if (itb->must_recalc) did_must_recalc = EINA_TRUE;
2131                 itb->must_recalc = EINA_FALSE;
2132              }
2133            if (itb->realized) _item_block_unrealize(itb);
2134            showme = _item_block_recalc(itb, in, 0, 1);
2135            chb = itb;
2136         }
2137       itb->y = y;
2138       itb->x = 0;
2139       minh += itb->minh;
2140       if (minw == -1) minw = itb->minw;
2141       else if ((!itb->must_recalc) && (minw < itb->minw))
2142         {
2143            minw = itb->minw;
2144            minw_change = 1;
2145         }
2146       itb->w = minw;
2147       itb->h = itb->minh;
2148       y += itb->h;
2149       in += itb->count;
2150       if ((showme) && (wd->show_item))
2151         {
2152            wd->show_item->showme = EINA_FALSE;
2153            if (wd->bring_in)
2154              elm_smart_scroller_region_bring_in(wd->scr,
2155                                                 wd->show_item->x +
2156                                                 wd->show_item->block->x,
2157                                                 wd->show_item->y +
2158                                                 wd->show_item->block->y,
2159                                                 wd->show_item->block->w,
2160                                                 wd->show_item->h);
2161            else
2162              elm_smart_scroller_child_region_show(wd->scr,
2163                                                   wd->show_item->x +
2164                                                   wd->show_item->block->x,
2165                                                   wd->show_item->y +
2166                                                   wd->show_item->block->y,
2167                                                   wd->show_item->block->w,
2168                                                   wd->show_item->h);
2169            wd->show_item = NULL;
2170         }
2171    }
2172    if (minw_change)
2173      {
2174         EINA_INLIST_FOREACH(wd->blocks, itb)
2175         {
2176            itb->minw = minw;
2177            itb->w = itb->minw;
2178         }
2179      }
2180    if ((chb) && (EINA_INLIST_GET(chb)->next))
2181      {
2182         EINA_INLIST_FOREACH(EINA_INLIST_GET(chb)->next, itb)
2183         {
2184            if (itb->realized) _item_block_unrealize(itb);
2185         }
2186      }
2187    wd->realminw = minw;
2188    if (minw < wd->w) minw = wd->w;
2189    if ((minw != wd->minw) || (minh != wd->minh))
2190      {
2191         wd->minw = minw;
2192         wd->minh = minh;
2193         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2194         _sizing_eval(wd->obj);
2195         if ((wd->anchor_item) && (wd->anchor_item->block))
2196           {
2197              Elm_Genlist_Item *it;
2198              Evas_Coord it_y;
2199
2200              it = wd->anchor_item;
2201              it_y = wd->anchor_y;
2202              elm_smart_scroller_child_pos_set(wd->scr, wd->pan_x,
2203                                               it->block->y + it->y + it_y);
2204              wd->anchor_item = it;
2205              wd->anchor_y = it_y;
2206           }
2207      }
2208    t = ecore_time_get();
2209    if (did_must_recalc)
2210      {
2211         if (!wd->must_recalc_idler)
2212           wd->must_recalc_idler = ecore_idler_add(_must_recalc_idler, wd);
2213      }
2214    wd->calc_job = NULL;
2215    evas_object_smart_changed(wd->pan_smart);
2216 }
2217
2218 static void
2219 _update_job(void *data)
2220 {
2221    Widget_Data *wd = data;
2222    Eina_List *l2;
2223    Item_Block *itb;
2224    int num, num0, position = 0, recalc = 0;
2225    if (!wd) return;
2226    wd->update_job = NULL;
2227    num = 0;
2228    EINA_INLIST_FOREACH(wd->blocks, itb)
2229    {
2230       Evas_Coord itminw, itminh;
2231       Elm_Genlist_Item *it;
2232
2233       if (!itb->updateme)
2234         {
2235            num += itb->count;
2236            if (position)
2237              _item_block_position(itb, num);
2238            continue;
2239         }
2240       num0 = num;
2241       recalc = 0;
2242       EINA_LIST_FOREACH(itb->items, l2, it)
2243         {
2244            if (it->updateme)
2245              {
2246                 itminw = it->w;
2247                 itminh = it->h;
2248
2249                 it->updateme = EINA_FALSE;
2250                 if (it->realized)
2251                   {
2252                      _item_unrealize(it);
2253                      _item_realize(it, num, 0);
2254                      position = 1;
2255                   }
2256                 else
2257                   {
2258                      _item_realize(it, num, 1);
2259                      _item_unrealize(it);
2260                   }
2261                 if ((it->minw != itminw) || (it->minh != itminh))
2262                   recalc = 1;
2263              }
2264            num++;
2265         }
2266       itb->updateme = EINA_FALSE;
2267       if (recalc)
2268         {
2269            position = 1;
2270            itb->changed = EINA_TRUE;
2271            _item_block_recalc(itb, num0, 0, 1);
2272            _item_block_position(itb, num0);
2273         }
2274    }
2275    if (position)
2276      {
2277         if (wd->calc_job) ecore_job_del(wd->calc_job);
2278         wd->calc_job = ecore_job_add(_calc_job, wd);
2279      }
2280 }
2281
2282 static void
2283 _pan_set(Evas_Object *obj,
2284          Evas_Coord   x,
2285          Evas_Coord   y)
2286 {
2287    Pan *sd = evas_object_smart_data_get(obj);
2288    Item_Block *itb;
2289
2290 //   Evas_Coord ow, oh;
2291 //   evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2292 //   ow = sd->wd->minw - ow;
2293 //   if (ow < 0) ow = 0;
2294 //   oh = sd->wd->minh - oh;
2295 //   if (oh < 0) oh = 0;
2296 //   if (x < 0) x = 0;
2297 //   if (y < 0) y = 0;
2298 //   if (x > ow) x = ow;
2299 //   if (y > oh) y = oh;
2300    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2301    sd->wd->pan_x = x;
2302    sd->wd->pan_y = y;
2303
2304    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2305    {
2306       if ((itb->y + itb->h) > y)
2307         {
2308            Elm_Genlist_Item *it;
2309            Eina_List *l2;
2310
2311            EINA_LIST_FOREACH(itb->items, l2, it)
2312              {
2313                 if ((itb->y + it->y) >= y)
2314                   {
2315                      sd->wd->anchor_item = it;
2316                      sd->wd->anchor_y = -(itb->y + it->y - y);
2317                      goto done;
2318                   }
2319              }
2320         }
2321    }
2322 done:
2323    evas_object_smart_changed(obj);
2324 }
2325
2326 static void
2327 _pan_get(Evas_Object *obj,
2328          Evas_Coord  *x,
2329          Evas_Coord  *y)
2330 {
2331    Pan *sd = evas_object_smart_data_get(obj);
2332
2333    if (x) *x = sd->wd->pan_x;
2334    if (y) *y = sd->wd->pan_y;
2335 }
2336
2337 static void
2338 _pan_max_get(Evas_Object *obj,
2339              Evas_Coord  *x,
2340              Evas_Coord  *y)
2341 {
2342    Pan *sd = evas_object_smart_data_get(obj);
2343    Evas_Coord ow, oh;
2344
2345    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2346    ow = sd->wd->minw - ow;
2347    if (ow < 0) ow = 0;
2348    oh = sd->wd->minh - oh;
2349    if (oh < 0) oh = 0;
2350    if (x) *x = ow;
2351    if (y) *y = oh;
2352 }
2353
2354 static void
2355 _pan_min_get(Evas_Object *obj __UNUSED__,
2356              Evas_Coord      *x,
2357              Evas_Coord      *y)
2358 {
2359    if (x) *x = 0;
2360    if (y) *y = 0;
2361 }
2362
2363 static void
2364 _pan_child_size_get(Evas_Object *obj,
2365                     Evas_Coord  *w,
2366                     Evas_Coord  *h)
2367 {
2368    Pan *sd = evas_object_smart_data_get(obj);
2369
2370    if (w) *w = sd->wd->minw;
2371    if (h) *h = sd->wd->minh;
2372 }
2373
2374 static void
2375 _pan_add(Evas_Object *obj)
2376 {
2377    Pan *sd;
2378    Evas_Object_Smart_Clipped_Data *cd;
2379
2380    _pan_sc.add(obj);
2381    cd = evas_object_smart_data_get(obj);
2382    sd = ELM_NEW(Pan);
2383    if (!sd) return;
2384    sd->__clipped_data = *cd;
2385    free(cd);
2386    evas_object_smart_data_set(obj, sd);
2387 }
2388
2389 static void
2390 _pan_del(Evas_Object *obj)
2391 {
2392    Pan *sd = evas_object_smart_data_get(obj);
2393
2394    if (!sd) return;
2395    if (sd->resize_job)
2396      {
2397         ecore_job_del(sd->resize_job);
2398         sd->resize_job = NULL;
2399      }
2400    _pan_sc.del(obj);
2401 }
2402
2403 static void
2404 _pan_resize_job(void *data)
2405 {
2406    Pan *sd = data;
2407    _sizing_eval(sd->wd->obj);
2408    sd->resize_job = NULL;
2409 }
2410
2411 static void
2412 _pan_resize(Evas_Object *obj,
2413             Evas_Coord   w,
2414             Evas_Coord   h)
2415 {
2416    Pan *sd = evas_object_smart_data_get(obj);
2417    Evas_Coord ow, oh;
2418
2419    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2420    if ((ow == w) && (oh == h)) return;
2421    if ((sd->wd->height_for_width) && (ow != w))
2422      {
2423         if (sd->resize_job) ecore_job_del(sd->resize_job);
2424         sd->resize_job = ecore_job_add(_pan_resize_job, sd);
2425      }
2426    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2427    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2428 }
2429
2430 static void
2431 _pan_calculate(Evas_Object *obj)
2432 {
2433    Pan *sd = evas_object_smart_data_get(obj);
2434    Item_Block *itb;
2435    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh;
2436    int in = 0;
2437    Elm_Genlist_Item *git;
2438    Eina_List *l;
2439
2440    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2441    evas_output_viewport_get(evas_object_evas_get(obj), &cvx, &cvy, &cvw, &cvh);
2442    EINA_LIST_FOREACH(sd->wd->group_items, l, git)
2443      {
2444         git->want_realize = EINA_FALSE;
2445      }
2446    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2447    {
2448       itb->w = sd->wd->minw;
2449       if (ELM_RECTS_INTERSECT(itb->x - sd->wd->pan_x + ox,
2450                               itb->y - sd->wd->pan_y + oy,
2451                               itb->w, itb->h,
2452                               cvx, cvy, cvw, cvh))
2453         {
2454            if ((!itb->realized) || (itb->changed))
2455              _item_block_realize(itb, in, 0);
2456            _item_block_position(itb, in);
2457         }
2458       else
2459         {
2460            if (itb->realized) _item_block_unrealize(itb);
2461         }
2462       in += itb->count;
2463    }
2464    _group_items_recalc(sd->wd);
2465 }
2466
2467 static void
2468 _pan_move(Evas_Object *obj,
2469           Evas_Coord x __UNUSED__,
2470           Evas_Coord y __UNUSED__)
2471 {
2472    Pan *sd = evas_object_smart_data_get(obj);
2473
2474    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2475    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2476 }
2477
2478 static void
2479 _hold_on(void *data       __UNUSED__,
2480          Evas_Object     *obj,
2481          void *event_info __UNUSED__)
2482 {
2483    Widget_Data *wd = elm_widget_data_get(obj);
2484    if (!wd) return;
2485    elm_smart_scroller_hold_set(wd->scr, 1);
2486 }
2487
2488 static void
2489 _hold_off(void *data       __UNUSED__,
2490           Evas_Object     *obj,
2491           void *event_info __UNUSED__)
2492 {
2493    Widget_Data *wd = elm_widget_data_get(obj);
2494    if (!wd) return;
2495    elm_smart_scroller_hold_set(wd->scr, 0);
2496 }
2497
2498 static void
2499 _freeze_on(void *data       __UNUSED__,
2500            Evas_Object     *obj,
2501            void *event_info __UNUSED__)
2502 {
2503    Widget_Data *wd = elm_widget_data_get(obj);
2504    if (!wd) return;
2505    elm_smart_scroller_freeze_set(wd->scr, 1);
2506 }
2507
2508 static void
2509 _freeze_off(void *data       __UNUSED__,
2510             Evas_Object     *obj,
2511             void *event_info __UNUSED__)
2512 {
2513    Widget_Data *wd = elm_widget_data_get(obj);
2514    if (!wd) return;
2515    elm_smart_scroller_freeze_set(wd->scr, 0);
2516 }
2517
2518 static void
2519 _scroll_edge_left(void            *data,
2520                   Evas_Object *scr __UNUSED__,
2521                   void *event_info __UNUSED__)
2522 {
2523    Evas_Object *obj = data;
2524    evas_object_smart_callback_call(obj, "scroll,edge,left", NULL);
2525 }
2526
2527 static void
2528 _scroll_edge_right(void            *data,
2529                    Evas_Object *scr __UNUSED__,
2530                    void *event_info __UNUSED__)
2531 {
2532    Evas_Object *obj = data;
2533    evas_object_smart_callback_call(obj, "scroll,edge,right", NULL);
2534 }
2535
2536 static void
2537 _scroll_edge_top(void            *data,
2538                  Evas_Object *scr __UNUSED__,
2539                  void *event_info __UNUSED__)
2540 {
2541    Evas_Object *obj = data;
2542    evas_object_smart_callback_call(obj, "scroll,edge,top", NULL);
2543 }
2544
2545 static void
2546 _scroll_edge_bottom(void            *data,
2547                     Evas_Object *scr __UNUSED__,
2548                     void *event_info __UNUSED__)
2549 {
2550    Evas_Object *obj = data;
2551    evas_object_smart_callback_call(obj, "scroll,edge,bottom", NULL);
2552 }
2553
2554 /**
2555  * Add a new Genlist object
2556  *
2557  * @param parent The parent object
2558  * @return The new object or NULL if it cannot be created
2559  *
2560  * @ingroup Genlist
2561  */
2562 EAPI Evas_Object *
2563 elm_genlist_add(Evas_Object *parent)
2564 {
2565    Evas_Object *obj;
2566    Evas *e;
2567    Widget_Data *wd;
2568    Evas_Coord minw, minh;
2569    static Evas_Smart *smart = NULL;
2570
2571    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
2572
2573    if (!smart)
2574      {
2575         static Evas_Smart_Class sc;
2576
2577         evas_object_smart_clipped_smart_set(&_pan_sc);
2578         sc = _pan_sc;
2579         sc.name = "elm_genlist_pan";
2580         sc.version = EVAS_SMART_CLASS_VERSION;
2581         sc.add = _pan_add;
2582         sc.del = _pan_del;
2583         sc.resize = _pan_resize;
2584         sc.move = _pan_move;
2585         sc.calculate = _pan_calculate;
2586         if (!(smart = evas_smart_class_new(&sc))) return NULL;
2587      }
2588    wd = ELM_NEW(Widget_Data);
2589    e = evas_object_evas_get(parent);
2590    if (!e) return NULL;
2591    obj = elm_widget_add(e);
2592    ELM_SET_WIDTYPE(widtype, "genlist");
2593    elm_widget_type_set(obj, "genlist");
2594    elm_widget_sub_object_add(parent, obj);
2595    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2596    elm_widget_data_set(obj, wd);
2597    elm_widget_del_hook_set(obj, _del_hook);
2598    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2599    elm_widget_theme_hook_set(obj, _theme_hook);
2600    elm_widget_can_focus_set(obj, EINA_TRUE);
2601    elm_widget_event_hook_set(obj, _event_hook);
2602
2603    wd->scr = elm_smart_scroller_add(e);
2604    elm_smart_scroller_widget_set(wd->scr, obj);
2605    elm_smart_scroller_object_theme_set(obj, wd->scr, "genlist", "base",
2606                                        elm_widget_style_get(obj));
2607    elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
2608                                        _elm_config->thumbscroll_bounce_enable);
2609    elm_widget_resize_object_set(obj, wd->scr);
2610
2611    evas_object_smart_callback_add(wd->scr, "edge,left", _scroll_edge_left, obj);
2612    evas_object_smart_callback_add(wd->scr, "edge,right", _scroll_edge_right,
2613                                   obj);
2614    evas_object_smart_callback_add(wd->scr, "edge,top", _scroll_edge_top, obj);
2615    evas_object_smart_callback_add(wd->scr, "edge,bottom", _scroll_edge_bottom,
2616                                   obj);
2617
2618    wd->obj = obj;
2619    wd->mode = ELM_LIST_SCROLL;
2620    wd->max_items_per_block = MAX_ITEMS_PER_BLOCK;
2621    wd->item_cache_max = wd->max_items_per_block * 2;
2622    wd->longpress_timeout = _elm_config->longpress_timeout;
2623
2624    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
2625    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
2626    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
2627    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
2628
2629    wd->pan_smart = evas_object_smart_add(e, smart);
2630    wd->pan = evas_object_smart_data_get(wd->pan_smart);
2631    wd->pan->wd = wd;
2632
2633    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
2634                                      _pan_set, _pan_get, _pan_max_get,
2635                                      _pan_min_get, _pan_child_size_get);
2636
2637    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
2638                              &minw, &minh);
2639    evas_object_size_hint_min_set(obj, minw, minh);
2640
2641    _sizing_eval(obj);
2642    return obj;
2643 }
2644
2645 static Elm_Genlist_Item *
2646 _item_new(Widget_Data                  *wd,
2647           const Elm_Genlist_Item_Class *itc,
2648           const void                   *data,
2649           Elm_Genlist_Item             *parent,
2650           Elm_Genlist_Item_Flags        flags,
2651           Evas_Smart_Cb                 func,
2652           const void                   *func_data)
2653 {
2654    Elm_Genlist_Item *it;
2655
2656    it = elm_widget_item_new(wd->obj, Elm_Genlist_Item);
2657    if (!it) return NULL;
2658    it->wd = wd;
2659    it->itc = itc;
2660    it->base.data = data;
2661    it->parent = parent;
2662    it->flags = flags;
2663    it->func.func = func;
2664    it->func.data = func_data;
2665    it->mouse_cursor = NULL;
2666    it->expanded_depth = 0;
2667    return it;
2668 }
2669
2670 static void
2671 _item_block_add(Widget_Data      *wd,
2672                 Elm_Genlist_Item *it)
2673 {
2674    Item_Block *itb = NULL;
2675
2676    if (!it->rel)
2677      {
2678 newblock:
2679         if (it->rel)
2680           {
2681              itb = calloc(1, sizeof(Item_Block));
2682              if (!itb) return;
2683              itb->wd = wd;
2684              if (!it->rel->block)
2685                {
2686                   wd->blocks =
2687                     eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
2688                   itb->items = eina_list_append(itb->items, it);
2689                }
2690              else
2691                {
2692                   if (it->before)
2693                     {
2694                        wd->blocks = eina_inlist_prepend_relative
2695                            (wd->blocks, EINA_INLIST_GET(itb),
2696                            EINA_INLIST_GET(it->rel->block));
2697                        itb->items =
2698                          eina_list_prepend_relative(itb->items, it, it->rel);
2699                     }
2700                   else
2701                     {
2702                        wd->blocks = eina_inlist_append_relative
2703                            (wd->blocks, EINA_INLIST_GET(itb),
2704                            EINA_INLIST_GET(it->rel->block));
2705                        itb->items =
2706                          eina_list_append_relative(itb->items, it, it->rel);
2707                     }
2708                }
2709           }
2710         else
2711           {
2712              if (it->before)
2713                {
2714                   if (wd->blocks)
2715                     {
2716                        itb = (Item_Block *)(wd->blocks);
2717                        if (itb->count >= wd->max_items_per_block)
2718                          {
2719                             itb = calloc(1, sizeof(Item_Block));
2720                             if (!itb) return;
2721                             itb->wd = wd;
2722                             wd->blocks =
2723                               eina_inlist_prepend(wd->blocks,
2724                                                   EINA_INLIST_GET(itb));
2725                          }
2726                     }
2727                   else
2728                     {
2729                        itb = calloc(1, sizeof(Item_Block));
2730                        if (!itb) return;
2731                        itb->wd = wd;
2732                        wd->blocks =
2733                          eina_inlist_prepend(wd->blocks, EINA_INLIST_GET(itb));
2734                     }
2735                   itb->items = eina_list_prepend(itb->items, it);
2736                }
2737              else
2738                {
2739                   if (wd->blocks)
2740                     {
2741                        itb = (Item_Block *)(wd->blocks->last);
2742                        if (itb->count >= wd->max_items_per_block)
2743                          {
2744                             itb = calloc(1, sizeof(Item_Block));
2745                             if (!itb) return;
2746                             itb->wd = wd;
2747                             wd->blocks =
2748                               eina_inlist_append(wd->blocks,
2749                                                  EINA_INLIST_GET(itb));
2750                          }
2751                     }
2752                   else
2753                     {
2754                        itb = calloc(1, sizeof(Item_Block));
2755                        if (!itb) return;
2756                        itb->wd = wd;
2757                        wd->blocks =
2758                          eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
2759                     }
2760                   itb->items = eina_list_append(itb->items, it);
2761                }
2762           }
2763      }
2764    else
2765      {
2766         itb = it->rel->block;
2767         if (!itb) goto newblock;
2768         if (it->before)
2769           itb->items = eina_list_prepend_relative(itb->items, it, it->rel);
2770         else
2771           itb->items = eina_list_append_relative(itb->items, it, it->rel);
2772      }
2773    itb->count++;
2774    itb->changed = EINA_TRUE;
2775    it->block = itb;
2776    if (itb->wd->calc_job) ecore_job_del(itb->wd->calc_job);
2777    itb->wd->calc_job = ecore_job_add(_calc_job, itb->wd);
2778    if (it->rel)
2779      {
2780         it->rel->relcount--;
2781         if ((it->rel->delete_me) && (!it->rel->relcount))
2782           _item_del(it->rel);
2783         it->rel = NULL;
2784      }
2785    if (itb->count > itb->wd->max_items_per_block)
2786      {
2787         int newc;
2788         Item_Block *itb2;
2789         Elm_Genlist_Item *it2;
2790
2791         newc = itb->count / 2;
2792         itb2 = calloc(1, sizeof(Item_Block));
2793         if (!itb2) return;
2794         itb2->wd = wd;
2795         wd->blocks =
2796           eina_inlist_append_relative(wd->blocks, EINA_INLIST_GET(itb2),
2797                                       EINA_INLIST_GET(itb));
2798         itb2->changed = EINA_TRUE;
2799         while ((itb->count > newc) && (itb->items))
2800           {
2801              Eina_List *l;
2802
2803              l = eina_list_last(itb->items);
2804              it2 = l->data;
2805              itb->items = eina_list_remove_list(itb->items, l);
2806              itb->count--;
2807
2808              itb2->items = eina_list_prepend(itb2->items, it2);
2809              it2->block = itb2;
2810              itb2->count++;
2811           }
2812      }
2813 }
2814
2815 static int
2816 _queue_proecess(Widget_Data *wd,
2817                 int          norender)
2818 {
2819    int n;
2820    Eina_Bool showme = EINA_FALSE;
2821    double t0, t;
2822
2823    t0 = ecore_time_get();
2824    for (n = 0; (wd->queue) && (n < 128); n++)
2825      {
2826         Elm_Genlist_Item *it;
2827
2828         it = wd->queue->data;
2829         wd->queue = eina_list_remove_list(wd->queue, wd->queue);
2830         it->queued = EINA_FALSE;
2831         _item_block_add(wd, it);
2832         t = ecore_time_get();
2833         if (it->block->changed)
2834           {
2835              showme = _item_block_recalc(it->block, it->block->num, 1,
2836                                          norender);
2837              it->block->changed = 0;
2838           }
2839         if (showme) it->block->showme = EINA_TRUE;
2840         if (eina_inlist_count(wd->blocks) > 1)
2841           {
2842              if ((t - t0) > (ecore_animator_frametime_get())) break;
2843           }
2844      }
2845    return n;
2846 }
2847
2848 static Eina_Bool
2849 _item_idler(void *data)
2850 {
2851    Widget_Data *wd = data;
2852
2853    //xxx
2854    //static double q_start = 0.0;
2855    //if (q_start == 0.0) q_start = ecore_time_get();
2856    //xxx
2857
2858    if (_queue_proecess(wd, 1) > 0)
2859      {
2860         if (wd->calc_job) ecore_job_del(wd->calc_job);
2861         wd->calc_job = ecore_job_add(_calc_job, wd);
2862      }
2863    if (!wd->queue)
2864      {
2865         //xxx
2866         //printf("PROCESS TIME: %3.3f\n", ecore_time_get() - q_start);
2867         //xxx
2868         wd->queue_idler = NULL;
2869         return ECORE_CALLBACK_CANCEL;
2870      }
2871    return ECORE_CALLBACK_RENEW;
2872 }
2873
2874 static void
2875 _item_queue(Widget_Data      *wd,
2876             Elm_Genlist_Item *it)
2877 {
2878    if (it->queued) return;
2879    it->queued = EINA_TRUE;
2880    wd->queue = eina_list_append(wd->queue, it);
2881    while ((wd->queue) && ((!wd->blocks) || (!wd->blocks->next)))
2882      {
2883         if (wd->queue_idler)
2884           {
2885              ecore_idler_del(wd->queue_idler);
2886              wd->queue_idler = NULL;
2887           }
2888         _queue_proecess(wd, 0);
2889      }
2890    if (!wd->queue_idler) wd->queue_idler = ecore_idler_add(_item_idler, wd);
2891 }
2892
2893 /**
2894  * Append item to the end of the genlist
2895  *
2896  * This appends the given item to the end of the list or the end of
2897  * the children if the parent is given.
2898  *
2899  * @param obj The genlist object
2900  * @param itc The item class for the item
2901  * @param data The item data
2902  * @param parent The parent item, or NULL if none
2903  * @param flags Item flags
2904  * @param func Convenience function called when item selected
2905  * @param func_data Data passed to @p func above.
2906  * @return A handle to the item added or NULL if not possible
2907  *
2908  * @ingroup Genlist
2909  */
2910 EAPI Elm_Genlist_Item *
2911 elm_genlist_item_append(Evas_Object                  *obj,
2912                         const Elm_Genlist_Item_Class *itc,
2913                         const void                   *data,
2914                         Elm_Genlist_Item             *parent,
2915                         Elm_Genlist_Item_Flags        flags,
2916                         Evas_Smart_Cb                 func,
2917                         const void                   *func_data)
2918 {
2919    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2920    Widget_Data *wd = elm_widget_data_get(obj);
2921    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
2922                                     func_data);
2923    if (!wd) return NULL;
2924    if (!it) return NULL;
2925    if (!it->parent)
2926      {
2927         if (flags & ELM_GENLIST_ITEM_GROUP)
2928            wd->group_items = eina_list_append(wd->group_items, it);
2929         wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
2930         it->rel = NULL;
2931      }
2932    else
2933      {
2934         Elm_Genlist_Item *it2 = NULL;
2935         Eina_List *ll = eina_list_last(it->parent->items);
2936         if (ll) it2 = ll->data;
2937         it->parent->items = eina_list_append(it->parent->items, it);
2938         if (!it2) it2 = it->parent;
2939         wd->items =
2940           eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
2941                                       EINA_INLIST_GET(it2));
2942         it->rel = it2;
2943         it->rel->relcount++;
2944
2945         if (it->parent->flags & ELM_GENLIST_ITEM_GROUP) 
2946            it->group_item = parent;
2947         else if (it->parent->group_item)
2948            it->group_item = it->parent->group_item;
2949      }
2950    it->before = EINA_FALSE;
2951    _item_queue(wd, it);
2952    return it;
2953 }
2954
2955 /**
2956  * Prepend item at start of the genlist
2957  *
2958  * This adds an item to the beginning of the list or beginning of the
2959  * children of the parent if given.
2960  *
2961  * @param obj The genlist object
2962  * @param itc The item class for the item
2963  * @param data The item data
2964  * @param parent The parent item, or NULL if none
2965  * @param flags Item flags
2966  * @param func Convenience function called when item selected
2967  * @param func_data Data passed to @p func above.
2968  * @return A handle to the item added or NULL if not possible
2969  *
2970  * @ingroup Genlist
2971  */
2972 EAPI Elm_Genlist_Item *
2973 elm_genlist_item_prepend(Evas_Object                  *obj,
2974                          const Elm_Genlist_Item_Class *itc,
2975                          const void                   *data,
2976                          Elm_Genlist_Item             *parent,
2977                          Elm_Genlist_Item_Flags        flags,
2978                          Evas_Smart_Cb                 func,
2979                          const void                   *func_data)
2980 {
2981    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2982    Widget_Data *wd = elm_widget_data_get(obj);
2983    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
2984                                     func_data);
2985    if (!wd) return NULL;
2986    if (!it) return NULL;
2987    if (!it->parent)
2988      {
2989         if (flags & ELM_GENLIST_ITEM_GROUP)
2990            wd->group_items = eina_list_prepend(wd->group_items, it);
2991         wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
2992         it->rel = NULL;
2993      }
2994    else
2995      {
2996         Elm_Genlist_Item *it2 = NULL;
2997         Eina_List *ll = it->parent->items;
2998         if (ll) it2 = ll->data;
2999         it->parent->items = eina_list_prepend(it->parent->items, it);
3000         if (!it2) it2 = it->parent;
3001         wd->items =
3002            eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3003                                         EINA_INLIST_GET(it2));
3004         it->rel = it2;
3005         it->rel->relcount++;
3006      }
3007    it->before = EINA_TRUE;
3008    _item_queue(wd, it);
3009    return it;
3010 }
3011
3012 /**
3013  * Insert item before another in the genlist
3014  *
3015  * This inserts an item before another in the list. It will be in the
3016  * same tree level or group as the item it is inseted before.
3017  *
3018  * @param obj The genlist object
3019  * @param itc The item class for the item
3020  * @param data The item data
3021  * @param before The item to insert before
3022  * @param flags Item flags
3023  * @param func Convenience function called when item selected
3024  * @param func_data Data passed to @p func above.
3025  * @return A handle to the item added or NULL if not possible
3026  *
3027  * @ingroup Genlist
3028  */
3029 EAPI Elm_Genlist_Item *
3030 elm_genlist_item_insert_before(Evas_Object                  *obj,
3031                                const Elm_Genlist_Item_Class *itc,
3032                                const void                   *data,
3033                                Elm_Genlist_Item             *parent,
3034                                Elm_Genlist_Item             *before,
3035                                Elm_Genlist_Item_Flags        flags,
3036                                Evas_Smart_Cb                 func,
3037                                const void                   *func_data)
3038 {
3039    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3040    EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
3041    Widget_Data *wd = elm_widget_data_get(obj);
3042    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3043                                     func_data);
3044    if (!wd) return NULL;
3045    if (!it) return NULL;
3046    if (it->parent)
3047      {
3048         it->parent->items = eina_list_prepend_relative(it->parent->items, it,
3049                                                        before);
3050      }
3051    wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3052                                             EINA_INLIST_GET(before));
3053    it->rel = before;
3054    it->rel->relcount++;
3055    it->before = EINA_TRUE;
3056    _item_queue(wd, it);
3057    return it;
3058 }
3059
3060 /**
3061  * Insert an item after another in the genlst
3062  *
3063  * This inserts an item after another in the list. It will be in the
3064  * same tree level or group as the item it is inseted after.
3065  *
3066  * @param obj The genlist object
3067  * @param itc The item class for the item
3068  * @param data The item data
3069  * @param after The item to insert after
3070  * @param flags Item flags
3071  * @param func Convenience function called when item selected
3072  * @param func_data Data passed to @p func above.
3073  * @return A handle to the item added or NULL if not possible
3074  *
3075  * @ingroup Genlist
3076  */
3077 EAPI Elm_Genlist_Item *
3078 elm_genlist_item_insert_after(Evas_Object                  *obj,
3079                               const Elm_Genlist_Item_Class *itc,
3080                               const void                   *data,
3081                               Elm_Genlist_Item             *parent,
3082                               Elm_Genlist_Item             *after,
3083                               Elm_Genlist_Item_Flags        flags,
3084                               Evas_Smart_Cb                 func,
3085                               const void                   *func_data)
3086 {
3087    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3088    EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
3089    Widget_Data *wd = elm_widget_data_get(obj);
3090    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3091                                     func_data);
3092    if (!wd) return NULL;
3093    if (!it) return NULL;
3094    wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3095                                            EINA_INLIST_GET(after));
3096    if (it->parent)
3097      {
3098         it->parent->items = eina_list_append_relative(it->parent->items, it,
3099                                                       after);
3100      }
3101    it->rel = after;
3102    it->rel->relcount++;
3103    it->before = EINA_FALSE;
3104    _item_queue(wd, it);
3105    return it;
3106 }
3107
3108 /**
3109  * Clear the genlist
3110  *
3111  * This clears all items in the list, leaving it empty.
3112  *
3113  * @param obj The genlist object
3114  *
3115  * @ingroup Genlist
3116  */
3117 EAPI void
3118 elm_genlist_clear(Evas_Object *obj)
3119 {
3120    ELM_CHECK_WIDTYPE(obj, widtype);
3121    Widget_Data *wd = elm_widget_data_get(obj);
3122    if (!wd) return;
3123    if (wd->walking > 0)
3124      {
3125         Elm_Genlist_Item *it;
3126
3127         wd->clear_me = EINA_TRUE;
3128         EINA_INLIST_FOREACH(wd->items, it)
3129         {
3130            it->delete_me = EINA_TRUE;
3131         }
3132         return;
3133      }
3134    wd->clear_me = EINA_FALSE;
3135    while (wd->items)
3136      {
3137         Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3138
3139         if (wd->anchor_item == it)
3140           {
3141              wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3142              if (!wd->anchor_item)
3143                wd->anchor_item =
3144                  ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3145           }
3146         wd->items = eina_inlist_remove(wd->items, wd->items);
3147         if (it->flags & ELM_GENLIST_ITEM_GROUP)
3148           it->wd->group_items = eina_list_remove(it->wd->group_items, it);
3149         elm_widget_item_pre_notify_del(it);
3150         if (it->realized) _item_unrealize(it);
3151         if (it->itc->func.del)
3152           it->itc->func.del((void *)it->base.data, it->base.widget);
3153         if (it->long_timer) ecore_timer_del(it->long_timer);
3154         if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
3155         elm_widget_item_del(it);
3156      }
3157    wd->anchor_item = NULL;
3158    while (wd->blocks)
3159      {
3160         Item_Block *itb = (Item_Block *)(wd->blocks);
3161
3162         wd->blocks = eina_inlist_remove(wd->blocks, wd->blocks);
3163         if (itb->items) eina_list_free(itb->items);
3164         free(itb);
3165      }
3166    if (wd->calc_job)
3167      {
3168         ecore_job_del(wd->calc_job);
3169         wd->calc_job = NULL;
3170      }
3171    if (wd->queue_idler)
3172      {
3173         ecore_idler_del(wd->queue_idler);
3174         wd->queue_idler = NULL;
3175      }
3176    if (wd->must_recalc_idler)
3177      {
3178         ecore_idler_del(wd->must_recalc_idler);
3179         wd->must_recalc_idler = NULL;
3180      }
3181    if (wd->queue)
3182      {
3183         eina_list_free(wd->queue);
3184         wd->queue = NULL;
3185      }
3186    if (wd->selected)
3187      {
3188         eina_list_free(wd->selected);
3189         wd->selected = NULL;
3190      }
3191    wd->show_item = NULL;
3192    wd->pan_x = 0;
3193    wd->pan_y = 0;
3194    wd->minw = 0;
3195    wd->minh = 0;
3196    if (wd->pan_smart)
3197      {
3198         evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
3199         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
3200      }
3201    _sizing_eval(obj);
3202 }
3203
3204 /**
3205  * Enable or disable multi-select in the genlist
3206  *
3207  * This enables (EINA_TRUE) or disableds (EINA_FALSE) multi-select in
3208  * the list. This allows more than 1 item to be selected.
3209  *
3210  * @param obj The genlist object
3211  * @param multi Multi-select enable/disable
3212  *
3213  * @ingroup Genlist
3214  */
3215 EAPI void
3216 elm_genlist_multi_select_set(Evas_Object *obj,
3217                              Eina_Bool    multi)
3218 {
3219    ELM_CHECK_WIDTYPE(obj, widtype);
3220    Widget_Data *wd = elm_widget_data_get(obj);
3221    if (!wd) return;
3222    wd->multi = multi;
3223 }
3224
3225 /**
3226  * Gets if multi-select in genlist is enable or disable
3227  *
3228  * @param obj The genlist object
3229  * @return Multi-select enable/disable
3230  * (EINA_TRUE = enabled/EINA_FALSE = disabled)
3231  *
3232  * @ingroup Genlist
3233  */
3234 EAPI Eina_Bool
3235 elm_genlist_multi_select_get(const Evas_Object *obj)
3236 {
3237    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3238    Widget_Data *wd = elm_widget_data_get(obj);
3239    if (!wd) return EINA_FALSE;
3240    return wd->multi;
3241 }
3242
3243 /**
3244  * Get the selectd item in the genlist
3245  *
3246  * This gets the selected item in the list (if multi-select is enabled
3247  * only the first item in the list is selected - which is not very
3248  * useful, so see elm_genlist_selected_items_get() for when
3249  * multi-select is used).
3250  *
3251  * If no item is selected, NULL is returned.
3252  *
3253  * @param obj The genlist object
3254  * @return The selected item, or NULL if none.
3255  *
3256  * @ingroup Genlist
3257  */
3258 EAPI Elm_Genlist_Item *
3259 elm_genlist_selected_item_get(const Evas_Object *obj)
3260 {
3261    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3262    Widget_Data *wd = elm_widget_data_get(obj);
3263    if (!wd) return NULL;
3264    if (wd->selected) return wd->selected->data;
3265    return NULL;
3266 }
3267
3268 /**
3269  * Get a list of selected items in the genlist
3270  *
3271  * This returns a list of the selected items. This list pointer is
3272  * only valid so long as no items are selected or unselected (or
3273  * unselected implicitly by deletion). The list contains
3274  * Elm_Genlist_Item pointers.
3275  *
3276  * @param obj The genlist object
3277  * @return The list of selected items, nor NULL if none are selected.
3278  *
3279  * @ingroup Genlist
3280  */
3281 EAPI const Eina_List *
3282 elm_genlist_selected_items_get(const Evas_Object *obj)
3283 {
3284    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3285    Widget_Data *wd = elm_widget_data_get(obj);
3286    if (!wd) return NULL;
3287    return wd->selected;
3288 }
3289
3290 /**
3291  * Get a list of realized items in genlist
3292  *
3293  * This returns a list of the realized items in the genlist. The list
3294  * contains Elm_Genlist_Item pointers. The list must be freed by the
3295  * caller when done with eina_list_free(). The item pointers in the
3296  * list are only valid so long as those items are not deleted or the
3297  * genlist is not deleted.
3298  *
3299  * @param obj The genlist object
3300  * @return The list of realized items, nor NULL if none are realized.
3301  *
3302  * @ingroup Genlist
3303  */
3304 EAPI Eina_List *
3305 elm_genlist_realized_items_get(const Evas_Object *obj)
3306 {
3307    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3308    Widget_Data *wd = elm_widget_data_get(obj);
3309    Eina_List *list = NULL;
3310    Item_Block *itb;
3311    Eina_Bool done = EINA_FALSE;
3312    if (!wd) return NULL;
3313    EINA_INLIST_FOREACH(wd->blocks, itb)
3314    {
3315       if (itb->realized)
3316         {
3317            Eina_List *l;
3318            Elm_Genlist_Item *it;
3319
3320            done = 1;
3321            EINA_LIST_FOREACH(itb->items, l, it)
3322              {
3323                 if (it->realized) list = eina_list_append(list, it);
3324              }
3325         }
3326       else
3327         {
3328            if (done) break;
3329         }
3330    }
3331    return list;
3332 }
3333
3334 /**
3335  * Get the item that is at the x, y canvas coords
3336  *
3337  * This returns the item at the given coordinates (which are canvas
3338  * relative not object-relative). If an item is at that coordinate,
3339  * that item handle is returned, and if @p posret is not NULL, the
3340  * integer pointed to is set to a value of -1, 0 or 1, depending if
3341  * the coordinate is on the upper portion of that item (-1), on the
3342  * middle section (0) or on the lower part (1). If NULL is returned as
3343  * an item (no item found there), then posret may indicate -1 or 1
3344  * based if the coordinate is above or below all items respectively in
3345  * the genlist.
3346  *
3347  * @param it The item
3348  * @param x The input x coordinate
3349  * @param y The input y coordinate
3350  * @param posret The position relative to the item returned here
3351  * @return The item at the coordinates or NULL if none
3352  *
3353  * @ingroup Genlist
3354  */
3355 EAPI Elm_Genlist_Item *
3356 elm_genlist_at_xy_item_get(const Evas_Object *obj,
3357                            Evas_Coord         x,
3358                            Evas_Coord         y,
3359                            int               *posret)
3360 {
3361    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3362    Widget_Data *wd = elm_widget_data_get(obj);
3363    Evas_Coord ox, oy, ow, oh;
3364    Item_Block *itb;
3365    Evas_Coord lasty;
3366    if (!wd) return NULL;
3367    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
3368    lasty = oy;
3369    EINA_INLIST_FOREACH(wd->blocks, itb)
3370    {
3371       Eina_List *l;
3372       Elm_Genlist_Item *it;
3373
3374       if (!ELM_RECTS_INTERSECT(ox + itb->x - itb->wd->pan_x,
3375                                oy + itb->y - itb->wd->pan_y,
3376                                itb->w, itb->h, x, y, 1, 1))
3377         continue;
3378       EINA_LIST_FOREACH(itb->items, l, it)
3379         {
3380            Evas_Coord itx, ity;
3381
3382            itx = ox + itb->x + it->x - itb->wd->pan_x;
3383            ity = oy + itb->y + it->y - itb->wd->pan_y;
3384            if (ELM_RECTS_INTERSECT(itx, ity, it->w, it->h, x, y, 1, 1))
3385              {
3386                 if (posret)
3387                   {
3388                      if (y <= (ity + (it->h / 4))) *posret = -1;
3389                      else if (y >= (ity + it->h - (it->h / 4)))
3390                        *posret = 1;
3391                      else *posret = 0;
3392                   }
3393                 return it;
3394              }
3395            lasty = ity + it->h;
3396         }
3397    }
3398    if (posret)
3399      {
3400         if (y > lasty) *posret = 1;
3401         else *posret = -1;
3402      }
3403    return NULL;
3404 }
3405
3406 /**
3407  * Get the first item in the genlist
3408  *
3409  * This returns the first item in the list.
3410  *
3411  * @param obj The genlist object
3412  * @return The first item, or NULL if none
3413  *
3414  * @ingroup Genlist
3415  */
3416 EAPI Elm_Genlist_Item *
3417 elm_genlist_first_item_get(const Evas_Object *obj)
3418 {
3419    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3420    Widget_Data *wd = elm_widget_data_get(obj);
3421    if (!wd) return NULL;
3422    if (!wd->items) return NULL;
3423    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3424    while ((it) && (it->delete_me))
3425      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3426    return it;
3427 }
3428
3429 /**
3430  * Get the last item in the genlist
3431  *
3432  * This returns the last item in the list.
3433  *
3434  * @return The last item, or NULL if none
3435  *
3436  * @ingroup Genlist
3437  */
3438 EAPI Elm_Genlist_Item *
3439 elm_genlist_last_item_get(const Evas_Object *obj)
3440 {
3441    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3442    Widget_Data *wd = elm_widget_data_get(obj);
3443    if (!wd) return NULL;
3444    if (!wd->items) return NULL;
3445    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items->last);
3446    while ((it) && (it->delete_me))
3447      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3448    return it;
3449 }
3450
3451 /**
3452  * Get the next item in the genlist
3453  *
3454  * This returns the item after the item @p it.
3455  *
3456  * @param it The item
3457  * @return The item after @p it, or NULL if none
3458  *
3459  * @ingroup Genlist
3460  */
3461 EAPI Elm_Genlist_Item *
3462 elm_genlist_item_next_get(const Elm_Genlist_Item *it)
3463 {
3464    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3465    while (it)
3466      {
3467         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3468         if ((it) && (!it->delete_me)) break;
3469      }
3470    return (Elm_Genlist_Item *)it;
3471 }
3472
3473 /**
3474  * Get the previous item in the genlist
3475  *
3476  * This returns the item before the item @p it.
3477  *
3478  * @param it The item
3479  * @return The item before @p it, or NULL if none
3480  *
3481  * @ingroup Genlist
3482  */
3483 EAPI Elm_Genlist_Item *
3484 elm_genlist_item_prev_get(const Elm_Genlist_Item *it)
3485 {
3486    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3487    while (it)
3488      {
3489         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3490         if ((it) && (!it->delete_me)) break;
3491      }
3492    return (Elm_Genlist_Item *)it;
3493 }
3494
3495 /**
3496  * Get the genlist object from an item
3497  *
3498  * This returns the genlist object itself that an item belongs to.
3499  *
3500  * @param it The item
3501  * @return The genlist object
3502  *
3503  * @ingroup Genlist
3504  */
3505 EAPI Evas_Object *
3506 elm_genlist_item_genlist_get(const Elm_Genlist_Item *it)
3507 {
3508    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3509    return it->base.widget;
3510 }
3511
3512 /**
3513  * Get the parent item of the given item
3514  *
3515  * This returns the parent item of the item @p it given.
3516  *
3517  * @param it The item
3518  * @return The parent of the item or NULL if none
3519  *
3520  * @ingroup Genlist
3521  */
3522 EAPI Elm_Genlist_Item *
3523 elm_genlist_item_parent_get(const Elm_Genlist_Item *it)
3524 {
3525    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3526    return it->parent;
3527 }
3528
3529 /**
3530  * Clear all sub-items (children) of the given item
3531  *
3532  * This clears all items that are children (or their descendants) of the
3533  * given item @p it.
3534  *
3535  * @param it The item
3536  *
3537  * @ingroup Genlist
3538  */
3539 EAPI void
3540 elm_genlist_item_subitems_clear(Elm_Genlist_Item *it)
3541 {
3542    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3543    Eina_List *tl = NULL, *l;
3544    Elm_Genlist_Item *it2;
3545
3546    EINA_LIST_FOREACH(it->items, l, it2)
3547      tl = eina_list_append(tl, it2);
3548    EINA_LIST_FREE(tl, it2)
3549      elm_genlist_item_del(it2);
3550 }
3551
3552 /**
3553  * Set the selected state of an item
3554  *
3555  * This sets the selected state (1 selected, 0 not selected) of the given
3556  * item @p it.
3557  *
3558  * @param it The item
3559  * @param selected The selected state
3560  *
3561  * @ingroup Genlist
3562  */
3563 EAPI void
3564 elm_genlist_item_selected_set(Elm_Genlist_Item *it,
3565                               Eina_Bool         selected)
3566 {
3567    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3568    Widget_Data *wd = elm_widget_data_get(it->base.widget);
3569    if (!wd) return;
3570    if (it->delete_me) return;
3571    selected = !!selected;
3572    if (it->selected == selected) return;
3573
3574    if (selected)
3575      {
3576         if (!wd->multi)
3577           {
3578              while (wd->selected)
3579                _item_unselect(wd->selected->data);
3580           }
3581         _item_hilight(it);
3582         _item_select(it);
3583      }
3584    else
3585      _item_unselect(it);
3586 }
3587
3588 /**
3589  * Get the selected state of an item
3590  *
3591  * This gets the selected state of an item (1 selected, 0 not selected).
3592  *
3593  * @param it The item
3594  * @return The selected state
3595  *
3596  * @ingroup Genlist
3597  */
3598 EAPI Eina_Bool
3599 elm_genlist_item_selected_get(const Elm_Genlist_Item *it)
3600 {
3601    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
3602    return it->selected;
3603 }
3604
3605 /**
3606  * Sets the expanded state of an item (if it's a parent)
3607  *
3608  * This expands or contracts a parent item (thus showing or hiding the
3609  * children).
3610  *
3611  * @param it The item
3612  * @param expanded The expanded state (1 expanded, 0 not expanded).
3613  *
3614  * @ingroup Genlist
3615  */
3616 EAPI void
3617 elm_genlist_item_expanded_set(Elm_Genlist_Item *it,
3618                               Eina_Bool         expanded)
3619 {
3620    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3621    if (it->expanded == expanded) return;
3622    it->expanded = expanded;
3623    if (it->expanded)
3624      {
3625         if (it->realized)
3626           edje_object_signal_emit(it->base.view, "elm,state,expanded", "elm");
3627         evas_object_smart_callback_call(it->base.widget, "expanded", it);
3628      }
3629    else
3630      {
3631         if (it->realized)
3632           edje_object_signal_emit(it->base.view, "elm,state,contracted", "elm");
3633         evas_object_smart_callback_call(it->base.widget, "contracted", it);
3634      }
3635 }
3636
3637 /**
3638  * Get the expanded state of an item
3639  *
3640  * This gets the expanded state of an item
3641  *
3642  * @param it The item
3643  * @return Thre expanded state
3644  *
3645  * @ingroup Genlist
3646  */
3647 EAPI Eina_Bool
3648 elm_genlist_item_expanded_get(const Elm_Genlist_Item *it)
3649 {
3650    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
3651    return it->expanded;
3652 }
3653
3654 /**
3655  * Get the depth of expanded item
3656  *
3657  * @param it The genlist item object
3658  * @return The depth of expanded item
3659  *
3660  * @ingroup Genlist
3661  */
3662 EAPI int
3663 elm_genlist_item_expanded_depth_get(const Elm_Genlist_Item *it)
3664 {
3665    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, 0);
3666    return it->expanded_depth;
3667 }
3668
3669 /**
3670  * Sets the disabled state of an item.
3671  *
3672  * A disabled item cannot be selected or unselected. It will also
3673  * change appearance to appear disabled. This sets the disabled state
3674  * (1 disabled, 0 not disabled).
3675  *
3676  * @param it The item
3677  * @param disabled The disabled state
3678  *
3679  * @ingroup Genlist
3680  */
3681 EAPI void
3682 elm_genlist_item_disabled_set(Elm_Genlist_Item *it,
3683                               Eina_Bool         disabled)
3684 {
3685    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3686    if (it->disabled == disabled) return;
3687    if (it->delete_me) return;
3688    it->disabled = disabled;
3689    if (it->realized)
3690      {
3691         if (it->disabled)
3692           edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
3693         else
3694           edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
3695      }
3696 }
3697
3698 /**
3699  * Get the disabled state of an item
3700  *
3701  * This gets the disabled state of the given item.
3702  *
3703  * @param it The item
3704  * @return The disabled state
3705  *
3706  * @ingroup Genlist
3707  */
3708 EAPI Eina_Bool
3709 elm_genlist_item_disabled_get(const Elm_Genlist_Item *it)
3710 {
3711    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
3712    if (it->delete_me) return EINA_FALSE;
3713    return it->disabled;
3714 }
3715
3716 /**
3717  * Sets the display only state of an item.
3718  *
3719  * A display only item cannot be selected or unselected. It is for
3720  * display only and not selecting or otherwise clicking, dragging
3721  * etc. by the user, thus finger size rules will not be applied to
3722  * this item.
3723  *
3724  * @param it The item
3725  * @param display_only The display only state
3726  *
3727  * @ingroup Genlist
3728  */
3729 EAPI void
3730 elm_genlist_item_display_only_set(Elm_Genlist_Item *it,
3731                                   Eina_Bool         display_only)
3732 {
3733    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3734    if (!it->block) return;
3735    if (it->display_only == display_only) return;
3736    if (it->delete_me) return;
3737    it->display_only = display_only;
3738    it->mincalcd = EINA_FALSE;
3739    it->updateme = EINA_TRUE;
3740    it->block->updateme = EINA_TRUE;
3741    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
3742    it->wd->update_job = ecore_job_add(_update_job, it->wd);
3743 }
3744
3745 /**
3746  * Get the display only state of an item
3747  *
3748  * This gets the display only state of the given item.
3749  *
3750  * @param it The item
3751  * @return The display only state
3752  *
3753  * @ingroup Genlist
3754  */
3755 EAPI Eina_Bool
3756 elm_genlist_item_display_only_get(const Elm_Genlist_Item *it)
3757 {
3758    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
3759    if (it->delete_me) return EINA_FALSE;
3760    return it->display_only;
3761 }
3762
3763 /**
3764  * Show the given item
3765  *
3766  * This causes genlist to jump to the given item @p it and show it (by
3767  * scrolling), if it is not fully visible.
3768  *
3769  * @param it The item
3770  *
3771  * @ingroup Genlist
3772  */
3773 EAPI void
3774 elm_genlist_item_show(Elm_Genlist_Item *it)
3775 {
3776    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3777    Evas_Coord gith = 0;
3778    if (it->delete_me) return;
3779    if ((it->queued) || (!it->mincalcd))
3780      {
3781         it->wd->show_item = it;
3782         it->wd->bring_in = EINA_TRUE;
3783         it->showme = EINA_TRUE;
3784         return;
3785      }
3786    if (it->wd->show_item)
3787      {
3788         it->wd->show_item->showme = EINA_FALSE;
3789         it->wd->show_item = NULL;
3790      }
3791    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
3792       gith = it->group_item->h;
3793    elm_smart_scroller_child_region_show(it->wd->scr,
3794                                         it->x + it->block->x,
3795                                         it->y + it->block->y - gith,
3796                                         it->block->w, it->h);
3797 }
3798
3799 /**
3800  * Bring in the given item
3801  *
3802  * This causes genlist to jump to the given item @p it and show it (by
3803  * scrolling), if it is not fully visible. This may use animation to
3804  * do so and take a period of time
3805  *
3806  * @param it The item
3807  *
3808  * @ingroup Genlist
3809  */
3810 EAPI void
3811 elm_genlist_item_bring_in(Elm_Genlist_Item *it)
3812 {
3813    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3814    Evas_Coord gith = 0; 
3815    if (it->delete_me) return;
3816    if ((it->queued) || (!it->mincalcd))
3817      {
3818         it->wd->show_item = it;
3819         it->wd->bring_in = EINA_TRUE;
3820         it->showme = EINA_TRUE;
3821         return;
3822      }
3823    if (it->wd->show_item)
3824      {
3825         it->wd->show_item->showme = EINA_FALSE;
3826         it->wd->show_item = NULL;
3827      }
3828    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
3829       gith = it->group_item->h;
3830    elm_smart_scroller_region_bring_in(it->wd->scr,
3831                                       it->x + it->block->x,
3832                                       it->y + it->block->y - gith,
3833                                       it->block->w, it->h);
3834 }
3835
3836 /**
3837  * Show the given item at the top
3838  *
3839  * This causes genlist to jump to the given item @p it and show it (by
3840  * scrolling), if it is not fully visible.
3841  *
3842  * @param it The item
3843  *
3844  * @ingroup Genlist
3845  */
3846 EAPI void
3847 elm_genlist_item_top_show(Elm_Genlist_Item *it)
3848 {
3849    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3850    Evas_Coord ow, oh;
3851    Evas_Coord gith = 0;
3852
3853    if (it->delete_me) return;
3854    if ((it->queued) || (!it->mincalcd))
3855      {
3856         it->wd->show_item = it;
3857         it->wd->bring_in = EINA_TRUE;
3858         it->showme = EINA_TRUE;
3859         return;
3860      }
3861    if (it->wd->show_item)
3862      {
3863         it->wd->show_item->showme = EINA_FALSE;
3864         it->wd->show_item = NULL;
3865      }
3866    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
3867    if (it->group_item) gith = it->group_item->h;
3868    elm_smart_scroller_child_region_show(it->wd->scr,
3869                                         it->x + it->block->x,
3870                                         it->y + it->block->y - gith,
3871                                         it->block->w, oh);
3872 }
3873
3874 /**
3875  * Bring in the given item at the top
3876  *
3877  * This causes genlist to jump to the given item @p it and show it (by
3878  * scrolling), if it is not fully visible. This may use animation to
3879  * do so and take a period of time
3880  *
3881  * @param it The item
3882  *
3883  * @ingroup Genlist
3884  */
3885 EAPI void
3886 elm_genlist_item_top_bring_in(Elm_Genlist_Item *it)
3887 {
3888    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3889    Evas_Coord ow, oh;
3890    Evas_Coord gith = 0;
3891
3892    if (it->delete_me) return;
3893    if ((it->queued) || (!it->mincalcd))
3894      {
3895         it->wd->show_item = it;
3896         it->wd->bring_in = EINA_TRUE;
3897         it->showme = EINA_TRUE;
3898         return;
3899      }
3900    if (it->wd->show_item)
3901      {
3902         it->wd->show_item->showme = EINA_FALSE;
3903         it->wd->show_item = NULL;
3904      }
3905    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
3906    if (it->group_item) gith = it->group_item->h;
3907    elm_smart_scroller_region_bring_in(it->wd->scr,
3908                                       it->x + it->block->x,
3909                                       it->y + it->block->y - gith,
3910                                       it->block->w, oh);
3911 }
3912
3913 /**
3914  * Show the given item at the middle
3915  *
3916  * This causes genlist to jump to the given item @p it and show it (by
3917  * scrolling), if it is not fully visible.
3918  *
3919  * @param it The item
3920  *
3921  * @ingroup Genlist
3922  */
3923 EAPI void
3924 elm_genlist_item_middle_show(Elm_Genlist_Item *it)
3925 {
3926    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3927    Evas_Coord ow, oh;
3928
3929    if (it->delete_me) return;
3930    if ((it->queued) || (!it->mincalcd))
3931      {
3932         it->wd->show_item = it;
3933         it->wd->bring_in = EINA_TRUE;
3934         it->showme = EINA_TRUE;
3935         return;
3936      }
3937    if (it->wd->show_item)
3938      {
3939         it->wd->show_item->showme = EINA_FALSE;
3940         it->wd->show_item = NULL;
3941      }
3942    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
3943    elm_smart_scroller_child_region_show(it->wd->scr,
3944                                         it->x + it->block->x,
3945                                         it->y + it->block->y - oh / 2 +
3946                                         it->h / 2, it->block->w, oh);
3947 }
3948
3949 /**
3950  * Bring in the given item at the middle
3951  *
3952  * This causes genlist to jump to the given item @p it and show it (by
3953  * scrolling), if it is not fully visible. This may use animation to
3954  * do so and take a period of time
3955  *
3956  * @param it The item
3957  *
3958  * @ingroup Genlist
3959  */
3960 EAPI void
3961 elm_genlist_item_middle_bring_in(Elm_Genlist_Item *it)
3962 {
3963    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
3964    Evas_Coord ow, oh;
3965
3966    if (it->delete_me) return;
3967    if ((it->queued) || (!it->mincalcd))
3968      {
3969         it->wd->show_item = it;
3970         it->wd->bring_in = EINA_TRUE;
3971         it->showme = EINA_TRUE;
3972         return;
3973      }
3974    if (it->wd->show_item)
3975      {
3976         it->wd->show_item->showme = EINA_FALSE;
3977         it->wd->show_item = NULL;
3978      }
3979    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
3980    elm_smart_scroller_region_bring_in(it->wd->scr,
3981                                       it->x + it->block->x,
3982                                       it->y + it->block->y - oh / 2 + it->h / 2,
3983                                       it->block->w, oh);
3984 }
3985
3986 /**
3987  * Delete a given item
3988  *
3989  * This deletes the item from genlist and calls the genlist item del
3990  * class callback defined in the item class, if it is set. This clears all
3991  * subitems if it is a tree.
3992  *
3993  * @param it The item
3994  *
3995  * @ingroup Genlist
3996  */
3997 EAPI void
3998 elm_genlist_item_del(Elm_Genlist_Item *it)
3999 {
4000    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4001    if ((it->relcount > 0) || (it->walking > 0))
4002      {
4003         elm_widget_item_pre_notify_del(it);
4004         elm_genlist_item_subitems_clear(it);
4005         it->delete_me = EINA_TRUE;
4006         if (it->wd->show_item == it) it->wd->show_item = NULL;
4007         if (it->selected)
4008           it->wd->selected = eina_list_remove(it->wd->selected,
4009                                               it);
4010         if (it->block)
4011           {
4012              if (it->realized) _item_unrealize(it);
4013              it->block->changed = EINA_TRUE;
4014              if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
4015              it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
4016           }
4017         if (it->itc->func.del)
4018           it->itc->func.del((void *)it->base.data, it->base.widget);
4019         return;
4020      }
4021    _item_del(it);
4022 }
4023
4024 /**
4025  * Set the data item from the genlist item
4026  *
4027  * This set the data value passed on the elm_genlist_item_append() and
4028  * related item addition calls. This function will also call
4029  * elm_genlist_item_update() so the item will be updated to reflect the
4030  * new data.
4031  *
4032  * @param it The item
4033  * @param data The new data pointer to set
4034  *
4035  * @ingroup Genlist
4036  */
4037 EAPI void
4038 elm_genlist_item_data_set(Elm_Genlist_Item *it,
4039                           const void       *data)
4040 {
4041    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4042    elm_widget_item_data_set(it, data);
4043    elm_genlist_item_update(it);
4044 }
4045
4046 /**
4047  * Get the data item from the genlist item
4048  *
4049  * This returns the data value passed on the elm_genlist_item_append()
4050  * and related item addition calls and elm_genlist_item_data_set().
4051  *
4052  * @param it The item
4053  * @return The data pointer provided when created
4054  *
4055  * @ingroup Genlist
4056  */
4057 EAPI void *
4058 elm_genlist_item_data_get(const Elm_Genlist_Item *it)
4059 {
4060    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4061    return elm_widget_item_data_get(it);
4062 }
4063
4064 /**
4065  * Tells genlist to "orphan" icons fetchs by the item class
4066  *
4067  * This instructs genlist to release references to icons in the item,
4068  * meaning that they will no longer be managed by genlist and are
4069  * floating "orphans" that can be re-used elsewhere if the user wants
4070  * to.
4071  *
4072  * @param it The item
4073  *
4074  * @ingroup Genlist
4075  */
4076 EAPI void
4077 elm_genlist_item_icons_orphan(Elm_Genlist_Item *it)
4078 {
4079    Evas_Object *icon;
4080    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4081    EINA_LIST_FREE(it->icon_objs, icon)
4082      {
4083         elm_widget_sub_object_del(it->base.widget, icon);
4084         evas_object_smart_member_del(icon);
4085         evas_object_hide(icon);
4086      }
4087 }
4088
4089 /**
4090  * Get the real evas object of the genlist item
4091  *
4092  * This returns the actual evas object used for the specified genlist
4093  * item. This may be NULL as it may not be created, and may be deleted
4094  * at any time by genlist. Do not modify this object (move, resize,
4095  * show, hide etc.) as genlist is controlling it. This function is for
4096  * querying, emitting custom signals or hooking lower level callbacks
4097  * for events. Do not delete this object under any circumstances.
4098  *
4099  * @param it The item
4100  * @return The object pointer
4101  *
4102  * @ingroup Genlist
4103  */
4104 EAPI const Evas_Object *
4105 elm_genlist_item_object_get(const Elm_Genlist_Item *it)
4106 {
4107    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4108    return it->base.view;
4109 }
4110
4111 /**
4112  * Update the contents of an item
4113  *
4114  * This updates an item by calling all the item class functions again
4115  * to get the icons, labels and states. Use this when the original
4116  * item data has changed and the changes are desired to be reflected.
4117  *
4118  * @param it The item
4119  *
4120  * @ingroup Genlist
4121  */
4122 EAPI void
4123 elm_genlist_item_update(Elm_Genlist_Item *it)
4124 {
4125    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4126    if (!it->block) return;
4127    if (it->delete_me) return;
4128    it->mincalcd = EINA_FALSE;
4129    it->updateme = EINA_TRUE;
4130    it->block->updateme = EINA_TRUE;
4131    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4132    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4133 }
4134
4135 /**
4136  * Update the item class of an item
4137  *
4138  * @param it The item
4139  * @parem itc The item class for the item
4140  *
4141  * @ingroup Genlist
4142  */
4143 EAPI void
4144 elm_genlist_item_item_class_update(Elm_Genlist_Item             *it,
4145                                    const Elm_Genlist_Item_Class *itc)
4146 {
4147    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4148    if (!it->block) return;
4149    EINA_SAFETY_ON_NULL_RETURN(itc);
4150    if (it->delete_me) return;
4151    it->itc = itc;
4152    it->nocache = EINA_TRUE;
4153    elm_genlist_item_update(it);
4154 }
4155
4156 static Evas_Object *
4157 _elm_genlist_item_label_create(void        *data,
4158                                Evas_Object *obj,
4159                                void *item   __UNUSED__)
4160 {
4161    Evas_Object *label = elm_label_add(obj);
4162    if (!label)
4163      return NULL;
4164    elm_object_style_set(label, "tooltip");
4165    elm_label_label_set(label, data);
4166    return label;
4167 }
4168
4169 static void
4170 _elm_genlist_item_label_del_cb(void            *data,
4171                                Evas_Object *obj __UNUSED__,
4172                                void *event_info __UNUSED__)
4173 {
4174    eina_stringshare_del(data);
4175 }
4176
4177 /**
4178  * Set the text to be shown in the genlist item.
4179  *
4180  * @param item Target item
4181  * @param text The text to set in the content
4182  *
4183  * Setup the text as tooltip to object. The item can have only one
4184  * tooltip, so any previous tooltip data is removed.
4185  *
4186  * @ingroup Genlist
4187  */
4188 EAPI void
4189 elm_genlist_item_tooltip_text_set(Elm_Genlist_Item *item,
4190                                   const char       *text)
4191 {
4192    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4193    text = eina_stringshare_add(text);
4194    elm_genlist_item_tooltip_content_cb_set(item, _elm_genlist_item_label_create,
4195                                            text,
4196                                            _elm_genlist_item_label_del_cb);
4197 }
4198
4199 /**
4200  * Set the content to be shown in the tooltip item
4201  *
4202  * Setup the tooltip to item. The item can have only one tooltip, so
4203  * any previous tooltip data is removed. @p func(with @p data) will be
4204  * called every time that need to show the tooltip and it should return a
4205  * valid Evas_Object. This object is then managed fully by tooltip
4206  * system and is deleted when the tooltip is gone.
4207  *
4208  * @param item the genlist item being attached by a tooltip.
4209  * @param func the function used to create the tooltip contents.
4210  * @param data what to provide to @a func as callback data/context.
4211  * @param del_cb called when data is not needed anymore, either when
4212  *        another callback replaces @func, the tooltip is unset with
4213  *        elm_genlist_item_tooltip_unset() or the owner @a item
4214  *        dies. This callback receives as the first parameter the
4215  *        given @a data, and @c event_info is the item.
4216  *
4217  * @ingroup Genlist
4218  */
4219 EAPI void
4220 elm_genlist_item_tooltip_content_cb_set(Elm_Genlist_Item           *item,
4221                                         Elm_Tooltip_Item_Content_Cb func,
4222                                         const void                 *data,
4223                                         Evas_Smart_Cb               del_cb)
4224 {
4225    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
4226
4227    if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
4228      return;
4229
4230    if (item->tooltip.del_cb)
4231      item->tooltip.del_cb((void *)item->tooltip.data,
4232                           item->base.widget, item);
4233
4234    item->tooltip.content_cb = func;
4235    item->tooltip.data = data;
4236    item->tooltip.del_cb = del_cb;
4237
4238    if (item->base.view)
4239      {
4240         elm_widget_item_tooltip_content_cb_set(item,
4241                                                item->tooltip.content_cb,
4242                                                item->tooltip.data, NULL);
4243         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
4244      }
4245
4246    return;
4247
4248 error:
4249    if (del_cb) del_cb((void *)data, NULL, NULL);
4250 }
4251
4252 /**
4253  * Unset tooltip from item
4254  *
4255  * @param item genlist item to remove previously set tooltip.
4256  *
4257  * Remove tooltip from item. The callback provided as del_cb to
4258  * elm_genlist_item_tooltip_content_cb_set() will be called to notify
4259  * it is not used anymore.
4260  *
4261  * @see elm_genlist_item_tooltip_content_cb_set()
4262  *
4263  * @ingroup Genlist
4264  */
4265 EAPI void
4266 elm_genlist_item_tooltip_unset(Elm_Genlist_Item *item)
4267 {
4268    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4269    if ((item->base.view) && (item->tooltip.content_cb))
4270      elm_widget_item_tooltip_unset(item);
4271
4272    if (item->tooltip.del_cb)
4273      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
4274    item->tooltip.del_cb = NULL;
4275    item->tooltip.content_cb = NULL;
4276    item->tooltip.data = NULL;
4277    if (item->tooltip.style)
4278      elm_genlist_item_tooltip_style_set(item, NULL);
4279 }
4280
4281 /**
4282  * Sets a different style for this item tooltip.
4283  *
4284  * @note before you set a style you should define a tooltip with
4285  *       elm_genlist_item_tooltip_content_cb_set() or
4286  *       elm_genlist_item_tooltip_text_set()
4287  *
4288  * @param item genlist item with tooltip already set.
4289  * @param style the theme style to use (default, transparent, ...)
4290  *
4291  * @ingroup Genlist
4292  */
4293 EAPI void
4294 elm_genlist_item_tooltip_style_set(Elm_Genlist_Item *item,
4295                                    const char       *style)
4296 {
4297    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4298    eina_stringshare_replace(&item->tooltip.style, style);
4299    if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
4300 }
4301
4302 /**
4303  * Get the style for this item tooltip.
4304  *
4305  * @param item genlist item with tooltip already set.
4306  * @return style the theme style in use, defaults to "default". If the
4307  *         object does not have a tooltip set, then NULL is returned.
4308  *
4309  * @ingroup Genlist
4310  */
4311 EAPI const char *
4312 elm_genlist_item_tooltip_style_get(const Elm_Genlist_Item *item)
4313 {
4314    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4315    return item->tooltip.style;
4316 }
4317
4318 /**
4319  * Set the cursor to be shown when mouse is over the genlist item
4320  *
4321  * @param item Target item
4322  * @param cursor the cursor name to be used.
4323  *
4324  * @see elm_object_cursor_set()
4325  * @ingroup Genlist
4326  */
4327 EAPI void
4328 elm_genlist_item_cursor_set(Elm_Genlist_Item *item,
4329                             const char       *cursor)
4330 {
4331    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4332    eina_stringshare_replace(&item->mouse_cursor, cursor);
4333    if (item->base.view) elm_widget_item_cursor_set(item, cursor);
4334 }
4335
4336 /**
4337  * Get the cursor to be shown when mouse is over the genlist item
4338  *
4339  * @param item genlist item with cursor already set.
4340  * @return the cursor name.
4341  *
4342  * @ingroup Genlist
4343  */
4344 EAPI const char *
4345 elm_genlist_item_cursor_get(const Elm_Genlist_Item *item)
4346 {
4347    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4348    return elm_widget_item_cursor_get(item);
4349 }
4350
4351 /**
4352  * Unset the cursor to be shown when mouse is over the genlist item
4353  *
4354  * @param item Target item
4355  *
4356  * @see elm_object_cursor_unset()
4357  * @ingroup Genlist
4358  */
4359 EAPI void
4360 elm_genlist_item_cursor_unset(Elm_Genlist_Item *item)
4361 {
4362    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4363    if (!item->mouse_cursor)
4364      return;
4365
4366    if (item->base.view)
4367      elm_widget_item_cursor_unset(item);
4368
4369    eina_stringshare_del(item->mouse_cursor);
4370    item->mouse_cursor = NULL;
4371 }
4372
4373 /**
4374  * Sets a different style for this item cursor.
4375  *
4376  * @note before you set a style you should define a cursor with
4377  *       elm_genlist_item_cursor_set()
4378  *
4379  * @param item genlist item with cursor already set.
4380  * @param style the theme style to use (default, transparent, ...)
4381  *
4382  * @ingroup Genlist
4383  */
4384 EAPI void
4385 elm_genlist_item_cursor_style_set(Elm_Genlist_Item *item,
4386                                   const char       *style)
4387 {
4388    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4389    elm_widget_item_cursor_style_set(item, style);
4390 }
4391
4392 /**
4393  * Get the style for this item cursor.
4394  *
4395  * @param item genlist item with cursor already set.
4396  * @return style the theme style in use, defaults to "default". If the
4397  *         object does not have a cursor set, then NULL is returned.
4398  *
4399  * @ingroup Genlist
4400  */
4401 EAPI const char *
4402 elm_genlist_item_cursor_style_get(const Elm_Genlist_Item *item)
4403 {
4404    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4405    return elm_widget_item_cursor_style_get(item);
4406 }
4407
4408 /**
4409  * Set if the cursor set should be searched on the theme or should use
4410  * the provided by the engine, only.
4411  *
4412  * @note before you set if should look on theme you should define a
4413  * cursor with elm_object_cursor_set(). By default it will only look
4414  * for cursors provided by the engine.
4415  *
4416  * @param item widget item with cursor already set.
4417  * @param engine_only boolean to define it cursors should be looked
4418  * only between the provided by the engine or searched on widget's
4419  * theme as well.
4420  *
4421  * @ingroup Genlist
4422  */
4423 EAPI void
4424 elm_genlist_item_cursor_engine_only_set(Elm_Genlist_Item *item,
4425                                         Eina_Bool         engine_only)
4426 {
4427    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4428    elm_widget_item_cursor_engine_only_set(item, engine_only);
4429 }
4430
4431 /**
4432  * Get the cursor engine only usage for this item cursor.
4433  *
4434  * @param item widget item with cursor already set.
4435  * @return engine_only boolean to define it cursors should be looked
4436  * only between the provided by the engine or searched on widget's
4437  * theme as well. If the object does not have a cursor set, then
4438  * EINA_FALSE is returned.
4439  *
4440  * @ingroup Genlist
4441  */
4442 EAPI Eina_Bool
4443 elm_genlist_item_cursor_engine_only_get(const Elm_Genlist_Item *item)
4444 {
4445    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
4446    return elm_widget_item_cursor_engine_only_get(item);
4447 }
4448
4449 /**
4450  * This sets the horizontal stretching mode
4451  *
4452  * This sets the mode used for sizing items horizontally. Valid modes
4453  * are ELM_LIST_LIMIT and ELM_LIST_SCROLL. The default is
4454  * ELM_LIST_SCROLL. This mode means that if items are too wide to fit,
4455  * the scroller will scroll horizontally. Otherwise items are expanded
4456  * to fill the width of the viewport of the scroller. If it is
4457  * ELM_LIST_LIMIT, Items will be expanded to the viewport width and
4458  * limited to that size.
4459  *
4460  * @param obj The genlist object
4461  * @param mode The mode to use
4462  *
4463  * @ingroup Genlist
4464  */
4465 EAPI void
4466 elm_genlist_horizontal_mode_set(Evas_Object  *obj,
4467                                 Elm_List_Mode mode)
4468 {
4469    ELM_CHECK_WIDTYPE(obj, widtype);
4470    Widget_Data *wd = elm_widget_data_get(obj);
4471    if (!wd) return;
4472    if (wd->mode == mode) return;
4473    wd->mode = mode;
4474    _sizing_eval(obj);
4475 }
4476
4477 /**
4478  * Gets the horizontal stretching mode
4479  *
4480  * @param obj The genlist object
4481  * @return The mode to use
4482  * (ELM_LIST_LIMIT, ELM_LIST_SCROLL)
4483  *
4484  * @ingroup Genlist
4485  */
4486 EAPI Elm_List_Mode
4487 elm_genlist_horizontal_mode_get(const Evas_Object *obj)
4488 {
4489    ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
4490    Widget_Data *wd = elm_widget_data_get(obj);
4491    if (!wd) return ELM_LIST_LAST;
4492    return wd->mode;
4493 }
4494
4495 /**
4496  * Set the always select mode.
4497  *
4498  * Items will only call their selection func and callback when first
4499  * becoming selected. Any further clicks will do nothing, unless you
4500  * enable always select with elm_genlist_always_select_mode_set().
4501  * This means even if selected, every click will make the selected
4502  * callbacks be called.
4503  *
4504  * @param obj The genlist object
4505  * @param always_select The always select mode
4506  * (EINA_TRUE = on, EINA_FALSE = off)
4507  *
4508  * @ingroup Genlist
4509  */
4510 EAPI void
4511 elm_genlist_always_select_mode_set(Evas_Object *obj,
4512                                    Eina_Bool    always_select)
4513 {
4514    ELM_CHECK_WIDTYPE(obj, widtype);
4515    Widget_Data *wd = elm_widget_data_get(obj);
4516    if (!wd) return;
4517    wd->always_select = always_select;
4518 }
4519
4520 /**
4521  * Get the always select mode.
4522  *
4523  * @param obj The genlist object
4524  * @return The always select mode
4525  * (EINA_TRUE = on, EINA_FALSE = off)
4526  *
4527  * @ingroup Genlist
4528  */
4529 EAPI Eina_Bool
4530 elm_genlist_always_select_mode_get(const Evas_Object *obj)
4531 {
4532    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4533    Widget_Data *wd = elm_widget_data_get(obj);
4534    if (!wd) return EINA_FALSE;
4535    return wd->always_select;
4536 }
4537
4538 /**
4539  * Set no select mode
4540  *
4541  * This will turn off the ability to select items entirely and they
4542  * will neither appear selected nor call selected callback functions.
4543  *
4544  * @param obj The genlist object
4545  * @param no_select The no select mode
4546  * (EINA_TRUE = on, EINA_FALSE = off)
4547  *
4548  * @ingroup Genlist
4549  */
4550 EAPI void
4551 elm_genlist_no_select_mode_set(Evas_Object *obj,
4552                                Eina_Bool    no_select)
4553 {
4554    ELM_CHECK_WIDTYPE(obj, widtype);
4555    Widget_Data *wd = elm_widget_data_get(obj);
4556    if (!wd) return;
4557    wd->no_select = no_select;
4558 }
4559
4560 /**
4561  * Gets no select mode
4562  *
4563  * @param obj The genlist object
4564  * @return The no select mode
4565  * (EINA_TRUE = on, EINA_FALSE = off)
4566  *
4567  * @ingroup Genlist
4568  */
4569 EAPI Eina_Bool
4570 elm_genlist_no_select_mode_get(const Evas_Object *obj)
4571 {
4572    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4573    Widget_Data *wd = elm_widget_data_get(obj);
4574    if (!wd) return EINA_FALSE;
4575    return wd->no_select;
4576 }
4577
4578 /**
4579  * Set compress mode
4580  *
4581  * This will enable the compress mode where items are "compressed"
4582  * horizontally to fit the genlist scrollable viewport width. This is
4583  * special for genlist.  Do not rely on
4584  * elm_genlist_horizontal_mode_set() being set to ELM_LIST_COMPRESS to
4585  * work as genlist needs to handle it specially.
4586  *
4587  * @param obj The genlist object
4588  * @param compress The compress mode
4589  * (EINA_TRUE = on, EINA_FALSE = off)
4590  *
4591  * @ingroup Genlist
4592  */
4593 EAPI void
4594 elm_genlist_compress_mode_set(Evas_Object *obj,
4595                               Eina_Bool    compress)
4596 {
4597    ELM_CHECK_WIDTYPE(obj, widtype);
4598    Widget_Data *wd = elm_widget_data_get(obj);
4599    if (!wd) return;
4600    wd->compress = compress;
4601 }
4602
4603 /**
4604  * Get the compress mode
4605  *
4606  * @param obj The genlist object
4607  * @return The compress mode
4608  * (EINA_TRUE = on, EINA_FALSE = off)
4609  *
4610  * @ingroup Genlist
4611  */
4612 EAPI Eina_Bool
4613 elm_genlist_compress_mode_get(const Evas_Object *obj)
4614 {
4615    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4616    Widget_Data *wd = elm_widget_data_get(obj);
4617    if (!wd) return EINA_FALSE;
4618    return wd->compress;
4619 }
4620
4621 /**
4622  * Set height-for-width mode
4623  *
4624  * With height-for-width mode the item width will be fixed (restricted
4625  * to a minimum of) to the list width when calculating its size in
4626  * order to allow the height to be calculated based on it. This allows,
4627  * for instance, text block to wrap lines if the Edje part is
4628  * configured with "text.min: 0 1".
4629  *
4630  * @note This mode will make list resize slower as it will have to
4631  *       recalculate every item height again whenever the list width
4632  *       changes!
4633  *
4634  * @note When height-for-width mode is enabled, it also enables
4635  *       compress mode (see elm_genlist_compress_mode_set()) and
4636  *       disables homogeneous (see elm_genlist_homogeneous_set()).
4637  *
4638  * @param obj The genlist object
4639  * @param setting The height-for-width mode (EINA_TRUE = on,
4640  * EINA_FALSE = off)
4641  *
4642  * @ingroup Genlist
4643  */
4644 EAPI void
4645 elm_genlist_height_for_width_mode_set(Evas_Object *obj,
4646                                       Eina_Bool    height_for_width)
4647 {
4648    ELM_CHECK_WIDTYPE(obj, widtype);
4649    Widget_Data *wd = elm_widget_data_get(obj);
4650    if (!wd) return;
4651    wd->height_for_width = !!height_for_width;
4652    if (wd->height_for_width)
4653      {
4654         elm_genlist_homogeneous_set(obj, EINA_FALSE);
4655         elm_genlist_compress_mode_set(obj, EINA_TRUE);
4656      }
4657 }
4658
4659 /**
4660  * Get the height-for-width mode
4661  *
4662  * @param obj The genlist object
4663  * @return The height-for-width mode (EINA_TRUE = on, EINA_FALSE =
4664  * off)
4665  *
4666  * @ingroup Genlist
4667  */
4668 EAPI Eina_Bool
4669 elm_genlist_height_for_width_mode_get(const Evas_Object *obj)
4670 {
4671    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4672    Widget_Data *wd = elm_widget_data_get(obj);
4673    if (!wd) return EINA_FALSE;
4674    return wd->height_for_width;
4675 }
4676
4677 /**
4678  * Set bounce mode
4679  *
4680  * This will enable or disable the scroller bounce mode for the
4681  * genlist. See elm_scroller_bounce_set() for details
4682  *
4683  * @param obj The genlist object
4684  * @param h_bounce Allow bounce horizontally
4685  * @param v_bounce Allow bounce vertically
4686  *
4687  * @ingroup Genlist
4688  */
4689 EAPI void
4690 elm_genlist_bounce_set(Evas_Object *obj,
4691                        Eina_Bool    h_bounce,
4692                        Eina_Bool    v_bounce)
4693 {
4694    ELM_CHECK_WIDTYPE(obj, widtype);
4695    Widget_Data *wd = elm_widget_data_get(obj);
4696    if (!wd) return;
4697    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
4698 }
4699
4700 /**
4701  * Get the bounce mode
4702  *
4703  * @param obj The genlist object
4704  * @param h_bounce Allow bounce horizontally
4705  * @param v_bounce Allow bounce vertically
4706  *
4707  * @ingroup Genlist
4708  */
4709 EAPI void
4710 elm_genlist_bounce_get(const Evas_Object *obj,
4711                        Eina_Bool         *h_bounce,
4712                        Eina_Bool         *v_bounce)
4713 {
4714    ELM_CHECK_WIDTYPE(obj, widtype);
4715    Widget_Data *wd = elm_widget_data_get(obj);
4716    if (!wd) return;
4717    elm_smart_scroller_bounce_allow_get(obj, h_bounce, v_bounce);
4718 }
4719
4720 /**
4721  * Set homogenous mode
4722  *
4723  * This will enable the homogeneous mode where items are of the same
4724  * height and width so that genlist may do the lazy-loading at its
4725  * maximum. This implies 'compressed' mode.
4726  *
4727  * @param obj The genlist object
4728  * @param homogeneous Assume the items within the genlist are of the
4729  * same height and width (EINA_TRUE = on, EINA_FALSE = off)
4730  *
4731  * @ingroup Genlist
4732  */
4733 EAPI void
4734 elm_genlist_homogeneous_set(Evas_Object *obj,
4735                             Eina_Bool    homogeneous)
4736 {
4737    ELM_CHECK_WIDTYPE(obj, widtype);
4738    Widget_Data *wd = elm_widget_data_get(obj);
4739    if (!wd) return;
4740    if (homogeneous) elm_genlist_compress_mode_set(obj, EINA_TRUE);
4741    wd->homogeneous = homogeneous;
4742 }
4743
4744 /**
4745  * Get the homogenous mode
4746  *
4747  * @param obj The genlist object
4748  * @return Assume the items within the genlist are of the same height
4749  * and width (EINA_TRUE = on, EINA_FALSE = off)
4750  *
4751  * @ingroup Genlist
4752  */
4753 EAPI Eina_Bool
4754 elm_genlist_homogeneous_get(const Evas_Object *obj)
4755 {
4756    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4757    Widget_Data *wd = elm_widget_data_get(obj);
4758    if (!wd) return EINA_FALSE;
4759    return wd->homogeneous;
4760 }
4761
4762 /**
4763  * Set the maximum number of items within an item block
4764  *
4765  * This will configure the block count to tune to the target with
4766  * particular performance matrix.
4767  *
4768  * @param obj The genlist object
4769  * @param n   Maximum number of items within an item block
4770  *
4771  * @ingroup Genlist
4772  */
4773 EAPI void
4774 elm_genlist_block_count_set(Evas_Object *obj,
4775                             int          n)
4776 {
4777    ELM_CHECK_WIDTYPE(obj, widtype);
4778    Widget_Data *wd = elm_widget_data_get(obj);
4779    if (!wd) return;
4780    wd->max_items_per_block = n;
4781    wd->item_cache_max = wd->max_items_per_block * 2;
4782    _item_cache_clean(wd);
4783 }
4784
4785 /**
4786  * Get the maximum number of items within an item block
4787  *
4788  * @param obj The genlist object
4789  * @return Maximum number of items within an item block
4790  *
4791  * @ingroup Genlist
4792  */
4793 EAPI int
4794 elm_genlist_block_count_get(const Evas_Object *obj)
4795 {
4796    ELM_CHECK_WIDTYPE(obj, widtype) 0;
4797    Widget_Data *wd = elm_widget_data_get(obj);
4798    if (!wd) return 0;
4799    return wd->max_items_per_block;
4800 }
4801
4802 /**
4803  * Set the timeout in seconds for the longpress event
4804  *
4805  * @param obj The genlist object
4806  * @param timeout timeout in seconds
4807  *
4808  * @ingroup Genlist
4809  */
4810 EAPI void
4811 elm_genlist_longpress_timeout_set(Evas_Object *obj,
4812                                   double       timeout)
4813 {
4814    ELM_CHECK_WIDTYPE(obj, widtype);
4815    Widget_Data *wd = elm_widget_data_get(obj);
4816    if (!wd) return;
4817    wd->longpress_timeout = timeout;
4818 }
4819
4820 /**
4821  * Get the timeout in seconds for the longpress event
4822  *
4823  * @param obj The genlist object
4824  * @return timeout in seconds
4825  *
4826  * @ingroup Genlist
4827  */
4828 EAPI double
4829 elm_genlist_longpress_timeout_get(const Evas_Object *obj)
4830 {
4831    ELM_CHECK_WIDTYPE(obj, widtype) 0;
4832    Widget_Data *wd = elm_widget_data_get(obj);
4833    if (!wd) return 0;
4834    return wd->longpress_timeout;
4835 }
4836
4837 /**
4838  * Set the scrollbar policy
4839  *
4840  * This sets the scrollbar visibility policy for the given genlist
4841  * scroller. ELM_SMART_SCROLLER_POLICY_AUTO means the scrollbar is
4842  * made visible if it is needed, and otherwise kept hidden.
4843  * ELM_SMART_SCROLLER_POLICY_ON turns it on all the time, and
4844  * ELM_SMART_SCROLLER_POLICY_OFF always keeps it off. This applies
4845  * respectively for the horizontal and vertical scrollbars.
4846  *
4847  * @param obj The genlist object
4848  * @param policy_h Horizontal scrollbar policy
4849  * @param policy_v Vertical scrollbar policy
4850  *
4851  * @ingroup Genlist
4852  */
4853 EAPI void
4854 elm_genlist_scroller_policy_set(Evas_Object        *obj,
4855                                 Elm_Scroller_Policy policy_h,
4856                                 Elm_Scroller_Policy policy_v)
4857 {
4858    ELM_CHECK_WIDTYPE(obj, widtype);
4859    Widget_Data *wd = elm_widget_data_get(obj);
4860    if (!wd) return;
4861    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
4862        (policy_v >= ELM_SCROLLER_POLICY_LAST))
4863      return;
4864    if (wd->scr)
4865      elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
4866 }
4867
4868 /**
4869  * Get the scrollbar policy
4870  *
4871  * @param obj The genlist object
4872  * @param policy_h Horizontal scrollbar policy
4873  * @param policy_v Vertical scrollbar policy
4874  *
4875  * @ingroup Genlist
4876  */
4877 EAPI void
4878 elm_genlist_scroller_policy_get(const Evas_Object   *obj,
4879                                 Elm_Scroller_Policy *policy_h,
4880                                 Elm_Scroller_Policy *policy_v)
4881 {
4882    ELM_CHECK_WIDTYPE(obj, widtype);
4883    Widget_Data *wd = elm_widget_data_get(obj);
4884    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
4885    if ((!wd) || (!wd->scr)) return;
4886    elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
4887    if (policy_h) *policy_h = (Elm_Scroller_Policy)s_policy_h;
4888    if (policy_v) *policy_v = (Elm_Scroller_Policy)s_policy_v;
4889 }