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