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