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