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