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