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