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