Merge "[elm_genlist.c] change edit mode logic and depricate unnecessary api"
[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 typedef struct _Edit_Data Edit_Data;
290
291 typedef enum _Elm_Genlist_Item_Move_effect_Mode
292 {
293    ELM_GENLIST_ITEM_MOVE_EFFECT_NONE         = 0,
294    ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND       = (1 << 0),
295    ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT     = (1 << 1),
296    ELM_GENLIST_ITEM_MOVE_EFFECT_EDIT_MODE    = (1 << 2),
297    ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE       = (1 << 3),
298 } Elm_Genlist_Item_Move_effect_Mode;
299
300 struct _Widget_Data
301 {
302    Evas_Object      *obj, *scr, *pan_smart;
303    Eina_Inlist      *items, *blocks;
304    Eina_List        *group_items;
305    Pan              *pan;
306    Evas_Coord        pan_x, pan_y, w, h, minw, minh, realminw, prev_viewport_w;
307    Ecore_Job        *calc_job, *update_job;
308    Ecore_Idler      *queue_idler;
309    Ecore_Idler      *must_recalc_idler;
310    Eina_List        *queue, *selected;
311    Elm_Genlist_Item *show_item;
312    Elm_Genlist_Item *last_selected_item;
313    Eina_Inlist      *item_cache;
314    Elm_Genlist_Item *anchor_item;
315    Evas_Coord        anchor_y;
316    Elm_List_Mode     mode;
317    Ecore_Timer      *multi_timer;
318    Evas_Coord        prev_x, prev_y, prev_mx, prev_my;
319    Evas_Coord        cur_x, cur_y, cur_mx, cur_my;
320    Eina_Bool         mouse_down : 1;
321    Eina_Bool         multi_down : 1;
322    Eina_Bool         multi_timeout : 1;
323    Eina_Bool         multitouched : 1;
324    Eina_Bool         on_hold : 1;
325    Eina_Bool         multi : 1;
326    Eina_Bool         always_select : 1;
327    Eina_Bool         longpressed : 1;
328    Eina_Bool         wasselected : 1;
329    Eina_Bool         no_select : 1;
330    Eina_Bool         bring_in : 1;
331    Eina_Bool         compress : 1;
332    Eina_Bool         height_for_width : 1;
333    Eina_Bool         homogeneous : 1;
334    Eina_Bool         clear_me : 1;
335    Eina_Bool         swipe : 1;
336    struct
337    {
338       Evas_Coord x, y;
339    } history[SWIPE_MOVES];
340    int               multi_device;
341    int               item_cache_count;
342    int               item_cache_max;
343    int               movements;
344    int               walking;
345    int               item_width;
346    int               item_height;
347    int               group_item_width;
348    int               group_item_height;
349    int               max_items_per_block;
350    double            longpress_timeout;
351
352    // TODO : refactoring
353    Eina_Bool         reorder_mode : 1;
354    Eina_Bool         reorder_pan_move : 1;
355    Eina_Bool         reorder_deleted : 1;
356    Eina_Bool         effect_mode : 1;
357    Eina_Bool         auto_scrolled : 1;
358    Eina_Bool         contracting : 1;
359    int               edit_mode;
360    Eina_List        *sweeped_items;
361    Ecore_Timer      *scr_hold_timer;
362    int               total_num;
363    Elm_Genlist_Item *reorder_it, *reorder_rel;
364    Evas_Coord        reorder_start_y;
365    Ecore_Animator   *item_moving_effect_timer;
366    Evas_Object      *alpha_bg;
367    Elm_Genlist_Item *expand_item;
368    Evas_Coord        expand_item_end;
369    Evas_Coord        expand_item_gap;
370    int               move_effect_mode;
371    unsigned int      start_time;
372    Ecore_Job        *changed_job;
373 };
374
375 struct _Item_Block
376 {
377    EINA_INLIST;
378    int          count;
379    int          num;
380    Widget_Data *wd;
381    Eina_List   *items;
382    Evas_Coord   x, y, w, h, minw, minh;
383    Eina_Bool    want_unrealize : 1;
384    Eina_Bool    realized : 1;
385    Eina_Bool    changed : 1;
386    Eina_Bool    updateme : 1;
387    Eina_Bool    showme : 1;
388    Eina_Bool    must_recalc : 1;
389    int          reorder_offset;
390 };
391
392 struct _Elm_Genlist_Item
393 {
394    Elm_Widget_Item               base;
395    EINA_INLIST;
396    Widget_Data                  *wd;
397    Item_Block                   *block;
398    Eina_List                    *items;
399    Evas_Coord                    x, y, w, h, minw, minh;
400    const Elm_Genlist_Item_Class *itc;
401    Elm_Genlist_Item             *parent;
402    Elm_Genlist_Item             *group_item;
403    Elm_Genlist_Item_Flags        flags;
404    struct
405    {
406       Evas_Smart_Cb func;
407       const void   *data;
408    } func;
409
410    Evas_Object      *spacer;
411    Eina_List        *labels, *icons, *states, *icon_objs;
412    Ecore_Timer      *long_timer;
413    Ecore_Timer      *swipe_timer;
414    Evas_Coord        dx, dy;
415    Evas_Coord        scrl_x, scrl_y;
416
417    Elm_Genlist_Item *rel;
418
419    struct
420    {
421       const void                 *data;
422       Elm_Tooltip_Item_Content_Cb content_cb;
423       Evas_Smart_Cb               del_cb;
424       const char                 *style;
425    } tooltip;
426
427    const char *mouse_cursor;
428
429    int         relcount;
430    int         walking;
431    int         expanded_depth;
432    int         order_num_in;
433
434    Eina_Bool   before : 1;
435
436    Eina_Bool   want_unrealize : 1;
437    Eina_Bool   want_realize : 1;
438    Eina_Bool   realized : 1;
439    Eina_Bool   selected : 1;
440    Eina_Bool   highlighted : 1;
441    Eina_Bool   expanded : 1;
442    Eina_Bool   disabled : 1;
443    Eina_Bool   display_only : 1;
444    Eina_Bool   mincalcd : 1;
445    Eina_Bool   queued : 1;
446    Eina_Bool   showme : 1;
447    Eina_Bool   delete_me : 1;
448    Eina_Bool   down : 1;
449    Eina_Bool   dragging : 1;
450    Eina_Bool   updateme : 1;
451    Eina_Bool   nocache : 1;
452
453    // TODO: refactoring
454    Eina_Bool   move_effect_me : 1;
455    Eina_Bool   effect_done : 1;
456    Eina_Bool   reordering : 1;
457    Eina_Bool   renamed : 1;
458    Eina_Bool   effect_item_realized : 1;
459    Eina_Bool   sweeped : 1;
460    Eina_Bool   wassweeped : 1;
461    Eina_List  *edit_icon_objs;
462    Evas_Object *edit_obj;
463    Eina_List  *sweep_labels, *sweep_icons, *sweep_icon_objs;
464    int         num;
465    Ecore_Animator *item_moving_effect_timer;
466    Evas_Coord  old_scrl_x, old_scrl_y;
467 };
468
469 struct _Item_Cache
470 {
471    EINA_INLIST;
472
473    Evas_Object *base_view, *spacer;
474
475    const char  *item_style; // it->itc->item_style
476    Eina_Bool    tree : 1; // it->flags & ELM_GENLIST_ITEM_SUBITEMS
477    Eina_Bool    compress : 1; // it->wd->compress
478    Eina_Bool    odd : 1; // in & 0x1
479
480    Eina_Bool    selected : 1; // it->selected
481    Eina_Bool    disabled : 1; // it->disabled
482    Eina_Bool    expanded : 1; // it->expanded
483 };
484
485 #define ELM_GENLIST_ITEM_FROM_INLIST(item) \
486   ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Genlist_Item) : NULL)
487
488 struct _Pan
489 {
490    Evas_Object_Smart_Clipped_Data __clipped_data;
491    Widget_Data                   *wd;
492    Ecore_Job                     *resize_job;
493 };
494
495 static const char *widtype = NULL;
496 static void      _item_cache_zero(Widget_Data *wd);
497 static void      _del_hook(Evas_Object *obj);
498 static void      _mirrored_set(Evas_Object *obj,
499                                Eina_Bool    rtl);
500 static void      _theme_hook(Evas_Object *obj);
501 static void      _show_region_hook(void        *data,
502                                    Evas_Object *obj);
503 static void      _sizing_eval(Evas_Object *obj);
504 static void      _item_unrealize(Elm_Genlist_Item *it);
505 static void      _item_block_unrealize(Item_Block *itb);
506 static void      _calc_job(void *data);
507 static void      _on_focus_hook(void        *data,
508                                 Evas_Object *obj);
509 static void      _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
510 static void      _changed_job(void *data);
511 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
512 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
513 static Eina_Bool _item_single_select_up(Widget_Data *wd);
514 static Eina_Bool _item_single_select_down(Widget_Data *wd);
515 static Eina_Bool _event_hook(Evas_Object       *obj,
516                              Evas_Object       *src,
517                              Evas_Callback_Type type,
518                              void              *event_info);
519 static Eina_Bool _deselect_all_items(Widget_Data *wd);
520 static void      _pan_calculate(Evas_Object *obj);
521 // TODO : refactoring
522 static Evas_Object* _create_tray_alpha_bg(const Evas_Object *obj);
523 static unsigned int current_time_get();
524 static Eina_Bool _item_moving_effect_timer_cb(void *data);
525 static int _item_flip_effect_show(Elm_Genlist_Item *it);
526 static void _effect_item_controls(Elm_Genlist_Item *it, int itx, int ity);
527 static void _effect_item_realize(Elm_Genlist_Item *it, Eina_Bool effect_on);
528 static void _effect_item_unrealize(Elm_Genlist_Item *it);
529 static void _item_slide(Elm_Genlist_Item *it, Eina_Bool slide_to_right);
530 static void _sweep_finish(void *data, Evas_Object *o, const char *emission, const char *source);
531 static void _create_sweep_objs(Elm_Genlist_Item *it);
532 static void _delete_sweep_objs(Elm_Genlist_Item *it);
533 static void _effect_item_move_after(Elm_Genlist_Item *it, Elm_Genlist_Item *after);
534 static void _effect_item_move_before(Elm_Genlist_Item *it, Elm_Genlist_Item *before);
535 static void _group_items_recalc(void *data);
536 static void _item_auto_scroll(void *data);
537
538 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
539
540 static Eina_Bool
541 _event_hook(Evas_Object       *obj,
542             Evas_Object *src   __UNUSED__,
543             Evas_Callback_Type type,
544             void              *event_info)
545 {
546    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
547    Evas_Event_Key_Down *ev = event_info;
548    Widget_Data *wd = elm_widget_data_get(obj);
549    if (!wd) return EINA_FALSE;
550    if (!wd->items) return EINA_FALSE;
551    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
552    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
553
554    Elm_Genlist_Item *it = NULL;
555    Evas_Coord x = 0;
556    Evas_Coord y = 0;
557    Evas_Coord step_x = 0;
558    Evas_Coord step_y = 0;
559    Evas_Coord v_w = 0;
560    Evas_Coord v_h = 0;
561    Evas_Coord page_x = 0;
562    Evas_Coord page_y = 0;
563
564    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
565    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
566    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
567    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
568
569    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
570      {
571         x -= step_x;
572      }
573    else if ((!strcmp(ev->keyname, "Right")) ||
574             (!strcmp(ev->keyname, "KP_Right")))
575      {
576         x += step_x;
577      }
578    else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
579      {
580         if (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
581              (_item_multi_select_up(wd)))
582             || (_item_single_select_up(wd)))
583           {
584              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
585              return EINA_TRUE;
586           }
587         else
588           y -= step_y;
589      }
590    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
591      {
592         if (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
593              (_item_multi_select_down(wd)))
594             || (_item_single_select_down(wd)))
595           {
596              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
597              return EINA_TRUE;
598           }
599         else
600           y += step_y;
601      }
602    else if ((!strcmp(ev->keyname, "Home")) ||
603             (!strcmp(ev->keyname, "KP_Home")))
604      {
605         it = elm_genlist_first_item_get(obj);
606         elm_genlist_item_bring_in(it);
607         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
608         return EINA_TRUE;
609      }
610    else if ((!strcmp(ev->keyname, "End")) ||
611             (!strcmp(ev->keyname, "KP_End")))
612      {
613         it = elm_genlist_last_item_get(obj);
614         elm_genlist_item_bring_in(it);
615         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
616         return EINA_TRUE;
617      }
618    else if ((!strcmp(ev->keyname, "Prior")) ||
619             (!strcmp(ev->keyname, "KP_Prior")))
620      {
621         if (page_y < 0)
622           y -= -(page_y * v_h) / 100;
623         else
624           y -= page_y;
625      }
626    else if ((!strcmp(ev->keyname, "Next")) ||
627             (!strcmp(ev->keyname, "KP_Next")))
628      {
629         if (page_y < 0)
630           y += -(page_y * v_h) / 100;
631         else
632           y += page_y;
633      }
634    else if(((!strcmp(ev->keyname, "Return")) ||
635             (!strcmp(ev->keyname, "KP_Enter")) ||
636             (!strcmp(ev->keyname, "space")))
637            && (!wd->multi) && (wd->selected))
638      {
639         Elm_Genlist_Item *it = elm_genlist_selected_item_get(obj);
640         elm_genlist_item_expanded_set(it,
641                                       !elm_genlist_item_expanded_get(it));
642      }
643    else if (!strcmp(ev->keyname, "Escape"))
644      {
645         if (!_deselect_all_items(wd)) return EINA_FALSE;
646         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
647         return EINA_TRUE;
648      }
649    else return EINA_FALSE;
650
651    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
652    elm_smart_scroller_child_pos_set(wd->scr, x, y);
653    return EINA_TRUE;
654 }
655
656 static Eina_Bool
657 _deselect_all_items(Widget_Data *wd)
658 {
659    if (!wd->selected) return EINA_FALSE;
660    while(wd->selected)
661      elm_genlist_item_selected_set(wd->selected->data, EINA_FALSE);
662
663    return EINA_TRUE;
664 }
665
666 static Eina_Bool
667 _item_multi_select_up(Widget_Data *wd)
668 {
669    if (!wd->selected) return EINA_FALSE;
670    if (!wd->multi) return EINA_FALSE;
671
672    Elm_Genlist_Item *prev = elm_genlist_item_prev_get(wd->last_selected_item);
673    if (!prev) return EINA_TRUE;
674
675    if (elm_genlist_item_selected_get(prev))
676      {
677         elm_genlist_item_selected_set(wd->last_selected_item, EINA_FALSE);
678         wd->last_selected_item = prev;
679         elm_genlist_item_show(wd->last_selected_item);
680      }
681    else
682      {
683         elm_genlist_item_selected_set(prev, EINA_TRUE);
684         elm_genlist_item_show(prev);
685      }
686    return EINA_TRUE;
687 }
688
689 static Eina_Bool
690 _item_multi_select_down(Widget_Data *wd)
691 {
692    if (!wd->selected) return EINA_FALSE;
693    if (!wd->multi) return EINA_FALSE;
694
695    Elm_Genlist_Item *next = elm_genlist_item_next_get(wd->last_selected_item);
696    if (!next) return EINA_TRUE;
697
698    if (elm_genlist_item_selected_get(next))
699      {
700         elm_genlist_item_selected_set(wd->last_selected_item, EINA_FALSE);
701         wd->last_selected_item = next;
702         elm_genlist_item_show(wd->last_selected_item);
703      }
704    else
705      {
706         elm_genlist_item_selected_set(next, EINA_TRUE);
707         elm_genlist_item_show(next);
708      }
709    return EINA_TRUE;
710 }
711
712 static Eina_Bool
713 _item_single_select_up(Widget_Data *wd)
714 {
715    Elm_Genlist_Item *prev;
716    if (!wd->selected)
717      {
718         prev = ELM_GENLIST_ITEM_FROM_INLIST(wd->items->last);
719         while ((prev) && (prev->delete_me))
720           prev = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
721      }
722    else prev = elm_genlist_item_prev_get(wd->last_selected_item);
723
724    if (!prev) return EINA_FALSE;
725
726    _deselect_all_items(wd);
727
728    elm_genlist_item_selected_set(prev, EINA_TRUE);
729    elm_genlist_item_show(prev);
730    return EINA_TRUE;
731 }
732
733 static Eina_Bool
734 _item_single_select_down(Widget_Data *wd)
735 {
736    Elm_Genlist_Item *next;
737    if (!wd->selected)
738      {
739         next = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
740         while ((next) && (next->delete_me))
741           next = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
742      }
743    else next = elm_genlist_item_next_get(wd->last_selected_item);
744
745    if (!next) return EINA_FALSE;
746
747    _deselect_all_items(wd);
748
749    elm_genlist_item_selected_set(next, EINA_TRUE);
750    elm_genlist_item_show(next);
751    return EINA_TRUE;
752 }
753
754 static void
755 _on_focus_hook(void *data   __UNUSED__,
756                Evas_Object *obj)
757 {
758    Widget_Data *wd = elm_widget_data_get(obj);
759    if (!wd) return;
760    if (elm_widget_focus_get(obj))
761      {
762         edje_object_signal_emit(wd->obj, "elm,action,focus", "elm");
763         evas_object_focus_set(wd->obj, EINA_TRUE);
764         if ((wd->selected) && (!wd->last_selected_item))
765           wd->last_selected_item = eina_list_data_get(wd->selected);
766      }
767    else
768      {
769         edje_object_signal_emit(wd->obj, "elm,action,unfocus", "elm");
770         evas_object_focus_set(wd->obj, EINA_FALSE);
771      }
772 }
773
774 static void
775 _del_hook(Evas_Object *obj)
776 {
777    Widget_Data *wd = elm_widget_data_get(obj);
778    if (!wd) return;
779    _item_cache_zero(wd);
780    if (wd->calc_job) ecore_job_del(wd->calc_job);
781    if (wd->update_job) ecore_job_del(wd->update_job);
782    if (wd->changed_job) ecore_job_del(wd->changed_job);
783    if (wd->must_recalc_idler) ecore_idler_del(wd->must_recalc_idler);
784    if (wd->multi_timer) ecore_timer_del(wd->multi_timer);
785    if (wd->scr_hold_timer) ecore_timer_del(wd->scr_hold_timer);
786    free(wd);
787 }
788
789 static void
790 _del_pre_hook(Evas_Object *obj)
791 {
792    Widget_Data *wd = elm_widget_data_get(obj);
793    if (!wd) return;
794    if (wd->edit_mode) elm_genlist_edit_mode_set(wd->obj, EINA_FALSE);
795    evas_object_del(wd->pan_smart);
796    wd->pan_smart = NULL;
797    elm_genlist_clear(obj);
798 }
799
800 static void
801 _mirrored_set(Evas_Object *obj,
802               Eina_Bool    rtl)
803 {
804    Widget_Data *wd = elm_widget_data_get(obj);
805    if (!wd) return;
806    _item_cache_zero(wd);
807    // TODO: uncomment this after upstream merge
808    //elm_smart_scroller_mirrored_set(wd->scr, rtl);
809 }
810
811 static void
812 _theme_hook(Evas_Object *obj)
813 {
814    Widget_Data *wd = elm_widget_data_get(obj);
815    Item_Block *itb;
816    if (!wd) return;
817    _item_cache_zero(wd);
818    // TODO: uncomment this after upstream merge
819    //_elm_widget_mirrored_reload(obj);
820    //_mirrored_set(obj, elm_widget_mirrored_get(obj));
821    elm_smart_scroller_object_theme_set(obj, wd->scr, "genlist", "base",
822                                        elm_widget_style_get(obj));
823 //   edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
824    wd->item_width = wd->item_height = 0;
825    wd->group_item_width = wd->group_item_height = 0;
826    wd->minw = wd->minh = wd->realminw = 0;
827    EINA_INLIST_FOREACH(wd->blocks, itb)
828      {
829         Eina_List *l;
830         Elm_Genlist_Item *it;
831
832         if (itb->realized) _item_block_unrealize(itb);
833         EINA_LIST_FOREACH(itb->items, l, it)
834           it->mincalcd = EINA_FALSE;
835
836         itb->changed = EINA_TRUE;
837      }
838    if (wd->calc_job) ecore_job_del(wd->calc_job);
839    wd->calc_job = ecore_job_add(_calc_job, wd);
840    _sizing_eval(obj);
841 }
842
843 static void
844 _show_region_hook(void        *data,
845                   Evas_Object *obj)
846 {
847    Widget_Data *wd = elm_widget_data_get(data);
848    Evas_Coord x, y, w, h;
849    if (!wd) return;
850    elm_widget_show_region_get(obj, &x, &y, &w, &h);
851    //x & y are screen coordinates, Add with pan coordinates
852    x += wd->pan_x;
853    y += wd->pan_y;
854    if (y > 0) elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
855 }
856
857 static void
858 _sizing_eval(Evas_Object *obj)
859 {
860    Widget_Data *wd = elm_widget_data_get(obj);
861    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
862    if (!wd) return;
863    evas_object_size_hint_min_get(wd->scr, &minw, &minh);
864    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
865    minh = -1;
866    if (wd->height_for_width)
867      {
868         Evas_Coord vw, vh;
869
870         elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
871         if ((vw != 0) && (vw != wd->prev_viewport_w))
872           {
873              Item_Block *itb;
874
875              wd->prev_viewport_w = vw;
876              EINA_INLIST_FOREACH(wd->blocks, itb)
877                {
878                   itb->must_recalc = EINA_TRUE;
879                }
880              if (wd->calc_job) ecore_job_del(wd->calc_job);
881              wd->calc_job = ecore_job_add(_calc_job, wd);
882           }
883      }
884    if (wd->mode == ELM_LIST_LIMIT)
885      {
886         Evas_Coord vmw, vmh, vw, vh;
887
888         minw = wd->realminw;
889         maxw = -1;
890         elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
891         if ((minw > 0) && (vw < minw)) vw = minw;
892         else if ((maxw > 0) && (vw > maxw))
893           vw = maxw;
894         edje_object_size_min_calc
895           (elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
896         minw = vmw + minw;
897      }
898    else
899      {
900         Evas_Coord vmw, vmh;
901
902         edje_object_size_min_calc
903           (elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
904         minw = vmw;
905         minh = vmh;
906      }
907    evas_object_size_hint_min_set(obj, minw, minh);
908    evas_object_size_hint_max_set(obj, maxw, maxh);
909 }
910
911 static void
912 _item_highlight(Elm_Genlist_Item *it)
913 {
914    const char *selectraise;
915    if ((it->wd->no_select) || (it->delete_me) || (it->highlighted) || (it->disabled) || (it->display_only)) return;
916    if ((!it->sweeped) && (!it->wd->edit_mode))
917       edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
918    selectraise = edje_object_data_get(it->base.view, "selectraise");
919    if ((selectraise) && (!strcmp(selectraise, "on")))
920      {
921         if (!it->wd->edit_mode) evas_object_raise(it->base.view);
922         if ((it->group_item) && (it->group_item->realized))
923            evas_object_raise(it->group_item->base.view);
924      }
925    it->highlighted = EINA_TRUE;
926 }
927
928 static void
929 _item_block_del(Elm_Genlist_Item *it)
930 {
931    Eina_Inlist *il;
932    Item_Block *itb = it->block;
933
934    itb->items = eina_list_remove(itb->items, it);
935    itb->count--;
936    itb->changed = EINA_TRUE;
937    if (!it->wd->reorder_deleted)
938      {
939         if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
940         it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
941      }
942    if (itb->count < 1)
943      {
944         il = EINA_INLIST_GET(itb);
945         Item_Block *itbn = (Item_Block *)(il->next);
946         if (it->parent)
947           it->parent->items = eina_list_remove(it->parent->items, it);
948         else
949           it->wd->blocks = eina_inlist_remove(it->wd->blocks, il);
950         free(itb);
951         if (itbn) itbn->changed = EINA_TRUE;
952      }
953    else
954      {
955         if (itb->count < itb->wd->max_items_per_block/2)
956           {
957              il = EINA_INLIST_GET(itb);
958              Item_Block *itbp = (Item_Block *)(il->prev);
959              Item_Block *itbn = (Item_Block *)(il->next);
960              if ((itbp) && ((itbp->count + itb->count) < itb->wd->max_items_per_block + itb->wd->max_items_per_block/2))
961                {
962                   Elm_Genlist_Item *it2;
963
964                   EINA_LIST_FREE(itb->items, it2)
965                     {
966                        it2->block = itbp;
967                        itbp->items = eina_list_append(itbp->items, it2);
968                        itbp->count++;
969                        itbp->changed = EINA_TRUE;
970                     }
971                   it->wd->blocks = eina_inlist_remove(it->wd->blocks,
972                                                       EINA_INLIST_GET(itb));
973                   free(itb);
974                }
975              else if ((itbn) && ((itbn->count + itb->count) < itb->wd->max_items_per_block + itb->wd->max_items_per_block/2))
976                {
977                   while (itb->items)
978                     {
979                        Eina_List *last = eina_list_last(itb->items);
980                        Elm_Genlist_Item *it2 = last->data;
981
982                        it2->block = itbn;
983                        itb->items = eina_list_remove_list(itb->items, last);
984                        itbn->items = eina_list_prepend(itbn->items, it2);
985                        itbn->count++;
986                        itbn->changed = EINA_TRUE;
987                     }
988                   it->wd->blocks =
989                     eina_inlist_remove(it->wd->blocks, EINA_INLIST_GET(itb));
990                   free(itb);
991                }
992           }
993      }
994 }
995
996 static void
997 _item_subitems_clear(Elm_Genlist_Item *it)
998 {
999    if (!it) return;
1000    Eina_List *tl = NULL, *l;
1001    Elm_Genlist_Item *it2;
1002
1003    EINA_LIST_FOREACH(it->items, l, it2)
1004       tl = eina_list_append(tl, it2);
1005
1006    EINA_LIST_FREE(tl, it2)
1007      elm_genlist_item_del(it2);
1008 }
1009
1010 static void
1011 _item_del(Elm_Genlist_Item *it)
1012 {
1013    elm_widget_item_pre_notify_del(it);
1014    elm_genlist_item_subitems_clear(it);
1015    it->wd->walking -= it->walking;
1016    if (it->wd->show_item == it) it->wd->show_item = NULL;
1017    if (it->selected) it->wd->selected = eina_list_remove(it->wd->selected, it);
1018    if (it->realized) _item_unrealize(it);
1019    if (it->effect_item_realized) _effect_item_unrealize(it);
1020    if (it->block) _item_block_del(it);
1021    if ((!it->delete_me) && (it->itc->func.del))
1022      it->itc->func.del((void *)it->base.data, it->base.widget);
1023    it->delete_me = EINA_TRUE;
1024    if (it->queued)
1025      it->wd->queue = eina_list_remove(it->wd->queue, it);
1026 #ifdef ANCHOR_ITEM
1027    if (it->wd->anchor_item == it)
1028      {
1029         it->wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
1030         if (!it->wd->anchor_item)
1031           it->wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
1032      }
1033 #endif
1034    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
1035    if (it->parent)
1036      it->parent->items = eina_list_remove(it->parent->items, it);
1037    if (it->flags & ELM_GENLIST_ITEM_GROUP)
1038      it->wd->group_items = eina_list_remove(it->wd->group_items, it);
1039    if (it->long_timer) ecore_timer_del(it->long_timer);
1040    if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
1041
1042    if (it->tooltip.del_cb)
1043      it->tooltip.del_cb((void *)it->tooltip.data, it->base.widget, it);
1044
1045    elm_widget_item_del(it);
1046    it->wd->total_num--;  // todo : remove
1047 }
1048
1049 static void
1050 _item_select(Elm_Genlist_Item *it)
1051 {
1052    if ((it->wd->no_select) || (it->delete_me)) return;
1053    if (it->selected)
1054      {
1055         if (it->wd->always_select) goto call;
1056         return;
1057      }
1058    it->selected = EINA_TRUE;
1059    it->wd->selected = eina_list_append(it->wd->selected, it);
1060 call:
1061    it->walking++;
1062    it->wd->walking++;
1063    if (it->func.func) it->func.func((void *)it->func.data, it->base.widget, it);
1064    if (!it->delete_me)
1065      evas_object_smart_callback_call(it->base.widget, "selected", it);
1066    it->walking--;
1067    it->wd->walking--;
1068    if ((it->wd->clear_me) && (!it->wd->walking))
1069      {
1070         elm_genlist_clear(it->base.widget);
1071         return;
1072      }
1073    else
1074      {
1075         if ((!it->walking) && (it->delete_me))
1076           {
1077              if (!it->relcount) _item_del(it);
1078           }
1079      }
1080    if (it && it->wd) it->wd->last_selected_item = it;
1081 }
1082
1083 static void
1084 _item_unselect(Elm_Genlist_Item *it)
1085 {
1086    const char *stacking, *selectraise;
1087
1088    if ((it->delete_me) || (!it->highlighted)) return;
1089    if (!it->sweeped)
1090       edje_object_signal_emit(it->base.view, "elm,state,unselected", "elm");
1091    stacking = edje_object_data_get(it->base.view, "stacking");
1092    selectraise = edje_object_data_get(it->base.view, "selectraise");
1093    if ((selectraise) && (!strcmp(selectraise, "on")))
1094      {
1095         if ((stacking) && (!strcmp(stacking, "below")))
1096           evas_object_lower(it->base.view);
1097      }
1098    it->highlighted = EINA_FALSE;
1099    if (it->selected)
1100      {
1101         it->selected = EINA_FALSE;
1102         it->wd->selected = eina_list_remove(it->wd->selected, it);
1103         evas_object_smart_callback_call(it->base.widget, "unselected", it);
1104      }
1105 }
1106
1107 static void
1108 _mouse_move(void        *data,
1109             Evas *evas   __UNUSED__,
1110             Evas_Object *obj,
1111             void        *event_info)
1112 {
1113    Elm_Genlist_Item *it = data;
1114    Evas_Event_Mouse_Move *ev = event_info;
1115    Evas_Coord minw = 0, minh = 0, x, y, dx, dy, adx, ady;
1116
1117    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1118      {
1119         if (!it->wd->on_hold)
1120           {
1121              it->wd->on_hold = EINA_TRUE;
1122              if (!it->wd->wasselected)
1123                _item_unselect(it);
1124           }
1125      }
1126    if (it->wd->multitouched)
1127      {
1128         it->wd->cur_x = ev->cur.canvas.x;
1129         it->wd->cur_y = ev->cur.canvas.y;
1130         return;
1131      }
1132    if ((it->dragging) && (it->down))
1133      {
1134         if (it->wd->movements == SWIPE_MOVES) it->wd->swipe = EINA_TRUE;
1135         else
1136           {
1137              it->wd->history[it->wd->movements].x = ev->cur.canvas.x;
1138              it->wd->history[it->wd->movements].y = ev->cur.canvas.y;
1139              if (abs((it->wd->history[it->wd->movements].x -
1140                       it->wd->history[0].x)) > 40)
1141                it->wd->swipe = EINA_TRUE;
1142              else
1143                it->wd->movements++;
1144           }
1145         if (it->long_timer)
1146           {
1147              ecore_timer_del(it->long_timer);
1148              it->long_timer = NULL;
1149           }
1150         evas_object_smart_callback_call(it->base.widget, "drag", it);
1151         return;
1152      }
1153    if ((!it->down) /* || (it->wd->on_hold)*/ || (it->wd->longpressed))
1154      {
1155         if (it->long_timer)
1156           {
1157              ecore_timer_del(it->long_timer);
1158              it->long_timer = NULL;
1159           }
1160         if (it->wd->reorder_mode && it->wd->reorder_it)
1161           {
1162              Evas_Coord ox,oy,oh,ow;
1163              evas_object_geometry_get(it->wd->pan_smart, &ox, &oy, &ow, &oh);
1164              int it_y = ev->cur.canvas.y - it->wd->reorder_it->dy;
1165              if (!it->wd->reorder_start_y) it->wd->reorder_start_y = it->block->y + it->y;
1166
1167              evas_object_resize(it->base.view, it->w, it->h);
1168              if (it_y < oy) _effect_item_controls(it, it->scrl_x, oy);
1169              else if (it_y + it->wd->reorder_it->h > oy+oh) _effect_item_controls(it, it->scrl_x, oy + oh - it->wd->reorder_it->h);
1170              else _effect_item_controls(it, it->scrl_x, it_y);
1171
1172              if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
1173              it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
1174           }
1175         return;
1176      }
1177    if (!it->display_only)
1178      elm_coords_finger_size_adjust(1, &minw, 1, &minh);
1179    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
1180    x = ev->cur.canvas.x - x;
1181    y = ev->cur.canvas.y - y;
1182    dx = x - it->dx;
1183    adx = dx;
1184    if (adx < 0) adx = -dx;
1185    dy = y - it->dy;
1186    ady = dy;
1187    if (ady < 0) ady = -dy;
1188    minw /= 2;
1189    minh /= 2;
1190    if ((adx > minw) || (ady > minh))
1191      {
1192         it->dragging = EINA_TRUE;
1193         if (it->long_timer)
1194           {
1195              ecore_timer_del(it->long_timer);
1196              it->long_timer = NULL;
1197           }
1198         if (!it->wd->wasselected)
1199           _item_unselect(it);
1200         if (dy < 0)
1201           {
1202              if (ady > adx)
1203                evas_object_smart_callback_call(it->base.widget,
1204                                                "drag,start,up", it);
1205              else
1206                {
1207                   if (dx < 0)
1208                     {
1209                        evas_object_smart_callback_call(it->base.widget,
1210                                                        "drag,start,left", it);
1211                        _item_slide(it, EINA_FALSE);
1212                     }
1213                   else
1214                     {
1215                        evas_object_smart_callback_call(it->base.widget,
1216                                                        "drag,start,right", it);
1217                        _item_slide(it, EINA_TRUE);
1218                     }
1219                }
1220           }
1221         else
1222           {
1223              if (ady > adx)
1224                evas_object_smart_callback_call(it->base.widget,
1225                                                "drag,start,down", it);
1226              else
1227                {
1228                   if (dx < 0)
1229                     {
1230                        evas_object_smart_callback_call(it->base.widget,
1231                                                        "drag,start,left", it);
1232                        _item_slide(it, EINA_FALSE);
1233                     }
1234                   else
1235                     {
1236                        evas_object_smart_callback_call(it->base.widget,
1237                                                        "drag,start,right", it);
1238                        _item_slide(it, EINA_TRUE);
1239                     }
1240                }
1241           }
1242      }
1243 }
1244
1245 static Eina_Bool
1246 _long_press(void *data)
1247 {
1248    Elm_Genlist_Item *it = data;
1249    Elm_Genlist_Item *it_tmp;
1250    static Eina_Bool done = EINA_FALSE;
1251    //static Eina_Bool contracted = EINA_FALSE;
1252    Eina_List *l;
1253    Item_Block *itb;
1254
1255    it->long_timer = NULL;
1256    if ((it->disabled) || (it->dragging) || (it->display_only))
1257      return ECORE_CALLBACK_CANCEL;
1258    it->wd->longpressed = EINA_TRUE;
1259    evas_object_smart_callback_call(it->base.widget, "longpressed", it);
1260    if ((it->wd->reorder_mode) && (it->flags != ELM_GENLIST_ITEM_GROUP))
1261      {
1262         it->wd->reorder_it = it;
1263         it->wd->reorder_start_y = 0;
1264         evas_object_raise(it->edit_obj);
1265         elm_smart_scroller_hold_set(it->wd->scr, EINA_TRUE);
1266         edje_object_signal_emit(it->edit_obj, "elm,action,item,reorder_start", "elm");
1267
1268         EINA_INLIST_FOREACH(it->wd->blocks, itb)
1269           {
1270              if (itb->realized)
1271                {
1272                   done = 1;
1273                   EINA_LIST_FOREACH(itb->items, l, it_tmp)
1274                     {
1275                        if (it_tmp->flags != ELM_GENLIST_ITEM_GROUP && it_tmp->realized)
1276                          {
1277                             _item_unselect(it_tmp);
1278                          }
1279                     }
1280                }
1281              else
1282                {
1283                   if (done) break;
1284                }
1285           }
1286
1287         if (it->items)
1288           {
1289              EINA_LIST_FOREACH(it->items, l, it_tmp)
1290                {
1291                   if (elm_genlist_item_expanded_get(it_tmp))
1292                     {
1293                        elm_genlist_item_expanded_set(it_tmp, EINA_FALSE);
1294                        return ECORE_CALLBACK_RENEW;
1295                     }
1296                }
1297           }
1298         if (elm_genlist_item_expanded_get(it)) {
1299              elm_genlist_item_expanded_set(it, EINA_FALSE);
1300              return ECORE_CALLBACK_RENEW;
1301         }
1302         if (it->wd->edit_field && it->renamed)
1303            elm_genlist_item_rename_mode_set(it, EINA_FALSE);
1304      }
1305
1306    return ECORE_CALLBACK_CANCEL;
1307 }
1308
1309 static void
1310 _swipe(Elm_Genlist_Item *it)
1311 {
1312    int i, sum = 0;
1313
1314    if (!it) return;
1315    if ((it->display_only) || (it->disabled)) return;
1316    it->wd->swipe = EINA_FALSE;
1317    for (i = 0; i < it->wd->movements; i++)
1318      {
1319         sum += it->wd->history[i].x;
1320         if (abs(it->wd->history[0].y - it->wd->history[i].y) > 10) return;
1321      }
1322
1323    sum /= it->wd->movements;
1324    if (abs(sum - it->wd->history[0].x) <= 10) return;
1325    evas_object_smart_callback_call(it->base.widget, "swipe", it);
1326 }
1327
1328 static Eina_Bool
1329 _swipe_cancel(void *data)
1330 {
1331    Elm_Genlist_Item *it = data;
1332
1333    if (!it) return ECORE_CALLBACK_CANCEL;
1334    it->wd->swipe = EINA_FALSE;
1335    it->wd->movements = 0;
1336    return ECORE_CALLBACK_RENEW;
1337 }
1338
1339 static Eina_Bool
1340 _multi_cancel(void *data)
1341 {
1342    Widget_Data *wd = data;
1343
1344    if (!wd) return ECORE_CALLBACK_CANCEL;
1345    wd->multi_timeout = EINA_TRUE;
1346    return ECORE_CALLBACK_RENEW;
1347 }
1348
1349 static void
1350 _multi_touch_gesture_eval(void *data)
1351 {
1352    Elm_Genlist_Item *it = data;
1353
1354    it->wd->multitouched = EINA_FALSE;
1355    if (it->wd->multi_timer)
1356      {
1357         ecore_timer_del(it->wd->multi_timer);
1358         it->wd->multi_timer = NULL;
1359      }
1360    if (it->wd->multi_timeout)
1361      {
1362         it->wd->multi_timeout = EINA_FALSE;
1363         return;
1364      }
1365
1366    Evas_Coord minw = 0, minh = 0;
1367    Evas_Coord off_x, off_y, off_mx, off_my;
1368
1369    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
1370    off_x = abs(it->wd->cur_x - it->wd->prev_x);
1371    off_y = abs(it->wd->cur_y - it->wd->prev_y);
1372    off_mx = abs(it->wd->cur_mx - it->wd->prev_mx);
1373    off_my = abs(it->wd->cur_my - it->wd->prev_my);
1374
1375    if (((off_x > minw) || (off_y > minh)) && ((off_mx > minw) || (off_my > minh)))
1376      {
1377         if ((off_x + off_mx) > (off_y + off_my))
1378           {
1379              if ((it->wd->cur_x > it->wd->prev_x) && (it->wd->cur_mx > it->wd->prev_mx))
1380                evas_object_smart_callback_call(it->base.widget,
1381                                                "multi,swipe,right", it);
1382              else if ((it->wd->cur_x < it->wd->prev_x) && (it->wd->cur_mx < it->wd->prev_mx))
1383                evas_object_smart_callback_call(it->base.widget,
1384                                                "multi,swipe,left", it);
1385              else if (abs(it->wd->cur_x - it->wd->cur_mx) > abs(it->wd->prev_x - it->wd->prev_mx))
1386                evas_object_smart_callback_call(it->base.widget,
1387                                                "multi,pinch,out", it);
1388              else
1389                evas_object_smart_callback_call(it->base.widget,
1390                                                "multi,pinch,in", it);
1391           }
1392         else
1393           {
1394              if ((it->wd->cur_y > it->wd->prev_y) && (it->wd->cur_my > it->wd->prev_my))
1395                evas_object_smart_callback_call(it->base.widget,
1396                                                "multi,swipe,down", it);
1397              else if ((it->wd->cur_y < it->wd->prev_y) && (it->wd->cur_my < it->wd->prev_my))
1398                evas_object_smart_callback_call(it->base.widget,
1399                                                "multi,swipe,up", it);
1400              else if (abs(it->wd->cur_y - it->wd->cur_my) > abs(it->wd->prev_y - it->wd->prev_my))
1401                evas_object_smart_callback_call(it->base.widget,
1402                                                "multi,pinch,out", it);
1403              else
1404                evas_object_smart_callback_call(it->base.widget,
1405                                                "multi,pinch,in", it);
1406           }
1407      }
1408    it->wd->multi_timeout = EINA_FALSE;
1409 }
1410
1411 static void
1412 _multi_down(void            *data,
1413             Evas *evas       __UNUSED__,
1414             Evas_Object *obj __UNUSED__,
1415             void            *event_info)
1416 {
1417    Elm_Genlist_Item *it = data;
1418    Evas_Event_Multi_Down *ev = event_info;
1419
1420    if ((it->wd->multi_device != 0) || (it->wd->multitouched) || (it->wd->multi_timeout)) return;
1421    it->wd->multi_device = ev->device;
1422    it->wd->multi_down = EINA_TRUE;
1423    it->wd->multitouched = EINA_TRUE;
1424    it->wd->prev_mx = ev->canvas.x;
1425    it->wd->prev_my = ev->canvas.y;
1426    if (!it->wd->wasselected) _item_unselect(it);
1427    it->wd->wasselected = EINA_FALSE;
1428    it->wd->longpressed = EINA_FALSE;
1429    if (it->long_timer)
1430      {
1431         ecore_timer_del(it->long_timer);
1432         it->long_timer = NULL;
1433      }
1434    if (it->dragging)
1435      {
1436         it->dragging = EINA_FALSE;
1437         evas_object_smart_callback_call(it->base.widget, "drag,stop", it);
1438      }
1439    if (it->swipe_timer)
1440      {
1441         ecore_timer_del(it->swipe_timer);
1442         it->swipe_timer = NULL;
1443      }
1444    if (it->wd->on_hold)
1445      {
1446         it->wd->swipe = EINA_FALSE;
1447         it->wd->movements = 0;
1448         it->wd->on_hold = EINA_FALSE;
1449      }
1450 }
1451
1452 static void
1453 _multi_up(void            *data,
1454           Evas *evas       __UNUSED__,
1455           Evas_Object *obj __UNUSED__,
1456           void            *event_info)
1457 {
1458    Elm_Genlist_Item *it = data;
1459    Evas_Event_Multi_Up *ev = event_info;
1460
1461    if (it->wd->multi_device != ev->device) return;
1462    it->wd->multi_device = 0;
1463    it->wd->multi_down = EINA_FALSE;
1464    if (it->wd->mouse_down) return;
1465    _multi_touch_gesture_eval(data);
1466 }
1467
1468 static void
1469 _multi_move(void            *data,
1470             Evas *evas       __UNUSED__,
1471             Evas_Object *obj __UNUSED__,
1472             void            *event_info)
1473 {
1474    Elm_Genlist_Item *it = data;
1475    Evas_Event_Multi_Move *ev = event_info;
1476
1477    if (it->wd->multi_device != ev->device) return;
1478    it->wd->cur_mx = ev->cur.canvas.x;
1479    it->wd->cur_my = ev->cur.canvas.y;
1480 }
1481
1482 static void
1483 _mouse_down(void        *data,
1484             Evas *evas   __UNUSED__,
1485             Evas_Object *obj,
1486             void        *event_info)
1487 {
1488    Elm_Genlist_Item *it = data;
1489    Evas_Event_Mouse_Down *ev = event_info;
1490    Evas_Coord x, y;
1491
1492    if (ev->button != 1) return;
1493    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1494      {
1495         it->wd->on_hold = EINA_TRUE;
1496      }
1497
1498    if (it->wd->edit_field && !it->renamed)
1499       elm_genlist_item_rename_mode_set(it, EINA_FALSE);
1500    it->down = EINA_TRUE;
1501    it->dragging = EINA_FALSE;
1502    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
1503    it->dx = ev->canvas.x - x;
1504    it->dy = ev->canvas.y - y;
1505    it->wd->mouse_down = EINA_TRUE;
1506    if (!it->wd->multitouched)
1507      {
1508         it->wd->prev_x = ev->canvas.x;
1509         it->wd->prev_y = ev->canvas.y;
1510         it->wd->multi_timeout = EINA_FALSE;
1511         if (it->wd->multi_timer) ecore_timer_del(it->wd->multi_timer);
1512         it->wd->multi_timer = ecore_timer_add(1, _multi_cancel, it->wd);
1513      }
1514    it->wd->longpressed = EINA_FALSE;
1515    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) it->wd->on_hold = EINA_TRUE;
1516    else it->wd->on_hold = EINA_FALSE;
1517    if (it->wd->on_hold) return;
1518    it->wd->wasselected = it->selected;
1519    _item_highlight(it);
1520    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1521      if ((!it->disabled) && (!it->display_only))
1522        evas_object_smart_callback_call(it->base.widget, "clicked", it);
1523    if (it->long_timer) ecore_timer_del(it->long_timer);
1524    if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
1525    it->swipe_timer = ecore_timer_add(0.4, _swipe_cancel, it);
1526    if (it->realized)
1527      it->long_timer = ecore_timer_add(it->wd->longpress_timeout, _long_press,
1528                                       it);
1529    else
1530      it->long_timer = NULL;
1531    it->wd->swipe = EINA_FALSE;
1532    it->wd->movements = 0;
1533 }
1534
1535 static void
1536 _mouse_up(void            *data,
1537           Evas *evas       __UNUSED__,
1538           Evas_Object *obj __UNUSED__,
1539           void            *event_info)
1540 {
1541    Elm_Genlist_Item *it = data;
1542    Evas_Event_Mouse_Up *ev = event_info;
1543    Eina_Bool dragged = EINA_FALSE;
1544
1545    if (ev->button != 1) return;
1546    it->down = EINA_FALSE;
1547    it->wd->mouse_down = EINA_FALSE;
1548    if (it->wd->multitouched)
1549      {
1550         if (it->wd->multi_down) return;
1551         _multi_touch_gesture_eval(data);
1552         return;
1553      }
1554    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) it->wd->on_hold = EINA_TRUE;
1555    else it->wd->on_hold = EINA_FALSE;
1556    if (it->long_timer)
1557      {
1558         ecore_timer_del(it->long_timer);
1559         it->long_timer = NULL;
1560      }
1561    if (it->dragging)
1562      {
1563         it->dragging = EINA_FALSE;
1564         evas_object_smart_callback_call(it->base.widget, "drag,stop", it);
1565         dragged = 1;
1566      }
1567    if (it->swipe_timer)
1568      {
1569         ecore_timer_del(it->swipe_timer);
1570         it->swipe_timer = NULL;
1571      }
1572    if (it->wd->multi_timer)
1573      {
1574         ecore_timer_del(it->wd->multi_timer);
1575         it->wd->multi_timer = NULL;
1576         it->wd->multi_timeout = EINA_FALSE;
1577      }
1578    if (it->wd->on_hold)
1579      {
1580         if (it->wd->swipe) _swipe(data);
1581         it->wd->longpressed = EINA_FALSE;
1582         it->wd->on_hold = EINA_FALSE;
1583         return;
1584      }
1585    if (it->wd->reorder_mode)
1586      {
1587         Evas_Coord rox, roy, row, roh;
1588         Elm_Genlist_Item *reorder_it = it->wd->reorder_it;
1589         if (reorder_it)
1590           {
1591              Evas_Coord ox,oy,oh,ow;
1592              evas_object_geometry_get(it->wd->pan_smart, &ox, &oy, &ow, &oh);
1593              evas_object_geometry_get(it->wd->reorder_it->base.view, &rox, &roy, &row, &roh);
1594              if (it->wd->reorder_rel)
1595                {
1596                   if (it->wd->reorder_it->parent == it->wd->reorder_rel->parent)  // todo : refactoring
1597                     {
1598                        if (roy + oy <= it->wd->reorder_rel->scrl_y)
1599                           _effect_item_move_before(it->wd->reorder_it, it->wd->reorder_rel);
1600                        else
1601                           _effect_item_move_after(it->wd->reorder_it, it->wd->reorder_rel);
1602                     }
1603                }
1604             it->wd->reorder_deleted = EINA_FALSE;
1605             it->wd->reorder_it = it->wd->reorder_rel = NULL;
1606             elm_smart_scroller_hold_set(it->wd->scr, EINA_FALSE);
1607             edje_object_signal_emit(it->edit_obj, "elm,action,item,reorder_end", "elm");
1608          }
1609       }
1610    if (it->wd->longpressed)
1611      {
1612         it->wd->longpressed = EINA_FALSE;
1613         if (!it->wd->wasselected)
1614           _item_unselect(it);
1615         it->wd->wasselected = EINA_FALSE;
1616         return;
1617      }
1618    if (dragged)
1619      {
1620         if (it->want_unrealize)
1621           {
1622              _item_unrealize(it);
1623              if (it->block->want_unrealize)
1624                _item_block_unrealize(it->block);
1625           }
1626      }
1627    if ((it->disabled) || (dragged) || (it->display_only)) return;
1628    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1629    if (it->wd->multi)
1630      {
1631         if ((!it->selected) && (!it->sweeped))
1632           {
1633              _item_highlight(it);
1634              _item_select(it);
1635           }
1636         else _item_unselect(it);
1637      }
1638    else
1639      {
1640         if (!it->selected)
1641           {
1642              Widget_Data *wd = it->wd;
1643              if (wd)
1644                {
1645                   while (wd->selected) _item_unselect(wd->selected->data);
1646                }
1647           }
1648         else
1649           {
1650              const Eina_List *l, *l_next;
1651              Elm_Genlist_Item *it2;
1652
1653              EINA_LIST_FOREACH_SAFE(it->wd->selected, l, l_next, it2)
1654                if (it2 != it) _item_unselect(it2);
1655              //_item_highlight(it);
1656              //_item_select(it);
1657           }
1658         if (!it->sweeped)
1659           {
1660              _item_highlight(it);
1661              _item_select(it);
1662           }
1663      }
1664 }
1665
1666 static void
1667 _signal_expand_toggle(void                *data,
1668                       Evas_Object *obj     __UNUSED__,
1669                       const char *emission __UNUSED__,
1670                       const char *source   __UNUSED__)
1671 {
1672    Elm_Genlist_Item *it = data;
1673
1674    if (it->expanded)
1675      evas_object_smart_callback_call(it->base.widget, "contract,request", it);
1676    else
1677      evas_object_smart_callback_call(it->base.widget, "expand,request", it);
1678 }
1679
1680 static void
1681 _signal_expand(void                *data,
1682                Evas_Object *obj     __UNUSED__,
1683                const char *emission __UNUSED__,
1684                const char *source   __UNUSED__)
1685 {
1686    Elm_Genlist_Item *it = data;
1687
1688    if (!it->expanded)
1689      evas_object_smart_callback_call(it->base.widget, "expand,request", it);
1690 }
1691
1692 static void
1693 _signal_contract(void                *data,
1694                  Evas_Object *obj     __UNUSED__,
1695                  const char *emission __UNUSED__,
1696                  const char *source   __UNUSED__)
1697 {
1698    Elm_Genlist_Item *it = data;
1699
1700    if (it->expanded)
1701      evas_object_smart_callback_call(it->base.widget, "contract,request", it);
1702 }
1703
1704 static void
1705 _item_cache_clean(Widget_Data *wd)
1706 {
1707    while ((wd->item_cache) && (wd->item_cache_count > wd->item_cache_max))
1708      {
1709         Item_Cache *itc;
1710
1711         itc = EINA_INLIST_CONTAINER_GET(wd->item_cache->last, Item_Cache);
1712         wd->item_cache = eina_inlist_remove(wd->item_cache,
1713                                             wd->item_cache->last);
1714         wd->item_cache_count--;
1715         if (itc->spacer) evas_object_del(itc->spacer);
1716         if (itc->base_view) evas_object_del(itc->base_view);
1717         if (itc->item_style) eina_stringshare_del(itc->item_style);
1718         free(itc);
1719      }
1720 }
1721
1722 static void
1723 _item_cache_zero(Widget_Data *wd)
1724 {
1725    int pmax = wd->item_cache_max;
1726    wd->item_cache_max = 0;
1727    _item_cache_clean(wd);
1728    wd->item_cache_max = pmax;
1729 }
1730
1731 static void
1732 _item_cache_add(Elm_Genlist_Item *it)
1733 {
1734    Item_Cache *itc;
1735
1736    if (it->wd->item_cache_max <= 0)
1737      {
1738         evas_object_del(it->base.view);
1739         it->base.view = NULL;
1740         evas_object_del(it->spacer);
1741         it->spacer = NULL;
1742         return;
1743      }
1744
1745    it->wd->item_cache_count++;
1746    itc = calloc(1, sizeof(Item_Cache));
1747    if (!itc) return;
1748    it->wd->item_cache = eina_inlist_prepend(it->wd->item_cache,
1749                                             EINA_INLIST_GET(itc));
1750    itc->spacer = it->spacer;
1751    it->spacer = NULL;
1752    itc->base_view = it->base.view;
1753    it->base.view = NULL;
1754    evas_object_hide(itc->base_view);
1755    evas_object_move(itc->base_view, -9999, -9999);
1756    itc->item_style = eina_stringshare_add(it->itc->item_style);
1757    if (it->flags & ELM_GENLIST_ITEM_SUBITEMS) itc->tree = 1;
1758    itc->compress = (it->wd->compress);
1759    itc->odd = (it->order_num_in & 0x1);
1760    itc->selected = it->selected;
1761    itc->disabled = it->disabled;
1762    itc->expanded = it->expanded;
1763    if (it->long_timer)
1764      {
1765         ecore_timer_del(it->long_timer);
1766         it->long_timer = NULL;
1767      }
1768    if (it->swipe_timer)
1769      {
1770         ecore_timer_del(it->swipe_timer);
1771         it->swipe_timer = NULL;
1772      }
1773    // FIXME: other callbacks?
1774    edje_object_signal_callback_del_full(itc->base_view,
1775                                         "elm,action,expand,toggle",
1776                                         "elm", _signal_expand_toggle, it);
1777    edje_object_signal_callback_del_full(itc->base_view, "elm,action,expand",
1778                                         "elm",
1779                                         _signal_expand, it);
1780    edje_object_signal_callback_del_full(itc->base_view, "elm,action,contract",
1781                                         "elm", _signal_contract, it);
1782    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MOUSE_DOWN,
1783                                        _mouse_down, it);
1784    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MOUSE_UP,
1785                                        _mouse_up, it);
1786    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MOUSE_MOVE,
1787                                        _mouse_move, it);
1788    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MULTI_DOWN,
1789                                        _multi_down, it);
1790    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MULTI_UP,
1791                                        _multi_up, it);
1792    evas_object_event_callback_del_full(itc->base_view, EVAS_CALLBACK_MULTI_MOVE,
1793                                        _multi_move, it);
1794    _item_cache_clean(it->wd);
1795 }
1796
1797 static Item_Cache *
1798 _item_cache_find(Elm_Genlist_Item *it)
1799 {
1800    Item_Cache *itc;
1801    Eina_Bool tree = 0, odd;
1802
1803    if (it->flags & ELM_GENLIST_ITEM_SUBITEMS) tree = 1;
1804    odd = (it->order_num_in & 0x1);
1805    EINA_INLIST_FOREACH(it->wd->item_cache, itc)
1806      {
1807         if ((itc->selected) || (itc->disabled) || (itc->expanded))
1808           continue;
1809         if ((itc->tree == tree) &&
1810             (itc->odd == odd) &&
1811             (itc->compress == it->wd->compress) &&
1812             (!strcmp(it->itc->item_style, itc->item_style)))
1813           {
1814              it->wd->item_cache = eina_inlist_remove(it->wd->item_cache,
1815                                                      EINA_INLIST_GET(itc));
1816              it->wd->item_cache_count--;
1817              return itc;
1818           }
1819      }
1820    return NULL;
1821 }
1822
1823 static void
1824 _item_cache_free(Item_Cache *itc)
1825 {
1826    if (itc->spacer) evas_object_del(itc->spacer);
1827    if (itc->base_view) evas_object_del(itc->base_view);
1828    if (itc->item_style) eina_stringshare_del(itc->item_style);
1829    free(itc);
1830 }
1831
1832 static void
1833 _item_realize(Elm_Genlist_Item *it,
1834               int               in,
1835               Eina_Bool         calc)
1836 {
1837    Elm_Genlist_Item *it2;
1838    const char *stacking;
1839    const char *treesize;
1840    char buf[1024];
1841    int depth, tsize = 20;
1842    Item_Cache *itc = NULL;
1843
1844    if ((it->realized) || (it->delete_me)) return;
1845    it->order_num_in = in;
1846    if (it->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE) calc = EINA_FALSE;
1847    if (it->nocache)
1848      it->nocache = EINA_FALSE;
1849    else
1850       itc = _item_cache_find(it);
1851    if ((!it->wd->effect_mode) && (itc))
1852      {
1853         it->base.view = itc->base_view;
1854         itc->base_view = NULL;
1855         it->spacer = itc->spacer;
1856         itc->spacer = NULL;
1857      }
1858    else
1859      {
1860         it->base.view = edje_object_add(evas_object_evas_get(it->base.widget));
1861         edje_object_scale_set(it->base.view,
1862                               elm_widget_scale_get(it->base.widget) *
1863                               _elm_config->scale);
1864         evas_object_smart_member_add(it->base.view, it->wd->pan_smart);
1865         elm_widget_sub_object_add(it->base.widget, it->base.view);
1866
1867         if (it->flags & ELM_GENLIST_ITEM_SUBITEMS)
1868           strncpy(buf, "tree", sizeof(buf));
1869         else strncpy(buf, "item", sizeof(buf));
1870         if (it->wd->compress)
1871           strncat(buf, "_compress", sizeof(buf) - strlen(buf));
1872
1873         if (in & 0x1) strncat(buf, "_odd", sizeof(buf) - strlen(buf));
1874         strncat(buf, "/", sizeof(buf) - strlen(buf));
1875         strncat(buf, it->itc->item_style, sizeof(buf) - strlen(buf));
1876
1877         _elm_theme_object_set(it->base.widget, it->base.view, "genlist", buf,
1878                               elm_widget_style_get(it->base.widget));
1879         // TODO: uncomment this after upstream merge
1880         //edje_object_mirrored_set(it->base.view,
1881         //                         elm_widget_mirrored_get(it->base.widget));
1882         it->spacer =
1883           evas_object_rectangle_add(evas_object_evas_get(it->base.widget));
1884         evas_object_color_set(it->spacer, 0, 0, 0, 0);
1885         elm_widget_sub_object_add(it->base.widget, it->spacer);
1886      }
1887    for (it2 = it, depth = 0; it2->parent; it2 = it2->parent)
1888      {
1889         if (it2->parent->flags != ELM_GENLIST_ITEM_GROUP) depth += 1;
1890      }
1891    it->expanded_depth = depth;
1892    treesize = edje_object_data_get(it->base.view, "treesize");
1893    if (treesize) tsize = atoi(treesize);
1894    evas_object_size_hint_min_set(it->spacer,
1895                                  (depth * tsize) * _elm_config->scale, 1);
1896    edje_object_part_swallow(it->base.view, "elm.swallow.pad", it->spacer);
1897    if (!calc)
1898      {
1899         edje_object_signal_callback_add(it->base.view,
1900                                         "elm,action,expand,toggle",
1901                                         "elm", _signal_expand_toggle, it);
1902         edje_object_signal_callback_add(it->base.view, "elm,action,expand",
1903                                         "elm", _signal_expand, it);
1904         edje_object_signal_callback_add(it->base.view, "elm,action,contract",
1905                                         "elm", _signal_contract, it);
1906         stacking = edje_object_data_get(it->base.view, "stacking");
1907         if (stacking)
1908           {
1909              if (!strcmp(stacking, "below")) evas_object_lower(it->base.view);
1910              else if (!strcmp(stacking, "above"))
1911                evas_object_raise(it->base.view);
1912           }
1913         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_DOWN,
1914                                        _mouse_down, it);
1915         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_UP,
1916                                        _mouse_up, it);
1917         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOUSE_MOVE,
1918                                        _mouse_move, it);
1919         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_DOWN,
1920                                        _multi_down, it);
1921         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_UP,
1922                                        _multi_up, it);
1923         evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MULTI_MOVE,
1924                                        _multi_move, it);
1925         if (itc)
1926           {
1927              if (it->selected != itc->selected)
1928                {
1929                   if ((it->selected) && (!it->sweeped) && (!it->wd->edit_mode))
1930                     edje_object_signal_emit(it->base.view,
1931                                             "elm,state,selected", "elm");
1932                }
1933              if (it->disabled != itc->disabled)
1934                {
1935                   if (it->disabled)
1936                     edje_object_signal_emit(it->base.view,
1937                                             "elm,state,disabled", "elm");
1938                }
1939              if (it->expanded != itc->expanded)
1940                {
1941                   if (it->expanded)
1942                     edje_object_signal_emit(it->base.view,
1943                                             "elm,state,expanded", "elm");
1944                }
1945           }
1946         else
1947           {
1948              if ((it->selected) && (!it->sweeped) && (!it->wd->edit_mode))
1949                 edje_object_signal_emit(it->base.view,
1950                                         "elm,state,selected", "elm");
1951              if (it->disabled)
1952                edje_object_signal_emit(it->base.view,
1953                                        "elm,state,disabled", "elm");
1954              if (it->expanded)
1955                edje_object_signal_emit(it->base.view,
1956                                        "elm,state,expanded", "elm");
1957           }
1958      }
1959
1960    if ((calc) && (it->wd->homogeneous) && ((it->wd->item_width) || ((it->wd->item_width) && (it->wd->group_item_width))))
1961      {
1962         /* homogenous genlist shortcut */
1963         if (!it->mincalcd)
1964           {
1965              if (it->flags & ELM_GENLIST_ITEM_GROUP)
1966                {
1967                   it->w = it->minw = it->wd->group_item_width;
1968                   it->h = it->minh = it->wd->group_item_height;
1969                }
1970              else
1971                {
1972                   it->w = it->minw = it->wd->item_width;
1973                   it->h = it->minh = it->wd->item_height;
1974                }
1975              it->mincalcd = EINA_TRUE;
1976           }
1977      }
1978    else
1979      {
1980         if (it->itc->func.label_get)
1981           {
1982              const Eina_List *l;
1983              const char *key;
1984
1985              it->labels =
1986                elm_widget_stringlist_get(edje_object_data_get(it->base.view,
1987                                                               "labels"));
1988              EINA_LIST_FOREACH(it->labels, l, key)
1989                {
1990                   char *s = it->itc->func.label_get
1991                       ((void *)it->base.data, it->base.widget, l->data);
1992
1993                   if (s)
1994                     {
1995                        edje_object_part_text_set(it->base.view, l->data, s);
1996                        free(s);
1997                     }
1998                   else if (itc)
1999                     edje_object_part_text_set(it->base.view, l->data, "");
2000                }
2001           }
2002         if (it->itc->func.icon_get)
2003           {
2004              const Eina_List *l;
2005              const char *key;
2006
2007              it->icons =
2008                elm_widget_stringlist_get(edje_object_data_get(it->base.view,
2009                                                               "icons"));
2010              EINA_LIST_FOREACH(it->icons, l, key)
2011                {
2012                   Evas_Object *ic = it->itc->func.icon_get
2013                       ((void *)it->base.data, it->base.widget, l->data);
2014
2015                   if (ic)
2016                     {
2017                        it->icon_objs = eina_list_append(it->icon_objs, ic);
2018                        edje_object_part_swallow(it->base.view, key, ic);
2019                        evas_object_show(ic);
2020                        elm_widget_sub_object_add(it->base.widget, ic);
2021                        evas_object_event_callback_add(ic, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
2022                     }
2023                }
2024           }
2025         if (it->itc->func.state_get)
2026           {
2027              const Eina_List *l;
2028              const char *key;
2029
2030              it->states =
2031                elm_widget_stringlist_get(edje_object_data_get(it->base.view,
2032                                                               "states"));
2033              EINA_LIST_FOREACH(it->states, l, key)
2034                {
2035                   Eina_Bool on = it->itc->func.state_get
2036                       ((void *)it->base.data, it->base.widget, l->data);
2037
2038                   if (on)
2039                     {
2040                        snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
2041                        edje_object_signal_emit(it->base.view, buf, "elm");
2042                     }
2043                   else if (itc)
2044                     {
2045                        snprintf(buf, sizeof(buf), "elm,state,%s,passive", key);
2046                        edje_object_signal_emit(it->base.view, buf, "elm");
2047                     }
2048                }
2049           }
2050         if (it->sweeped)
2051            _create_sweep_objs(it);
2052         if (!it->mincalcd)
2053           {
2054              Evas_Coord mw = -1, mh = -1;
2055
2056              if (it->wd->height_for_width) mw = it->wd->w;
2057
2058              if (!it->display_only)
2059                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
2060              if (it->wd->height_for_width) mw = it->wd->prev_viewport_w;
2061              edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw,
2062                                                   mh);
2063              if (!it->display_only)
2064                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
2065              it->w = it->minw = mw;
2066              it->h = it->minh = mh;
2067              it->mincalcd = EINA_TRUE;
2068
2069              if ((!it->wd->group_item_width) && (it->flags == ELM_GENLIST_ITEM_GROUP))
2070                {
2071                   it->wd->group_item_width = mw;
2072                   it->wd->group_item_height = mh;
2073                }
2074              else if ((!it->wd->item_width) && (it->flags == ELM_GENLIST_ITEM_NONE))
2075                {
2076                   it->wd->item_width = mw;
2077                   it->wd->item_height = mh;
2078                }
2079           }
2080         if (!calc) evas_object_show(it->base.view);
2081      }
2082
2083    if (it->tooltip.content_cb)
2084      {
2085         elm_widget_item_tooltip_content_cb_set(it,
2086                                                it->tooltip.content_cb,
2087                                                it->tooltip.data, NULL);
2088         elm_widget_item_tooltip_style_set(it, it->tooltip.style);
2089      }
2090
2091    if (it->mouse_cursor)
2092      elm_widget_item_cursor_set(it, it->mouse_cursor);
2093
2094    it->realized = EINA_TRUE;
2095    it->want_unrealize = EINA_FALSE;
2096
2097    if (itc) _item_cache_free(itc);
2098    evas_object_smart_callback_call(it->base.widget, "realized", it);
2099    if ((!calc) && (it->wd->edit_mode) && (it->flags != ELM_GENLIST_ITEM_GROUP))
2100      {
2101         if (it->itc->edit_item_style )
2102           {
2103             _effect_item_realize(it, EINA_FALSE);
2104             edje_object_message_signal_process(it->edit_obj);
2105           }
2106      }
2107 }
2108
2109 static void
2110 _item_unrealize(Elm_Genlist_Item *it)
2111 {
2112    Evas_Object *icon;
2113
2114    if (!it->realized) return;
2115    if (it->wd->reorder_it && it->wd->reorder_it == it) return;
2116    evas_object_smart_callback_call(it->base.widget, "unrealized", it);
2117    if (it->long_timer)
2118      {
2119         ecore_timer_del(it->long_timer);
2120         it->long_timer = NULL;
2121      }
2122    if ((it->sweeped) || (it->wassweeped) || (it->nocache))
2123      {
2124         it->sweeped = EINA_FALSE;
2125         it->wassweeped = EINA_FALSE;
2126         it->wd->sweeped_items = eina_list_remove(it->wd->sweeped_items, it);
2127         _delete_sweep_objs(it);
2128         evas_object_del(it->base.view);
2129         it->base.view = NULL;
2130         evas_object_del(it->spacer);
2131         it->spacer = NULL;
2132      }
2133    else
2134      {
2135         // TODO: uncomment this after upstream merge
2136         //edje_object_mirrored_set(it->base.view, elm_widget_mirrored_get(it->base.widget));
2137         _item_cache_add(it);
2138      }
2139    elm_widget_stringlist_free(it->labels);
2140    it->labels = NULL;
2141    elm_widget_stringlist_free(it->icons);
2142    it->icons = NULL;
2143    elm_widget_stringlist_free(it->states);
2144
2145    EINA_LIST_FREE(it->icon_objs, icon)
2146      evas_object_del(icon);
2147
2148    it->states = NULL;
2149    it->realized = EINA_FALSE;
2150    it->want_unrealize = EINA_FALSE;
2151    if (it->wd->edit_mode) _effect_item_unrealize(it);
2152 }
2153
2154 static Eina_Bool
2155 _item_block_recalc(Item_Block *itb,
2156                    int         in,
2157                    int         qadd,
2158                    int         norender)
2159 {
2160    const Eina_List *l;
2161    Elm_Genlist_Item *it;
2162    Evas_Coord minw = 0, minh = 0;
2163    Eina_Bool showme = EINA_FALSE, changed = EINA_FALSE;
2164    Evas_Coord y = 0;
2165
2166    itb->num = in;
2167    EINA_LIST_FOREACH(itb->items, l, it)
2168      {
2169         if (it->delete_me) continue;
2170         showme |= it->showme;
2171         if (!itb->realized)
2172           {
2173              if (qadd)
2174                {
2175                   if (!it->mincalcd) changed = EINA_TRUE;
2176                   if (changed)
2177                     {
2178                        _item_realize(it, in, EINA_TRUE);
2179                        _item_unrealize(it);
2180                     }
2181                }
2182              else
2183                {
2184                   _item_realize(it, in, EINA_TRUE);
2185                   if (!it->wd->contracting) _item_unrealize(it);
2186                }
2187           }
2188         else
2189           _item_realize(it, in, EINA_FALSE);
2190         minh += it->minh;
2191         if (minw < it->minw) minw = it->minw;
2192         in++;
2193         it->x = 0;
2194         it->y = y;
2195         y += it->h;
2196      }
2197    itb->minw = minw;
2198    itb->minh = minh;
2199    itb->changed = EINA_FALSE;
2200    /* force an evas norender to garbage collect deleted objects */
2201    if (norender) evas_norender(evas_object_evas_get(itb->wd->obj));
2202    return showme;
2203 }
2204
2205 static void
2206 _item_block_realize(Item_Block *itb,
2207                     int         in,
2208                     int         full)
2209 {
2210    const Eina_List *l;
2211    Elm_Genlist_Item *it;
2212
2213    if (itb->realized) return;
2214    EINA_LIST_FOREACH(itb->items, l, it)
2215      {
2216         if (it->delete_me) continue;
2217         if (full) _item_realize(it, in, EINA_FALSE);
2218         in++;
2219      }
2220    itb->realized = EINA_TRUE;
2221    itb->want_unrealize = EINA_FALSE;
2222 }
2223
2224 static void
2225 _item_block_unrealize(Item_Block *itb)
2226 {
2227    const Eina_List *l;
2228    Elm_Genlist_Item *it;
2229    Eina_Bool dragging = EINA_FALSE;
2230
2231    if (!itb->realized) return;
2232    EINA_LIST_FOREACH(itb->items, l, it)
2233      {
2234         if (it->flags != ELM_GENLIST_ITEM_GROUP)
2235           {
2236              if (it->dragging)
2237                {
2238                   dragging = EINA_TRUE;
2239                   it->want_unrealize = EINA_TRUE;
2240                }
2241              else
2242                 if (!it->wd->contracting) _item_unrealize(it);
2243           }
2244      }
2245    if (!dragging)
2246      {
2247         itb->realized = EINA_FALSE;
2248         itb->want_unrealize = EINA_TRUE;
2249      }
2250    else
2251      itb->want_unrealize = EINA_FALSE;
2252 }
2253
2254 static int
2255 _get_space_for_reorder_item(Elm_Genlist_Item *it)
2256 {
2257    Evas_Coord rox, roy, row, roh;
2258    Eina_Bool top = EINA_FALSE;
2259    Elm_Genlist_Item *reorder_it = it->wd->reorder_it;
2260    if (!reorder_it) return 0;
2261
2262    Evas_Coord   ox,oy,oh,ow;
2263    evas_object_geometry_get(it->wd->pan_smart, &ox, &oy, &ow, &oh);
2264    evas_object_geometry_get(it->wd->reorder_it->base.view, &rox, &roy, &row, &roh);
2265
2266    if ((it->wd->reorder_start_y < it->block->y) && (roy - oy + roh/2 >= it->block->y -  it->wd->pan_y))
2267      {
2268         it->block->reorder_offset = it->wd->reorder_it->h * -1;
2269         if (it->block->count == 1)
2270            it->wd->reorder_rel = it;
2271      }
2272    else if ((it->wd->reorder_start_y >= it->block->y) && (roy - oy + roh/2  <=  it->block->y -  it->wd->pan_y))
2273      {
2274         it->block->reorder_offset = it->wd->reorder_it->h;
2275      }
2276    else
2277      it->block->reorder_offset = 0;
2278
2279    it->scrl_y += it->block->reorder_offset;
2280
2281    top = (ELM_RECTS_INTERSECT(it->scrl_x, it->scrl_y, it->w, it->h,
2282                                             rox, roy+roh/2, row, 1));
2283    if (top)
2284      {
2285         it->wd->reorder_rel = it;
2286         it->scrl_y+=it->wd->reorder_it->h;
2287         return it->wd->reorder_it->h;
2288      }
2289    else
2290      return 0;
2291 }
2292
2293 static Eina_Bool
2294 _reorder_item_moving_effect_timer_cb(void *data)
2295 {
2296    Elm_Genlist_Item *it = data;
2297           Eina_Bool down = EINA_FALSE;
2298    double time = 0.4, t;
2299    int y, dy = 4;
2300    t = ((0.0 > (t = current_time_get() -  it->wd->start_time)) ? 0.0 : t) / 1000;
2301
2302    if (t <= time)
2303       y = (1 * sin((t / time) * (M_PI / 2)) * dy);
2304    else
2305       y = dy;
2306
2307    if (it->old_scrl_y < it->scrl_y)
2308      {
2309         it->old_scrl_y += y;
2310         down = EINA_TRUE;
2311      }
2312    else if (it->old_scrl_y > it->scrl_y)
2313      {
2314         it->old_scrl_y -= y;
2315         down = EINA_FALSE;
2316      }
2317
2318    _effect_item_controls(it,  it->scrl_x, it->old_scrl_y);
2319
2320    _group_items_recalc(it->wd);
2321    if (!it->wd->reorder_it || it->wd->reorder_pan_move)
2322      {
2323         it->old_scrl_y = it->scrl_y;
2324         it->move_effect_me = EINA_FALSE;
2325         it->wd->item_moving_effect_timer = NULL;
2326         return ECORE_CALLBACK_CANCEL;
2327      }
2328    if ((down && it->old_scrl_y >= it->scrl_y) || (!down && it->old_scrl_y <= it->scrl_y))
2329      {
2330         it->old_scrl_y = it->scrl_y;
2331         it->move_effect_me = EINA_FALSE;
2332         it->wd->item_moving_effect_timer = NULL;
2333         return ECORE_CALLBACK_CANCEL;
2334      }
2335    return ECORE_CALLBACK_RENEW;
2336 }
2337
2338 static void
2339 _item_block_position(Item_Block *itb,
2340                      int         in)
2341 {
2342    const Eina_List *l;
2343    Elm_Genlist_Item *it;
2344    Elm_Genlist_Item *git;
2345    Evas_Coord y = 0, ox, oy, ow, oh, cvx, cvy, cvw, cvh;
2346    int vis = 0;
2347
2348    evas_object_geometry_get(itb->wd->pan_smart, &ox, &oy, &ow, &oh);
2349    evas_output_viewport_get(evas_object_evas_get(itb->wd->obj), &cvx, &cvy,
2350                             &cvw, &cvh);
2351
2352    EINA_LIST_FOREACH(itb->items, l, it)
2353      {
2354         if (it->delete_me) continue;
2355         else if (it->wd->reorder_it && it->wd->reorder_it == it) continue;
2356
2357         it->x = 0;
2358         it->y = y;
2359         it->w = itb->w;
2360         it->scrl_x = itb->x + it->x - it->wd->pan_x + ox;
2361         it->scrl_y = itb->y + it->y - it->wd->pan_y + oy;
2362
2363         vis = (ELM_RECTS_INTERSECT(it->scrl_x, it->scrl_y, it->w, it->h,
2364                                    cvx, cvy, cvw, cvh));
2365         if (it->flags != ELM_GENLIST_ITEM_GROUP || (it->wd->reorder_it ))
2366           {
2367              if ((itb->realized) && (!it->realized))
2368                {
2369                   if (vis)
2370                     {
2371                        _item_realize(it, in, 0);
2372                        if (it->renamed)
2373                          {
2374                             if (it->wd->edit_mode) edje_object_signal_emit(it->edit_obj, "elm,state,rename,enabled", "elm");
2375                             edje_object_signal_emit(it->base.view, "elm,state,rename,enabled", "elm");
2376                          }
2377                     }
2378                }
2379              if (it->realized)
2380                {
2381                   if (vis)
2382                     {
2383                        if(it->wd->reorder_mode)
2384                           y += _get_space_for_reorder_item(it);
2385                        git = it->group_item;
2386                        if (git)
2387                          {
2388                             git->scrl_x = it->scrl_x;
2389                             if (git->scrl_y < oy)
2390                                git->scrl_y = oy;
2391                             if ((git->scrl_y + git->h) > (it->scrl_y + it->h))
2392                               git->scrl_y = (it->scrl_y + it->h) - git->h;
2393                             git->want_realize = EINA_TRUE;
2394                          }
2395                        if (it->wd->reorder_it && !it->wd->reorder_pan_move && it->old_scrl_y && it->old_scrl_y != it->scrl_y)
2396                          {
2397                             if (!it->move_effect_me)
2398                               {
2399                                  it->move_effect_me = EINA_TRUE;
2400                                  it->item_moving_effect_timer = ecore_animator_add(_reorder_item_moving_effect_timer_cb, it);
2401                               }
2402
2403                          }
2404                        if (!it->move_effect_me )
2405                             if (!it->wd->effect_mode || it->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_NONE || ((it->wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE) && it->parent == it->wd->expand_item))
2406                             {
2407                               if (it->wd->edit_mode && it->itc->edit_item_style)
2408                                 {
2409                                   _effect_item_controls(it,  it->scrl_x, it->scrl_y);
2410                                 }
2411                               else
2412                                {
2413                                   evas_object_resize(it->base.view, it->w, it->h);
2414                                   evas_object_move(it->base.view, it->scrl_x, it->scrl_y);
2415                                   if((!it->wd->effect_mode || it->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_NONE) || ((it->wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_NONE) && (it->old_scrl_y == it->scrl_y)))
2416                                      evas_object_show(it->base.view);
2417                                   else
2418                                      evas_object_hide(it->base.view);
2419                                }
2420                                it->old_scrl_x = it->scrl_x;
2421                                it->old_scrl_y = it->scrl_y;
2422                             }
2423                     }
2424                   else
2425                     {
2426                        if (!it->dragging) _item_unrealize(it);
2427                     }
2428                }
2429              in++;
2430           }
2431         else
2432           {
2433              if (vis) it->want_realize = EINA_TRUE;
2434           }
2435         y += it->h;
2436      }
2437 }
2438
2439 static void
2440 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2441 {
2442    Elm_Genlist_Item *it = data;
2443    if (!it) return;
2444    it->mincalcd = EINA_FALSE;
2445    it->block->updateme = EINA_TRUE;
2446    if (it->wd->changed_job) ecore_job_del(it->wd->changed_job);
2447    it->wd->changed_job = ecore_job_add(_changed_job, it->wd);
2448 }
2449
2450 static void
2451 _group_items_recalc(void *data)
2452 {
2453    Widget_Data *wd = data;
2454    Eina_List *l;
2455    Elm_Genlist_Item *git;
2456
2457    EINA_LIST_FOREACH(wd->group_items, l, git)
2458      {
2459         if (git->want_realize)
2460           {
2461              if (!git->realized)
2462                _item_realize(git, 0, EINA_FALSE);
2463              evas_object_resize(git->base.view, wd->minw, git->h);
2464              evas_object_move(git->base.view, git->scrl_x, git->scrl_y);
2465              evas_object_show(git->base.view);
2466              evas_object_raise(git->base.view);
2467           }
2468         else if (!git->want_realize && git->realized)
2469           {
2470              if (!git->dragging)
2471                _item_unrealize(git);
2472           }
2473      }
2474 }
2475
2476 static Eina_Bool
2477 _must_recalc_idler(void *data)
2478 {
2479    Widget_Data *wd = data;
2480    if (wd->calc_job) ecore_job_del(wd->calc_job);
2481    wd->calc_job = ecore_job_add(_calc_job, wd);
2482    wd->must_recalc_idler = NULL;
2483    return ECORE_CALLBACK_CANCEL;
2484 }
2485
2486 static void
2487 _calc_job(void *data)
2488 {
2489    Widget_Data *wd = data;
2490    Item_Block *itb;
2491    Evas_Coord minw = -1, minh = 0, y = 0, ow;
2492    Item_Block *chb = NULL;
2493    int in = 0, minw_change = 0;
2494    Eina_Bool changed = EINA_FALSE;
2495    double t0, t;
2496    Eina_Bool did_must_recalc = EINA_FALSE;
2497    if (!wd) return;
2498
2499    t0 = ecore_time_get();
2500    evas_object_geometry_get(wd->pan_smart, NULL, NULL, &ow, &wd->h);
2501    if (wd->w != ow)
2502      {
2503         wd->w = ow;
2504 //        if (wd->height_for_width) changed = EINA_TRUE;
2505      }
2506
2507    EINA_INLIST_FOREACH(wd->blocks, itb)
2508      {
2509         Eina_Bool showme = EINA_FALSE;
2510
2511       itb->num = in;
2512       showme = itb->showme;
2513       itb->showme = EINA_FALSE;
2514       if (chb)
2515         {
2516            if (itb->realized) _item_block_unrealize(itb);
2517         }
2518       if ((itb->changed) || (changed) ||
2519           ((itb->must_recalc) && (!did_must_recalc)))
2520         {
2521            if ((changed) || (itb->must_recalc))
2522              {
2523                 Eina_List *l;
2524                 Elm_Genlist_Item *it;
2525                 EINA_LIST_FOREACH(itb->items, l, it)
2526                   if (it->mincalcd) it->mincalcd = EINA_FALSE;
2527                 itb->changed = EINA_TRUE;
2528                 if (itb->must_recalc) did_must_recalc = EINA_TRUE;
2529                 itb->must_recalc = EINA_FALSE;
2530              }
2531            if (itb->realized) _item_block_unrealize(itb);
2532            showme = _item_block_recalc(itb, in, 0, 1);
2533            chb = itb;
2534         }
2535       itb->y = y;
2536       itb->x = 0;
2537       minh += itb->minh;
2538       if (minw == -1) minw = itb->minw;
2539       else if ((!itb->must_recalc) && (minw < itb->minw))
2540         {
2541            minw = itb->minw;
2542            minw_change = 1;
2543         }
2544       itb->w = minw;
2545       itb->h = itb->minh;
2546       y += itb->h;
2547       in += itb->count;
2548       if ((showme) && (wd->show_item) && (!wd->show_item->queued))
2549         {
2550            wd->show_item->showme = EINA_FALSE;
2551            if (wd->bring_in)
2552              elm_smart_scroller_region_bring_in(wd->scr,
2553                                                 wd->show_item->x +
2554                                                 wd->show_item->block->x,
2555                                                 wd->show_item->y +
2556                                                 wd->show_item->block->y,
2557                                                 wd->show_item->block->w,
2558                                                 wd->show_item->h);
2559            else
2560              elm_smart_scroller_child_region_show(wd->scr,
2561                                                   wd->show_item->x +
2562                                                   wd->show_item->block->x,
2563                                                   wd->show_item->y +
2564                                                   wd->show_item->block->y,
2565                                                   wd->show_item->block->w,
2566                                                   wd->show_item->h);
2567            wd->show_item = NULL;
2568         }
2569    }
2570    if (minw_change)
2571      {
2572         EINA_INLIST_FOREACH(wd->blocks, itb)
2573           {
2574              itb->minw = minw;
2575              itb->w = itb->minw;
2576           }
2577      }
2578    if ((chb) && (EINA_INLIST_GET(chb)->next))
2579      {
2580         EINA_INLIST_FOREACH(EINA_INLIST_GET(chb)->next, itb)
2581           {
2582              if (itb->realized) _item_block_unrealize(itb);
2583           }
2584      }
2585    wd->realminw = minw;
2586    if (minw < wd->w) minw = wd->w;
2587    if ((minw != wd->minw) || (minh != wd->minh))
2588      {
2589         wd->minw = minw;
2590         wd->minh = minh;
2591         if (wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE)
2592            evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2593         _sizing_eval(wd->obj);
2594 #ifdef ANCHOR_ITEM
2595         if ((wd->anchor_item) && (wd->anchor_item->block) && (!wd->auto_scrolled))
2596           {
2597              Elm_Genlist_Item *it;
2598              Evas_Coord it_y;
2599
2600              it = wd->anchor_item;
2601              it_y = wd->anchor_y;
2602              elm_smart_scroller_child_pos_set(wd->scr, wd->pan_x,
2603                                               it->block->y + it->y + it_y);
2604              wd->anchor_item = it;
2605              wd->anchor_y = it_y;
2606           }
2607 #endif
2608      }
2609    t = ecore_time_get();
2610    if (did_must_recalc)
2611      {
2612         if (!wd->must_recalc_idler)
2613           wd->must_recalc_idler = ecore_idler_add(_must_recalc_idler, wd);
2614      }
2615    wd->calc_job = NULL;
2616    evas_object_smart_changed(wd->pan_smart);
2617 }
2618
2619 static void
2620 _update_job(void *data)
2621 {
2622    Widget_Data *wd = data;
2623    Eina_List *l2;
2624    Item_Block *itb;
2625    int num, num0, position = 0, recalc = 0;
2626    if (!wd) return;
2627    wd->update_job = NULL;
2628    num = 0;
2629    EINA_INLIST_FOREACH(wd->blocks, itb)
2630    {
2631       Evas_Coord itminw, itminh;
2632       Elm_Genlist_Item *it;
2633
2634       if (!itb->updateme)
2635         {
2636            num += itb->count;
2637            if (position)
2638              _item_block_position(itb, num);
2639            continue;
2640         }
2641       num0 = num;
2642       recalc = 0;
2643       EINA_LIST_FOREACH(itb->items, l2, it)
2644         {
2645            if (it->updateme)
2646              {
2647                 itminw = it->minw;
2648                 itminh = it->minh;
2649
2650                 it->updateme = EINA_FALSE;
2651                 if (it->realized)
2652                   {
2653                      _item_unrealize(it);
2654                      _item_realize(it, num, 0);
2655                      position = 1;
2656                   }
2657                 else
2658                   {
2659                      _item_realize(it, num, 1);
2660                      _item_unrealize(it);
2661                   }
2662                 if ((it->minw != itminw) || (it->minh != itminh))
2663                   recalc = 1;
2664              }
2665            num++;
2666         }
2667       itb->updateme = EINA_FALSE;
2668       if (recalc)
2669         {
2670            position = 1;
2671            itb->changed = EINA_TRUE;
2672            _item_block_recalc(itb, num0, 0, 1);
2673            _item_block_position(itb, num0);
2674         }
2675    }
2676    if (position)
2677      {
2678         if (wd->calc_job) ecore_job_del(wd->calc_job);
2679         wd->calc_job = ecore_job_add(_calc_job, wd);
2680      }
2681 }
2682
2683 static void
2684 _changed_job(void *data)
2685 {
2686    Widget_Data *wd = data; Eina_List *l2;
2687    Item_Block *itb;
2688    int num, num0, position = 0, recalc = 0;
2689    if (!wd) return;
2690    wd->changed_job = NULL;
2691    num = 0;
2692    EINA_INLIST_FOREACH(wd->blocks, itb)
2693    {
2694       Evas_Coord itminw, itminh;
2695       Elm_Genlist_Item *it;
2696
2697       if (!itb->updateme)
2698         {
2699            num += itb->count;
2700            if (position)
2701              _item_block_position(itb, num);
2702            continue;
2703         }
2704       num0 = num;
2705       recalc = 0;
2706       EINA_LIST_FOREACH(itb->items, l2, it)
2707       {
2708          if (!it->mincalcd)
2709            {
2710               Evas_Coord mw = -1, mh = -1;
2711               itminw = it->w;
2712               itminh = it->h;
2713
2714               if (it->wd->height_for_width) mw = it->wd->w;
2715               if (!it->display_only)
2716                 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
2717               if (it->wd->height_for_width) mw = it->wd->prev_viewport_w;
2718               edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw, mh);
2719               if (!it->display_only)
2720                 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
2721               it->w = it->minw = mw;
2722               it->h = it->minh = mh;
2723               it->mincalcd = EINA_TRUE;
2724
2725               //if ((it->minw != itminw) || (it->minh != itminh))
2726               if ((it->minh != itminh))
2727                 recalc = 1;
2728            }
2729          num++;
2730       }
2731       itb->updateme = EINA_FALSE;
2732       if (recalc)
2733         {
2734            position = 1;
2735            itb->changed = EINA_TRUE;
2736            _item_block_recalc(itb, num0, 0, 1);
2737            _item_block_position(itb, num0);
2738         }
2739    }
2740    if (position)
2741      {
2742         if (wd->calc_job) ecore_job_del(wd->calc_job);
2743         wd->calc_job = ecore_job_add(_calc_job, wd);
2744      }
2745 }
2746
2747 static void
2748 _pan_set(Evas_Object *obj,
2749          Evas_Coord   x,
2750          Evas_Coord   y)
2751 {
2752    Pan *sd = evas_object_smart_data_get(obj);
2753    //Item_Block *itb;
2754
2755 //   Evas_Coord ow, oh;
2756 //   evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2757 //   ow = sd->wd->minw - ow;
2758 //   if (ow < 0) ow = 0;
2759 //   oh = sd->wd->minh - oh;
2760 //   if (oh < 0) oh = 0;
2761 //   if (x < 0) x = 0;
2762 //   if (y < 0) y = 0;
2763 //   if (x > ow) x = ow;
2764 //   if (y > oh) y = oh;
2765    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
2766    sd->wd->pan_x = x;
2767    sd->wd->pan_y = y;
2768
2769 #ifdef ANCHOR_ITEM
2770    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2771    {
2772       if ((itb->y + itb->h) > y)
2773         {
2774            Elm_Genlist_Item *it;
2775            Eina_List *l2;
2776
2777            EINA_LIST_FOREACH(itb->items, l2, it)
2778              {
2779                 if ((itb->y + it->y) >= y)
2780                   {
2781                      sd->wd->anchor_item = it;
2782                      sd->wd->anchor_y = -(itb->y + it->y - y);
2783                      goto done;
2784                   }
2785              }
2786         }
2787    }
2788 done:
2789 #endif
2790    if(!sd->wd->item_moving_effect_timer) evas_object_smart_changed(obj);
2791 }
2792
2793 static void
2794 _pan_get(Evas_Object *obj,
2795          Evas_Coord  *x,
2796          Evas_Coord  *y)
2797 {
2798    Pan *sd = evas_object_smart_data_get(obj);
2799
2800    if (x) *x = sd->wd->pan_x;
2801    if (y) *y = sd->wd->pan_y;
2802 }
2803
2804 static void
2805 _pan_max_get(Evas_Object *obj,
2806              Evas_Coord  *x,
2807              Evas_Coord  *y)
2808 {
2809    Pan *sd = evas_object_smart_data_get(obj);
2810    Evas_Coord ow, oh;
2811
2812    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2813    ow = sd->wd->minw - ow;
2814    if (ow < 0) ow = 0;
2815    oh = sd->wd->minh - oh;
2816    if (oh < 0) oh = 0;
2817    if (x) *x = ow;
2818    if (y) *y = oh;
2819 }
2820
2821 static void
2822 _pan_min_get(Evas_Object *obj __UNUSED__,
2823              Evas_Coord      *x,
2824              Evas_Coord      *y)
2825 {
2826    if (x) *x = 0;
2827    if (y) *y = 0;
2828 }
2829
2830 static void
2831 _pan_child_size_get(Evas_Object *obj,
2832                     Evas_Coord  *w,
2833                     Evas_Coord  *h)
2834 {
2835    Pan *sd = evas_object_smart_data_get(obj);
2836
2837    if (w) *w = sd->wd->minw;
2838    if (h) *h = sd->wd->minh;
2839 }
2840
2841 static void
2842 _pan_add(Evas_Object *obj)
2843 {
2844    Pan *sd;
2845    Evas_Object_Smart_Clipped_Data *cd;
2846
2847    _pan_sc.add(obj);
2848    cd = evas_object_smart_data_get(obj);
2849    sd = ELM_NEW(Pan);
2850    if (!sd) return;
2851    sd->__clipped_data = *cd;
2852    free(cd);
2853    evas_object_smart_data_set(obj, sd);
2854 }
2855
2856 static void
2857 _pan_del(Evas_Object *obj)
2858 {
2859    Pan *sd = evas_object_smart_data_get(obj);
2860
2861    if (!sd) return;
2862    if (sd->resize_job)
2863      {
2864         ecore_job_del(sd->resize_job);
2865         sd->resize_job = NULL;
2866      }
2867    _pan_sc.del(obj);
2868 }
2869
2870 static void
2871 _pan_resize_job(void *data)
2872 {
2873    Pan *sd = data;
2874    _sizing_eval(sd->wd->obj);
2875    sd->resize_job = NULL;
2876 }
2877
2878 static void
2879 _pan_resize(Evas_Object *obj,
2880             Evas_Coord   w,
2881             Evas_Coord   h)
2882 {
2883    Pan *sd = evas_object_smart_data_get(obj);
2884    Evas_Coord ow, oh;
2885
2886    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2887    if ((ow == w) && (oh == h)) return;
2888    if ((sd->wd->height_for_width) && (ow != w))
2889      {
2890         if (sd->resize_job) ecore_job_del(sd->resize_job);
2891         sd->resize_job = ecore_job_add(_pan_resize_job, sd);
2892      }
2893    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2894    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2895 }
2896
2897 static void
2898 _pan_calculate(Evas_Object *obj)
2899 {
2900    Pan *sd = evas_object_smart_data_get(obj);
2901    Item_Block *itb;
2902    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh;
2903    static Evas_Coord old_pan_y = 0;
2904    int in = 0;
2905    Elm_Genlist_Item *git;
2906    Eina_List *l;
2907
2908    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2909    evas_output_viewport_get(evas_object_evas_get(obj), &cvx, &cvy, &cvw, &cvh);
2910    EINA_LIST_FOREACH(sd->wd->group_items, l, git)
2911      {
2912         git->want_realize = EINA_FALSE;
2913      }
2914    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2915    {
2916       itb->w = sd->wd->minw;
2917       if (ELM_RECTS_INTERSECT(itb->x - sd->wd->pan_x + ox,
2918                               itb->y - sd->wd->pan_y + oy,
2919                               itb->w, itb->h,
2920                               cvx, cvy, cvw, cvh))
2921         {
2922            if ((!itb->realized) || (itb->changed))
2923              _item_block_realize(itb, in, 0);
2924            _item_block_position(itb, in);
2925         }
2926       else
2927         {
2928            if (itb->realized) _item_block_unrealize(itb);
2929         }
2930       in += itb->count;
2931    }
2932    if (!sd->wd->reorder_it || sd->wd->reorder_pan_move)
2933       _group_items_recalc(sd->wd);
2934
2935    if (sd->wd->reorder_mode && sd->wd->reorder_it)
2936      {
2937         if (sd->wd->pan_y != old_pan_y) sd->wd->reorder_pan_move = EINA_TRUE;
2938         else sd->wd->reorder_pan_move = EINA_FALSE;
2939         evas_object_raise(sd->wd->reorder_it->edit_obj);
2940         old_pan_y = sd->wd->pan_y;
2941      }
2942
2943       if (sd->wd->effect_mode &&
2944           ((sd->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND) ||
2945            (sd->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT) ||
2946            (sd->wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE)))
2947         {
2948            if (!sd->wd->item_moving_effect_timer)
2949              {
2950                 if (sd->wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE)
2951                    _item_flip_effect_show(sd->wd->expand_item);
2952
2953                 evas_object_raise(sd->wd->alpha_bg);
2954                 evas_object_show(sd->wd->alpha_bg);
2955                 elm_smart_scroller_bounce_animator_disabled_set(sd->wd->scr, EINA_TRUE);
2956                 sd->wd->start_time = current_time_get();
2957                 sd->wd->item_moving_effect_timer = ecore_animator_add(_item_moving_effect_timer_cb, sd->wd);
2958              }
2959         }
2960       else _item_auto_scroll(sd->wd);
2961    sd->wd->contracting = EINA_FALSE;
2962  }
2963
2964 static void
2965 _pan_move(Evas_Object *obj,
2966           Evas_Coord x __UNUSED__,
2967           Evas_Coord y __UNUSED__)
2968 {
2969    Pan *sd = evas_object_smart_data_get(obj);
2970
2971    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2972    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2973 }
2974
2975 static void
2976 _hold_on(void *data       __UNUSED__,
2977          Evas_Object     *obj,
2978          void *event_info __UNUSED__)
2979 {
2980    Widget_Data *wd = elm_widget_data_get(obj);
2981    if (!wd) return;
2982    elm_smart_scroller_hold_set(wd->scr, 1);
2983 }
2984
2985 static void
2986 _hold_off(void *data       __UNUSED__,
2987           Evas_Object     *obj,
2988           void *event_info __UNUSED__)
2989 {
2990    Widget_Data *wd = elm_widget_data_get(obj);
2991    if (!wd) return;
2992    elm_smart_scroller_hold_set(wd->scr, 0);
2993 }
2994
2995 static void
2996 _freeze_on(void *data       __UNUSED__,
2997            Evas_Object     *obj,
2998            void *event_info __UNUSED__)
2999 {
3000    Widget_Data *wd = elm_widget_data_get(obj);
3001    if (!wd) return;
3002    elm_smart_scroller_freeze_set(wd->scr, 1);
3003 }
3004
3005 static void
3006 _freeze_off(void *data       __UNUSED__,
3007             Evas_Object     *obj,
3008             void *event_info __UNUSED__)
3009 {
3010    Widget_Data *wd = elm_widget_data_get(obj);
3011    if (!wd) return;
3012    elm_smart_scroller_freeze_set(wd->scr, 0);
3013 }
3014
3015 static void
3016 _scroll_edge_left(void            *data,
3017                   Evas_Object *scr __UNUSED__,
3018                   void *event_info __UNUSED__)
3019 {
3020    Evas_Object *obj = data;
3021    evas_object_smart_callback_call(obj, "scroll,edge,left", NULL);
3022 }
3023
3024 static void
3025 _scroll_edge_right(void            *data,
3026                    Evas_Object *scr __UNUSED__,
3027                    void *event_info __UNUSED__)
3028 {
3029    Evas_Object *obj = data;
3030    evas_object_smart_callback_call(obj, "scroll,edge,right", NULL);
3031 }
3032
3033 static void
3034 _scroll_edge_top(void            *data,
3035                  Evas_Object *scr __UNUSED__,
3036                  void *event_info __UNUSED__)
3037 {
3038    Evas_Object *obj = data;
3039    evas_object_smart_callback_call(obj, "scroll,edge,top", NULL);
3040 }
3041
3042 static void
3043 _scroll_edge_bottom(void            *data,
3044                     Evas_Object *scr __UNUSED__,
3045                     void *event_info __UNUSED__)
3046 {
3047    Evas_Object *obj = data;
3048    evas_object_smart_callback_call(obj, "scroll,edge,bottom", NULL);
3049 }
3050
3051 /**
3052  * Add a new Genlist object
3053  *
3054  * @param parent The parent object
3055  * @return The new object or NULL if it cannot be created
3056  *
3057  * @ingroup Genlist
3058  */
3059 EAPI Evas_Object *
3060 elm_genlist_add(Evas_Object *parent)
3061 {
3062    Evas_Object *obj;
3063    Evas *e;
3064    Widget_Data *wd;
3065    Evas_Coord minw, minh;
3066    static Evas_Smart *smart = NULL;
3067
3068    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
3069
3070    if (!smart)
3071      {
3072         static Evas_Smart_Class sc;
3073
3074         evas_object_smart_clipped_smart_set(&_pan_sc);
3075         sc = _pan_sc;
3076         sc.name = "elm_genlist_pan";
3077         sc.version = EVAS_SMART_CLASS_VERSION;
3078         sc.add = _pan_add;
3079         sc.del = _pan_del;
3080         sc.resize = _pan_resize;
3081         sc.move = _pan_move;
3082         sc.calculate = _pan_calculate;
3083         if (!(smart = evas_smart_class_new(&sc))) return NULL;
3084      }
3085    wd = ELM_NEW(Widget_Data);
3086    e = evas_object_evas_get(parent);
3087    if (!e) return NULL;
3088    obj = elm_widget_add(e);
3089    ELM_SET_WIDTYPE(widtype, "genlist");
3090    elm_widget_type_set(obj, "genlist");
3091    elm_widget_sub_object_add(parent, obj);
3092    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
3093    elm_widget_data_set(obj, wd);
3094    elm_widget_del_hook_set(obj, _del_hook);
3095    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
3096    elm_widget_theme_hook_set(obj, _theme_hook);
3097    elm_widget_can_focus_set(obj, EINA_TRUE);
3098    elm_widget_event_hook_set(obj, _event_hook);
3099    elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
3100
3101    wd->scr = elm_smart_scroller_add(e);
3102    elm_smart_scroller_widget_set(wd->scr, obj);
3103    elm_smart_scroller_object_theme_set(obj, wd->scr, "genlist", "base",
3104                                        elm_widget_style_get(obj));
3105    elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE,
3106                                        _elm_config->thumbscroll_bounce_enable);
3107    elm_widget_resize_object_set(obj, wd->scr);
3108
3109    evas_object_smart_callback_add(wd->scr, "edge,left", _scroll_edge_left, obj);
3110    evas_object_smart_callback_add(wd->scr, "edge,right", _scroll_edge_right,
3111                                   obj);
3112    evas_object_smart_callback_add(wd->scr, "edge,top", _scroll_edge_top, obj);
3113    evas_object_smart_callback_add(wd->scr, "edge,bottom", _scroll_edge_bottom,
3114                                   obj);
3115
3116    wd->obj = obj;
3117    wd->mode = ELM_LIST_SCROLL;
3118    wd->max_items_per_block = MAX_ITEMS_PER_BLOCK;
3119    wd->item_cache_max = wd->max_items_per_block * 2;
3120    wd->longpress_timeout = _elm_config->longpress_timeout;
3121    //wd->effect_mode = _elm_config->effect_enable;
3122 //   wd->effect_mode = EINA_TRUE;
3123
3124    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
3125    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
3126    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
3127    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
3128
3129    wd->pan_smart = evas_object_smart_add(e, smart);
3130    wd->pan = evas_object_smart_data_get(wd->pan_smart);
3131    wd->pan->wd = wd;
3132
3133    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
3134                                      _pan_set, _pan_get, _pan_max_get,
3135                                      _pan_min_get, _pan_child_size_get);
3136
3137    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
3138                              &minw, &minh);
3139    evas_object_size_hint_min_set(obj, minw, minh);
3140
3141    // TODO: uncomment this after upstream merge
3142    //_mirrored_set(obj, elm_widget_mirrored_get(obj));
3143    _sizing_eval(obj);
3144    return obj;
3145 }
3146
3147 static Elm_Genlist_Item *
3148 _item_new(Widget_Data                  *wd,
3149           const Elm_Genlist_Item_Class *itc,
3150           const void                   *data,
3151           Elm_Genlist_Item             *parent,
3152           Elm_Genlist_Item_Flags        flags,
3153           Evas_Smart_Cb                 func,
3154           const void                   *func_data)
3155 {
3156    Elm_Genlist_Item *it;
3157
3158    it = elm_widget_item_new(wd->obj, Elm_Genlist_Item);
3159    if (!it) return NULL;
3160    it->wd = wd;
3161    it->itc = itc;
3162    it->base.data = data;
3163    it->parent = parent;
3164    it->flags = flags;
3165    it->func.func = func;
3166    it->func.data = func_data;
3167    it->mouse_cursor = NULL;
3168    it->expanded_depth = 0;
3169    it->num = ++wd->total_num;   // todo : remov
3170    return it;
3171 }
3172
3173 static void
3174 _item_block_add(Widget_Data      *wd,
3175                 Elm_Genlist_Item *it)
3176 {
3177    Item_Block *itb = NULL;
3178
3179    if (!it->rel)
3180      {
3181 newblock:
3182         if (it->rel)
3183           {
3184              itb = calloc(1, sizeof(Item_Block));
3185              if (!itb) return;
3186              itb->wd = wd;
3187              if (!it->rel->block)
3188                {
3189                   wd->blocks =
3190                     eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
3191                   itb->items = eina_list_append(itb->items, it);
3192                }
3193              else
3194                {
3195                   if (it->before)
3196                     {
3197                        wd->blocks = eina_inlist_prepend_relative
3198                            (wd->blocks, EINA_INLIST_GET(itb),
3199                            EINA_INLIST_GET(it->rel->block));
3200                        itb->items =
3201                          eina_list_prepend_relative(itb->items, it, it->rel);
3202                     }
3203                   else
3204                     {
3205                        wd->blocks = eina_inlist_append_relative
3206                            (wd->blocks, EINA_INLIST_GET(itb),
3207                            EINA_INLIST_GET(it->rel->block));
3208                        itb->items =
3209                          eina_list_append_relative(itb->items, it, it->rel);
3210                     }
3211                }
3212           }
3213         else
3214           {
3215              if (it->before)
3216                {
3217                   if (wd->blocks)
3218                     {
3219                        itb = (Item_Block *)(wd->blocks);
3220                        if (itb->count >= wd->max_items_per_block)
3221                          {
3222                             itb = calloc(1, sizeof(Item_Block));
3223                             if (!itb) return;
3224                             itb->wd = wd;
3225                             wd->blocks =
3226                               eina_inlist_prepend(wd->blocks,
3227                                                   EINA_INLIST_GET(itb));
3228                          }
3229                     }
3230                   else
3231                     {
3232                        itb = calloc(1, sizeof(Item_Block));
3233                        if (!itb) return;
3234                        itb->wd = wd;
3235                        wd->blocks =
3236                          eina_inlist_prepend(wd->blocks, EINA_INLIST_GET(itb));
3237                     }
3238                   itb->items = eina_list_prepend(itb->items, it);
3239                }
3240              else
3241                {
3242                   if (wd->blocks)
3243                     {
3244                        itb = (Item_Block *)(wd->blocks->last);
3245                        if (itb->count >= wd->max_items_per_block)
3246                          {
3247                             itb = calloc(1, sizeof(Item_Block));
3248                             if (!itb) return;
3249                             itb->wd = wd;
3250                             wd->blocks =
3251                               eina_inlist_append(wd->blocks,
3252                                                  EINA_INLIST_GET(itb));
3253                          }
3254                     }
3255                   else
3256                     {
3257                        itb = calloc(1, sizeof(Item_Block));
3258                        if (!itb) return;
3259                        itb->wd = wd;
3260                        wd->blocks =
3261                          eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
3262                     }
3263                   itb->items = eina_list_append(itb->items, it);
3264                }
3265           }
3266      }
3267    else
3268      {
3269         itb = it->rel->block;
3270         if (!itb) goto newblock;
3271         if (it->before)
3272           itb->items = eina_list_prepend_relative(itb->items, it, it->rel);
3273         else
3274           itb->items = eina_list_append_relative(itb->items, it, it->rel);
3275      }
3276    itb->count++;
3277    itb->changed = EINA_TRUE;
3278    it->block = itb;
3279    if (itb->wd->calc_job) ecore_job_del(itb->wd->calc_job);
3280    itb->wd->calc_job = ecore_job_add(_calc_job, itb->wd);
3281    if (it->rel)
3282      {
3283         it->rel->relcount--;
3284         if ((it->rel->delete_me) && (!it->rel->relcount))
3285           _item_del(it->rel);
3286         it->rel = NULL;
3287      }
3288    if (itb->count > itb->wd->max_items_per_block)
3289      {
3290         int newc;
3291         Item_Block *itb2;
3292         Elm_Genlist_Item *it2;
3293
3294         newc = itb->count / 2;
3295         itb2 = calloc(1, sizeof(Item_Block));
3296         if (!itb2) return;
3297         itb2->wd = wd;
3298         wd->blocks =
3299           eina_inlist_append_relative(wd->blocks, EINA_INLIST_GET(itb2),
3300                                       EINA_INLIST_GET(itb));
3301         itb2->changed = EINA_TRUE;
3302         while ((itb->count > newc) && (itb->items))
3303           {
3304              Eina_List *l;
3305
3306              l = eina_list_last(itb->items);
3307              it2 = l->data;
3308              itb->items = eina_list_remove_list(itb->items, l);
3309              itb->count--;
3310
3311              itb2->items = eina_list_prepend(itb2->items, it2);
3312              it2->block = itb2;
3313              itb2->count++;
3314           }
3315      }
3316 }
3317
3318 static int
3319 _queue_process(Widget_Data *wd,
3320                int          norender)
3321 {
3322    int n;
3323    Eina_Bool showme = EINA_FALSE;
3324    double t0, t;
3325
3326    t0 = ecore_time_get();
3327    for (n = 0; (wd->queue) && (n < 128); n++)
3328      {
3329         Elm_Genlist_Item *it;
3330
3331         it = wd->queue->data;
3332         wd->queue = eina_list_remove_list(wd->queue, wd->queue);
3333         it->queued = EINA_FALSE;
3334         _item_block_add(wd, it);
3335         t = ecore_time_get();
3336         if (it->block->changed)
3337           {
3338              showme = _item_block_recalc(it->block, it->block->num, 1,
3339                                          norender);
3340              it->block->changed = 0;
3341           }
3342         if (showme) it->block->showme = EINA_TRUE;
3343         if (eina_inlist_count(wd->blocks) > 1)
3344           {
3345              if ((t - t0) > (ecore_animator_frametime_get())) break;
3346           }
3347      }
3348    return n;
3349 }
3350
3351 static Eina_Bool
3352 _item_idler(void *data)
3353 {
3354    Widget_Data *wd = data;
3355
3356    //xxx
3357    //static double q_start = 0.0;
3358    //if (q_start == 0.0) q_start = ecore_time_get();
3359    //xxx
3360
3361    if (_queue_process(wd, 1) > 0)
3362      {
3363         if (wd->calc_job) ecore_job_del(wd->calc_job);
3364         wd->calc_job = ecore_job_add(_calc_job, wd);
3365      }
3366    if (!wd->queue)
3367      {
3368         //xxx
3369         //printf("PROCESS TIME: %3.3f\n", ecore_time_get() - q_start);
3370         //xxx
3371         wd->queue_idler = NULL;
3372         return ECORE_CALLBACK_CANCEL;
3373      }
3374    return ECORE_CALLBACK_RENEW;
3375 }
3376
3377 static void
3378 _item_queue(Widget_Data      *wd,
3379             Elm_Genlist_Item *it)
3380 {
3381    if (it->queued) return;
3382    it->queued = EINA_TRUE;
3383    wd->queue = eina_list_append(wd->queue, it);
3384    while ((wd->queue) && ((!wd->blocks) || (!wd->blocks->next)))
3385      {
3386         if (wd->queue_idler)
3387           {
3388              ecore_idler_del(wd->queue_idler);
3389              wd->queue_idler = NULL;
3390           }
3391         _queue_process(wd, 0);
3392      }
3393    if (!wd->queue_idler) wd->queue_idler = ecore_idler_add(_item_idler, wd);
3394 }
3395
3396 /**
3397  * Append item to the end of the genlist
3398  *
3399  * This appends the given item to the end of the list or the end of
3400  * the children if the parent is given.
3401  *
3402  * @param obj The genlist object
3403  * @param itc The item class for the item
3404  * @param data The item data
3405  * @param parent The parent item, or NULL if none
3406  * @param flags Item flags
3407  * @param func Convenience function called when item selected
3408  * @param func_data Data passed to @p func above.
3409  * @return A handle to the item added or NULL if not possible
3410  *
3411  * @ingroup Genlist
3412  */
3413 EAPI Elm_Genlist_Item *
3414 elm_genlist_item_append(Evas_Object                  *obj,
3415                         const Elm_Genlist_Item_Class *itc,
3416                         const void                   *data,
3417                         Elm_Genlist_Item             *parent,
3418                         Elm_Genlist_Item_Flags        flags,
3419                         Evas_Smart_Cb                 func,
3420                         const void                   *func_data)
3421 {
3422    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3423    Widget_Data *wd = elm_widget_data_get(obj);
3424    if (!wd) return NULL;
3425    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3426                                     func_data);
3427    if (!it) return NULL;
3428    if (!it->parent)
3429      {
3430         if (flags & ELM_GENLIST_ITEM_GROUP)
3431           wd->group_items = eina_list_append(wd->group_items, it);
3432         wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
3433         it->rel = NULL;
3434      }
3435    else
3436      {
3437         Elm_Genlist_Item *it2 = NULL;
3438         Eina_List *ll = eina_list_last(it->parent->items);
3439         if (ll) it2 = ll->data;
3440         it->parent->items = eina_list_append(it->parent->items, it);
3441         if (!it2) it2 = it->parent;
3442         if (it2->delete_me)
3443            it2 = elm_genlist_item_prev_get(it2);
3444         wd->items =
3445           eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3446                                       EINA_INLIST_GET(it2));
3447         it->rel = it2;
3448         it->rel->relcount++;
3449
3450         if (it->parent->flags & ELM_GENLIST_ITEM_GROUP)
3451           it->group_item = parent;
3452         else if (it->parent->group_item)
3453           it->group_item = it->parent->group_item;
3454      }
3455    it->before = EINA_FALSE;
3456    _item_queue(wd, it);
3457    return it;
3458 }
3459
3460 /**
3461  * Prepend item at start of the genlist
3462  *
3463  * This adds an item to the beginning of the list or beginning of the
3464  * children of the parent if given.
3465  *
3466  * @param obj The genlist object
3467  * @param itc The item class for the item
3468  * @param data The item data
3469  * @param parent The parent item, or NULL if none
3470  * @param flags Item flags
3471  * @param func Convenience function called when item selected
3472  * @param func_data Data passed to @p func above.
3473  * @return A handle to the item added or NULL if not possible
3474  *
3475  * @ingroup Genlist
3476  */
3477 EAPI Elm_Genlist_Item *
3478 elm_genlist_item_prepend(Evas_Object                  *obj,
3479                          const Elm_Genlist_Item_Class *itc,
3480                          const void                   *data,
3481                          Elm_Genlist_Item             *parent,
3482                          Elm_Genlist_Item_Flags        flags,
3483                          Evas_Smart_Cb                 func,
3484                          const void                   *func_data)
3485 {
3486    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3487    Widget_Data *wd = elm_widget_data_get(obj);
3488    if (!wd) return NULL;
3489    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3490                                     func_data);
3491    if (!it) return NULL;
3492    if (!it->parent)
3493      {
3494         if (flags & ELM_GENLIST_ITEM_GROUP)
3495           wd->group_items = eina_list_prepend(wd->group_items, it);
3496         wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
3497         it->rel = NULL;
3498      }
3499    else
3500      {
3501         Elm_Genlist_Item *it2 = NULL;
3502         Eina_List *ll = it->parent->items;
3503         if (ll) it2 = ll->data;
3504         it->parent->items = eina_list_prepend(it->parent->items, it);
3505         if (!it2) it2 = it->parent;
3506         if (it2->delete_me)
3507            it2 = elm_genlist_item_next_get(it2);
3508         wd->items =
3509           eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3510                                        EINA_INLIST_GET(it2));
3511         it->rel = it2;
3512         it->rel->relcount++;
3513      }
3514    it->before = EINA_TRUE;
3515    _item_queue(wd, it);
3516    return it;
3517 }
3518
3519 /**
3520  * Insert item before another in the genlist
3521  *
3522  * This inserts an item before another in the list. It will be in the
3523  * same tree level or group as the item it is inseted before.
3524  *
3525  * @param obj The genlist object
3526  * @param itc The item class for the item
3527  * @param data The item data
3528  * @param before The item to insert before
3529  * @param flags Item flags
3530  * @param func Convenience function called when item selected
3531  * @param func_data Data passed to @p func above.
3532  * @return A handle to the item added or NULL if not possible
3533  *
3534  * @ingroup Genlist
3535  */
3536 EAPI Elm_Genlist_Item *
3537 elm_genlist_item_insert_before(Evas_Object                  *obj,
3538                                const Elm_Genlist_Item_Class *itc,
3539                                const void                   *data,
3540                                Elm_Genlist_Item             *parent,
3541                                Elm_Genlist_Item             *before,
3542                                Elm_Genlist_Item_Flags        flags,
3543                                Evas_Smart_Cb                 func,
3544                                const void                   *func_data)
3545 {
3546    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3547    EINA_SAFETY_ON_NULL_RETURN_VAL(before, NULL);
3548    Widget_Data *wd = elm_widget_data_get(obj);
3549    if (!wd) return NULL;
3550    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3551                                     func_data);
3552    if (!it) return NULL;
3553    if (it->parent)
3554      {
3555         it->parent->items = eina_list_prepend_relative(it->parent->items, it,
3556                                                        before);
3557      }
3558    wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
3559                                             EINA_INLIST_GET(before));
3560    it->rel = before;
3561    it->rel->relcount++;
3562    it->before = EINA_TRUE;
3563    _item_queue(wd, it);
3564    return it;
3565 }
3566
3567 /**
3568  * Insert an item after another in the genlst
3569  *
3570  * This inserts an item after another in the list. It will be in the
3571  * same tree level or group as the item it is inseted after.
3572  *
3573  * @param obj The genlist object
3574  * @param itc The item class for the item
3575  * @param data The item data
3576  * @param after The item to insert after
3577  * @param flags Item flags
3578  * @param func Convenience function called when item selected
3579  * @param func_data Data passed to @p func above.
3580  * @return A handle to the item added or NULL if not possible
3581  *
3582  * @ingroup Genlist
3583  */
3584 EAPI Elm_Genlist_Item *
3585 elm_genlist_item_insert_after(Evas_Object                  *obj,
3586                               const Elm_Genlist_Item_Class *itc,
3587                               const void                   *data,
3588                               Elm_Genlist_Item             *parent,
3589                               Elm_Genlist_Item             *after,
3590                               Elm_Genlist_Item_Flags        flags,
3591                               Evas_Smart_Cb                 func,
3592                               const void                   *func_data)
3593 {
3594    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3595    EINA_SAFETY_ON_NULL_RETURN_VAL(after, NULL);
3596    Widget_Data *wd = elm_widget_data_get(obj);
3597    if (!wd) return NULL;
3598    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func,
3599                                     func_data);
3600    if (!it) return NULL;
3601    wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
3602                                            EINA_INLIST_GET(after));
3603    if (it->parent)
3604      {
3605         it->parent->items = eina_list_append_relative(it->parent->items, it,
3606                                                       after);
3607      }
3608    it->rel = after;
3609    it->rel->relcount++;
3610    it->before = EINA_FALSE;
3611    _item_queue(wd, it);
3612    return it;
3613 }
3614
3615 /**
3616  * Clear the genlist
3617  *
3618  * This clears all items in the list, leaving it empty.
3619  *
3620  * @param obj The genlist object
3621  *
3622  * @ingroup Genlist
3623  */
3624 EAPI void
3625 elm_genlist_clear(Evas_Object *obj)
3626 {
3627    ELM_CHECK_WIDTYPE(obj, widtype);
3628    Widget_Data *wd = elm_widget_data_get(obj);
3629    if (!wd) return;
3630    if (wd->walking > 0)
3631      {
3632         Elm_Genlist_Item *it;
3633
3634         wd->clear_me = EINA_TRUE;
3635         EINA_INLIST_FOREACH(wd->items, it)
3636           {
3637              it->delete_me = EINA_TRUE;
3638           }
3639         return;
3640      }
3641    while (wd->items)
3642      {
3643         Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3644         it->nocache = EINA_TRUE;
3645         it->highlighted = EINA_FALSE;
3646 #ifdef ANCHOR_ITEM
3647         if (wd->anchor_item == it)
3648           {
3649              wd->anchor_item = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3650              if (!wd->anchor_item)
3651                wd->anchor_item =
3652                  ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3653           }
3654 #endif
3655         wd->items = eina_inlist_remove(wd->items, wd->items);
3656         if (it->flags & ELM_GENLIST_ITEM_GROUP)
3657           it->wd->group_items = eina_list_remove(it->wd->group_items, it);
3658         elm_widget_item_pre_notify_del(it);
3659         if (it->effect_item_realized) _effect_item_unrealize(it);
3660         if (it->realized) _item_unrealize(it);
3661         if (((wd->clear_me) || (!it->delete_me)) && (it->itc->func.del))
3662           it->itc->func.del((void *)it->base.data, it->base.widget);
3663         if (it->long_timer) ecore_timer_del(it->long_timer);
3664         if (it->swipe_timer) ecore_timer_del(it->swipe_timer);
3665         elm_widget_item_del(it);
3666      }
3667    wd->clear_me = EINA_FALSE;
3668    wd->anchor_item = NULL;
3669    while (wd->blocks)
3670      {
3671         Item_Block *itb = (Item_Block *)(wd->blocks);
3672
3673         wd->blocks = eina_inlist_remove(wd->blocks, wd->blocks);
3674         if (itb->items) eina_list_free(itb->items);
3675         free(itb);
3676      }
3677    if (wd->calc_job)
3678      {
3679         ecore_job_del(wd->calc_job);
3680         wd->calc_job = NULL;
3681      }
3682    if (wd->queue_idler)
3683      {
3684         ecore_idler_del(wd->queue_idler);
3685         wd->queue_idler = NULL;
3686      }
3687    if (wd->must_recalc_idler)
3688      {
3689         ecore_idler_del(wd->must_recalc_idler);
3690         wd->must_recalc_idler = NULL;
3691      }
3692    if (wd->queue)
3693      {
3694         eina_list_free(wd->queue);
3695         wd->queue = NULL;
3696      }
3697    if (wd->selected)
3698      {
3699         eina_list_free(wd->selected);
3700         wd->selected = NULL;
3701      }
3702    if (wd->item_moving_effect_timer)
3703      {
3704         ecore_animator_del(wd->item_moving_effect_timer);
3705         wd->item_moving_effect_timer = NULL;
3706      }
3707    wd->show_item = NULL;
3708    wd->pan_x = 0;
3709    wd->pan_y = 0;
3710    wd->minw = 0;
3711    wd->minh = 0;
3712
3713    if (wd->alpha_bg)
3714       evas_object_del(wd->alpha_bg);
3715    wd->alpha_bg = NULL;
3716
3717    if (wd->pan_smart)
3718      {
3719         evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
3720         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
3721      }
3722    _sizing_eval(obj);
3723 }
3724
3725 /**
3726  * Enable or disable multi-select in the genlist
3727  *
3728  * This enables (EINA_TRUE) or disables (EINA_FALSE) multi-select in
3729  * the list. This allows more than 1 item to be selected.
3730  *
3731  * @param obj The genlist object
3732  * @param multi Multi-select enable/disable
3733  *
3734  * @ingroup Genlist
3735  */
3736 EAPI void
3737 elm_genlist_multi_select_set(Evas_Object *obj,
3738                              Eina_Bool    multi)
3739 {
3740    ELM_CHECK_WIDTYPE(obj, widtype);
3741    Widget_Data *wd = elm_widget_data_get(obj);
3742    if (!wd) return;
3743    wd->multi = multi;
3744 }
3745
3746 /**
3747  * Gets if multi-select in genlist is enable or disable
3748  *
3749  * @param obj The genlist object
3750  * @return Multi-select enable/disable
3751  * (EINA_TRUE = enabled/EINA_FALSE = disabled)
3752  *
3753  * @ingroup Genlist
3754  */
3755 EAPI Eina_Bool
3756 elm_genlist_multi_select_get(const Evas_Object *obj)
3757 {
3758    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3759    Widget_Data *wd = elm_widget_data_get(obj);
3760    if (!wd) return EINA_FALSE;
3761    return wd->multi;
3762 }
3763
3764 /**
3765  * Get the selectd item in the genlist
3766  *
3767  * This gets the selected item in the list (if multi-select is enabled
3768  * only the first item in the list is selected - which is not very
3769  * useful, so see elm_genlist_selected_items_get() for when
3770  * multi-select is used).
3771  *
3772  * If no item is selected, NULL is returned.
3773  *
3774  * @param obj The genlist object
3775  * @return The selected item, or NULL if none.
3776  *
3777  * @ingroup Genlist
3778  */
3779 EAPI Elm_Genlist_Item *
3780 elm_genlist_selected_item_get(const Evas_Object *obj)
3781 {
3782    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3783    Widget_Data *wd = elm_widget_data_get(obj);
3784    if (!wd) return NULL;
3785    if (wd->selected) return wd->selected->data;
3786    return NULL;
3787 }
3788
3789 /**
3790  * Get a list of selected items in the genlist
3791  *
3792  * This returns a list of the selected items. This list pointer is
3793  * only valid so long as no items are selected or unselected (or
3794  * unselected implicitly by deletion). The list contains
3795  * Elm_Genlist_Item pointers.
3796  *
3797  * @param obj The genlist object
3798  * @return The list of selected items, nor NULL if none are selected.
3799  *
3800  * @ingroup Genlist
3801  */
3802 EAPI const Eina_List *
3803 elm_genlist_selected_items_get(const Evas_Object *obj)
3804 {
3805    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3806    Widget_Data *wd = elm_widget_data_get(obj);
3807    if (!wd) return NULL;
3808    return wd->selected;
3809 }
3810
3811 /**
3812  * Get a list of realized items in genlist
3813  *
3814  * This returns a list of the realized items in the genlist. The list
3815  * contains Elm_Genlist_Item pointers. The list must be freed by the
3816  * caller when done with eina_list_free(). The item pointers in the
3817  * list are only valid so long as those items are not deleted or the
3818  * genlist is not deleted.
3819  *
3820  * @param obj The genlist object
3821  * @return The list of realized items, nor NULL if none are realized.
3822  *
3823  * @ingroup Genlist
3824  */
3825 EAPI Eina_List *
3826 elm_genlist_realized_items_get(const Evas_Object *obj)
3827 {
3828    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3829    Widget_Data *wd = elm_widget_data_get(obj);
3830    Eina_List *list = NULL;
3831    Item_Block *itb;
3832    Eina_Bool done = EINA_FALSE;
3833    if (!wd) return NULL;
3834    EINA_INLIST_FOREACH(wd->blocks, itb)
3835      {
3836         if (itb->realized)
3837           {
3838              Eina_List *l;
3839              Elm_Genlist_Item *it;
3840
3841              done = 1;
3842              EINA_LIST_FOREACH(itb->items, l, it)
3843                {
3844                   if (it->realized) list = eina_list_append(list, it);
3845                }
3846           }
3847         else
3848           {
3849              if (done) break;
3850           }
3851      }
3852    return list;
3853 }
3854
3855 /**
3856  * Get the item that is at the x, y canvas coords
3857  *
3858  * This returns the item at the given coordinates (which are canvas
3859  * relative not object-relative). If an item is at that coordinate,
3860  * that item handle is returned, and if @p posret is not NULL, the
3861  * integer pointed to is set to a value of -1, 0 or 1, depending if
3862  * the coordinate is on the upper portion of that item (-1), on the
3863  * middle section (0) or on the lower part (1). If NULL is returned as
3864  * an item (no item found there), then posret may indicate -1 or 1
3865  * based if the coordinate is above or below all items respectively in
3866  * the genlist.
3867  *
3868  * @param it The item
3869  * @param x The input x coordinate
3870  * @param y The input y coordinate
3871  * @param posret The position relative to the item returned here
3872  * @return The item at the coordinates or NULL if none
3873  *
3874  * @ingroup Genlist
3875  */
3876 EAPI Elm_Genlist_Item *
3877 elm_genlist_at_xy_item_get(const Evas_Object *obj,
3878                            Evas_Coord         x,
3879                            Evas_Coord         y,
3880                            int               *posret)
3881 {
3882    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3883    Widget_Data *wd = elm_widget_data_get(obj);
3884    Evas_Coord ox, oy, ow, oh;
3885    Item_Block *itb;
3886    Evas_Coord lasty;
3887    if (!wd) return NULL;
3888    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
3889    lasty = oy;
3890    EINA_INLIST_FOREACH(wd->blocks, itb)
3891      {
3892         Eina_List *l;
3893         Elm_Genlist_Item *it;
3894
3895         if (!ELM_RECTS_INTERSECT(ox + itb->x - itb->wd->pan_x,
3896                                  oy + itb->y - itb->wd->pan_y,
3897                                  itb->w, itb->h, x, y, 1, 1))
3898           continue;
3899         EINA_LIST_FOREACH(itb->items, l, it)
3900           {
3901              Evas_Coord itx, ity;
3902
3903              itx = ox + itb->x + it->x - itb->wd->pan_x;
3904              ity = oy + itb->y + it->y - itb->wd->pan_y;
3905              if (ELM_RECTS_INTERSECT(itx, ity, it->w, it->h, x, y, 1, 1))
3906                {
3907                   if (posret)
3908                     {
3909                        if (y <= (ity + (it->h / 4))) *posret = -1;
3910                        else if (y >= (ity + it->h - (it->h / 4)))
3911                          *posret = 1;
3912                        else *posret = 0;
3913                     }
3914                   return it;
3915                }
3916              lasty = ity + it->h;
3917           }
3918      }
3919    if (posret)
3920      {
3921         if (y > lasty) *posret = 1;
3922         else *posret = -1;
3923      }
3924    return NULL;
3925 }
3926
3927 /**
3928  * Get the first item in the genlist
3929  *
3930  * This returns the first item in the list.
3931  *
3932  * @param obj The genlist object
3933  * @return The first item, or NULL if none
3934  *
3935  * @ingroup Genlist
3936  */
3937 EAPI Elm_Genlist_Item *
3938 elm_genlist_first_item_get(const Evas_Object *obj)
3939 {
3940    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3941    Widget_Data *wd = elm_widget_data_get(obj);
3942    if (!wd) return NULL;
3943    if (!wd->items) return NULL;
3944    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items);
3945    while ((it) && (it->delete_me))
3946      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3947    return it;
3948 }
3949
3950 /**
3951  * Get the last item in the genlist
3952  *
3953  * This returns the last item in the list.
3954  *
3955  * @return The last item, or NULL if none
3956  *
3957  * @ingroup Genlist
3958  */
3959 EAPI Elm_Genlist_Item *
3960 elm_genlist_last_item_get(const Evas_Object *obj)
3961 {
3962    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3963    Widget_Data *wd = elm_widget_data_get(obj);
3964    if (!wd) return NULL;
3965    if (!wd->items) return NULL;
3966    Elm_Genlist_Item *it = ELM_GENLIST_ITEM_FROM_INLIST(wd->items->last);
3967    while ((it) && (it->delete_me))
3968      it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3969    return it;
3970 }
3971
3972 /**
3973  * Get the next item in the genlist
3974  *
3975  * This returns the item after the item @p it.
3976  *
3977  * @param it The item
3978  * @return The item after @p it, or NULL if none
3979  *
3980  * @ingroup Genlist
3981  */
3982 EAPI Elm_Genlist_Item *
3983 elm_genlist_item_next_get(const Elm_Genlist_Item *it)
3984 {
3985    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
3986    while (it)
3987      {
3988         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3989         if ((it) && (!it->delete_me)) break;
3990      }
3991    return (Elm_Genlist_Item *)it;
3992 }
3993
3994 /**
3995  * Get the previous item in the genlist
3996  *
3997  * This returns the item before the item @p it.
3998  *
3999  * @param it The item
4000  * @return The item before @p it, or NULL if none
4001  *
4002  * @ingroup Genlist
4003  */
4004 EAPI Elm_Genlist_Item *
4005 elm_genlist_item_prev_get(const Elm_Genlist_Item *it)
4006 {
4007    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4008    while (it)
4009      {
4010         it = ELM_GENLIST_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
4011         if ((it) && (!it->delete_me)) break;
4012      }
4013    return (Elm_Genlist_Item *)it;
4014 }
4015
4016 /**
4017  * Get the genlist object from an item
4018  *
4019  * This returns the genlist object itself that an item belongs to.
4020  *
4021  * @param it The item
4022  * @return The genlist object
4023  *
4024  * @ingroup Genlist
4025  */
4026 EAPI Evas_Object *
4027 elm_genlist_item_genlist_get(const Elm_Genlist_Item *it)
4028 {
4029    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4030    return it->base.widget;
4031 }
4032
4033 /**
4034  * Get the parent item of the given item
4035  *
4036  * This returns the parent item of the item @p it given.
4037  *
4038  * @param it The item
4039  * @return The parent of the item or NULL if none
4040  *
4041  * @ingroup Genlist
4042  */
4043 EAPI Elm_Genlist_Item *
4044 elm_genlist_item_parent_get(const Elm_Genlist_Item *it)
4045 {
4046    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4047    return it->parent;
4048 }
4049
4050 /**
4051  * Clear all sub-items (children) of the given item
4052  *
4053  * This clears all items that are children (or their descendants) of the
4054  * given item @p it.
4055  *
4056  * @param it The item
4057  *
4058  * @ingroup Genlist
4059  */
4060 EAPI void
4061 elm_genlist_item_subitems_clear(Elm_Genlist_Item *it)
4062 {
4063    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4064    Elm_Genlist_Item *it2;
4065    Evas_Coord y, h;
4066
4067    if(!it->wd->effect_mode || !it->wd->move_effect_mode)
4068       _item_subitems_clear(it);
4069    else
4070      {
4071         if((!it->wd->item_moving_effect_timer) && (it->flags != ELM_GENLIST_ITEM_GROUP) &&
4072         it->wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE )
4073           {
4074              it->wd->expand_item = it;
4075              _item_flip_effect_show(it);
4076              evas_object_geometry_get(it->base.view, NULL, &y, NULL, &h);
4077              it->wd->expand_item_end = y + h;
4078
4079               it2= it;
4080              do {
4081                   it2 = elm_genlist_item_next_get(it2);
4082                   if(!it2) break;
4083              } while (it2->expanded_depth > it->expanded_depth);
4084              if(it2)
4085                 it->wd->expand_item_gap = it->wd->expand_item_end - it2->old_scrl_y;
4086              else
4087                 it->wd->expand_item_gap = 0;
4088
4089              evas_object_raise(it->wd->alpha_bg);
4090              evas_object_show(it->wd->alpha_bg);
4091
4092              it->wd->start_time = current_time_get();
4093              it->wd->item_moving_effect_timer = ecore_animator_add(_item_moving_effect_timer_cb, it->wd);
4094           }
4095         else
4096            _item_subitems_clear(it);
4097      }
4098 }
4099
4100 /**
4101  * Set the selected state of an item
4102  *
4103  * This sets the selected state (1 selected, 0 not selected) of the given
4104  * item @p it.
4105  *
4106  * @param it The item
4107  * @param selected The selected state
4108  *
4109  * @ingroup Genlist
4110  */
4111 EAPI void
4112 elm_genlist_item_selected_set(Elm_Genlist_Item *it,
4113                               Eina_Bool         selected)
4114 {
4115    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4116    Widget_Data *wd = elm_widget_data_get(it->base.widget);
4117    if (!wd) return;
4118    if (it->delete_me) return;
4119    selected = !!selected;
4120    if (it->selected == selected) return;
4121
4122    if (selected)
4123      {
4124         if (!wd->multi)
4125           {
4126              while (wd->selected)
4127                _item_unselect(wd->selected->data);
4128           }
4129         _item_highlight(it);
4130         _item_select(it);
4131      }
4132    else
4133      _item_unselect(it);
4134 }
4135
4136 /**
4137  * Get the selected state of an item
4138  *
4139  * This gets the selected state of an item (1 selected, 0 not selected).
4140  *
4141  * @param it The item
4142  * @return The selected state
4143  *
4144  * @ingroup Genlist
4145  */
4146 EAPI Eina_Bool
4147 elm_genlist_item_selected_get(const Elm_Genlist_Item *it)
4148 {
4149    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4150    return it->selected;
4151 }
4152
4153 /**
4154  * Sets the expanded state of an item (if it's a parent)
4155  *
4156  * This expands or contracts a parent item (thus showing or hiding the
4157  * children).
4158  *
4159  * @param it The item
4160  * @param expanded The expanded state (1 expanded, 0 not expanded).
4161  *
4162  * @ingroup Genlist
4163  */
4164 EAPI void
4165 elm_genlist_item_expanded_set(Elm_Genlist_Item *it,
4166                               Eina_Bool         expanded)
4167 {
4168    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4169    if (it->expanded == expanded) return;
4170    it->expanded = expanded;
4171    it->wd->expand_item = it;
4172
4173    if(it->wd->effect_mode && !it->wd->alpha_bg)
4174       it->wd->alpha_bg = _create_tray_alpha_bg(it->base.widget);
4175
4176    if (it->expanded)
4177      {
4178         it->wd->auto_scrolled = EINA_FALSE;
4179         it->wd->move_effect_mode = ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND;
4180         if (it->realized)
4181           edje_object_signal_emit(it->base.view, "elm,state,expanded", "elm");
4182         evas_object_smart_callback_call(it->base.widget, "expanded", it);
4183      }
4184    else
4185      {
4186         it->wd->contracting = EINA_TRUE;
4187         it->wd->move_effect_mode = ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT;
4188         if (it->realized)
4189           edje_object_signal_emit(it->base.view, "elm,state,contracted", "elm");
4190         evas_object_smart_callback_call(it->base.widget, "contracted", it);
4191      }
4192 }
4193
4194 /**
4195  * Get the expanded state of an item
4196  *
4197  * This gets the expanded state of an item
4198  *
4199  * @param it The item
4200  * @return Thre expanded state
4201  *
4202  * @ingroup Genlist
4203  */
4204 EAPI Eina_Bool
4205 elm_genlist_item_expanded_get(const Elm_Genlist_Item *it)
4206 {
4207    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4208    return it->expanded;
4209 }
4210
4211 /**
4212  * Get the depth of expanded item
4213  *
4214  * @param it The genlist item object
4215  * @return The depth of expanded item
4216  *
4217  * @ingroup Genlist
4218  */
4219 EAPI int
4220 elm_genlist_item_expanded_depth_get(const Elm_Genlist_Item *it)
4221 {
4222    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, 0);
4223    return it->expanded_depth;
4224 }
4225
4226 /**
4227  * Sets the disabled state of an item.
4228  *
4229  * A disabled item cannot be selected or unselected. It will also
4230  * change appearance to appear disabled. This sets the disabled state
4231  * (1 disabled, 0 not disabled).
4232  *
4233  * @param it The item
4234  * @param disabled The disabled state
4235  *
4236  * @ingroup Genlist
4237  */
4238 EAPI void
4239 elm_genlist_item_disabled_set(Elm_Genlist_Item *it,
4240                               Eina_Bool         disabled)
4241 {
4242    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4243    if (it->disabled == disabled) return;
4244    if (it->delete_me) return;
4245    it->disabled = disabled;
4246    if (it->realized)
4247      {
4248         if (it->disabled)
4249           edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
4250         else
4251           edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
4252      }
4253 }
4254
4255 /**
4256  * Get the disabled state of an item
4257  *
4258  * This gets the disabled state of the given item.
4259  *
4260  * @param it The item
4261  * @return The disabled state
4262  *
4263  * @ingroup Genlist
4264  */
4265 EAPI Eina_Bool
4266 elm_genlist_item_disabled_get(const Elm_Genlist_Item *it)
4267 {
4268    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4269    if (it->delete_me) return EINA_FALSE;
4270    return it->disabled;
4271 }
4272
4273 /**
4274  * Sets the display only state of an item.
4275  *
4276  * A display only item cannot be selected or unselected. It is for
4277  * display only and not selecting or otherwise clicking, dragging
4278  * etc. by the user, thus finger size rules will not be applied to
4279  * this item.
4280  *
4281  * @param it The item
4282  * @param display_only The display only state
4283  *
4284  * @ingroup Genlist
4285  */
4286 EAPI void
4287 elm_genlist_item_display_only_set(Elm_Genlist_Item *it,
4288                                   Eina_Bool         display_only)
4289 {
4290    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4291    if (it->display_only == display_only) return;
4292    if (it->delete_me) return;
4293    it->display_only = display_only;
4294    it->mincalcd = EINA_FALSE;
4295    it->updateme = EINA_TRUE;
4296    if (it->block) it->block->updateme = EINA_TRUE;
4297    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4298    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4299 }
4300
4301 /**
4302  * Get the display only state of an item
4303  *
4304  * This gets the display only state of the given item.
4305  *
4306  * @param it The item
4307  * @return The display only state
4308  *
4309  * @ingroup Genlist
4310  */
4311 EAPI Eina_Bool
4312 elm_genlist_item_display_only_get(const Elm_Genlist_Item *it)
4313 {
4314    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
4315    if (it->delete_me) return EINA_FALSE;
4316    return it->display_only;
4317 }
4318
4319 /**
4320  * Show the given item
4321  *
4322  * This causes genlist to jump to the given item @p it and show it (by
4323  * scrolling), if it is not fully visible.
4324  *
4325  * @param it The item
4326  *
4327  * @ingroup Genlist
4328  */
4329 EAPI void
4330 elm_genlist_item_show(Elm_Genlist_Item *it)
4331 {
4332    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4333    Evas_Coord gith = 0;
4334    if (it->delete_me) return;
4335    if ((it->queued) || (!it->mincalcd))
4336      {
4337         it->wd->show_item = it;
4338         it->wd->bring_in = EINA_TRUE;
4339         it->showme = EINA_TRUE;
4340         return;
4341      }
4342    if (it->wd->show_item)
4343      {
4344         it->wd->show_item->showme = EINA_FALSE;
4345         it->wd->show_item = NULL;
4346      }
4347    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4348      gith = it->group_item->h;
4349    elm_smart_scroller_child_region_show(it->wd->scr,
4350                                         it->x + it->block->x,
4351                                         it->y + it->block->y - gith,
4352                                         it->block->w, it->h);
4353 }
4354
4355 /**
4356  * Bring in the given item
4357  *
4358  * This causes genlist to jump to the given item @p it and show it (by
4359  * scrolling), if it is not fully visible. This may use animation to
4360  * do so and take a period of time
4361  *
4362  * @param it The item
4363  *
4364  * @ingroup Genlist
4365  */
4366 EAPI void
4367 elm_genlist_item_bring_in(Elm_Genlist_Item *it)
4368 {
4369    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4370    Evas_Coord gith = 0;
4371    if (it->delete_me) return;
4372    if ((it->queued) || (!it->mincalcd))
4373      {
4374         it->wd->show_item = it;
4375         it->wd->bring_in = EINA_TRUE;
4376         it->showme = EINA_TRUE;
4377         return;
4378      }
4379    if (it->wd->show_item)
4380      {
4381         it->wd->show_item->showme = EINA_FALSE;
4382         it->wd->show_item = NULL;
4383      }
4384    if ((it->group_item) && (it->wd->pan_y > (it->y + it->block->y)))
4385      gith = it->group_item->h;
4386    elm_smart_scroller_region_bring_in(it->wd->scr,
4387                                       it->x + it->block->x,
4388                                       it->y + it->block->y - gith,
4389                                       it->block->w, it->h);
4390 }
4391
4392 /**
4393  * Show the given item at the top
4394  *
4395  * This causes genlist to jump to the given item @p it and show it (by
4396  * scrolling), if it is not fully visible.
4397  *
4398  * @param it The item
4399  *
4400  * @ingroup Genlist
4401  */
4402 EAPI void
4403 elm_genlist_item_top_show(Elm_Genlist_Item *it)
4404 {
4405    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4406    Evas_Coord ow, oh;
4407    Evas_Coord gith = 0;
4408
4409    if (it->delete_me) return;
4410    if ((it->queued) || (!it->mincalcd))
4411      {
4412         it->wd->show_item = it;
4413         it->wd->bring_in = EINA_TRUE;
4414         it->showme = EINA_TRUE;
4415         return;
4416      }
4417    if (it->wd->show_item)
4418      {
4419         it->wd->show_item->showme = EINA_FALSE;
4420         it->wd->show_item = NULL;
4421      }
4422    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4423    if (it->group_item) gith = it->group_item->h;
4424    elm_smart_scroller_child_region_show(it->wd->scr,
4425                                         it->x + it->block->x,
4426                                         it->y + it->block->y - gith,
4427                                         it->block->w, oh);
4428 }
4429
4430 /**
4431  * Bring in the given item at the top
4432  *
4433  * This causes genlist to jump to the given item @p it and show it (by
4434  * scrolling), if it is not fully visible. This may use animation to
4435  * do so and take a period of time
4436  *
4437  * @param it The item
4438  *
4439  * @ingroup Genlist
4440  */
4441 EAPI void
4442 elm_genlist_item_top_bring_in(Elm_Genlist_Item *it)
4443 {
4444    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4445    Evas_Coord ow, oh;
4446    Evas_Coord gith = 0;
4447
4448    if (it->delete_me) return;
4449    if ((it->queued) || (!it->mincalcd))
4450      {
4451         it->wd->show_item = it;
4452         it->wd->bring_in = EINA_TRUE;
4453         it->showme = EINA_TRUE;
4454         return;
4455      }
4456    if (it->wd->show_item)
4457      {
4458         it->wd->show_item->showme = EINA_FALSE;
4459         it->wd->show_item = NULL;
4460      }
4461    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4462    if (it->group_item) gith = it->group_item->h;
4463    elm_smart_scroller_region_bring_in(it->wd->scr,
4464                                       it->x + it->block->x,
4465                                       it->y + it->block->y - gith,
4466                                       it->block->w, oh);
4467 }
4468
4469 /**
4470  * Show the given item at the middle
4471  *
4472  * This causes genlist to jump to the given item @p it and show it (by
4473  * scrolling), if it is not fully visible.
4474  *
4475  * @param it The item
4476  *
4477  * @ingroup Genlist
4478  */
4479 EAPI void
4480 elm_genlist_item_middle_show(Elm_Genlist_Item *it)
4481 {
4482    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4483    Evas_Coord ow, oh;
4484
4485    if (it->delete_me) return;
4486    if ((it->queued) || (!it->mincalcd))
4487      {
4488         it->wd->show_item = it;
4489         it->wd->bring_in = EINA_TRUE;
4490         it->showme = EINA_TRUE;
4491         return;
4492      }
4493    if (it->wd->show_item)
4494      {
4495         it->wd->show_item->showme = EINA_FALSE;
4496         it->wd->show_item = NULL;
4497      }
4498    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4499    elm_smart_scroller_child_region_show(it->wd->scr,
4500                                         it->x + it->block->x,
4501                                         it->y + it->block->y - oh / 2 +
4502                                         it->h / 2, it->block->w, oh);
4503 }
4504
4505 /**
4506  * Bring in the given item at the middle
4507  *
4508  * This causes genlist to jump to the given item @p it and show it (by
4509  * scrolling), if it is not fully visible. This may use animation to
4510  * do so and take a period of time
4511  *
4512  * @param it The item
4513  *
4514  * @ingroup Genlist
4515  */
4516 EAPI void
4517 elm_genlist_item_middle_bring_in(Elm_Genlist_Item *it)
4518 {
4519    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4520    Evas_Coord ow, oh;
4521
4522    if (it->delete_me) return;
4523    if ((it->queued) || (!it->mincalcd))
4524      {
4525         it->wd->show_item = it;
4526         it->wd->bring_in = EINA_TRUE;
4527         it->showme = EINA_TRUE;
4528         return;
4529      }
4530    if (it->wd->show_item)
4531      {
4532         it->wd->show_item->showme = EINA_FALSE;
4533         it->wd->show_item = NULL;
4534      }
4535    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
4536    elm_smart_scroller_region_bring_in(it->wd->scr,
4537                                       it->x + it->block->x,
4538                                       it->y + it->block->y - oh / 2 + it->h / 2,
4539                                       it->block->w, oh);
4540 }
4541
4542 /**
4543  * Delete a given item
4544  *
4545  * This deletes the item from genlist and calls the genlist item del
4546  * class callback defined in the item class, if it is set. This clears all
4547  * subitems if it is a tree.
4548  *
4549  * @param it The item
4550  *
4551  * @ingroup Genlist
4552  */
4553 EAPI void
4554 elm_genlist_item_del(Elm_Genlist_Item *it)
4555 {
4556    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4557    if ((it->relcount > 0) || (it->walking > 0))
4558      {
4559         elm_widget_item_pre_notify_del(it);
4560         elm_genlist_item_subitems_clear(it);
4561         it->delete_me = EINA_TRUE;
4562         if (it->wd->show_item == it) it->wd->show_item = NULL;
4563         if (it->selected)
4564           it->wd->selected = eina_list_remove(it->wd->selected,
4565                                               it);
4566         if (it->block)
4567           {
4568              if (it->realized) _item_unrealize(it);
4569              if (it->effect_item_realized) _effect_item_unrealize(it);
4570              it->block->changed = EINA_TRUE;
4571              if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
4572              it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
4573           }
4574         if (it->itc->func.del)
4575           it->itc->func.del((void *)it->base.data, it->base.widget);
4576         return;
4577      }
4578    _item_del(it);
4579 }
4580
4581 /**
4582  * Set the data item from the genlist item
4583  *
4584  * This set the data value passed on the elm_genlist_item_append() and
4585  * related item addition calls. This function will also call
4586  * elm_genlist_item_update() so the item will be updated to reflect the
4587  * new data.
4588  *
4589  * @param it The item
4590  * @param data The new data pointer to set
4591  *
4592  * @ingroup Genlist
4593  */
4594 EAPI void
4595 elm_genlist_item_data_set(Elm_Genlist_Item *it,
4596                           const void       *data)
4597 {
4598    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4599    elm_widget_item_data_set(it, data);
4600    elm_genlist_item_update(it);
4601 }
4602
4603 /**
4604  * Get the data item from the genlist item
4605  *
4606  * This returns the data value passed on the elm_genlist_item_append()
4607  * and related item addition calls and elm_genlist_item_data_set().
4608  *
4609  * @param it The item
4610  * @return The data pointer provided when created
4611  *
4612  * @ingroup Genlist
4613  */
4614 EAPI void *
4615 elm_genlist_item_data_get(const Elm_Genlist_Item *it)
4616 {
4617    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4618    return elm_widget_item_data_get(it);
4619 }
4620
4621 /**
4622  * Tells genlist to "orphan" icons fetchs by the item class
4623  *
4624  * This instructs genlist to release references to icons in the item,
4625  * meaning that they will no longer be managed by genlist and are
4626  * floating "orphans" that can be re-used elsewhere if the user wants
4627  * to.
4628  *
4629  * @param it The item
4630  *
4631  * @ingroup Genlist
4632  */
4633 EAPI void
4634 elm_genlist_item_icons_orphan(Elm_Genlist_Item *it)
4635 {
4636    Evas_Object *icon;
4637    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4638    EINA_LIST_FREE(it->icon_objs, icon)
4639      {
4640         elm_widget_sub_object_del(it->base.widget, icon);
4641         evas_object_smart_member_del(icon);
4642         evas_object_hide(icon);
4643      }
4644 }
4645
4646 /**
4647  * Get the real evas object of the genlist item
4648  *
4649  * This returns the actual evas object used for the specified genlist
4650  * item. This may be NULL as it may not be created, and may be deleted
4651  * at any time by genlist. Do not modify this object (move, resize,
4652  * show, hide etc.) as genlist is controlling it. This function is for
4653  * querying, emitting custom signals or hooking lower level callbacks
4654  * for events. Do not delete this object under any circumstances.
4655  *
4656  * @param it The item
4657  * @return The object pointer
4658  *
4659  * @ingroup Genlist
4660  */
4661 EAPI const Evas_Object *
4662 elm_genlist_item_object_get(const Elm_Genlist_Item *it)
4663 {
4664    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
4665    return it->base.view;
4666 }
4667
4668 /**
4669  * Update the contents of an item
4670  *
4671  * This updates an item by calling all the item class functions again
4672  * to get the icons, labels and states. Use this when the original
4673  * item data has changed and the changes are desired to be reflected.
4674  *
4675  * @param it The item
4676  *
4677  * @ingroup Genlist
4678  */
4679 EAPI void
4680 elm_genlist_item_update(Elm_Genlist_Item *it)
4681 {
4682    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4683    if (!it->block) return;
4684    if (it->delete_me) return;
4685    it->mincalcd = EINA_FALSE;
4686    it->updateme = EINA_TRUE;
4687    it->block->updateme = EINA_TRUE;
4688    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
4689    it->wd->update_job = ecore_job_add(_update_job, it->wd);
4690 }
4691
4692 /**
4693  * Update the item class of an item
4694  *
4695  * @param it The item
4696  * @parem itc The item class for the item
4697  *
4698  * @ingroup Genlist
4699  */
4700 EAPI void
4701 elm_genlist_item_item_class_update(Elm_Genlist_Item             *it,
4702                                    const Elm_Genlist_Item_Class *itc)
4703 {
4704    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
4705    if (!it->block) return;
4706    EINA_SAFETY_ON_NULL_RETURN(itc);
4707    if (it->delete_me) return;
4708    it->itc = itc;
4709    it->nocache = EINA_TRUE;
4710    elm_genlist_item_update(it);
4711 }
4712
4713 static Evas_Object *
4714 _elm_genlist_item_label_create(void        *data,
4715                                Evas_Object *obj,
4716                                void *item   __UNUSED__)
4717 {
4718    Evas_Object *label = elm_label_add(obj);
4719    if (!label)
4720      return NULL;
4721    elm_object_style_set(label, "tooltip");
4722    elm_label_label_set(label, data);
4723    return label;
4724 }
4725
4726 static void
4727 _elm_genlist_item_label_del_cb(void            *data,
4728                                Evas_Object *obj __UNUSED__,
4729                                void *event_info __UNUSED__)
4730 {
4731    eina_stringshare_del(data);
4732 }
4733
4734 /**
4735  * Set the text to be shown in the genlist item.
4736  *
4737  * @param item Target item
4738  * @param text The text to set in the content
4739  *
4740  * Setup the text as tooltip to object. The item can have only one
4741  * tooltip, so any previous tooltip data is removed.
4742  *
4743  * @ingroup Genlist
4744  */
4745 EAPI void
4746 elm_genlist_item_tooltip_text_set(Elm_Genlist_Item *item,
4747                                   const char       *text)
4748 {
4749    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4750    text = eina_stringshare_add(text);
4751    elm_genlist_item_tooltip_content_cb_set(item, _elm_genlist_item_label_create,
4752                                            text,
4753                                            _elm_genlist_item_label_del_cb);
4754 }
4755
4756 /**
4757  * Set the content to be shown in the tooltip item
4758  *
4759  * Setup the tooltip to item. The item can have only one tooltip, so
4760  * any previous tooltip data is removed. @p func(with @p data) will be
4761  * called every time that need to show the tooltip and it should return a
4762  * valid Evas_Object. This object is then managed fully by tooltip
4763  * system and is deleted when the tooltip is gone.
4764  *
4765  * @param item the genlist item being attached by a tooltip.
4766  * @param func the function used to create the tooltip contents.
4767  * @param data what to provide to @a func as callback data/context.
4768  * @param del_cb called when data is not needed anymore, either when
4769  *        another callback replaces @func, the tooltip is unset with
4770  *        elm_genlist_item_tooltip_unset() or the owner @a item
4771  *        dies. This callback receives as the first parameter the
4772  *        given @a data, and @c event_info is the item.
4773  *
4774  * @ingroup Genlist
4775  */
4776 EAPI void
4777 elm_genlist_item_tooltip_content_cb_set(Elm_Genlist_Item           *item,
4778                                         Elm_Tooltip_Item_Content_Cb func,
4779                                         const void                 *data,
4780                                         Evas_Smart_Cb               del_cb)
4781 {
4782    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
4783
4784    if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
4785      return;
4786
4787    if (item->tooltip.del_cb)
4788      item->tooltip.del_cb((void *)item->tooltip.data,
4789                           item->base.widget, item);
4790
4791    item->tooltip.content_cb = func;
4792    item->tooltip.data = data;
4793    item->tooltip.del_cb = del_cb;
4794
4795    if (item->base.view)
4796      {
4797         elm_widget_item_tooltip_content_cb_set(item,
4798                                                item->tooltip.content_cb,
4799                                                item->tooltip.data, NULL);
4800         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
4801      }
4802
4803    return;
4804
4805 error:
4806    if (del_cb) del_cb((void *)data, NULL, NULL);
4807 }
4808
4809 /**
4810  * Unset tooltip from item
4811  *
4812  * @param item genlist item to remove previously set tooltip.
4813  *
4814  * Remove tooltip from item. The callback provided as del_cb to
4815  * elm_genlist_item_tooltip_content_cb_set() will be called to notify
4816  * it is not used anymore.
4817  *
4818  * @see elm_genlist_item_tooltip_content_cb_set()
4819  *
4820  * @ingroup Genlist
4821  */
4822 EAPI void
4823 elm_genlist_item_tooltip_unset(Elm_Genlist_Item *item)
4824 {
4825    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4826    if ((item->base.view) && (item->tooltip.content_cb))
4827      elm_widget_item_tooltip_unset(item);
4828
4829    if (item->tooltip.del_cb)
4830      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
4831    item->tooltip.del_cb = NULL;
4832    item->tooltip.content_cb = NULL;
4833    item->tooltip.data = NULL;
4834    if (item->tooltip.style)
4835      elm_genlist_item_tooltip_style_set(item, NULL);
4836 }
4837
4838 /**
4839  * Sets a different style for this item tooltip.
4840  *
4841  * @note before you set a style you should define a tooltip with
4842  *       elm_genlist_item_tooltip_content_cb_set() or
4843  *       elm_genlist_item_tooltip_text_set()
4844  *
4845  * @param item genlist item with tooltip already set.
4846  * @param style the theme style to use (default, transparent, ...)
4847  *
4848  * @ingroup Genlist
4849  */
4850 EAPI void
4851 elm_genlist_item_tooltip_style_set(Elm_Genlist_Item *item,
4852                                    const char       *style)
4853 {
4854    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4855    eina_stringshare_replace(&item->tooltip.style, style);
4856    if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
4857 }
4858
4859 /**
4860  * Get the style for this item tooltip.
4861  *
4862  * @param item genlist item with tooltip already set.
4863  * @return style the theme style in use, defaults to "default". If the
4864  *         object does not have a tooltip set, then NULL is returned.
4865  *
4866  * @ingroup Genlist
4867  */
4868 EAPI const char *
4869 elm_genlist_item_tooltip_style_get(const Elm_Genlist_Item *item)
4870 {
4871    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4872    return item->tooltip.style;
4873 }
4874
4875 /**
4876  * Set the cursor to be shown when mouse is over the genlist item
4877  *
4878  * @param item Target item
4879  * @param cursor the cursor name to be used.
4880  *
4881  * @see elm_object_cursor_set()
4882  * @ingroup Genlist
4883  */
4884 EAPI void
4885 elm_genlist_item_cursor_set(Elm_Genlist_Item *item,
4886                             const char       *cursor)
4887 {
4888    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4889    eina_stringshare_replace(&item->mouse_cursor, cursor);
4890    if (item->base.view) elm_widget_item_cursor_set(item, cursor);
4891 }
4892
4893 /**
4894  * Get the cursor to be shown when mouse is over the genlist item
4895  *
4896  * @param item genlist item with cursor already set.
4897  * @return the cursor name.
4898  *
4899  * @ingroup Genlist
4900  */
4901 EAPI const char *
4902 elm_genlist_item_cursor_get(const Elm_Genlist_Item *item)
4903 {
4904    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4905    return elm_widget_item_cursor_get(item);
4906 }
4907
4908 /**
4909  * Unset the cursor to be shown when mouse is over the genlist item
4910  *
4911  * @param item Target item
4912  *
4913  * @see elm_object_cursor_unset()
4914  * @ingroup Genlist
4915  */
4916 EAPI void
4917 elm_genlist_item_cursor_unset(Elm_Genlist_Item *item)
4918 {
4919    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4920    if (!item->mouse_cursor)
4921      return;
4922
4923    if (item->base.view)
4924      elm_widget_item_cursor_unset(item);
4925
4926    eina_stringshare_del(item->mouse_cursor);
4927    item->mouse_cursor = NULL;
4928 }
4929
4930 /**
4931  * Sets a different style for this item cursor.
4932  *
4933  * @note before you set a style you should define a cursor with
4934  *       elm_genlist_item_cursor_set()
4935  *
4936  * @param item genlist item with cursor already set.
4937  * @param style the theme style to use (default, transparent, ...)
4938  *
4939  * @ingroup Genlist
4940  */
4941 EAPI void
4942 elm_genlist_item_cursor_style_set(Elm_Genlist_Item *item,
4943                                   const char       *style)
4944 {
4945    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4946    elm_widget_item_cursor_style_set(item, style);
4947 }
4948
4949 /**
4950  * Get the style for this item cursor.
4951  *
4952  * @param item genlist item with cursor already set.
4953  * @return style the theme style in use, defaults to "default". If the
4954  *         object does not have a cursor set, then NULL is returned.
4955  *
4956  * @ingroup Genlist
4957  */
4958 EAPI const char *
4959 elm_genlist_item_cursor_style_get(const Elm_Genlist_Item *item)
4960 {
4961    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
4962    return elm_widget_item_cursor_style_get(item);
4963 }
4964
4965 /**
4966  * Set if the cursor set should be searched on the theme or should use
4967  * the provided by the engine, only.
4968  *
4969  * @note before you set if should look on theme you should define a
4970  * cursor with elm_object_cursor_set(). By default it will only look
4971  * for cursors provided by the engine.
4972  *
4973  * @param item widget item with cursor already set.
4974  * @param engine_only boolean to define it cursors should be looked
4975  * only between the provided by the engine or searched on widget's
4976  * theme as well.
4977  *
4978  * @ingroup Genlist
4979  */
4980 EAPI void
4981 elm_genlist_item_cursor_engine_only_set(Elm_Genlist_Item *item,
4982                                         Eina_Bool         engine_only)
4983 {
4984    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
4985    elm_widget_item_cursor_engine_only_set(item, engine_only);
4986 }
4987
4988 /**
4989  * Get the cursor engine only usage for this item cursor.
4990  *
4991  * @param item widget item with cursor already set.
4992  * @return engine_only boolean to define it cursors should be looked
4993  * only between the provided by the engine or searched on widget's
4994  * theme as well. If the object does not have a cursor set, then
4995  * EINA_FALSE is returned.
4996  *
4997  * @ingroup Genlist
4998  */
4999 EAPI Eina_Bool
5000 elm_genlist_item_cursor_engine_only_get(const Elm_Genlist_Item *item)
5001 {
5002    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
5003    return elm_widget_item_cursor_engine_only_get(item);
5004 }
5005
5006 /**
5007  * This sets the horizontal stretching mode
5008  *
5009  * This sets the mode used for sizing items horizontally. Valid modes
5010  * are ELM_LIST_LIMIT and ELM_LIST_SCROLL. The default is
5011  * ELM_LIST_SCROLL. This mode means that if items are too wide to fit,
5012  * the scroller will scroll horizontally. Otherwise items are expanded
5013  * to fill the width of the viewport of the scroller. If it is
5014  * ELM_LIST_LIMIT, Items will be expanded to the viewport width and
5015  * limited to that size.
5016  *
5017  * @param obj The genlist object
5018  * @param mode The mode to use
5019  *
5020  * @ingroup Genlist
5021  */
5022 EAPI void
5023 elm_genlist_horizontal_mode_set(Evas_Object  *obj,
5024                                 Elm_List_Mode mode)
5025 {
5026    ELM_CHECK_WIDTYPE(obj, widtype);
5027    Widget_Data *wd = elm_widget_data_get(obj);
5028    if (!wd) return;
5029    if (wd->mode == mode) return;
5030    wd->mode = mode;
5031    _sizing_eval(obj);
5032 }
5033
5034 /**
5035  * Gets the horizontal stretching mode
5036  *
5037  * @param obj The genlist object
5038  * @return The mode to use
5039  * (ELM_LIST_LIMIT, ELM_LIST_SCROLL)
5040  *
5041  * @ingroup Genlist
5042  */
5043 EAPI Elm_List_Mode
5044 elm_genlist_horizontal_mode_get(const Evas_Object *obj)
5045 {
5046    ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
5047    Widget_Data *wd = elm_widget_data_get(obj);
5048    if (!wd) return ELM_LIST_LAST;
5049    return wd->mode;
5050 }
5051
5052 /**
5053  * Set the always select mode.
5054  *
5055  * Items will only call their selection func and callback when first
5056  * becoming selected. Any further clicks will do nothing, unless you
5057  * enable always select with elm_genlist_always_select_mode_set().
5058  * This means even if selected, every click will make the selected
5059  * callbacks be called.
5060  *
5061  * @param obj The genlist object
5062  * @param always_select The always select mode
5063  * (EINA_TRUE = on, EINA_FALSE = off)
5064  *
5065  * @ingroup Genlist
5066  */
5067 EAPI void
5068 elm_genlist_always_select_mode_set(Evas_Object *obj,
5069                                    Eina_Bool    always_select)
5070 {
5071    ELM_CHECK_WIDTYPE(obj, widtype);
5072    Widget_Data *wd = elm_widget_data_get(obj);
5073    if (!wd) return;
5074    wd->always_select = always_select;
5075 }
5076
5077 /**
5078  * Get the always select mode.
5079  *
5080  * @param obj The genlist object
5081  * @return The always select mode
5082  * (EINA_TRUE = on, EINA_FALSE = off)
5083  *
5084  * @ingroup Genlist
5085  */
5086 EAPI Eina_Bool
5087 elm_genlist_always_select_mode_get(const Evas_Object *obj)
5088 {
5089    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5090    Widget_Data *wd = elm_widget_data_get(obj);
5091    if (!wd) return EINA_FALSE;
5092    return wd->always_select;
5093 }
5094
5095 /**
5096  * Set no select mode
5097  *
5098  * This will turn off the ability to select items entirely and they
5099  * will neither appear selected nor call selected callback functions.
5100  *
5101  * @param obj The genlist object
5102  * @param no_select The no select mode
5103  * (EINA_TRUE = on, EINA_FALSE = off)
5104  *
5105  * @ingroup Genlist
5106  */
5107 EAPI void
5108 elm_genlist_no_select_mode_set(Evas_Object *obj,
5109                                Eina_Bool    no_select)
5110 {
5111    ELM_CHECK_WIDTYPE(obj, widtype);
5112    Widget_Data *wd = elm_widget_data_get(obj);
5113    if (!wd) return;
5114    wd->no_select = no_select;
5115 }
5116
5117 /**
5118  * Gets no select mode
5119  *
5120  * @param obj The genlist object
5121  * @return The no select mode
5122  * (EINA_TRUE = on, EINA_FALSE = off)
5123  *
5124  * @ingroup Genlist
5125  */
5126 EAPI Eina_Bool
5127 elm_genlist_no_select_mode_get(const Evas_Object *obj)
5128 {
5129    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5130    Widget_Data *wd = elm_widget_data_get(obj);
5131    if (!wd) return EINA_FALSE;
5132    return wd->no_select;
5133 }
5134
5135 /**
5136  * Set compress mode
5137  *
5138  * This will enable the compress mode where items are "compressed"
5139  * horizontally to fit the genlist scrollable viewport width. This is
5140  * special for genlist.  Do not rely on
5141  * elm_genlist_horizontal_mode_set() being set to ELM_LIST_COMPRESS to
5142  * work as genlist needs to handle it specially.
5143  *
5144  * @param obj The genlist object
5145  * @param compress The compress mode
5146  * (EINA_TRUE = on, EINA_FALSE = off)
5147  *
5148  * @ingroup Genlist
5149  */
5150 EAPI void
5151 elm_genlist_compress_mode_set(Evas_Object *obj,
5152                               Eina_Bool    compress)
5153 {
5154    ELM_CHECK_WIDTYPE(obj, widtype);
5155    Widget_Data *wd = elm_widget_data_get(obj);
5156    if (!wd) return;
5157    wd->compress = compress;
5158 }
5159
5160 /**
5161  * Get the compress mode
5162  *
5163  * @param obj The genlist object
5164  * @return The compress mode
5165  * (EINA_TRUE = on, EINA_FALSE = off)
5166  *
5167  * @ingroup Genlist
5168  */
5169 EAPI Eina_Bool
5170 elm_genlist_compress_mode_get(const Evas_Object *obj)
5171 {
5172    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5173    Widget_Data *wd = elm_widget_data_get(obj);
5174    if (!wd) return EINA_FALSE;
5175    return wd->compress;
5176 }
5177
5178 /**
5179  * Set height-for-width mode
5180  *
5181  * With height-for-width mode the item width will be fixed (restricted
5182  * to a minimum of) to the list width when calculating its size in
5183  * order to allow the height to be calculated based on it. This allows,
5184  * for instance, text block to wrap lines if the Edje part is
5185  * configured with "text.min: 0 1".
5186  *
5187  * @note This mode will make list resize slower as it will have to
5188  *       recalculate every item height again whenever the list width
5189  *       changes!
5190  *
5191  * @note When height-for-width mode is enabled, it also enables
5192  *       compress mode (see elm_genlist_compress_mode_set()) and
5193  *       disables homogeneous (see elm_genlist_homogeneous_set()).
5194  *
5195  * @param obj The genlist object
5196  * @param setting The height-for-width mode (EINA_TRUE = on,
5197  * EINA_FALSE = off)
5198  *
5199  * @ingroup Genlist
5200  */
5201 EAPI void
5202 elm_genlist_height_for_width_mode_set(Evas_Object *obj,
5203                                       Eina_Bool    height_for_width)
5204 {
5205    ELM_CHECK_WIDTYPE(obj, widtype);
5206    Widget_Data *wd = elm_widget_data_get(obj);
5207    if (!wd) return;
5208    wd->height_for_width = !!height_for_width;
5209    if (wd->height_for_width)
5210      {
5211         elm_genlist_homogeneous_set(obj, EINA_FALSE);
5212         elm_genlist_compress_mode_set(obj, EINA_TRUE);
5213      }
5214 }
5215
5216 /**
5217  * Get the height-for-width mode
5218  *
5219  * @param obj The genlist object
5220  * @return The height-for-width mode (EINA_TRUE = on, EINA_FALSE =
5221  * off)
5222  *
5223  * @ingroup Genlist
5224  */
5225 EAPI Eina_Bool
5226 elm_genlist_height_for_width_mode_get(const Evas_Object *obj)
5227 {
5228    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5229    Widget_Data *wd = elm_widget_data_get(obj);
5230    if (!wd) return EINA_FALSE;
5231    return wd->height_for_width;
5232 }
5233
5234 /**
5235  * Set bounce mode
5236  *
5237  * This will enable or disable the scroller bounce mode for the
5238  * genlist. See elm_scroller_bounce_set() for details
5239  *
5240  * @param obj The genlist object
5241  * @param h_bounce Allow bounce horizontally
5242  * @param v_bounce Allow bounce vertically
5243  *
5244  * @ingroup Genlist
5245  */
5246 EAPI void
5247 elm_genlist_bounce_set(Evas_Object *obj,
5248                        Eina_Bool    h_bounce,
5249                        Eina_Bool    v_bounce)
5250 {
5251    ELM_CHECK_WIDTYPE(obj, widtype);
5252    Widget_Data *wd = elm_widget_data_get(obj);
5253    if (!wd) return;
5254    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
5255 }
5256
5257 /**
5258  * Get the bounce mode
5259  *
5260  * @param obj The genlist object
5261  * @param h_bounce Allow bounce horizontally
5262  * @param v_bounce Allow bounce vertically
5263  *
5264  * @ingroup Genlist
5265  */
5266 EAPI void
5267 elm_genlist_bounce_get(const Evas_Object *obj,
5268                        Eina_Bool         *h_bounce,
5269                        Eina_Bool         *v_bounce)
5270 {
5271    ELM_CHECK_WIDTYPE(obj, widtype);
5272    Widget_Data *wd = elm_widget_data_get(obj);
5273    if (!wd) return;
5274    elm_smart_scroller_bounce_allow_get(obj, h_bounce, v_bounce);
5275 }
5276
5277 /**
5278  * Set homogenous mode
5279  *
5280  * This will enable the homogeneous mode where items are of the same
5281  * height and width so that genlist may do the lazy-loading at its
5282  * maximum. This implies 'compressed' mode.
5283  *
5284  * @param obj The genlist object
5285  * @param homogeneous Assume the items within the genlist are of the
5286  * same height and width (EINA_TRUE = on, EINA_FALSE = off)
5287  *
5288  * @ingroup Genlist
5289  */
5290 EAPI void
5291 elm_genlist_homogeneous_set(Evas_Object *obj,
5292                             Eina_Bool    homogeneous)
5293 {
5294    ELM_CHECK_WIDTYPE(obj, widtype);
5295    Widget_Data *wd = elm_widget_data_get(obj);
5296    if (!wd) return;
5297    if (homogeneous) elm_genlist_compress_mode_set(obj, EINA_TRUE);
5298    wd->homogeneous = homogeneous;
5299 }
5300
5301 /**
5302  * Get the homogenous mode
5303  *
5304  * @param obj The genlist object
5305  * @return Assume the items within the genlist are of the same height
5306  * and width (EINA_TRUE = on, EINA_FALSE = off)
5307  *
5308  * @ingroup Genlist
5309  */
5310 EAPI Eina_Bool
5311 elm_genlist_homogeneous_get(const Evas_Object *obj)
5312 {
5313    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5314    Widget_Data *wd = elm_widget_data_get(obj);
5315    if (!wd) return EINA_FALSE;
5316    return wd->homogeneous;
5317 }
5318
5319 /**
5320  * Set the maximum number of items within an item block
5321  *
5322  * This will configure the block count to tune to the target with
5323  * particular performance matrix.
5324  *
5325  * @param obj The genlist object
5326  * @param n   Maximum number of items within an item block
5327  *
5328  * @ingroup Genlist
5329  */
5330 EAPI void
5331 elm_genlist_block_count_set(Evas_Object *obj,
5332                             int          n)
5333 {
5334    ELM_CHECK_WIDTYPE(obj, widtype);
5335    Widget_Data *wd = elm_widget_data_get(obj);
5336    if (!wd) return;
5337    wd->max_items_per_block = n;
5338    wd->item_cache_max = wd->max_items_per_block * 2;
5339    _item_cache_clean(wd);
5340 }
5341
5342 /**
5343  * Get the maximum number of items within an item block
5344  *
5345  * @param obj The genlist object
5346  * @return Maximum number of items within an item block
5347  *
5348  * @ingroup Genlist
5349  */
5350 EAPI int
5351 elm_genlist_block_count_get(const Evas_Object *obj)
5352 {
5353    ELM_CHECK_WIDTYPE(obj, widtype) 0;
5354    Widget_Data *wd = elm_widget_data_get(obj);
5355    if (!wd) return 0;
5356    return wd->max_items_per_block;
5357 }
5358
5359 /**
5360  * Set the timeout in seconds for the longpress event
5361  *
5362  * @param obj The genlist object
5363  * @param timeout timeout in seconds
5364  *
5365  * @ingroup Genlist
5366  */
5367 EAPI void
5368 elm_genlist_longpress_timeout_set(Evas_Object *obj,
5369                                   double       timeout)
5370 {
5371    ELM_CHECK_WIDTYPE(obj, widtype);
5372    Widget_Data *wd = elm_widget_data_get(obj);
5373    if (!wd) return;
5374    wd->longpress_timeout = timeout;
5375 }
5376
5377 /**
5378  * Get the timeout in seconds for the longpress event
5379  *
5380  * @param obj The genlist object
5381  * @return timeout in seconds
5382  *
5383  * @ingroup Genlist
5384  */
5385 EAPI double
5386 elm_genlist_longpress_timeout_get(const Evas_Object *obj)
5387 {
5388    ELM_CHECK_WIDTYPE(obj, widtype) 0;
5389    Widget_Data *wd = elm_widget_data_get(obj);
5390    if (!wd) return 0;
5391    return wd->longpress_timeout;
5392 }
5393
5394 /**
5395  * Set the scrollbar policy
5396  *
5397  * This sets the scrollbar visibility policy for the given genlist
5398  * scroller. ELM_SMART_SCROLLER_POLICY_AUTO means the scrollbar is
5399  * made visible if it is needed, and otherwise kept hidden.
5400  * ELM_SMART_SCROLLER_POLICY_ON turns it on all the time, and
5401  * ELM_SMART_SCROLLER_POLICY_OFF always keeps it off. This applies
5402  * respectively for the horizontal and vertical scrollbars.
5403  *
5404  * @param obj The genlist object
5405  * @param policy_h Horizontal scrollbar policy
5406  * @param policy_v Vertical scrollbar policy
5407  *
5408  * @ingroup Genlist
5409  */
5410 EAPI void
5411 elm_genlist_scroller_policy_set(Evas_Object        *obj,
5412                                 Elm_Scroller_Policy policy_h,
5413                                 Elm_Scroller_Policy policy_v)
5414 {
5415    ELM_CHECK_WIDTYPE(obj, widtype);
5416    Widget_Data *wd = elm_widget_data_get(obj);
5417    if (!wd) return;
5418    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
5419        (policy_v >= ELM_SCROLLER_POLICY_LAST))
5420      return;
5421    if (wd->scr)
5422      elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
5423 }
5424
5425 /**
5426  * Get the scrollbar policy
5427  *
5428  * @param obj The genlist object
5429  * @param policy_h Horizontal scrollbar policy
5430  * @param policy_v Vertical scrollbar policy
5431  *
5432  * @ingroup Genlist
5433  */
5434 EAPI void
5435 elm_genlist_scroller_policy_get(const Evas_Object   *obj,
5436                                 Elm_Scroller_Policy *policy_h,
5437                                 Elm_Scroller_Policy *policy_v)
5438 {
5439    ELM_CHECK_WIDTYPE(obj, widtype);
5440    Widget_Data *wd = elm_widget_data_get(obj);
5441    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
5442    if ((!wd) || (!wd->scr)) return;
5443    elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
5444    if (policy_h) *policy_h = (Elm_Scroller_Policy)s_policy_h;
5445    if (policy_v) *policy_v = (Elm_Scroller_Policy)s_policy_v;
5446 }
5447
5448 /****************************************************************************/
5449 /**
5450  * Set reorder mode
5451  *
5452  *
5453  * @param obj The genlist object
5454  * @param reorder_mode The reorder mode
5455  * (EINA_TRUE = on, EINA_FALSE = off)
5456  *
5457  * @ingroup Genlist
5458  */
5459 EAPI void
5460 elm_genlist_reorder_mode_set(Evas_Object *obj,
5461                              Eina_Bool    reorder_mode)
5462 {
5463    ELM_CHECK_WIDTYPE(obj, widtype);
5464    Widget_Data *wd = elm_widget_data_get(obj);
5465    if (!wd) return;
5466    wd->reorder_mode = reorder_mode;
5467 }
5468
5469 /**
5470  * Get the reorder mode
5471  *
5472  * @param obj The genlist object
5473  * @return The reorder mode
5474  * (EINA_TRUE = on, EINA_FALSE = off)
5475  *
5476  * @ingroup Genlist
5477  */
5478 EAPI Eina_Bool
5479 elm_genlist_reorder_mode_get(const Evas_Object *obj)
5480 {
5481    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5482    Widget_Data *wd = elm_widget_data_get(obj);
5483    if (!wd) return EINA_FALSE;
5484    return wd->reorder_mode;
5485 }
5486
5487 EAPI void
5488 elm_genlist_item_move_after(Elm_Genlist_Item *it, Elm_Genlist_Item *after)
5489 {
5490    return;
5491 }
5492
5493 EAPI void
5494 elm_genlist_item_move_before(Elm_Genlist_Item *it, Elm_Genlist_Item *before)
5495 {
5496    return;
5497 }
5498
5499 static void
5500 _effect_item_move_after(Elm_Genlist_Item *it, Elm_Genlist_Item *after)
5501 {
5502    if (!it) return;
5503    if (!after) return;
5504
5505    if (it->wd->ed->ec->move)
5506       it->wd->ed->ec->move(it->base.widget, it, after, EINA_TRUE);
5507
5508 // printf("MOVE AFTER : %d  after = %d \n", (int)elm_genlist_item_data_get(it)+1, (int)elm_genlist_item_data_get(after)+1);
5509    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
5510    it->wd->reorder_deleted = EINA_TRUE;
5511    _item_block_del(it);
5512
5513    it->wd->items = eina_inlist_append_relative(it->wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(after));
5514    it->rel = after;
5515    it->rel->relcount++;
5516    it->before = EINA_FALSE;
5517    _item_queue(it->wd, it);
5518 }
5519
5520 static void
5521 _effect_item_move_before(Elm_Genlist_Item *it, Elm_Genlist_Item *before)
5522 {
5523    if (!it) return;
5524    if (!before) return;
5525
5526    if (it->wd->ed->ec->move)
5527       it->wd->ed->ec->move(it->base.widget, it, before, EINA_FALSE);
5528
5529 //   printf("MOVE BEFORE : %d  before = %d \n", (int)elm_genlist_item_data_get(it)+1, (int)elm_genlist_item_data_get(before)+1);
5530    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
5531    it->wd->reorder_deleted = EINA_TRUE;
5532    _item_block_del(it);
5533    it->wd->items = eina_inlist_prepend_relative(it->wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(before));
5534    it->rel = before;
5535    it->rel->relcount++;
5536    it->before = EINA_TRUE;
5537    _item_queue(it->wd, it);
5538 }
5539
5540 EAPI void
5541 elm_genlist_effect_set(const Evas_Object *obj, Eina_Bool emode)
5542 {
5543    ELM_CHECK_WIDTYPE(obj, widtype);
5544    Widget_Data *wd = elm_widget_data_get(obj);
5545    if (!wd) return;
5546    wd->effect_mode = emode;
5547    //   wd->point_rect = evas_object_rectangle_add(evas_object_evas_get(wd->obj));
5548    //   evas_object_resize(wd->point_rect, 10, 25);
5549    //   evas_object_color_set(wd->point_rect, 255, 0, 0, 130);
5550    //   evas_object_show(wd->point_rect);
5551    //   evas_object_hide(wd->point_rect);
5552 }
5553
5554 static Evas_Object*
5555 _create_tray_alpha_bg(const Evas_Object *obj)
5556 {
5557    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
5558    Widget_Data *wd = elm_widget_data_get(obj);
5559    if (!wd) return NULL;
5560
5561    Evas_Object *bg = NULL;
5562    Evas_Coord ox, oy, ow, oh;
5563
5564    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
5565    bg  =  evas_object_rectangle_add(evas_object_evas_get(wd->obj));
5566    evas_object_color_set(bg,0,0,0,0);
5567    evas_object_resize(bg , ow, oh);
5568    evas_object_move(bg , ox, oy);
5569    evas_object_show(bg);
5570    evas_object_hide(bg);
5571    return bg ;
5572 }
5573
5574 static unsigned int
5575 current_time_get()
5576 {
5577    struct timeval timev;
5578
5579    gettimeofday(&timev, NULL);
5580    return ((timev.tv_sec * 1000) + ((timev.tv_usec) / 1000));
5581 }
5582
5583 // added for item moving animation.
5584 static Eina_Bool
5585 _item_moving_effect_timer_cb(void *data)
5586 {
5587    Widget_Data *wd = data;
5588    if (!wd) return EINA_FALSE;
5589    Item_Block *itb;
5590    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh;
5591    Elm_Genlist_Item *it, *it2;
5592    const Eina_List *l;
5593    double time = 0.4, t;
5594    int y, dy;
5595    Eina_Bool check, end = EINA_FALSE;
5596    //   static Eina_Bool first = EINA_TRUE;
5597    int in = 0;
5598
5599    t = ((0.0 > (t = current_time_get() - wd->start_time)) ? 0.0 : t) / 1000;
5600
5601    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
5602    evas_output_viewport_get(evas_object_evas_get(wd->pan_smart), &cvx, &cvy, &cvw, &cvh);
5603    if (t > time) end = EINA_TRUE;
5604    EINA_INLIST_FOREACH(wd->blocks, itb)
5605      {
5606         itb->w = wd->minw;
5607         if (ELM_RECTS_INTERSECT(itb->x - wd->pan_x + ox,
5608                                 itb->y - wd->pan_y + oy,
5609                                 itb->w, itb->h,
5610                                 cvx, cvy, cvw, cvh))
5611           {
5612              EINA_LIST_FOREACH(itb->items, l, it)
5613                {
5614                   if (wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE)
5615                     {
5616                        it2 = it;
5617                        check = EINA_FALSE;
5618                        do {
5619                             if(it2->parent == wd->expand_item) check = EINA_TRUE;
5620                             it2 = it2->parent;
5621                        } while(it2);
5622                        if(check) continue;
5623                     }
5624                   dy = 0;
5625                   //printf(" s: %d %d ", oy, oh);
5626                   if(wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND)
5627                      dy = it->scrl_y - it->old_scrl_y;
5628                   else if(wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT)
5629                     {
5630                        //                  printf("%d %d\n", it->old_scrl_y, wd->expand_item_end);
5631                        if(wd->expand_item_end < it->old_scrl_y)
5632                           dy = wd->expand_item_gap;
5633                     }
5634                   else if (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE)
5635                     {
5636                         if (wd->expand_item_end < it->old_scrl_y)
5637                           dy = wd->expand_item_gap;
5638                     }
5639                   if (t <= time)
5640                      y = (1 * sin((t / time) * (M_PI / 2)) * dy);
5641                   else
5642                     {
5643                        end = EINA_TRUE;
5644                        y = dy;
5645                     }
5646
5647                   if (!it->old_scrl_y)
5648                      it->old_scrl_y  = it->scrl_y;
5649
5650
5651                   if (it->old_scrl_y + y < oy + oh)
5652                     {
5653                        if (!it->realized) _item_realize(it, in, 0);
5654                     }
5655                   if (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE && it->old_scrl_y + y < it->scrl_y)
5656                      it->old_scrl_y = it->scrl_y - y;
5657                   in++;
5658
5659                  if (wd->move_effect_mode != ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE ||
5660                        (wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_DELETE && it->old_scrl_y + y >= it->scrl_y))
5661                    {
5662                       if (wd->edit_mode) _effect_item_controls(it, it->scrl_x, it->old_scrl_y + y);
5663                       else
5664                        {
5665                            evas_object_resize(it->base.view, it->w, it->h);
5666                            evas_object_move(it->base.view, it->scrl_x, it->old_scrl_y + y);
5667                            evas_object_show(it->base.view);
5668                            evas_object_raise(it->base.view);
5669                        }
5670
5671                       if (it->group_item) evas_object_raise(it->group_item->base.view);
5672                    }
5673
5674                   if(wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND)
5675                     {
5676                        it2 = elm_genlist_item_prev_get(it);
5677                        while(it2)
5678                          {
5679                             if((it2->scrl_y < it->old_scrl_y + y) && (it2->expanded_depth > it->expanded_depth))
5680                               {
5681                                  if(!it2->effect_done)
5682                                    {
5683                                       //edje_object_signal_emit(it2->base.view, "elm,state,expand_flip", "");
5684                                       evas_object_move(it2->base.view, it2->scrl_x, it2->scrl_y);
5685                                       evas_object_show(it2->base.view);
5686                                       it2->effect_done = EINA_TRUE;
5687                                    }
5688                                 // break;
5689                               }
5690                             it2 = elm_genlist_item_prev_get(it2);
5691                          }
5692                     }
5693                   else if(wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT)
5694                     {
5695                        it2 = elm_genlist_item_prev_get(it);
5696                        while(it2)
5697                          {
5698                             if((it2->scrl_y > it->old_scrl_y + y) && (it2->expanded_depth > it->expanded_depth))
5699                               {
5700                                  if(!it2->effect_done)
5701                                    {
5702                                       edje_object_signal_emit(it2->base.view, "elm,state,hide", "");
5703                                       it2->effect_done = EINA_TRUE;
5704                                    }
5705                               }
5706                             else
5707                                break;
5708                             it2 = elm_genlist_item_prev_get(it2);
5709                          }
5710                     }
5711                }
5712           }
5713      }
5714    //   first = EINA_FALSE;
5715    //   printf("\n");
5716    if (end)
5717      {
5718         if (wd->item_moving_effect_timer)
5719           {
5720              if(wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT)
5721                 _item_subitems_clear(wd->expand_item);
5722              EINA_INLIST_FOREACH(wd->blocks, itb)
5723                {
5724                   EINA_LIST_FOREACH(itb->items, l, it)
5725                     {
5726                        it->effect_done = EINA_TRUE;
5727                        it->old_scrl_y = it->scrl_y;
5728                     }
5729                }
5730           }
5731         //evas_render(evas_object_evas_get(wd->obj));
5732         wd->item_moving_effect_timer = NULL;
5733         //        first = EINA_TRUE;
5734
5735         _item_auto_scroll(wd);
5736         evas_object_lower(wd->alpha_bg);
5737         evas_object_hide(wd->alpha_bg);
5738         if (wd->calc_job) ecore_job_del(wd->calc_job);
5739         wd->calc_job = ecore_job_add(_calc_job, wd);
5740         elm_smart_scroller_bounce_animator_disabled_set(wd->scr, EINA_FALSE);
5741         wd->move_effect_mode = ELM_GENLIST_ITEM_MOVE_EFFECT_NONE;
5742
5743         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
5744         evas_object_smart_callback_call(wd->obj, "effect_done", NULL);
5745         return ECORE_CALLBACK_CANCEL;
5746      }
5747    return ECORE_CALLBACK_RENEW;
5748 }
5749
5750 static void
5751 _emit_contract(Elm_Genlist_Item *it)
5752 {
5753    Elm_Genlist_Item *it2;
5754    Eina_List *l;
5755
5756    //   printf("%p is emited contract\n", it);
5757    edje_object_signal_emit(it->base.view, "elm,state,contract_flip", "");
5758    it->effect_done = EINA_FALSE;
5759
5760    EINA_LIST_FOREACH(it->items, l, it2)
5761       if(it2)
5762          _emit_contract(it2);
5763 }
5764
5765 // added for item moving animation.
5766 static int
5767 _item_flip_effect_show(Elm_Genlist_Item *it)
5768 {
5769    Elm_Genlist_Item *it2;
5770    Eina_List *l;
5771    Widget_Data *wd = it->wd;
5772    Eina_Bool check = EINA_FALSE;
5773
5774    it2 = elm_genlist_item_next_get(it);
5775    while(it2)
5776      {
5777         if(it2->expanded_depth <= it->expanded_depth) check = EINA_TRUE;
5778         it2 = elm_genlist_item_next_get(it2);
5779      }
5780    EINA_LIST_FOREACH(it->items, l, it2)
5781      {
5782         if (it2->parent && it == it2->parent)
5783           {
5784              if(wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_EXPAND)
5785                {
5786                   edje_object_signal_emit(it2->base.view, "flip_item", "");
5787                   if(check)
5788                      evas_object_move(it2->base.view, -9999, -9999);
5789                   else
5790                      evas_object_show(it2->base.view);
5791                }
5792              else if(wd->move_effect_mode == ELM_GENLIST_ITEM_MOVE_EFFECT_CONTRACT)
5793                 _emit_contract(it2);
5794           }
5795      }
5796
5797    return ECORE_CALLBACK_CANCEL;
5798 }
5799
5800 /*
5801 static void
5802 _elm_genlist_pinch_zoom_execute(Evas_Object *obj, Eina_Bool emode)
5803 {
5804    printf("!!! NOW FIXING \n");
5805 }
5806 */
5807
5808 /**
5809  * Set pinch zoom mode
5810  *
5811  * @param obj The genlist object
5812  * @param emode
5813  * (EINA_TRUE = pinch contract (zoom in), EINA_FALSE = pinch expand (zoom out)
5814  *
5815  * @ingroup Genlist
5816  */
5817 EAPI void
5818 elm_genlist_pinch_zoom_mode_set(Evas_Object *obj, Eina_Bool emode)
5819 {
5820    printf("!!! NOW FIXING \n");
5821 }
5822
5823 /**
5824  * Get pinch zoom mode
5825  *
5826  * @param obj The genlist object
5827  * @return The pinch mode
5828  * (EINA_TRUE = pinch contract (zoom in), EINA_FALSE = pinch expand (zoom out)
5829  *
5830  * @ingroup Genlist
5831  */
5832 EAPI Eina_Bool
5833 elm_genlist_pinch_zoom_mode_get(const Evas_Object *obj)
5834 {
5835    printf("!!! NOW FIXING \n");
5836    return EINA_FALSE;
5837 }
5838
5839 EAPI void
5840 elm_genlist_pinch_zoom_set(Evas_Object *obj, Eina_Bool emode)
5841 {
5842    printf("!!! NOW FIXING \n");
5843 }
5844
5845
5846 ////////////////////////////////////////////////////////////////////////
5847 //  EDIT  MODE
5848 ////////////////////////////////////////////////////////////////////////
5849
5850 static void
5851 _effect_item_controls(Elm_Genlist_Item *it, int itx, int ity)
5852 {
5853    if (!it->wd->edit_mode) return;
5854    evas_object_resize(it->edit_obj,it->w, it->h);
5855    evas_object_move(it->edit_obj, itx, ity);
5856 }
5857
5858 static void
5859 _effect_item_realize(Elm_Genlist_Item *it, Eina_Bool effect_on)
5860 {
5861    if ((it->effect_item_realized) || (it->delete_me)) return;
5862    char buf[1024];
5863
5864    it->edit_obj = edje_object_add(evas_object_evas_get(it->base.widget));
5865    edje_object_scale_set(it->edit_obj, elm_widget_scale_get(it->base.widget) *
5866                          _elm_config->scale);
5867    evas_object_smart_member_add(it->edit_obj, it->wd->pan_smart);
5868    elm_widget_sub_object_add(it->base.widget, it->edit_obj);
5869
5870    if (it->flags & ELM_GENLIST_ITEM_SUBITEMS) strncpy(buf, "tree", sizeof(buf));
5871    else strncpy(buf, "item", sizeof(buf));
5872    if (it->wd->compress) strncat(buf, "_compress", sizeof(buf) - strlen(buf));
5873
5874    strncat(buf, "/", sizeof(buf) - strlen(buf));
5875
5876    if (it->itc->edit_item_style && strcmp(it->itc->edit_item_style, "default"))
5877      {
5878         strncat(buf, it->itc->edit_item_style, sizeof(buf) - strlen(buf));
5879         _elm_theme_object_set(it->base.widget, it->edit_obj, "genlist", buf, elm_widget_style_get(it->base.widget));
5880      }
5881    else
5882      {
5883         _elm_theme_object_set(it->base.widget, it->edit_obj, "genlist", "item/edit_default", elm_widget_style_get(it->base.widget));
5884      }
5885
5886    if (it->wd->reorder_mode)
5887      {
5888         if (effect_on) edje_object_signal_emit(it->edit_obj, "elm,state,reorder_enabled_effect", "elm");
5889         else edje_object_signal_emit(it->edit_obj, "elm,state,reorder_enabled", "elm");
5890      }
5891    if (effect_on) edje_object_signal_emit(it->edit_obj, "elm,state,emode_enabled_effect", "elm");
5892    else edje_object_signal_emit(it->edit_obj, "elm,state,emode_enabled", "elm");
5893
5894    if (it->disabled) edje_object_signal_emit(it->edit_obj, "elm,state,disabled", "elm");
5895    else edje_object_signal_emit(it->edit_obj, "elm,state,enabled", "elm");
5896
5897
5898    if ((it->wd->edit_mode))
5899      {
5900         if (it->itc->func.icon_get)
5901           {
5902              const Eina_List *l;
5903              const char *key;
5904
5905              it->icons = elm_widget_stringlist_get(edje_object_data_get(it->edit_obj, "edit_icons"));
5906              EINA_LIST_FOREACH(it->icons, l, key)
5907                {
5908                   Evas_Object *ic = it->itc->func.icon_get
5909                      (it->base.data, it->base.widget, l->data);
5910
5911                   if (ic)
5912                     {
5913                        it->edit_icon_objs = eina_list_append(it->edit_icon_objs, ic);
5914                        edje_object_part_swallow(it->edit_obj, key, ic);
5915                        evas_object_show(ic);
5916                        elm_widget_sub_object_add(it->base.widget, ic);
5917                     }
5918                }
5919           }
5920      }
5921    edje_object_part_swallow(it->edit_obj, "original_edc", it->base.view);
5922    _effect_item_controls(it,it->scrl_x, it->scrl_y);
5923    evas_object_show(it->edit_obj);
5924
5925    it->effect_item_realized = EINA_TRUE;
5926    it->want_unrealize = EINA_FALSE;
5927 }
5928
5929 static void
5930 _effect_item_unrealize(Elm_Genlist_Item *it)
5931 {
5932    Evas_Object *icon;
5933
5934    if (!it->effect_item_realized) return;
5935    if (it->wd->reorder_it && it->wd->reorder_it == it) return;
5936
5937    edje_object_signal_emit(it->edit_obj, "elm,state,reorder_disable_effect", "elm");
5938    edje_object_signal_emit(it->edit_obj, "elm,state,sel,disable", "elm");
5939    edje_object_message_signal_process(it->edit_obj);
5940    edje_object_part_unswallow(it->edit_obj, it->base.view);
5941    evas_object_smart_member_add(it->base.view, it->wd->pan_smart);
5942    elm_widget_sub_object_add(it->base.widget, it->base.view);
5943    //   evas_object_smart_callback_call(it->edit_obj, "unrealized", it);
5944    //   _item_cache_add(it);
5945    evas_object_del(it->edit_obj);
5946    it->edit_obj = NULL;
5947    EINA_LIST_FREE(it->edit_icon_objs, icon)
5948       evas_object_del(icon);
5949
5950 //   edje_object_signal_emit(it->edit_obj, "elm,state,edit_end,disable", "elm");
5951    it->effect_item_realized = EINA_FALSE;
5952 }
5953
5954 /**
5955  * Get Genlist edit mode
5956  *
5957  * @param obj The genlist object
5958  * @return The edit mode status
5959  * (EINA_TRUE = edit mode, EINA_FALSE = normal mode
5960  *
5961  * @ingroup Genlist
5962  */
5963 EAPI Eina_Bool
5964 elm_genlist_edit_mode_get(const Evas_Object *obj)
5965 {
5966    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
5967    Widget_Data *wd = elm_widget_data_get(obj);
5968    if (!wd) return EINA_FALSE;
5969
5970    if (wd->edit_mode) return EINA_TRUE;
5971    else return EINA_FALSE;
5972 }
5973
5974 /**
5975  * Set Genlist edit mode
5976  *
5977  * This sets Genlist edit mode.
5978  *
5979  * @param obj The Genlist object
5980  * @param emode ELM_GENLIST_EDIT_MODE_{NONE & REORDER & INSERT & DELETE & SELECT & SELECT_ALL}
5981  * @param edit_class Genlist edit class (Elm_Genlist_Edit_Class structure)
5982  *
5983  * @ingroup Genlist
5984  */
5985 EAPI void
5986 elm_genlist_edit_mode_set(Evas_Object *obj, Eina_Bool edit_mode)
5987 {
5988    ELM_CHECK_WIDTYPE(obj, widtype);
5989
5990    Item_Block *itb;
5991    Eina_List *l;
5992    Elm_Genlist_Item *it;
5993
5994    Widget_Data *wd = elm_widget_data_get(obj);
5995    if (!wd) return;
5996    if (wd->edit_mode == edit_mode) return;
5997
5998    wd->edit_mode = edit_mode;
5999    if (!wd->edit_mode)
6000      {
6001         EINA_INLIST_FOREACH(wd->blocks, itb)
6002           {
6003              if (itb->realized)
6004                {
6005                   EINA_LIST_FOREACH(itb->items, l, it)
6006                     {
6007                        if (it->flags != ELM_GENLIST_ITEM_GROUP && it->realized)
6008                          {
6009                             _effect_item_unrealize(it);
6010                          }
6011                     }
6012                }
6013           }
6014         _item_cache_zero(wd);
6015      }
6016    else
6017      {
6018
6019         EINA_INLIST_FOREACH(wd->blocks, itb)
6020           {
6021              if (itb->realized)
6022                {
6023                   EINA_LIST_FOREACH(itb->items, l, it)
6024                     {
6025                        if (it->flags != ELM_GENLIST_ITEM_GROUP && it->realized)
6026                          {
6027                             if(it->selected) _item_unselect(it);
6028                             if (it->itc->edit_item_style) _effect_item_realize(it, EINA_TRUE);
6029                          }
6030                     }
6031                 }
6032            }
6033       }
6034
6035    if (wd->calc_job) ecore_job_del(wd->calc_job);
6036    wd->calc_job = ecore_job_add(_calc_job, wd);
6037 }
6038
6039 /**
6040  * Delete selected items in genlist edit mode.
6041  *
6042  * @param obj The genlist object
6043  *
6044  * @ingroup Genlist
6045  */
6046 EAPI void
6047 elm_genlist_edit_selected_items_del(Evas_Object *obj)
6048 {
6049    fprintf(stderr, "=================> Caution!!! <========================\n");
6050    fprintf(stderr, "==> elm_genlist_edit_selected_items_del() is deprecated. <=======\n");
6051    fprintf(stderr, "=======================================================\n");
6052 }
6053
6054 EAPI void
6055 elm_genlist_selected_items_del(Evas_Object *obj)
6056 {
6057    fprintf(stderr, "=================> Caution!!! <========================\n");
6058    fprintf(stderr, "==> elm_genlist_selected_items_del() is deprecated. <=======\n");
6059    fprintf(stderr, "==> Please use elm_genlist_edit_selected_items_del() instead. <==\n");
6060    fprintf(stderr, "=======================================================\n");
6061 }
6062
6063 /**
6064  * Get a list of selected items in genlist
6065  *
6066  * This returns a list of the selected items in the genlist. The list
6067  * contains Elm_Genlist_Item pointers. The list must be freed by the
6068  * caller when done with eina_list_free(). The item pointers in the list
6069  * are only vallid so long as those items are not deleted or the genlist is
6070  * not deleted.
6071  *
6072  * @param obj The genlist object
6073  * @return The list of selected items, nor NULL if none are selected.
6074  *
6075  * @ingroup Genlist
6076  */
6077 EAPI Eina_List *
6078 elm_genlist_edit_selected_items_get(const Evas_Object *obj)
6079 {
6080    fprintf(stderr, "========================> Caution!!! <==========================\n");
6081    fprintf(stderr, "==> elm_genlist_edit_selected_items_get() is deprecated. <=======\n");
6082    fprintf(stderr, "================================================================\n");
6083    return NULL;
6084 }
6085
6086 // TODO : add comment
6087 EAPI void
6088 elm_genlist_edit_item_selected_set(Elm_Genlist_Item *it,
6089                                    Eina_Bool         selected)
6090 {
6091    fprintf(stderr, "========================> Caution!!! <==========================\n");
6092    fprintf(stderr, "==> elm_genlist_edit_item_selected_set() is deprecated. <=======\n");
6093    fprintf(stderr, "================================================================\n");
6094 }
6095
6096 // TODO : add comment
6097 EAPI Eina_Bool
6098 elm_genlist_edit_item_selected_get(const Elm_Genlist_Item *it)
6099 {
6100    fprintf(stderr, "========================> Caution!!! <==========================\n");
6101    fprintf(stderr, "==> elm_genlist_edit_item_selected_get() is deprecated. <=======\n");
6102    fprintf(stderr, "================================================================\n");
6103    return EINA_FALSE;
6104 }
6105
6106 /**
6107  * Set a given item's rename mode
6108  *
6109  * This renames the item's label from genlist
6110  *
6111  * @param it The item
6112  * @param emode set if emode is EINA_TRUE, unset if emode is EINA_FALSE
6113  *
6114  * @ingroup Genlist
6115  */
6116 EAPI Evas_Object *
6117 elm_genlist_item_rename_mode_set(Elm_Genlist_Item *it, int emode)
6118 {
6119    if (!it) return NULL;
6120    if (it->wd->queue_idler) return NULL;
6121
6122    const Eina_List *l, *list, *l2;
6123    const char *label, *rename_swallow_part;
6124    char *s;
6125    Eina_Bool done = EINA_FALSE;
6126    int label_cnt = 0 , swallow_part_cnt = 0;
6127
6128    Item_Block *itb;
6129    Evas_Object *editfield;
6130    Evas_Object *entry = NULL;
6131    int edit_field_cnt = 0;
6132
6133    EINA_INLIST_FOREACH(it->wd->blocks, itb)
6134      {
6135         if (itb->realized)
6136           {
6137              Eina_List *l;
6138              Elm_Genlist_Item *it;
6139
6140              EINA_LIST_FOREACH(itb->items, l, it)
6141                {
6142                   if (it->renamed)
6143                     {
6144                        it->renamed = EINA_FALSE;
6145                        if (it->selected)  _item_unselect(it);
6146                        EINA_LIST_FOREACH(it->wd->edit_field, l2, editfield)
6147                          {
6148                             entry = elm_editfield_entry_get(editfield);
6149                             const char *text = elm_entry_entry_get(entry);
6150                            if (it->itc->func.label_changed)
6151                                it->itc->func.label_changed(it->base.data, it, text, edit_field_cnt++);
6152                          }
6153                        EINA_LIST_FREE(it->wd->edit_field, editfield)
6154                          evas_object_del(editfield);
6155                        it->wd->edit_field = NULL;
6156
6157                        if (it->wd->edit_mode)
6158                          {
6159                             edje_object_signal_emit(it->edit_obj, "elm,state,edit_end,enable", "elm");
6160                             edje_object_signal_emit(it->edit_obj, "elm,state,rename,disable", "elm");
6161                             if (it->wd->edit_mode & ELM_GENLIST_EDIT_MODE_SELECT)
6162                                edje_object_signal_emit(it->edit_obj, "elm,state,sel_uncheck", "elm");
6163                          }
6164
6165                        if(!it->wd->edit_mode) _effect_item_unrealize(it);
6166                        done = EINA_TRUE;
6167                     }
6168                }
6169           }
6170         else
6171           {
6172              if (done) break;
6173           }
6174      }
6175
6176    if (emode)
6177      {
6178         it->renamed = EINA_TRUE;
6179         if (it->wd->edit_mode == ELM_GENLIST_EDIT_MODE_NONE)
6180           {
6181              it->wd->edit_mode = 0xF0;
6182              _effect_item_realize(it, EINA_TRUE);
6183              it->wd->edit_mode = ELM_GENLIST_EDIT_MODE_NONE;
6184           }
6185
6186         edje_object_signal_emit(it->edit_obj, "elm,state,rename,enable", "elm");
6187         EINA_LIST_FOREACH(it->labels, list, label)
6188           {
6189              if (it->itc->func.label_get)
6190                {
6191                   swallow_part_cnt = 0;
6192
6193                   Eina_List *rename = elm_widget_stringlist_get(edje_object_data_get(it->edit_obj, "rename"));
6194                   EINA_LIST_FOREACH(rename, l, rename_swallow_part)
6195                     {
6196                        if (label_cnt == swallow_part_cnt)
6197                          {
6198                             editfield = elm_editfield_add(it->base.widget);
6199                             it->wd->edit_field = eina_list_append(it->wd->edit_field, editfield);
6200
6201                             elm_editfield_entry_single_line_set(editfield, EINA_TRUE);
6202                             elm_editfield_eraser_set(editfield, EINA_TRUE);
6203                             edje_object_part_swallow(it->edit_obj, rename_swallow_part, editfield);
6204                             elm_widget_sub_object_add(it->edit_obj, editfield);
6205
6206                             evas_object_show(editfield);
6207
6208                             s = it->itc->func.label_get((void *)it->base.data, it->base.widget, list->data);
6209                             if (s)
6210                               {
6211                                  entry = elm_editfield_entry_get(editfield);
6212                                  elm_entry_entry_set(entry,s);
6213                                  elm_entry_cursor_end_set(entry);
6214                                  free(s);
6215                               }
6216                             else
6217                                elm_editfield_guide_text_set(editfield, "Text Input");
6218                          }
6219                        swallow_part_cnt++;
6220                     }
6221                   label_cnt++;
6222                }
6223           }
6224         elm_widget_focused_object_clear(elm_widget_focused_object_get(it->wd->obj));
6225         elm_widget_focus_set(editfield, EINA_TRUE);
6226      }
6227
6228    return entry;
6229 }
6230
6231 static void _sweep_finish(void *data, Evas_Object *o, const char *emission, const char *source)
6232 {
6233    Elm_Genlist_Item *it = data;
6234
6235    _delete_sweep_objs(it);
6236 }
6237
6238 static Eina_Bool
6239 _scr_hold_timer_cb(void *data)
6240 {
6241    Elm_Genlist_Item *it = data;
6242    elm_smart_scroller_hold_set(it->wd->scr, EINA_FALSE);
6243    it->wd->scr_hold_timer = NULL;
6244    return ECORE_CALLBACK_CANCEL;
6245 }
6246
6247 static void
6248 _delete_sweep_objs(Elm_Genlist_Item *it)
6249 {
6250    Evas_Object *ic;
6251
6252    elm_widget_stringlist_free(it->sweep_labels);
6253    it->sweep_labels = NULL;
6254    elm_widget_stringlist_free(it->sweep_icons);
6255    it->sweep_icons = NULL;
6256    EINA_LIST_FREE(it->sweep_icon_objs, ic)
6257       evas_object_del(ic);
6258 }
6259
6260 static void
6261 _create_sweep_objs(Elm_Genlist_Item *it)
6262 {
6263    Evas_Object *ic;
6264    const Eina_List *l;
6265    const char *key;
6266
6267    if (it->itc->func.label_get)
6268      {
6269         it->sweep_labels =
6270            elm_widget_stringlist_get(edje_object_data_get(it->base.view,
6271                                                           "sweep_labels"));
6272         EINA_LIST_FOREACH(it->sweep_labels, l, key)
6273           {
6274              char *s = it->itc->func.label_get
6275                 ((void *)it->base.data, it->base.widget, l->data);
6276
6277              if (s)
6278                {
6279                   edje_object_part_text_set(it->base.view, l->data, s);
6280                   free(s);
6281                }
6282           }
6283      }
6284    if (it->itc->func.icon_get)
6285      {
6286         it->sweep_icons =
6287            elm_widget_stringlist_get(edje_object_data_get(it->base.view,
6288                                                           "sweep_icons"));
6289         EINA_LIST_FOREACH(it->sweep_icons, l, key)
6290           {
6291              ic = it->itc->func.icon_get
6292                 ((void *)it->base.data, it->base.widget, l->data);
6293
6294              if (ic)
6295                {
6296                   it->sweep_icon_objs = eina_list_append(it->sweep_icon_objs, ic);
6297                   edje_object_part_swallow(it->base.view, key, ic);
6298                   evas_object_show(ic);
6299                   elm_widget_sub_object_add(it->base.widget, ic);
6300                }
6301           }
6302      }
6303 }
6304
6305 static void
6306 _item_slide(Elm_Genlist_Item *it, Eina_Bool slide_to_right)
6307 {
6308    const Eina_List *l;
6309    Elm_Genlist_Item *it2;
6310    const char *allow_slide;
6311
6312    allow_slide = edje_object_data_get(it->base.view, "allow_slide");
6313    if ((!allow_slide) || (atoi(allow_slide) != 1))
6314       return;
6315
6316    if (slide_to_right)
6317      {
6318         if (it->sweeped) return;
6319         if (it->wd->scr_hold_timer)
6320           {
6321              ecore_timer_del(it->wd->scr_hold_timer);
6322              it->wd->scr_hold_timer = NULL;
6323           }
6324         elm_smart_scroller_hold_set(it->wd->scr, EINA_TRUE);
6325         it->wd->scr_hold_timer = ecore_timer_add(0.1, _scr_hold_timer_cb, it);
6326
6327         _delete_sweep_objs(it);
6328         _create_sweep_objs(it);
6329         edje_object_signal_emit(it->base.view, "elm,state,slide,right", "elm");
6330         it->wd->sweeped_items = eina_list_append(it->wd->sweeped_items, it);
6331         it->wassweeped = EINA_TRUE;
6332         it->sweeped = EINA_TRUE;
6333
6334         EINA_LIST_FOREACH(it->wd->sweeped_items, l, it2)
6335           {
6336              if (it2 != it)
6337                {
6338                   it2->sweeped = EINA_FALSE;
6339                   edje_object_signal_emit(it2->base.view, "elm,state,slide,left", "elm");
6340                   edje_object_signal_callback_add(it2->base.view, "elm,action,sweep,left,finish", "elm", _sweep_finish, it2);
6341                   it2->wd->sweeped_items = eina_list_remove(it2->wd->sweeped_items, it2);
6342                }
6343           }
6344      }
6345    else
6346      {
6347         if (!it->sweeped) return;
6348         edje_object_signal_emit(it->base.view, "elm,state,slide,left", "elm");
6349         edje_object_signal_callback_add(it->base.view, "elm,action,sweep,left,finish", "elm", _sweep_finish, it);
6350         it->wd->sweeped_items = eina_list_remove(it->wd->sweeped_items, it);
6351         it->sweeped = EINA_FALSE;
6352      }
6353 }
6354
6355 static void
6356 _item_auto_scroll(void *data)
6357 {
6358    Widget_Data *wd = data;
6359    if (!wd) return;
6360
6361    if ((wd->expand_item) && (!wd->auto_scrolled))
6362      {
6363         Elm_Genlist_Item  *it;
6364         Eina_List *l;
6365         Evas_Coord ox, oy, ow, oh;
6366         evas_object_geometry_get(wd->obj, &ox, &oy, &ow, &oh);
6367
6368         wd->auto_scrolled = EINA_TRUE;
6369         if (wd->expand_item->scrl_y > (oh + oy) / 2)
6370           {
6371             EINA_LIST_FOREACH(wd->expand_item->items, l, it)
6372               {
6373                  elm_genlist_item_bring_in(it);
6374               }
6375           }
6376      }
6377 }