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