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