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