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