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