fix elm_object_item_text_part_get for genlist and 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 const char *
1258 _item_label_hook(Elm_Gengrid_Item *it, const char *part)
1259 {
1260    if (!it->gic->func.label_get) return NULL;
1261    return edje_object_part_text_get(it->base.view, part);
1262 }
1263
1264 static Elm_Gengrid_Item *
1265 _item_create(Widget_Data                  *wd,
1266              const Elm_Gengrid_Item_Class *gic,
1267              const void                   *data,
1268              Evas_Smart_Cb                 func,
1269              const void                   *func_data)
1270 {
1271    Elm_Gengrid_Item *item;
1272
1273    item = elm_widget_item_new(wd->self, Elm_Gengrid_Item);
1274    if (!item) return NULL;
1275    wd->count++;
1276    item->wd = wd;
1277    item->gic = gic;
1278    item->base.data = data;
1279    item->func.func = func;
1280    item->func.data = func_data;
1281    item->mouse_cursor = NULL;
1282    elm_widget_item_text_get_hook_set(item, _item_label_hook);
1283    return item;
1284 }
1285
1286 static void
1287 _item_del(Elm_Gengrid_Item *item)
1288 {
1289    elm_widget_item_pre_notify_del(item);
1290    if (item->selected)
1291      item->wd->selected = eina_list_remove(item->wd->selected, item);
1292    if (item->realized) _item_unrealize(item);
1293    if ((!item->delete_me) && (item->gic->func.del))
1294      item->gic->func.del((void *)item->base.data, item->wd->self);
1295    item->delete_me = EINA_TRUE;
1296    item->wd->items = eina_inlist_remove(item->wd->items, EINA_INLIST_GET(item));
1297    if (item->long_timer) ecore_timer_del(item->long_timer);
1298    if (item->tooltip.del_cb)
1299      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
1300    item->wd->walking -= item->walking;
1301    item->wd->count--;
1302    if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1303    item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1304    elm_widget_item_del(item);
1305 }
1306
1307 static void
1308 _item_select(Elm_Gengrid_Item *item)
1309 {
1310    if ((item->wd->no_select) || (item->delete_me)) return;
1311    if (item->selected)
1312      {
1313         if (item->wd->always_select) goto call;
1314         return;
1315      }
1316    item->selected = EINA_TRUE;
1317    item->wd->selected = eina_list_append(item->wd->selected, item);
1318 call:
1319    item->walking++;
1320    item->wd->walking++;
1321    if (item->func.func)
1322      item->func.func((void *)item->func.data, item->wd->self, item);
1323    if (!item->delete_me)
1324      evas_object_smart_callback_call(item->wd->self, SIG_SELECTED, item);
1325    item->walking--;
1326    item->wd->walking--;
1327    item->wd->last_selected_item = item;
1328    if ((item->wd->clear_me) && (!item->wd->walking))
1329      elm_gengrid_clear(item->base.widget);
1330    else
1331      {
1332         if ((!item->walking) && (item->delete_me))
1333           if (!item->relcount) _item_del(item);
1334      }
1335 }
1336
1337 static void
1338 _item_unselect(Elm_Gengrid_Item *item)
1339 {
1340    if ((item->delete_me) || (!item->hilighted)) return;
1341    edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
1342    item->hilighted = EINA_FALSE;
1343    if (item->selected)
1344      {
1345         item->selected = EINA_FALSE;
1346         item->wd->selected = eina_list_remove(item->wd->selected, item);
1347         evas_object_smart_callback_call(item->wd->self, SIG_UNSELECTED, item);
1348      }
1349 }
1350
1351 static void
1352 _calc_job(void *data)
1353 {
1354    Widget_Data *wd = data;
1355    Evas_Coord minw = 0, minh = 0, nmax = 0, cvw, cvh;
1356    int count;
1357
1358    evas_object_geometry_get(wd->pan_smart, NULL, NULL, &cvw, &cvh);
1359    if ((cvw != 0) || (cvh != 0))
1360      {
1361         if ((wd->horizontal) && (wd->item_height > 0))
1362           nmax = cvh / wd->item_height;
1363         else if (wd->item_width > 0)
1364           nmax = cvw / wd->item_width;
1365
1366         if (nmax < 1)
1367           nmax = 1;
1368
1369         count = wd->count;
1370         if (wd->horizontal)
1371           {
1372              minw = ceil(count / (float)nmax) * wd->item_width;
1373              minh = nmax * wd->item_height;
1374           }
1375         else
1376           {
1377              minw = nmax * wd->item_width;
1378              minh = ceil(count / (float)nmax) * wd->item_height;
1379           }
1380
1381         if ((minw != wd->minw) || (minh != wd->minh))
1382           {
1383              wd->minh = minh;
1384              wd->minw = minw;
1385              evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1386           }
1387
1388         wd->nmax = nmax;
1389         evas_object_smart_changed(wd->pan_smart);
1390      }
1391    wd->calc_job = NULL;
1392 }
1393
1394 static void
1395 _pan_add(Evas_Object *obj)
1396 {
1397    Pan *sd;
1398    Evas_Object_Smart_Clipped_Data *cd;
1399
1400    _pan_sc.add(obj);
1401    cd = evas_object_smart_data_get(obj);
1402    sd = ELM_NEW(Pan);
1403    if (!sd) return;
1404    sd->__clipped_data = *cd;
1405    free(cd);
1406    evas_object_smart_data_set(obj, sd);
1407 }
1408
1409 static void
1410 _pan_del(Evas_Object *obj)
1411 {
1412    Pan *sd = evas_object_smart_data_get(obj);
1413
1414    if (!sd) return;
1415    _pan_sc.del(obj);
1416 }
1417
1418 static void
1419 _pan_set(Evas_Object *obj,
1420          Evas_Coord   x,
1421          Evas_Coord   y)
1422 {
1423    Pan *sd = evas_object_smart_data_get(obj);
1424    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1425    sd->wd->pan_x = x;
1426    sd->wd->pan_y = y;
1427    evas_object_smart_changed(obj);
1428 }
1429
1430 static void
1431 _pan_get(Evas_Object *obj,
1432          Evas_Coord  *x,
1433          Evas_Coord  *y)
1434 {
1435    Pan *sd = evas_object_smart_data_get(obj);
1436    if (x) *x = sd->wd->pan_x;
1437    if (y) *y = sd->wd->pan_y;
1438 }
1439
1440 static void
1441 _pan_child_size_get(Evas_Object *obj,
1442                     Evas_Coord  *w,
1443                     Evas_Coord  *h)
1444 {
1445    Pan *sd = evas_object_smart_data_get(obj);
1446    if (w) *w = sd->wd->minw;
1447    if (h) *h = sd->wd->minh;
1448 }
1449
1450 static void
1451 _pan_max_get(Evas_Object *obj,
1452              Evas_Coord  *x,
1453              Evas_Coord  *y)
1454 {
1455    Pan *sd = evas_object_smart_data_get(obj);
1456    Evas_Coord ow, oh;
1457
1458    if (!sd) return;
1459    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1460    if (x)
1461      *x = (ow < sd->wd->minw) ? sd->wd->minw - ow : 0;
1462    if (y)
1463      *y = (oh < sd->wd->minh) ? sd->wd->minh - oh : 0;
1464 }
1465
1466 static void
1467 _pan_min_get(Evas_Object *obj,
1468              Evas_Coord  *x,
1469              Evas_Coord  *y)
1470 {
1471    Pan *sd = evas_object_smart_data_get(obj);
1472    Evas_Coord mx, my;
1473
1474    if (!sd) return;
1475    _pan_max_get(obj, &mx, &my);
1476    if (x)
1477      *x = -mx * sd->wd->align_x;
1478    if (y)
1479      *y = -my * sd->wd->align_y;
1480 }
1481
1482 static void
1483 _pan_resize(Evas_Object *obj,
1484             Evas_Coord   w,
1485             Evas_Coord   h)
1486 {
1487    Pan *sd = evas_object_smart_data_get(obj);
1488    Evas_Coord ow, oh;
1489
1490    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1491    if ((ow == w) && (oh == h)) return;
1492    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1493    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1494 }
1495
1496 static void
1497 _pan_calculate(Evas_Object *obj)
1498 {
1499    Pan *sd = evas_object_smart_data_get(obj);
1500    Evas_Coord cx = 0, cy = 0;
1501    Elm_Gengrid_Item *item;
1502
1503    if (!sd) return;
1504    if (!sd->wd->nmax) return;
1505
1506    sd->wd->reorder_item_changed = EINA_FALSE;
1507
1508    EINA_INLIST_FOREACH(sd->wd->items, item)
1509      {
1510         _item_place(item, cx, cy);
1511         if (sd->wd->reorder_item_changed) return;
1512         if (sd->wd->horizontal)
1513           {
1514              cy = (cy + 1) % sd->wd->nmax;
1515              if (!cy) cx++;
1516           }
1517         else
1518           {
1519              cx = (cx + 1) % sd->wd->nmax;
1520              if (!cx) cy++;
1521           }
1522      }
1523
1524    if ((sd->wd->reorder_mode) && (sd->wd->reorder_item))
1525      {
1526         if (!sd->wd->reorder_item_changed)
1527           {
1528              sd->wd->old_pan_x = sd->wd->pan_x;
1529              sd->wd->old_pan_y = sd->wd->pan_y;
1530           }
1531         sd->wd->move_effect_enabled = EINA_FALSE;
1532      }
1533    evas_object_smart_callback_call(sd->wd->self, SIG_CHANGED, NULL);
1534 }
1535
1536 static void
1537 _pan_move(Evas_Object *obj,
1538           Evas_Coord x __UNUSED__,
1539           Evas_Coord y __UNUSED__)
1540 {
1541    Pan *sd = evas_object_smart_data_get(obj);
1542    if (!sd) return;
1543    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1544    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1545 }
1546
1547 static void
1548 _hold_on(void *data       __UNUSED__,
1549          Evas_Object     *obj,
1550          void *event_info __UNUSED__)
1551 {
1552    Widget_Data *wd = elm_widget_data_get(obj);
1553    if (!wd) return;
1554    elm_smart_scroller_hold_set(wd->scr, 1);
1555 }
1556
1557 static void
1558 _hold_off(void *data       __UNUSED__,
1559           Evas_Object     *obj,
1560           void *event_info __UNUSED__)
1561 {
1562    Widget_Data *wd = elm_widget_data_get(obj);
1563    if (!wd) return;
1564    elm_smart_scroller_hold_set(wd->scr, 0);
1565 }
1566
1567 static void
1568 _freeze_on(void *data       __UNUSED__,
1569            Evas_Object     *obj,
1570            void *event_info __UNUSED__)
1571 {
1572    Widget_Data *wd = elm_widget_data_get(obj);
1573    if (!wd) return;
1574    elm_smart_scroller_freeze_set(wd->scr, 1);
1575 }
1576
1577 static void
1578 _freeze_off(void *data       __UNUSED__,
1579             Evas_Object     *obj,
1580             void *event_info __UNUSED__)
1581 {
1582    Widget_Data *wd = elm_widget_data_get(obj);
1583    if (!wd) return;
1584    elm_smart_scroller_freeze_set(wd->scr, 0);
1585 }
1586
1587 static void
1588 _scr_drag_start(void            *data,
1589                 Evas_Object *obj __UNUSED__,
1590                 void *event_info __UNUSED__)
1591 {
1592    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1593 }
1594
1595 static void
1596 _scr_drag_stop(void            *data,
1597                Evas_Object *obj __UNUSED__,
1598                void *event_info __UNUSED__)
1599 {
1600    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1601 }
1602
1603 static void
1604 _scr_scroll(void            *data,
1605             Evas_Object *obj __UNUSED__,
1606             void *event_info __UNUSED__)
1607 {
1608    evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1609 }
1610
1611 static int
1612 _elm_gengrid_item_compare_data(const void *data, const void *data1)
1613 {
1614    const Elm_Gengrid_Item *item = data;
1615    const Elm_Gengrid_Item *item1 = data1;
1616
1617    return _elm_gengrid_item_compare_data_cb(item->base.data, item1->base.data);
1618 }
1619
1620 static int
1621 _elm_gengrid_item_compare(const void *data, const void *data1)
1622 {
1623    Elm_Gengrid_Item *item, *item1;
1624    item = ELM_GENGRID_ITEM_FROM_INLIST(data);
1625    item1 = ELM_GENGRID_ITEM_FROM_INLIST(data1);
1626    return _elm_gengrid_item_compare_cb(item, item1);
1627 }
1628
1629 EAPI Evas_Object *
1630 elm_gengrid_add(Evas_Object *parent)
1631 {
1632    Evas_Object *obj;
1633    Evas *e;
1634    Widget_Data *wd;
1635    static Evas_Smart *smart = NULL;
1636    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1637
1638    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1639
1640    ELM_SET_WIDTYPE(widtype, "gengrid");
1641    elm_widget_type_set(obj, "gengrid");
1642    elm_widget_sub_object_add(parent, obj);
1643    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1644    elm_widget_data_set(obj, wd);
1645    elm_widget_del_hook_set(obj, _del_hook);
1646    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1647    elm_widget_theme_hook_set(obj, _theme_hook);
1648    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1649    elm_widget_can_focus_set(obj, EINA_TRUE);
1650    elm_widget_event_hook_set(obj, _event_hook);
1651
1652    wd->scr = elm_smart_scroller_add(e);
1653    elm_smart_scroller_widget_set(wd->scr, obj);
1654    elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
1655                                        "default");
1656    elm_widget_resize_object_set(obj, wd->scr);
1657
1658    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1659    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1660    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1661
1662    elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1663
1664    wd->self = obj;
1665    wd->align_x = 0.5;
1666    wd->align_y = 0.5;
1667    wd->h_bounce = bounce;
1668    wd->v_bounce = bounce;
1669    wd->no_select = EINA_FALSE;
1670
1671    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1672    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1673    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1674    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1675
1676    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1677
1678    if (!smart)
1679      {
1680         static Evas_Smart_Class sc;
1681
1682         evas_object_smart_clipped_smart_set(&_pan_sc);
1683         sc = _pan_sc;
1684         sc.name = "elm_gengrid_pan";
1685         sc.version = EVAS_SMART_CLASS_VERSION;
1686         sc.add = _pan_add;
1687         sc.del = _pan_del;
1688         sc.resize = _pan_resize;
1689         sc.move = _pan_move;
1690         sc.calculate = _pan_calculate;
1691         smart = evas_smart_class_new(&sc);
1692      }
1693    if (smart)
1694      {
1695         wd->pan_smart = evas_object_smart_add(e, smart);
1696         wd->pan = evas_object_smart_data_get(wd->pan_smart);
1697         wd->pan->wd = wd;
1698      }
1699
1700    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1701                                      _pan_set, _pan_get, _pan_max_get,
1702                                      _pan_min_get, _pan_child_size_get);
1703
1704    _mirrored_set(obj, elm_widget_mirrored_get(obj));
1705    return obj;
1706 }
1707
1708 EAPI void
1709 elm_gengrid_item_size_set(Evas_Object *obj,
1710                           Evas_Coord   w,
1711                           Evas_Coord   h)
1712 {
1713    ELM_CHECK_WIDTYPE(obj, widtype);
1714    Widget_Data *wd = elm_widget_data_get(obj);
1715    if (!wd) return;
1716    if ((wd->item_width == w) && (wd->item_height == h)) return;
1717    wd->item_width = w;
1718    wd->item_height = h;
1719    if (wd->calc_job) ecore_job_del(wd->calc_job);
1720    wd->calc_job = ecore_job_add(_calc_job, wd);
1721 }
1722
1723 EAPI void
1724 elm_gengrid_item_size_get(const Evas_Object *obj,
1725                           Evas_Coord        *w,
1726                           Evas_Coord        *h)
1727 {
1728    ELM_CHECK_WIDTYPE(obj, widtype);
1729    Widget_Data *wd = elm_widget_data_get(obj);
1730    if (!wd) return;
1731    if (w) *w = wd->item_width;
1732    if (h) *h = wd->item_height;
1733 }
1734
1735 EAPI void
1736 elm_gengrid_align_set(Evas_Object *obj,
1737                       double       align_x,
1738                       double       align_y)
1739 {
1740    ELM_CHECK_WIDTYPE(obj, widtype);
1741
1742    Widget_Data *wd = elm_widget_data_get(obj);
1743    double old_h = wd->align_x, old_y = wd->align_y;
1744
1745    if (align_x > 1.0)
1746      align_x = 1.0;
1747    else if (align_x < 0.0)
1748      align_x = 0.0;
1749    wd->align_x = align_x;
1750
1751    if (align_y > 1.0)
1752      align_y = 1.0;
1753    else if (align_y < 0.0)
1754      align_y = 0.0;
1755    wd->align_y = align_y;
1756
1757    if ((old_h != wd->align_x) || (old_y != wd->align_y))
1758      evas_object_smart_calculate(wd->pan_smart);
1759 }
1760
1761 EAPI void
1762 elm_gengrid_align_get(const Evas_Object *obj,
1763                       double            *align_x,
1764                       double            *align_y)
1765 {
1766    ELM_CHECK_WIDTYPE(obj, widtype);
1767    Widget_Data *wd = elm_widget_data_get(obj);
1768    if (align_x) *align_x = wd->align_x;
1769    if (align_y) *align_y = wd->align_y;
1770 }
1771
1772 EAPI Elm_Gengrid_Item *
1773 elm_gengrid_item_append(Evas_Object                  *obj,
1774                         const Elm_Gengrid_Item_Class *gic,
1775                         const void                   *data,
1776                         Evas_Smart_Cb                 func,
1777                         const void                   *func_data)
1778 {
1779    Elm_Gengrid_Item *item;
1780    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1781    Widget_Data *wd = elm_widget_data_get(obj);
1782    if (!wd) return NULL;
1783
1784    item = _item_create(wd, gic, data, func, func_data);
1785    if (!item) return NULL;
1786    wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(item));
1787
1788    if (wd->calc_job) ecore_job_del(wd->calc_job);
1789    wd->calc_job = ecore_job_add(_calc_job, wd);
1790
1791    return item;
1792 }
1793
1794 EAPI Elm_Gengrid_Item *
1795 elm_gengrid_item_prepend(Evas_Object                  *obj,
1796                          const Elm_Gengrid_Item_Class *gic,
1797                          const void                   *data,
1798                          Evas_Smart_Cb                 func,
1799                          const void                   *func_data)
1800 {
1801    Elm_Gengrid_Item *item;
1802    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1803    Widget_Data *wd = elm_widget_data_get(obj);
1804    if (!wd) return NULL;
1805
1806    item = _item_create(wd, gic, data, func, func_data);
1807    if (!item) return NULL;
1808    wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(item));
1809
1810    if (wd->calc_job) ecore_job_del(wd->calc_job);
1811    wd->calc_job = ecore_job_add(_calc_job, wd);
1812
1813    return item;
1814 }
1815
1816 EAPI Elm_Gengrid_Item *
1817 elm_gengrid_item_insert_before(Evas_Object                  *obj,
1818                                const Elm_Gengrid_Item_Class *gic,
1819                                const void                   *data,
1820                                Elm_Gengrid_Item             *relative,
1821                                Evas_Smart_Cb                 func,
1822                                const void                   *func_data)
1823 {
1824    Elm_Gengrid_Item *item;
1825    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1826    EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
1827    Widget_Data *wd = elm_widget_data_get(obj);
1828    if (!wd) return NULL;
1829
1830    item = _item_create(wd, gic, data, func, func_data);
1831    if (!item) return NULL;
1832    wd->items = eina_inlist_prepend_relative
1833       (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
1834
1835    if (wd->calc_job) ecore_job_del(wd->calc_job);
1836    wd->calc_job = ecore_job_add(_calc_job, wd);
1837
1838    return item;
1839 }
1840
1841 EAPI Elm_Gengrid_Item *
1842 elm_gengrid_item_insert_after(Evas_Object                  *obj,
1843                               const Elm_Gengrid_Item_Class *gic,
1844                               const void                   *data,
1845                               Elm_Gengrid_Item             *relative,
1846                               Evas_Smart_Cb                 func,
1847                               const void                   *func_data)
1848 {
1849    Elm_Gengrid_Item *item;
1850    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1851    EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
1852    Widget_Data *wd = elm_widget_data_get(obj);
1853    if (!wd) return NULL;
1854
1855    item = _item_create(wd, gic, data, func, func_data);
1856    if (!item) return NULL;
1857    wd->items = eina_inlist_append_relative
1858       (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
1859
1860    if (wd->calc_job) ecore_job_del(wd->calc_job);
1861    wd->calc_job = ecore_job_add(_calc_job, wd);
1862
1863    return item;
1864 }
1865
1866 EAPI Elm_Gengrid_Item *
1867 elm_gengrid_item_direct_sorted_insert(Evas_Object                  *obj,
1868                                       const Elm_Gengrid_Item_Class *gic,
1869                                       const void                   *data,
1870                                       Eina_Compare_Cb               comp,
1871                                       Evas_Smart_Cb                 func,
1872                                       const void                   *func_data)
1873 {
1874    Elm_Gengrid_Item *item;
1875    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1876    Widget_Data *wd = elm_widget_data_get(obj);
1877    if (!wd) return NULL;
1878
1879    item = _item_create(wd, gic, data, func, func_data);
1880    if (!item) return NULL;
1881
1882    _elm_gengrid_item_compare_cb = comp;
1883    wd->items = eina_inlist_sorted_insert(wd->items, EINA_INLIST_GET(item),
1884                                          _elm_gengrid_item_compare);
1885    if (wd->calc_job) ecore_job_del(wd->calc_job);
1886    wd->calc_job = ecore_job_add(_calc_job, wd);
1887
1888    return item;
1889 }
1890
1891 EAPI Elm_Gengrid_Item *
1892 elm_gengrid_item_sorted_insert(Evas_Object                  *obj,
1893                                const Elm_Gengrid_Item_Class *gic,
1894                                const void                   *data,
1895                                Eina_Compare_Cb               comp,
1896                                Evas_Smart_Cb                 func,
1897                                const void                   *func_data)
1898 {
1899    _elm_gengrid_item_compare_data_cb = comp;
1900
1901    return elm_gengrid_item_direct_sorted_insert(obj, gic, data, _elm_gengrid_item_compare_data, func, func_data);
1902 }
1903
1904 EAPI void
1905 elm_gengrid_item_del(Elm_Gengrid_Item *item)
1906 {
1907    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1908    if ((item->relcount > 0) || (item->walking > 0))
1909      {
1910         item->delete_me = EINA_TRUE;
1911         elm_widget_item_pre_notify_del(item);
1912         if (item->selected)
1913           item->wd->selected = eina_list_remove(item->wd->selected, item);
1914         if (item->gic->func.del)
1915           item->gic->func.del((void *)item->base.data, item->wd->self);
1916         return;
1917      }
1918
1919    _item_del(item);
1920 }
1921
1922 EAPI void
1923 elm_gengrid_horizontal_set(Evas_Object *obj,
1924                            Eina_Bool    setting)
1925 {
1926    ELM_CHECK_WIDTYPE(obj, widtype);
1927    Widget_Data *wd = elm_widget_data_get(obj);
1928    if (!wd) return;
1929    if (setting == wd->horizontal) return;
1930    wd->horizontal = setting;
1931
1932    /* Update the items to conform to the new layout */
1933    if (wd->calc_job) ecore_job_del(wd->calc_job);
1934    wd->calc_job = ecore_job_add(_calc_job, wd);
1935 }
1936
1937 EAPI Eina_Bool
1938 elm_gengrid_horizontal_get(const Evas_Object *obj)
1939 {
1940    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1941    Widget_Data *wd = elm_widget_data_get(obj);
1942    if (!wd) return EINA_FALSE;
1943    return wd->horizontal;
1944 }
1945
1946 EAPI void
1947 elm_gengrid_clear(Evas_Object *obj)
1948 {
1949    ELM_CHECK_WIDTYPE(obj, widtype);
1950    Widget_Data *wd = elm_widget_data_get(obj);
1951    if (!wd) return;
1952
1953    if (wd->calc_job)
1954      {
1955         ecore_job_del(wd->calc_job);
1956         wd->calc_job = NULL;
1957      }
1958
1959    if (wd->walking > 0)
1960      {
1961         Elm_Gengrid_Item *item;
1962         wd->clear_me = 1;
1963         EINA_INLIST_FOREACH(wd->items, item)
1964            item->delete_me = 1;
1965         return;
1966      }
1967    wd->clear_me = 0;
1968    while (wd->items)
1969      {
1970         Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
1971
1972         wd->items = eina_inlist_remove(wd->items, wd->items);
1973         elm_widget_item_pre_notify_del(item);
1974         if (item->realized) _item_unrealize(item);
1975         if (item->gic->func.del)
1976           item->gic->func.del((void *)item->base.data, wd->self);
1977         if (item->long_timer) ecore_timer_del(item->long_timer);
1978         elm_widget_item_del(item);
1979      }
1980
1981    if (wd->selected)
1982      {
1983         eina_list_free(wd->selected);
1984         wd->selected = NULL;
1985      }
1986
1987    wd->pan_x = 0;
1988    wd->pan_y = 0;
1989    wd->minw = 0;
1990    wd->minh = 0;
1991    wd->count = 0;
1992    evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
1993    evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1994 }
1995
1996 EAPI const Evas_Object *
1997 elm_gengrid_item_object_get(const Elm_Gengrid_Item *item)
1998 {
1999    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2000    return item->base.view;
2001 }
2002
2003 EAPI void
2004 elm_gengrid_item_update(Elm_Gengrid_Item *item)
2005 {
2006    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2007    if (!item->realized) return;
2008    if (item->want_unrealize) return;
2009    _item_unrealize(item);
2010    _item_realize(item);
2011    _item_place(item, item->x, item->y);
2012 }
2013
2014 EAPI void *
2015 elm_gengrid_item_data_get(const Elm_Gengrid_Item *item)
2016 {
2017    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2018    return elm_widget_item_data_get(item);
2019 }
2020
2021 EAPI void
2022 elm_gengrid_item_data_set(Elm_Gengrid_Item *item,
2023                           const void       *data)
2024 {
2025    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2026    elm_widget_item_data_set(item, data);
2027 }
2028
2029 EAPI const Elm_Gengrid_Item_Class *
2030 elm_gengrid_item_item_class_get(const Elm_Gengrid_Item *item)
2031 {
2032    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2033    if (item->delete_me) return NULL;
2034    return item->gic;
2035 }
2036
2037 EAPI void
2038 elm_gengrid_item_item_class_set(Elm_Gengrid_Item *item,
2039                                 const Elm_Gengrid_Item_Class *gic)
2040 {
2041    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2042    EINA_SAFETY_ON_NULL_RETURN(gic);
2043    if (item->delete_me) return;
2044    item->gic = gic;
2045    elm_gengrid_item_update(item);
2046 }
2047
2048 EAPI void
2049 elm_gengrid_item_pos_get(const Elm_Gengrid_Item *item,
2050                          unsigned int           *x,
2051                          unsigned int           *y)
2052 {
2053    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2054    if (x) *x = item->x;
2055    if (y) *y = item->y;
2056 }
2057
2058 EAPI void
2059 elm_gengrid_multi_select_set(Evas_Object *obj,
2060                              Eina_Bool    multi)
2061 {
2062    ELM_CHECK_WIDTYPE(obj, widtype);
2063    Widget_Data *wd = elm_widget_data_get(obj);
2064    if (!wd) return;
2065    wd->multi = multi;
2066 }
2067
2068 EAPI Eina_Bool
2069 elm_gengrid_multi_select_get(const Evas_Object *obj)
2070 {
2071    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2072    Widget_Data *wd = elm_widget_data_get(obj);
2073    if (!wd) return EINA_FALSE;
2074    return wd->multi;
2075 }
2076
2077 EAPI Elm_Gengrid_Item *
2078 elm_gengrid_selected_item_get(const Evas_Object *obj)
2079 {
2080    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2081    Widget_Data *wd = elm_widget_data_get(obj);
2082    if (!wd) return NULL;
2083    if (wd->selected) return wd->selected->data;
2084    return NULL;
2085 }
2086
2087 EAPI const Eina_List *
2088 elm_gengrid_selected_items_get(const Evas_Object *obj)
2089 {
2090    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2091    Widget_Data *wd = elm_widget_data_get(obj);
2092    if (!wd) return NULL;
2093    return wd->selected;
2094 }
2095
2096 EAPI void
2097 elm_gengrid_item_selected_set(Elm_Gengrid_Item *item,
2098                               Eina_Bool         selected)
2099 {
2100    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2101    Widget_Data *wd = item->wd;
2102    if (!wd) return;
2103    if (item->delete_me) return;
2104    selected = !!selected;
2105    if (item->selected == selected) return;
2106
2107    if (selected)
2108      {
2109         if (!wd->multi)
2110           {
2111              while (wd->selected)
2112                _item_unselect(wd->selected->data);
2113           }
2114         _item_hilight(item);
2115         _item_select(item);
2116      }
2117    else
2118      _item_unselect(item);
2119 }
2120
2121 EAPI Eina_Bool
2122 elm_gengrid_item_selected_get(const Elm_Gengrid_Item *item)
2123 {
2124    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2125    return item->selected;
2126 }
2127
2128 EAPI void
2129 elm_gengrid_item_disabled_set(Elm_Gengrid_Item *item,
2130                               Eina_Bool         disabled)
2131 {
2132    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2133    if (item->disabled == disabled) return;
2134    if (item->delete_me) return;
2135    item->disabled = !!disabled;
2136    if (item->realized)
2137      {
2138         if (item->disabled)
2139           edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
2140         else
2141           edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
2142      }
2143 }
2144
2145 EAPI Eina_Bool
2146 elm_gengrid_item_disabled_get(const Elm_Gengrid_Item *item)
2147 {
2148    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2149    if (item->delete_me) return EINA_FALSE;
2150    return item->disabled;
2151 }
2152
2153 static Evas_Object *
2154 _elm_gengrid_item_label_create(void        *data,
2155                                Evas_Object *obj __UNUSED__,
2156                                Evas_Object *tooltip,
2157                                void *item   __UNUSED__)
2158 {
2159    Evas_Object *label = elm_label_add(tooltip);
2160    if (!label)
2161      return NULL;
2162    elm_object_style_set(label, "tooltip");
2163    elm_object_text_set(label, data);
2164    return label;
2165 }
2166
2167 static void
2168 _elm_gengrid_item_label_del_cb(void            *data,
2169                                Evas_Object *obj __UNUSED__,
2170                                void *event_info __UNUSED__)
2171 {
2172    eina_stringshare_del(data);
2173 }
2174
2175 EAPI void
2176 elm_gengrid_item_tooltip_text_set(Elm_Gengrid_Item *item,
2177                                   const char       *text)
2178 {
2179    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2180    text = eina_stringshare_add(text);
2181    elm_gengrid_item_tooltip_content_cb_set(item, _elm_gengrid_item_label_create,
2182                                            text,
2183                                            _elm_gengrid_item_label_del_cb);
2184 }
2185
2186 EAPI void
2187 elm_gengrid_item_tooltip_content_cb_set(Elm_Gengrid_Item           *item,
2188                                         Elm_Tooltip_Item_Content_Cb func,
2189                                         const void                 *data,
2190                                         Evas_Smart_Cb               del_cb)
2191 {
2192    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
2193
2194    if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
2195      return;
2196
2197    if (item->tooltip.del_cb)
2198      item->tooltip.del_cb((void *)item->tooltip.data,
2199                           item->base.widget, item);
2200    item->tooltip.content_cb = func;
2201    item->tooltip.data = data;
2202    item->tooltip.del_cb = del_cb;
2203    if (item->base.view)
2204      {
2205         elm_widget_item_tooltip_content_cb_set(item,
2206                                                item->tooltip.content_cb,
2207                                                item->tooltip.data, NULL);
2208         elm_widget_item_tooltip_style_set(item, item->tooltip.style);
2209         elm_widget_item_tooltip_size_restrict_disable(item, item->tooltip.free_size);
2210      }
2211
2212    return;
2213
2214 error:
2215    if (del_cb) del_cb((void *)data, NULL, NULL);
2216 }
2217
2218 EAPI void
2219 elm_gengrid_item_tooltip_unset(Elm_Gengrid_Item *item)
2220 {
2221    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2222    if ((item->base.view) && (item->tooltip.content_cb))
2223      elm_widget_item_tooltip_unset(item);
2224
2225    if (item->tooltip.del_cb)
2226      item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
2227    item->tooltip.del_cb = NULL;
2228    item->tooltip.content_cb = NULL;
2229    item->tooltip.data = NULL;
2230    item->tooltip.free_size = EINA_FALSE;
2231    if (item->tooltip.style)
2232      elm_gengrid_item_tooltip_style_set(item, NULL);
2233 }
2234
2235 EAPI void
2236 elm_gengrid_item_tooltip_style_set(Elm_Gengrid_Item *item,
2237                                    const char       *style)
2238 {
2239    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2240    eina_stringshare_replace(&item->tooltip.style, style);
2241    if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
2242 }
2243
2244 EAPI const char *
2245 elm_gengrid_item_tooltip_style_get(const Elm_Gengrid_Item *item)
2246 {
2247    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2248    return item->tooltip.style;
2249 }
2250
2251 EAPI Eina_Bool
2252 elm_gengrid_item_tooltip_size_restrict_disable(Elm_Gengrid_Item *item, Eina_Bool disable)
2253 {
2254    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2255    item->tooltip.free_size = disable;
2256    if (item->base.view) return elm_widget_item_tooltip_size_restrict_disable(item, disable);
2257    return EINA_TRUE;
2258 }
2259
2260 EAPI Eina_Bool
2261 elm_gengrid_item_tooltip_size_restrict_disabled_get(const Elm_Gengrid_Item *item)
2262 {
2263    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2264    return item->tooltip.free_size;
2265 }
2266
2267 EAPI void
2268 elm_gengrid_item_cursor_set(Elm_Gengrid_Item *item,
2269                             const char       *cursor)
2270 {
2271    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2272    eina_stringshare_replace(&item->mouse_cursor, cursor);
2273    if (item->base.view) elm_widget_item_cursor_set(item, cursor);
2274 }
2275
2276 EAPI const char *
2277 elm_gengrid_item_cursor_get(const Elm_Gengrid_Item *item)
2278 {
2279    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2280    return elm_widget_item_cursor_get(item);
2281 }
2282
2283 EAPI void
2284 elm_gengrid_item_cursor_unset(Elm_Gengrid_Item *item)
2285 {
2286    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2287    if (!item->mouse_cursor)
2288      return;
2289
2290    if (item->base.view)
2291      elm_widget_item_cursor_unset(item);
2292
2293    eina_stringshare_del(item->mouse_cursor);
2294    item->mouse_cursor = NULL;
2295 }
2296
2297 EAPI void
2298 elm_gengrid_item_cursor_style_set(Elm_Gengrid_Item *item,
2299                                   const char       *style)
2300 {
2301    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2302    elm_widget_item_cursor_style_set(item, style);
2303 }
2304
2305 EAPI const char *
2306 elm_gengrid_item_cursor_style_get(const Elm_Gengrid_Item *item)
2307 {
2308    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2309    return elm_widget_item_cursor_style_get(item);
2310 }
2311
2312 EAPI void
2313 elm_gengrid_item_cursor_engine_only_set(Elm_Gengrid_Item *item,
2314                                         Eina_Bool         engine_only)
2315 {
2316    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2317    elm_widget_item_cursor_engine_only_set(item, engine_only);
2318 }
2319
2320 EAPI Eina_Bool
2321 elm_gengrid_item_cursor_engine_only_get(const Elm_Gengrid_Item *item)
2322 {
2323    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2324    return elm_widget_item_cursor_engine_only_get(item);
2325 }
2326
2327 EAPI void
2328 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2329                              Eina_Bool    reorder_mode)
2330 {
2331    ELM_CHECK_WIDTYPE(obj, widtype);
2332    Widget_Data *wd = elm_widget_data_get(obj);
2333    if (!wd) return;
2334    wd->reorder_mode = reorder_mode;
2335 }
2336
2337 EAPI Eina_Bool
2338 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
2339 {
2340    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2341    Widget_Data *wd = elm_widget_data_get(obj);
2342    if (!wd) return EINA_FALSE;
2343    return wd->reorder_mode;
2344 }
2345
2346 EAPI void
2347 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2348                                    Eina_Bool    always_select)
2349 {
2350    ELM_CHECK_WIDTYPE(obj, widtype);
2351    Widget_Data *wd = elm_widget_data_get(obj);
2352    if (!wd) return;
2353    wd->always_select = always_select;
2354 }
2355
2356 EAPI Eina_Bool
2357 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2358 {
2359    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2360    Widget_Data *wd = elm_widget_data_get(obj);
2361    if (!wd) return EINA_FALSE;
2362    return wd->always_select;
2363 }
2364
2365 EAPI void
2366 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2367                                Eina_Bool    no_select)
2368 {
2369    ELM_CHECK_WIDTYPE(obj, widtype);
2370    Widget_Data *wd = elm_widget_data_get(obj);
2371    if (!wd) return;
2372    wd->no_select = no_select;
2373 }
2374
2375 EAPI Eina_Bool
2376 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2377 {
2378    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2379    Widget_Data *wd = elm_widget_data_get(obj);
2380    if (!wd) return EINA_FALSE;
2381    return wd->no_select;
2382 }
2383
2384 EAPI void
2385 elm_gengrid_bounce_set(Evas_Object *obj,
2386                        Eina_Bool    h_bounce,
2387                        Eina_Bool    v_bounce)
2388 {
2389    ELM_CHECK_WIDTYPE(obj, widtype);
2390    Widget_Data *wd = elm_widget_data_get(obj);
2391    if (!wd) return;
2392    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
2393    wd->h_bounce = h_bounce;
2394    wd->v_bounce = v_bounce;
2395 }
2396
2397 EAPI void
2398 elm_gengrid_bounce_get(const Evas_Object *obj,
2399                        Eina_Bool         *h_bounce,
2400                        Eina_Bool         *v_bounce)
2401 {
2402    ELM_CHECK_WIDTYPE(obj, widtype);
2403    Widget_Data *wd = elm_widget_data_get(obj);
2404    if (!wd) return;
2405    if (h_bounce) *h_bounce = wd->h_bounce;
2406    if (v_bounce) *v_bounce = wd->v_bounce;
2407 }
2408
2409 EAPI void
2410 elm_gengrid_page_relative_set(Evas_Object *obj,
2411                               double       h_pagerel,
2412                               double       v_pagerel)
2413 {
2414    Evas_Coord pagesize_h;
2415    Evas_Coord pagesize_v;
2416
2417    ELM_CHECK_WIDTYPE(obj, widtype);
2418    Widget_Data *wd = elm_widget_data_get(obj);
2419    if (!wd) return;
2420
2421    elm_smart_scroller_paging_get(wd->scr, NULL, NULL, &pagesize_h, &pagesize_v);
2422    elm_smart_scroller_paging_set(wd->scr, h_pagerel, v_pagerel, pagesize_h,
2423                                  pagesize_v);
2424 }
2425
2426 EAPI void
2427 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
2428 {
2429    ELM_CHECK_WIDTYPE(obj, widtype);
2430    Widget_Data *wd = elm_widget_data_get(obj);
2431    if (!wd) return;
2432
2433    elm_smart_scroller_paging_get(wd->scr, h_pagerel, v_pagerel, NULL, NULL);
2434 }
2435
2436 EAPI void
2437 elm_gengrid_page_size_set(Evas_Object *obj,
2438                           Evas_Coord   h_pagesize,
2439                           Evas_Coord   v_pagesize)
2440 {
2441    double pagerel_h;
2442    double pagerel_v;
2443
2444    ELM_CHECK_WIDTYPE(obj, widtype);
2445    Widget_Data *wd = elm_widget_data_get(obj);
2446    if (!wd) return;
2447    elm_smart_scroller_paging_get(wd->scr, &pagerel_h, &pagerel_v, NULL, NULL);
2448    elm_smart_scroller_paging_set(wd->scr, pagerel_h, pagerel_v, h_pagesize,
2449                                  v_pagesize);
2450 }
2451
2452 EAPI Elm_Gengrid_Item *
2453 elm_gengrid_first_item_get(const Evas_Object *obj)
2454 {
2455    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2456    Widget_Data *wd = elm_widget_data_get(obj);
2457    if (!wd) return NULL;
2458    if (!wd->items) return NULL;
2459    Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
2460    while ((item) && (item->delete_me))
2461      item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
2462    return item;
2463 }
2464
2465 EAPI Elm_Gengrid_Item *
2466 elm_gengrid_last_item_get(const Evas_Object *obj)
2467 {
2468    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2469    Widget_Data *wd = elm_widget_data_get(obj);
2470    if (!wd) return NULL;
2471    if (!wd->items) return NULL;
2472    Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
2473    while ((item) && (item->delete_me))
2474      item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
2475    return item;
2476 }
2477
2478 EAPI Elm_Gengrid_Item *
2479 elm_gengrid_item_next_get(const Elm_Gengrid_Item *item)
2480 {
2481    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2482    while (item)
2483      {
2484         item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
2485         if ((item) && (!item->delete_me)) break;
2486      }
2487    return (Elm_Gengrid_Item *)item;
2488 }
2489
2490 EAPI Elm_Gengrid_Item *
2491 elm_gengrid_item_prev_get(const Elm_Gengrid_Item *item)
2492 {
2493    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2494    while (item)
2495      {
2496         item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
2497         if ((item) && (!item->delete_me)) break;
2498      }
2499    return (Elm_Gengrid_Item *)item;
2500 }
2501
2502 EAPI Evas_Object *
2503 elm_gengrid_item_gengrid_get(const Elm_Gengrid_Item *item)
2504 {
2505    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2506    return item->base.widget;
2507 }
2508
2509 EAPI void
2510 elm_gengrid_item_show(Elm_Gengrid_Item *item)
2511 {
2512    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2513    Widget_Data *wd = elm_widget_data_get(item->wd->self);
2514    Evas_Coord minx = 0, miny = 0;
2515
2516    if (!wd) return;
2517    if ((!item) || (item->delete_me)) return;
2518    _pan_min_get(wd->pan_smart, &minx, &miny);
2519
2520    elm_smart_scroller_child_region_show(item->wd->scr,
2521                                         item->x * wd->item_width + minx,
2522                                         item->y * wd->item_height + miny,
2523                                         item->wd->item_width,
2524                                         item->wd->item_height);
2525 }
2526
2527 EAPI void
2528 elm_gengrid_item_bring_in(Elm_Gengrid_Item *item)
2529 {
2530    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2531    if (item->delete_me) return;
2532
2533    Evas_Coord minx = 0, miny = 0;
2534    Widget_Data *wd = elm_widget_data_get(item->wd->self);
2535    if (!wd) return;
2536    _pan_min_get(wd->pan_smart, &minx, &miny);
2537
2538    elm_smart_scroller_region_bring_in(item->wd->scr,
2539                                       item->x * wd->item_width + minx,
2540                                       item->y * wd->item_height + miny,
2541                                       item->wd->item_width,
2542                                       item->wd->item_height);
2543 }