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