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