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