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