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