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