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