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