elementary: use sorted state to improve gengrid and genlist.
[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  * TODO:
7  * Handle non-homogeneous objects too.
8  */
9
10  typedef struct _Widget_Data Widget_Data;
11  typedef struct _Pan         Pan;
12
13 #define PRELOAD 1
14 #define REORDER_EFFECT_TIME 0.5
15
16  struct _Elm_Gengrid_Item
17 {
18    Elm_Widget_Item               base;
19    EINA_INLIST;
20    Evas_Object                  *spacer;
21    const Elm_Gengrid_Item_Class *gic;
22    Ecore_Timer                  *long_timer;
23    Ecore_Animator               *item_moving_effect_timer;
24    Widget_Data                  *wd;
25    Eina_List                    *labels, *icons, *states, *icon_objs;
26    struct
27      {
28         Evas_Smart_Cb func;
29         const void   *data;
30      } func;
31
32    Evas_Coord   x, y, dx, dy, ox, oy, tx, ty, rx, ry;
33    unsigned int moving_effect_start_time;
34    int          relcount;
35    int          walking;
36
37    struct
38      {
39         const void                 *data;
40         Elm_Tooltip_Item_Content_Cb content_cb;
41         Evas_Smart_Cb               del_cb;
42         const char                 *style;
43         Eina_Bool                   free_size : 1;
44      } tooltip;
45
46    const char *mouse_cursor;
47
48    Eina_Bool   want_unrealize : 1;
49    Eina_Bool   realized : 1;
50    Eina_Bool   dragging : 1;
51    Eina_Bool   down : 1;
52    Eina_Bool   delete_me : 1;
53    Eina_Bool   display_only : 1;
54    Eina_Bool   disabled : 1;
55    Eina_Bool   selected : 1;
56    Eina_Bool   highlighted : 1;
57    Eina_Bool   moving : 1;
58 };
59
60 struct _Widget_Data
61 {
62    Eina_Inlist_Sorted_State *state;
63    Evas_Object      *self, *scr;
64    Evas_Object      *pan_smart;
65    Pan              *pan;
66    Eina_Inlist      *items;
67    Ecore_Job        *calc_job;
68    Eina_List        *selected;
69    Elm_Gengrid_Item *last_selected_item, *reorder_item;
70    double            align_x, align_y;
71
72    Evas_Coord        pan_x, pan_y, old_pan_x, old_pan_y;
73    Evas_Coord        item_width, item_height; /* Each item size */
74    Evas_Coord        minw, minh; /* Total obj size */
75    Evas_Coord        reorder_item_x, reorder_item_y;
76    unsigned int      nmax;
77    long              count;
78    int               walking;
79
80    Eina_Bool         horizontal : 1;
81    Eina_Bool         on_hold : 1;
82    Eina_Bool         longpressed : 1;
83    Eina_Bool         multi : 1;
84    Eina_Bool         no_select : 1;
85    Eina_Bool         wasselected : 1;
86    Eina_Bool         always_select : 1;
87    Eina_Bool         clear_me : 1;
88    Eina_Bool         h_bounce : 1;
89    Eina_Bool         v_bounce : 1;
90    Eina_Bool         reorder_mode : 1;
91    Eina_Bool         reorder_item_changed : 1;
92    Eina_Bool         move_effect_enabled : 1;
93 };
94
95 #define ELM_GENGRID_ITEM_FROM_INLIST(item) \
96    ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Gengrid_Item) : NULL)
97
98 struct _Pan
99 {
100    Evas_Object_Smart_Clipped_Data __clipped_data;
101    Widget_Data                   *wd;
102 };
103
104 static const char *widtype = NULL;
105 static void      _item_highlight(Elm_Gengrid_Item *item);
106 static void      _item_unrealize(Elm_Gengrid_Item *item);
107 static void      _item_select(Elm_Gengrid_Item *item);
108 static void      _item_unselect(Elm_Gengrid_Item *item);
109 static void      _calc_job(void *data);
110 static void      _on_focus_hook(void        *data,
111                                 Evas_Object *obj);
112 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
113 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
114 static Eina_Bool _item_multi_select_left(Widget_Data *wd);
115 static Eina_Bool _item_multi_select_right(Widget_Data *wd);
116 static Eina_Bool _item_single_select_up(Widget_Data *wd);
117 static Eina_Bool _item_single_select_down(Widget_Data *wd);
118 static Eina_Bool _item_single_select_left(Widget_Data *wd);
119 static Eina_Bool _item_single_select_right(Widget_Data *wd);
120 static Eina_Bool _event_hook(Evas_Object       *obj,
121                              Evas_Object       *src,
122                              Evas_Callback_Type type,
123                              void              *event_info);
124 static Eina_Bool _deselect_all_items(Widget_Data *wd);
125
126 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
127 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
128
129 static const char SIG_ACTIVATED[] = "activated";
130 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
131 static const char SIG_SELECTED[] = "selected";
132 static const char SIG_UNSELECTED[] = "unselected";
133 static const char SIG_REALIZED[] = "realized";
134 static const char SIG_UNREALIZED[] = "unrealized";
135 static const char SIG_CHANGED[] = "changed";
136 static const char SIG_DRAG_START_UP[] = "drag,start,up";
137 static const char SIG_DRAG_START_DOWN[] = "drag,start,down";
138 static const char SIG_DRAG_START_LEFT[] = "drag,start,left";
139 static const char SIG_DRAG_START_RIGHT[] = "drag,start,right";
140 static const char SIG_DRAG_STOP[] = "drag,stop";
141 static const char SIG_DRAG[] = "drag";
142 static const char SIG_SCROLL[] = "scroll";
143 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
144 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
145 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
146 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
147 static const char SIG_MOVED[] = "moved";
148
149 static const Evas_Smart_Cb_Description _signals[] = {
150    {SIG_ACTIVATED, ""},
151    {SIG_CLICKED_DOUBLE, ""},
152    {SIG_SELECTED, ""},
153    {SIG_UNSELECTED, ""},
154    {SIG_REALIZED, ""},
155    {SIG_UNREALIZED, ""},
156    {SIG_CHANGED, ""},
157    {SIG_DRAG_START_UP, ""},
158    {SIG_DRAG_START_DOWN, ""},
159    {SIG_DRAG_START_LEFT, ""},
160    {SIG_DRAG_START_RIGHT, ""},
161    {SIG_DRAG_STOP, ""},
162    {SIG_DRAG, ""},
163    {SIG_SCROLL, ""},
164    {SIG_SCROLL_ANIM_START, ""},
165    {SIG_SCROLL_ANIM_STOP, ""},
166    {SIG_SCROLL_DRAG_START, ""},
167    {SIG_SCROLL_DRAG_STOP, ""},
168    {SIG_MOVED, ""},
169    {NULL, NULL}
170 };
171
172 static Eina_Compare_Cb _elm_gengrid_item_compare_cb;
173 static Eina_Compare_Cb _elm_gengrid_item_compare_data_cb;
174
175 static Eina_Bool
176 _event_hook(Evas_Object       *obj,
177             Evas_Object *src   __UNUSED__,
178             Evas_Callback_Type type,
179             void              *event_info)
180 {
181    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
182    Evas_Event_Key_Down *ev = event_info;
183    Widget_Data *wd = elm_widget_data_get(obj);
184    if (!wd) return EINA_FALSE;
185    if (!wd->items) return EINA_FALSE;
186    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
187    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
188
189    Elm_Gengrid_Item *item = NULL;
190    Evas_Coord x = 0;
191    Evas_Coord y = 0;
192    Evas_Coord step_x = 0;
193    Evas_Coord step_y = 0;
194    Evas_Coord v_w = 0;
195    Evas_Coord v_h = 0;
196    Evas_Coord page_x = 0;
197    Evas_Coord page_y = 0;
198
199    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
200    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
201    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
202    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
203
204    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
205      {
206         if ((wd->horizontal) &&
207             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
208               (_item_multi_select_up(wd)))
209              || (_item_single_select_up(wd))))
210           {
211              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
212              return EINA_TRUE;
213           }
214         else if ((!wd->horizontal) &&
215                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
216                    (_item_multi_select_left(wd)))
217                   || (_item_single_select_left(wd))))
218           {
219              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
220              return EINA_TRUE;
221           }
222         else
223           x -= step_x;
224      }
225    else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
226      {
227         if ((wd->horizontal) &&
228             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
229               (_item_multi_select_down(wd)))
230              || (_item_single_select_down(wd))))
231           {
232              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
233              return EINA_TRUE;
234           }
235         else if ((!wd->horizontal) &&
236                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
237                    (_item_multi_select_right(wd)))
238                   || (_item_single_select_right(wd))))
239           {
240              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
241              return EINA_TRUE;
242           }
243         else
244           x += step_x;
245      }
246    else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
247      {
248         if ((wd->horizontal) &&
249             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
250               (_item_multi_select_left(wd)))
251              || (_item_single_select_left(wd))))
252           {
253              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
254              return EINA_TRUE;
255           }
256         else if ((!wd->horizontal) &&
257                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
258                    (_item_multi_select_up(wd)))
259                   || (_item_single_select_up(wd))))
260           {
261              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
262              return EINA_TRUE;
263           }
264         else
265           y -= step_y;
266      }
267    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
268      {
269         if ((wd->horizontal) &&
270             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
271               (_item_multi_select_right(wd)))
272              || (_item_single_select_right(wd))))
273           {
274              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
275              return EINA_TRUE;
276           }
277         else if ((!wd->horizontal) &&
278                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
279                    (_item_multi_select_down(wd)))
280                   || (_item_single_select_down(wd))))
281           {
282              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
283              return EINA_TRUE;
284           }
285         else
286           y += step_y;
287      }
288    else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
289      {
290         item = elm_gengrid_first_item_get(obj);
291         elm_gengrid_item_bring_in(item);
292         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
293         return EINA_TRUE;
294      }
295    else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
296      {
297         item = elm_gengrid_last_item_get(obj);
298         elm_gengrid_item_bring_in(item);
299         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
300         return EINA_TRUE;
301      }
302    else if ((!strcmp(ev->keyname, "Prior")) ||
303             (!strcmp(ev->keyname, "KP_Prior")))
304      {
305         if (wd->horizontal)
306           {
307              if (page_x < 0)
308                x -= -(page_x * v_w) / 100;
309              else
310                x -= page_x;
311           }
312         else
313           {
314              if (page_y < 0)
315                y -= -(page_y * v_h) / 100;
316              else
317                y -= page_y;
318           }
319      }
320    else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
321      {
322         if (wd->horizontal)
323           {
324              if (page_x < 0)
325                x += -(page_x * v_w) / 100;
326              else
327                x += page_x;
328           }
329         else
330           {
331              if (page_y < 0)
332                y += -(page_y * v_h) / 100;
333              else
334                y += page_y;
335           }
336      }
337    else if (!strcmp(ev->keyname, "Escape"))
338      {
339         if (!_deselect_all_items(wd)) return EINA_FALSE;
340         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
341         return EINA_TRUE;
342      }
343    else if ((!strcmp(ev->keyname, "Return")) ||
344             (!strcmp(ev->keyname, "KP_Enter")) ||
345             (!strcmp(ev->keyname, "space")))
346      {
347         item = elm_gengrid_selected_item_get(obj);
348         evas_object_smart_callback_call(item->wd->self, SIG_ACTIVATED, item);
349      }
350    else return EINA_FALSE;
351
352    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
353    elm_smart_scroller_child_pos_set(wd->scr, x, y);
354    return EINA_TRUE;
355 }
356
357 static Eina_Bool
358 _deselect_all_items(Widget_Data *wd)
359 {
360    if (!wd->selected) return EINA_FALSE;
361    while(wd->selected)
362      elm_gengrid_item_selected_set(wd->selected->data, EINA_FALSE);
363
364    return EINA_TRUE;
365 }
366
367 static Eina_Bool
368 _item_multi_select_left(Widget_Data *wd)
369 {
370    if (!wd->selected) return EINA_FALSE;
371
372    Elm_Gengrid_Item *prev = elm_gengrid_item_prev_get(wd->last_selected_item);
373    if (!prev) return EINA_TRUE;
374    if (elm_gengrid_item_selected_get(prev))
375      {
376         elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
377         wd->last_selected_item = prev;
378         elm_gengrid_item_show(wd->last_selected_item);
379      }
380    else
381      {
382         elm_gengrid_item_selected_set(prev, EINA_TRUE);
383         elm_gengrid_item_show(prev);
384      }
385
386    return EINA_TRUE;
387 }
388
389 static Eina_Bool
390 _item_multi_select_right(Widget_Data *wd)
391 {
392    if (!wd->selected) return EINA_FALSE;
393
394    Elm_Gengrid_Item *next = elm_gengrid_item_next_get(wd->last_selected_item);
395    if (!next) return EINA_TRUE;
396    if (elm_gengrid_item_selected_get(next))
397      {
398         elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
399         wd->last_selected_item = next;
400         elm_gengrid_item_show(wd->last_selected_item);
401      }
402    else
403      {
404         elm_gengrid_item_selected_set(next, EINA_TRUE);
405         elm_gengrid_item_show(next);
406      }
407
408    return EINA_TRUE;
409 }
410
411 static Eina_Bool
412 _item_multi_select_up(Widget_Data *wd)
413 {
414    unsigned int i;
415    Eina_Bool r = EINA_TRUE;
416
417    if (!wd->selected) return EINA_FALSE;
418
419    for (i = 0; (r) && (i < wd->nmax); i++)
420      r &= _item_multi_select_left(wd);
421
422    return r;
423 }
424
425 static Eina_Bool
426 _item_multi_select_down(Widget_Data *wd)
427 {
428    unsigned int i;
429    Eina_Bool r = EINA_TRUE;
430
431    if (!wd->selected) return EINA_FALSE;
432
433    for (i = 0; (r) && (i < wd->nmax); i++)
434      r &= _item_multi_select_right(wd);
435
436    return r;
437 }
438
439 static Eina_Bool
440 _item_single_select_up(Widget_Data *wd)
441 {
442    unsigned int i;
443
444    Elm_Gengrid_Item *prev;
445
446    if (!wd->selected)
447      {
448         prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
449         while ((prev) && (prev->delete_me))
450           prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
451         elm_gengrid_item_selected_set(prev, EINA_TRUE);
452         elm_gengrid_item_show(prev);
453         return EINA_TRUE;
454      }
455    else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
456
457    if (!prev) return EINA_FALSE;
458
459    for (i = 1; i < wd->nmax; i++)
460      {
461         Elm_Gengrid_Item *tmp = elm_gengrid_item_prev_get(prev);
462         if (!tmp) return EINA_FALSE;
463         prev = tmp;
464      }
465
466    _deselect_all_items(wd);
467
468    elm_gengrid_item_selected_set(prev, EINA_TRUE);
469    elm_gengrid_item_show(prev);
470    return EINA_TRUE;
471 }
472
473 static Eina_Bool
474 _item_single_select_down(Widget_Data *wd)
475 {
476    unsigned int i;
477
478    Elm_Gengrid_Item *next;
479
480    if (!wd->selected)
481      {
482         next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
483         while ((next) && (next->delete_me))
484           next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
485         elm_gengrid_item_selected_set(next, EINA_TRUE);
486         elm_gengrid_item_show(next);
487         return EINA_TRUE;
488      }
489    else next = elm_gengrid_item_next_get(wd->last_selected_item);
490
491    if (!next) return EINA_FALSE;
492
493    for (i = 1; i < wd->nmax; i++)
494      {
495         Elm_Gengrid_Item *tmp = elm_gengrid_item_next_get(next);
496         if (!tmp) return EINA_FALSE;
497         next = tmp;
498      }
499
500    _deselect_all_items(wd);
501
502    elm_gengrid_item_selected_set(next, EINA_TRUE);
503    elm_gengrid_item_show(next);
504    return EINA_TRUE;
505 }
506
507 static Eina_Bool
508 _item_single_select_left(Widget_Data *wd)
509 {
510    Elm_Gengrid_Item *prev;
511    if (!wd->selected)
512      {
513         prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
514         while ((prev) && (prev->delete_me))
515           prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
516      }
517    else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
518
519    if (!prev) return EINA_FALSE;
520
521    _deselect_all_items(wd);
522
523    elm_gengrid_item_selected_set(prev, EINA_TRUE);
524    elm_gengrid_item_show(prev);
525    return EINA_TRUE;
526 }
527
528 static Eina_Bool
529 _item_single_select_right(Widget_Data *wd)
530 {
531    Elm_Gengrid_Item *next;
532    if (!wd->selected)
533      {
534         next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
535         while ((next) && (next->delete_me))
536           next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
537      }
538    else next = elm_gengrid_item_next_get(wd->last_selected_item);
539
540    if (!next) return EINA_FALSE;
541
542    _deselect_all_items(wd);
543
544    elm_gengrid_item_selected_set(next, EINA_TRUE);
545    elm_gengrid_item_show(next);
546    return EINA_TRUE;
547 }
548
549 static void
550 _on_focus_hook(void *data   __UNUSED__,
551                Evas_Object *obj)
552 {
553    Widget_Data *wd = elm_widget_data_get(obj);
554    if (!wd) return;
555    if (elm_widget_focus_get(obj))
556      {
557         edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
558         evas_object_focus_set(wd->self, EINA_TRUE);
559         if ((wd->selected) && (!wd->last_selected_item))
560           wd->last_selected_item = eina_list_data_get(wd->selected);
561      }
562    else
563      {
564         edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
565         evas_object_focus_set(wd->self, EINA_FALSE);
566      }
567 }
568
569 static void
570 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
571 {
572    Widget_Data *wd = elm_widget_data_get(obj);
573    Elm_Gengrid_Item *item;
574    if (!wd) return;
575    elm_smart_scroller_mirrored_set(wd->scr, rtl);
576    if (!wd->items) return;
577    item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
578
579    while (item)
580      {
581         edje_object_mirrored_set(item->base.view, rtl);
582         elm_gengrid_item_update(item);
583         item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
584      }
585 }
586
587 static void
588 _theme_hook(Evas_Object *obj)
589 {
590    Widget_Data *wd = elm_widget_data_get(obj);
591    if (!wd) return;
592    _elm_widget_mirrored_reload(obj);
593    _mirrored_set(obj, elm_widget_mirrored_get(obj));
594    elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
595                                        elm_widget_style_get(obj));
596 }
597
598 static void
599 _del_pre_hook(Evas_Object *obj)
600 {
601    Widget_Data *wd = elm_widget_data_get(obj);
602    if (!wd) return;
603    elm_gengrid_clear(obj);
604    evas_object_del(wd->pan_smart);
605    wd->pan_smart = NULL;
606 }
607
608 static void
609 _del_hook(Evas_Object *obj)
610 {
611    Widget_Data *wd = elm_widget_data_get(obj);
612    free(wd);
613 }
614
615 static void
616 _signal_emit_hook(Evas_Object *obj,
617                   const char  *emission,
618                   const char  *source)
619 {
620    Widget_Data *wd = elm_widget_data_get(obj);
621    if (!wd) return;
622    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
623                            emission, source);
624 }
625
626 static void
627 _mouse_move(void        *data,
628             Evas *evas   __UNUSED__,
629             Evas_Object *obj,
630             void        *event_info)
631 {
632    Elm_Gengrid_Item *item = data;
633    Evas_Event_Mouse_Move *ev = event_info;
634    Evas_Coord minw = 0, minh = 0, x, y, dx, dy, adx, ady;
635    Evas_Coord ox, oy, ow, oh, it_scrl_x, it_scrl_y;
636
637    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
638      {
639         if (!item->wd->on_hold)
640           {
641              item->wd->on_hold = EINA_TRUE;
642              if (!item->wd->wasselected)
643                _item_unselect(item);
644           }
645      }
646    if ((item->dragging) && (item->down))
647      {
648         if (item->long_timer)
649           {
650              ecore_timer_del(item->long_timer);
651              item->long_timer = NULL;
652           }
653         evas_object_smart_callback_call(item->wd->self, SIG_DRAG, item);
654         return;
655      }
656    if ((!item->down) || (item->wd->longpressed))
657      {
658         if (item->long_timer)
659           {
660              ecore_timer_del(item->long_timer);
661              item->long_timer = NULL;
662           }
663         if ((item->wd->reorder_mode) && (item->wd->reorder_item))
664           {
665              evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &ow, &oh);
666
667              it_scrl_x = ev->cur.canvas.x - item->wd->reorder_item->dx;
668              it_scrl_y = ev->cur.canvas.y - item->wd->reorder_item->dy;
669
670              if (it_scrl_x < ox) item->wd->reorder_item_x = ox;
671              else if (it_scrl_x + item->wd->item_width > ox + ow)
672                item->wd->reorder_item_x = ox + ow - item->wd->item_width;
673              else item->wd->reorder_item_x = it_scrl_x;
674
675              if (it_scrl_y < oy) item->wd->reorder_item_y = oy;
676              else if (it_scrl_y + item->wd->item_height > oy + oh)
677                item->wd->reorder_item_y = oy + oh - item->wd->item_height;
678              else item->wd->reorder_item_y = it_scrl_y;
679
680              if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
681              item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
682           }
683         return;
684      }
685    if (!item->display_only)
686      elm_coords_finger_size_adjust(1, &minw, 1, &minh);
687    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
688    x = ev->cur.canvas.x - x;
689    y = ev->cur.canvas.y - y;
690    dx = x - item->dx;
691    adx = dx;
692    if (adx < 0) adx = -dx;
693    dy = y - item->dy;
694    ady = dy;
695    if (ady < 0) ady = -dy;
696    minw /= 2;
697    minh /= 2;
698    if ((adx > minw) || (ady > minh))
699      {
700         const char *left_drag, *right_drag;
701         if (!elm_widget_mirrored_get(item->wd->self))
702           {
703              left_drag = SIG_DRAG_START_LEFT;
704              right_drag = SIG_DRAG_START_RIGHT;
705           }
706         else
707           {
708              left_drag = SIG_DRAG_START_RIGHT;
709              right_drag = SIG_DRAG_START_LEFT;
710           }
711
712         item->dragging = 1;
713         if (item->long_timer)
714           {
715              ecore_timer_del(item->long_timer);
716              item->long_timer = NULL;
717           }
718         if (!item->wd->wasselected)
719           _item_unselect(item);
720         if (dy < 0)
721           {
722              if (ady > adx)
723                evas_object_smart_callback_call(item->wd->self, SIG_DRAG_START_UP,
724                                                item);
725              else
726                {
727                   if (dx < 0)
728                     evas_object_smart_callback_call(item->wd->self,
729                                                     left_drag, item);
730                }
731           }
732         else
733           {
734              if (ady > adx)
735                evas_object_smart_callback_call(item->wd->self,
736                                                SIG_DRAG_START_DOWN, item);
737              else
738                {
739                   if (dx < 0)
740                     evas_object_smart_callback_call(item->wd->self,
741                                                     left_drag, item);
742                   else
743                     evas_object_smart_callback_call(item->wd->self,
744                                                     right_drag, item);
745                }
746           }
747      }
748 }
749
750 static Eina_Bool
751 _long_press(void *data)
752 {
753    Elm_Gengrid_Item *item = data;
754
755    item->long_timer = NULL;
756    if ((item->disabled) || (item->dragging)) return ECORE_CALLBACK_CANCEL;
757    item->wd->longpressed = EINA_TRUE;
758    evas_object_smart_callback_call(item->wd->self, "longpressed", item);
759    if (item->wd->reorder_mode)
760      {
761         item->wd->reorder_item = item;
762         evas_object_raise(item->base.view);
763         elm_smart_scroller_hold_set(item->wd->scr, EINA_TRUE);
764         elm_smart_scroller_bounce_allow_set(item->wd->scr, EINA_FALSE, EINA_FALSE);
765         edje_object_signal_emit(item->base.view, "elm,state,reorder,enabled", "elm");
766      }
767    return ECORE_CALLBACK_CANCEL;
768 }
769
770 static void
771 _mouse_down(void        *data,
772             Evas *evas   __UNUSED__,
773             Evas_Object *obj,
774             void        *event_info)
775 {
776    Elm_Gengrid_Item *item = data;
777    Evas_Event_Mouse_Down *ev = event_info;
778    Evas_Coord x, y;
779
780    if (ev->button != 1) return;
781    item->down = 1;
782    item->dragging = 0;
783    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
784    item->dx = ev->canvas.x - x;
785    item->dy = ev->canvas.y - y;
786    item->wd->longpressed = EINA_FALSE;
787    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
788    else item->wd->on_hold = EINA_FALSE;
789    item->wd->wasselected = item->selected;
790    _item_highlight(item);
791    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
792      {
793         evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
794         evas_object_smart_callback_call(item->wd->self, SIG_ACTIVATED, item);
795      }
796    if (item->long_timer) ecore_timer_del(item->long_timer);
797    if (item->realized)
798      item->long_timer = ecore_timer_add(_elm_config->longpress_timeout,
799                                         _long_press, item);
800    else
801      item->long_timer = NULL;
802 }
803
804 static void
805 _mouse_up(void            *data,
806           Evas *evas       __UNUSED__,
807           Evas_Object *obj __UNUSED__,
808           void            *event_info)
809 {
810    Elm_Gengrid_Item *item = data;
811    Evas_Event_Mouse_Up *ev = event_info;
812    Eina_Bool dragged = EINA_FALSE;
813
814    if (ev->button != 1) return;
815    item->down = EINA_FALSE;
816    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
817    else item->wd->on_hold = EINA_FALSE;
818    if (item->long_timer)
819      {
820         ecore_timer_del(item->long_timer);
821         item->long_timer = NULL;
822      }
823    if (item->dragging)
824      {
825         item->dragging = EINA_FALSE;
826         evas_object_smart_callback_call(item->wd->self, SIG_DRAG_STOP, item);
827         dragged = EINA_TRUE;
828      }
829    if (item->wd->on_hold)
830      {
831         item->wd->longpressed = EINA_FALSE;
832         item->wd->on_hold = EINA_FALSE;
833         return;
834      }
835    if ((item->wd->reorder_mode) && (item->wd->reorder_item))
836      {
837         if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
838           item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
839
840         evas_object_smart_callback_call(item->wd->self, SIG_MOVED, item->wd->reorder_item);
841         item->wd->reorder_item = NULL;
842         elm_smart_scroller_hold_set(item->wd->scr, EINA_FALSE);
843         elm_smart_scroller_bounce_allow_set(item->wd->scr, item->wd->h_bounce, item->wd->v_bounce);
844         edje_object_signal_emit(item->base.view, "elm,state,reorder,disabled", "elm");
845      }
846    if (item->wd->longpressed)
847      {
848         item->wd->longpressed = EINA_FALSE;
849         if (!item->wd->wasselected) _item_unselect(item);
850         item->wd->wasselected = EINA_FALSE;
851         return;
852      }
853    if (dragged)
854      {
855         if (item->want_unrealize) _item_unrealize(item);
856      }
857    if ((item->disabled) || (dragged)) return;
858    if (item->wd->multi)
859      {
860         if (!item->selected)
861           {
862              _item_highlight(item);
863              _item_select(item);
864           }
865         else _item_unselect(item);
866      }
867    else
868      {
869         if (!item->selected)
870           {
871              while (item->wd->selected)
872                _item_unselect(item->wd->selected->data);
873           }
874         else
875           {
876              const Eina_List *l, *l_next;
877              Elm_Gengrid_Item *item2;
878
879              EINA_LIST_FOREACH_SAFE(item->wd->selected, l, l_next, item2)
880                 if (item2 != item) _item_unselect(item2);
881           }
882         _item_highlight(item);
883         _item_select(item);
884      }
885 }
886
887 static void
888 _item_highlight(Elm_Gengrid_Item *item)
889 {
890    if ((item->wd->no_select) || (item->delete_me) || (item->highlighted)) return;
891    edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
892    item->highlighted = EINA_TRUE;
893 }
894
895 static void
896 _item_realize(Elm_Gengrid_Item *item)
897 {
898    char buf[1024];
899    char style[1024];
900
901    if ((item->realized) || (item->delete_me)) return;
902    item->base.view = edje_object_add(evas_object_evas_get(item->wd->self));
903    edje_object_scale_set(item->base.view, elm_widget_scale_get(item->wd->self) *
904                          _elm_config->scale);
905    edje_object_mirrored_set(item->base.view, elm_widget_mirrored_get(item->base.widget));
906    evas_object_smart_member_add(item->base.view, item->wd->pan_smart);
907    elm_widget_sub_object_add(item->wd->self, item->base.view);
908    snprintf(style, sizeof(style), "item/%s",
909             item->gic->item_style ? item->gic->item_style : "default");
910    _elm_theme_object_set(item->wd->self, item->base.view, "gengrid", style,
911                          elm_widget_style_get(item->wd->self));
912    item->spacer =
913       evas_object_rectangle_add(evas_object_evas_get(item->wd->self));
914    evas_object_color_set(item->spacer, 0, 0, 0, 0);
915    elm_widget_sub_object_add(item->wd->self, item->spacer);
916    evas_object_size_hint_min_set(item->spacer, 2 * _elm_config->scale, 1);
917    edje_object_part_swallow(item->base.view, "elm.swallow.pad", item->spacer);
918
919    if (item->gic->func.label_get)
920      {
921         const Eina_List *l;
922         const char *key;
923
924         item->labels =
925            elm_widget_stringlist_get(edje_object_data_get(item->base.view,
926                                                           "labels"));
927         EINA_LIST_FOREACH(item->labels, l, key)
928           {
929              char *s = item->gic->func.label_get
930                 ((void *)item->base.data, item->wd->self, l->data);
931              if (s)
932                {
933                   edje_object_part_text_set(item->base.view, l->data, s);
934                   free(s);
935                }
936           }
937      }
938
939    if (item->gic->func.icon_get)
940      {
941         const Eina_List *l;
942         const char *key;
943
944         item->icons =
945            elm_widget_stringlist_get(edje_object_data_get(item->base.view,
946                                                           "icons"));
947         EINA_LIST_FOREACH(item->icons, l, key)
948           {
949              Evas_Object *ic = item->gic->func.icon_get
950                 ((void *)item->base.data, item->wd->self, l->data);
951              if (ic)
952                {
953                   item->icon_objs = eina_list_append(item->icon_objs, ic);
954                   edje_object_part_swallow(item->base.view, key, ic);
955                   evas_object_show(ic);
956                   elm_widget_sub_object_add(item->wd->self, ic);
957                }
958           }
959      }
960
961    if (item->gic->func.state_get)
962      {
963         const Eina_List *l;
964         const char *key;
965
966         item->states =
967            elm_widget_stringlist_get(edje_object_data_get(item->base.view,
968                                                           "states"));
969         EINA_LIST_FOREACH(item->states, l, key)
970           {
971              Eina_Bool on = item->gic->func.state_get
972                 ((void *)item->base.data, item->wd->self, l->data);
973              if (on)
974                {
975                   snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
976                   edje_object_signal_emit(item->base.view, buf, "elm");
977                }
978           }
979      }
980
981    if ((!item->wd->item_width) && (!item->wd->item_height))
982      {
983         edje_object_size_min_restricted_calc(item->base.view,
984                                              &item->wd->item_width,
985                                              &item->wd->item_height,
986                                              item->wd->item_width,
987                                              item->wd->item_height);
988         elm_coords_finger_size_adjust(1, &item->wd->item_width,
989                                       1, &item->wd->item_height);
990      }
991
992    evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_DOWN,
993                                   _mouse_down, item);
994    evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_UP,
995                                   _mouse_up, item);
996    evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_MOVE,
997                                   _mouse_move, item);
998
999    if (item->selected)
1000      edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
1001    if (item->disabled)
1002      edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1003
1004    evas_object_show(item->base.view);
1005
1006    if (item->tooltip.content_cb)
1007      {
1008         elm_widget_item_tooltip_content_cb_set(item,
1009                                                item->tooltip.content_cb,
1010                                                item->tooltip.data, NULL);
1011         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
1012         elm_widget_item_tooltip_size_restrict_disable(item, item->tooltip.free_size);
1013      }
1014
1015    if (item->mouse_cursor)
1016      elm_widget_item_cursor_set(item, item->mouse_cursor);
1017
1018    item->realized = EINA_TRUE;
1019    item->want_unrealize = EINA_FALSE;
1020 }
1021
1022 static void
1023 _item_unrealize(Elm_Gengrid_Item *item)
1024 {
1025    Evas_Object *icon;
1026
1027    if (!item->realized) return;
1028    if (item->long_timer)
1029      {
1030         ecore_timer_del(item->long_timer);
1031         item->long_timer = NULL;
1032      }
1033    evas_object_del(item->base.view);
1034    item->base.view = NULL;
1035    evas_object_del(item->spacer);
1036    item->spacer = NULL;
1037    elm_widget_stringlist_free(item->labels);
1038    item->labels = NULL;
1039    elm_widget_stringlist_free(item->icons);
1040    item->icons = NULL;
1041    elm_widget_stringlist_free(item->states);
1042    item->states = NULL;
1043
1044    EINA_LIST_FREE(item->icon_objs, icon)
1045       evas_object_del(icon);
1046
1047    item->realized = EINA_FALSE;
1048    item->want_unrealize = EINA_FALSE;
1049 }
1050
1051 static Eina_Bool
1052 _reorder_item_moving_effect_timer_cb(void *data)
1053 {
1054    Elm_Gengrid_Item *item = data;
1055    double time, t;
1056    Evas_Coord dx, dy;
1057
1058    time = REORDER_EFFECT_TIME;
1059    t = ((0.0 > (t = ecore_loop_time_get()-item->moving_effect_start_time)) ? 0.0 : t);
1060    dx = ((item->tx - item->ox) / 10) * _elm_config->scale;
1061    dy = ((item->ty - item->oy) / 10) * _elm_config->scale;
1062
1063    if (t <= time)
1064      {
1065         item->rx += (1 * sin((t / time) * (M_PI / 2)) * dx);
1066         item->ry += (1 * sin((t / time) * (M_PI / 2)) * dy);
1067      }
1068    else
1069      {
1070         item->rx += dx;
1071         item->ry += dy;
1072      }
1073
1074    if ((((dx > 0) && (item->rx >= item->tx)) || ((dx <= 0) && (item->rx <= item->tx))) &&
1075        (((dy > 0) && (item->ry >= item->ty)) || ((dy <= 0) && (item->ry <= item->ty))))
1076      {
1077         evas_object_move(item->base.view, item->tx, item->ty);
1078         evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
1079         item->moving = EINA_FALSE;
1080         item->item_moving_effect_timer = NULL;
1081         return ECORE_CALLBACK_CANCEL;
1082      }
1083
1084    evas_object_move(item->base.view, item->rx, item->ry);
1085    evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
1086
1087    return ECORE_CALLBACK_RENEW;
1088 }
1089
1090 static void
1091 _item_place(Elm_Gengrid_Item *item,
1092             Evas_Coord        cx,
1093             Evas_Coord        cy)
1094 {
1095    Evas_Coord x, y, ox, oy, cvx, cvy, cvw, cvh;
1096    Evas_Coord tch, tcw, alignw = 0, alignh = 0, vw, vh;
1097    Eina_Bool reorder_item_move_forward = EINA_FALSE;
1098    item->x = cx;
1099    item->y = cy;
1100    evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &vw, &vh);
1101
1102    /* Preload rows/columns at each side of the Gengrid */
1103    cvx = ox - PRELOAD * item->wd->item_width;
1104    cvy = oy - PRELOAD * item->wd->item_height;
1105    cvw = vw + 2 * PRELOAD * item->wd->item_width;
1106    cvh = vh + 2 * PRELOAD * item->wd->item_height;
1107
1108    alignh = 0;
1109    alignw = 0;
1110
1111    if (item->wd->horizontal)
1112      {
1113         int columns, items_visible = 0, items_row;
1114
1115         if (item->wd->item_height > 0)
1116           items_visible = vh / item->wd->item_height;
1117         if (items_visible < 1)
1118           items_visible = 1;
1119
1120         columns = item->wd->count / items_visible;
1121         if (item->wd->count % items_visible)
1122           columns++;
1123
1124         tcw = item->wd->item_width * columns;
1125         alignw = (vw - tcw) * item->wd->align_x;
1126
1127         items_row = items_visible;
1128         if (items_row > item->wd->count)
1129           items_row = item->wd->count;
1130         tch = items_row * item->wd->item_height;
1131         alignh = (vh - tch) * item->wd->align_y;
1132      }
1133    else
1134      {
1135         int rows, items_visible = 0, items_col;
1136
1137         if (item->wd->item_width > 0)
1138           items_visible = vw / item->wd->item_width;
1139         if (items_visible < 1)
1140           items_visible = 1;
1141
1142         rows = item->wd->count / items_visible;
1143         if (item->wd->count % items_visible)
1144           rows++;
1145
1146         tch = item->wd->item_height * rows;
1147         alignh = (vh - tch) * item->wd->align_y;
1148
1149         items_col = items_visible;
1150         if (items_col > item->wd->count)
1151           items_col = item->wd->count;
1152         tcw = items_col * item->wd->item_width;
1153         alignw = (vw - tcw) * item->wd->align_x;
1154      }
1155
1156    x = cx * item->wd->item_width - item->wd->pan_x + ox + alignw;
1157    if (elm_widget_mirrored_get(item->wd->self))
1158      {  /* Switch items side and componsate for pan_x when in RTL mode */
1159         Evas_Coord ww;
1160         evas_object_geometry_get(item->wd->self, NULL, NULL, &ww, NULL);
1161         x = ww - x - item->wd->item_width - item->wd->pan_x - item->wd->pan_x;
1162      }
1163
1164    y = cy * item->wd->item_height - item->wd->pan_y + oy + alignh;
1165
1166    Eina_Bool was_realized = item->realized;
1167    if (ELM_RECTS_INTERSECT(x, y, item->wd->item_width, item->wd->item_height,
1168                            cvx, cvy, cvw, cvh))
1169      {
1170         _item_realize(item);
1171         if (!was_realized)
1172           evas_object_smart_callback_call(item->wd->self, SIG_REALIZED, item);
1173         if ((item->wd->reorder_mode) && (item->wd->reorder_item))
1174           {
1175              if (item->moving) return;
1176
1177              if (!item->wd->move_effect_enabled)
1178                {
1179                   item->ox = x;
1180                   item->oy = y;
1181                }
1182              if (item->wd->reorder_item == item)
1183                {
1184                   evas_object_move(item->base.view,
1185                                    item->wd->reorder_item_x, item->wd->reorder_item_y);
1186                   evas_object_resize(item->base.view,
1187                                      item->wd->item_width, item->wd->item_height);
1188                   return;
1189                }
1190              else
1191                {
1192                   if (item->wd->move_effect_enabled)
1193                     {
1194                        if ((item->ox != x) || (item->oy != y))
1195                          {
1196                             if (((item->wd->old_pan_x == item->wd->pan_x) && (item->wd->old_pan_y == item->wd->pan_y)) ||
1197                                 ((item->wd->old_pan_x != item->wd->pan_x) && !(item->ox - item->wd->pan_x + item->wd->old_pan_x == x)) ||
1198                                 ((item->wd->old_pan_y != item->wd->pan_y) && !(item->oy - item->wd->pan_y + item->wd->old_pan_y == y)))
1199                               {
1200                                  item->tx = x;
1201                                  item->ty = y;
1202                                  item->rx = item->ox;
1203                                  item->ry = item->oy;
1204                                  item->moving = EINA_TRUE;
1205                                  item->moving_effect_start_time = ecore_loop_time_get();
1206                                  item->item_moving_effect_timer = ecore_animator_add(_reorder_item_moving_effect_timer_cb, item);
1207                                  return;
1208                               }
1209                          }
1210                     }
1211
1212                   if (ELM_RECTS_INTERSECT(item->wd->reorder_item_x, item->wd->reorder_item_y,
1213                                           item->wd->item_width, item->wd->item_height,
1214                                           x+(item->wd->item_width/2), y+(item->wd->item_height/2),
1215                                           1, 1))
1216                     {
1217                        if (item->wd->horizontal)
1218                          {
1219                             if ((item->wd->nmax * item->wd->reorder_item->x + item->wd->reorder_item->y) >
1220                                 (item->wd->nmax * item->x + item->y))
1221                               reorder_item_move_forward = EINA_TRUE;
1222                          }
1223                        else
1224                          {
1225                             if ((item->wd->nmax * item->wd->reorder_item->y + item->wd->reorder_item->x) >
1226                                 (item->wd->nmax * item->y + item->x))
1227                               reorder_item_move_forward = EINA_TRUE;
1228                          }
1229
1230                        item->wd->items = eina_inlist_remove(item->wd->items,
1231                                                             EINA_INLIST_GET(item->wd->reorder_item));
1232                        if (reorder_item_move_forward)
1233                          item->wd->items = eina_inlist_prepend_relative(item->wd->items,
1234                                                                         EINA_INLIST_GET(item->wd->reorder_item),
1235                                                                         EINA_INLIST_GET(item));
1236                        else
1237                          item->wd->items = eina_inlist_append_relative(item->wd->items,
1238                                                                        EINA_INLIST_GET(item->wd->reorder_item),
1239                                                                        EINA_INLIST_GET(item));
1240
1241                        item->wd->reorder_item_changed = EINA_TRUE;
1242                        item->wd->move_effect_enabled = EINA_TRUE;
1243                        if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1244                          item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1245
1246                        return;
1247                     }
1248                }
1249           }
1250         evas_object_move(item->base.view, x, y);
1251         evas_object_resize(item->base.view, item->wd->item_width,
1252                            item->wd->item_height);
1253      }
1254    else
1255      {
1256         _item_unrealize(item);
1257         if (was_realized)
1258           evas_object_smart_callback_call(item->wd->self, SIG_UNREALIZED, item);
1259      }
1260 }
1261
1262 static const char *
1263 _item_label_hook(Elm_Gengrid_Item *it, const char *part)
1264 {
1265    if (!it->gic->func.label_get) return NULL;
1266    return edje_object_part_text_get(it->base.view, part);
1267 }
1268
1269 static Elm_Gengrid_Item *
1270 _item_create(Widget_Data                  *wd,
1271              const Elm_Gengrid_Item_Class *gic,
1272              const void                   *data,
1273              Evas_Smart_Cb                 func,
1274              const void                   *func_data)
1275 {
1276    Elm_Gengrid_Item *item;
1277
1278    item = elm_widget_item_new(wd->self, Elm_Gengrid_Item);
1279    if (!item) return NULL;
1280    wd->count++;
1281    item->wd = wd;
1282    item->gic = gic;
1283    item->base.data = data;
1284    item->func.func = func;
1285    item->func.data = func_data;
1286    item->mouse_cursor = NULL;
1287    elm_widget_item_text_get_hook_set(item, _item_label_hook);
1288    return item;
1289 }
1290
1291 static void
1292 _item_del(Elm_Gengrid_Item *item)
1293 {
1294    elm_widget_item_pre_notify_del(item);
1295    if (item->selected)
1296      item->wd->selected = eina_list_remove(item->wd->selected, item);
1297    if (item->realized) _item_unrealize(item);
1298    if ((!item->delete_me) && (item->gic->func.del))
1299      item->gic->func.del((void *)item->base.data, item->wd->self);
1300    item->delete_me = EINA_TRUE;
1301    item->wd->items = eina_inlist_remove(item->wd->items, EINA_INLIST_GET(item));
1302    if (item->long_timer) ecore_timer_del(item->long_timer);
1303    if (item->tooltip.del_cb)
1304      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
1305    item->wd->walking -= item->walking;
1306    item->wd->count--;
1307    if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1308    item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1309    elm_widget_item_del(item);
1310 }
1311
1312 static void
1313 _item_select(Elm_Gengrid_Item *item)
1314 {
1315    if ((item->wd->no_select) || (item->delete_me)) return;
1316    if (item->selected)
1317      {
1318         if (item->wd->always_select) goto call;
1319         return;
1320      }
1321    item->selected = EINA_TRUE;
1322    item->wd->selected = eina_list_append(item->wd->selected, item);
1323 call:
1324    item->walking++;
1325    item->wd->walking++;
1326    if (item->func.func)
1327      item->func.func((void *)item->func.data, item->wd->self, item);
1328    if (!item->delete_me)
1329      evas_object_smart_callback_call(item->wd->self, SIG_SELECTED, item);
1330    item->walking--;
1331    item->wd->walking--;
1332    item->wd->last_selected_item = item;
1333    if ((item->wd->clear_me) && (!item->wd->walking))
1334      elm_gengrid_clear(item->base.widget);
1335    else
1336      {
1337         if ((!item->walking) && (item->delete_me))
1338           if (!item->relcount) _item_del(item);
1339      }
1340 }
1341
1342 static void
1343 _item_unselect(Elm_Gengrid_Item *item)
1344 {
1345    if ((item->delete_me) || (!item->highlighted)) return;
1346    edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
1347    item->highlighted = EINA_FALSE;
1348    if (item->selected)
1349      {
1350         item->selected = EINA_FALSE;
1351         item->wd->selected = eina_list_remove(item->wd->selected, item);
1352         evas_object_smart_callback_call(item->wd->self, SIG_UNSELECTED, item);
1353      }
1354 }
1355
1356 static void
1357 _calc_job(void *data)
1358 {
1359    Widget_Data *wd = data;
1360    Evas_Coord minw = 0, minh = 0, nmax = 0, cvw, cvh;
1361    int count;
1362
1363    evas_object_geometry_get(wd->pan_smart, NULL, NULL, &cvw, &cvh);
1364    if ((cvw != 0) || (cvh != 0))
1365      {
1366         if ((wd->horizontal) && (wd->item_height > 0))
1367           nmax = cvh / wd->item_height;
1368         else if (wd->item_width > 0)
1369           nmax = cvw / wd->item_width;
1370
1371         if (nmax < 1)
1372           nmax = 1;
1373
1374         count = wd->count;
1375         if (wd->horizontal)
1376           {
1377              minw = ceil(count / (float)nmax) * wd->item_width;
1378              minh = nmax * wd->item_height;
1379           }
1380         else
1381           {
1382              minw = nmax * wd->item_width;
1383              minh = ceil(count / (float)nmax) * wd->item_height;
1384           }
1385
1386         if ((minw != wd->minw) || (minh != wd->minh))
1387           {
1388              wd->minh = minh;
1389              wd->minw = minw;
1390              evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1391           }
1392
1393         wd->nmax = nmax;
1394         evas_object_smart_changed(wd->pan_smart);
1395      }
1396    wd->calc_job = NULL;
1397 }
1398
1399 static void
1400 _pan_add(Evas_Object *obj)
1401 {
1402    Pan *sd;
1403    Evas_Object_Smart_Clipped_Data *cd;
1404
1405    _pan_sc.add(obj);
1406    cd = evas_object_smart_data_get(obj);
1407    sd = ELM_NEW(Pan);
1408    if (!sd) return;
1409    sd->__clipped_data = *cd;
1410    free(cd);
1411    evas_object_smart_data_set(obj, sd);
1412 }
1413
1414 static void
1415 _pan_del(Evas_Object *obj)
1416 {
1417    Pan *sd = evas_object_smart_data_get(obj);
1418
1419    if (!sd) return;
1420    _pan_sc.del(obj);
1421 }
1422
1423 static void
1424 _pan_set(Evas_Object *obj,
1425          Evas_Coord   x,
1426          Evas_Coord   y)
1427 {
1428    Pan *sd = evas_object_smart_data_get(obj);
1429    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1430    sd->wd->pan_x = x;
1431    sd->wd->pan_y = y;
1432    evas_object_smart_changed(obj);
1433 }
1434
1435 static void
1436 _pan_get(Evas_Object *obj,
1437          Evas_Coord  *x,
1438          Evas_Coord  *y)
1439 {
1440    Pan *sd = evas_object_smart_data_get(obj);
1441    if (x) *x = sd->wd->pan_x;
1442    if (y) *y = sd->wd->pan_y;
1443 }
1444
1445 static void
1446 _pan_child_size_get(Evas_Object *obj,
1447                     Evas_Coord  *w,
1448                     Evas_Coord  *h)
1449 {
1450    Pan *sd = evas_object_smart_data_get(obj);
1451    if (w) *w = sd->wd->minw;
1452    if (h) *h = sd->wd->minh;
1453 }
1454
1455 static void
1456 _pan_max_get(Evas_Object *obj,
1457              Evas_Coord  *x,
1458              Evas_Coord  *y)
1459 {
1460    Pan *sd = evas_object_smart_data_get(obj);
1461    Evas_Coord ow, oh;
1462
1463    if (!sd) return;
1464    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1465    if (x)
1466      *x = (ow < sd->wd->minw) ? sd->wd->minw - ow : 0;
1467    if (y)
1468      *y = (oh < sd->wd->minh) ? sd->wd->minh - oh : 0;
1469 }
1470
1471 static void
1472 _pan_min_get(Evas_Object *obj,
1473              Evas_Coord  *x,
1474              Evas_Coord  *y)
1475 {
1476    Pan *sd = evas_object_smart_data_get(obj);
1477    Evas_Coord mx, my;
1478
1479    if (!sd) return;
1480    _pan_max_get(obj, &mx, &my);
1481    if (x)
1482      *x = -mx * sd->wd->align_x;
1483    if (y)
1484      *y = -my * sd->wd->align_y;
1485 }
1486
1487 static void
1488 _pan_resize(Evas_Object *obj,
1489             Evas_Coord   w,
1490             Evas_Coord   h)
1491 {
1492    Pan *sd = evas_object_smart_data_get(obj);
1493    Evas_Coord ow, oh;
1494
1495    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1496    if ((ow == w) && (oh == h)) return;
1497    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1498    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1499 }
1500
1501 static void
1502 _pan_calculate(Evas_Object *obj)
1503 {
1504    Pan *sd = evas_object_smart_data_get(obj);
1505    Evas_Coord cx = 0, cy = 0;
1506    Elm_Gengrid_Item *item;
1507
1508    if (!sd) return;
1509    if (!sd->wd->nmax) return;
1510
1511    sd->wd->reorder_item_changed = EINA_FALSE;
1512
1513    EINA_INLIST_FOREACH(sd->wd->items, item)
1514      {
1515         _item_place(item, cx, cy);
1516         if (sd->wd->reorder_item_changed) return;
1517         if (sd->wd->horizontal)
1518           {
1519              cy = (cy + 1) % sd->wd->nmax;
1520              if (!cy) cx++;
1521           }
1522         else
1523           {
1524              cx = (cx + 1) % sd->wd->nmax;
1525              if (!cx) cy++;
1526           }
1527      }
1528
1529    if ((sd->wd->reorder_mode) && (sd->wd->reorder_item))
1530      {
1531         if (!sd->wd->reorder_item_changed)
1532           {
1533              sd->wd->old_pan_x = sd->wd->pan_x;
1534              sd->wd->old_pan_y = sd->wd->pan_y;
1535           }
1536         sd->wd->move_effect_enabled = EINA_FALSE;
1537      }
1538    evas_object_smart_callback_call(sd->wd->self, SIG_CHANGED, NULL);
1539 }
1540
1541 static void
1542 _pan_move(Evas_Object *obj,
1543           Evas_Coord x __UNUSED__,
1544           Evas_Coord y __UNUSED__)
1545 {
1546    Pan *sd = evas_object_smart_data_get(obj);
1547    if (!sd) return;
1548    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1549    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1550 }
1551
1552 static void
1553 _hold_on(void *data       __UNUSED__,
1554          Evas_Object     *obj,
1555          void *event_info __UNUSED__)
1556 {
1557    Widget_Data *wd = elm_widget_data_get(obj);
1558    if (!wd) return;
1559    elm_smart_scroller_hold_set(wd->scr, 1);
1560 }
1561
1562 static void
1563 _hold_off(void *data       __UNUSED__,
1564           Evas_Object     *obj,
1565           void *event_info __UNUSED__)
1566 {
1567    Widget_Data *wd = elm_widget_data_get(obj);
1568    if (!wd) return;
1569    elm_smart_scroller_hold_set(wd->scr, 0);
1570 }
1571
1572 static void
1573 _freeze_on(void *data       __UNUSED__,
1574            Evas_Object     *obj,
1575            void *event_info __UNUSED__)
1576 {
1577    Widget_Data *wd = elm_widget_data_get(obj);
1578    if (!wd) return;
1579    elm_smart_scroller_freeze_set(wd->scr, 1);
1580 }
1581
1582 static void
1583 _freeze_off(void *data       __UNUSED__,
1584             Evas_Object     *obj,
1585             void *event_info __UNUSED__)
1586 {
1587    Widget_Data *wd = elm_widget_data_get(obj);
1588    if (!wd) return;
1589    elm_smart_scroller_freeze_set(wd->scr, 0);
1590 }
1591
1592 static void
1593 _scr_anim_start(void        *data,
1594                 Evas_Object *obj __UNUSED__,
1595                 void        *event_info __UNUSED__)
1596 {
1597    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
1598 }
1599
1600 static void
1601 _scr_anim_stop(void        *data,
1602                 Evas_Object *obj __UNUSED__,
1603                 void        *event_info __UNUSED__)
1604 {
1605    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
1606 }
1607
1608 static void
1609 _scr_drag_start(void            *data,
1610                 Evas_Object *obj __UNUSED__,
1611                 void *event_info __UNUSED__)
1612 {
1613    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1614 }
1615
1616 static void
1617 _scr_drag_stop(void            *data,
1618                Evas_Object *obj __UNUSED__,
1619                void *event_info __UNUSED__)
1620 {
1621    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1622 }
1623
1624 static void
1625 _scr_scroll(void            *data,
1626             Evas_Object *obj __UNUSED__,
1627             void *event_info __UNUSED__)
1628 {
1629    evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1630 }
1631
1632 static int
1633 _elm_gengrid_item_compare_data(const void *data, const void *data1)
1634 {
1635    const Elm_Gengrid_Item *item = data;
1636    const Elm_Gengrid_Item *item1 = data1;
1637
1638    return _elm_gengrid_item_compare_data_cb(item->base.data, item1->base.data);
1639 }
1640
1641 static int
1642 _elm_gengrid_item_compare(const void *data, const void *data1)
1643 {
1644    Elm_Gengrid_Item *item, *item1;
1645    item = ELM_GENGRID_ITEM_FROM_INLIST(data);
1646    item1 = ELM_GENGRID_ITEM_FROM_INLIST(data1);
1647    return _elm_gengrid_item_compare_cb(item, item1);
1648 }
1649
1650 EAPI Evas_Object *
1651 elm_gengrid_add(Evas_Object *parent)
1652 {
1653    Evas_Object *obj;
1654    Evas *e;
1655    Widget_Data *wd;
1656    static Evas_Smart *smart = NULL;
1657    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1658
1659    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1660
1661    ELM_SET_WIDTYPE(widtype, "gengrid");
1662    elm_widget_type_set(obj, "gengrid");
1663    elm_widget_sub_object_add(parent, obj);
1664    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1665    elm_widget_data_set(obj, wd);
1666    elm_widget_del_hook_set(obj, _del_hook);
1667    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1668    elm_widget_theme_hook_set(obj, _theme_hook);
1669    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1670    elm_widget_can_focus_set(obj, EINA_TRUE);
1671    elm_widget_event_hook_set(obj, _event_hook);
1672
1673    wd->scr = elm_smart_scroller_add(e);
1674    elm_smart_scroller_widget_set(wd->scr, obj);
1675    elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
1676                                        "default");
1677    elm_widget_resize_object_set(obj, wd->scr);
1678
1679    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1680    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1681    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1682    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1683    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1684
1685    elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1686
1687    wd->self = obj;
1688    wd->align_x = 0.5;
1689    wd->align_y = 0.5;
1690    wd->h_bounce = bounce;
1691    wd->v_bounce = bounce;
1692    wd->no_select = EINA_FALSE;
1693
1694    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1695    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1696    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1697    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1698
1699    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1700
1701    if (!smart)
1702      {
1703         static Evas_Smart_Class sc;
1704
1705         evas_object_smart_clipped_smart_set(&_pan_sc);
1706         sc = _pan_sc;
1707         sc.name = "elm_gengrid_pan";
1708         sc.version = EVAS_SMART_CLASS_VERSION;
1709         sc.add = _pan_add;
1710         sc.del = _pan_del;
1711         sc.resize = _pan_resize;
1712         sc.move = _pan_move;
1713         sc.calculate = _pan_calculate;
1714         smart = evas_smart_class_new(&sc);
1715      }
1716    if (smart)
1717      {
1718         wd->pan_smart = evas_object_smart_add(e, smart);
1719         wd->pan = evas_object_smart_data_get(wd->pan_smart);
1720         wd->pan->wd = wd;
1721      }
1722
1723    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1724                                      _pan_set, _pan_get, _pan_max_get,
1725                                      _pan_min_get, _pan_child_size_get);
1726
1727    _mirrored_set(obj, elm_widget_mirrored_get(obj));
1728    return obj;
1729 }
1730
1731 EAPI void
1732 elm_gengrid_item_size_set(Evas_Object *obj,
1733                           Evas_Coord   w,
1734                           Evas_Coord   h)
1735 {
1736    ELM_CHECK_WIDTYPE(obj, widtype);
1737    Widget_Data *wd = elm_widget_data_get(obj);
1738    if (!wd) return;
1739    if ((wd->item_width == w) && (wd->item_height == h)) return;
1740    wd->item_width = w;
1741    wd->item_height = h;
1742    if (wd->calc_job) ecore_job_del(wd->calc_job);
1743    wd->calc_job = ecore_job_add(_calc_job, wd);
1744 }
1745
1746 EAPI void
1747 elm_gengrid_item_size_get(const Evas_Object *obj,
1748                           Evas_Coord        *w,
1749                           Evas_Coord        *h)
1750 {
1751    ELM_CHECK_WIDTYPE(obj, widtype);
1752    Widget_Data *wd = elm_widget_data_get(obj);
1753    if (!wd) return;
1754    if (w) *w = wd->item_width;
1755    if (h) *h = wd->item_height;
1756 }
1757
1758 EAPI void
1759 elm_gengrid_align_set(Evas_Object *obj,
1760                       double       align_x,
1761                       double       align_y)
1762 {
1763    ELM_CHECK_WIDTYPE(obj, widtype);
1764
1765    Widget_Data *wd = elm_widget_data_get(obj);
1766    double old_h = wd->align_x, old_y = wd->align_y;
1767
1768    if (align_x > 1.0)
1769      align_x = 1.0;
1770    else if (align_x < 0.0)
1771      align_x = 0.0;
1772    wd->align_x = align_x;
1773
1774    if (align_y > 1.0)
1775      align_y = 1.0;
1776    else if (align_y < 0.0)
1777      align_y = 0.0;
1778    wd->align_y = align_y;
1779
1780    if ((old_h != wd->align_x) || (old_y != wd->align_y))
1781      evas_object_smart_calculate(wd->pan_smart);
1782 }
1783
1784 EAPI void
1785 elm_gengrid_align_get(const Evas_Object *obj,
1786                       double            *align_x,
1787                       double            *align_y)
1788 {
1789    ELM_CHECK_WIDTYPE(obj, widtype);
1790    Widget_Data *wd = elm_widget_data_get(obj);
1791    if (align_x) *align_x = wd->align_x;
1792    if (align_y) *align_y = wd->align_y;
1793 }
1794
1795 EAPI Elm_Gengrid_Item *
1796 elm_gengrid_item_append(Evas_Object                  *obj,
1797                         const Elm_Gengrid_Item_Class *gic,
1798                         const void                   *data,
1799                         Evas_Smart_Cb                 func,
1800                         const void                   *func_data)
1801 {
1802    Elm_Gengrid_Item *item;
1803    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1804    Widget_Data *wd = elm_widget_data_get(obj);
1805    if (!wd) return NULL;
1806
1807    item = _item_create(wd, gic, data, func, func_data);
1808    if (!item) return NULL;
1809    wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(item));
1810
1811    if (wd->calc_job) ecore_job_del(wd->calc_job);
1812    wd->calc_job = ecore_job_add(_calc_job, wd);
1813
1814    return item;
1815 }
1816
1817 EAPI Elm_Gengrid_Item *
1818 elm_gengrid_item_prepend(Evas_Object                  *obj,
1819                          const Elm_Gengrid_Item_Class *gic,
1820                          const void                   *data,
1821                          Evas_Smart_Cb                 func,
1822                          const void                   *func_data)
1823 {
1824    Elm_Gengrid_Item *item;
1825    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1826    Widget_Data *wd = elm_widget_data_get(obj);
1827    if (!wd) return NULL;
1828
1829    item = _item_create(wd, gic, data, func, func_data);
1830    if (!item) return NULL;
1831    wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(item));
1832
1833    if (wd->calc_job) ecore_job_del(wd->calc_job);
1834    wd->calc_job = ecore_job_add(_calc_job, wd);
1835
1836    return item;
1837 }
1838
1839 EAPI Elm_Gengrid_Item *
1840 elm_gengrid_item_insert_before(Evas_Object                  *obj,
1841                                const Elm_Gengrid_Item_Class *gic,
1842                                const void                   *data,
1843                                Elm_Gengrid_Item             *relative,
1844                                Evas_Smart_Cb                 func,
1845                                const void                   *func_data)
1846 {
1847    Elm_Gengrid_Item *item;
1848    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1849    EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
1850    Widget_Data *wd = elm_widget_data_get(obj);
1851    if (!wd) return NULL;
1852
1853    item = _item_create(wd, gic, data, func, func_data);
1854    if (!item) return NULL;
1855    wd->items = eina_inlist_prepend_relative
1856       (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
1857
1858    if (wd->calc_job) ecore_job_del(wd->calc_job);
1859    wd->calc_job = ecore_job_add(_calc_job, wd);
1860
1861    return item;
1862 }
1863
1864 EAPI Elm_Gengrid_Item *
1865 elm_gengrid_item_insert_after(Evas_Object                  *obj,
1866                               const Elm_Gengrid_Item_Class *gic,
1867                               const void                   *data,
1868                               Elm_Gengrid_Item             *relative,
1869                               Evas_Smart_Cb                 func,
1870                               const void                   *func_data)
1871 {
1872    Elm_Gengrid_Item *item;
1873    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1874    EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
1875    Widget_Data *wd = elm_widget_data_get(obj);
1876    if (!wd) return NULL;
1877
1878    item = _item_create(wd, gic, data, func, func_data);
1879    if (!item) return NULL;
1880    wd->items = eina_inlist_append_relative
1881       (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
1882
1883    if (wd->calc_job) ecore_job_del(wd->calc_job);
1884    wd->calc_job = ecore_job_add(_calc_job, wd);
1885
1886    return item;
1887 }
1888
1889 EAPI Elm_Gengrid_Item *
1890 elm_gengrid_item_direct_sorted_insert(Evas_Object                  *obj,
1891                                       const Elm_Gengrid_Item_Class *gic,
1892                                       const void                   *data,
1893                                       Eina_Compare_Cb               comp,
1894                                       Evas_Smart_Cb                 func,
1895                                       const void                   *func_data)
1896 {
1897    Elm_Gengrid_Item *item;
1898    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1899    Widget_Data *wd = elm_widget_data_get(obj);
1900    if (!wd) return NULL;
1901
1902    item = _item_create(wd, gic, data, func, func_data);
1903    if (!item) return NULL;
1904
1905    if (!wd->state)
1906      wd->state = eina_inlist_sorted_state_new();
1907
1908    _elm_gengrid_item_compare_cb = comp;
1909    wd->items = eina_inlist_sorted_state_insert(wd->items, EINA_INLIST_GET(item),
1910                                          _elm_gengrid_item_compare, wd->state);
1911    if (wd->calc_job) ecore_job_del(wd->calc_job);
1912    wd->calc_job = ecore_job_add(_calc_job, wd);
1913
1914    return item;
1915 }
1916
1917 EAPI Elm_Gengrid_Item *
1918 elm_gengrid_item_sorted_insert(Evas_Object                  *obj,
1919                                const Elm_Gengrid_Item_Class *gic,
1920                                const void                   *data,
1921                                Eina_Compare_Cb               comp,
1922                                Evas_Smart_Cb                 func,
1923                                const void                   *func_data)
1924 {
1925    _elm_gengrid_item_compare_data_cb = comp;
1926
1927    return elm_gengrid_item_direct_sorted_insert(obj, gic, data, _elm_gengrid_item_compare_data, func, func_data);
1928 }
1929
1930 EAPI void
1931 elm_gengrid_item_del(Elm_Gengrid_Item *item)
1932 {
1933    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1934    if ((item->relcount > 0) || (item->walking > 0))
1935      {
1936         item->delete_me = EINA_TRUE;
1937         elm_widget_item_pre_notify_del(item);
1938         if (item->selected)
1939           item->wd->selected = eina_list_remove(item->wd->selected, item);
1940         if (item->gic->func.del)
1941           item->gic->func.del((void *)item->base.data, item->wd->self);
1942         return;
1943      }
1944
1945    _item_del(item);
1946 }
1947
1948 EAPI void
1949 elm_gengrid_horizontal_set(Evas_Object *obj,
1950                            Eina_Bool    setting)
1951 {
1952    ELM_CHECK_WIDTYPE(obj, widtype);
1953    Widget_Data *wd = elm_widget_data_get(obj);
1954    if (!wd) return;
1955    if (setting == wd->horizontal) return;
1956    wd->horizontal = setting;
1957
1958    /* Update the items to conform to the new layout */
1959    if (wd->calc_job) ecore_job_del(wd->calc_job);
1960    wd->calc_job = ecore_job_add(_calc_job, wd);
1961 }
1962
1963 EAPI Eina_Bool
1964 elm_gengrid_horizontal_get(const Evas_Object *obj)
1965 {
1966    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1967    Widget_Data *wd = elm_widget_data_get(obj);
1968    if (!wd) return EINA_FALSE;
1969    return wd->horizontal;
1970 }
1971
1972 EAPI void
1973 elm_gengrid_clear(Evas_Object *obj)
1974 {
1975    ELM_CHECK_WIDTYPE(obj, widtype);
1976    Widget_Data *wd = elm_widget_data_get(obj);
1977    if (!wd) return;
1978
1979    if (wd->state)
1980      {
1981         eina_inlist_sorted_state_free(wd->state);
1982         wd->state = NULL;
1983      }
1984    if (wd->calc_job)
1985      {
1986         ecore_job_del(wd->calc_job);
1987         wd->calc_job = NULL;
1988      }
1989
1990    if (wd->walking > 0)
1991      {
1992         Elm_Gengrid_Item *item;
1993         wd->clear_me = 1;
1994         EINA_INLIST_FOREACH(wd->items, item)
1995            item->delete_me = 1;
1996         return;
1997      }
1998    wd->clear_me = 0;
1999    while (wd->items)
2000      {
2001         Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
2002
2003         wd->items = eina_inlist_remove(wd->items, wd->items);
2004         elm_widget_item_pre_notify_del(item);
2005         if (item->realized) _item_unrealize(item);
2006         if (item->gic->func.del)
2007           item->gic->func.del((void *)item->base.data, wd->self);
2008         if (item->long_timer) ecore_timer_del(item->long_timer);
2009         elm_widget_item_del(item);
2010      }
2011
2012    if (wd->selected)
2013      {
2014         eina_list_free(wd->selected);
2015         wd->selected = NULL;
2016      }
2017
2018    wd->pan_x = 0;
2019    wd->pan_y = 0;
2020    wd->minw = 0;
2021    wd->minh = 0;
2022    wd->count = 0;
2023    evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
2024    evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2025 }
2026
2027 EAPI const Evas_Object *
2028 elm_gengrid_item_object_get(const Elm_Gengrid_Item *item)
2029 {
2030    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2031    return item->base.view;
2032 }
2033
2034 EAPI void
2035 elm_gengrid_item_update(Elm_Gengrid_Item *item)
2036 {
2037    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2038    if (!item->realized) return;
2039    if (item->want_unrealize) return;
2040    _item_unrealize(item);
2041    _item_realize(item);
2042    _item_place(item, item->x, item->y);
2043 }
2044
2045 EAPI void *
2046 elm_gengrid_item_data_get(const Elm_Gengrid_Item *item)
2047 {
2048    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2049    return elm_widget_item_data_get(item);
2050 }
2051
2052 EAPI void
2053 elm_gengrid_item_data_set(Elm_Gengrid_Item *item,
2054                           const void       *data)
2055 {
2056    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2057    elm_widget_item_data_set(item, data);
2058 }
2059
2060 EAPI const Elm_Gengrid_Item_Class *
2061 elm_gengrid_item_item_class_get(const Elm_Gengrid_Item *item)
2062 {
2063    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2064    if (item->delete_me) return NULL;
2065    return item->gic;
2066 }
2067
2068 EAPI void
2069 elm_gengrid_item_item_class_set(Elm_Gengrid_Item *item,
2070                                 const Elm_Gengrid_Item_Class *gic)
2071 {
2072    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2073    EINA_SAFETY_ON_NULL_RETURN(gic);
2074    if (item->delete_me) return;
2075    item->gic = gic;
2076    elm_gengrid_item_update(item);
2077 }
2078
2079 EAPI void
2080 elm_gengrid_item_pos_get(const Elm_Gengrid_Item *item,
2081                          unsigned int           *x,
2082                          unsigned int           *y)
2083 {
2084    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2085    if (x) *x = item->x;
2086    if (y) *y = item->y;
2087 }
2088
2089 EAPI void
2090 elm_gengrid_multi_select_set(Evas_Object *obj,
2091                              Eina_Bool    multi)
2092 {
2093    ELM_CHECK_WIDTYPE(obj, widtype);
2094    Widget_Data *wd = elm_widget_data_get(obj);
2095    if (!wd) return;
2096    wd->multi = multi;
2097 }
2098
2099 EAPI Eina_Bool
2100 elm_gengrid_multi_select_get(const Evas_Object *obj)
2101 {
2102    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2103    Widget_Data *wd = elm_widget_data_get(obj);
2104    if (!wd) return EINA_FALSE;
2105    return wd->multi;
2106 }
2107
2108 EAPI Elm_Gengrid_Item *
2109 elm_gengrid_selected_item_get(const Evas_Object *obj)
2110 {
2111    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2112    Widget_Data *wd = elm_widget_data_get(obj);
2113    if (!wd) return NULL;
2114    if (wd->selected) return wd->selected->data;
2115    return NULL;
2116 }
2117
2118 EAPI const Eina_List *
2119 elm_gengrid_selected_items_get(const Evas_Object *obj)
2120 {
2121    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2122    Widget_Data *wd = elm_widget_data_get(obj);
2123    if (!wd) return NULL;
2124    return wd->selected;
2125 }
2126
2127 EAPI void
2128 elm_gengrid_item_selected_set(Elm_Gengrid_Item *item,
2129                               Eina_Bool         selected)
2130 {
2131    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2132    Widget_Data *wd = item->wd;
2133    if (!wd) return;
2134    if (item->delete_me) return;
2135    selected = !!selected;
2136    if (item->selected == selected) return;
2137
2138    if (selected)
2139      {
2140         if (!wd->multi)
2141           {
2142              while (wd->selected)
2143                _item_unselect(wd->selected->data);
2144           }
2145         _item_highlight(item);
2146         _item_select(item);
2147      }
2148    else
2149      _item_unselect(item);
2150 }
2151
2152 EAPI Eina_Bool
2153 elm_gengrid_item_selected_get(const Elm_Gengrid_Item *item)
2154 {
2155    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2156    return item->selected;
2157 }
2158
2159 EAPI void
2160 elm_gengrid_item_disabled_set(Elm_Gengrid_Item *item,
2161                               Eina_Bool         disabled)
2162 {
2163    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2164    if (item->disabled == disabled) return;
2165    if (item->delete_me) return;
2166    item->disabled = !!disabled;
2167    if (item->realized)
2168      {
2169         if (item->disabled)
2170           edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
2171         else
2172           edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
2173      }
2174 }
2175
2176 EAPI Eina_Bool
2177 elm_gengrid_item_disabled_get(const Elm_Gengrid_Item *item)
2178 {
2179    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2180    if (item->delete_me) return EINA_FALSE;
2181    return item->disabled;
2182 }
2183
2184 static Evas_Object *
2185 _elm_gengrid_item_label_create(void        *data,
2186                                Evas_Object *obj __UNUSED__,
2187                                Evas_Object *tooltip,
2188                                void *item   __UNUSED__)
2189 {
2190    Evas_Object *label = elm_label_add(tooltip);
2191    if (!label)
2192      return NULL;
2193    elm_object_style_set(label, "tooltip");
2194    elm_object_text_set(label, data);
2195    return label;
2196 }
2197
2198 static void
2199 _elm_gengrid_item_label_del_cb(void            *data,
2200                                Evas_Object *obj __UNUSED__,
2201                                void *event_info __UNUSED__)
2202 {
2203    eina_stringshare_del(data);
2204 }
2205
2206 EAPI void
2207 elm_gengrid_item_tooltip_text_set(Elm_Gengrid_Item *item,
2208                                   const char       *text)
2209 {
2210    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2211    text = eina_stringshare_add(text);
2212    elm_gengrid_item_tooltip_content_cb_set(item, _elm_gengrid_item_label_create,
2213                                            text,
2214                                            _elm_gengrid_item_label_del_cb);
2215 }
2216
2217 EAPI void
2218 elm_gengrid_item_tooltip_content_cb_set(Elm_Gengrid_Item           *item,
2219                                         Elm_Tooltip_Item_Content_Cb func,
2220                                         const void                 *data,
2221                                         Evas_Smart_Cb               del_cb)
2222 {
2223    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
2224
2225    if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
2226      return;
2227
2228    if (item->tooltip.del_cb)
2229      item->tooltip.del_cb((void *)item->tooltip.data,
2230                           item->base.widget, item);
2231    item->tooltip.content_cb = func;
2232    item->tooltip.data = data;
2233    item->tooltip.del_cb = del_cb;
2234    if (item->base.view)
2235      {
2236         elm_widget_item_tooltip_content_cb_set(item,
2237                                                item->tooltip.content_cb,
2238                                                item->tooltip.data, NULL);
2239         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
2240         elm_widget_item_tooltip_size_restrict_disable(item, item->tooltip.free_size);
2241      }
2242
2243    return;
2244
2245 error:
2246    if (del_cb) del_cb((void *)data, NULL, NULL);
2247 }
2248
2249 EAPI void
2250 elm_gengrid_item_tooltip_unset(Elm_Gengrid_Item *item)
2251 {
2252    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2253    if ((item->base.view) && (item->tooltip.content_cb))
2254      elm_widget_item_tooltip_unset(item);
2255
2256    if (item->tooltip.del_cb)
2257      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
2258    item->tooltip.del_cb = NULL;
2259    item->tooltip.content_cb = NULL;
2260    item->tooltip.data = NULL;
2261    item->tooltip.free_size = EINA_FALSE;
2262    if (item->tooltip.style)
2263      elm_gengrid_item_tooltip_style_set(item, NULL);
2264 }
2265
2266 EAPI void
2267 elm_gengrid_item_tooltip_style_set(Elm_Gengrid_Item *item,
2268                                    const char       *style)
2269 {
2270    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2271    eina_stringshare_replace(&item->tooltip.style, style);
2272    if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
2273 }
2274
2275 EAPI const char *
2276 elm_gengrid_item_tooltip_style_get(const Elm_Gengrid_Item *item)
2277 {
2278    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2279    return item->tooltip.style;
2280 }
2281
2282 EAPI Eina_Bool
2283 elm_gengrid_item_tooltip_size_restrict_disable(Elm_Gengrid_Item *item, Eina_Bool disable)
2284 {
2285    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2286    item->tooltip.free_size = disable;
2287    if (item->base.view) return elm_widget_item_tooltip_size_restrict_disable(item, disable);
2288    return EINA_TRUE;
2289 }
2290
2291 EAPI Eina_Bool
2292 elm_gengrid_item_tooltip_size_restrict_disabled_get(const Elm_Gengrid_Item *item)
2293 {
2294    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2295    return item->tooltip.free_size;
2296 }
2297
2298 EAPI void
2299 elm_gengrid_item_cursor_set(Elm_Gengrid_Item *item,
2300                             const char       *cursor)
2301 {
2302    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2303    eina_stringshare_replace(&item->mouse_cursor, cursor);
2304    if (item->base.view) elm_widget_item_cursor_set(item, cursor);
2305 }
2306
2307 EAPI const char *
2308 elm_gengrid_item_cursor_get(const Elm_Gengrid_Item *item)
2309 {
2310    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2311    return elm_widget_item_cursor_get(item);
2312 }
2313
2314 EAPI void
2315 elm_gengrid_item_cursor_unset(Elm_Gengrid_Item *item)
2316 {
2317    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2318    if (!item->mouse_cursor)
2319      return;
2320
2321    if (item->base.view)
2322      elm_widget_item_cursor_unset(item);
2323
2324    eina_stringshare_del(item->mouse_cursor);
2325    item->mouse_cursor = NULL;
2326 }
2327
2328 EAPI void
2329 elm_gengrid_item_cursor_style_set(Elm_Gengrid_Item *item,
2330                                   const char       *style)
2331 {
2332    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2333    elm_widget_item_cursor_style_set(item, style);
2334 }
2335
2336 EAPI const char *
2337 elm_gengrid_item_cursor_style_get(const Elm_Gengrid_Item *item)
2338 {
2339    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2340    return elm_widget_item_cursor_style_get(item);
2341 }
2342
2343 EAPI void
2344 elm_gengrid_item_cursor_engine_only_set(Elm_Gengrid_Item *item,
2345                                         Eina_Bool         engine_only)
2346 {
2347    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2348    elm_widget_item_cursor_engine_only_set(item, engine_only);
2349 }
2350
2351 EAPI Eina_Bool
2352 elm_gengrid_item_cursor_engine_only_get(const Elm_Gengrid_Item *item)
2353 {
2354    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2355    return elm_widget_item_cursor_engine_only_get(item);
2356 }
2357
2358 EAPI void
2359 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2360                              Eina_Bool    reorder_mode)
2361 {
2362    ELM_CHECK_WIDTYPE(obj, widtype);
2363    Widget_Data *wd = elm_widget_data_get(obj);
2364    if (!wd) return;
2365    wd->reorder_mode = reorder_mode;
2366 }
2367
2368 EAPI Eina_Bool
2369 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
2370 {
2371    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2372    Widget_Data *wd = elm_widget_data_get(obj);
2373    if (!wd) return EINA_FALSE;
2374    return wd->reorder_mode;
2375 }
2376
2377 EAPI void
2378 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2379                                    Eina_Bool    always_select)
2380 {
2381    ELM_CHECK_WIDTYPE(obj, widtype);
2382    Widget_Data *wd = elm_widget_data_get(obj);
2383    if (!wd) return;
2384    wd->always_select = always_select;
2385 }
2386
2387 EAPI Eina_Bool
2388 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2389 {
2390    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2391    Widget_Data *wd = elm_widget_data_get(obj);
2392    if (!wd) return EINA_FALSE;
2393    return wd->always_select;
2394 }
2395
2396 EAPI void
2397 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2398                                Eina_Bool    no_select)
2399 {
2400    ELM_CHECK_WIDTYPE(obj, widtype);
2401    Widget_Data *wd = elm_widget_data_get(obj);
2402    if (!wd) return;
2403    wd->no_select = no_select;
2404 }
2405
2406 EAPI Eina_Bool
2407 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2408 {
2409    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2410    Widget_Data *wd = elm_widget_data_get(obj);
2411    if (!wd) return EINA_FALSE;
2412    return wd->no_select;
2413 }
2414
2415 EAPI void
2416 elm_gengrid_bounce_set(Evas_Object *obj,
2417                        Eina_Bool    h_bounce,
2418                        Eina_Bool    v_bounce)
2419 {
2420    ELM_CHECK_WIDTYPE(obj, widtype);
2421    Widget_Data *wd = elm_widget_data_get(obj);
2422    if (!wd) return;
2423    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
2424    wd->h_bounce = h_bounce;
2425    wd->v_bounce = v_bounce;
2426 }
2427
2428 EAPI void
2429 elm_gengrid_bounce_get(const Evas_Object *obj,
2430                        Eina_Bool         *h_bounce,
2431                        Eina_Bool         *v_bounce)
2432 {
2433    ELM_CHECK_WIDTYPE(obj, widtype);
2434    Widget_Data *wd = elm_widget_data_get(obj);
2435    if (!wd) return;
2436    if (h_bounce) *h_bounce = wd->h_bounce;
2437    if (v_bounce) *v_bounce = wd->v_bounce;
2438 }
2439
2440 EAPI void
2441 elm_gengrid_page_relative_set(Evas_Object *obj,
2442                               double       h_pagerel,
2443                               double       v_pagerel)
2444 {
2445    Evas_Coord pagesize_h;
2446    Evas_Coord pagesize_v;
2447
2448    ELM_CHECK_WIDTYPE(obj, widtype);
2449    Widget_Data *wd = elm_widget_data_get(obj);
2450    if (!wd) return;
2451
2452    elm_smart_scroller_paging_get(wd->scr, NULL, NULL, &pagesize_h, &pagesize_v);
2453    elm_smart_scroller_paging_set(wd->scr, h_pagerel, v_pagerel, pagesize_h,
2454                                  pagesize_v);
2455 }
2456
2457 EAPI void
2458 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
2459 {
2460    ELM_CHECK_WIDTYPE(obj, widtype);
2461    Widget_Data *wd = elm_widget_data_get(obj);
2462    if (!wd) return;
2463
2464    elm_smart_scroller_paging_get(wd->scr, h_pagerel, v_pagerel, NULL, NULL);
2465 }
2466
2467 EAPI void
2468 elm_gengrid_page_size_set(Evas_Object *obj,
2469                           Evas_Coord   h_pagesize,
2470                           Evas_Coord   v_pagesize)
2471 {
2472    double pagerel_h;
2473    double pagerel_v;
2474
2475    ELM_CHECK_WIDTYPE(obj, widtype);
2476    Widget_Data *wd = elm_widget_data_get(obj);
2477    if (!wd) return;
2478    elm_smart_scroller_paging_get(wd->scr, &pagerel_h, &pagerel_v, NULL, NULL);
2479    elm_smart_scroller_paging_set(wd->scr, pagerel_h, pagerel_v, h_pagesize,
2480                                  v_pagesize);
2481 }
2482
2483 EAPI Elm_Gengrid_Item *
2484 elm_gengrid_first_item_get(const Evas_Object *obj)
2485 {
2486    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2487    Widget_Data *wd = elm_widget_data_get(obj);
2488    if (!wd) return NULL;
2489    if (!wd->items) return NULL;
2490    Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
2491    while ((item) && (item->delete_me))
2492      item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
2493    return item;
2494 }
2495
2496 EAPI Elm_Gengrid_Item *
2497 elm_gengrid_last_item_get(const Evas_Object *obj)
2498 {
2499    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2500    Widget_Data *wd = elm_widget_data_get(obj);
2501    if (!wd) return NULL;
2502    if (!wd->items) return NULL;
2503    Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
2504    while ((item) && (item->delete_me))
2505      item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
2506    return item;
2507 }
2508
2509 EAPI Elm_Gengrid_Item *
2510 elm_gengrid_item_next_get(const Elm_Gengrid_Item *item)
2511 {
2512    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2513    while (item)
2514      {
2515         item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
2516         if ((item) && (!item->delete_me)) break;
2517      }
2518    return (Elm_Gengrid_Item *)item;
2519 }
2520
2521 EAPI Elm_Gengrid_Item *
2522 elm_gengrid_item_prev_get(const Elm_Gengrid_Item *item)
2523 {
2524    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2525    while (item)
2526      {
2527         item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
2528         if ((item) && (!item->delete_me)) break;
2529      }
2530    return (Elm_Gengrid_Item *)item;
2531 }
2532
2533 EAPI Evas_Object *
2534 elm_gengrid_item_gengrid_get(const Elm_Gengrid_Item *item)
2535 {
2536    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2537    return item->base.widget;
2538 }
2539
2540 EAPI void
2541 elm_gengrid_item_show(Elm_Gengrid_Item *item)
2542 {
2543    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2544    Widget_Data *wd = elm_widget_data_get(item->wd->self);
2545    Evas_Coord minx = 0, miny = 0;
2546
2547    if (!wd) return;
2548    if ((!item) || (item->delete_me)) return;
2549    _pan_min_get(wd->pan_smart, &minx, &miny);
2550
2551    elm_smart_scroller_child_region_show(item->wd->scr,
2552                                         item->x * wd->item_width + minx,
2553                                         item->y * wd->item_height + miny,
2554                                         item->wd->item_width,
2555                                         item->wd->item_height);
2556 }
2557
2558 EAPI void
2559 elm_gengrid_item_bring_in(Elm_Gengrid_Item *item)
2560 {
2561    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2562    if (item->delete_me) return;
2563
2564    Evas_Coord minx = 0, miny = 0;
2565    Widget_Data *wd = elm_widget_data_get(item->wd->self);
2566    if (!wd) return;
2567    _pan_min_get(wd->pan_smart, &minx, &miny);
2568
2569    elm_smart_scroller_region_bring_in(item->wd->scr,
2570                                       item->x * wd->item_width + minx,
2571                                       item->y * wd->item_height + miny,
2572                                       item->wd->item_width,
2573                                       item->wd->item_height);
2574 }