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