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