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