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