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