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