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