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