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