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