Merge branch 'master' of chuneon.park@165.213.180.234:/git/slp2.0/slp2.0-pkgs/EFL...
[framework/uifw/elementary.git] / src / lib / elm_genlist.c
1 /*
2  *
3  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
4  */
5 #include <Elementary.h>
6 #include "elm_priv.h"
7
8 /**
9  * @defgroup Genlist Genlist
10  *
11  * The aim was to have  more expansive list that the simple list in
12  * Elementary that could have more flexible items and allow many more entries
13  * while still being fast and low on memory usage. At the same time it was
14  * also made to be able to do tree structures. But the price to pay is more
15  * complexity when it comes to usage. If all you want is a simple list with
16  * icons and a single label, use the normal List object.
17  *
18  * Signals that you can add callbacks for are:
19  *
20  * clicked - This is called when a user has double-clicked an item. The
21  * event_info parameter is the genlist item that was double-clicked.
22  *
23  * selected - This is called when a user has made an item selected. The
24  * event_info parameter is the genlist item that was selected.
25  *
26  * unselected - This is called when a user has made an item unselected. The
27  * event_info parameter is the genlist item that was unselected.
28  *
29  * expanded -  This is called when elm_genlist_item_expanded_set() is called
30  * and the item is now meant to be expanded. The event_info parameter is the
31  * genlist item that was indicated to expand. It is the job of this callback
32  * to then fill in the child items.
33  *
34  * contracted - This is called when elm_genlist_item_expanded_set() is called
35  * and the item is now meant to be contracted. The event_info parameter is
36  * the genlist item that was indicated to contract. It is the job of this
37  * callback to then delete the child items
38  *
39  * expand,request - This is called when a user has indicated they want to
40  * expand a tree branch item. The callback should decide if the item can
41  * expand (has any children) and then call elm_genlist_item_expanded_set()
42  * appropriately to set the state. The event_info parameter is the genlist
43  * item that was indicated to expand.
44  *
45  * contract,request - This is called when a user has indicated they want to
46  * contract a tree branch item. The callback should decide if the item can
47  * contract (has any children) and then call elm_genlist_item_expanded_set()
48  * appropriately to set the state. The event_info parameter is the genlist
49  * item that was indicated to contract.
50  *
51  * realized - This is called when the item in the list is created as a real
52  * evas object. event_info parameter is the genlist item that was created.
53  * The object may be deleted at any time, so it is up to the caller to
54  * not use the object pointer from elm_genlist_item_object_get() in a way
55  * where it may point to freed objects.
56  *
57  * drag,start,up - This is called when the item in the list has been dragged
58  * (not scrolled) up.
59  *
60  * drag,start,down - This is called when the item in the list has been dragged
61  * (not scrolled) down.
62  *
63  * drag,start,left - This is called when the item in the list has been dragged
64  * (not scrolled) left.
65  *
66  * drag,start,right - This is called when the item in the list has been dragged
67  * (not scrolled) right.
68  *
69  * drag,stop - This is called when the item in the list has stopped being
70  * dragged.
71  *
72  * drag - This is called when the item in the list is being dragged.
73  *
74  * Genlist has a fairly large API, mostly because it's relatively complex,
75  * trying to be both expansive, powerful and efficient. First we will begin
76  * an overview o the theory behind genlist.
77  *
78  * Evas tracks every object you create. Every time it processes an event
79  * (mouse move, down, up etc.) it needs to walk through objects and find out
80  * what event that affects. Even worse every time it renders display updates,
81  * in order to just calculate what to re-draw, it needs to walk through many
82  * many many objects. Thus, the more objects you keep active, the more
83  * overhead Evas has in just doing its work. It is advisable to keep your
84  * active objects to the minimum working set you need. Also remember that
85  * object creation and deletion carries an overhead, so there is a
86  * middle-ground, which is not easily determined. But don't keep massive lists
87  * of objects you can't see or use. Genlist does this with list objects. It
88  * creates and destroys them dynamically as you scroll around. It groups them
89  * into blocks so it can determine the visibility etc. of a whole block at
90  * once as opposed to having to walk the whole list. This 2-level list allows
91  * for very large numbers of items to be in the list (tests have used up to
92  * 2,000,000 items). Also genlist employs a queue for adding items. As items
93  * may be different sizes, every item added needs to be calculated as to its
94  * size and thus this presents a lot of overhead on populating the list, this
95  * genlist employs a queue. Any item added is queued and spooled off over
96  * time, actually appearing some time later, so if your list has many members
97  * you may find it takes a while for them to all appear, with your process
98  * consuming a lot of CPU while it is busy spooling.
99  *
100  * Genlist also implements a tree structure, but it does so with callbacks to
101  * the application, with the application filling in tree structures when
102  * requested (allowing for efficient building of a very deep tree that could
103  * even be used for file-management). See the above smart signal callbacks for
104  * details.
105  *
106  * An item in the genlist world can have 0 or more text labels (they can be
107  * regular text or textblock – that's up to the style to determine), 0 or
108  * more icons (which are simply objects swallowed into the genlist item) and
109  * 0 or more boolean states that can be used for check, radio or other
110  * indicators by the edje theme style. An item may be one of several styles
111  * (Elementary provides 2 by default - “default” and “double_label”, but this
112  * can be extended by system or application custom themes/overlays/extensions).
113  *
114  * In order to implement the ability to add and delete items on the fly,
115  * Genlist implements a class/callback system where the application provides
116  * a structure with information about that type of item (genlist may contain
117  * multiple different items with different classes, states and styles).
118  * Genlist will call the functions in this struct (methods) when an item is
119  * “realized” (that is created dynamically while scrolling). All objects will
120  * simply be deleted  when no longer needed with evas_object_del(). The
121  * Elm_Genlist_Item_Class structure contains the following members:
122  *
123  * item_style - This is a constant string and simply defines the name of the
124  * item style. It must be specified and the default should be “default”.
125  *
126  * func.label_get - This function is called when an actual item object is
127  * created. The data parameter is the data parameter passed to
128  * elm_genlist_item_append() and related item creation functions. The obj
129  * parameter is the genlist object and the part parameter is the string name
130  * of the text part in the edje design that is listed as one of the possible
131  * labels that can be set. This function must return a strudup()'ed string as
132  * the caller will free() it when done.
133  *
134  * func.icon_get - This function is called when an actual item object is
135  * created. The data parameter is the data parameter passed to
136  * elm_genlist_item_append() and related item creation functions. The obj
137  * parameter is the genlist object and the part parameter is the string name
138  * of the icon part in the edje design that is listed as one of the possible
139  * icons that can be set. This must return NULL for no object or a valid
140  * object. The object will be deleted by genlist on shutdown or when the item
141  * its unrealized.
142  *
143  * func.state_get - This function is called when an actual item object is
144  * created. The data parameter is the data parameter passed to
145  * elm_genlist_item_append() and related item creation functions. The obj
146  * parameter is the genlist object and the part parameter is the string name
147  * of the state part in the edje design that is listed as one of the possible
148  * states that can be set. Return 0 for false or 1 for true. Genlist will
149  * emit a signal to the edje object with “elm,state,XXX,active” “elm” when
150  * true (the default is false), where XXX is the name of the part.
151  *
152  * func.del - This is called when elm_genlist_item_del() is called on an
153  * item, elm_genlist_clear() is called on the genlist, or
154  * elm_genlist_item_subitems_clear() is called to clear sub-items. This is
155  * intended for use when actual genlist items are deleted, so any backing
156  * data attached to the item (e.g. its data parameter on creation) can be
157  * deleted.
158  *
159  * Items can be added by several calls. All of them return a Elm_Genlist_Item
160  * handle that is an internal member inside the genlist. They all take a data
161  * parameter that is meant to be used for a handle to the applications
162  * internal data (eg the struct with the original item data). The parent
163  * parameter is the parent genlist item this belongs to if it is a tree, and
164  * NULL if there is no parent. The flags can be a bitmask of
165  * ELM_GENLIST_ITEM_NONE and ELM_GENLIST_ITEM_SUBITEMS. If
166  * ELM_GENLIST_ITEM_SUBITEMS is set then this item is displayed as a item
167  * that is able to expand and have child items. The func parameter is a
168  * convenience callback that is called when the item is selected and the data
169  * parameter will be the func_data parameter, obj be the genlist object and
170  * vent_info will be the genlist item.
171  *
172  * elm_genlist_item_append() appends an item to the end of the list, or if
173  * there is a parent, to the end of all the child items of the parent.
174  * elm_genlist_item_prepend() is the same but prepends to the beginning of
175  * the list or children list. elm_genlist_item_insert_before() inserts at
176  * item before another item and elm_genlist_item_insert_after() inserts after
177  * the indicated item.
178  *
179  * The application can clear the list with elm_genlist_clear() which deletes
180  * all the items in the list and elm_genlist_item_del() will delete a specific
181  * item. elm_genlist_item_subitems_clear() will clear all items that are
182  * children of the indicated parent item.
183  *
184  * If the application wants multiple items to be able to be selected,
185  * elm_genlist_multi_select_set() can enable this. If the list is
186  * single-selection only (the default), then elm_genlist_selected_item_get()
187  * will return the selected item, if any, or NULL I none is selected. If the
188  * list is multi-select then elm_genlist_selected_items_get() will return a
189  * list (that is only valid as long as no items are modified (added, deleted,
190  * selected or unselected).
191  *
192  * To help inspect list items you can jump to the item at the top of the list
193  * with elm_genlist_first_item_get() which will return the item pointer, and
194  * similarly elm_genlist_last_item_get() gets the item at the end of the list.
195  * elm_genlist_item_next_get() and elm_genlist_item_prev_get() get the next
196  * and previous items respectively relative to the indicated item. Using
197  * these calls you can walk the entire item list/tree. Note that as a tree
198  * the items are flattened in the list, so elm_genlist_item_parent_get() will
199  * let you know which item is the parent (and thus know how to skip them if
200  * wanted).
201  *
202  * There are also convenience functions. elm_genlist_item_genlist_get() will
203  * return the genlist object the item belongs to.  elm_genlist_item_show()
204  * will make the scroller scroll to show that specific item so its visible.
205  * elm_genlist_item_data_get() returns the data pointer set by the item
206  * creation functions.
207  *
208  * If an item changes (state of boolean changes, label or icons change),
209  * then use elm_genlist_item_update() to have genlist update the item with
210  * the new state. Genlist will re-realize the item thus call the functions
211  * in the _Elm_Genlist_Item_Class for that item.
212  *
213  * To programmatically (un)select an item use elm_genlist_item_selected_set().
214  * To get its selected state use elm_genlist_item_selected_get(). Similarly
215  * to expand/contract and item and get its expanded state, use
216  * elm_genlist_item_expanded_set() and elm_genlist_item_expanded_get(). And
217  * again to make an item disabled (unable to be selected and appear
218  * differently) use elm_genlist_item_disabled_set() to set this and
219  * elm_genlist_item_disabled_get() to get the disabled state.
220  *
221  * In general to indicate how the genlist should expand items horizontally to
222  * fill the list area, use elm_genlist_horizontal_mode_set(). Valid modes are
223  * ELM_LIST_LIMIT and ELM_LIST_SCROLL . The default is ELM_LIST_SCROLL. This
224  * mode means that if items are too wide to fit, the scroller will scroll
225  * horizontally. Otherwise items are expanded to fill the width of the
226  * viewport of the scroller. If it is ELM_LIST_LIMIT, Items will be expanded
227  * to the viewport width and limited to that size. This can be combined with
228  * a different style that uses edjes' ellipsis feature (cutting text off like
229  * this: “tex...”).
230  *
231  * Items will only call their selection func and callback when first becoming
232  * selected. Any further clicks will do nothing, unless you enable always
233  * select with elm_genlist_always_select_mode_set(). This means even if
234  * selected, every click will make the selected callbacks be called.
235  * elm_genlist_no_select_mode_set() will turn off the ability to select
236  * items entirely and they will neither appear selected nor call selected
237  * callback functions.
238  *
239  * Remember that you can create new styles and add you own theme augmentation
240  * per application with elm_theme_extension_add(). If you absolutely must
241  * have a specific style that overrides any theme the user or system sets up
242  * you can use elm_theme_overlay_add() to add such a file.
243  */
244
245 typedef struct _Widget_Data Widget_Data;
246 typedef struct _Item_Block Item_Block;
247 typedef struct _Pan Pan;
248 typedef struct _Edit_Data Edit_Data;
249
250 #define GROUP_ALIGN_NORTH 1
251 #define GROUP_ALIGN_WEST 2
252 struct _Widget_Data
253 {
254    Evas_Object *obj, *scr, *pan_smart;
255    Eina_Inlist *items, *blocks, *group_items;
256    Pan *pan;
257    Evas_Coord pan_x, pan_y, minw, minh;
258    Ecore_Job *calc_job, *update_job;
259    Ecore_Idler *queue_idler;
260    Eina_List *queue, *selected;
261    Elm_Genlist_Item *show_item;
262    Elm_List_Mode mode;
263    Eina_Bool on_hold : 1;
264    Eina_Bool multi : 1;
265    Eina_Bool always_select : 1;
266    Eina_Bool longpressed : 1;
267    Eina_Bool wasselected : 1;
268    Eina_Bool no_select : 1;
269    Eina_Bool bring_in : 1;
270    Eina_Bool compress : 1;
271    Eina_Bool homogeneous : 1;
272    int item_width;
273    int item_height;
274    int max_items_per_block;
275    int edit_mode;
276    Eina_Bool animate_edit_controls :1;
277    Edit_Data *ed;
278 };
279 struct _Edit_Data
280 {
281   Elm_Genlist_Edit_Class  *ec;
282   Elm_Genlist_Item *del_item;
283   Elm_Genlist_Item *reorder_item;
284   Elm_Genlist_Item *reorder_rel;
285   Eina_Bool del_confirm_state : 1;
286   Evas_Object *del_confirm;
287 };
288
289 struct _Item_Block
290 {
291    EINA_INLIST;
292    int count;
293    int num;
294    Widget_Data *wd;
295    Eina_List *items;
296    Evas_Coord x, y, w, h, minw, minh;
297    Eina_Bool want_unrealize : 1;
298    Eina_Bool realized : 1;
299    Eina_Bool changed : 1;
300    Eina_Bool updateme : 1;
301    Eina_Bool showme : 1;
302 };
303
304 struct _Elm_Genlist_Item
305 {
306    EINA_INLIST;
307    Widget_Data *wd;
308    Item_Block *block;
309    Eina_List *items;
310    Evas_Coord x, y, w, h, minw, minh, edx;
311    const Elm_Genlist_Item_Class *itc;
312    const void *data;
313    Elm_Genlist_Item *parent;
314    Elm_Genlist_Item_Flags flags;
315    Elm_Genlist_GroupItem *group_item;
316    struct 
317      {
318         Evas_Smart_Cb func;
319         const void *data;
320      } func;
321
322    Evas_Object *base, *spacer, *edit_obj;
323    Eina_List *labels, *icons, *states, *icon_objs;
324    Ecore_Timer *long_timer;
325    Evas_Coord dx, dy, scrl_x, scrl_y;
326
327    Elm_Genlist_Item *rel;
328    int relcount;
329    int walking;
330    Eina_Bool before : 1;
331
332    Eina_Bool want_unrealize : 1;
333    Eina_Bool realized : 1;
334    Eina_Bool selected : 1;
335    Eina_Bool hilighted : 1;
336    Eina_Bool expanded : 1;
337    Eina_Bool disabled : 1;
338    Eina_Bool display_only : 1;
339    Eina_Bool mincalcd : 1;
340    Eina_Bool queued : 1;
341    Eina_Bool showme : 1;
342    Eina_Bool delete_me : 1;
343    Eina_Bool down : 1;
344    Eina_Bool dragging : 1;
345    Eina_Bool updateme : 1;
346    Eina_Bool reordering : 1;
347
348    int pad_left, pad_right;
349 };
350
351
352 struct _Elm_Genlist_GroupItem
353 {
354       EINA_INLIST;
355       Widget_Data *wd;
356       Eina_List *items;
357       Evas_Coord x, y, w, h, minw, minh;
358       const Elm_Genlist_Item_Class *itc;
359       const void *data;
360       struct
361       {
362         Evas_Smart_Cb func;
363         const void *data;
364       } func;
365
366       Evas_Object *base;
367       Eina_List *labels, *icons, *states, *icon_objs;
368       int align;
369       Eina_Bool realized : 1;
370       Eina_Bool delete_me : 1;
371       Eina_Bool visible : 1;
372       Eina_Bool mincalcd : 1;
373 };
374
375 struct _Pan
376 {
377    Evas_Object_Smart_Clipped_Data __clipped_data;
378    Widget_Data *wd;
379 };
380
381 static const char *widtype = NULL;
382 static void _del_hook(Evas_Object *obj);
383 static void _theme_hook(Evas_Object *obj);
384 //static void _show_region_hook(void *data, Evas_Object *obj);
385 static void _sizing_eval(Evas_Object *obj);
386 static void _item_unrealize(Elm_Genlist_Item *it);
387 static void _item_block_unrealize(Item_Block *itb);
388 static void _groupitem_remove(Elm_Genlist_GroupItem *git, Eina_Bool update_items);
389 static void _groupitem_unrealize(Elm_Genlist_GroupItem *git);
390 static void _calc_job(void *data);
391 static Eina_Bool _edit_mode_reset(Widget_Data *wd);
392 static void _edit_controls_eval( Elm_Genlist_Item *it );
393 static void _move_edit_controls( Elm_Genlist_Item *it, int itx, int ity );
394
395
396 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
397
398 static void
399 _del_hook(Evas_Object *obj)
400 {
401    Widget_Data *wd = elm_widget_data_get(obj);
402    if (!wd) return;
403    if (wd->calc_job) ecore_job_del(wd->calc_job);
404    if (wd->update_job) ecore_job_del(wd->update_job);
405    free(wd);
406 }
407
408 static void
409 _del_pre_hook(Evas_Object *obj)
410 {
411    Widget_Data *wd = elm_widget_data_get(obj);
412    if (!wd) return;
413    evas_object_del(wd->pan_smart);
414    wd->pan_smart = NULL;
415    elm_genlist_clear(obj);
416 }
417
418 static void
419 _theme_hook(Evas_Object *obj)
420 {
421    Widget_Data *wd = elm_widget_data_get(obj);
422    Item_Block *itb;
423    Elm_Genlist_GroupItem *git;
424    if (!wd) return;
425    elm_smart_scroller_object_theme_set(obj, wd->scr, "genlist", "base", elm_widget_style_get(obj));
426 //   edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
427    EINA_INLIST_FOREACH(wd->group_items, git)
428     {
429        _groupitem_unrealize(git);
430     }
431    EINA_INLIST_FOREACH(wd->blocks, itb)
432      {
433         Eina_List *l;
434         Elm_Genlist_Item *it;
435         
436         if (itb->realized) _item_block_unrealize(itb);
437         EINA_LIST_FOREACH(itb->items, l, it)
438           it->mincalcd = EINA_FALSE;
439
440         itb->changed = EINA_TRUE;
441      }
442    if (wd->calc_job) ecore_job_del(wd->calc_job);
443    wd->calc_job = ecore_job_add(_calc_job, wd);
444    _sizing_eval(obj);
445 }
446
447 /*
448 static void
449 _show_region_hook(void *data, Evas_Object *obj)
450 {
451    Widget_Data *wd = elm_widget_data_get(data);
452    Evas_Coord x, y, w, h;
453    if (!wd) return;
454    elm_widget_show_region_get(obj, &x, &y, &w, &h);
455    elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
456 }
457 */
458
459 static void
460 _sizing_eval(Evas_Object *obj)
461 {
462    Widget_Data *wd = elm_widget_data_get(obj);
463    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
464    if (!wd) return;
465    evas_object_size_hint_min_get(wd->scr, &minw, &minh);
466    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
467    minh = -1;
468    if (wd->mode != ELM_LIST_LIMIT) minw = -1;
469    else
470      {
471         Evas_Coord  vmw, vmh, vw, vh;
472         
473         minw = wd->minw;
474         maxw = -1;
475         elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
476         if ((minw > 0) && (vw < minw)) vw = minw;
477         else if ((maxw > 0) && (vw > maxw)) vw = maxw;
478         minw = -1;
479         edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
480         minw = vmw + minw;
481      }
482    evas_object_size_hint_min_set(obj, minw, minh);
483    evas_object_size_hint_max_set(obj, maxw, maxh);
484 }
485
486 static void
487 _item_hilight(Elm_Genlist_Item *it)
488 {
489    const char *selectraise;
490
491    if ((it->wd->no_select) || (it->delete_me) || (it->hilighted) ||
492          (it->wd->edit_mode != ELM_GENLIST_EDIT_MODE_NONE)) return;
493    edje_object_signal_emit(it->base, "elm,state,selected", "elm");
494    selectraise = edje_object_data_get(it->base, "selectraise");
495    if ((selectraise) && (!strcmp(selectraise, "on")))
496    {
497      evas_object_raise(it->base);
498      if( it->group_item && it->group_item->realized )
499        evas_object_raise(it->group_item->base);
500    }
501    it->hilighted = EINA_TRUE;
502 }
503
504 static void
505 _item_block_del(Elm_Genlist_Item *it)
506 {
507    Eina_Inlist *il;
508    Item_Block *itb = it->block;
509
510    itb->items = eina_list_remove(itb->items, it);
511    itb->count--;
512    itb->changed = EINA_TRUE;
513    if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
514    it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
515    if (itb->count < 1)
516      {
517         il = EINA_INLIST_GET(itb);
518         Item_Block *itbn = (Item_Block *)(il->next);
519         if (it->parent)
520           it->parent->items = eina_list_remove(it->parent->items, it);
521         else
522           it->wd->blocks = eina_inlist_remove(it->wd->blocks, il);
523         free(itb);
524         if (itbn) itbn->changed = EINA_TRUE;
525      }
526    else
527      {
528         if (itb->count < 16)
529           {
530              il = EINA_INLIST_GET(itb);
531              Item_Block *itbp = (Item_Block *)(il->prev);
532              Item_Block *itbn = (Item_Block *)(il->next);
533              if ((itbp) && ((itbp->count + itb->count) < 48))
534                {
535                   Elm_Genlist_Item *it2;
536
537                   EINA_LIST_FREE(itb->items, it2)
538                     {
539                        it2->block = itbp;
540                        itbp->items = eina_list_append(itbp->items, it2);
541                        itbp->count++;
542                        itbp->changed = EINA_TRUE;
543                     }
544                   it->wd->blocks = eina_inlist_remove(it->wd->blocks, EINA_INLIST_GET(itb));
545                   free(itb);
546                }
547              else if ((itbn) && ((itbn->count + itb->count) < 48))
548                {
549                   while (itb->items)
550                     {
551                        Eina_List *last = eina_list_last(itb->items);
552                        Elm_Genlist_Item *it2 = last->data;
553
554                        it2->block = itbn;
555                        itb->items = eina_list_remove_list(itb->items, last);
556                        itbn->items = eina_list_prepend(itbn->items, it2);
557                        itbn->count++;
558                        itbn->changed = EINA_TRUE;
559                     }
560                   it->wd->blocks = 
561                     eina_inlist_remove(it->wd->blocks, EINA_INLIST_GET(itb));
562                   free(itb);
563                }
564           }
565      }
566 }
567
568 static void
569 _item_del(Elm_Genlist_Item *it)
570 {
571    elm_genlist_item_subitems_clear(it);
572    if (it->wd->show_item == it) it->wd->show_item = NULL;
573    if (it->selected) it->wd->selected = eina_list_remove(it->wd->selected, it);
574    if (it->realized) _item_unrealize(it);
575    if (it->block) _item_block_del(it);
576    if ((!it->delete_me) && (it->itc->func.del)) 
577      it->itc->func.del(it->data, it->wd->obj);
578    it->delete_me = EINA_TRUE;
579    if (it->queued)
580      it->wd->queue = eina_list_remove(it->wd->queue, it);
581    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
582    if (it->parent)
583      it->parent->items = eina_list_remove(it->parent->items, it);
584    if (it->long_timer) ecore_timer_del(it->long_timer);
585    if( it->group_item )
586    {
587        it->group_item->items = eina_list_remove(it->group_item->items,it);
588    }
589    free(it);
590 }
591
592 static void
593 _item_select(Elm_Genlist_Item *it)
594 {
595    if ((it->wd->no_select) || (it->delete_me) || (it->wd->edit_mode != ELM_GENLIST_EDIT_MODE_NONE)) return;
596    if (it->selected)
597      {
598         if (it->wd->always_select) goto call;
599         return;
600      }
601    it->selected = EINA_TRUE;
602    it->wd->selected = eina_list_append(it->wd->selected, it);
603    call:
604    it->walking++;
605    if (it->func.func) it->func.func((void *)it->func.data, it->wd->obj, it);
606    if (!it->delete_me)
607      evas_object_smart_callback_call(it->wd->obj, "selected", it);
608    it->walking--;
609    if ((it->walking == 0) && (it->delete_me))
610      {
611         if (it->relcount == 0) _item_del(it);
612      }
613 }
614
615 static void
616 _item_unselect(Elm_Genlist_Item *it)
617 {
618    const char *stacking, *selectraise;
619
620    if ((it->delete_me) || (!it->hilighted)) return;
621    edje_object_signal_emit(it->base, "elm,state,unselected", "elm");
622    stacking = edje_object_data_get(it->base, "stacking");
623    selectraise = edje_object_data_get(it->base, "selectraise");
624    if ((selectraise) && (!strcmp(selectraise, "on")))
625      {
626         if ((stacking) && (!strcmp(stacking, "below")))
627           evas_object_lower(it->base);
628      }
629    it->hilighted = EINA_FALSE;
630    if (it->selected)
631      {
632         it->selected = EINA_FALSE;
633         it->wd->selected = eina_list_remove(it->wd->selected, it);
634         evas_object_smart_callback_call(it->wd->obj, "unselected", it);
635      }
636 }
637
638 static void
639 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
640 {
641    Elm_Genlist_Item *it = data;
642    Evas_Event_Mouse_Move *ev = event_info;
643    Evas_Coord minw = 0, minh = 0, x, y, dx, dy, adx, ady;
644
645    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
646      {
647         if (!it->wd->on_hold)
648           {
649              it->wd->on_hold = EINA_TRUE;
650              _item_unselect(it);
651           }
652      }
653    if ((it->dragging) && (it->down))
654      {
655         if (it->long_timer)
656           {
657              ecore_timer_del(it->long_timer);
658              it->long_timer = NULL;
659           }
660         evas_object_smart_callback_call(it->wd->obj, "drag", it);
661         return;
662      }
663    if ((!it->down)/* || (it->wd->on_hold)*/ || (it->wd->longpressed))
664      {
665         if (it->long_timer)
666           {
667              ecore_timer_del(it->long_timer);
668              it->long_timer = NULL;
669           }
670         return;
671      }
672    if (!it->display_only)
673      elm_coords_finger_size_adjust(1, &minw, 1, &minh);
674    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
675    x = ev->cur.canvas.x - x;
676    y = ev->cur.canvas.y - y;
677    dx = x - it->dx;
678    adx = dx;
679    if (adx < 0) adx = -dx;
680    dy = y - it->dy;
681    ady = dy;
682    if (ady < 0) ady = -dy;
683    minw /= 2;
684    minh /= 2;
685    if ((adx > minw) || (ady > minh))
686      {
687         it->dragging = 1;
688         if (it->long_timer)
689           {
690              ecore_timer_del(it->long_timer);
691              it->long_timer = NULL;
692           }
693         if (!it->wd->wasselected)
694           _item_unselect(it);
695         it->wd->wasselected = 0;
696         if (dy < 0)
697           {
698              if (ady > adx)
699                evas_object_smart_callback_call(it->wd->obj, "drag,start,up", it);
700              else
701                {
702                   if (dx < 0)
703                     evas_object_smart_callback_call(it->wd->obj, 
704                                                     "drag,start,left", it);
705                   else
706                     evas_object_smart_callback_call(it->wd->obj, 
707                                                     "drag,start,right", it);
708                }
709           }
710         else
711           {
712              if (ady > adx)
713                evas_object_smart_callback_call(it->wd->obj, 
714                                                "drag,start,down", it);
715              else
716                {
717                   if (dx < 0)
718                     evas_object_smart_callback_call(it->wd->obj, 
719                                                     "drag,start,left", it);
720                   else
721                     evas_object_smart_callback_call(it->wd->obj, 
722                                                     "drag,start,right", it);
723                }
724           }
725      }
726 }
727
728 static int
729 _long_press(void *data)
730 {
731    Elm_Genlist_Item *it = data;
732
733    it->long_timer = NULL;
734    if ((it->disabled) || (it->dragging)) return 0;
735    it->wd->longpressed = EINA_TRUE;
736    evas_object_smart_callback_call(it->wd->obj, "longpressed", it);
737    return 0;
738 }
739
740 static void
741 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
742 {
743    Elm_Genlist_Item *it = data;
744    Evas_Event_Mouse_Down *ev = event_info;
745    Evas_Coord x, y;
746
747    if( it->wd->edit_mode != ELM_GENLIST_EDIT_MODE_NONE )
748      (void)_edit_mode_reset( it->wd );
749    if (ev->button != 1) return;
750    it->down = 1;
751    it->dragging  = 0;
752    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
753    it->dx = ev->canvas.x - x;
754    it->dy = ev->canvas.y - y;
755    it->wd->longpressed = EINA_FALSE;
756    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) it->wd->on_hold = EINA_TRUE;
757    else it->wd->on_hold = EINA_FALSE;
758    it->wd->wasselected = it->selected;
759    _item_hilight(it);
760    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
761      evas_object_smart_callback_call(it->wd->obj, "clicked", it);
762    if (it->long_timer) ecore_timer_del(it->long_timer);
763    if (it->realized)
764      it->long_timer = ecore_timer_add(1.0, _long_press, it);
765    else
766      it->long_timer = NULL;
767 }
768
769 static void
770 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
771 {
772    Elm_Genlist_Item *it = data;
773    Evas_Event_Mouse_Up *ev = event_info;
774    Eina_Bool dragged = 0;
775
776    if (ev->button != 1) return;
777    it->down = 0;
778    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) it->wd->on_hold = EINA_TRUE;
779    else it->wd->on_hold = EINA_FALSE;
780    if (it->long_timer)
781      {
782         ecore_timer_del(it->long_timer);
783         it->long_timer = NULL;
784      }
785    if (it->dragging)
786      {
787         it->dragging = 0;
788         evas_object_smart_callback_call(it->wd->obj, "drag,stop", it);
789         dragged = 1;
790      }
791    if (it->wd->on_hold)
792      {
793         it->wd->longpressed = EINA_FALSE;
794         it->wd->on_hold = EINA_FALSE;
795         return;
796      }
797    if (it->wd->longpressed)
798      {
799         it->wd->longpressed = EINA_FALSE;
800         if (!it->wd->wasselected)
801           _item_unselect(it);
802         it->wd->wasselected = 0;
803         return;
804      }
805    if (dragged)
806      {
807         if (it->want_unrealize)
808           {
809              _item_unrealize(it);
810              if (it->block->want_unrealize)
811                _item_block_unrealize(it->block);
812           }
813      }
814    if ((it->disabled) || (dragged)) return;
815    if (it->wd->multi)
816      {
817         if (!it->selected)
818           {
819              _item_hilight(it);
820              _item_select(it);
821           }
822         else _item_unselect(it);
823      }
824    else
825      {
826         if (!it->selected)
827           {
828              Widget_Data *wd = it->wd;
829              if (wd)
830                {
831                   while (wd->selected) _item_unselect(wd->selected->data);
832                }
833           }
834         else
835           {
836              const Eina_List *l, *l_next;
837              Elm_Genlist_Item *it2;
838
839              EINA_LIST_FOREACH_SAFE(it->wd->selected, l, l_next, it2)
840                if (it2 != it) _item_unselect(it2);
841 //           _item_hilight(it);
842 //           _item_select(it);
843           }
844         _item_hilight(it);
845         _item_select(it);
846      }
847 }
848
849 static void
850 _signal_expand_toggle(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
851 {
852    Elm_Genlist_Item *it = data;
853
854    if (it->expanded)
855      evas_object_smart_callback_call(it->wd->obj, "contract,request", it);
856    else
857      evas_object_smart_callback_call(it->wd->obj, "expand,request", it);
858 }
859
860 static void
861 _signal_expand(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
862 {
863    Elm_Genlist_Item *it = data;
864
865    if (!it->expanded)
866      evas_object_smart_callback_call(it->wd->obj, "expand,request", it);
867 }
868
869 static void
870 _signal_contract(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
871 {
872    Elm_Genlist_Item *it = data;
873
874    if (it->expanded)
875      evas_object_smart_callback_call(it->wd->obj, "contract,request", it);
876 }
877
878 static void
879 _set_groupitem( Elm_Genlist_Item *it, Elm_Genlist_GroupItem *git)
880 {
881   if(it && git )
882   {
883     it->group_item = git;
884     git->items = eina_list_append(git->items, it);
885   }
886 }
887
888 static void
889 _groupitem_realize(Elm_Genlist_GroupItem *git)
890 {
891       char buf[1024];
892       const char *align;
893
894       if ((git->realized) || (git->delete_me)) return;
895       git->base = edje_object_add(evas_object_evas_get(git->wd->obj));
896       edje_object_scale_set(git->base, elm_widget_scale_get(git->wd->obj) *
897                                                _elm_config->scale);
898       evas_object_smart_member_add(git->base, git->wd->pan_smart);
899       elm_widget_sub_object_add(git->wd->obj, git->base);
900
901       strncpy(buf, "item/", sizeof(buf));
902       strncat(buf, git->itc->item_style, sizeof(buf) - strlen(buf));
903       _elm_theme_object_set(git->wd->obj, git->base, "genlist", buf, elm_widget_style_get(git->wd->obj));
904
905       align = edje_object_data_get(git->base, "orientation");
906       git->align = GROUP_ALIGN_NORTH;
907       if(align)
908       {
909           if( !strcmp(align, "top") )
910                   git->align = GROUP_ALIGN_NORTH;
911           else if( !strcmp(align, "left") )
912                   git->align = GROUP_ALIGN_WEST;
913           else git->align = GROUP_ALIGN_NORTH;
914       }
915
916       if (git->itc->func.label_get)
917       {
918           const Eina_List *l;
919           const char *key;
920
921           git->labels = _elm_stringlist_get(edje_object_data_get(git->base, "labels"));
922           EINA_LIST_FOREACH(git->labels, l, key)
923           {
924                 char *s = git->itc->func.label_get(git->data, git->wd->obj, l->data);
925
926                 if (s)
927                 {
928                    edje_object_part_text_set(git->base, l->data, s);
929                    free(s);
930                 }
931           }
932       }
933
934       if (git->itc->func.icon_get)
935       {
936           const Eina_List *l;
937           const char *key;
938
939           git->icons = _elm_stringlist_get(edje_object_data_get(git->base, "icons"));
940           EINA_LIST_FOREACH(git->icons, l, key)
941           {
942                 Evas_Object *ic = git->itc->func.icon_get(git->data, git->wd->obj, l->data);
943
944                 if (ic)
945                 {
946                    git->icon_objs = eina_list_append(git->icon_objs, ic);
947                    edje_object_part_swallow(git->base, key, ic);
948                    evas_object_show(ic);
949                    elm_widget_sub_object_add(git->wd->obj, ic);
950                 }
951           }
952
953       }
954       if (git->itc->func.state_get)
955       {
956           const Eina_List *l;
957           const char *key;
958
959           git->states = _elm_stringlist_get(edje_object_data_get(git->base, "states"));
960           EINA_LIST_FOREACH(git->states, l, key)
961           {
962                 Eina_Bool on = git->itc->func.state_get(git->data, git->wd->obj, l->data);
963
964                 if (on)
965                 {
966                    snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
967                    edje_object_signal_emit(git->base, buf, "elm");
968                 }
969           }
970       }
971       if (!git->mincalcd)
972       {
973           Evas_Coord mw = -1, mh = -1;
974
975           edje_object_size_min_restricted_calc(git->base, &mw, &mh, mw, mh);
976
977           git->w = git->minw = mw;
978           git->h = git->minh = mh;
979           git->mincalcd = EINA_TRUE;
980       }
981       git->y = git->y = -1;
982       evas_object_show(git->base);
983
984      git->realized = EINA_TRUE;
985 }
986
987
988 static void
989 _groupitem_unrealize(Elm_Genlist_GroupItem *git)
990 {
991    Evas_Object *icon;
992
993    if (!git->realized) return;
994    evas_object_del(git->base);
995    git->base = NULL;
996    _elm_stringlist_free(git->labels);
997    git->labels = NULL;
998    _elm_stringlist_free(git->icons);
999    git->icons = NULL;
1000    _elm_stringlist_free(git->states);
1001
1002    EINA_LIST_FREE(git->icon_objs, icon)
1003      evas_object_del(icon);
1004
1005    git->states = NULL;
1006    git->realized = EINA_FALSE;
1007 }
1008
1009 static void
1010 _groupitem_remove(Elm_Genlist_GroupItem *git, Eina_Bool update_items)
1011 {
1012    Elm_Genlist_Item *it;
1013    const Eina_List *l;
1014
1015    if (!git) return;
1016
1017    if( git->realized )
1018       _groupitem_unrealize( git );
1019
1020    git->wd->group_items = eina_inlist_remove(git->wd->group_items,EINA_INLIST_GET(git));
1021
1022    if( update_items  )
1023    {
1024        EINA_LIST_FOREACH(git->items,l, it)
1025        {
1026             it->group_item = NULL;
1027             elm_genlist_item_update(it);
1028        }
1029    }
1030
1031    if (git->itc->func.del) git->itc->func.del(git->data, git->wd->obj);
1032    free(git);
1033 }
1034
1035 static void
1036 _item_realize(Elm_Genlist_Item *it, int in, int calc)
1037 {
1038    Elm_Genlist_Item *it2;
1039    const char *stacking;
1040    const char *treesize;
1041    char buf[1024];
1042    int depth, tsize = 20;
1043
1044    if ((it->realized) || (it->delete_me)) return;
1045    it->base = edje_object_add(evas_object_evas_get(it->wd->obj));
1046    edje_object_scale_set(it->base, elm_widget_scale_get(it->wd->obj) *
1047                          _elm_config->scale);
1048    evas_object_smart_member_add(it->base, it->wd->pan_smart);
1049    elm_widget_sub_object_add(it->wd->obj, it->base);
1050
1051    if (it->flags & ELM_GENLIST_ITEM_SUBITEMS) strncpy(buf, "tree", sizeof(buf));
1052    else strncpy(buf, "item", sizeof(buf));
1053    if (it->wd->compress) strncat(buf, "_compress", sizeof(buf) - strlen(buf));
1054
1055    if (in & 0x1) strncat(buf, "_odd", sizeof(buf) - strlen(buf));
1056    strncat(buf, "/", sizeof(buf) - strlen(buf));
1057    strncat(buf, it->itc->item_style, sizeof(buf) - strlen(buf));
1058    
1059    _elm_theme_object_set(it->wd->obj, it->base, "genlist", buf, elm_widget_style_get(it->wd->obj));
1060    it->spacer = evas_object_rectangle_add(evas_object_evas_get(it->wd->obj));
1061    evas_object_color_set(it->spacer, 0, 0, 0, 0);
1062    elm_widget_sub_object_add(it->wd->obj, it->spacer);
1063    for (it2 = it, depth = 0; it2->parent; it2 = it2->parent) depth += 1;
1064    treesize = edje_object_data_get(it->base, "treesize");
1065    if (treesize) tsize = atoi(treesize);
1066    evas_object_size_hint_min_set(it->spacer,
1067                                  (depth * tsize) * _elm_config->scale, 1);
1068    edje_object_part_swallow(it->base, "elm.swallow.pad", it->spacer);
1069    if (!calc)
1070      {
1071         edje_object_signal_callback_add(it->base, "elm,action,expand,toggle",
1072                                         "elm", _signal_expand_toggle, it);
1073         edje_object_signal_callback_add(it->base, "elm,action,expand", "elm",
1074                                         _signal_expand, it);
1075         edje_object_signal_callback_add(it->base, "elm,action,contract",
1076                                         "elm", _signal_contract, it);
1077         stacking = edje_object_data_get(it->base, "stacking");
1078         if (stacking)
1079           {
1080              if (!strcmp(stacking, "below")) evas_object_lower(it->base);
1081              else if (!strcmp(stacking, "above")) evas_object_raise(it->base);
1082           }
1083         evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_DOWN,
1084                                        _mouse_down, it);
1085         evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_UP,
1086                                        _mouse_up, it);
1087         evas_object_event_callback_add(it->base, EVAS_CALLBACK_MOUSE_MOVE,
1088                                        _mouse_move, it);
1089         if (it->selected)
1090           edje_object_signal_emit(it->base, "elm,state,selected", "elm");
1091         if (it->disabled)
1092           edje_object_signal_emit(it->base, "elm,state,disabled", "elm");
1093         if (it->expanded)
1094           edje_object_signal_emit(it->base, "elm,state,expanded", "elm");
1095      }
1096
1097    if (calc && it->wd->homogeneous && it->wd->item_width)
1098      {
1099         /* homogenous genlist shortcut */
1100         if (!it->mincalcd)
1101           {
1102              it->w = it->minw = it->wd->item_width;
1103              it->h = it->minh = it->wd->item_height;
1104              it->mincalcd = EINA_TRUE;
1105           }
1106      }
1107    else
1108      {
1109         if (it->itc->func.label_get)
1110           {
1111              const Eina_List *l;
1112              const char *key;
1113
1114              it->labels = _elm_stringlist_get(edje_object_data_get(it->base, "labels"));
1115              EINA_LIST_FOREACH(it->labels, l, key)
1116                {
1117                   char *s = it->itc->func.label_get(it->data, it->wd->obj, l->data);
1118
1119                   if (s)
1120                     {
1121                        edje_object_part_text_set(it->base, l->data, s);
1122                        free(s);
1123                     }
1124                }
1125           }
1126         if (it->itc->func.icon_get)
1127           {
1128              const Eina_List *l;
1129              const char *key;
1130
1131              it->icons = _elm_stringlist_get(edje_object_data_get(it->base, "icons"));
1132              EINA_LIST_FOREACH(it->icons, l, key)
1133                {
1134                   Evas_Object *ic = it->itc->func.icon_get(it->data, it->wd->obj, l->data);
1135
1136                   if (ic)
1137                     {
1138                        it->icon_objs = eina_list_append(it->icon_objs, ic);
1139                        edje_object_part_swallow(it->base, key, ic);
1140                        evas_object_show(ic);
1141                        elm_widget_sub_object_add(it->wd->obj, ic);
1142                     }
1143                }
1144           }
1145         if (it->itc->func.state_get)
1146           {
1147              const Eina_List *l;
1148              const char *key;
1149
1150              it->states = _elm_stringlist_get(edje_object_data_get(it->base, "states"));
1151              EINA_LIST_FOREACH(it->states, l, key)
1152                {
1153                   Eina_Bool on = it->itc->func.state_get(it->data, it->wd->obj, l->data);
1154
1155                   if (on)
1156                     {
1157                        snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1158                        edje_object_signal_emit(it->base, buf, "elm");
1159                     }
1160                }
1161           }
1162         if (!it->mincalcd)
1163           {
1164              Evas_Coord mw = -1, mh = -1;
1165              
1166              if (!it->display_only)
1167                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1168              edje_object_size_min_restricted_calc(it->base, &mw, &mh, mw, mh);
1169              if (!it->display_only)
1170                elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1171              it->w = it->minw = mw;
1172              it->h = it->minh = mh;
1173              it->mincalcd = EINA_TRUE;
1174
1175              if (in == 0 && it->wd->homogeneous)
1176                {
1177                   it->wd->item_width = mw;
1178                   it->wd->item_height = mh;
1179                }
1180           }
1181         if (!calc) evas_object_show(it->base);
1182      }
1183    it->realized = EINA_TRUE;
1184    it->want_unrealize = EINA_FALSE;
1185    if(it->group_item && !it->group_item->realized)
1186      _groupitem_realize(it->group_item);
1187    if( ELM_GENLIST_EDIT_MODE_NONE != it->wd->edit_mode )
1188      _edit_controls_eval(it);
1189 }
1190
1191 static void
1192 _item_unrealize(Elm_Genlist_Item *it)
1193 {
1194    Evas_Object *icon;
1195
1196    if (!it->realized) return;
1197    if (it->long_timer)
1198      {
1199         ecore_timer_del(it->long_timer);
1200         it->long_timer = NULL;
1201      }
1202    evas_object_del(it->base);
1203    it->base = NULL;
1204    evas_object_del(it->spacer);
1205    it->spacer = NULL;
1206    if(it->edit_obj)
1207      evas_object_del(it->edit_obj);
1208    it->edit_obj = NULL;
1209    _elm_stringlist_free(it->labels);
1210    it->labels = NULL;
1211    _elm_stringlist_free(it->icons);
1212    it->icons = NULL;
1213    _elm_stringlist_free(it->states);
1214
1215    EINA_LIST_FREE(it->icon_objs, icon) 
1216      evas_object_del(icon);
1217
1218    it->states = NULL;
1219    it->realized = EINA_FALSE;
1220    it->want_unrealize = EINA_FALSE;
1221 }
1222
1223 static int
1224 _item_block_recalc(Item_Block *itb, int in, int qadd, int norender)
1225 {
1226    const Eina_List *l;
1227    Elm_Genlist_Item *it;
1228    Elm_Genlist_GroupItem *git = NULL;
1229    Evas_Coord minw = 0, minh = 0;
1230    int showme = 0, changed = 0;
1231    Evas_Coord y = 0;
1232
1233    itb->num = in;
1234    EINA_LIST_FOREACH(itb->items, l, it)
1235      {
1236         if (it->delete_me) continue;
1237         showme |= it->showme;
1238         if (!itb->realized)
1239           {
1240              if (qadd)
1241                {
1242                   if (!it->mincalcd) changed = 1;
1243                   if (changed)
1244                     {
1245                        _item_realize(it, in, 1);
1246                        _item_unrealize(it);
1247                     }
1248                }
1249              else
1250                {
1251                   _item_realize(it, in, 1);
1252                   _item_unrealize(it);
1253                }
1254           }
1255         else
1256           {
1257              Eina_Bool was_realized = it->realized;
1258
1259              _item_realize(it, in, 0);
1260              if (!was_realized)
1261                evas_object_smart_callback_call(it->wd->obj, "realized", it);
1262           }
1263         minh += it->minh;
1264         if (minw < it->minw) minw = it->minw;
1265         in++;
1266         it->x = 0;
1267         it->y = y;
1268         y += it->h;
1269         if( git != it->group_item )
1270         {
1271             git = it->group_item;
1272             if( git && git->align == GROUP_ALIGN_NORTH && git->items->data == it) //Add Place holder for Group title
1273             {
1274                 minh += git->minh;
1275                 it->y += git->minh;
1276                 y += git->minh;
1277             }
1278         }
1279      }
1280    itb->minw = minw;
1281    itb->minh = minh;
1282    itb->changed = EINA_FALSE;
1283    /* force an evas norender to garbage collect deleted objects */
1284    if (norender) evas_norender(evas_object_evas_get(itb->wd->obj));
1285    return showme;
1286 }
1287
1288 static void
1289 _item_block_realize(Item_Block *itb, int in, int full)
1290 {
1291    const Eina_List *l;
1292    Elm_Genlist_Item *it;
1293
1294    if (itb->realized) return;
1295    EINA_LIST_FOREACH(itb->items, l, it)
1296      {
1297         if (it->delete_me) continue;
1298         if (full)
1299           {
1300              Eina_Bool was_realized = it->realized;
1301
1302              _item_realize(it, in, 0);
1303              if (!was_realized)
1304                evas_object_smart_callback_call(it->wd->obj, "realized", it);
1305           }
1306         in++;
1307      }
1308    itb->realized = EINA_TRUE;
1309    itb->want_unrealize = EINA_FALSE;
1310 }
1311
1312 static void
1313 _item_block_unrealize(Item_Block *itb)
1314 {
1315    const Eina_List *l;
1316    Elm_Genlist_Item *it;
1317    int dragging = 0;
1318
1319    if (!itb->realized) return;
1320    EINA_LIST_FOREACH(itb->items, l, it)
1321      {
1322         if (it->dragging || it->reordering)
1323           {
1324              dragging = 1;
1325              it->want_unrealize = EINA_TRUE;
1326           }
1327         else
1328           _item_unrealize(it);
1329      }
1330    if (!dragging)
1331      {
1332         itb->realized = EINA_FALSE;
1333         itb->want_unrealize = EINA_TRUE;
1334      }
1335    else
1336      itb->want_unrealize = EINA_FALSE;
1337 }
1338
1339 static void
1340 _delete_confirm_cb(void *data, Evas_Object *obj, void *event_info)
1341 {
1342   Widget_Data *wd = data;
1343   wd->ed->del_confirm_state = 0;
1344   evas_object_hide( wd->ed->del_confirm );
1345   if( wd->ed->ec && wd->ed->ec->remove  )
1346     wd->ed->ec->remove(wd->obj, wd->ed->del_item);
1347   wd->ed->del_item = NULL;
1348 }
1349
1350 static void
1351 _hide_delete_confirm_object (void *data, Evas_Object *obj, const char *emission, const char *source)
1352 {
1353   const char *del_icon_part;
1354   Elm_Genlist_Item *it = data;
1355   del_icon_part = edje_object_data_get(it->edit_obj, "del_confirm");
1356   if (del_icon_part)
1357     edje_object_part_unswallow( it->edit_obj, it->wd->ed->del_confirm );
1358
1359    evas_object_hide( it->wd->ed->del_confirm );
1360 }
1361
1362 static void
1363 _remove_item_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
1364 {
1365   const char *del_icon_part, *del_conf_style;
1366   Elm_Genlist_Item *it = data;
1367   if(_edit_mode_reset( it->wd ))
1368      return;
1369
1370   it->wd->ed->del_confirm_state = 1;
1371   it->wd->ed->del_item = it;
1372
1373   del_conf_style = edje_object_data_get(it->edit_obj, "del_button_style");
1374   if(del_conf_style )
1375     elm_object_style_set( it->wd->ed->del_confirm, del_conf_style);
1376
1377
1378    del_icon_part = edje_object_data_get(it->edit_obj, "del_confirm");
1379    if (del_icon_part)
1380      edje_object_part_swallow(it->edit_obj, del_icon_part, it->wd->ed->del_confirm);
1381    evas_object_show( it->wd->ed->del_confirm );
1382    edje_object_signal_emit(it->edit_obj, "elm,state,del_confirm", "elm");
1383 }
1384
1385 static void
1386 _insert_new_item_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
1387 {
1388   Elm_Genlist_Item *it = data;
1389
1390   if(_edit_mode_reset( it->wd ))
1391      return;
1392
1393   if( it->wd->ed->ec && it->wd->ed->ec->insert_new )
1394     it->wd->ed->ec->insert_new(it->wd->obj, it);
1395 }
1396
1397 static Eina_Bool
1398 _edit_mode_reset(Widget_Data *wd)
1399 {
1400   if(wd->ed->del_confirm_state)
1401   {
1402        edje_object_signal_emit(wd->ed->del_item->edit_obj, "elm,state,delete", "elm");
1403        wd->ed->del_confirm_state = 0;
1404        wd->ed->del_item = NULL;
1405        return EINA_TRUE;
1406   }
1407   return EINA_FALSE;
1408 }
1409
1410 static void
1411 _reorder_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1412 {
1413   Elm_Genlist_Item *it = data;
1414   Evas_Event_Mouse_Down *ev = event_info;
1415   Evas_Coord x, y;
1416
1417   if(_edit_mode_reset( it->wd ) )
1418     return;
1419
1420   edje_object_signal_emit(it->edit_obj, "elm,action,item,reorder_start", "elm");
1421
1422   evas_object_raise(it->base);
1423   evas_object_raise( it->edit_obj );
1424
1425   evas_object_geometry_get(it->base, &x, &y, NULL, NULL);
1426   it->dx = ev->canvas.x - x;
1427   it->dy = ev->canvas.y - y;
1428   it->wd->ed->reorder_item = it;
1429   it->wd->ed->reorder_item->reordering = 1;
1430   it->wd->ed->reorder_rel = NULL;
1431   elm_smart_scroller_hold_set(it->wd->scr, EINA_TRUE);
1432 }
1433
1434 static void
1435 _reorder_mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1436 {
1437   Elm_Genlist_Item *it = data;
1438   Elm_Genlist_Item *rel_it;
1439
1440   if( it->reordering && it->wd->ed->reorder_item )
1441      {
1442        int ox,oy;
1443        it->wd->ed->reorder_item->reordering = 0;
1444        edje_object_signal_emit(it->wd->ed->reorder_item->edit_obj, "elm,action,item,reorder_end", "elm");
1445        elm_smart_scroller_hold_set(it->wd->scr, EINA_FALSE);
1446
1447        if(  (!it->wd->ed->reorder_rel) || (!it->wd->ed->ec->move) ||
1448           (!it->wd->ed->ec->move(it->wd->obj, it->wd->ed->reorder_item, it->wd->ed->reorder_rel, EINA_TRUE ) ) )
1449         {
1450           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);
1451           _move_edit_controls( it,it->wd->ed->reorder_item->scrl_x, it->wd->ed->reorder_item->scrl_y );
1452        }
1453        it->wd->ed->reorder_item = NULL;
1454        it->wd->ed->reorder_rel = NULL;
1455        return;
1456      }
1457 }
1458
1459 static void
1460 _reorder_mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj, void *event_info)
1461 {
1462   Elm_Genlist_Item *it = data;
1463   Evas_Event_Mouse_Move *ev = event_info;
1464
1465   if( it->reordering && it->wd->ed->reorder_item )
1466   {
1467       Elm_Genlist_Item *rel_it;
1468       int y = ev->cur.canvas.y - it->wd->ed->reorder_item->dy;
1469       evas_object_raise(it->wd->ed->reorder_item->base);
1470       evas_object_move(it->wd->ed->reorder_item->base, it->wd->ed->reorder_item->scrl_x+it->pad_left, y);
1471       evas_object_show(it->wd->ed->reorder_item->base);
1472       _move_edit_controls( it,it->wd->ed->reorder_item->scrl_x, y );
1473
1474         it->block->updateme = EINA_TRUE;
1475
1476         if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
1477          it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
1478
1479       return;
1480   }
1481 }
1482
1483 static void
1484 _move_edit_controls( Elm_Genlist_Item *it, int itx, int ity )
1485 {
1486    if(it->wd->edit_mode == ELM_GENLIST_EDIT_MODE_NONE )
1487      return;
1488
1489    evas_object_resize(it->edit_obj,it->w, it->h );
1490    evas_object_move(it->edit_obj, itx, ity );
1491    evas_object_raise( it->edit_obj );
1492 }
1493
1494 static void
1495 _edit_controls_eval( Elm_Genlist_Item *it )
1496 {
1497     int itmode = 0;
1498     const char *pad_str;
1499     int pad = 0;
1500     it->pad_left = 0;
1501     it->pad_right = 0;
1502
1503     if( it->wd->edit_mode == ELM_GENLIST_EDIT_MODE_NONE && !it->edit_obj )
1504       return;
1505
1506      if( it->itc->func.editmode_get )
1507        itmode = it->itc->func.editmode_get( it->data, it->wd->obj, it->wd->edit_mode );
1508      itmode &= it->wd->edit_mode;
1509
1510      if( !it->edit_obj )
1511      {
1512        it->edit_obj = edje_object_add(evas_object_evas_get(it->wd->obj));
1513        edje_object_scale_set(it->edit_obj, elm_widget_scale_get(it->wd->obj) *
1514                             _elm_config->scale);
1515        evas_object_smart_member_add(it->edit_obj, it->wd->pan_smart);
1516        elm_widget_sub_object_add(it->wd->obj, it->edit_obj);
1517        _elm_theme_object_set(it->wd->obj, it->edit_obj, "genlist", "item/edit_control", elm_widget_style_get(it->wd->obj));
1518
1519        edje_object_signal_callback_add(it->edit_obj, "elm,action,edit,reset",
1520                                              "elm", _edit_mode_reset, it);
1521      }
1522
1523        pad_str = edje_object_data_get(it->edit_obj, "icon_width");
1524        if (pad_str) pad = atoi(pad_str);
1525
1526        if( (itmode & ELM_GENLIST_EDIT_MODE_INSERT) )
1527        {
1528            if(it->wd->animate_edit_controls)
1529              edje_object_signal_emit(it->edit_obj, "elm,state,ins,animated,enable", "elm");
1530            else
1531              edje_object_signal_emit(it->edit_obj, "elm,state,ins,enable", "elm");
1532
1533            edje_object_signal_callback_add(it->edit_obj, "elm,action,item,insert",
1534                                                 "elm", _insert_new_item_cb, it);
1535            it->pad_left += pad;
1536        }else
1537        {
1538           if(it->wd->animate_edit_controls)
1539             edje_object_signal_emit(it->edit_obj, "elm,state,ins,animated,disable", "elm");
1540           else
1541             edje_object_signal_emit(it->edit_obj, "elm,state,ins,disable", "elm");
1542
1543           edje_object_signal_callback_del(it->edit_obj, "elm,action,item,insert",
1544                                             "elm", _insert_new_item_cb );
1545        }
1546
1547        if( (itmode & ELM_GENLIST_EDIT_MODE_DELETE) )
1548        {
1549            if(it->wd->animate_edit_controls)
1550              edje_object_signal_emit(it->edit_obj, "elm,state,del,animated,enable", "elm");
1551            else
1552              edje_object_signal_emit(it->edit_obj, "elm,state,del,enable", "elm");
1553
1554            edje_object_signal_callback_add(it->edit_obj, "elm,action,item,delete",
1555                                                  "elm", _remove_item_cb, it);
1556
1557            edje_object_signal_callback_add(it->edit_obj, "elm,action,hide,del_confirm",
1558                                            "elm", _hide_delete_confirm_object, it );
1559            it->pad_left += pad;
1560        }
1561        else
1562        {
1563            if(it->wd->animate_edit_controls)
1564              edje_object_signal_emit(it->edit_obj, "elm,state,del,animated,disable", "elm");
1565            else
1566              edje_object_signal_emit(it->edit_obj, "elm,state,del,disable", "elm");
1567
1568            edje_object_signal_callback_del(it->edit_obj, "elm,action,item,delete",
1569                                                  "elm", _remove_item_cb );
1570            edje_object_signal_callback_del(it->edit_obj, "elm,action,hide,del_confirm",
1571                                                   "elm", _hide_delete_confirm_object );
1572
1573        }
1574
1575        if( (itmode & ELM_GENLIST_EDIT_MODE_REORDER) )
1576        {
1577            Evas_Object *reorder_icon;
1578            const char* reorder_part;
1579
1580            if(it->wd->animate_edit_controls)
1581              edje_object_signal_emit(it->edit_obj, "elm,state,reorder,animated,enable", "elm");
1582            else
1583              edje_object_signal_emit(it->edit_obj, "elm,state,reorder,enable", "elm");
1584
1585            reorder_part = edje_object_data_get(it->edit_obj, "reorder");
1586            if( reorder_part && edje_object_part_exists(it->edit_obj, reorder_part ) )
1587            {
1588              reorder_icon = edje_object_part_object_get(it->edit_obj, reorder_part );
1589
1590              evas_object_event_callback_add(reorder_icon, EVAS_CALLBACK_MOUSE_DOWN,
1591                                          _reorder_mouse_down, it);
1592              evas_object_event_callback_add(reorder_icon, EVAS_CALLBACK_MOUSE_UP,
1593                                           _reorder_mouse_up, it);
1594              evas_object_event_callback_add(reorder_icon, EVAS_CALLBACK_MOUSE_MOVE,
1595                                           _reorder_mouse_move, it);
1596            }
1597            it->pad_right += pad;
1598         }
1599        else
1600        {
1601             Evas_Object *reorder_icon;
1602             const char* reorder_part;
1603
1604             if(it->wd->animate_edit_controls)
1605               edje_object_signal_emit(it->edit_obj, "elm,state,reorder,animated,disable", "elm");
1606             else
1607               edje_object_signal_emit(it->edit_obj, "elm,state,reorder,disable", "elm");
1608
1609             reorder_part = edje_object_data_get(it->edit_obj, "reorder");
1610             if( reorder_part && edje_object_part_exists(it->edit_obj, reorder_part ) )
1611             {
1612               reorder_icon = edje_object_part_object_get(it->edit_obj, reorder_part );
1613
1614               evas_object_event_callback_del(reorder_icon, EVAS_CALLBACK_MOUSE_DOWN,
1615                                           _reorder_mouse_down);
1616               evas_object_event_callback_del(reorder_icon, EVAS_CALLBACK_MOUSE_UP,
1617                                            _reorder_mouse_up);
1618               evas_object_event_callback_del(reorder_icon, EVAS_CALLBACK_MOUSE_MOVE,
1619                                            _reorder_mouse_move);
1620             }
1621        }
1622
1623      if( it->wd->edit_mode == ELM_GENLIST_EDIT_MODE_NONE )//Unrealize
1624      {
1625          evas_object_del(it->edit_obj);
1626          it->edit_obj = NULL;
1627          return;
1628      }
1629      _move_edit_controls(it,it->scrl_x, it->scrl_y );
1630      evas_object_show( it->edit_obj );
1631 }
1632
1633 static void
1634 _notify_item_position( Elm_Genlist_Item *it )
1635 {
1636    const Eina_List *l;
1637     if( it->parent )
1638     {
1639         l = eina_list_last(it->parent->items);
1640
1641         //Check if the Item is First Node or Last node of its Parent & raise signal.
1642         if( it->parent->items->data != it &&  l->data != it )
1643         {
1644           edje_object_signal_emit(it->base, "normal_item", "elm");
1645         } else {
1646           if(it->parent->items->data == it )
1647                edje_object_signal_emit(it->base, "first_item", "elm");
1648
1649           if(l->data == it )
1650                edje_object_signal_emit(it->base, "last_item", "elm");
1651         }
1652     }
1653 }
1654
1655
1656 static int
1657 _get_space_for_reorder_item( Elm_Genlist_Item *it )
1658 {
1659   int top=0, bottom=0;
1660   Evas_Coord rox, roy, row, roh;
1661
1662   if( !(it->wd->edit_mode & ELM_GENLIST_EDIT_MODE_REORDER ) || !it->wd->ed->reorder_item )
1663     return 0;
1664
1665   evas_object_geometry_get(it->wd->ed->reorder_item->base, &rox, &roy, &row, &roh);
1666
1667   top = (ELM_RECTS_INTERSECT(it->scrl_x, it->scrl_y, it->w, it->h,
1668                              rox, roy+roh/2, row, 1));
1669
1670   if( top )
1671   {
1672     it->wd->ed->reorder_rel = it;
1673     it->scrl_y+=it->wd->ed->reorder_item->h;
1674     return it->wd->ed->reorder_item->h;
1675   }
1676
1677   return 0;
1678 }
1679
1680 static void
1681 _item_block_position(Item_Block *itb, int in)
1682 {
1683    const Eina_List *l;
1684    Elm_Genlist_Item *it;
1685    Elm_Genlist_GroupItem *git = NULL;
1686    Evas_Coord y = 0, ox, oy, ow, oh, cvx, cvy, cvw, cvh;
1687    int vis=0, new_mov_y = 0;
1688
1689    evas_object_geometry_get(itb->wd->pan_smart, &ox, &oy, &ow, &oh);
1690    evas_output_viewport_get(evas_object_evas_get(itb->wd->obj), &cvx, &cvy, &cvw, &cvh);
1691    EINA_LIST_FOREACH(itb->items, l, it)
1692      {
1693         if (it->delete_me) continue;
1694         it->x = 0;
1695         it->y = y;
1696         it->w = itb->w;
1697         vis = (ELM_RECTS_INTERSECT(itb->x - it->wd->pan_x + ox,
1698                                    itb->y - it->wd->pan_y + oy,
1699                                    itb->w, itb->h,
1700                                    cvx, cvy, cvw, cvh));
1701         if ((itb->realized) && (!it->realized))
1702           {
1703              if (vis)
1704                {
1705                   Eina_Bool was_realized = it->realized;
1706
1707                   _item_realize(it, in, 0);
1708                   if (!was_realized)
1709                     evas_object_smart_callback_call(it->wd->obj, 
1710                                                     "realized", it);
1711                }
1712           }
1713         if (it->realized)
1714           {
1715             _notify_item_position( it );
1716              if (vis)
1717                {
1718                   it->scrl_x = ox + itb->x + it->x - itb->wd->pan_x;
1719                   it->scrl_y = oy + itb->y + it->y - itb->wd->pan_y;
1720                    if( git != it->group_item )
1721                    {
1722                        git = it->group_item;
1723                        if( git )
1724                        {
1725                           git->visible = EINA_TRUE; //Mark Group Item to make it visible
1726                           if( git->items->data == it)
1727                              git->y = it->scrl_y;
1728                           if( GROUP_ALIGN_NORTH == git->align )
1729                            {
1730                               git->w = itb->w;
1731                               if( git->items->data == it)
1732                                 {
1733                                   it->scrl_y += git->minh;
1734                                   y += git->minh;
1735                                 }
1736                             }
1737                         }
1738                     }
1739                   if( git )
1740                   {
1741                       git->x = ox + itb->x - itb->wd->pan_x;
1742
1743                       if( git->y < oy   )
1744                               git->y = oy;
1745
1746                       if( git->align == GROUP_ALIGN_WEST )
1747                         {
1748                           it->w -= git->w;
1749                           it->scrl_x += git->x + git->w;
1750                           git->h = (it->scrl_y + it->h)  -  git->y ;
1751                           if( git->h < it->h )
1752                           {
1753                                   git->y = it->scrl_y;
1754                                   git->h = it->h;
1755                           }
1756                         }
1757                         if( git->align == GROUP_ALIGN_NORTH )
1758                         {
1759                           git->h = git->minh;
1760                           if( (git->y + git->h) > (it->scrl_y + it->h) )
1761                                   git->y = (it->scrl_y + it->h) - git->minh;
1762
1763                         }
1764                   }
1765
1766                   y+=_get_space_for_reorder_item( it );
1767
1768                   if(!it->reordering )
1769                   {
1770                     _move_edit_controls( it,it->scrl_x, it->scrl_y );
1771                     evas_object_resize(it->base, it->w-(it->pad_left+it->pad_right), it->h);
1772                     evas_object_move(it->base, it->scrl_x+it->pad_left, it->scrl_y);
1773                     evas_object_show(it->base);
1774                   }
1775               }
1776              else
1777                {
1778                   if (!it->dragging)
1779                     _item_unrealize(it);
1780                }
1781           }
1782
1783         if(!it->reordering )
1784            y += it->h;
1785
1786         in++;
1787      }
1788
1789      if( vis )
1790      {
1791         itb->wd->animate_edit_controls = 0;
1792         if(git)
1793          git->visible = EINA_TRUE;
1794      }
1795 }
1796
1797 static void
1798 _calc_job(void *data)
1799 {
1800    Widget_Data *wd = data;
1801    Item_Block *itb;
1802    Evas_Coord minw = -1, minh = 0, y = 0, ow, oh;
1803    Item_Block *chb = NULL;
1804    int in = 0, minw_change = 0;
1805    if (!wd) return;
1806    EINA_INLIST_FOREACH(wd->blocks, itb)
1807      {
1808         int showme = 0;
1809
1810         itb->num = in;
1811         showme = itb->showme;
1812         itb->showme = 0;
1813         if (chb)
1814           {
1815              if (itb->realized) _item_block_unrealize(itb);
1816           }
1817         if (itb->changed)
1818           {
1819              if (itb->realized) _item_block_unrealize(itb);
1820              showme = _item_block_recalc(itb, in, 0, 1);
1821              chb = itb;
1822           }
1823         itb->y = y;
1824         itb->x = 0;
1825         minh += itb->minh;
1826         if (minw == -1) minw = itb->minw;
1827         else if (minw < itb->minw)
1828           {
1829              minw = itb->minw;
1830              minw_change = 1;
1831           }
1832         itb->w = minw;
1833         itb->h = itb->minh;
1834         y += itb->h;
1835         in += itb->count;
1836         if (showme)
1837           {
1838              wd->show_item->showme = 0;
1839              if (wd->bring_in)
1840                elm_smart_scroller_region_bring_in(wd->scr,
1841                                                   wd->show_item->x + wd->show_item->block->x,
1842                                                   wd->show_item->y + wd->show_item->block->y,
1843                                                   wd->show_item->block->w,
1844                                                   wd->show_item->h);
1845              else
1846                elm_smart_scroller_child_region_show(wd->scr,
1847                                                     wd->show_item->x + wd->show_item->block->x,
1848                                                     wd->show_item->y + wd->show_item->block->y,
1849                                                     wd->show_item->block->w,
1850                                                     wd->show_item->h);
1851              wd->show_item = NULL;
1852              showme = 0;
1853           }
1854      }
1855    if (minw_change)
1856      {
1857         EINA_INLIST_FOREACH(wd->blocks, itb)
1858           {
1859              itb->minw = minw;
1860              itb->w = itb->minw;
1861           }
1862      }
1863    if ((chb) && (EINA_INLIST_GET(chb)->next))
1864      {
1865         EINA_INLIST_FOREACH(EINA_INLIST_GET(chb)->next, itb)
1866           if (itb->realized) _item_block_unrealize(itb);
1867      }
1868    evas_object_geometry_get(wd->pan_smart, NULL, NULL, &ow, &oh);
1869    if (minw < ow) minw = ow;
1870    if ((minw != wd->minw) || (minh != wd->minh))
1871      {
1872         wd->minw = minw;
1873         wd->minh = minh;
1874         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1875         _sizing_eval(wd->obj);
1876      }
1877    wd->calc_job = NULL;
1878    evas_object_smart_changed(wd->pan_smart);
1879 }
1880
1881 static void
1882 _update_job(void *data)
1883 {
1884    Widget_Data *wd = data;
1885    Eina_List *l2;
1886    Item_Block *itb;
1887    int num, num0, position = 0, recalc = 0;
1888    if (!wd) return;
1889    wd->update_job = NULL;
1890    num = 0;
1891    EINA_INLIST_FOREACH(wd->blocks, itb)
1892      {
1893         Evas_Coord itminw, itminh;
1894         Elm_Genlist_Item *it;
1895
1896         if (!itb->updateme)
1897           {
1898              num += itb->count;
1899              if (position)
1900                _item_block_position(itb, num);
1901              continue;
1902           }
1903         num0 = num;
1904         recalc = 0;
1905         EINA_LIST_FOREACH(itb->items, l2, it)
1906           {
1907              if (it->updateme)
1908                {
1909                   itminw = it->w;
1910                   itminh = it->h;
1911
1912                   it->updateme = 0;
1913                   if (it->realized)
1914                     {
1915                        _item_unrealize(it);
1916                        _item_realize(it, num, 0);
1917                        evas_object_smart_callback_call(it->wd->obj, 
1918                                                        "realized", it);
1919                     }
1920                   else
1921                     {
1922                        _item_realize(it, num, 1);
1923                        _item_unrealize(it);
1924                     }
1925                   if ((it->minw != itminw) || (it->minh != itminh))
1926                     recalc = 1;
1927                }
1928              num++;
1929           }
1930         itb->updateme = 0;
1931         if (recalc)
1932           {
1933              position = 1;
1934              itb->changed = EINA_TRUE;
1935              _item_block_recalc(itb, num0, 0, 1);
1936              _item_block_position(itb, num0);
1937           }
1938      }
1939    if (position)
1940      {
1941         if (wd->calc_job) ecore_job_del(wd->calc_job);
1942         wd->calc_job = ecore_job_add(_calc_job, wd);
1943      }
1944 }
1945
1946 static void
1947 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
1948 {
1949    Pan *sd = evas_object_smart_data_get(obj);
1950 //   Evas_Coord ow, oh;
1951 //   evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1952 //   ow = sd->wd->minw - ow;
1953 //   if (ow < 0) ow = 0;
1954 //   oh = sd->wd->minh - oh;
1955 //   if (oh < 0) oh = 0;
1956 //   if (x < 0) x = 0;
1957 //   if (y < 0) y = 0;
1958 //   if (x > ow) x = ow;
1959 //   if (y > oh) y = oh;
1960    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1961    sd->wd->pan_x = x;
1962    sd->wd->pan_y = y;
1963    evas_object_smart_changed(obj);
1964 }
1965
1966 static void
1967 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1968 {
1969    Pan *sd = evas_object_smart_data_get(obj);
1970
1971    if (x) *x = sd->wd->pan_x;
1972    if (y) *y = sd->wd->pan_y;
1973 }
1974
1975 static void
1976 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
1977 {
1978    Pan *sd = evas_object_smart_data_get(obj);
1979    Evas_Coord ow, oh;
1980
1981    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1982    ow = sd->wd->minw - ow;
1983    if (ow < 0) ow = 0;
1984    oh = sd->wd->minh - oh;
1985    if (oh < 0) oh = 0;
1986    if (x) *x = ow;
1987    if (y) *y = oh;
1988 }
1989
1990 static void
1991 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
1992 {
1993    Pan *sd = evas_object_smart_data_get(obj);
1994
1995    if (w) *w = sd->wd->minw;
1996    if (h) *h = sd->wd->minh;
1997 }
1998
1999 static void
2000 _pan_add(Evas_Object *obj)
2001 {
2002    Pan *sd;
2003    Evas_Object_Smart_Clipped_Data *cd;
2004
2005    _pan_sc.add(obj);
2006    cd = evas_object_smart_data_get(obj);
2007    sd = ELM_NEW(Pan);
2008    if (!sd) return;
2009    sd->__clipped_data = *cd;
2010    free(cd);
2011    evas_object_smart_data_set(obj, sd);
2012 }
2013
2014 static void
2015 _pan_del(Evas_Object *obj)
2016 {
2017    Pan *sd = evas_object_smart_data_get(obj);
2018
2019    if (!sd) return;
2020    _pan_sc.del(obj);
2021 }
2022
2023 static void
2024 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
2025 {
2026    Pan *sd = evas_object_smart_data_get(obj);
2027    Evas_Coord ow, oh;
2028
2029    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
2030    if ((ow == w) && (oh == h)) return;
2031    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2032    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2033 }
2034
2035 static void
2036 _pan_calculate(Evas_Object *obj)
2037 {
2038    Pan *sd = evas_object_smart_data_get(obj);
2039    Item_Block *itb;
2040    Elm_Genlist_GroupItem *git;
2041    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh;
2042    int in = 0;
2043    if( sd->wd->edit_mode != ELM_GENLIST_EDIT_MODE_NONE )
2044      (void)_edit_mode_reset( sd->wd );
2045    EINA_INLIST_FOREACH(sd->wd->group_items, git)
2046    {
2047      git->visible = EINA_FALSE;
2048    }
2049
2050    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
2051    evas_output_viewport_get(evas_object_evas_get(obj), &cvx, &cvy, &cvw, &cvh);
2052    EINA_INLIST_FOREACH(sd->wd->blocks, itb)
2053      {
2054         itb->w = sd->wd->minw;
2055         if (ELM_RECTS_INTERSECT(itb->x - sd->wd->pan_x + ox,
2056                                 itb->y - sd->wd->pan_y + oy,
2057                                 itb->w, itb->h,
2058                                 cvx, cvy, cvw, cvh))
2059           {
2060              if ((!itb->realized) || (itb->changed))
2061                _item_block_realize(itb, in, 0);
2062              _item_block_position(itb,  in);
2063           }
2064         else
2065           {
2066              if (itb->realized) _item_block_unrealize(itb);
2067           }
2068         in += itb->count;
2069      }
2070    EINA_INLIST_FOREACH(sd->wd->group_items, git)
2071    {
2072        if( git->visible )
2073        {
2074          evas_object_raise(git->base);
2075          evas_object_resize( git->base, git->w, git->h-1 );
2076          evas_object_move(git->base, git->x, git->y );
2077          evas_object_show(git->base);
2078        }
2079        else
2080          evas_object_hide(git->base);
2081    }
2082    if( (sd->wd->edit_mode & ELM_GENLIST_EDIT_MODE_REORDER ) && (sd->wd->ed->reorder_item ) )
2083    {
2084      evas_object_raise(sd->wd->ed->reorder_item->base);
2085      evas_object_raise(sd->wd->ed->reorder_item->edit_obj);
2086      }
2087 }
2088
2089 static void
2090 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
2091 {
2092    Pan *sd = evas_object_smart_data_get(obj);
2093
2094    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
2095    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
2096 }
2097
2098 static void
2099 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2100 {
2101    Widget_Data *wd = elm_widget_data_get(obj);
2102    if (!wd) return;
2103    elm_smart_scroller_hold_set(wd->scr, 1);
2104 }
2105
2106 static void
2107 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2108 {
2109    Widget_Data *wd = elm_widget_data_get(obj);
2110    if (!wd) return;
2111    elm_smart_scroller_hold_set(wd->scr, 0);
2112 }
2113
2114 static void
2115 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2116 {
2117    Widget_Data *wd = elm_widget_data_get(obj);
2118    if (!wd) return;
2119    elm_smart_scroller_freeze_set(wd->scr, 1);
2120 }
2121
2122 static void
2123 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
2124 {
2125    Widget_Data *wd = elm_widget_data_get(obj);
2126    if (!wd) return;
2127    elm_smart_scroller_freeze_set(wd->scr, 0);
2128 }
2129
2130 /**
2131  * Add a new Genlist object
2132  *
2133  * @param parent The parent object
2134  * @return The new object or NULL if it cannot be created
2135  *
2136  * @ingroup Genlist
2137  */
2138 EAPI Evas_Object *
2139 elm_genlist_add(Evas_Object *parent)
2140 {
2141    Evas_Object *obj;
2142    Evas *e;
2143    Widget_Data *wd;
2144    Evas_Coord minw, minh;
2145    static Evas_Smart *smart = NULL;
2146
2147    wd = ELM_NEW(Widget_Data);
2148    e = evas_object_evas_get(parent);
2149    obj = elm_widget_add(e);
2150    ELM_SET_WIDTYPE(widtype, "genlist");
2151    elm_widget_type_set(obj, "genlist");
2152    elm_widget_sub_object_add(parent, obj);
2153    elm_widget_data_set(obj, wd);
2154    elm_widget_del_hook_set(obj, _del_hook);
2155    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2156    elm_widget_theme_hook_set(obj, _theme_hook);
2157
2158    wd->scr = elm_smart_scroller_add(e);
2159    elm_smart_scroller_widget_set(wd->scr, obj);
2160    elm_smart_scroller_object_theme_set(obj, wd->scr, "genlist", "base", elm_widget_style_get(obj));
2161    elm_widget_resize_object_set(obj, wd->scr);
2162
2163    elm_smart_scroller_bounce_allow_set(wd->scr, 0, 1);
2164
2165    wd->obj = obj;
2166    wd->mode = ELM_LIST_SCROLL;
2167    wd->max_items_per_block = 32;
2168
2169    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
2170    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
2171    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
2172    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
2173
2174    if (!smart)
2175      {
2176         static Evas_Smart_Class sc;
2177
2178         evas_object_smart_clipped_smart_set(&_pan_sc);
2179         sc = _pan_sc;
2180         sc.name = "elm_genlist_pan";
2181         sc.version = EVAS_SMART_CLASS_VERSION;
2182         sc.add = _pan_add;
2183         sc.del = _pan_del;
2184         sc.resize = _pan_resize;
2185         sc.move = _pan_move;
2186         sc.calculate = _pan_calculate;
2187         smart = evas_smart_class_new(&sc);
2188      }
2189    if (smart)
2190      {
2191         wd->pan_smart = evas_object_smart_add(e, smart);
2192         wd->pan = evas_object_smart_data_get(wd->pan_smart);
2193         wd->pan->wd = wd;
2194      }
2195
2196    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
2197                                      _pan_set, _pan_get,
2198                                      _pan_max_get, _pan_child_size_get);
2199
2200    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
2201                              &minw, &minh);
2202    evas_object_size_hint_min_set(obj, minw, minh);
2203
2204    _sizing_eval(obj);
2205    return obj;
2206 }
2207
2208 static Elm_Genlist_Item *
2209 _item_new(Widget_Data *wd, const Elm_Genlist_Item_Class *itc,
2210           const void *data, Elm_Genlist_Item *parent,
2211           Elm_Genlist_Item_Flags flags,
2212           Evas_Smart_Cb func,
2213           const void *func_data)
2214 {
2215    Elm_Genlist_Item *it;
2216
2217    it = calloc(1, sizeof(Elm_Genlist_Item));
2218    if (!it) return NULL;
2219    it->wd = wd;
2220    it->itc = itc;
2221    it->data = data;
2222    it->parent = parent;
2223    it->flags = flags;
2224    it->func.func = func;
2225    it->func.data = func_data;
2226    return it;
2227 }
2228
2229 static void
2230 _item_block_add(Widget_Data *wd, Elm_Genlist_Item *it)
2231 {
2232    Item_Block *itb = NULL;
2233
2234    if (!it->rel)
2235      {
2236         newblock:
2237         if (it->rel)
2238           {
2239              itb = calloc(1, sizeof(Item_Block));
2240              if (!itb) return;
2241              itb->wd = wd;
2242              if (!it->rel->block)
2243                {
2244                   wd->blocks = 
2245                     eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
2246                   itb->items = eina_list_append(itb->items, it);
2247                }
2248              else
2249                {
2250                   if (it->before)
2251                     {
2252                        wd->blocks = 
2253                          eina_inlist_prepend_relative(wd->blocks, 
2254                                                       EINA_INLIST_GET(itb), 
2255                                                       EINA_INLIST_GET(it->rel->block));
2256                        itb->items = 
2257                          eina_list_prepend_relative(itb->items, it, it->rel);
2258                     }
2259                   else
2260                     {
2261                        wd->blocks = 
2262                          eina_inlist_append_relative(wd->blocks, 
2263                                                      EINA_INLIST_GET(itb), 
2264                                                      EINA_INLIST_GET(it->rel->block));
2265                        itb->items = 
2266                          eina_list_append_relative(itb->items, it, it->rel);
2267                     }
2268                }
2269           }
2270         else
2271           {
2272              if (it->before)
2273                {
2274                   if (wd->blocks)
2275                     {
2276                        itb = (Item_Block *)(wd->blocks);
2277                        if (itb->count >= wd->max_items_per_block)
2278                          {
2279                             itb = calloc(1, sizeof(Item_Block));
2280                             if (!itb) return;
2281                             itb->wd = wd;
2282                             wd->blocks = 
2283                               eina_inlist_prepend(wd->blocks, 
2284                                                   EINA_INLIST_GET(itb));
2285                          }
2286                     }
2287                   else
2288                     {
2289                        itb = calloc(1, sizeof(Item_Block));
2290                        if (!itb) return;
2291                        itb->wd = wd;
2292                        wd->blocks = 
2293                          eina_inlist_prepend(wd->blocks, EINA_INLIST_GET(itb));
2294                     }
2295                   itb->items = eina_list_prepend(itb->items, it);
2296                }
2297              else
2298                {
2299                   if (wd->blocks)
2300                     {
2301                        itb = (Item_Block *)(wd->blocks->last);
2302                        if (itb->count >= wd->max_items_per_block)
2303                          {
2304                             itb = calloc(1, sizeof(Item_Block));
2305                             if (!itb) return;
2306                             itb->wd = wd;
2307                             wd->blocks = 
2308                               eina_inlist_append(wd->blocks, 
2309                                                  EINA_INLIST_GET(itb));
2310                          }
2311                     }
2312                   else
2313                     {
2314                        itb = calloc(1, sizeof(Item_Block));
2315                        if (!itb) return;
2316                        itb->wd = wd;
2317                        wd->blocks = 
2318                          eina_inlist_append(wd->blocks, EINA_INLIST_GET(itb));
2319                     }
2320                   itb->items = eina_list_append(itb->items, it);
2321                }
2322           }
2323      }
2324    else
2325      {
2326         itb = it->rel->block;
2327         if (!itb) goto newblock;
2328         if (it->before)
2329           itb->items = eina_list_prepend_relative(itb->items, it, it->rel);
2330         else
2331           itb->items = eina_list_append_relative(itb->items, it, it->rel);
2332      }
2333    itb->count++;
2334    itb->changed = EINA_TRUE;
2335    it->block = itb;
2336    if (itb->wd->calc_job) ecore_job_del(itb->wd->calc_job);
2337    itb->wd->calc_job = ecore_job_add(_calc_job, itb->wd);
2338    if (it->rel)
2339      {
2340         it->rel->relcount--;
2341         if ((it->rel->delete_me) && (it->rel->relcount == 0))
2342           _item_del(it->rel);
2343         it->rel = NULL;
2344      }
2345    if (itb->count > itb->wd->max_items_per_block)
2346      {
2347         int newc;
2348         Item_Block *itb2;
2349         Elm_Genlist_Item *it2;
2350
2351         newc = itb->count / 2;
2352         itb2 = calloc(1, sizeof(Item_Block));
2353         if (!itb2) return;
2354         itb2->wd = wd;
2355         wd->blocks = 
2356           eina_inlist_append_relative(wd->blocks, EINA_INLIST_GET(itb2), 
2357                                       EINA_INLIST_GET(itb));
2358         itb2->changed = EINA_TRUE;
2359         while ((itb->count > newc) && (itb->items))
2360           {
2361              Eina_List *l;
2362
2363              l = eina_list_last(itb->items);
2364              it2 = l->data;
2365              itb->items = eina_list_remove_list(itb->items, l);
2366              itb->count--;
2367
2368              itb2->items = eina_list_prepend(itb2->items, it2);
2369              it2->block = itb2;
2370              itb2->count++;
2371           }
2372      }
2373 }
2374
2375 #if 1
2376
2377 static int
2378 _queue_proecess(Widget_Data *wd, int norender)
2379 {
2380    int n, showme = 0;
2381    double t0, t;
2382
2383    t0 = ecore_time_get();
2384    for (n = 0; (wd->queue) && (n < 128); n++)
2385      {
2386         Elm_Genlist_Item *it;
2387
2388         it = wd->queue->data;
2389         wd->queue = eina_list_remove_list(wd->queue, wd->queue);
2390         it->queued = EINA_FALSE;
2391         _item_block_add(wd, it);
2392         t = ecore_time_get();
2393         if (it->block->changed)
2394           {
2395              showme = _item_block_recalc(it->block, it->block->num, 1, norender);
2396              it->block->changed = 0;
2397           }
2398         if (showme) it->block->showme = 1;
2399         if (eina_inlist_count(wd->blocks) > 1)
2400           {
2401              if ((t - t0) > (ecore_animator_frametime_get())) break;
2402           }
2403      }
2404    return n;
2405 }
2406
2407 static int
2408 _item_idler(void *data)
2409 {
2410    Widget_Data *wd = data;
2411
2412    if (_queue_proecess(wd, 1) > 0)
2413      {
2414         if (wd->calc_job) ecore_job_del(wd->calc_job);
2415         wd->calc_job = ecore_job_add(_calc_job, wd);
2416      }
2417    if (!wd->queue)
2418      {
2419         wd->queue_idler = NULL;
2420         return 0;
2421      }
2422    return 1;
2423 }
2424
2425 static void
2426 _item_queue(Widget_Data *wd, Elm_Genlist_Item *it)
2427 {
2428    if (it->queued) return;
2429    it->queued = EINA_TRUE;
2430    wd->queue = eina_list_append(wd->queue, it);
2431    while ((wd->queue) && ((!wd->blocks) || (!wd->blocks->next)))
2432      {
2433         if (wd->queue_idler)
2434           {
2435              ecore_idler_del(wd->queue_idler);
2436              wd->queue_idler = NULL;
2437           }
2438         _queue_proecess(wd, 0);
2439      }
2440    if (!wd->queue_idler) wd->queue_idler = ecore_idler_add(_item_idler, wd);
2441 }
2442 #else
2443
2444 static int
2445 _item_idler(void *data)
2446 {
2447    Widget_Data *wd = data;
2448    int n, showme = 0;
2449    double t0, t;
2450
2451    t0 = ecore_time_get();
2452    for (n = 0; (wd->queue) && (n < 128); n++)
2453      {
2454         Elm_Genlist_Item *it;
2455
2456         it = wd->queue->data;
2457         wd->queue = eina_list_remove_list(wd->queue, wd->queue);
2458         it->queued = EINA_FALSE;
2459         _item_block_add(wd, it);
2460         t = ecore_time_get();
2461         if (it->block->changed)
2462           {
2463              showme = _item_block_recalc(it->block, it->block->num, 1, 1);
2464              it->block->changed = 0;
2465           }
2466         if (showme) it->block->showme = 1;
2467         if (eina_inlist_count(wd->blocks) > 1)
2468           {
2469              if ((t - t0) > (ecore_animator_frametime_get())) break;
2470           }
2471      }
2472    if (n > 0)
2473      {
2474         if (wd->calc_job) ecore_job_del(wd->calc_job);
2475         wd->calc_job = ecore_job_add(_calc_job, wd);
2476      }
2477    if (!wd->queue)
2478      {
2479         wd->queue_idler = NULL;
2480         return 0;
2481      }
2482    return 1;
2483 }
2484
2485 static void
2486 _item_queue(Widget_Data *wd, Elm_Genlist_Item *it)
2487 {
2488         Item_Block *itb;
2489
2490         // Add the initial set of Items directly to the Blocks, to show the genlist
2491         // without empty screen.
2492         itb = (Item_Block *)(wd->blocks);
2493         if( (NULL == itb) || (itb->count < wd->max_items_per_block) )
2494         {
2495                 _item_block_add(wd, it);
2496         }
2497         else
2498         {
2499                 if (it->queued) return;
2500                 if (!wd->queue_idler) wd->queue_idler = ecore_idler_add(_item_idler, wd);
2501                 it->queued = EINA_TRUE;
2502                 wd->queue = eina_list_append(wd->queue, it);
2503         }
2504 }
2505
2506 #endif
2507
2508 /**
2509  * Add Group Item to the genlist
2510  *
2511  * @param obj The genlist object
2512  * @param itc The item class for the item
2513  * @param data The group item data
2514  */
2515 EAPI Elm_Genlist_GroupItem *
2516 elm_genlist_groupitem_add(Evas_Object *obj, const Elm_Genlist_Item_Class *itc,
2517                         const void *data)
2518 {
2519         Elm_Genlist_GroupItem *git;
2520         Widget_Data *wd = elm_widget_data_get(obj);
2521
2522         git = calloc(1, sizeof(Elm_Genlist_GroupItem));
2523         if (!git) return NULL;
2524         git->wd = wd;
2525         git->itc = itc;
2526         git->data = data;
2527
2528         wd->group_items = eina_inlist_append(wd->group_items, EINA_INLIST_GET(git) );
2529         return git;
2530 }
2531
2532 /**
2533  * Delete a given groupitem
2534  *
2535  * This deletes the group item from genlist and calls the genlist group item del class
2536  * callback defined in the item class, if it is set.
2537  *
2538  * @param git The group item
2539  *
2540  * @ingroup Genlist
2541  */
2542 EAPI void
2543 elm_genlist_groupitem_del(Elm_Genlist_GroupItem *git)
2544 {
2545    _groupitem_remove( git, EINA_TRUE);
2546 }
2547
2548 /**
2549  * Append item to the end of the genlist
2550  *
2551  * This appends the given item to the end of the list or the end of the
2552  * children if the parent is given.
2553  *
2554  * @param obj The genlist object
2555  * @param itc The item class for the item
2556  * @param data The item data
2557  * @param parent The parent item, or NULL if none
2558  * @param flags Item flags
2559  * @param func Convenience function called when item selected
2560  * @param func_data Data passed to @p func above.
2561  * @return A handle to the item added or NULL if not possible
2562  *
2563  * @ingroup Genlist
2564  */
2565 EAPI Elm_Genlist_Item *
2566 elm_genlist_item_append(Evas_Object *obj, const Elm_Genlist_Item_Class *itc,
2567                         const void *data, Elm_Genlist_Item *parent,
2568                         Elm_Genlist_Item_Flags flags,
2569                         Evas_Smart_Cb func, const void *func_data)
2570 {
2571    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2572    Widget_Data *wd = elm_widget_data_get(obj);
2573    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func, func_data);
2574    if (!wd) return NULL;
2575    if (!it) return NULL;
2576    if (!it->parent)
2577      {
2578         wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
2579         it->rel = NULL;
2580         it->before = 0;
2581      }
2582    else
2583      {
2584         Elm_Genlist_Item *it2 = NULL;
2585         Eina_List *ll = eina_list_last(it->parent->items);
2586         if (ll) it2 = ll->data;
2587         it->parent->items = eina_list_append(it->parent->items, it);
2588         if (!it2) it2 = it->parent;
2589         wd->items =
2590           eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
2591                                       EINA_INLIST_GET(it2));
2592         if( it->parent->group_item)
2593           _set_groupitem( it, it->parent->group_item );
2594         it->rel = it2;
2595         it->rel->relcount++;
2596         it->before = 0;
2597      }
2598    _item_queue(wd, it);
2599    return it;
2600 }
2601
2602 /**
2603  * Append item to the end of the genlist with Group Item
2604  *
2605  * This appends the given item to the end of the list or the end of the
2606  * children if the parent is given.
2607  *
2608  * @param obj The genlist object
2609  * @param itc The item class for the item
2610  * @param data The item data
2611  * @param parent The parent item, or NULL if none
2612  * @param flags Item flags
2613  * @param git Group Item
2614  * @param func Convenience function called when item selected
2615  * @param func_data Data passed to @p func above.
2616  * @return A handle to the item added or NULL if not possible
2617  *
2618  * @ingroup Genlist
2619  */
2620 EAPI Elm_Genlist_Item *
2621 elm_genlist_item_append_with_group(Evas_Object *obj, const Elm_Genlist_Item_Class *itc,
2622                         const void *data, Elm_Genlist_Item *parent,
2623                         Elm_Genlist_Item_Flags flags, Elm_Genlist_GroupItem *git,
2624                         Evas_Smart_Cb func, const void *func_data)
2625 {
2626     ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2627     Widget_Data *wd = elm_widget_data_get(obj);
2628     Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func, func_data);
2629     if (!wd) return NULL;
2630     if (!it) return NULL;
2631     if (!it->parent)
2632     {
2633       wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
2634       it->rel = NULL;
2635       it->before = 0;
2636     }
2637     else
2638     {
2639       Elm_Genlist_Item *it2 = NULL;
2640       Eina_List *ll = eina_list_last(it->parent->items);
2641       if (ll) it2 = ll->data;
2642       it->parent->items = eina_list_append(it->parent->items, it);
2643       if (!it2) it2 = it->parent;
2644       wd->items =
2645         eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
2646                                     EINA_INLIST_GET(it2));
2647       if( it->parent->group_item)
2648         _set_groupitem( it, it->parent->group_item );
2649       it->rel = it2;
2650       it->rel->relcount++;
2651       it->before = 0;
2652     }
2653     _set_groupitem( it, git );
2654     _item_queue(wd, it);
2655     return it;
2656 }
2657
2658 /**
2659  * Prepend item at start of the genlist
2660  *
2661  * This adds an item to the beginning of the list or beginning of the children
2662  * of the parent if given.
2663  *
2664  * @param obj The genlist object
2665  * @param itc The item class for the item
2666  * @param data The item data
2667  * @param parent The parent item, or NULL if none
2668  * @param flags Item flags
2669  * @param func Convenience function called when item selected
2670  * @param func_data Data passed to @p func above.
2671  * @return A handle to the item added or NULL if not possible
2672  *
2673  * @ingroup Genlist
2674  */
2675 EAPI Elm_Genlist_Item *
2676 elm_genlist_item_prepend(Evas_Object *obj, const Elm_Genlist_Item_Class *itc,
2677                          const void *data, Elm_Genlist_Item *parent,
2678                          Elm_Genlist_Item_Flags flags,
2679                          Evas_Smart_Cb func, const void *func_data)
2680 {
2681    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2682    Widget_Data *wd = elm_widget_data_get(obj);
2683    Elm_Genlist_Item *it = _item_new(wd, itc, data, parent, flags, func, func_data);
2684    if (!wd) return NULL;
2685    if (!it) return NULL;
2686    if (!it->parent)
2687      wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
2688    else
2689      {
2690         printf("FIXME: 12 tree not handled yet\n");
2691      }
2692    it->rel = NULL;
2693    it->before = 1;
2694    _item_queue(wd, it);
2695    return it;
2696 }
2697
2698 /**
2699  * Insert item before another in the genlist
2700  *
2701  * This inserts an item before another in the list. It will be in the same tree
2702  * level as the item it is inseted before.
2703  *
2704  * @param obj The genlist object
2705  * @param itc The item class for the item
2706  * @param data The item data
2707  * @param before The item to insert before
2708  * @param flags Item flags
2709  * @param func Convenience function called when item selected
2710  * @param func_data Data passed to @p func above.
2711  * @return A handle to the item added or NULL if not possible
2712  *
2713  * @ingroup Genlist
2714  */
2715 EAPI Elm_Genlist_Item *
2716 elm_genlist_item_insert_before(Evas_Object *obj, const Elm_Genlist_Item_Class *itc,
2717                                const void *data, Elm_Genlist_Item *before,
2718                                Elm_Genlist_Item_Flags flags,
2719                                Evas_Smart_Cb func, const void *func_data)
2720 {
2721    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2722    Widget_Data *wd = elm_widget_data_get(obj);
2723    Elm_Genlist_Item *it = _item_new(wd, itc, data, NULL, flags, func, func_data);
2724    if (!wd) return NULL;
2725    if (!it) return NULL;
2726    if (!it->parent)
2727      wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it), 
2728                                               EINA_INLIST_GET(before));
2729    else
2730      {
2731         printf("FIXME: 13 tree not handled yet\n");
2732      }
2733    it->rel = before;
2734    it->rel->relcount++;
2735    it->before = 1;
2736    _item_queue(wd, it);
2737    return it;
2738 }
2739
2740 /**
2741  * Insert and item after another in the genlst
2742  *
2743  * This inserts an item after another in the list. It will be in the same tree
2744  * level as the item it is inseted after.
2745  *
2746  * @param obj The genlist object
2747  * @param itc The item class for the item
2748  * @param data The item data
2749  * @param after The item to insert after
2750  * @param flags Item flags
2751  * @param func Convenience function called when item selected
2752  * @param func_data Data passed to @p func above.
2753  * @return A handle to the item added or NULL if not possible
2754  *
2755  * @ingroup Genlist
2756  */
2757 EAPI Elm_Genlist_Item *
2758 elm_genlist_item_insert_after(Evas_Object *obj, const Elm_Genlist_Item_Class *itc,
2759                               const void *data, Elm_Genlist_Item *after,
2760                               Elm_Genlist_Item_Flags flags,
2761                               Evas_Smart_Cb func, const void *func_data)
2762 {
2763    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2764    Widget_Data *wd = elm_widget_data_get(obj);
2765    Elm_Genlist_Item *it = _item_new(wd, itc, data, NULL, flags, func, func_data);
2766    if (!wd) return NULL;
2767    if (!it) return NULL;
2768    if (!it->parent)
2769      wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it), 
2770                                              EINA_INLIST_GET(after));
2771    else
2772      {
2773         printf("FIXME: 14 tree not handled yet\n");
2774      }
2775    it->rel = after;
2776    it->rel->relcount++;
2777    it->before = 0;
2778    _item_queue(wd, it);
2779    return it;
2780 }
2781
2782 /**
2783  * Moves the Genlist Item
2784  */
2785 EAPI void
2786 elm_genlist_item_move_after(Elm_Genlist_Item *it, Elm_Genlist_Item *after )
2787 {
2788   if (!it) return;
2789
2790   it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
2791   _item_block_del(it);
2792
2793   if( after)
2794     {
2795     it->wd->items = eina_inlist_prepend_relative(it->wd->items, EINA_INLIST_GET(it),
2796                                                  EINA_INLIST_GET(after));
2797      it->rel = after;
2798       it->rel->relcount++;
2799     }
2800   else
2801   {
2802       it->wd->items = eina_inlist_prepend(it->wd->items, EINA_INLIST_GET(it));
2803     }
2804
2805     it->before = 1;
2806    _item_queue(it->wd, it);
2807 }
2808
2809 /**
2810  * Clear the genlist
2811  *
2812  * This clears all items in the list, leaving it empty.
2813  *
2814  * @param obj The genlist object
2815  *
2816  * @ingroup Genlist
2817  */
2818 EAPI void
2819 elm_genlist_clear(Evas_Object *obj)
2820 {
2821    ELM_CHECK_WIDTYPE(obj, widtype);
2822    Widget_Data *wd = elm_widget_data_get(obj);
2823    if (!wd) return;
2824
2825    while (wd->group_items)
2826    {
2827      _groupitem_remove((Elm_Genlist_GroupItem *)wd->group_items, EINA_FALSE);
2828
2829    }
2830    while (wd->items)
2831      {
2832         Elm_Genlist_Item *it = (Elm_Genlist_Item *)(wd->items);
2833
2834         wd->items = eina_inlist_remove(wd->items, wd->items);
2835         if (it->realized) _item_unrealize(it);
2836         if (it->itc->func.del) it->itc->func.del(it->data, it->wd->obj);
2837         if (it->long_timer) ecore_timer_del(it->long_timer);
2838         free(it);
2839      }
2840    while (wd->blocks)
2841      {
2842         Item_Block *itb = (Item_Block *)(wd->blocks);
2843
2844         wd->blocks = eina_inlist_remove(wd->blocks, wd->blocks);
2845         if (itb->items) eina_list_free(itb->items);
2846         free(itb);
2847      }
2848    if (wd->calc_job)
2849      {
2850         ecore_job_del(wd->calc_job);
2851         wd->calc_job = NULL;
2852      }
2853    if (wd->queue_idler)
2854      {
2855         ecore_idler_del(wd->queue_idler);
2856         wd->queue_idler = NULL;
2857      }
2858    if (wd->queue)
2859      {
2860         eina_list_free(wd->queue);
2861         wd->queue = NULL;
2862      }
2863    if (wd->selected)
2864      {
2865         eina_list_free(wd->selected);
2866         wd->selected = NULL;
2867      }
2868    wd->show_item = NULL;
2869    wd->pan_x = 0;
2870    wd->pan_y = 0;
2871    wd->minw = 0;
2872    wd->minh = 0;
2873    evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
2874    evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2875    _sizing_eval(obj);
2876 }
2877
2878 /**
2879  * Enable or disable multi-select in the genlist
2880  *
2881  * This enables (EINA_TRUE) or disableds (EINA_FALSE) multi-select in the list. This allows
2882  * more than 1 item to be selected.
2883  *
2884  * @param obj The genlist object
2885  * @param multi Multi-select enable/disable
2886  *
2887  * @ingroup Genlist
2888  */
2889 EAPI void
2890 elm_genlist_multi_select_set(Evas_Object *obj, Eina_Bool multi)
2891 {
2892    ELM_CHECK_WIDTYPE(obj, widtype);
2893    Widget_Data *wd = elm_widget_data_get(obj);
2894    if (!wd) return;
2895    wd->multi = multi;
2896 }
2897
2898 /**
2899  * Gets if multi-select in genlist is enable or disable
2900  *
2901  * @param obj The genlist object
2902  * @return Multi-select enable/disable
2903  * (EINA_TRUE = enabled/EINA_FALSE = disabled)
2904  *
2905  * @ingroup Genlist
2906  */
2907 EAPI Eina_Bool
2908 elm_genlist_multi_select_get(const Evas_Object *obj)
2909 {
2910    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2911    Widget_Data *wd = elm_widget_data_get(obj);
2912    if (!wd) return EINA_FALSE;
2913    return wd->multi;
2914 }
2915
2916
2917 /**
2918  * Get the selectd item in the genlist
2919  *
2920  * This gets the selected item in the list (if multi-select is enabled only
2921  * the first item in the list is selected - which is not very useful, so see
2922  * elm_genlist_selected_items_get()for when multi-select is used).
2923  *
2924  * If no item is selected, NULL is returned.
2925  *
2926  * @param obj The genlist object
2927  * @return The selected item, or NULL if none.
2928  *
2929  * @ingroup Genlist
2930  */
2931 EAPI Elm_Genlist_Item *
2932 elm_genlist_selected_item_get(const Evas_Object *obj)
2933 {
2934    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2935    Widget_Data *wd = elm_widget_data_get(obj);
2936    if (!wd) return NULL;
2937    if (wd->selected) return wd->selected->data;
2938    return NULL;
2939 }
2940
2941 /**
2942  * Get a list of selected items in the genlist
2943  *
2944  * This retgurns a list of the selected items. This list pointer is only valid
2945  * so long as no items are selected or unselected (or unselected implicitly
2946  * by deletion). The list contains Elm_Genlist_Item pointers.
2947  *
2948  * @param obj The genlist object
2949  * @return The list of selected items, nor NULL if none are selected.
2950  *
2951  * @ingroup Genlist
2952  */
2953 EAPI const Eina_List *
2954 elm_genlist_selected_items_get(const Evas_Object *obj)
2955 {
2956    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2957    Widget_Data *wd = elm_widget_data_get(obj);
2958    if (!wd) return NULL;
2959    return wd->selected;
2960 }
2961
2962 /**
2963  * Get a list of realized items in genlist
2964  *
2965  * This returns a list of the realized items in the genlist. The list
2966  * contains Elm_Genlist_Item pointers. The list must be freed by the
2967  * caller when done with eina_list_free(). The item pointers in the list
2968  * are only vallid so long as those items are not deleted or the genlist is
2969  * not deleted.
2970  *
2971  * @param obj The genlist object
2972  * @return The list of realized items, nor NULL if none are realized.
2973  *
2974  * @ingroup Genlist
2975  */
2976 EAPI Eina_List *
2977 elm_genlist_realized_items_get(const Evas_Object *obj)
2978 {
2979    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2980    Widget_Data *wd = elm_widget_data_get(obj);
2981    Eina_List *list = NULL;
2982    Item_Block *itb;
2983    Eina_Bool done = 0;
2984    if (!wd) return NULL;
2985    EINA_INLIST_FOREACH(wd->blocks, itb)
2986      {
2987         if (itb->realized)
2988           {
2989              Eina_List *l;
2990              Elm_Genlist_Item *it;
2991              
2992              done = 1;
2993              EINA_LIST_FOREACH(itb->items, l, it)
2994                {
2995                   if (it->realized) list = eina_list_append(list, it);
2996                }
2997           }
2998         else
2999           {
3000              if (done) break;
3001           }
3002      }
3003    return list;
3004 }
3005
3006 /**
3007  * Get the item that is at the x, y canvas coords
3008  *
3009  * This returns the item at the given coordinates (which are canvas relative
3010  * not object-relative). If an item is at that coordinate, that item handle
3011  * is returned, and if @p posret is not NULL, the integer pointed to is set
3012  * to a value of -1, 0 or 1, depending if the coordinate is on the upper
3013  * portion of that item (-1), on the middle section (0) or on the lower part
3014  * (1). If NULL is returned as an item (no item found there), then posret
3015  * may indicate -1 or 1 based if the coordinate is above or below all items
3016  * respectively in the genlist.
3017  *
3018  * @param it The item
3019  * @param x The input x coordinate
3020  * @param y The input y coordinate
3021  * @param posret The position relative to the item returned here
3022  * @return The item at the coordinates or NULL if none
3023  *
3024  * @ingroup Genlist
3025  */
3026 EAPI Elm_Genlist_Item *
3027 elm_genlist_at_xy_item_get(const Evas_Object *obj, Evas_Coord x, Evas_Coord y, int *posret)
3028 {
3029    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3030    Widget_Data *wd = elm_widget_data_get(obj);
3031    Evas_Coord ox, oy, ow, oh;
3032    Item_Block *itb;
3033    Evas_Coord lasty;
3034    if (!wd) return NULL;
3035    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
3036    lasty = oy;
3037    EINA_INLIST_FOREACH(wd->blocks, itb)
3038      {
3039         Eina_List *l;
3040         Elm_Genlist_Item *it;
3041
3042         if (!ELM_RECTS_INTERSECT(ox + itb->x - itb->wd->pan_x,
3043                                  oy + itb->y - itb->wd->pan_y,
3044                                  itb->w, itb->h, x, y, 1, 1))
3045           continue;
3046         EINA_LIST_FOREACH(itb->items, l, it)
3047           {
3048              Evas_Coord itx, ity;
3049
3050              itx = ox + itb->x + it->x - itb->wd->pan_x;
3051              ity = oy + itb->y + it->y - itb->wd->pan_y;
3052              if (ELM_RECTS_INTERSECT(itx, ity, it->w, it->h, x, y, 1, 1))
3053                {
3054                   if (posret)
3055                     {
3056                        if (y <= (ity + (it->h / 4))) *posret = -1;
3057                        else if (y >= (ity + it->h - (it->h / 4))) *posret = 1;
3058                        else *posret = 0;
3059                     }
3060                   return it;
3061                }
3062              lasty = ity + it->h;
3063           }
3064      }
3065    if (posret)
3066      {
3067         if (y > lasty) *posret = 1;
3068         else *posret = -1;
3069      }
3070    return NULL;
3071 }
3072
3073 /**
3074  * Get the first item in the genlist
3075  *
3076  * This returns the first item in the list.
3077  *
3078  * @param obj The genlist object
3079  * @return The first item, or NULL if none
3080  *
3081  * @ingroup Genlist
3082  */
3083 EAPI Elm_Genlist_Item *
3084 elm_genlist_first_item_get(const Evas_Object *obj)
3085 {
3086    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3087    Widget_Data *wd = elm_widget_data_get(obj);
3088    if (!wd) return NULL;
3089    if (!wd->items) return NULL;
3090    Elm_Genlist_Item *it = (Elm_Genlist_Item *)(wd->items);
3091    while ((it) && (it->delete_me))
3092      it = (Elm_Genlist_Item *)(EINA_INLIST_GET(it)->next);
3093    return it;
3094 }
3095
3096 /**
3097  * Get the last item in the genlist
3098  *
3099  * This returns the last item in the list.
3100  *
3101  * @return The last item, or NULL if none
3102  *
3103  * @ingroup Genlist
3104  */
3105 EAPI Elm_Genlist_Item *
3106 elm_genlist_last_item_get(const Evas_Object *obj)
3107 {
3108    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3109    Widget_Data *wd = elm_widget_data_get(obj);
3110    if (!wd->items) return NULL;
3111    Elm_Genlist_Item *it = (Elm_Genlist_Item *)(wd->items->last);
3112    if (!wd) return NULL;
3113    while ((it) && (it->delete_me))
3114      it = (Elm_Genlist_Item *)(EINA_INLIST_GET(it)->prev);
3115    return it;
3116 }
3117
3118 /**
3119  * Get the next item in the genlist
3120  *
3121  * This returns the item after the item @p it.
3122  *
3123  * @param it The item
3124  * @return The item after @p it, or NULL if none
3125  *
3126  * @ingroup Genlist
3127  */
3128 EAPI Elm_Genlist_Item *
3129 elm_genlist_item_next_get(const Elm_Genlist_Item *it)
3130 {
3131    while (it)
3132      {
3133         it = (Elm_Genlist_Item *)(EINA_INLIST_GET(it)->next);
3134         if ((it) && (!it->delete_me)) break;
3135      }
3136    return (Elm_Genlist_Item *)it;
3137 }
3138
3139 /**
3140  * Get the previous item in the genlist
3141  *
3142  * This returns the item before the item @p it.
3143  *
3144  * @param it The item
3145  * @return The item before @p it, or NULL if none
3146  *
3147  * @ingroup Genlist
3148  */
3149 EAPI Elm_Genlist_Item *
3150 elm_genlist_item_prev_get(const Elm_Genlist_Item *it)
3151 {
3152    while (it)
3153      {
3154         it = (Elm_Genlist_Item *)(EINA_INLIST_GET(it)->prev);
3155         if ((it) && (!it->delete_me)) break;
3156      }
3157    return (Elm_Genlist_Item *)it;
3158 }
3159
3160 /**
3161  * Get the genlist object from an item
3162  *
3163  * This returns the genlist object itself that an item belongs to.
3164  *
3165  * @param it The item
3166  * @return The genlist object
3167  *
3168  * @ingroup Genlist
3169  */
3170 EAPI Evas_Object *
3171 elm_genlist_item_genlist_get(const Elm_Genlist_Item *it)
3172 {
3173    if (!it) return NULL;
3174    return it->wd->obj;
3175 }
3176
3177 /**
3178  * Get the parent item of the given item
3179  *
3180  * This returns the prent item of the item @p it given.
3181  *
3182  * @param it The item
3183  * @return The parent of the item or NULL if none
3184  *
3185  * @ingroup Genlist
3186  */
3187 EAPI Elm_Genlist_Item *
3188 elm_genlist_item_parent_get(const Elm_Genlist_Item *it)
3189 {
3190    if (!it) return NULL;
3191    return it->parent;
3192 }
3193
3194 /**
3195  * Clear all sub-items (children) of the given item
3196  *
3197  * This clears all items that are children (or their descendants) of the
3198  * given item @p it.
3199  *
3200  * @param it The item
3201  *
3202  * @ingroup Genlist
3203  */
3204 EAPI void
3205 elm_genlist_item_subitems_clear(Elm_Genlist_Item *it)
3206 {
3207    Eina_List *tl = NULL, *l;
3208    Elm_Genlist_Item *it2;
3209
3210    if (!it) return;
3211    EINA_LIST_FOREACH(it->items, l, it2)
3212      tl = eina_list_append(tl, it2);
3213    EINA_LIST_FREE(tl, it2)
3214      elm_genlist_item_del(it2);
3215 }
3216
3217 /**
3218  * Set the selected state of an item
3219  *
3220  * This sets the selected state (1 selected, 0 not selected) of the given
3221  * item @p it.
3222  *
3223  * @param it The item
3224  * @param selected The slected state
3225  *
3226  * @ingroup Genlist
3227  */
3228 EAPI void
3229 elm_genlist_item_selected_set(Elm_Genlist_Item *it, Eina_Bool selected)
3230 {
3231    Widget_Data *wd = elm_widget_data_get(it->wd->obj);
3232    if (!wd) return;
3233    if (!it) return;
3234    if (it->delete_me) return;
3235    selected = !!selected;
3236    if (it->selected == selected) return;
3237
3238    if (selected)
3239      {
3240         if (!wd->multi)
3241           {
3242              while (wd->selected)
3243                _item_unselect(wd->selected->data);
3244           }
3245         _item_hilight(it);
3246         _item_select(it);
3247      }
3248    else
3249      _item_unselect(it);
3250 }
3251
3252 /**
3253  * Get the selected state of an item
3254  *
3255  * This gets the selected state of an item (1 selected, 0 not selected).
3256  *
3257  * @param it The item
3258  * @return The selected state
3259  *
3260  * @ingroup Genlist
3261  */
3262 EAPI Eina_Bool
3263 elm_genlist_item_selected_get(const Elm_Genlist_Item *it)
3264 {
3265    if (!it) return EINA_FALSE;
3266    return it->selected;
3267 }
3268
3269 /**
3270  * Sets the expanded state of an item (if it's a parent)
3271  *
3272  * This expands or contracts a parent iterm (thus showing or hiding the
3273  * children).
3274  *
3275  * @param it The item
3276  * @param expanded The expanded state (1 expanded, 0 not expanded).
3277  *
3278  * @ingroup Genlist
3279  */
3280 EAPI void
3281 elm_genlist_item_expanded_set(Elm_Genlist_Item *it, Eina_Bool expanded)
3282 {
3283    if (!it) return;
3284    if (it->expanded == expanded) return;
3285    it->expanded = expanded;
3286    if (it->expanded)
3287      {
3288         if (it->realized)
3289           edje_object_signal_emit(it->base, "elm,state,expanded", "elm");
3290         evas_object_smart_callback_call(it->wd->obj, "expanded", it);
3291      }
3292    else
3293      {
3294         if (it->realized)
3295           edje_object_signal_emit(it->base, "elm,state,contracted", "elm");
3296         evas_object_smart_callback_call(it->wd->obj, "contracted", it);
3297      }
3298 }
3299
3300 /**
3301  * Get the expanded state of an item
3302  *
3303  * This gets the expanded state of an item
3304  *
3305  * @param it The item
3306  * @return Thre expanded state
3307  *
3308  * @ingroup Genlist
3309  */
3310 EAPI Eina_Bool
3311 elm_genlist_item_expanded_get(const Elm_Genlist_Item *it)
3312 {
3313    if (!it) return EINA_FALSE;
3314    return it->expanded;
3315 }
3316
3317 /**
3318  * Sets the disabled state of an item.
3319  *
3320  * A disabled item cannot be selected or unselected. It will also change
3321  * appearance to appear disabled. This sets the disabled state (1 disabled, 0
3322  * not disabled).
3323  *
3324  * @param it The item
3325  * @param disabled The disabled state
3326  *
3327  * @ingroup Genlist
3328  */
3329 EAPI void
3330 elm_genlist_item_disabled_set(Elm_Genlist_Item *it, Eina_Bool disabled)
3331 {
3332    if (!it) return;
3333    if (it->disabled == disabled) return;
3334    if (it->delete_me) return;
3335    it->disabled = disabled;
3336    if (it->realized)
3337      {
3338         if (it->disabled)
3339           edje_object_signal_emit(it->base, "elm,state,disabled", "elm");
3340         else
3341           edje_object_signal_emit(it->base, "elm,state,enabled", "elm");
3342      }
3343 }
3344
3345 /**
3346  * Get the disabled state of an item
3347  *
3348  * This gets the disabld state of the given item.
3349  *
3350  * @param it The item
3351  * @return The disabled state
3352  *
3353  * @ingroup Genlist
3354  */
3355 EAPI Eina_Bool
3356 elm_genlist_item_disabled_get(const Elm_Genlist_Item *it)
3357 {
3358    if (!it) return EINA_FALSE;
3359    if (it->delete_me) return EINA_FALSE;
3360    return it->disabled;
3361 }
3362
3363 /**
3364  * Sets the display only state of an item.
3365  *
3366  * A display only item cannot be selected or unselected. It is for display
3367  * only and not selecting or otherwise clicking, dragging etc. by the user,
3368  * thus finger size rules will not be applied to this item.
3369  *
3370  * @param it The item
3371  * @param display_only The display only state
3372  *
3373  * @ingroup Genlist
3374  */
3375 EAPI void
3376 elm_genlist_item_display_only_set(Elm_Genlist_Item *it, Eina_Bool display_only)
3377 {
3378    if (!it) return;
3379    if (!it->block) return;
3380    if (it->display_only == display_only) return;
3381    if (it->delete_me) return;
3382    it->display_only = display_only;
3383    it->mincalcd = EINA_FALSE;
3384    it->updateme = EINA_TRUE;
3385    it->block->updateme = EINA_TRUE;
3386    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
3387    it->wd->update_job = ecore_job_add(_update_job, it->wd);
3388 }
3389
3390 /**
3391  * Get the display only state of an item
3392  *
3393  * This gets the display only state of the given item.
3394  *
3395  * @param it The item
3396  * @return The display only state
3397  *
3398  * @ingroup Genlist
3399  */
3400 EAPI Eina_Bool
3401 elm_genlist_item_display_only_get(const Elm_Genlist_Item *it)
3402 {
3403    if (!it) return EINA_FALSE;
3404    if (it->delete_me) return EINA_FALSE;
3405    return it->display_only;
3406 }
3407
3408 /**
3409  * Show the given item
3410  *
3411  * This causes genlist to jump to the given item @p it and show it (by scrolling),
3412  * if it is not fully visible.
3413  *
3414  * @param it The item
3415  *
3416  * @ingroup Genlist
3417  */
3418 EAPI void
3419 elm_genlist_item_show(Elm_Genlist_Item *it)
3420 {
3421    if (!it) return;
3422    if (it->delete_me) return;
3423    if ((it->queued) || (!it->mincalcd))
3424      {
3425         it->wd->show_item = it;
3426         it->wd->bring_in = 1;
3427         it->showme = EINA_TRUE;
3428         return;
3429      }
3430    if (it->wd->show_item)
3431      {
3432         it->wd->show_item->showme = EINA_FALSE;
3433         it->wd->show_item = NULL;
3434      }
3435    elm_smart_scroller_child_region_show(it->wd->scr,
3436                                         it->x + it->block->x,
3437                                         it->y + it->block->y,
3438                                         it->block->w, it->h);
3439 }
3440
3441 /**
3442  * Bring in the given item
3443  *
3444  * This causes genlist to jump to the given item @p it and show it (by scrolling),
3445  * if it is not fully visible. This may use animation to do so and take a
3446  * period of time
3447  *
3448  * @param it The item
3449  *
3450  * @ingroup Genlist
3451  */
3452 EAPI void
3453 elm_genlist_item_bring_in(Elm_Genlist_Item *it)
3454 {
3455    if (!it) return;
3456    if (it->delete_me) return;
3457    if ((it->queued) || (!it->mincalcd))
3458      {
3459         it->wd->show_item = it;
3460         it->wd->bring_in = 1;
3461         it->showme = EINA_TRUE;
3462         return;
3463      }
3464    if (it->wd->show_item)
3465      {
3466         it->wd->show_item->showme = EINA_FALSE;
3467         it->wd->show_item = NULL;
3468      }
3469    elm_smart_scroller_region_bring_in(it->wd->scr,
3470                                       it->x + it->block->x,
3471                                       it->y + it->block->y,
3472                                       it->block->w, it->h);
3473 }
3474
3475 /**
3476  * Show the given item at the top
3477  *
3478  * This causes genlist to jump to the given item @p it and show it (by scrolling),
3479  * if it is not fully visible.
3480  *
3481  * @param it The item
3482  *
3483  * @ingroup Genlist
3484  */
3485 EAPI void
3486 elm_genlist_item_top_show(Elm_Genlist_Item *it)
3487 {
3488    Evas_Coord ow, oh;
3489
3490    if (!it) return;
3491    if (it->delete_me) return;
3492    if ((it->queued) || (!it->mincalcd))
3493      {
3494         it->wd->show_item = it;
3495         it->wd->bring_in = 1;
3496         it->showme = EINA_TRUE;
3497         return;
3498      }
3499    if (it->wd->show_item)
3500      {
3501         it->wd->show_item->showme = EINA_FALSE;
3502         it->wd->show_item = NULL;
3503      }
3504    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
3505    elm_smart_scroller_child_region_show(it->wd->scr,
3506                                         it->x + it->block->x,
3507                                         it->y + it->block->y,
3508                                         it->block->w, oh);
3509 }
3510
3511 /**
3512  * Bring in the given item at the top
3513  *
3514  * This causes genlist to jump to the given item @p it and show it (by scrolling),
3515  * if it is not fully visible. This may use animation to do so and take a
3516  * period of time
3517  *
3518  * @param it The item
3519  *
3520  * @ingroup Genlist
3521  */
3522 EAPI void
3523 elm_genlist_item_top_bring_in(Elm_Genlist_Item *it)
3524 {
3525    Evas_Coord ow, oh;
3526
3527    if (!it) return;
3528    if (it->delete_me) return;
3529    if ((it->queued) || (!it->mincalcd))
3530      {
3531         it->wd->show_item = it;
3532         it->wd->bring_in = 1;
3533         it->showme = EINA_TRUE;
3534         return;
3535      }
3536    if (it->wd->show_item)
3537      {
3538         it->wd->show_item->showme = EINA_FALSE;
3539         it->wd->show_item = NULL;
3540      }
3541    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
3542    elm_smart_scroller_region_bring_in(it->wd->scr,
3543                                       it->x + it->block->x,
3544                                       it->y + it->block->y,
3545                                       it->block->w, oh);
3546 }
3547
3548 /**
3549  * Show the given item at the middle
3550  *
3551  * This causes genlist to jump to the given item @p it and show it (by scrolling),
3552  * if it is not fully visible.
3553  *
3554  * @param it The item
3555  *
3556  * @ingroup Genlist
3557  */
3558 EAPI void
3559 elm_genlist_item_middle_show(Elm_Genlist_Item *it)
3560 {
3561    Evas_Coord ow, oh;
3562
3563    if (!it) return;
3564    if (it->delete_me) return;
3565    if ((it->queued) || (!it->mincalcd))
3566      {
3567         it->wd->show_item = it;
3568         it->wd->bring_in = 1;
3569         it->showme = EINA_TRUE;
3570         return;
3571      }
3572    if (it->wd->show_item)
3573      {
3574         it->wd->show_item->showme = EINA_FALSE;
3575         it->wd->show_item = NULL;
3576      }
3577    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
3578    elm_smart_scroller_child_region_show(it->wd->scr,
3579                                         it->x + it->block->x,
3580                          it->y + it->block->y - oh/2 + it->h/2,
3581                                         it->block->w, oh);
3582 }
3583
3584
3585 /**
3586  * Bring in the given item at the middle
3587  *
3588  * This causes genlist to jump to the given item @p it and show it (by scrolling),
3589  * if it is not fully visible. This may use animation to do so and take a
3590  * period of time
3591  *
3592  * @param it The item
3593  *
3594  * @ingroup Genlist
3595  */
3596 EAPI void
3597 elm_genlist_item_middle_bring_in(Elm_Genlist_Item *it)
3598 {
3599    Evas_Coord ow, oh;
3600
3601    if (!it) return;
3602    if (it->delete_me) return;
3603    if ((it->queued) || (!it->mincalcd))
3604      {
3605         it->wd->show_item = it;
3606         it->wd->bring_in = 1;
3607         it->showme = EINA_TRUE;
3608         return;
3609      }
3610    if (it->wd->show_item)
3611      {
3612         it->wd->show_item->showme = EINA_FALSE;
3613         it->wd->show_item = NULL;
3614      }
3615    evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &ow, &oh);
3616    elm_smart_scroller_region_bring_in(it->wd->scr,
3617                                       it->x + it->block->x,
3618                                       it->y + it->block->y - oh/2 + it->h/2,
3619                                       it->block->w, oh);
3620 }
3621
3622 /**
3623  * Delete a given item
3624  *
3625  * This deletes the item from genlist and calls the genlist item del class
3626  * callback defined in the item class, if it is set.
3627  *
3628  * @param it The item
3629  *
3630  * @ingroup Genlist
3631  */
3632 EAPI void
3633 elm_genlist_item_del(Elm_Genlist_Item *it)
3634 {
3635    if (!it) return;
3636    if ((it->relcount > 0) || (it->walking > 0))
3637      {
3638         elm_genlist_item_subitems_clear(it);
3639         it->delete_me = EINA_TRUE;
3640         if (it->wd->show_item == it) it->wd->show_item = NULL;
3641         if (it->selected) it->wd->selected = eina_list_remove(it->wd->selected, it);
3642         if (it->block)
3643           {
3644              if (it->realized) _item_unrealize(it);
3645              it->block->changed = EINA_TRUE;
3646              if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
3647              it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
3648           }
3649         if (it->itc->func.del) it->itc->func.del(it->data, it->wd->obj);
3650         return;
3651      }
3652    _item_del(it);
3653 }
3654
3655 /**
3656  * Set the data item from the genlist item
3657  *
3658  * This set the data value passed on the elm_genlist_item_append() and
3659  * related item addition calls. This function will also call
3660  * elm_genlist_item_update() so the item will be updated to reflect the
3661  * new data.
3662  *
3663  * @param it The item
3664  * @param data The new data pointer to set
3665  *
3666  * @ingroup Genlist
3667  */
3668 EAPI void
3669 elm_genlist_item_data_set(Elm_Genlist_Item *it, const void *data)
3670 {
3671    if (!it) return;
3672    it->data = data;
3673    elm_genlist_item_update(it);
3674 }
3675
3676 /**
3677  * Get the data item from the genlist item
3678  *
3679  * This returns the data value passed on the elm_genlist_item_append() and
3680  * related item addition calls.
3681  *
3682  * @param it The item
3683  * @return The data pointer provided when created
3684  *
3685  * @ingroup Genlist
3686  */
3687 EAPI const void *
3688 elm_genlist_item_data_get(const Elm_Genlist_Item *it)
3689 {
3690    if (!it) return NULL;
3691    return it->data;
3692 }
3693
3694 /**
3695  * Get the real evas object of the genlist item
3696  *
3697  * This returns the actual evas object used for the specified genlist item.
3698  * This may be NULL as it may not be created, and ma be deleted at any time
3699  * by genlist. Do not modify this object (move, resize, show, hide etc.) as
3700  * genlist is controlling it. This function is for querying, emitting
3701  * custom signals or hooking lower level callbacks for events. Do not
3702  * delete this object under any circumstances.
3703  *
3704  * @param it The item
3705  * @return The objct pointer
3706  *
3707  * @ingroup Genlist
3708  */
3709 EAPI const Evas_Object *
3710 elm_genlist_item_object_get(const Elm_Genlist_Item *it)
3711 {
3712    if (!it) return NULL;
3713    return it->base;
3714 }
3715
3716 /**
3717  * Update the contents of an item
3718  *
3719  * This updates an item by calling all the item class functions again to get
3720  * the icons, labels and states. Use this when he original item data has
3721  * changed and the changes are desired to be reflected.
3722  *
3723  * @param it The item
3724  *
3725  * @ingroup Genlist
3726  */
3727 EAPI void
3728 elm_genlist_item_update(Elm_Genlist_Item *it)
3729 {
3730    if (!it->block) return;
3731    if (it->delete_me) return;
3732    it->mincalcd = EINA_FALSE;
3733    it->updateme = EINA_TRUE;
3734    it->block->updateme = EINA_TRUE;
3735    if (it->wd->update_job) ecore_job_del(it->wd->update_job);
3736    it->wd->update_job = ecore_job_add(_update_job, it->wd);
3737 }
3738
3739 /**
3740  * This sets the horizontal stretching mode
3741  *
3742  * This sets the mode used for sizing items horizontally. Valid modes are
3743  * ELM_LIST_LIMIT and ELM_LIST_SCROLL. The default is ELM_LIST_SCROLL. This
3744  * mode means that if items are too wide to fit, the scroller will scroll
3745  * horizontally. Otherwise items are expanded to fill the width of the
3746  * viewport of the scroller. If it is ELM_LIST_LIMIT, Items will be expanded
3747  * to the viewport width and limited to that size.
3748  *
3749  * @param obj The genlist object
3750  * @param mode The mode to use
3751  *
3752  * @ingroup Genlist
3753  */
3754 EAPI void
3755 elm_genlist_horizontal_mode_set(Evas_Object *obj, Elm_List_Mode mode)
3756 {
3757    ELM_CHECK_WIDTYPE(obj, widtype);
3758    Widget_Data *wd = elm_widget_data_get(obj);
3759    if (!wd) return;
3760    if (wd->mode == mode) return;
3761    wd->mode = mode;
3762    _sizing_eval(obj);
3763 }
3764
3765 /**
3766  * Gets the horizontal stretching mode
3767  *
3768  * @param obj The genlist object
3769  * @return The mode to use
3770  * (ELM_LIST_LIMIT, ELM_LIST_SCROLL, ELM_LIST_LIMIT)
3771  *
3772  * @ingroup Genlist
3773  */
3774 EAPI Elm_List_Mode
3775 elm_genlist_horizontal_mode_get(const Evas_Object *obj)
3776 {
3777    ELM_CHECK_WIDTYPE(obj, widtype) ELM_LIST_LAST;
3778    Widget_Data *wd = elm_widget_data_get(obj);
3779    if (!wd) return ELM_LIST_LAST;
3780    return wd->mode;
3781 }
3782
3783 /**
3784  * Set the always select mode.
3785  *
3786  * Items will only call their selection func and callback when first becoming
3787  * selected. Any further clicks will do nothing, unless you enable always
3788  * select with elm_genlist_always_select_mode_set(). This means even if
3789  * selected, every click will make the selected callbacks be called.
3790  *
3791  * @param obj The genlist object
3792  * @param always_select The always select mode
3793  * (EINA_TRUE = on, EINA_FALSE = off)
3794  *
3795  * @ingroup Genlist
3796  */
3797 EAPI void
3798 elm_genlist_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
3799 {
3800    ELM_CHECK_WIDTYPE(obj, widtype);
3801    Widget_Data *wd = elm_widget_data_get(obj);
3802    if (!wd) return;
3803    wd->always_select = always_select;
3804 }
3805
3806 /**
3807  * Get the always select mode.
3808  *
3809  * @param obj The genlist object
3810  * @return The always select mode
3811  * (EINA_TRUE = on, EINA_FALSE = off)
3812  *
3813  * @ingroup Genlist
3814  */
3815 EAPI Eina_Bool
3816 elm_genlist_always_select_mode_get(const Evas_Object *obj)
3817 {
3818    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3819    Widget_Data *wd = elm_widget_data_get(obj);
3820    if (!wd) return EINA_FALSE;
3821    return wd->always_select;
3822 }
3823
3824 /**
3825  * Set no select mode
3826  *
3827  * This will turn off the ability to select items entirely and they will
3828  * neither appear selected nor call selected callback functions.
3829  *
3830  * @param obj The genlist object
3831  * @param no_select The no select mode
3832  * (EINA_TRUE = on, EINA_FALSE = off)
3833  *
3834  * @ingroup Genlist
3835  */
3836 EAPI void
3837 elm_genlist_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
3838 {
3839    ELM_CHECK_WIDTYPE(obj, widtype);
3840    Widget_Data *wd = elm_widget_data_get(obj);
3841    if (!wd) return;
3842    wd->no_select = no_select;
3843 }
3844
3845 /**
3846  * Gets no select mode
3847  *
3848  * @param obj The genlist object
3849  * @return The no select mode
3850  * (EINA_TRUE = on, EINA_FALSE = off)
3851  *
3852  * @ingroup Genlist
3853  */
3854 EAPI Eina_Bool
3855 elm_genlist_no_select_mode_get(const Evas_Object *obj)
3856 {
3857    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3858    Widget_Data *wd = elm_widget_data_get(obj);
3859    if (!wd) return EINA_FALSE;
3860    return wd->no_select;
3861 }
3862
3863 /**
3864  * Set compress mode
3865  *
3866  * This will enable the compress mode where items are "compressed" horizontally
3867  * to fit the genlist scrollable viewport width.
3868  *
3869  * @param obj The genlist object
3870  * @param no_select The compress mode
3871  * (EINA_TRUE = on, EINA_FALSE = off)
3872  *
3873  * @ingroup Genlist
3874  */
3875 EAPI void
3876 elm_genlist_compress_mode_set(Evas_Object *obj, Eina_Bool compress)
3877 {
3878    ELM_CHECK_WIDTYPE(obj, widtype);
3879    Widget_Data *wd = elm_widget_data_get(obj);
3880    if (!wd) return;
3881    wd->compress = compress;
3882 }
3883
3884 /**
3885  * Get the compress mode
3886  *
3887  * @param obj The genlist object
3888  * @return The compress mode
3889  * (EINA_TRUE = on, EINA_FALSE = off)
3890  *
3891  * @ingroup Genlist
3892  */
3893 EAPI Eina_Bool
3894 elm_genlist_compress_mode_get(const Evas_Object *obj)
3895 {
3896    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3897    Widget_Data *wd = elm_widget_data_get(obj);
3898    if (!wd) return EINA_FALSE;
3899    return wd->compress;
3900 }
3901
3902 /**
3903  * Set bounce mode
3904  *
3905  * This will enable or disable the scroller bounce mode for the genlist. See 
3906  * elm_scroller_bounce_set() for details
3907  *
3908  * @param obj The genlist object
3909  * @param h_bounce Allow bounce horizontally
3910  * @param v_bounce Allow bounce vertically
3911  *
3912  * @ingroup Genlist
3913  */
3914 EAPI void
3915 elm_genlist_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
3916 {
3917    ELM_CHECK_WIDTYPE(obj, widtype);
3918    Widget_Data *wd = elm_widget_data_get(obj);
3919    if (!wd) return;
3920    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
3921 }
3922
3923 /**
3924  * Get the bounce mode
3925  *
3926  * @param obj The genlist object
3927  * @param h_bounce Allow bounce horizontally
3928  * @param v_bounce Allow bounce vertically
3929  *
3930  * @ingroup Genlist
3931  */
3932 EAPI void
3933 elm_genlist_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
3934 {
3935    ELM_CHECK_WIDTYPE(obj, widtype);
3936    Widget_Data *wd = elm_widget_data_get(obj);
3937    if (!wd) return;
3938    elm_smart_scroller_bounce_allow_get(obj, h_bounce, v_bounce);
3939 }
3940
3941 /**
3942  * Set homogenous mode
3943  *
3944  * This will enable the homogeneous mode where items are of the same height and width
3945  * so that genlist may do the lazy-loading at its maximum.  This implies 'compressed' mode
3946  *
3947  * @param obj The genlist object
3948  * @param homogeneous Assume the items within the genlist are of the same height and width
3949  * (EINA_TRUE = on, EINA_FALSE = off)
3950  *
3951  * @ingroup Genlist
3952  */
3953 EAPI void
3954 elm_genlist_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
3955 {
3956    ELM_CHECK_WIDTYPE(obj, widtype);
3957    Widget_Data *wd = elm_widget_data_get(obj);
3958    if (!wd) return;
3959    if (homogeneous) elm_genlist_compress_mode_set(obj, EINA_TRUE);
3960    wd->homogeneous = homogeneous;
3961 }
3962
3963 /**
3964  * Get the homogenous mode
3965  *
3966  * @param obj The genlist object
3967  * @return Assume the items within the genlist are of the same height and width
3968  * (EINA_TRUE = on, EINA_FALSE = off)
3969  *
3970  * @ingroup Genlist
3971  */
3972 EAPI Eina_Bool
3973 elm_genlist_homogeneous_get(const Evas_Object *obj)
3974 {
3975    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3976    Widget_Data *wd = elm_widget_data_get(obj);
3977    if (!wd) return EINA_FALSE;
3978    return wd->homogeneous;
3979 }
3980
3981 /**
3982  * Set the maximum number of items within an item block
3983  *
3984  * This will configure the block count to tune to the target with particular performance matrix.
3985  *
3986  * @param obj The genlist object
3987  * @param n   Maximum number of items within an item block
3988  *
3989  * @ingroup Genlist
3990  */
3991 EAPI void
3992 elm_genlist_block_count_set(Evas_Object *obj, int n)
3993 {
3994    ELM_CHECK_WIDTYPE(obj, widtype);
3995    Widget_Data *wd = elm_widget_data_get(obj);
3996    if (!wd) return;
3997    wd->max_items_per_block = n;
3998 }
3999
4000 /**
4001  * Get the maximum number of items within an item block
4002  *
4003  * @param obj The genlist object
4004  * @return Maximum number of items within an item block
4005  *
4006  * @ingroup Genlist
4007  */
4008 EAPI int
4009 elm_genlist_block_count_get(const Evas_Object *obj)
4010 {
4011    ELM_CHECK_WIDTYPE(obj, widtype) 0;
4012    Widget_Data *wd = elm_widget_data_get(obj);
4013    if (!wd) return 0;
4014    return wd->max_items_per_block;
4015 }
4016
4017 /**
4018  * Set the Genlist Internal scroller scrollbar policy
4019  *
4020  * This sets the Genlist Internal scrollbar visibility policy.
4021  * ELM_SMART_SCROLLER_POLICY_AUTO means the scrollbar is made visible if it
4022  * is needed, and otherwise kept hidden. ELM_SMART_SCROLLER_POLICY_ON turns
4023  * it on all the time, and ELM_SMART_SCROLLER_POLICY_OFF always keeps it off.
4024  * This applies respectively for the horizontal and vertical scrollbars.
4025  *
4026  * @param obj The Genlist object
4027  * @param policy_h Horizontal scrollbar policy
4028  * @param policy_v Vertical scrollbar policy
4029  *
4030  * @ingroup Genlist
4031  */
4032 EAPI void
4033 elm_genlist_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
4034 {
4035    ELM_CHECK_WIDTYPE(obj, widtype);
4036    Widget_Data *wd = elm_widget_data_get(obj);
4037    if (!wd)  return;
4038
4039    const Elm_Scroller_Policy map[3] =
4040        {
4041            ELM_SMART_SCROLLER_POLICY_AUTO,
4042             ELM_SMART_SCROLLER_POLICY_ON,
4043             ELM_SMART_SCROLLER_POLICY_OFF
4044        };
4045    if ((policy_h < 0) || (policy_h >= 3) || (policy_v < 0) || (policy_v >= 3))
4046      return;
4047
4048    elm_smart_scroller_policy_set(wd->scr, map[policy_h], map[policy_v]);
4049 }
4050
4051
4052 EAPI void
4053 elm_genlist_set_edit_mode(Evas_Object *obj, int emode, Elm_Genlist_Edit_Class *edit_class )
4054 {
4055     Eina_List * realized_list;
4056     Elm_Genlist_Item *it;
4057     Eina_List *l;
4058
4059     ELM_CHECK_WIDTYPE(obj, widtype);
4060     Widget_Data *wd = elm_widget_data_get(obj);
4061     if (!wd) return;
4062     if( wd->edit_mode == emode ) return;
4063
4064     wd->edit_mode = emode;
4065
4066     wd->animate_edit_controls = 1;
4067     if( wd->edit_mode == ELM_GENLIST_EDIT_MODE_NONE)
4068     {
4069       if( wd->ed ) free (wd->ed);
4070       wd->ed = NULL;
4071     }
4072     else
4073     {
4074       if( !wd->ed )
4075         wd->ed = calloc(1, sizeof(Edit_Data));
4076
4077       wd->ed->ec = edit_class;
4078
4079       if( (wd->edit_mode & ELM_GENLIST_EDIT_MODE_DELETE) && !wd->ed->del_confirm)
4080       {
4081           wd->ed->del_confirm = elm_button_add(wd->obj);
4082           elm_button_label_set(wd->ed->del_confirm, "Delete");
4083           evas_object_smart_member_add(wd->ed->del_confirm, wd->pan_smart);
4084           edje_object_scale_set( wd->ed->del_confirm, elm_widget_scale_get(wd->ed->del_confirm) *
4085                                                         _elm_config->scale);
4086           evas_object_smart_callback_add(wd->ed->del_confirm, "clicked", _delete_confirm_cb, wd );
4087       }
4088     }
4089
4090     realized_list = elm_genlist_realized_items_get(obj);
4091
4092     EINA_LIST_FOREACH(realized_list, l, it)
4093     {
4094      _edit_controls_eval(it);
4095     }
4096
4097     if (wd->calc_job) ecore_job_del(wd->calc_job);
4098     wd->calc_job = ecore_job_add(_calc_job, wd);
4099 }