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