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