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