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