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