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