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