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