elementary/gengrid - fixed a bug by jh0506.yun@samsung.com
[framework/uifw/elementary.git] / src / lib / elm_gengrid.c
1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
3 #include "elm_priv.h"
4
5 /**
6  * @defgroup Gengrid Gengrid
7  *
8  * This widget aims to position objects in a grid layout while
9  * actually building only the visible ones, using the same idea as
10  * genlist: the user define a class for each item, specifying
11  * functions that will be called at object creation and deletion.
12  *
13  * Signals that you can add callbacks for are:
14  *
15  * clicked - The user has double-clicked or pressed enter on 
16  * a item. The event_infoparameter is the Gengrid item 
17  * that was double-clicked.
18  *
19  * selected - The user has made an item selected. The event_info
20  * parameter is the Gengrid item that was selected.
21  *
22  * unselected - The user has made an item unselected. The event_info
23  * parameter is the Gengrid item that was unselected.
24  *
25  * realized - This is called when the item in the Gengrid is created
26  * as a real evas object. event_info is the Gengrid item that was
27  * created. The object may be deleted at any time, so it is up to the
28  * caller to not use the object pointer from
29  * elm_gengrid_item_object_get() in a way where it may point to freed
30  * objects.
31  *
32  * unrealized - This is called when the real evas object for this item
33  * is deleted. event_info is the Gengrid item that was created.
34  *
35  * changed - Called when an item is added, removed, resized or moved
36  * and when gengrid is resized or horizontal property changes.
37  *
38  * drag,start,up - Called when the item in the Gengrid has been
39  * dragged (not scrolled) up.
40  *
41  * drag,start,down - Called when the item in the Gengrid has been
42  * dragged (not scrolled) down.
43  *
44  * drag,start,left - Called when the item in the Gengrid has been
45  * dragged (not scrolled) left.
46  *
47  * drag,start,right - Called when the item in the Gengrid has been
48  * dragged (not scrolled) right.
49  *
50  * drag,stop - Called when the item in the Gengrid has stopped being
51  * dragged.
52  *
53  * drag - Called when the item in the Gengrid is being dragged.
54  *
55  * scroll - called when the content has been scrolled (moved).
56  *
57  * scroll,drag,start - called when dragging the content has started.
58  *
59  * scroll,drag,stop - called when dragging the content has stopped.
60  *
61  *
62  * A item in the Gengrid can have 0 or more text labels (they can be
63  * regular text or textblock - that's up to the style to determine), 0
64  * or more icons (which are simply objects swallowed into the Gengrid
65  * item) and 0 or more boolean states that can be used for check,
66  * radio or other indicators by the edje theme style.  A item may be
67  * one of several styles (Elementary provides 1 by default -
68  * "default", but this can be extended by system or application custom
69  * themes/overlays/extensions).
70  *
71  * In order to implement the ability to add and delete items on the
72  * fly, Gengrid implements a class/callback system where the
73  * application provides a structure with information about that type
74  * of item (Gengrid may contain multiple different items with
75  * different classes, states and styles). Gengrid will call the
76  * functions in this struct (methods) when a item is "realized" (that
77  * is created dynamically while scrolling). All objects will simply be
78  * deleted when no longer needed with evas_object_del(). The
79  * Elm_GenGrid_Item_Class structure contains the following members:
80  *
81  * item_style - This is a constant string and simply defines the name
82  * of the item style. It must be specified and the default should be
83  * "default".
84  *
85  * func.label_get - This function is called when an actual item object
86  * is created. The data parameter is the one passed to
87  * elm_gengrid_item_append() and related item creation functions. The
88  * obj parameter is the Gengrid object and the part parameter is the
89  * string name of the text part in the edje design that is listed as
90  * one of the possible labels that can be set. This function must
91  * return a strdup'()ed string as the caller will free() it when done.
92  *
93  * func.icon_get - This function is called when an actual item object
94  * is created. The data parameter is the one passed to
95  * elm_gengrid_item_append() and related item creation functions. The
96  * obj parameter is the Gengrid object and the part parameter is the
97  * string name of the icon part in the edje design that is listed as
98  * one of the possible icons that can be set. This must return NULL
99  * for no object or a valid object. The object will be deleted by
100  * Gengrid on shutdown or when the item is unrealized.
101  *
102  * func.state_get - This function is called when an actual item object
103  * is created. The data parameter is the one passed to
104  * elm_gengrid_item_append() and related item creation functions. The
105  * obj parameter is the Gengrid object and the part parameter is the
106  * string name of th state part in the edje design that is listed as
107  * one of the possible states that can be set. Return 0 for false and
108  * 1 for true. Gengrid will emit a signal to the edje object with
109  * "elm,state,XXX,active" "elm" when true (the default is false),
110  * where XXX is the name of the part.
111  *
112  * func.del - This is called when elm_gengrid_item_del() is called on
113  * a item or elm_gengrid_clear() is called on the Gengrid. This is
114  * intended for use when actual Gengrid items are deleted, so any
115  * backing data attached to the item (e.g. its data parameter on
116  * creation) can be deleted.
117  *
118  * If the application wants multiple items to be able to be selected,
119  * elm_gengrid_multi_select_set() can enable this. If the Gengrid is
120  * single-selection only (the default), then
121  * elm_gengrid_select_item_get() will return the selected item, if
122  * any, or NULL if none is selected. If the Gengrid is multi-select
123  * then elm_gengrid_selected_items_get() will return a list (that is
124  * only valid as long as no items are modified (added, deleted,
125  * selected or unselected).
126  *
127  * If a item changes (state of boolean changes, label or icons
128  * change), then use elm_gengrid_item_update() to have Gengrid update
129  * the item with the new state. Gengrid will re-realize the item thus
130  * call the functions in the _Elm_Gengrid_Item_Class for that item.
131  *
132  * To programmatically (un)select a item use
133  * elm_gengrid_item_selected_set().  To get its selected state use
134  * elm_gengrid_item_selected_get(). To make a item disabled (unable to
135  * be selected and appear differently) use
136  * elm_gengrid_item_disabled_set() to set this and
137  * elm_gengrid_item_disabled_get() to get the disabled state.
138  *
139  * Cells will only call their selection func and callback when first
140  * becoming selected. Any further clicks will do nothing, unless you
141  * enable always select with
142  * elm_gengrid_always_select_mode_set(). This means event if selected,
143  * every click will make the selected callbacks be called.
144  * elm_gengrid_no_select_mode_set() will turn off the ability to
145  * select items entirely and they will neither appear selected nor
146  * call selected callback function.
147  *
148  * Remember that you can create new styles and add your own theme
149  * augmentation per application with elm_theme_extension_add(). If you
150  * absolutely must have a specific style that overrides any theme the
151  * user or system sets up you can use elm_theme_overlay_add() to add
152  * such a file.
153  *
154  * --
155  * TODO:
156  *  * Handle non-homogeneous objects too.
157  */
158
159 typedef struct _Widget_Data Widget_Data;
160 typedef struct _Pan         Pan;
161
162 #define PRELOAD 1
163
164 struct _Elm_Gengrid_Item
165 {
166    Elm_Widget_Item               base;
167    EINA_INLIST;
168    Evas_Object                  *spacer;
169    const Elm_Gengrid_Item_Class *gic;
170    Ecore_Timer                  *long_timer;
171    Widget_Data                  *wd;
172    Eina_List                    *labels, *icons, *states, *icon_objs;
173    struct
174    {
175       Evas_Smart_Cb func;
176       const void   *data;
177    } func;
178
179    Evas_Coord x, y, dx, dy;
180    int        relcount;
181    int        walking;
182
183    struct
184    {
185       const void                 *data;
186       Elm_Tooltip_Item_Content_Cb content_cb;
187       Evas_Smart_Cb               del_cb;
188       const char                 *style;
189    } tooltip;
190
191    const char *mouse_cursor;
192
193    Eina_Bool   want_unrealize : 1;
194    Eina_Bool   realized : 1;
195    Eina_Bool   dragging : 1;
196    Eina_Bool   down : 1;
197    Eina_Bool   delete_me : 1;
198    Eina_Bool   display_only : 1;
199    Eina_Bool   disabled : 1;
200    Eina_Bool   selected : 1;
201    Eina_Bool   hilighted : 1;
202 };
203
204 struct _Widget_Data
205 {
206    Evas_Object      *self, *scr;
207    Evas_Object      *pan_smart;
208    Pan              *pan;
209    Eina_Inlist      *items;
210    Ecore_Job        *calc_job;
211    Eina_List        *selected;
212    Elm_Gengrid_Item *last_selected_item;
213    double            align_x, align_y;
214
215    Evas_Coord        pan_x, pan_y;
216    Evas_Coord        item_width, item_height; /* Each item size */
217    Evas_Coord        minw, minh; /* Total obj size */
218    unsigned int      nmax;
219    long              count;
220    int               walking;
221
222    Eina_Bool         horizontal : 1;
223    Eina_Bool         on_hold : 1;
224    Eina_Bool         longpressed : 1;
225    Eina_Bool         multi : 1;
226    Eina_Bool         no_select : 1;
227    Eina_Bool         wasselected : 1;
228    Eina_Bool         always_select : 1;
229    Eina_Bool         clear_me : 1;
230 };
231
232 #define ELM_GENGRID_ITEM_FROM_INLIST(item) \
233   ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Gengrid_Item) : NULL)
234
235 struct _Pan
236 {
237    Evas_Object_Smart_Clipped_Data __clipped_data;
238    Widget_Data                   *wd;
239 };
240
241 static const char *widtype = NULL;
242 static void      _item_hilight(Elm_Gengrid_Item *item);
243 static void      _item_unrealize(Elm_Gengrid_Item *item);
244 static void      _item_select(Elm_Gengrid_Item *item);
245 static void      _item_unselect(Elm_Gengrid_Item *item);
246 static void      _calc_job(void *data);
247 static void      _on_focus_hook(void        *data,
248                                 Evas_Object *obj);
249 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
250 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
251 static Eina_Bool _item_multi_select_left(Widget_Data *wd);
252 static Eina_Bool _item_multi_select_right(Widget_Data *wd);
253 static Eina_Bool _item_single_select_up(Widget_Data *wd);
254 static Eina_Bool _item_single_select_down(Widget_Data *wd);
255 static Eina_Bool _item_single_select_left(Widget_Data *wd);
256 static Eina_Bool _item_single_select_right(Widget_Data *wd);
257 static Eina_Bool _event_hook(Evas_Object       *obj,
258                              Evas_Object       *src,
259                              Evas_Callback_Type type,
260                              void              *event_info);
261 static Eina_Bool _deselect_all_items(Widget_Data *wd);
262
263 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
264 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
265
266 static Eina_Bool
267 _event_hook(Evas_Object       *obj,
268             Evas_Object *src   __UNUSED__,
269             Evas_Callback_Type type,
270             void              *event_info)
271 {
272    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
273    Evas_Event_Key_Down *ev = event_info;
274    Widget_Data *wd = elm_widget_data_get(obj);
275    if (!wd) return EINA_FALSE;
276    if (!wd->items) return EINA_FALSE;
277    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
278    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
279
280    Elm_Gengrid_Item *item = NULL;
281    Evas_Coord x = 0;
282    Evas_Coord y = 0;
283    Evas_Coord step_x = 0;
284    Evas_Coord step_y = 0;
285    Evas_Coord v_w = 0;
286    Evas_Coord v_h = 0;
287    Evas_Coord page_x = 0;
288    Evas_Coord page_y = 0;
289
290    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
291    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
292    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
293    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
294
295    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
296      {
297         if ((wd->horizontal) &&
298             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
299               (_item_multi_select_up(wd)))
300              || (_item_single_select_up(wd))))
301           {
302              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
303              return EINA_TRUE;
304           }
305         else if ((!wd->horizontal) &&
306                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
307                    (_item_multi_select_left(wd)))
308                   || (_item_single_select_left(wd))))
309           {
310              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
311              return EINA_TRUE;
312           }
313         else
314           x -= step_x;
315      }
316    else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
317      {
318         if ((wd->horizontal) &&
319             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
320               (_item_multi_select_down(wd)))
321              || (_item_single_select_down(wd))))
322           {
323              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
324              return EINA_TRUE;
325           }
326         else if ((!wd->horizontal) &&
327                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
328                    (_item_multi_select_right(wd)))
329                   || (_item_single_select_right(wd))))
330           {
331              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
332              return EINA_TRUE;
333           }
334         else
335           x += step_x;
336      }
337    else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
338      {
339         if ((wd->horizontal) &&
340             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
341               (_item_multi_select_left(wd)))
342              || (_item_single_select_left(wd))))
343           {
344              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
345              return EINA_TRUE;
346           }
347         else if ((!wd->horizontal) &&
348                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
349                    (_item_multi_select_up(wd)))
350                   || (_item_single_select_up(wd))))
351           {
352              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
353              return EINA_TRUE;
354           }
355         else
356           y -= step_y;
357      }
358    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
359      {
360         if ((wd->horizontal) &&
361             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
362               (_item_multi_select_right(wd)))
363              || (_item_single_select_right(wd))))
364           {
365              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
366              return EINA_TRUE;
367           }
368         else if ((!wd->horizontal) &&
369                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
370                    (_item_multi_select_down(wd)))
371                   || (_item_single_select_down(wd))))
372           {
373              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
374              return EINA_TRUE;
375           }
376         else
377           y += step_y;
378      }
379    else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
380      {
381         item = elm_gengrid_first_item_get(obj);
382         elm_gengrid_item_bring_in(item);
383         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
384         return EINA_TRUE;
385      }
386    else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
387      {
388         item = elm_gengrid_last_item_get(obj);
389         elm_gengrid_item_bring_in(item);
390         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
391         return EINA_TRUE;
392      }
393    else if ((!strcmp(ev->keyname, "Prior")) ||
394             (!strcmp(ev->keyname, "KP_Prior")))
395      {
396         if (wd->horizontal)
397           {
398              if (page_x < 0)
399                x -= -(page_x * v_w) / 100;
400              else
401                x -= page_x;
402           }
403         else
404           {
405              if (page_y < 0)
406                y -= -(page_y * v_h) / 100;
407              else
408                y -= page_y;
409           }
410      }
411    else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
412      {
413         if (wd->horizontal)
414           {
415              if (page_x < 0)
416                x += -(page_x * v_w) / 100;
417              else
418                x += page_x;
419           }
420         else
421           {
422              if (page_y < 0)
423                y += -(page_y * v_h) / 100;
424              else
425                y += page_y;
426           }
427      }
428    else if (!strcmp(ev->keyname, "Escape"))
429      {
430         if (!_deselect_all_items(wd)) return EINA_FALSE;
431         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
432         return EINA_TRUE;
433      }
434    else if (!strcmp(ev->keyname, "Return"))
435      {
436         item = elm_gengrid_selected_item_get(obj);
437         evas_object_smart_callback_call(item->wd->self, "clicked", item);
438      }
439    else return EINA_FALSE;
440
441    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
442    elm_smart_scroller_child_pos_set(wd->scr, x, y);
443    return EINA_TRUE;
444 }
445
446 static Eina_Bool
447 _deselect_all_items(Widget_Data *wd)
448 {
449    if (!wd->selected) return EINA_FALSE;
450    while(wd->selected)
451      elm_gengrid_item_selected_set(wd->selected->data, EINA_FALSE);
452
453    return EINA_TRUE;
454 }
455
456 static Eina_Bool
457 _item_multi_select_left(Widget_Data *wd)
458 {
459    if (!wd->selected) return EINA_FALSE;
460
461    Elm_Gengrid_Item *prev = elm_gengrid_item_prev_get(wd->last_selected_item);
462    if (!prev) return EINA_TRUE;
463    if (elm_gengrid_item_selected_get(prev))
464      {
465         elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
466         wd->last_selected_item = prev;
467         elm_gengrid_item_show(wd->last_selected_item);
468      }
469    else
470      {
471         elm_gengrid_item_selected_set(prev, EINA_TRUE);
472         elm_gengrid_item_show(prev);
473      }
474
475    return EINA_TRUE;
476 }
477
478 static Eina_Bool
479 _item_multi_select_right(Widget_Data *wd)
480 {
481    if (!wd->selected) return EINA_FALSE;
482
483    Elm_Gengrid_Item *next = elm_gengrid_item_next_get(wd->last_selected_item);
484    if (!next) return EINA_TRUE;
485    if (elm_gengrid_item_selected_get(next))
486      {
487         elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
488         wd->last_selected_item = next;
489         elm_gengrid_item_show(wd->last_selected_item);
490      }
491    else
492      {
493         elm_gengrid_item_selected_set(next, EINA_TRUE);
494         elm_gengrid_item_show(next);
495      }
496
497    return EINA_TRUE;
498 }
499
500 static Eina_Bool
501 _item_multi_select_up(Widget_Data *wd)
502 {
503    unsigned int i;
504    Eina_Bool r = EINA_TRUE;
505
506    if (!wd->selected) return EINA_FALSE;
507
508    for (i = 0; (r) && (i < wd->nmax); i++)
509      r &= _item_multi_select_left(wd);
510
511    return r;
512 }
513
514 static Eina_Bool
515 _item_multi_select_down(Widget_Data *wd)
516 {
517    unsigned int i;
518    Eina_Bool r = EINA_TRUE;
519
520    if (!wd->selected) return EINA_FALSE;
521
522    for (i = 0; (r) && (i < wd->nmax); i++)
523      r &= _item_multi_select_right(wd);
524
525    return r;
526 }
527
528 static Eina_Bool
529 _item_single_select_up(Widget_Data *wd)
530 {
531    unsigned int i;
532
533    Elm_Gengrid_Item *prev;
534
535    if (!wd->selected)
536      {
537         prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
538         while ((prev) && (prev->delete_me))
539           prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
540         elm_gengrid_item_selected_set(prev, EINA_TRUE);
541         elm_gengrid_item_show(prev);
542         return EINA_TRUE;
543      }
544    else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
545
546    if (!prev) return EINA_FALSE;
547
548    for (i = 1; i < wd->nmax; i++)
549      {
550         Elm_Gengrid_Item *tmp = elm_gengrid_item_prev_get(prev);
551         if (!tmp) return EINA_FALSE;
552         prev = tmp;
553      }
554
555    _deselect_all_items(wd);
556
557    elm_gengrid_item_selected_set(prev, EINA_TRUE);
558    elm_gengrid_item_show(prev);
559    return EINA_TRUE;
560 }
561
562 static Eina_Bool
563 _item_single_select_down(Widget_Data *wd)
564 {
565    unsigned int i;
566
567    Elm_Gengrid_Item *next;
568
569    if (!wd->selected)
570      {
571         next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
572         while ((next) && (next->delete_me))
573           next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
574         elm_gengrid_item_selected_set(next, EINA_TRUE);
575         elm_gengrid_item_show(next);
576         return EINA_TRUE;
577      }
578    else next = elm_gengrid_item_next_get(wd->last_selected_item);
579
580    if (!next) return EINA_FALSE;
581
582    for (i = 1; i < wd->nmax; i++)
583      {
584         Elm_Gengrid_Item *tmp = elm_gengrid_item_next_get(next);
585         if (!tmp) return EINA_FALSE;
586         next = tmp;
587      }
588
589    _deselect_all_items(wd);
590
591    elm_gengrid_item_selected_set(next, EINA_TRUE);
592    elm_gengrid_item_show(next);
593    return EINA_TRUE;
594 }
595
596 static Eina_Bool
597 _item_single_select_left(Widget_Data *wd)
598 {
599    Elm_Gengrid_Item *prev;
600    if (!wd->selected)
601      {
602         prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
603         while ((prev) && (prev->delete_me))
604           prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
605      }
606    else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
607
608    if (!prev) return EINA_FALSE;
609
610    _deselect_all_items(wd);
611
612    elm_gengrid_item_selected_set(prev, EINA_TRUE);
613    elm_gengrid_item_show(prev);
614    return EINA_TRUE;
615 }
616
617 static Eina_Bool
618 _item_single_select_right(Widget_Data *wd)
619 {
620    Elm_Gengrid_Item *next;
621    if (!wd->selected)
622      {
623         next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
624         while ((next) && (next->delete_me))
625           next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
626      }
627    else next = elm_gengrid_item_next_get(wd->last_selected_item);
628
629    if (!next) return EINA_FALSE;
630
631    _deselect_all_items(wd);
632
633    elm_gengrid_item_selected_set(next, EINA_TRUE);
634    elm_gengrid_item_show(next);
635    return EINA_TRUE;
636 }
637
638 static void
639 _on_focus_hook(void *data   __UNUSED__,
640                Evas_Object *obj)
641 {
642    Widget_Data *wd = elm_widget_data_get(obj);
643    if (!wd) return;
644    if (elm_widget_focus_get(obj))
645      {
646         edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
647         evas_object_focus_set(wd->self, EINA_TRUE);
648         if ((wd->selected) && (!wd->last_selected_item))
649           wd->last_selected_item = eina_list_data_get(wd->selected);
650      }
651    else
652      {
653         edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
654         evas_object_focus_set(wd->self, EINA_FALSE);
655      }
656 }
657
658 static void
659 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
660 {
661    Widget_Data *wd = elm_widget_data_get(obj);
662    Elm_Gengrid_Item *item;
663    if (!wd) return;
664    elm_smart_scroller_mirrored_set(wd->scr, rtl);
665    if (!wd->items) return;
666    item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
667
668    while (item)
669      {
670         edje_object_mirrored_set(item->base.view, rtl);
671         elm_gengrid_item_update(item);
672         item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
673      }
674 }
675
676 static void
677 _theme_hook(Evas_Object *obj)
678 {
679    Widget_Data *wd = elm_widget_data_get(obj);
680    if (!wd) return;
681    _elm_widget_mirrored_reload(obj);
682    _mirrored_set(obj, elm_widget_mirrored_get(obj));
683    elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
684                                        elm_widget_style_get(obj));
685 }
686
687 static void
688 _del_pre_hook(Evas_Object *obj)
689 {
690    Widget_Data *wd = elm_widget_data_get(obj);
691    if (!wd) return;
692    elm_gengrid_clear(obj);
693    evas_object_del(wd->pan_smart);
694    wd->pan_smart = NULL;
695 }
696
697 static void
698 _del_hook(Evas_Object *obj)
699 {
700    Widget_Data *wd = elm_widget_data_get(obj);
701    free(wd);
702 }
703
704 static void
705 _signal_emit_hook(Evas_Object *obj,
706                   const char  *emission,
707                   const char  *source)
708 {
709    Widget_Data *wd = elm_widget_data_get(obj);
710    if (!wd) return;
711    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
712                            emission, source);
713 }
714
715 static void
716 _mouse_move(void        *data,
717             Evas *evas   __UNUSED__,
718             Evas_Object *obj,
719             void        *event_info)
720 {
721    Elm_Gengrid_Item *item = data;
722    Evas_Event_Mouse_Move *ev = event_info;
723    Evas_Coord minw = 0, minh = 0, x, y, dx, dy, adx, ady;
724
725    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
726      {
727         if (!item->wd->on_hold)
728           {
729              item->wd->on_hold = EINA_TRUE;
730              if (!item->wd->wasselected)
731                _item_unselect(item);
732           }
733      }
734    if ((item->dragging) && (item->down))
735      {
736         if (item->long_timer)
737           {
738              ecore_timer_del(item->long_timer);
739              item->long_timer = NULL;
740           }
741         evas_object_smart_callback_call(item->wd->self, "drag", item);
742         return;
743      }
744    if ((!item->down) || (item->wd->longpressed))
745      {
746         if (item->long_timer)
747           {
748              ecore_timer_del(item->long_timer);
749              item->long_timer = NULL;
750           }
751         return;
752      }
753    if (!item->display_only)
754      elm_coords_finger_size_adjust(1, &minw, 1, &minh);
755    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
756    x = ev->cur.canvas.x - x;
757    y = ev->cur.canvas.y - y;
758    dx = x - item->dx;
759    adx = dx;
760    if (adx < 0) adx = -dx;
761    dy = y - item->dy;
762    ady = dy;
763    if (ady < 0) ady = -dy;
764    minw /= 2;
765    minh /= 2;
766    if ((adx > minw) || (ady > minh))
767      {
768         const char *left_drag, *right_drag;
769         if (!elm_widget_mirrored_get(item->wd->self))
770           {
771              left_drag = "drag,start,left";
772              right_drag = "drag,start,right";
773           }
774         else
775           {
776              left_drag = "drag,start,right";
777              right_drag = "drag,start,left";
778           }
779
780         item->dragging = 1;
781         if (item->long_timer)
782           {
783              ecore_timer_del(item->long_timer);
784              item->long_timer = NULL;
785           }
786         if (!item->wd->wasselected)
787           _item_unselect(item);
788         if (dy < 0)
789           {
790              if (ady > adx)
791                evas_object_smart_callback_call(item->wd->self, "drag,start,up",
792                                                item);
793              else
794                {
795                   if (dx < 0)
796                     evas_object_smart_callback_call(item->wd->self,
797                           left_drag, item);
798                }
799           }
800         else
801           {
802              if (ady > adx)
803                evas_object_smart_callback_call(item->wd->self,
804                                                "drag,start,down", item);
805              else
806                {
807                   if (dx < 0)
808                     evas_object_smart_callback_call(item->wd->self,
809                                                     left_drag, item);
810                   else
811                     evas_object_smart_callback_call(item->wd->self,
812                           right_drag, item);
813                }
814           }
815      }
816 }
817
818 static Eina_Bool
819 _long_press(void *data)
820 {
821    Elm_Gengrid_Item *item = data;
822
823    item->long_timer = NULL;
824    if ((item->disabled) || (item->dragging)) return ECORE_CALLBACK_CANCEL;
825    item->wd->longpressed = EINA_TRUE;
826    evas_object_smart_callback_call(item->wd->self, "longpressed", item);
827    return ECORE_CALLBACK_CANCEL;
828 }
829
830 static void
831 _mouse_down(void        *data,
832             Evas *evas   __UNUSED__,
833             Evas_Object *obj,
834             void        *event_info)
835 {
836    Elm_Gengrid_Item *item = data;
837    Evas_Event_Mouse_Down *ev = event_info;
838    Evas_Coord x, y;
839
840    if (ev->button != 1) return;
841    item->down = 1;
842    item->dragging = 0;
843    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
844    item->dx = ev->canvas.x - x;
845    item->dy = ev->canvas.y - y;
846    item->wd->longpressed = EINA_FALSE;
847    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
848    else item->wd->on_hold = EINA_FALSE;
849    item->wd->wasselected = item->selected;
850    _item_hilight(item);
851    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
852      evas_object_smart_callback_call(item->wd->self, "clicked", item);
853    if (item->long_timer) ecore_timer_del(item->long_timer);
854    if (item->realized)
855      item->long_timer = ecore_timer_add(_elm_config->longpress_timeout,
856                                         _long_press, item);
857    else
858      item->long_timer = NULL;
859 }
860
861 static void
862 _mouse_up(void            *data,
863           Evas *evas       __UNUSED__,
864           Evas_Object *obj __UNUSED__,
865           void            *event_info)
866 {
867    Elm_Gengrid_Item *item = data;
868    Evas_Event_Mouse_Up *ev = event_info;
869    Eina_Bool dragged = EINA_FALSE;
870
871    if (ev->button != 1) return;
872    item->down = EINA_FALSE;
873    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
874    else item->wd->on_hold = EINA_FALSE;
875    if (item->long_timer)
876      {
877         ecore_timer_del(item->long_timer);
878         item->long_timer = NULL;
879      }
880    if (item->dragging)
881      {
882         item->dragging = EINA_FALSE;
883         evas_object_smart_callback_call(item->wd->self, "drag,stop", item);
884         dragged = EINA_TRUE;
885      }
886    if (item->wd->on_hold)
887      {
888         item->wd->longpressed = EINA_FALSE;
889         item->wd->on_hold = EINA_FALSE;
890         return;
891      }
892    if (item->wd->longpressed)
893      {
894         item->wd->longpressed = EINA_FALSE;
895         if (!item->wd->wasselected) _item_unselect(item);
896         item->wd->wasselected = EINA_FALSE;
897         return;
898      }
899    if (dragged)
900      {
901         if (item->want_unrealize) _item_unrealize(item);
902      }
903    if ((item->disabled) || (dragged)) return;
904    if (item->wd->multi)
905      {
906         if (!item->selected)
907           {
908              _item_hilight(item);
909              _item_select(item);
910           }
911         else _item_unselect(item);
912      }
913    else
914      {
915         if (!item->selected)
916           {
917              while (item->wd->selected)
918                _item_unselect(item->wd->selected->data);
919           }
920         else
921           {
922              const Eina_List *l, *l_next;
923              Elm_Gengrid_Item *item2;
924
925              EINA_LIST_FOREACH_SAFE(item->wd->selected, l, l_next, item2)
926                if (item2 != item) _item_unselect(item2);
927           }
928         _item_hilight(item);
929         _item_select(item);
930      }
931 }
932
933 static void
934 _item_hilight(Elm_Gengrid_Item *item)
935 {
936    if ((item->wd->no_select) || (item->delete_me) || (item->hilighted)) return;
937    edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
938    item->hilighted = EINA_TRUE;
939 }
940
941 static void
942 _item_realize(Elm_Gengrid_Item *item)
943 {
944    char buf[1024];
945    char style[1024];
946
947    if ((item->realized) || (item->delete_me)) return;
948    item->base.view = edje_object_add(evas_object_evas_get(item->wd->self));
949    edje_object_scale_set(item->base.view, elm_widget_scale_get(item->wd->self) *
950                          _elm_config->scale);
951    edje_object_mirrored_set(item->base.view, elm_widget_mirrored_get(item->base.widget));
952    evas_object_smart_member_add(item->base.view, item->wd->pan_smart);
953    elm_widget_sub_object_add(item->wd->self, item->base.view);
954    snprintf(style, sizeof(style), "item/%s",
955             item->gic->item_style ? item->gic->item_style : "default");
956    _elm_theme_object_set(item->wd->self, item->base.view, "gengrid", style,
957                          elm_widget_style_get(item->wd->self));
958    item->spacer =
959        evas_object_rectangle_add(evas_object_evas_get(item->wd->self));
960    evas_object_color_set(item->spacer, 0, 0, 0, 0);
961    elm_widget_sub_object_add(item->wd->self, item->spacer);
962    evas_object_size_hint_min_set(item->spacer, 2 * _elm_config->scale, 1);
963    edje_object_part_swallow(item->base.view, "elm.swallow.pad", item->spacer);
964
965    if (item->gic->func.label_get)
966      {
967         const Eina_List *l;
968         const char *key;
969
970         item->labels =
971             elm_widget_stringlist_get(edje_object_data_get(item->base.view,
972                                                            "labels"));
973         EINA_LIST_FOREACH(item->labels, l, key)
974           {
975              char *s = item->gic->func.label_get
976                  ((void *)item->base.data, item->wd->self, l->data);
977              if (s)
978                {
979                   edje_object_part_text_set(item->base.view, l->data, s);
980                   free(s);
981                }
982           }
983      }
984
985    if (item->gic->func.icon_get)
986      {
987         const Eina_List *l;
988         const char *key;
989
990         item->icons =
991             elm_widget_stringlist_get(edje_object_data_get(item->base.view,
992                                                            "icons"));
993         EINA_LIST_FOREACH(item->icons, l, key)
994           {
995              Evas_Object *ic = item->gic->func.icon_get
996                  ((void *)item->base.data, item->wd->self, l->data);
997              if (ic)
998                {
999                   item->icon_objs = eina_list_append(item->icon_objs, ic);
1000                   edje_object_part_swallow(item->base.view, key, ic);
1001                   evas_object_show(ic);
1002                   elm_widget_sub_object_add(item->wd->self, ic);
1003                }
1004           }
1005      }
1006
1007    if (item->gic->func.state_get)
1008      {
1009         const Eina_List *l;
1010         const char *key;
1011
1012         item->states =
1013             elm_widget_stringlist_get(edje_object_data_get(item->base.view,
1014                                                            "states"));
1015         EINA_LIST_FOREACH(item->states, l, key)
1016           {
1017              Eina_Bool on = item->gic->func.state_get
1018                  ((void *)item->base.data, item->wd->self, l->data);
1019              if (on)
1020                {
1021                   snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1022                   edje_object_signal_emit(item->base.view, buf, "elm");
1023                }
1024           }
1025      }
1026
1027    if ((!item->wd->item_width) && (!item->wd->item_height))
1028      {
1029         edje_object_size_min_restricted_calc(item->base.view,
1030                                              &item->wd->item_width,
1031                                              &item->wd->item_height,
1032                                              item->wd->item_width,
1033                                              item->wd->item_height);
1034         elm_coords_finger_size_adjust(1, &item->wd->item_width,
1035                                       1, &item->wd->item_height);
1036      }
1037
1038    evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_DOWN,
1039                                   _mouse_down, item);
1040    evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_UP,
1041                                   _mouse_up, item);
1042    evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_MOVE,
1043                                   _mouse_move, item);
1044
1045    if (item->selected)
1046      edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
1047    if (item->disabled)
1048      edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1049
1050    evas_object_show(item->base.view);
1051
1052    if (item->tooltip.content_cb)
1053      {
1054         elm_widget_item_tooltip_content_cb_set(item,
1055                                                item->tooltip.content_cb,
1056                                                item->tooltip.data, NULL);
1057         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
1058      }
1059
1060    if (item->mouse_cursor)
1061      elm_widget_item_cursor_set(item, item->mouse_cursor);
1062
1063    item->realized = EINA_TRUE;
1064    item->want_unrealize = EINA_FALSE;
1065 }
1066
1067 static void
1068 _item_unrealize(Elm_Gengrid_Item *item)
1069 {
1070    Evas_Object *icon;
1071
1072    if (!item->realized) return;
1073    if (item->long_timer)
1074      {
1075         ecore_timer_del(item->long_timer);
1076         item->long_timer = NULL;
1077      }
1078    evas_object_del(item->base.view);
1079    item->base.view = NULL;
1080    evas_object_del(item->spacer);
1081    item->spacer = NULL;
1082    elm_widget_stringlist_free(item->labels);
1083    item->labels = NULL;
1084    elm_widget_stringlist_free(item->icons);
1085    item->icons = NULL;
1086    elm_widget_stringlist_free(item->states);
1087    item->states = NULL;
1088
1089    EINA_LIST_FREE(item->icon_objs, icon)
1090      evas_object_del(icon);
1091
1092    item->realized = EINA_FALSE;
1093    item->want_unrealize = EINA_FALSE;
1094 }
1095
1096 static void
1097 _item_place(Elm_Gengrid_Item *item,
1098             Evas_Coord        cx,
1099             Evas_Coord        cy)
1100 {
1101    Evas_Coord x, y, ox, oy, cvx, cvy, cvw, cvh;
1102    Evas_Coord tch, tcw, alignw = 0, alignh = 0, vw, vh;
1103    item->x = cx;
1104    item->y = cy;
1105    evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &vw, &vh);
1106
1107    /* Preload rows/columns at each side of the Gengrid */
1108    cvx = ox - PRELOAD * item->wd->item_width;
1109    cvy = oy - PRELOAD * item->wd->item_height;
1110    cvw = vw + 2 * PRELOAD * item->wd->item_width;
1111    cvh = vh + 2 * PRELOAD * item->wd->item_height;
1112
1113    alignh = 0;
1114    alignw = 0;
1115
1116    if (item->wd->horizontal)
1117      {
1118         int columns, items_visible = 0, items_row;
1119
1120         if (item->wd->item_height > 0)
1121           items_visible = vh / item->wd->item_height;
1122         if (items_visible < 1)
1123           items_visible = 1;
1124
1125         columns = item->wd->count / items_visible;
1126         if (item->wd->count % items_visible)
1127           columns++;
1128
1129         tcw = item->wd->item_width * columns;
1130         alignw = (vw - tcw) * item->wd->align_x;
1131
1132         items_row = items_visible;
1133         if (items_row > item->wd->count)
1134           items_row = item->wd->count;
1135         tch = items_row * item->wd->item_height;
1136         alignh = (vh - tch) * item->wd->align_y;
1137      }
1138    else
1139      {
1140         int rows, items_visible = 0, items_col;
1141
1142         if (item->wd->item_width > 0)
1143           items_visible = vw / item->wd->item_width;
1144         if (items_visible < 1)
1145           items_visible = 1;
1146
1147         rows = item->wd->count / items_visible;
1148         if (item->wd->count % items_visible)
1149           rows++;
1150
1151         tch = item->wd->item_height * rows;
1152         alignh = (vh - tch) * item->wd->align_y;
1153
1154         items_col = items_visible;
1155         if (items_col > item->wd->count)
1156           items_col = item->wd->count;
1157         tcw = items_col * item->wd->item_width;
1158         alignw = (vw - tcw) * item->wd->align_x;
1159      }
1160
1161    x = cx * item->wd->item_width - item->wd->pan_x + ox + alignw;
1162    if (elm_widget_mirrored_get(item->wd->self))
1163      {  /* Switch items side and componsate for pan_x when in RTL mode */
1164         Evas_Coord ww;
1165         evas_object_geometry_get(item->wd->self, NULL, NULL, &ww, NULL);
1166         x = ww - x - item->wd->item_width - item->wd->pan_x - item->wd->pan_x;
1167      }
1168
1169    y = cy * item->wd->item_height - item->wd->pan_y + oy + alignh;
1170
1171    Eina_Bool was_realized = item->realized;
1172    if (ELM_RECTS_INTERSECT(x, y, item->wd->item_width, item->wd->item_height,
1173                            cvx, cvy, cvw, cvh))
1174      {
1175         _item_realize(item);
1176         if (!was_realized)
1177           evas_object_smart_callback_call(item->wd->self, "realized", item);
1178         evas_object_move(item->base.view, x, y);
1179         evas_object_resize(item->base.view, item->wd->item_width,
1180                            item->wd->item_height);
1181      }
1182    else
1183      {
1184         _item_unrealize(item);
1185         if (was_realized)
1186           evas_object_smart_callback_call(item->wd->self, "unrealized", item);
1187      }
1188 }
1189
1190 static Elm_Gengrid_Item *
1191 _item_create(Widget_Data                  *wd,
1192              const Elm_Gengrid_Item_Class *gic,
1193              const void                   *data,
1194              Evas_Smart_Cb                 func,
1195              const void                   *func_data)
1196 {
1197    Elm_Gengrid_Item *item;
1198
1199    item = elm_widget_item_new(wd->self, Elm_Gengrid_Item);
1200    if (!item) return NULL;
1201    wd->count++;
1202    item->wd = wd;
1203    item->gic = gic;
1204    item->base.data = data;
1205    item->func.func = func;
1206    item->func.data = func_data;
1207    item->mouse_cursor = NULL;
1208    return item;
1209 }
1210
1211 static void
1212 _item_del(Elm_Gengrid_Item *item)
1213 {
1214    elm_widget_item_pre_notify_del(item);
1215    if (item->selected)
1216      item->wd->selected = eina_list_remove(item->wd->selected, item);
1217    if (item->realized) _item_unrealize(item);
1218    if ((!item->delete_me) && (item->gic->func.del))
1219      item->gic->func.del((void *)item->base.data, item->wd->self);
1220    item->delete_me = EINA_TRUE;
1221    item->wd->items = eina_inlist_remove(item->wd->items, EINA_INLIST_GET(item));
1222    if (item->long_timer) ecore_timer_del(item->long_timer);
1223    if (item->tooltip.del_cb)
1224      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
1225    item->wd->walking -= item->walking;
1226    item->wd->count--;
1227    if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1228    item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1229    elm_widget_item_del(item);
1230 }
1231
1232 static void
1233 _item_select(Elm_Gengrid_Item *item)
1234 {
1235    if ((item->wd->no_select) || (item->delete_me)) return;
1236    if (item->selected)
1237      {
1238         if (item->wd->always_select) goto call;
1239         return;
1240      }
1241    item->selected = EINA_TRUE;
1242    item->wd->selected = eina_list_append(item->wd->selected, item);
1243 call:
1244    item->walking++;
1245    item->wd->walking++;
1246    if (item->func.func)
1247      item->func.func((void *)item->func.data, item->wd->self, item);
1248    if (!item->delete_me)
1249      evas_object_smart_callback_call(item->wd->self, "selected", item);
1250    item->walking--;
1251    item->wd->walking--;
1252    if ((item->wd->clear_me) && (!item->wd->walking))
1253      elm_gengrid_clear(item->base.widget);
1254    else
1255      {
1256         if ((!item->walking) && (item->delete_me))
1257           if (!item->relcount) _item_del(item);
1258      }
1259    item->wd->last_selected_item = item;
1260 }
1261
1262 static void
1263 _item_unselect(Elm_Gengrid_Item *item)
1264 {
1265    if ((item->delete_me) || (!item->hilighted)) return;
1266    edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
1267    item->hilighted = EINA_FALSE;
1268    if (item->selected)
1269      {
1270         item->selected = EINA_FALSE;
1271         item->wd->selected = eina_list_remove(item->wd->selected, item);
1272         evas_object_smart_callback_call(item->wd->self, "unselected", item);
1273      }
1274 }
1275
1276 static void
1277 _calc_job(void *data)
1278 {
1279    Widget_Data *wd = data;
1280    Evas_Coord minw = 0, minh = 0, nmax = 0, cvw, cvh;
1281    int count;
1282
1283    evas_object_geometry_get(wd->pan_smart, NULL, NULL, &cvw, &cvh);
1284    if ((cvw != 0) || (cvh != 0))
1285      {
1286         if ((wd->horizontal) && (wd->item_height > 0))
1287           nmax = cvh / wd->item_height;
1288         else if (wd->item_width > 0)
1289           nmax = cvw / wd->item_width;
1290
1291         if (nmax < 1)
1292           nmax = 1;
1293
1294         count = wd->count;
1295         if (wd->horizontal)
1296           {
1297              minw = ceil(count / (float)nmax) * wd->item_width;
1298              minh = nmax * wd->item_height;
1299           }
1300         else
1301           {
1302              minw = nmax * wd->item_width;
1303              minh = ceil(count / (float)nmax) * wd->item_height;
1304           }
1305
1306         if ((minw != wd->minw) || (minh != wd->minh))
1307           {
1308              wd->minh = minh;
1309              wd->minw = minw;
1310              evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1311           }
1312
1313         wd->nmax = nmax;
1314         wd->calc_job = NULL;
1315         evas_object_smart_changed(wd->pan_smart);
1316      }
1317 }
1318
1319 static void
1320 _pan_add(Evas_Object *obj)
1321 {
1322    Pan *sd;
1323    Evas_Object_Smart_Clipped_Data *cd;
1324
1325    _pan_sc.add(obj);
1326    cd = evas_object_smart_data_get(obj);
1327    sd = ELM_NEW(Pan);
1328    if (!sd) return;
1329    sd->__clipped_data = *cd;
1330    free(cd);
1331    evas_object_smart_data_set(obj, sd);
1332 }
1333
1334 static void
1335 _pan_del(Evas_Object *obj)
1336 {
1337    Pan *sd = evas_object_smart_data_get(obj);
1338
1339    if (!sd) return;
1340    _pan_sc.del(obj);
1341 }
1342
1343 static void
1344 _pan_set(Evas_Object *obj,
1345          Evas_Coord   x,
1346          Evas_Coord   y)
1347 {
1348    Pan *sd = evas_object_smart_data_get(obj);
1349    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1350    sd->wd->pan_x = x;
1351    sd->wd->pan_y = y;
1352    evas_object_smart_changed(obj);
1353 }
1354
1355 static void
1356 _pan_get(Evas_Object *obj,
1357          Evas_Coord  *x,
1358          Evas_Coord  *y)
1359 {
1360    Pan *sd = evas_object_smart_data_get(obj);
1361    if (x) *x = sd->wd->pan_x;
1362    if (y) *y = sd->wd->pan_y;
1363 }
1364
1365 static void
1366 _pan_child_size_get(Evas_Object *obj,
1367                     Evas_Coord  *w,
1368                     Evas_Coord  *h)
1369 {
1370    Pan *sd = evas_object_smart_data_get(obj);
1371    if (w) *w = sd->wd->minw;
1372    if (h) *h = sd->wd->minh;
1373 }
1374
1375 static void
1376 _pan_max_get(Evas_Object *obj,
1377              Evas_Coord  *x,
1378              Evas_Coord  *y)
1379 {
1380    Pan *sd = evas_object_smart_data_get(obj);
1381    Evas_Coord ow, oh;
1382
1383    if (!sd) return;
1384    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1385    if (x)
1386      *x = (ow < sd->wd->minw) ? sd->wd->minw - ow : 0;
1387    if (y)
1388      *y = (oh < sd->wd->minh) ? sd->wd->minh - oh : 0;
1389 }
1390
1391 static void
1392 _pan_min_get(Evas_Object *obj,
1393              Evas_Coord  *x,
1394              Evas_Coord  *y)
1395 {
1396    Pan *sd = evas_object_smart_data_get(obj);
1397    Evas_Coord mx, my;
1398
1399    if (!sd) return;
1400    _pan_max_get(obj, &mx, &my);
1401    if (x)
1402      *x = -mx * sd->wd->align_x;
1403    if (y)
1404      *y = -my * sd->wd->align_y;
1405 }
1406
1407 static void
1408 _pan_resize(Evas_Object *obj,
1409             Evas_Coord   w,
1410             Evas_Coord   h)
1411 {
1412    Pan *sd = evas_object_smart_data_get(obj);
1413    Evas_Coord ow, oh;
1414
1415    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1416    if ((ow == w) && (oh == h)) return;
1417    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1418    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1419 }
1420
1421 static void
1422 _pan_calculate(Evas_Object *obj)
1423 {
1424    Pan *sd = evas_object_smart_data_get(obj);
1425    Evas_Coord cx = 0, cy = 0;
1426    Elm_Gengrid_Item *item;
1427
1428    if (!sd) return;
1429    if (!sd->wd->nmax) return;
1430
1431    EINA_INLIST_FOREACH(sd->wd->items, item)
1432    {
1433       _item_place(item, cx, cy);
1434       if (sd->wd->horizontal)
1435         {
1436            cy = (cy + 1) % sd->wd->nmax;
1437            if (!cy) cx++;
1438         }
1439       else
1440         {
1441            cx = (cx + 1) % sd->wd->nmax;
1442            if (!cx) cy++;
1443         }
1444    }
1445    evas_object_smart_callback_call(sd->wd->self, "changed", NULL);
1446 }
1447
1448 static void
1449 _pan_move(Evas_Object *obj,
1450           Evas_Coord x __UNUSED__,
1451           Evas_Coord y __UNUSED__)
1452 {
1453    Pan *sd = evas_object_smart_data_get(obj);
1454    if (!sd) return;
1455    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1456    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1457 }
1458
1459 static void
1460 _hold_on(void *data       __UNUSED__,
1461          Evas_Object     *obj,
1462          void *event_info __UNUSED__)
1463 {
1464    Widget_Data *wd = elm_widget_data_get(obj);
1465    if (!wd) return;
1466    elm_smart_scroller_hold_set(wd->scr, 1);
1467 }
1468
1469 static void
1470 _hold_off(void *data       __UNUSED__,
1471           Evas_Object     *obj,
1472           void *event_info __UNUSED__)
1473 {
1474    Widget_Data *wd = elm_widget_data_get(obj);
1475    if (!wd) return;
1476    elm_smart_scroller_hold_set(wd->scr, 0);
1477 }
1478
1479 static void
1480 _freeze_on(void *data       __UNUSED__,
1481            Evas_Object     *obj,
1482            void *event_info __UNUSED__)
1483 {
1484    Widget_Data *wd = elm_widget_data_get(obj);
1485    if (!wd) return;
1486    elm_smart_scroller_freeze_set(wd->scr, 1);
1487 }
1488
1489 static void
1490 _freeze_off(void *data       __UNUSED__,
1491             Evas_Object     *obj,
1492             void *event_info __UNUSED__)
1493 {
1494    Widget_Data *wd = elm_widget_data_get(obj);
1495    if (!wd) return;
1496    elm_smart_scroller_freeze_set(wd->scr, 0);
1497 }
1498
1499 static void
1500 _scr_drag_start(void            *data,
1501                 Evas_Object *obj __UNUSED__,
1502                 void *event_info __UNUSED__)
1503 {
1504    evas_object_smart_callback_call(data, "scroll,drag,start", NULL);
1505 }
1506
1507 static void
1508 _scr_drag_stop(void            *data,
1509                Evas_Object *obj __UNUSED__,
1510                void *event_info __UNUSED__)
1511 {
1512    evas_object_smart_callback_call(data, "scroll,drag,stop", NULL);
1513 }
1514
1515 static void
1516 _scr_scroll(void            *data,
1517             Evas_Object *obj __UNUSED__,
1518             void *event_info __UNUSED__)
1519 {
1520    evas_object_smart_callback_call(data, "scroll", NULL);
1521 }
1522
1523 /**
1524  * Add a new Gengrid object.
1525  *
1526  * @param parent The parent object.
1527  * @return  The new object or NULL if it cannot be created.
1528  *
1529  * @see elm_gengrid_item_size_set()
1530  * @see elm_gengrid_horizontal_set()
1531  * @see elm_gengrid_item_append()
1532  * @see elm_gengrid_item_del()
1533  * @see elm_gengrid_clear()
1534  *
1535  * @ingroup Gengrid
1536  */
1537 EAPI Evas_Object *
1538 elm_gengrid_add(Evas_Object *parent)
1539 {
1540    Evas_Object *obj;
1541    Evas *e;
1542    Widget_Data *wd;
1543    static Evas_Smart *smart = NULL;
1544    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1545
1546    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1547
1548    wd = ELM_NEW(Widget_Data);
1549    e = evas_object_evas_get(parent);
1550    if (!e) return NULL;
1551    obj = elm_widget_add(e);
1552    ELM_SET_WIDTYPE(widtype, "gengrid");
1553    elm_widget_type_set(obj, "gengrid");
1554    elm_widget_sub_object_add(parent, obj);
1555    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1556    elm_widget_data_set(obj, wd);
1557    elm_widget_del_hook_set(obj, _del_hook);
1558    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1559    elm_widget_theme_hook_set(obj, _theme_hook);
1560    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1561    elm_widget_can_focus_set(obj, EINA_TRUE);
1562    elm_widget_event_hook_set(obj, _event_hook);
1563
1564    wd->scr = elm_smart_scroller_add(e);
1565    elm_smart_scroller_widget_set(wd->scr, obj);
1566    elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
1567                                        "default");
1568    elm_widget_resize_object_set(obj, wd->scr);
1569
1570    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1571    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1572    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1573
1574    elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1575
1576    wd->self = obj;
1577    wd->align_x = 0.5;
1578    wd->align_y = 0.5;
1579    wd->no_select = EINA_FALSE;
1580
1581    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1582    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1583    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1584    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1585
1586    if (!smart)
1587      {
1588         static Evas_Smart_Class sc;
1589
1590         evas_object_smart_clipped_smart_set(&_pan_sc);
1591         sc = _pan_sc;
1592         sc.name = "elm_gengrid_pan";
1593         sc.version = EVAS_SMART_CLASS_VERSION;
1594         sc.add = _pan_add;
1595         sc.del = _pan_del;
1596         sc.resize = _pan_resize;
1597         sc.move = _pan_move;
1598         sc.calculate = _pan_calculate;
1599         smart = evas_smart_class_new(&sc);
1600      }
1601    if (smart)
1602      {
1603         wd->pan_smart = evas_object_smart_add(e, smart);
1604         wd->pan = evas_object_smart_data_get(wd->pan_smart);
1605         wd->pan->wd = wd;
1606      }
1607
1608    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1609                                      _pan_set, _pan_get, _pan_max_get,
1610                                      _pan_min_get, _pan_child_size_get);
1611
1612    _mirrored_set(obj, elm_widget_mirrored_get(obj));
1613    return obj;
1614 }
1615
1616 /**
1617  * Set the size for the item of the Gengrid.
1618  *
1619  * @param obj The Gengrid object.
1620  * @param w The item's width.
1621  * @param h The item's height;
1622  *
1623  * @see elm_gengrid_item_size_get()
1624  *
1625  * @ingroup Gengrid
1626  */
1627 EAPI void
1628 elm_gengrid_item_size_set(Evas_Object *obj,
1629                           Evas_Coord   w,
1630                           Evas_Coord   h)
1631 {
1632    ELM_CHECK_WIDTYPE(obj, widtype);
1633    Widget_Data *wd = elm_widget_data_get(obj);
1634    if (!wd) return;
1635    if ((wd->item_width == w) && (wd->item_height == h)) return;
1636    wd->item_width = w;
1637    wd->item_height = h;
1638    if (wd->calc_job) ecore_job_del(wd->calc_job);
1639    wd->calc_job = ecore_job_add(_calc_job, wd);
1640 }
1641
1642 /**
1643  * Get the size of the item of the Gengrid.
1644  *
1645  * @param obj The Gengrid object.
1646  * @param w Pointer to the item's width.
1647  * @param h Pointer to the item's height.
1648  *
1649  * @see elm_gengrid_item_size_get()
1650  *
1651  * @ingroup Gengrid
1652  */
1653 EAPI void
1654 elm_gengrid_item_size_get(const Evas_Object *obj,
1655                           Evas_Coord        *w,
1656                           Evas_Coord        *h)
1657 {
1658    ELM_CHECK_WIDTYPE(obj, widtype);
1659    Widget_Data *wd = elm_widget_data_get(obj);
1660    if (!wd) return;
1661    if (w) *w = wd->item_width;
1662    if (h) *h = wd->item_height;
1663 }
1664
1665 /**
1666  * Set item's alignment within the scroller.
1667  *
1668  * @param obj The Gengrid object.
1669  * @param align_x The x alignment (0 <= x <= 1).
1670  * @param align_y The y alignment (0 <= y <= 1).
1671  *
1672  * @see elm_gengrid_align_get()
1673  *
1674  * @ingroup Gengrid
1675  */
1676 EAPI void
1677 elm_gengrid_align_set(Evas_Object *obj,
1678                       double       align_x,
1679                       double       align_y)
1680 {
1681    ELM_CHECK_WIDTYPE(obj, widtype);
1682    Widget_Data *wd = elm_widget_data_get(obj);
1683
1684    if (align_x > 1.0)
1685      align_x = 1.0;
1686    else if (align_x < 0.0)
1687      align_x = 0.0;
1688    wd->align_x = align_x;
1689
1690    if (align_y > 1.0)
1691      align_y = 1.0;
1692    else if (align_y < 0.0)
1693      align_y = 0.0;
1694    wd->align_y = align_y;
1695 }
1696
1697 /**
1698  * Get the alignenment set for the Gengrid object.
1699  *
1700  * @param obj The Gengrid object.
1701  * @param align_x Pointer to x alignenment.
1702  * @param align_y Pointer to y alignenment.
1703  *
1704  * @see elm_gengrid_align_set()
1705  *
1706  * @ingroup Gengrid
1707  */
1708 EAPI void
1709 elm_gengrid_align_get(const Evas_Object *obj,
1710                       double            *align_x,
1711                       double            *align_y)
1712 {
1713    ELM_CHECK_WIDTYPE(obj, widtype);
1714    Widget_Data *wd = elm_widget_data_get(obj);
1715    if (align_x) *align_x = wd->align_x;
1716    if (align_y) *align_y = wd->align_y;
1717 }
1718
1719 /**
1720  * Add item to the end of the Gengrid.
1721  *
1722  * @param obj The Gengrid object.
1723  * @param gic The item class for the item.
1724  * @param data The item data.
1725  * @param func Convenience function called when item is selected.
1726  * @param func_data Data passed to @p func above.
1727  * @return A handle to the item added or NULL if not possible.
1728  *
1729  * @see elm_gengrid_item_prepend()
1730  * @see elm_gengrid_item_insert_before()
1731  * @see elm_gengrid_item_insert_after()
1732  * @see elm_gengrid_item_del()
1733  *
1734  * @ingroup Gengrid
1735  */
1736 EAPI Elm_Gengrid_Item *
1737 elm_gengrid_item_append(Evas_Object                  *obj,
1738                         const Elm_Gengrid_Item_Class *gic,
1739                         const void                   *data,
1740                         Evas_Smart_Cb                 func,
1741                         const void                   *func_data)
1742 {
1743    Elm_Gengrid_Item *item;
1744    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1745    Widget_Data *wd = elm_widget_data_get(obj);
1746    if (!wd) return NULL;
1747
1748    item = _item_create(wd, gic, data, func, func_data);
1749    if (!item) return NULL;
1750    wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(item));
1751
1752    if (wd->calc_job) ecore_job_del(wd->calc_job);
1753    wd->calc_job = ecore_job_add(_calc_job, wd);
1754
1755    return item;
1756 }
1757
1758 /**
1759  * Add item at start of the Gengrid.
1760  *
1761  * This adds an item to the beginning of the grid.
1762  *
1763  * @param obj The Gengrid object.
1764  * @param gic The item class for the item.
1765  * @param data The item data.
1766  * @param func Convenience function called when item is selected.
1767  * @param func_data Data passed to @p func above.
1768  * @return A handle to the item added or NULL if not possible.
1769  *
1770  * @see elm_gengrid_item_append()
1771  * @see elm_gengrid_item_insert_before()
1772  * @see elm_gengrid_item_insert_after()
1773  * @see elm_gengrid_item_del()
1774  *
1775  * @ingroup Gengrid
1776  */
1777 EAPI Elm_Gengrid_Item *
1778 elm_gengrid_item_prepend(Evas_Object                  *obj,
1779                          const Elm_Gengrid_Item_Class *gic,
1780                          const void                   *data,
1781                          Evas_Smart_Cb                 func,
1782                          const void                   *func_data)
1783 {
1784    Elm_Gengrid_Item *item;
1785    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1786    Widget_Data *wd = elm_widget_data_get(obj);
1787    if (!wd) return NULL;
1788
1789    item = _item_create(wd, gic, data, func, func_data);
1790    if (!item) return NULL;
1791    wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(item));
1792
1793    if (wd->calc_job) ecore_job_del(wd->calc_job);
1794    wd->calc_job = ecore_job_add(_calc_job, wd);
1795
1796    return item;
1797 }
1798
1799 /**
1800  * Insert and item before another in the Gengrid.
1801  *
1802  * This inserts an item before another in the grid.
1803  *
1804  * @param obj The Gengrid object.
1805  * @param gic The item class for the item.
1806  * @param data The item data.
1807  * @param relative The item to which insert before.
1808  * @param func Convenience function called when item is selected.
1809  * @param func_data Data passed to @p func above.
1810  * @return A handle to the item added or NULL if not possible.
1811  *
1812  * @see elm_gengrid_item_append()
1813  * @see elm_gengrid_item_prepend()
1814  * @see elm_gengrid_item_insert_after()
1815  * @see elm_gengrid_item_del()
1816  *
1817  * @ingroup Gengrid
1818  */
1819 EAPI Elm_Gengrid_Item *
1820 elm_gengrid_item_insert_before(Evas_Object                  *obj,
1821                                const Elm_Gengrid_Item_Class *gic,
1822                                const void                   *data,
1823                                Elm_Gengrid_Item             *relative,
1824                                Evas_Smart_Cb                 func,
1825                                const void                   *func_data)
1826 {
1827    Elm_Gengrid_Item *item;
1828    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1829    EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
1830    Widget_Data *wd = elm_widget_data_get(obj);
1831    if (!wd) return NULL;
1832
1833    item = _item_create(wd, gic, data, func, func_data);
1834    if (!item) return NULL;
1835    wd->items = eina_inlist_prepend_relative
1836        (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
1837
1838    if (wd->calc_job) ecore_job_del(wd->calc_job);
1839    wd->calc_job = ecore_job_add(_calc_job, wd);
1840
1841    return item;
1842 }
1843
1844 /**
1845  * Insert and item after another in the Gengrid.
1846  *
1847  * This inserts an item after another in the grid.
1848  *
1849  * @param obj The Gengrid object.
1850  * @param gic The item class for the item.
1851  * @param data The item data.
1852  * @param relative The item to which insert after.
1853  * @param func Convenience function called when item is selected.
1854  * @param func_data Data passed to @p func above.
1855  * @return A handle to the item added or NULL if not possible.
1856  *
1857  * @see elm_gengrid_item_append()
1858  * @see elm_gengrid_item_prepend()
1859  * @see elm_gengrid_item_insert_before()
1860  * @see elm_gengrid_item_del()
1861  *
1862  * @ingroup Gengrid
1863  */
1864 EAPI Elm_Gengrid_Item *
1865 elm_gengrid_item_insert_after(Evas_Object                  *obj,
1866                               const Elm_Gengrid_Item_Class *gic,
1867                               const void                   *data,
1868                               Elm_Gengrid_Item             *relative,
1869                               Evas_Smart_Cb                 func,
1870                               const void                   *func_data)
1871 {
1872    Elm_Gengrid_Item *item;
1873    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1874    EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
1875    Widget_Data *wd = elm_widget_data_get(obj);
1876    if (!wd) return NULL;
1877
1878    item = _item_create(wd, gic, data, func, func_data);
1879    if (!item) return NULL;
1880    wd->items = eina_inlist_append_relative
1881        (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
1882
1883    if (wd->calc_job) ecore_job_del(wd->calc_job);
1884    wd->calc_job = ecore_job_add(_calc_job, wd);
1885
1886    return item;
1887 }
1888
1889 /**
1890  * Remove a item from the Gengrid.
1891  *
1892  * @param item The item to be removed.
1893  * @return @c EINA_TRUE on success or @c EINA_FALSE otherwise.
1894  *
1895  * @see elm_gengrid_clear() to remove all items of the Gengrid.
1896  *
1897  * @ingroup Gengrid
1898  */
1899 EAPI void
1900 elm_gengrid_item_del(Elm_Gengrid_Item *item)
1901 {
1902    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1903    if ((item->relcount > 0) || (item->walking > 0))
1904      {
1905         item->delete_me = EINA_TRUE;
1906         elm_widget_item_pre_notify_del(item);
1907         if (item->selected)
1908           item->wd->selected = eina_list_remove(item->wd->selected, item);
1909         if (item->gic->func.del)
1910           item->gic->func.del((void *)item->base.data, item->wd->self);
1911         return;
1912      }
1913
1914    _item_del(item);
1915 }
1916
1917 /**
1918  * Set for what direction the Gengrid will expand.
1919  *
1920  * @param obj The Gengrid object.
1921  * @param setting If @c EINA_TRUE the Gengrid will expand horizontally
1922  * or vertically if @c EINA_FALSE.
1923  *
1924  * @ingroup Gengrid
1925  */
1926 EAPI void
1927 elm_gengrid_horizontal_set(Evas_Object *obj,
1928                            Eina_Bool    setting)
1929 {
1930    ELM_CHECK_WIDTYPE(obj, widtype);
1931    Widget_Data *wd = elm_widget_data_get(obj);
1932    if (!wd) return;
1933    if (setting == wd->horizontal) return;
1934    wd->horizontal = setting;
1935
1936    /* Update the items to conform to the new layout */
1937    if (wd->calc_job) ecore_job_del(wd->calc_job);
1938    wd->calc_job = ecore_job_add(_calc_job, wd);
1939 }
1940
1941 /**
1942  * Clear the Gengrid
1943  *
1944  * This clears all items in the Gengrid, leaving it empty.
1945  *
1946  * @param obj The Gengrid object.
1947  *
1948  * @see elm_gengrid_item_del() to remove just one item.
1949  *
1950  * @ingroup Gengrid
1951  */
1952 EAPI void
1953 elm_gengrid_clear(Evas_Object *obj)
1954 {
1955    ELM_CHECK_WIDTYPE(obj, widtype);
1956    Widget_Data *wd = elm_widget_data_get(obj);
1957    if (!wd) return;
1958
1959    if (wd->calc_job)
1960      {
1961         ecore_job_del(wd->calc_job);
1962         wd->calc_job = NULL;
1963      }
1964
1965    if (wd->walking > 0)
1966      {
1967         Elm_Gengrid_Item *item;
1968         wd->clear_me = 1;
1969         EINA_INLIST_FOREACH(wd->items, item)
1970         item->delete_me = 1;
1971         return;
1972      }
1973    wd->clear_me = 0;
1974    while (wd->items)
1975      {
1976         Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
1977
1978         wd->items = eina_inlist_remove(wd->items, wd->items);
1979         elm_widget_item_pre_notify_del(item);
1980         if (item->realized) _item_unrealize(item);
1981         if (item->gic->func.del)
1982           item->gic->func.del((void *)item->base.data, wd->self);
1983         if (item->long_timer) ecore_timer_del(item->long_timer);
1984         elm_widget_item_del(item);
1985      }
1986
1987    if (wd->selected)
1988      {
1989         eina_list_free(wd->selected);
1990         wd->selected = NULL;
1991      }
1992
1993    wd->pan_x = 0;
1994    wd->pan_y = 0;
1995    wd->minw = 0;
1996    wd->minh = 0;
1997    wd->count = 0;
1998    evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
1999    evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2000 }
2001
2002 /**
2003  * Get the real evas object of the Gengrid item
2004  *
2005  * This returns the actual evas object used for the specified Gengrid
2006  * item.  This may be NULL as it may not be created, and may be
2007  * deleted at any time by Gengrid. Do not modify this object (move,
2008  * resize, show, hide etc.) as Gengrid is controlling it. This
2009  * function is for querying, emitting custom signals or hooking lower
2010  * level callbacks for events. Do not delete this object under any
2011  * circumstances.
2012  *
2013  * @param item The Gengrid item.
2014  * @return the evas object associated to this item.
2015  *
2016  * @see elm_gengrid_item_data_get()
2017  *
2018  * @ingroup Gengrid
2019  */
2020 EAPI const Evas_Object *
2021 elm_gengrid_item_object_get(const Elm_Gengrid_Item *item)
2022 {
2023    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2024    return item->base.view;
2025 }
2026
2027 /**
2028  * Update the contents of an item
2029  *
2030  * This updates an item by calling all the item class functions again
2031  * to get the icons, labels and states. Use this when the original
2032  * item data has changed and the changes are desired to be reflected.
2033  *
2034  * @param item The item
2035  *
2036  * @ingroup Gengrid
2037  */
2038 EAPI void
2039 elm_gengrid_item_update(Elm_Gengrid_Item *item)
2040 {
2041    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2042    if (!item->realized) return;
2043    if (item->want_unrealize) return;
2044    _item_unrealize(item);
2045    _item_realize(item);
2046    _item_place(item, item->x, item->y);
2047 }
2048
2049 /**
2050  * Returns the data associated to a item
2051  *
2052  * This returns the data value passed on the elm_gengrid_item_append()
2053  * and related item addition calls.
2054  *
2055  * @param item The Gengrid item.
2056  * @return the data associated to this item.
2057  *
2058  * @see elm_gengrid_item_append()
2059  * @see elm_gengrid_item_object_get()
2060  *
2061  * @ingroup Gengrid
2062  */
2063 EAPI void *
2064 elm_gengrid_item_data_get(const Elm_Gengrid_Item *item)
2065 {
2066    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2067    return elm_widget_item_data_get(item);
2068 }
2069
2070 /**
2071  * Set the data item from the gengrid item
2072  *
2073  * This set the data value passed on the elm_gengrid_item_append() and
2074  * related item addition calls. This function will also call
2075  * elm_gengrid_item_update() so the item will be updated to reflect
2076  * the new data.
2077  *
2078  * @param item The item
2079  * @param data The new data pointer to set
2080  *
2081  * @ingroup Gengrid
2082  */
2083 EAPI void
2084 elm_gengrid_item_data_set(Elm_Gengrid_Item *item,
2085                           const void       *data)
2086 {
2087    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2088    elm_widget_item_data_set(item, data);
2089    elm_gengrid_item_update(item);
2090 }
2091
2092 /**
2093  * Get the item's coordinates.
2094  *
2095  * This returns the logical position of the item whithin the Gengrid.
2096  *
2097  * @param item The Gengrid item.
2098  * @param x The x-axis coordinate pointer.
2099  * @param y The y-axis coordinate pointer.
2100  *
2101  * @ingroup Gengrid
2102  */
2103 EAPI void
2104 elm_gengrid_item_pos_get(const Elm_Gengrid_Item *item,
2105                          unsigned int           *x,
2106                          unsigned int           *y)
2107 {
2108    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2109    if (x) *x = item->x;
2110    if (y) *y = item->y;
2111 }
2112
2113 /**
2114  * Enable or disable multi-select in the Gengrid.
2115  *
2116  * This enables (EINA_TRUE) or disables (EINA_FALSE) multi-select in
2117  * the Gengrid.  This allows more than 1 item to be selected.
2118  *
2119  * @param obj The Gengrid object.
2120  * @param multi Multi-select enabled/disabled
2121  *
2122  * @ingroup Gengrid
2123  */
2124 EAPI void
2125 elm_gengrid_multi_select_set(Evas_Object *obj,
2126                              Eina_Bool    multi)
2127 {
2128    ELM_CHECK_WIDTYPE(obj, widtype);
2129    Widget_Data *wd = elm_widget_data_get(obj);
2130    if (!wd) return;
2131    wd->multi = multi;
2132 }
2133
2134 /**
2135  * Get if multi-select in Gengrid is enabled or disabled
2136  *
2137  * @param obj The Gengrid object
2138  * @return Multi-select enable/disable
2139  * (EINA_TRUE = enabled / EINA_FALSE = disabled)
2140  *
2141  * @ingroup Gengrid
2142  */
2143 EAPI Eina_Bool
2144 elm_gengrid_multi_select_get(const Evas_Object *obj)
2145 {
2146    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2147    Widget_Data *wd = elm_widget_data_get(obj);
2148    if (!wd) return EINA_FALSE;
2149    return wd->multi;
2150 }
2151
2152 /**
2153  * Get the selected item in the Gengrid
2154  *
2155  * This gets the selected item in the Gengrid (if multi-select is
2156  * enabled only the first item in the list is selected - which is not
2157  * very useful, so see elm_gengrid_selected_items_get() for when
2158  * multi-select is used).
2159  *
2160  * If no item is selected, NULL is returned.
2161  *
2162  * @param obj The Gengrid object.
2163  * @return The selected item, or NULL if none.
2164  *
2165  * @ingroup Gengrid
2166  */
2167 EAPI Elm_Gengrid_Item *
2168 elm_gengrid_selected_item_get(const Evas_Object *obj)
2169 {
2170    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2171    Widget_Data *wd = elm_widget_data_get(obj);
2172    if (!wd) return NULL;
2173    if (wd->selected) return wd->selected->data;
2174    return NULL;
2175 }
2176
2177 /**
2178  * Get a list of selected items in the Gengrid.
2179  *
2180  * This returns a list of the selected items. This list pointer is
2181  * only valid so long as no items are selected or unselected (or
2182  * unselected implictly by deletion). The list contains
2183  * Elm_Gengrid_Item pointers.
2184  *
2185  * @param obj The Gengrid object.
2186  * @return The list of selected items, or NULL if none are selected.
2187  *
2188  * @ingroup Gengrid
2189  */
2190 EAPI const Eina_List *
2191 elm_gengrid_selected_items_get(const Evas_Object *obj)
2192 {
2193    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2194    Widget_Data *wd = elm_widget_data_get(obj);
2195    if (!wd) return NULL;
2196    return wd->selected;
2197 }
2198
2199 /**
2200  * Set the selected state of a item.
2201  *
2202  * This sets the selected state of a item. If multi-select is not
2203  * enabled and selected is EINA_TRUE, previously selected items are
2204  * unselected.
2205  *
2206  * @param item The item
2207  * @param selected The selected state.
2208  *
2209  * @ingroup Gengrid
2210  */
2211 EAPI void
2212 elm_gengrid_item_selected_set(Elm_Gengrid_Item *item,
2213                               Eina_Bool         selected)
2214 {
2215    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2216    Widget_Data *wd = item->wd;
2217    if (!wd) return;
2218    if (item->delete_me) return;
2219    selected = !!selected;
2220    if (item->selected == selected) return;
2221
2222    if (selected)
2223      {
2224         if (!wd->multi)
2225           {
2226              while (wd->selected)
2227                _item_unselect(wd->selected->data);
2228           }
2229         _item_hilight(item);
2230         _item_select(item);
2231      }
2232    else
2233      _item_unselect(item);
2234 }
2235
2236 /**
2237  * Get the selected state of a item.
2238  *
2239  * This gets the selected state of a item (1 selected, 0 not selected).
2240  *
2241  * @param item The item
2242  * @return The selected state
2243  *
2244  * @ingroup Gengrid
2245  */
2246 EAPI Eina_Bool
2247 elm_gengrid_item_selected_get(const Elm_Gengrid_Item *item)
2248 {
2249    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2250    return item->selected;
2251 }
2252
2253 /**
2254  * Sets the disabled state of a item.
2255  *
2256  * A disabled item cannot be selected or unselected. It will also
2257  * change appearance to disabled. This sets the disabled state (1
2258  * disabled, 0 not disabled).
2259  *
2260  * @param item The item
2261  * @param disabled The disabled state
2262  *
2263  * @ingroup Gengrid
2264  */
2265 EAPI void
2266 elm_gengrid_item_disabled_set(Elm_Gengrid_Item *item,
2267                               Eina_Bool         disabled)
2268 {
2269    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2270    if (item->disabled == disabled) return;
2271    if (item->delete_me) return;
2272    item->disabled = disabled;
2273    if (item->realized)
2274      {
2275         if (item->disabled)
2276           edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
2277         else
2278           edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
2279      }
2280 }
2281
2282 /**
2283  * Get the disabled state of a item.
2284  *
2285  * This gets the disabled state of the given item.
2286  *
2287  * @param item The item
2288  * @return The disabled state
2289  *
2290  * @ingroup Gengrid
2291  */
2292 EAPI Eina_Bool
2293 elm_gengrid_item_disabled_get(const Elm_Gengrid_Item *item)
2294 {
2295    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2296    if (item->delete_me) return EINA_FALSE;
2297    return item->disabled;
2298 }
2299
2300 static Evas_Object *
2301 _elm_gengrid_item_label_create(void        *data,
2302                                Evas_Object *obj,
2303                                void *item   __UNUSED__)
2304 {
2305    Evas_Object *label = elm_label_add(obj);
2306    if (!label)
2307      return NULL;
2308    elm_object_style_set(label, "tooltip");
2309    elm_label_label_set(label, data);
2310    return label;
2311 }
2312
2313 static void
2314 _elm_gengrid_item_label_del_cb(void            *data,
2315                                Evas_Object *obj __UNUSED__,
2316                                void *event_info __UNUSED__)
2317 {
2318    eina_stringshare_del(data);
2319 }
2320
2321 /**
2322  * Set the text to be shown in the gengrid item.
2323  *
2324  * @param item Target item
2325  * @param text The text to set in the content
2326  *
2327  * Setup the text as tooltip to object. The item can have only one
2328  * tooltip, so any previous tooltip data is removed.
2329  *
2330  * @ingroup Gengrid
2331  */
2332 EAPI void
2333 elm_gengrid_item_tooltip_text_set(Elm_Gengrid_Item *item,
2334                                   const char       *text)
2335 {
2336    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2337    text = eina_stringshare_add(text);
2338    elm_gengrid_item_tooltip_content_cb_set(item, _elm_gengrid_item_label_create,
2339                                            text,
2340                                            _elm_gengrid_item_label_del_cb);
2341 }
2342
2343 /**
2344  * Set the content to be shown in the tooltip item
2345  *
2346  * Setup the tooltip to item. The item can have only one tooltip, so
2347  * any previous tooltip data is removed. @p func(with @p data) will be
2348  * called every time that need show the tooltip and it should return a
2349  * valid Evas_Object. This object is then managed fully by tooltip
2350  * system and is deleted when the tooltip is gone.
2351  *
2352  * @param item the gengrid item being attached a tooltip.
2353  * @param func the function used to create the tooltip contents.
2354  * @param data what to provide to @a func as callback data/context.
2355  * @param del_cb called when data is not needed anymore, either when
2356  *        another callback replaces @func, the tooltip is unset with
2357  *        elm_gengrid_item_tooltip_unset() or the owner @a item
2358  *        dies. This callback receives as the first parameter the
2359  *        given @a data, and @c event_info is the item.
2360  *
2361  * @ingroup Gengrid
2362  */
2363 EAPI void
2364 elm_gengrid_item_tooltip_content_cb_set(Elm_Gengrid_Item           *item,
2365                                         Elm_Tooltip_Item_Content_Cb func,
2366                                         const void                 *data,
2367                                         Evas_Smart_Cb               del_cb)
2368 {
2369    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
2370
2371    if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
2372      return;
2373
2374    if (item->tooltip.del_cb)
2375      item->tooltip.del_cb((void *)item->tooltip.data,
2376                           item->base.widget, item);
2377    item->tooltip.content_cb = func;
2378    item->tooltip.data = data;
2379    item->tooltip.del_cb = del_cb;
2380    if (item->base.view)
2381      {
2382         elm_widget_item_tooltip_content_cb_set(item,
2383                                                item->tooltip.content_cb,
2384                                                item->tooltip.data, NULL);
2385         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
2386      }
2387
2388    return;
2389
2390 error:
2391    if (del_cb) del_cb((void *)data, NULL, NULL);
2392 }
2393
2394 /**
2395  * Unset tooltip from item
2396  *
2397  * @param item gengrid item to remove previously set tooltip.
2398  *
2399  * Remove tooltip from item. The callback provided as del_cb to
2400  * elm_gengrid_item_tooltip_content_cb_set() will be called to notify
2401  * it is not used anymore.
2402  *
2403  * @see elm_gengrid_item_tooltip_content_cb_set()
2404  *
2405  * @ingroup Gengrid
2406  */
2407 EAPI void
2408 elm_gengrid_item_tooltip_unset(Elm_Gengrid_Item *item)
2409 {
2410    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2411    if ((item->base.view) && (item->tooltip.content_cb))
2412      elm_widget_item_tooltip_unset(item);
2413
2414    if (item->tooltip.del_cb)
2415      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
2416    item->tooltip.del_cb = NULL;
2417    item->tooltip.content_cb = NULL;
2418    item->tooltip.data = NULL;
2419    if (item->tooltip.style)
2420      elm_gengrid_item_tooltip_style_set(item, NULL);
2421 }
2422
2423 /**
2424  * Sets a different style for this item tooltip.
2425  *
2426  * @note before you set a style you should define a tooltip with
2427  *       elm_gengrid_item_tooltip_content_cb_set() or
2428  *       elm_gengrid_item_tooltip_text_set()
2429  *
2430  * @param item gengrid item with tooltip already set.
2431  * @param style the theme style to use (default, transparent, ...)
2432  *
2433  * @ingroup Gengrid
2434  */
2435 EAPI void
2436 elm_gengrid_item_tooltip_style_set(Elm_Gengrid_Item *item,
2437                                    const char       *style)
2438 {
2439    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2440    eina_stringshare_replace(&item->tooltip.style, style);
2441    if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
2442 }
2443
2444 /**
2445  * Get the style for this item tooltip.
2446  *
2447  * @param item gengrid item with tooltip already set.
2448  * @return style the theme style in use, defaults to "default". If the
2449  *         object does not have a tooltip set, then NULL is returned.
2450  *
2451  * @ingroup Gengrid
2452  */
2453 EAPI const char *
2454 elm_gengrid_item_tooltip_style_get(const Elm_Gengrid_Item *item)
2455 {
2456    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2457    return item->tooltip.style;
2458 }
2459
2460 /**
2461  * Set the cursor to be shown when mouse is over the gengrid item
2462  *
2463  * @param item Target item
2464  * @param cursor the cursor name to be used.
2465  *
2466  * @see elm_object_cursor_set()
2467  * @ingroup Gengrid
2468  */
2469 EAPI void
2470 elm_gengrid_item_cursor_set(Elm_Gengrid_Item *item,
2471                             const char       *cursor)
2472 {
2473    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2474    eina_stringshare_replace(&item->mouse_cursor, cursor);
2475    if (item->base.view) elm_widget_item_cursor_set(item, cursor);
2476 }
2477
2478 /**
2479  * Get the cursor to be shown when mouse is over the gengrid item
2480  *
2481  * @param item gengrid item with cursor already set.
2482  * @return the cursor name.
2483  *
2484  * @ingroup Gengrid
2485  */
2486 EAPI const char *
2487 elm_gengrid_item_cursor_get(const Elm_Gengrid_Item *item)
2488 {
2489    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2490    return elm_widget_item_cursor_get(item);
2491 }
2492
2493 /**
2494  * Unset the cursor to be shown when mouse is over the gengrid item
2495  *
2496  * @param item Target item
2497  *
2498  * @see elm_object_cursor_unset()
2499  * @ingroup Gengrid
2500  */
2501 EAPI void
2502 elm_gengrid_item_cursor_unset(Elm_Gengrid_Item *item)
2503 {
2504    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2505    if (!item->mouse_cursor)
2506      return;
2507
2508    if (item->base.view)
2509      elm_widget_item_cursor_unset(item);
2510
2511    eina_stringshare_del(item->mouse_cursor);
2512    item->mouse_cursor = NULL;
2513 }
2514
2515 /**
2516  * Sets a different style for this item cursor.
2517  *
2518  * @note before you set a style you should define a cursor with
2519  *       elm_gengrid_item_cursor_set()
2520  *
2521  * @param item gengrid item with cursor already set.
2522  * @param style the theme style to use (default, transparent, ...)
2523  *
2524  * @ingroup Gengrid
2525  */
2526 EAPI void
2527 elm_gengrid_item_cursor_style_set(Elm_Gengrid_Item *item,
2528                                   const char       *style)
2529 {
2530    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2531    elm_widget_item_cursor_style_set(item, style);
2532 }
2533
2534 /**
2535  * Get the style for this item cursor.
2536  *
2537  * @param item gengrid item with cursor already set.
2538  * @return style the theme style in use, defaults to "default". If the
2539  *         object does not have a cursor set, then NULL is returned.
2540  *
2541  * @ingroup Gengrid
2542  */
2543 EAPI const char *
2544 elm_gengrid_item_cursor_style_get(const Elm_Gengrid_Item *item)
2545 {
2546    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2547    return elm_widget_item_cursor_style_get(item);
2548 }
2549
2550 /**
2551  * Set if the cursor set should be searched on the theme or should use
2552  * the provided by the engine, only.
2553  *
2554  * @note before you set if should look on theme you should define a
2555  * cursor with elm_object_cursor_set(). By default it will only look
2556  * for cursors provided by the engine.
2557  *
2558  * @param item widget item with cursor already set.
2559  * @param engine_only boolean to define it cursors should be looked
2560  * only between the provided by the engine or searched on widget's
2561  * theme as well.
2562  *
2563  * @ingroup Gengrid
2564  */
2565 EAPI void
2566 elm_gengrid_item_cursor_engine_only_set(Elm_Gengrid_Item *item,
2567                                         Eina_Bool         engine_only)
2568 {
2569    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2570    elm_widget_item_cursor_engine_only_set(item, engine_only);
2571 }
2572
2573 /**
2574  * Get the cursor engine only usage for this item cursor.
2575  *
2576  * @param item widget item with cursor already set.
2577  * @return engine_only boolean to define it cursors should be looked
2578  * only between the provided by the engine or searched on widget's
2579  * theme as well. If the object does not have a cursor set, then
2580  * EINA_FALSE is returned.
2581  *
2582  * @ingroup Gengrid
2583  */
2584 EAPI Eina_Bool
2585 elm_gengrid_item_cursor_engine_only_get(const Elm_Gengrid_Item *item)
2586 {
2587    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2588    return elm_widget_item_cursor_engine_only_get(item);
2589 }
2590
2591 /**
2592  * Set the always select mode.
2593  *
2594  * Cells will only call their selection func and callback when first
2595  * becoming selected. Any further clicks will do nothing, unless you
2596  * enable always select with
2597  * elm_gengrid_always_select_mode_set(). This means even if selected,
2598  * every click will make the selected callbacks be called.
2599  *
2600  * @param obj The Gengrid object
2601  * @param always_select The always select mode (EINA_TRUE = on,
2602  * EINA_FALSE = off)
2603  *
2604  * @ingroup Gengrid
2605  */
2606 EAPI void
2607 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2608                                    Eina_Bool    always_select)
2609 {
2610    ELM_CHECK_WIDTYPE(obj, widtype);
2611    Widget_Data *wd = elm_widget_data_get(obj);
2612    if (!wd) return;
2613    wd->always_select = always_select;
2614 }
2615
2616 /**
2617  * Get the always select mode.
2618  *
2619  * @param obj The Gengrid object.
2620  * @return The always select mode (EINA_TRUE = on, EINA_FALSE = off)
2621  *
2622  * @ingroup Gengrid
2623  */
2624 EAPI Eina_Bool
2625 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2626 {
2627    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2628    Widget_Data *wd = elm_widget_data_get(obj);
2629    if (!wd) return EINA_FALSE;
2630    return wd->always_select;
2631 }
2632
2633 /**
2634  * Set no select mode.
2635  *
2636  * This will turn off the ability to select items entirely and they
2637  * will neither appear selected nor call selected callback functions.
2638  *
2639  * @param obj The Gengrid object
2640  * @param no_select The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2641  *
2642  * @ingroup Gengrid
2643  */
2644 EAPI void
2645 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2646                                Eina_Bool    no_select)
2647 {
2648    ELM_CHECK_WIDTYPE(obj, widtype);
2649    Widget_Data *wd = elm_widget_data_get(obj);
2650    if (!wd) return;
2651    wd->no_select = no_select;
2652 }
2653
2654 /**
2655  * Gets no select mode.
2656  *
2657  * @param obj The Gengrid object
2658  * @return The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2659  *
2660  * @ingroup Gengrid
2661  */
2662 EAPI Eina_Bool
2663 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2664 {
2665    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2666    Widget_Data *wd = elm_widget_data_get(obj);
2667    if (!wd) return EINA_FALSE;
2668    return wd->no_select;
2669 }
2670
2671 /**
2672  * Set bounce mode.
2673  *
2674  * This will enable or disable the scroller bounce mode for the
2675  * Gengrid. See elm_scroller_bounce_set() for details.
2676  *
2677  * @param obj The Gengrid object
2678  * @param h_bounce Allow bounce horizontally
2679  * @param v_bounce Allow bounce vertically
2680  *
2681  * @ingroup Gengrid
2682  */
2683 EAPI void
2684 elm_gengrid_bounce_set(Evas_Object *obj,
2685                        Eina_Bool    h_bounce,
2686                        Eina_Bool    v_bounce)
2687 {
2688    ELM_CHECK_WIDTYPE(obj, widtype);
2689    Widget_Data *wd = elm_widget_data_get(obj);
2690    if (!wd) return;
2691    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
2692 }
2693
2694 /**
2695  * Get the bounce mode
2696  *
2697  * @param obj The Gengrid object
2698  * @param h_bounce Allow bounce horizontally
2699  * @param v_bounce Allow bounce vertically
2700  *
2701  * @ingroup Gengrid
2702  */
2703 EAPI void
2704 elm_gengrid_bounce_get(const Evas_Object *obj,
2705                        Eina_Bool         *h_bounce,
2706                        Eina_Bool         *v_bounce)
2707 {
2708    ELM_CHECK_WIDTYPE(obj, widtype);
2709    Widget_Data *wd = elm_widget_data_get(obj);
2710    if (!wd) return;
2711    elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
2712 }
2713
2714 /**
2715  * Get all items in the Gengrid.
2716  *
2717  * This returns a list of the Gengrid items. The list contains
2718  * Elm_Gengrid_Item pointers.
2719  *
2720  * @param obj The Gengrid object.
2721  * @return The list of items, or NULL if none.
2722  *
2723  * @ingroup Gengrid
2724  */
2725
2726 /**
2727  * Set gengrid scroll page size relative to viewport size.
2728  *
2729  * The gengrid scroller is capable of limiting scrolling by the user
2730  * to "pages" That is to jump by and only show a "whole page" at a
2731  * time as if the continuous area of the scroller content is split
2732  * into page sized pieces.  This sets the size of a page relative to
2733  * the viewport of the scroller. 1.0 is "1 viewport" is size
2734  * (horizontally or vertically). 0.0 turns it off in that axis. This
2735  * is mutually exclusive with page size (see
2736  * elm_gengrid_page_size_set() for more information). Likewise 0.5 is
2737  * "half a viewport". Sane usable valus are normally between 0.0 and
2738  * 1.0 including 1.0. If you only want 1 axis to be page "limited",
2739  * use 0.0 for the other axis.
2740  *
2741  * @param obj The gengrid object
2742  * @param h_pagerel The horizontal page relative size
2743  * @param v_pagerel The vertical page relative size
2744  *
2745  * @ingroup Gengrid
2746  */
2747 EAPI void
2748 elm_gengrid_page_relative_set(Evas_Object *obj,
2749                               double       h_pagerel,
2750                               double       v_pagerel)
2751 {
2752    Evas_Coord pagesize_h;
2753    Evas_Coord pagesize_v;
2754
2755    ELM_CHECK_WIDTYPE(obj, widtype);
2756    Widget_Data *wd = elm_widget_data_get(obj);
2757    if (!wd) return;
2758
2759    elm_smart_scroller_paging_get(wd->scr, NULL, NULL, &pagesize_h, &pagesize_v);
2760    elm_smart_scroller_paging_set(wd->scr, h_pagerel, v_pagerel, pagesize_h,
2761                                  pagesize_v);
2762 }
2763
2764 /**
2765  * Set gengrid scroll page size.
2766  *
2767  * See also elm_gengrid_page_relative_set(). This, instead of a page
2768  * size being relative to the viewport, sets it to an absolute fixed
2769  * value, with 0 turning it off for that axis.
2770  *
2771  * @param obj The gengrid object
2772  * @param h_pagesize The horizontal page size
2773  * @param v_pagesize The vertical page size
2774  *
2775  * @ingroup Gengrid
2776  */
2777 EAPI void
2778 elm_gengrid_page_size_set(Evas_Object *obj,
2779                           Evas_Coord   h_pagesize,
2780                           Evas_Coord   v_pagesize)
2781 {
2782    double pagerel_h;
2783    double pagerel_v;
2784
2785    ELM_CHECK_WIDTYPE(obj, widtype);
2786    Widget_Data *wd = elm_widget_data_get(obj);
2787    if (!wd) return;
2788    elm_smart_scroller_paging_get(wd->scr, &pagerel_h, &pagerel_v, NULL, NULL);
2789    elm_smart_scroller_paging_set(wd->scr, pagerel_h, pagerel_v, h_pagesize,
2790                                  v_pagesize);
2791 }
2792
2793 /**
2794  * Get the first item in the gengrid
2795  *
2796  * This returns the first item in the list.
2797  *
2798  * @param obj The gengrid object
2799  * @return The first item, or NULL if none
2800  *
2801  * @ingroup Gengrid
2802  */
2803 EAPI Elm_Gengrid_Item *
2804 elm_gengrid_first_item_get(const Evas_Object *obj)
2805 {
2806    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2807    Widget_Data *wd = elm_widget_data_get(obj);
2808    if (!wd) return NULL;
2809    if (!wd->items) return NULL;
2810    Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
2811    while ((item) && (item->delete_me))
2812      item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
2813    return item;
2814 }
2815
2816 /**
2817  * Get the last item in the gengrid
2818  *
2819  * This returns the last item in the list.
2820  *
2821  * @return The last item, or NULL if none
2822  *
2823  * @ingroup Gengrid
2824  */
2825 EAPI Elm_Gengrid_Item *
2826 elm_gengrid_last_item_get(const Evas_Object *obj)
2827 {
2828    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2829    Widget_Data *wd = elm_widget_data_get(obj);
2830    if (!wd) return NULL;
2831    if (!wd->items) return NULL;
2832    Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
2833    while ((item) && (item->delete_me))
2834      item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
2835    return item;
2836 }
2837
2838 /**
2839  * Get the next item in the gengrid
2840  *
2841  * This returns the item after the item @p item.
2842  *
2843  * @param item The item
2844  * @return The item after @p item, or NULL if none
2845  *
2846  * @ingroup Gengrid
2847  */
2848 EAPI Elm_Gengrid_Item *
2849 elm_gengrid_item_next_get(const Elm_Gengrid_Item *item)
2850 {
2851    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2852    while (item)
2853      {
2854         item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
2855         if ((item) && (!item->delete_me)) break;
2856      }
2857    return (Elm_Gengrid_Item *)item;
2858 }
2859
2860 /**
2861  * Get the previous item in the gengrid
2862  *
2863  * This returns the item before the item @p item.
2864  *
2865  * @param item The item
2866  * @return The item before @p item, or NULL if none
2867  *
2868  * @ingroup Gengrid
2869  */
2870 EAPI Elm_Gengrid_Item *
2871 elm_gengrid_item_prev_get(const Elm_Gengrid_Item *item)
2872 {
2873    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2874    while (item)
2875      {
2876         item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
2877         if ((item) && (!item->delete_me)) break;
2878      }
2879    return (Elm_Gengrid_Item *)item;
2880 }
2881
2882 /**
2883  * Get the gengrid object from an item
2884  *
2885  * This returns the gengrid object itself that an item belongs to.
2886  *
2887  * @param item The item
2888  * @return The gengrid object
2889  *
2890  * @ingroup Gengrid
2891  */
2892 EAPI Evas_Object *
2893 elm_gengrid_item_gengrid_get(const Elm_Gengrid_Item *item)
2894 {
2895    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2896    return item->base.widget;
2897 }
2898
2899 /**
2900  * Show the given item
2901  *
2902  * This causes gengrid to jump to the given item @p item and show it
2903  * (by scrolling), if it is not fully visible.
2904  *
2905  * @param item The item
2906  *
2907  * @ingroup Gengrid
2908  */
2909 EAPI void
2910 elm_gengrid_item_show(Elm_Gengrid_Item *item)
2911 {
2912    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2913    Widget_Data *wd = elm_widget_data_get(item->wd->self);
2914    Evas_Coord minx = 0, miny = 0;
2915
2916    if (!wd) return;
2917    if ((!item) || (item->delete_me)) return;
2918    _pan_min_get(wd->pan_smart, &minx, &miny);
2919
2920    elm_smart_scroller_child_region_show(item->wd->scr,
2921                                         item->x * wd->item_width + minx,
2922                                         item->y * wd->item_height + miny,
2923                                         item->wd->item_width,
2924                                         item->wd->item_height);
2925 }
2926
2927 /**
2928  * Bring in the given item
2929  *
2930  * This causes gengrig to jump to the given item @p item and show it
2931  * (by scrolling), if it is not fully visible. This may use animation
2932  * to do so and take a period of time
2933  *
2934  * @param item The item
2935  *
2936  * @ingroup Gengrid
2937  */
2938 EAPI void
2939 elm_gengrid_item_bring_in(Elm_Gengrid_Item *item)
2940 {
2941    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2942    if (item->delete_me) return;
2943
2944    Evas_Coord minx = 0, miny = 0;
2945    Widget_Data *wd = elm_widget_data_get(item->wd->self);
2946    if (!wd) return;
2947    _pan_min_get(wd->pan_smart, &minx, &miny);
2948
2949    elm_smart_scroller_region_bring_in(item->wd->scr,
2950                                       item->x * wd->item_width + minx,
2951                                       item->y * wd->item_height + miny,
2952                                       item->wd->item_width,
2953                                       item->wd->item_height);
2954 }