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