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