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