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