elm genlist/gengrid: Added documentation. Fixed documentation. Fixed
[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_genlist.h"
6
7 /* --
8  * TODO:
9  * Handle non-homogeneous objects too.
10  */
11
12 #define PRELOAD 1
13 #define REORDER_EFFECT_TIME 0.5
14
15 #define ELM_GEN_SETUP(wd) \
16    (wd)->calc_cb = (Ecore_Cb)_calc_job
17
18 #define ELM_GEN_ITEM_SETUP(it) \
19    (it)->del_cb = (Ecore_Cb)_item_del; \
20    (it)->highlight_cb = (Ecore_Cb)_item_highlight; \
21    (it)->unsel_cb = (Ecore_Cb)_item_unselect; \
22    (it)->unrealize_cb = (Ecore_Cb)_item_unrealize_cb
23
24 struct Elm_Gen_Item_Type
25 {
26    Elm_Gen_Item   *it;
27    Ecore_Animator *item_moving_effect_timer;
28    Evas_Coord   gx, gy, ox, oy, tx, ty, rx, ry;
29    unsigned int moving_effect_start_time;
30    int          prev_group;
31
32    Eina_Bool   group_realized : 1;
33    Eina_Bool   moving : 1;
34 };
35
36 #if 0
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    int               generation;
76
77    Eina_Bool         horizontal : 1;
78    Eina_Bool         longpressed : 1;
79    Eina_Bool         reorder_item_changed : 1;
80    Eina_Bool         move_effect_enabled : 1;
81 };
82 #endif
83
84 static const char *widtype = NULL;
85 static void      _item_highlight(Elm_Gen_Item *it);
86 static void      _item_unrealize_cb(Elm_Gen_Item *it);
87 static void      _item_unselect(Elm_Gen_Item *it);
88 static void      _calc_job(void *data);
89 static void      _on_focus_hook(void        *data,
90                                 Evas_Object *obj);
91 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
92 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
93 static Eina_Bool _item_multi_select_left(Widget_Data *wd);
94 static Eina_Bool _item_multi_select_right(Widget_Data *wd);
95 static Eina_Bool _item_single_select_up(Widget_Data *wd);
96 static Eina_Bool _item_single_select_down(Widget_Data *wd);
97 static Eina_Bool _item_single_select_left(Widget_Data *wd);
98 static Eina_Bool _item_single_select_right(Widget_Data *wd);
99 static Eina_Bool _event_hook(Evas_Object       *obj,
100                              Evas_Object       *src,
101                              Evas_Callback_Type type,
102                              void              *event_info);
103 static Eina_Bool _deselect_all_items(Widget_Data *wd);
104
105 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
106 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
107
108 static const char SIG_ACTIVATED[] = "activated";
109 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
110 static const char SIG_LONGPRESSED[] = "longpressed";
111 static const char SIG_SELECTED[] = "selected";
112 static const char SIG_UNSELECTED[] = "unselected";
113 static const char SIG_REALIZED[] = "realized";
114 static const char SIG_UNREALIZED[] = "unrealized";
115 static const char SIG_CHANGED[] = "changed";
116 static const char SIG_DRAG_START_UP[] = "drag,start,up";
117 static const char SIG_DRAG_START_DOWN[] = "drag,start,down";
118 static const char SIG_DRAG_START_LEFT[] = "drag,start,left";
119 static const char SIG_DRAG_START_RIGHT[] = "drag,start,right";
120 static const char SIG_DRAG_STOP[] = "drag,stop";
121 static const char SIG_DRAG[] = "drag";
122 static const char SIG_SCROLL[] = "scroll";
123 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
124 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
125 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
126 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
127 static const char SIG_EDGE_TOP[] = "edge,top";
128 static const char SIG_EDGE_BOTTOM[] = "edge,bottom";
129 static const char SIG_EDGE_LEFT[] = "edge,left";
130 static const char SIG_EDGE_RIGHT[] = "edge,right";
131 static const char SIG_MOVED[] = "moved";
132
133 static const Evas_Smart_Cb_Description _signals[] = {
134    {SIG_ACTIVATED, ""},
135    {SIG_CLICKED_DOUBLE, ""},
136    {SIG_LONGPRESSED, ""},
137    {SIG_SELECTED, ""},
138    {SIG_UNSELECTED, ""},
139    {SIG_REALIZED, ""},
140    {SIG_UNREALIZED, ""},
141    {SIG_CHANGED, ""},
142    {SIG_DRAG_START_UP, ""},
143    {SIG_DRAG_START_DOWN, ""},
144    {SIG_DRAG_START_LEFT, ""},
145    {SIG_DRAG_START_RIGHT, ""},
146    {SIG_DRAG_STOP, ""},
147    {SIG_DRAG, ""},
148    {SIG_SCROLL, ""},
149    {SIG_SCROLL_ANIM_START, ""},
150    {SIG_SCROLL_ANIM_STOP, ""},
151    {SIG_SCROLL_DRAG_START, ""},
152    {SIG_SCROLL_DRAG_STOP, ""},
153    {SIG_EDGE_TOP, ""},
154    {SIG_EDGE_BOTTOM, ""},
155    {SIG_EDGE_LEFT, ""},
156    {SIG_EDGE_RIGHT, ""},
157    {SIG_MOVED, ""},
158    {NULL, NULL}
159 };
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->generation < wd->generation))
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->generation < wd->generation))
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->generation < wd->generation))
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->generation < wd->generation))
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_genlist_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->generation < it->wd->generation) || (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->generation < it->wd->generation)) 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.text_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.text_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_window_mode_set(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_genlist_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_genlist_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_genlist_item_unrealize(it, EINA_FALSE);
1428    it->wd->count--;
1429    _elm_genlist_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->generation < it->wd->generation) || (!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 it->wd->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 it->wd->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_genlist_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->generation = 1;
1897    wd->scr = elm_smart_scroller_add(e);
1898    elm_smart_scroller_widget_set(wd->scr, obj);
1899    elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
1900                                        "default");
1901    elm_smart_scroller_bounce_allow_set(wd->scr, bounce,
1902                                        _elm_config->thumbscroll_bounce_enable);
1903    elm_widget_resize_object_set(obj, wd->scr);
1904
1905    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1906    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1907    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1908    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1909    evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
1910    evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
1911    evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
1912    evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom,
1913                                   obj);
1914    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1915
1916    wd->obj = obj;
1917    wd->align_x = 0.5;
1918    wd->align_y = 0.5;
1919    wd->h_bounce = bounce;
1920    wd->v_bounce = bounce;
1921
1922    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1923    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1924    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1925    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1926
1927    wd->pan_smart = evas_object_smart_add(e, smart);
1928    wd->pan = evas_object_smart_data_get(wd->pan_smart);
1929    wd->pan->wd = wd;
1930
1931    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1932                                      _pan_set, _pan_get, _pan_max_get,
1933                                      _pan_min_get, _pan_child_size_get);
1934
1935    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1936
1937    _mirrored_set(obj, elm_widget_mirrored_get(obj));
1938    return obj;
1939 }
1940
1941 EAPI void
1942 elm_gengrid_item_size_set(Evas_Object *obj,
1943                           Evas_Coord   w,
1944                           Evas_Coord   h)
1945 {
1946    ELM_CHECK_WIDTYPE(obj, widtype);
1947    Widget_Data *wd = elm_widget_data_get(obj);
1948    if (!wd) return;
1949    if ((wd->item_width == w) && (wd->item_height == h)) return;
1950    wd->item_width = w;
1951    wd->item_height = h;
1952    if (wd->calc_job) ecore_job_del(wd->calc_job);
1953    wd->calc_job = ecore_job_add(_calc_job, wd);
1954 }
1955
1956 EAPI void
1957 elm_gengrid_item_size_get(const Evas_Object *obj,
1958                           Evas_Coord        *w,
1959                           Evas_Coord        *h)
1960 {
1961    ELM_CHECK_WIDTYPE(obj, widtype);
1962    Widget_Data *wd = elm_widget_data_get(obj);
1963    if (!wd) return;
1964    if (w) *w = wd->item_width;
1965    if (h) *h = wd->item_height;
1966 }
1967
1968 EAPI void
1969 elm_gengrid_group_item_size_set(Evas_Object *obj,
1970                           Evas_Coord   w,
1971                           Evas_Coord   h)
1972 {
1973    ELM_CHECK_WIDTYPE(obj, widtype);
1974    Widget_Data *wd = elm_widget_data_get(obj);
1975    if (!wd) return;
1976    if ((wd->group_item_width == w) && (wd->group_item_height == h)) return;
1977    wd->group_item_width = w;
1978    wd->group_item_height = h;
1979    if (wd->calc_job) ecore_job_del(wd->calc_job);
1980    wd->calc_job = ecore_job_add(_calc_job, wd);
1981 }
1982
1983 EAPI void
1984 elm_gengrid_group_item_size_get(const Evas_Object *obj,
1985                           Evas_Coord        *w,
1986                           Evas_Coord        *h)
1987 {
1988    ELM_CHECK_WIDTYPE(obj, widtype);
1989    Widget_Data *wd = elm_widget_data_get(obj);
1990    if (!wd) return;
1991    if (w) *w = wd->group_item_width;
1992    if (h) *h = wd->group_item_height;
1993 }
1994
1995 EAPI void
1996 elm_gengrid_align_set(Evas_Object *obj,
1997                       double       align_x,
1998                       double       align_y)
1999 {
2000    ELM_CHECK_WIDTYPE(obj, widtype);
2001
2002    Widget_Data *wd = elm_widget_data_get(obj);
2003    double old_h = wd->align_x, old_y = wd->align_y;
2004
2005    if (align_x > 1.0)
2006      align_x = 1.0;
2007    else if (align_x < 0.0)
2008      align_x = 0.0;
2009    wd->align_x = align_x;
2010
2011    if (align_y > 1.0)
2012      align_y = 1.0;
2013    else if (align_y < 0.0)
2014      align_y = 0.0;
2015    wd->align_y = align_y;
2016
2017    if ((old_h != wd->align_x) || (old_y != wd->align_y))
2018      evas_object_smart_calculate(wd->pan_smart);
2019 }
2020
2021 EAPI void
2022 elm_gengrid_align_get(const Evas_Object *obj,
2023                       double            *align_x,
2024                       double            *align_y)
2025 {
2026    ELM_CHECK_WIDTYPE(obj, widtype);
2027    Widget_Data *wd = elm_widget_data_get(obj);
2028    if (align_x) *align_x = wd->align_x;
2029    if (align_y) *align_y = wd->align_y;
2030 }
2031
2032 EAPI Elm_Gen_Item *
2033 elm_gengrid_item_append(Evas_Object                  *obj,
2034                         const Elm_Gengrid_Item_Class *itc,
2035                         const void                   *data,
2036                         Evas_Smart_Cb                 func,
2037                         const void                   *func_data)
2038 {
2039    Elm_Gen_Item *it;
2040    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2041    Widget_Data *wd = elm_widget_data_get(obj);
2042    if (!wd) return NULL;
2043
2044    it = _item_new(wd, itc, data, func, func_data);
2045    if (!it) return NULL;
2046    wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
2047
2048    if (it->group)
2049      wd->group_items = eina_list_prepend(wd->group_items, it);
2050
2051    if (wd->calc_job) ecore_job_del(wd->calc_job);
2052    wd->calc_job = ecore_job_add(_calc_job, wd);
2053
2054    return it;
2055 }
2056
2057 EAPI Elm_Gen_Item *
2058 elm_gengrid_item_prepend(Evas_Object                  *obj,
2059                          const Elm_Gengrid_Item_Class *itc,
2060                          const void                   *data,
2061                          Evas_Smart_Cb                 func,
2062                          const void                   *func_data)
2063 {
2064    Elm_Gen_Item *it;
2065    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2066    Widget_Data *wd = elm_widget_data_get(obj);
2067    if (!wd) return NULL;
2068
2069    it = _item_new(wd, itc, data, func, func_data);
2070    if (!it) return NULL;
2071    wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
2072    if (it->group)
2073      wd->group_items = eina_list_append(wd->group_items, it);
2074
2075    if (wd->calc_job) ecore_job_del(wd->calc_job);
2076    wd->calc_job = ecore_job_add(_calc_job, wd);
2077
2078    return it;
2079 }
2080
2081 EAPI Elm_Gen_Item *
2082 elm_gengrid_item_insert_before(Evas_Object                  *obj,
2083                                const Elm_Gengrid_Item_Class *itc,
2084                                const void                   *data,
2085                                Elm_Gen_Item             *relative,
2086                                Evas_Smart_Cb                 func,
2087                                const void                   *func_data)
2088 {
2089    Elm_Gen_Item *it;
2090    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2091    EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
2092    Widget_Data *wd = elm_widget_data_get(obj);
2093    if (!wd) return NULL;
2094
2095    it = _item_new(wd, itc, data, func, func_data);
2096    if (!it) return NULL;
2097    wd->items = eina_inlist_prepend_relative
2098       (wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(relative));
2099    if (it->group)
2100      wd->group_items = eina_list_append_relative(wd->group_items, it, relative->parent);
2101
2102    if (wd->calc_job) ecore_job_del(wd->calc_job);
2103    wd->calc_job = ecore_job_add(_calc_job, wd);
2104
2105    return it;
2106 }
2107
2108 EAPI Elm_Gen_Item *
2109 elm_gengrid_item_insert_after(Evas_Object                  *obj,
2110                               const Elm_Gengrid_Item_Class *itc,
2111                               const void                   *data,
2112                               Elm_Gen_Item             *relative,
2113                               Evas_Smart_Cb                 func,
2114                               const void                   *func_data)
2115 {
2116    Elm_Gen_Item *it;
2117    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2118    EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
2119    Widget_Data *wd = elm_widget_data_get(obj);
2120    if (!wd) return NULL;
2121
2122    it = _item_new(wd, itc, data, func, func_data);
2123    if (!it) return NULL;
2124    wd->items = eina_inlist_append_relative
2125       (wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET(relative));
2126    if (it->group)
2127      wd->group_items = eina_list_prepend_relative(wd->group_items, it, relative->parent);
2128
2129    if (wd->calc_job) ecore_job_del(wd->calc_job);
2130    wd->calc_job = ecore_job_add(_calc_job, wd);
2131
2132    return it;
2133 }
2134
2135 EAPI Elm_Gen_Item *
2136 elm_gengrid_item_direct_sorted_insert(Evas_Object                  *obj,
2137                                       const Elm_Gengrid_Item_Class *itc,
2138                                       const void                   *data,
2139                                       Eina_Compare_Cb               comp,
2140                                       Evas_Smart_Cb                 func,
2141                                       const void                   *func_data)
2142 {
2143    Elm_Gen_Item *it;
2144    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2145    Widget_Data *wd = elm_widget_data_get(obj);
2146    if (!wd) return NULL;
2147
2148    it = _item_new(wd, itc, data, func, func_data);
2149    if (!it) return NULL;
2150
2151    if (!wd->state)
2152      wd->state = eina_inlist_sorted_state_new();
2153
2154    wd->item_compare_cb = comp;
2155    wd->items = eina_inlist_sorted_state_insert(wd->items, EINA_INLIST_GET(it),
2156                                          _elm_gengrid_item_compare, wd->state);
2157    if (wd->calc_job) ecore_job_del(wd->calc_job);
2158    wd->calc_job = ecore_job_add(_calc_job, wd);
2159
2160    return it;
2161 }
2162
2163 EAPI Elm_Gen_Item *
2164 elm_gengrid_item_sorted_insert(Evas_Object                  *obj,
2165                                const Elm_Gengrid_Item_Class *itc,
2166                                const void                   *data,
2167                                Eina_Compare_Cb               comp,
2168                                Evas_Smart_Cb                 func,
2169                                const void                   *func_data)
2170 {
2171    Widget_Data *wd = elm_widget_data_get(obj);
2172    wd->item_compare_data_cb = comp;
2173
2174    return elm_gengrid_item_direct_sorted_insert(obj, itc, data, _elm_gengrid_item_compare_data, func, func_data);
2175 }
2176
2177 EAPI void
2178 elm_gengrid_item_del(Elm_Gen_Item *it)
2179 {
2180    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2181    if ((it->relcount > 0) || (it->walking > 0))
2182      {
2183         _elm_genlist_item_del_notserious(it);
2184         return;
2185      }
2186
2187    _item_del(it);
2188 }
2189
2190 EAPI void
2191 elm_gengrid_horizontal_set(Evas_Object *obj,
2192                            Eina_Bool    setting)
2193 {
2194    ELM_CHECK_WIDTYPE(obj, widtype);
2195    Widget_Data *wd = elm_widget_data_get(obj);
2196    if (!wd) return;
2197    if (setting == wd->horizontal) return;
2198    wd->horizontal = setting;
2199
2200    /* Update the items to conform to the new layout */
2201    if (wd->calc_job) ecore_job_del(wd->calc_job);
2202    wd->calc_job = ecore_job_add(_calc_job, wd);
2203 }
2204
2205 EAPI Eina_Bool
2206 elm_gengrid_horizontal_get(const Evas_Object *obj)
2207 {
2208    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2209    Widget_Data *wd = elm_widget_data_get(obj);
2210    if (!wd) return EINA_FALSE;
2211    return wd->horizontal;
2212 }
2213
2214 EAPI void
2215 elm_gengrid_clear(Evas_Object *obj)
2216 {
2217    elm_genlist_clear(obj);
2218 }
2219
2220 EAPI const Evas_Object *
2221 elm_gengrid_item_object_get(const Elm_Gen_Item *it)
2222 {
2223    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
2224    return VIEW(it);
2225 }
2226
2227 EAPI void
2228 elm_gengrid_item_update(Elm_Gen_Item *it)
2229 {
2230    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2231    if (!it->realized) return;
2232    if (it->want_unrealize) return;
2233    _elm_genlist_item_unrealize(it, EINA_FALSE);
2234    _item_realize(it);
2235    _item_place(it, it->x, it->y);
2236 }
2237
2238 EAPI void *
2239 elm_gengrid_item_data_get(const Elm_Gen_Item *it)
2240 {
2241    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
2242    return elm_widget_item_data_get(it);
2243 }
2244
2245 EAPI void
2246 elm_gengrid_item_data_set(Elm_Gen_Item *it,
2247                           const void       *data)
2248 {
2249    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2250    elm_widget_item_data_set(it, data);
2251 }
2252
2253 EAPI const Elm_Gengrid_Item_Class *
2254 elm_gengrid_item_item_class_get(const Elm_Gen_Item *it)
2255 {
2256    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
2257    if (it->generation < it->wd->generation) return NULL;
2258    return it->itc;
2259 }
2260
2261 EAPI void
2262 elm_gengrid_item_item_class_set(Elm_Gen_Item *it,
2263                                 const Elm_Gengrid_Item_Class *itc)
2264 {
2265    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2266    EINA_SAFETY_ON_NULL_RETURN(itc);
2267    if (it->generation < it->wd->generation) return;
2268    it->itc = itc;
2269    elm_gengrid_item_update(it);
2270 }
2271
2272 EAPI void
2273 elm_gengrid_item_pos_get(const Elm_Gen_Item *it,
2274                          unsigned int           *x,
2275                          unsigned int           *y)
2276 {
2277    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2278    if (x) *x = it->x;
2279    if (y) *y = it->y;
2280 }
2281
2282 EAPI void
2283 elm_gengrid_multi_select_set(Evas_Object *obj,
2284                              Eina_Bool    multi)
2285 {
2286    ELM_CHECK_WIDTYPE(obj, widtype);
2287    Widget_Data *wd = elm_widget_data_get(obj);
2288    if (!wd) return;
2289    wd->multi = multi;
2290 }
2291
2292 EAPI Eina_Bool
2293 elm_gengrid_multi_select_get(const Evas_Object *obj)
2294 {
2295    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2296    Widget_Data *wd = elm_widget_data_get(obj);
2297    if (!wd) return EINA_FALSE;
2298    return wd->multi;
2299 }
2300
2301 EAPI Elm_Gen_Item *
2302 elm_gengrid_selected_item_get(const Evas_Object *obj)
2303 {
2304    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2305    Widget_Data *wd = elm_widget_data_get(obj);
2306    if (!wd) return NULL;
2307    if (wd->selected) return wd->selected->data;
2308    return NULL;
2309 }
2310
2311 EAPI const Eina_List *
2312 elm_gengrid_selected_items_get(const Evas_Object *obj)
2313 {
2314    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2315    Widget_Data *wd = elm_widget_data_get(obj);
2316    if (!wd) return NULL;
2317    return wd->selected;
2318 }
2319
2320 EAPI void
2321 elm_gengrid_item_selected_set(Elm_Gen_Item *it,
2322                               Eina_Bool         selected)
2323 {
2324    elm_genlist_item_selected_set(it, selected);
2325 }
2326
2327 EAPI Eina_Bool
2328 elm_gengrid_item_selected_get(const Elm_Gen_Item *it)
2329 {
2330    return elm_genlist_item_selected_get(it);
2331 }
2332
2333 EAPI void
2334 elm_gengrid_item_disabled_set(Elm_Gen_Item *it,
2335                               Eina_Bool         disabled)
2336 {
2337    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2338    if (it->disabled == disabled) return;
2339    if (it->generation < it->wd->generation) return;
2340    it->disabled = !!disabled;
2341    if (it->realized)
2342      {
2343         if (it->disabled)
2344           edje_object_signal_emit(VIEW(it), "elm,state,disabled", "elm");
2345         else
2346           edje_object_signal_emit(VIEW(it), "elm,state,enabled", "elm");
2347      }
2348 }
2349
2350 EAPI Eina_Bool
2351 elm_gengrid_item_disabled_get(const Elm_Gen_Item *it)
2352 {
2353    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
2354    if (it->generation < it->wd->generation) return EINA_FALSE;
2355    return it->disabled;
2356 }
2357
2358 static Evas_Object *
2359 _elm_gengrid_item_label_create(void        *data,
2360                                Evas_Object *obj __UNUSED__,
2361                                Evas_Object *tooltip,
2362                                void *it   __UNUSED__)
2363 {
2364    Evas_Object *label = elm_label_add(tooltip);
2365    if (!label)
2366      return NULL;
2367    elm_object_style_set(label, "tooltip");
2368    elm_object_text_set(label, data);
2369    return label;
2370 }
2371
2372 static void
2373 _elm_gengrid_item_label_del_cb(void            *data,
2374                                Evas_Object *obj __UNUSED__,
2375                                void *event_info __UNUSED__)
2376 {
2377    eina_stringshare_del(data);
2378 }
2379
2380 EAPI void
2381 elm_gengrid_item_tooltip_text_set(Elm_Gen_Item *it,
2382                                   const char       *text)
2383 {
2384    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2385    text = eina_stringshare_add(text);
2386    elm_gengrid_item_tooltip_content_cb_set(it, _elm_gengrid_item_label_create,
2387                                            text,
2388                                            _elm_gengrid_item_label_del_cb);
2389 }
2390
2391 EAPI void
2392 elm_gengrid_item_tooltip_content_cb_set(Elm_Gen_Item           *it,
2393                                         Elm_Tooltip_Item_Content_Cb func,
2394                                         const void                 *data,
2395                                         Evas_Smart_Cb               del_cb)
2396 {
2397    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(it, error);
2398
2399    if ((it->tooltip.content_cb == func) && (it->tooltip.data == data))
2400      return;
2401
2402    if (it->tooltip.del_cb)
2403      it->tooltip.del_cb((void *)it->tooltip.data,
2404                           WIDGET(it), it);
2405    it->tooltip.content_cb = func;
2406    it->tooltip.data = data;
2407    it->tooltip.del_cb = del_cb;
2408    if (VIEW(it))
2409      {
2410         elm_widget_item_tooltip_content_cb_set(it,
2411                                                it->tooltip.content_cb,
2412                                                it->tooltip.data, NULL);
2413         elm_widget_item_tooltip_style_set(it, it->tooltip.style);
2414         elm_widget_item_tooltip_window_mode_set(it, it->tooltip.free_size);
2415      }
2416
2417    return;
2418
2419 error:
2420    if (del_cb) del_cb((void *)data, NULL, NULL);
2421 }
2422
2423 EAPI void
2424 elm_gengrid_item_tooltip_unset(Elm_Gen_Item *it)
2425 {
2426    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2427    if ((VIEW(it)) && (it->tooltip.content_cb))
2428      elm_widget_item_tooltip_unset(it);
2429
2430    if (it->tooltip.del_cb)
2431      it->tooltip.del_cb((void *)it->tooltip.data, WIDGET(it), it);
2432    it->tooltip.del_cb = NULL;
2433    it->tooltip.content_cb = NULL;
2434    it->tooltip.data = NULL;
2435    it->tooltip.free_size = EINA_FALSE;
2436    if (it->tooltip.style)
2437      elm_gengrid_item_tooltip_style_set(it, NULL);
2438 }
2439
2440 EAPI void
2441 elm_gengrid_item_tooltip_style_set(Elm_Gen_Item *it,
2442                                    const char       *style)
2443 {
2444    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2445    eina_stringshare_replace(&it->tooltip.style, style);
2446    if (VIEW(it)) elm_widget_item_tooltip_style_set(it, style);
2447 }
2448
2449 EAPI const char *
2450 elm_gengrid_item_tooltip_style_get(const Elm_Gen_Item *it)
2451 {
2452    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
2453    return it->tooltip.style;
2454 }
2455
2456 EAPI Eina_Bool
2457 elm_gengrid_item_tooltip_window_mode_set(Elm_Gen_Item *it, Eina_Bool disable)
2458 {
2459    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
2460    it->tooltip.free_size = disable;
2461    if (VIEW(it)) return elm_widget_item_tooltip_window_mode_set(it, disable);
2462    return EINA_TRUE;
2463 }
2464
2465 EAPI Eina_Bool
2466 elm_gengrid_item_tooltip_window_mode_get(const Elm_Gen_Item *it)
2467 {
2468    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
2469    return it->tooltip.free_size;
2470 }
2471
2472 EAPI void
2473 elm_gengrid_item_cursor_set(Elm_Gen_Item *it,
2474                             const char       *cursor)
2475 {
2476    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2477    eina_stringshare_replace(&it->mouse_cursor, cursor);
2478    if (VIEW(it)) elm_widget_item_cursor_set(it, cursor);
2479 }
2480
2481 EAPI const char *
2482 elm_gengrid_item_cursor_get(const Elm_Gen_Item *it)
2483 {
2484    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
2485    return elm_widget_item_cursor_get(it);
2486 }
2487
2488 EAPI void
2489 elm_gengrid_item_cursor_unset(Elm_Gen_Item *it)
2490 {
2491    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2492    if (!it->mouse_cursor)
2493      return;
2494
2495    if (VIEW(it))
2496      elm_widget_item_cursor_unset(it);
2497
2498    eina_stringshare_del(it->mouse_cursor);
2499    it->mouse_cursor = NULL;
2500 }
2501
2502 EAPI void
2503 elm_gengrid_item_cursor_style_set(Elm_Gen_Item *it,
2504                                   const char       *style)
2505 {
2506    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2507    elm_widget_item_cursor_style_set(it, style);
2508 }
2509
2510 EAPI const char *
2511 elm_gengrid_item_cursor_style_get(const Elm_Gen_Item *it)
2512 {
2513    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
2514    return elm_widget_item_cursor_style_get(it);
2515 }
2516
2517 EAPI void
2518 elm_gengrid_item_cursor_engine_only_set(Elm_Gen_Item *it,
2519                                         Eina_Bool         engine_only)
2520 {
2521    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2522    elm_widget_item_cursor_engine_only_set(it, engine_only);
2523 }
2524
2525 EAPI Eina_Bool
2526 elm_gengrid_item_cursor_engine_only_get(const Elm_Gen_Item *it)
2527 {
2528    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
2529    return elm_widget_item_cursor_engine_only_get(it);
2530 }
2531
2532 EAPI void
2533 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2534                              Eina_Bool    reorder_mode)
2535 {
2536    ELM_CHECK_WIDTYPE(obj, widtype);
2537    Widget_Data *wd = elm_widget_data_get(obj);
2538    if (!wd) return;
2539    wd->reorder_mode = reorder_mode;
2540 }
2541
2542 EAPI Eina_Bool
2543 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
2544 {
2545    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2546    Widget_Data *wd = elm_widget_data_get(obj);
2547    if (!wd) return EINA_FALSE;
2548    return wd->reorder_mode;
2549 }
2550
2551 EAPI void
2552 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2553                                    Eina_Bool    always_select)
2554 {
2555    elm_genlist_always_select_mode_set(obj, always_select);
2556 }
2557
2558 EAPI Eina_Bool
2559 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2560 {
2561    return elm_genlist_always_select_mode_get(obj);
2562 }
2563
2564 EAPI void
2565 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2566                                Eina_Bool    no_select)
2567 {
2568    elm_genlist_no_select_mode_set(obj, no_select);
2569 }
2570
2571 EAPI Eina_Bool
2572 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2573 {
2574    return elm_genlist_no_select_mode_get(obj);
2575 }
2576
2577 EAPI void
2578 elm_gengrid_bounce_set(Evas_Object *obj,
2579                        Eina_Bool    h_bounce,
2580                        Eina_Bool    v_bounce)
2581 {
2582    elm_genlist_bounce_set(obj, h_bounce, v_bounce);
2583 }
2584
2585 EAPI void
2586 elm_gengrid_bounce_get(const Evas_Object *obj,
2587                        Eina_Bool         *h_bounce,
2588                        Eina_Bool         *v_bounce)
2589 {
2590    elm_genlist_bounce_get(obj, h_bounce, v_bounce);
2591 }
2592
2593 EAPI void
2594 elm_gengrid_page_relative_set(Evas_Object *obj,
2595                               double       h_pagerel,
2596                               double       v_pagerel)
2597 {
2598    _elm_genlist_page_relative_set(obj, h_pagerel, v_pagerel);
2599 }
2600
2601 EAPI void
2602 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
2603 {
2604    _elm_genlist_page_relative_get(obj, h_pagerel, v_pagerel);
2605 }
2606
2607 EAPI void
2608 elm_gengrid_page_size_set(Evas_Object *obj,
2609                           Evas_Coord   h_pagesize,
2610                           Evas_Coord   v_pagesize)
2611 {
2612    _elm_genlist_page_size_set(obj, h_pagesize, v_pagesize);
2613 }
2614
2615 EAPI void
2616 elm_gengrid_current_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2617 {
2618    _elm_genlist_current_page_get(obj, h_pagenumber, v_pagenumber);
2619 }
2620
2621 EAPI void
2622 elm_gengrid_last_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2623 {
2624    _elm_genlist_last_page_get(obj, h_pagenumber, v_pagenumber);
2625 }
2626
2627 EAPI void
2628 elm_gengrid_page_show(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2629 {
2630    _elm_genlist_page_show(obj, h_pagenumber, v_pagenumber);
2631 }
2632
2633 EAPI void
2634 elm_gengrid_page_bring_in(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2635 {
2636    _elm_genlist_page_bring_in(obj, h_pagenumber, v_pagenumber);
2637 }
2638
2639 EAPI Elm_Gen_Item *
2640 elm_gengrid_first_item_get(const Evas_Object *obj)
2641 {
2642    return elm_genlist_first_item_get(obj);
2643 }
2644
2645 EAPI Elm_Gen_Item *
2646 elm_gengrid_last_item_get(const Evas_Object *obj)
2647 {
2648    return elm_genlist_last_item_get(obj);
2649 }
2650
2651 EAPI Elm_Gen_Item *
2652 elm_gengrid_item_next_get(const Elm_Gen_Item *it)
2653 {
2654    return elm_genlist_item_next_get(it);
2655 }
2656
2657 EAPI Elm_Gen_Item *
2658 elm_gengrid_item_prev_get(const Elm_Gen_Item *it)
2659 {
2660    return elm_genlist_item_prev_get(it);
2661 }
2662
2663 EAPI Evas_Object *
2664 elm_gengrid_item_gengrid_get(const Elm_Gen_Item *it)
2665 {
2666    return _elm_genlist_item_widget_get(it);
2667 }
2668
2669 EAPI void
2670 elm_gengrid_item_show(Elm_Gen_Item *it)
2671 {
2672    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2673    Widget_Data *wd = it->wd;
2674    Evas_Coord minx = 0, miny = 0;
2675
2676    if (!wd) return;
2677    if ((!it) || (it->generation < it->wd->generation)) return;
2678    _pan_min_get(wd->pan_smart, &minx, &miny);
2679
2680    if (wd->horizontal)
2681      elm_smart_scroller_region_bring_in(it->wd->scr,
2682                                         ((it->x - it->item->prev_group) * wd->item_width) + (it->item->prev_group * it->wd->group_item_width) + minx,
2683                                         it->y * wd->item_height + miny,
2684                                         it->wd->item_width,
2685                                         it->wd->item_height);
2686    else
2687      elm_smart_scroller_region_bring_in(it->wd->scr,
2688                                         it->x * wd->item_width + minx,
2689                                         ((it->y - it->item->prev_group)* wd->item_height) + (it->item->prev_group * it->wd->group_item_height) + miny,
2690                                         it->wd->item_width,
2691                                         it->wd->item_height);
2692 }
2693
2694 EAPI void
2695 elm_gengrid_item_bring_in(Elm_Gen_Item *it)
2696 {
2697    ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
2698    if (it->generation < it->wd->generation) return;
2699
2700    Evas_Coord minx = 0, miny = 0;
2701    Widget_Data *wd = it->wd;
2702    if (!wd) return;
2703    _pan_min_get(wd->pan_smart, &minx, &miny);
2704
2705    if (wd->horizontal)
2706      elm_smart_scroller_region_bring_in(it->wd->scr,
2707                                         ((it->x - it->item->prev_group) * wd->item_width) + (it->item->prev_group * it->wd->group_item_width) + minx,
2708                                         it->y * wd->item_height + miny,
2709                                         it->wd->item_width,
2710                                         it->wd->item_height);
2711    else
2712      elm_smart_scroller_region_bring_in(it->wd->scr,
2713                                         it->x * wd->item_width + minx,
2714                                         ((it->y - it->item->prev_group)* wd->item_height) + (it->item->prev_group * it->wd->group_item_height) + miny,
2715                                         it->wd->item_width,
2716                                         it->wd->item_height);
2717 }