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