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