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