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