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