elm genlist: Fixed genlist crash issue when huge amount of items are expanded/contrac...
[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_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    tt = REORDER_EFFECT_TIME;
1060    t = ((0.0 > (t = ecore_loop_time_get()-it->item->moving_effect_start_time)) ? 0.0 : t);
1061    dx = ((it->item->tx - it->item->ox) / 10) * _elm_config->scale;
1062    dy = ((it->item->ty - it->item->oy) / 10) * _elm_config->scale;
1063
1064    if (t <= tt)
1065      {
1066         it->item->rx += (1 * sin((t / tt) * (M_PI / 2)) * dx);
1067         it->item->ry += (1 * sin((t / tt) * (M_PI / 2)) * dy);
1068      }
1069    else
1070      {
1071         it->item->rx += dx;
1072         it->item->ry += dy;
1073      }
1074
1075    if ((((dx > 0) && (it->item->rx >= it->item->tx)) || ((dx <= 0) && (it->item->rx <= it->item->tx))) &&
1076        (((dy > 0) && (it->item->ry >= it->item->ty)) || ((dy <= 0) && (it->item->ry <= it->item->ty))))
1077      {
1078         evas_object_move(VIEW(it), it->item->tx, it->item->ty);
1079         if (it->group)
1080           {
1081              Evas_Coord vw, vh;
1082              evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &vw, &vh);
1083              if (it->wd->horizontal)
1084                evas_object_resize(VIEW(it), it->wd->group_item_width, vh);
1085              else
1086                evas_object_resize(VIEW(it), vw, it->wd->group_item_height);
1087           }
1088         else
1089           evas_object_resize(VIEW(it), it->wd->item_width, it->wd->item_height);
1090         it->item->moving = EINA_FALSE;
1091         it->item->item_reorder_move_animator = NULL;
1092         return ECORE_CALLBACK_CANCEL;
1093      }
1094
1095    evas_object_move(VIEW(it), it->item->rx, it->item->ry);
1096    if (it->group)
1097      {
1098         Evas_Coord vw, vh;
1099         evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &vw, &vh);
1100         if (it->wd->horizontal)
1101           evas_object_resize(VIEW(it), it->wd->group_item_width, vh);
1102         else
1103           evas_object_resize(VIEW(it), vw, it->wd->group_item_height);
1104      }
1105    else
1106      evas_object_resize(VIEW(it), it->wd->item_width, it->wd->item_height);
1107
1108    return ECORE_CALLBACK_RENEW;
1109 }
1110
1111 static void
1112 _group_item_place(Pan *sd)
1113 {
1114    Evas_Coord iw, ih, vw, vh;
1115    Eina_List *l;
1116    Eina_Bool was_realized;
1117    Elm_Gen_Item *it;
1118    evas_object_geometry_get(sd->wd->pan_smart, NULL, NULL, &vw, &vh);
1119    if (sd->wd->horizontal)
1120      {
1121         iw = sd->wd->group_item_width;
1122         ih = vh;
1123      }
1124    else
1125      {
1126         iw = vw;
1127         ih = sd->wd->group_item_height;
1128      }
1129    EINA_LIST_FOREACH(sd->wd->group_items, l, it)
1130      {
1131         was_realized = it->realized;
1132         if (it->item->group_realized)
1133           {
1134              _item_realize(it);
1135              if (!was_realized)
1136                evas_object_smart_callback_call(WIDGET(it), SIG_REALIZED, it);
1137              evas_object_move(VIEW(it), it->item->gx, it->item->gy);
1138              evas_object_resize(VIEW(it), iw, ih);
1139              evas_object_raise(VIEW(it));
1140           }
1141         else
1142           _elm_genlist_item_unrealize(it, EINA_FALSE);
1143      }
1144 }
1145
1146
1147 static void
1148 _item_place(Elm_Gen_Item *it,
1149             Evas_Coord    cx,
1150             Evas_Coord    cy)
1151 {
1152    Evas_Coord x, y, ox, oy, cvx, cvy, cvw, cvh, iw, ih, ww;
1153    Evas_Coord tch, tcw, alignw = 0, alignh = 0, vw, vh;
1154    Eina_Bool reorder_item_move_forward = EINA_FALSE;
1155    long items_count;
1156    it->x = cx;
1157    it->y = cy;
1158    evas_object_geometry_get(it->wd->pan_smart, &ox, &oy, &vw, &vh);
1159
1160    /* Preload rows/columns at each side of the Gengrid */
1161    cvx = ox - PRELOAD * it->wd->item_width;
1162    cvy = oy - PRELOAD * it->wd->item_height;
1163    cvw = vw + 2 * PRELOAD * it->wd->item_width;
1164    cvh = vh + 2 * PRELOAD * it->wd->item_height;
1165
1166    alignh = 0;
1167    alignw = 0;
1168
1169    items_count = it->wd->item_count - eina_list_count(it->wd->group_items) + it->wd->items_lost;
1170    if (it->wd->horizontal)
1171      {
1172         int columns, items_visible = 0, items_row;
1173
1174         if (it->wd->item_height > 0)
1175           items_visible = vh / it->wd->item_height;
1176         if (items_visible < 1)
1177           items_visible = 1;
1178
1179         columns = items_count / items_visible;
1180         if (items_count % items_visible)
1181           columns++;
1182
1183         tcw = (it->wd->item_width * columns) + (it->wd->group_item_width * eina_list_count(it->wd->group_items));
1184         alignw = (vw - tcw) * it->wd->align_x;
1185
1186         items_row = items_visible;
1187         if ((unsigned int)items_row > it->wd->item_count)
1188           items_row = it->wd->item_count;
1189          if (it->wd->filled
1190              && (unsigned int)it->wd->nmax > (unsigned int)it->wd->item_count)
1191            tch = it->wd->nmax * it->wd->item_height;
1192          else
1193            tch = items_row * it->wd->item_height;
1194         alignh = (vh - tch) * it->wd->align_y;
1195      }
1196    else
1197      {
1198         unsigned int rows, items_visible = 0, items_col;
1199
1200         if (it->wd->item_width > 0)
1201           items_visible = vw / it->wd->item_width;
1202         if (items_visible < 1)
1203           items_visible = 1;
1204
1205         rows = items_count / items_visible;
1206         if (items_count % items_visible)
1207           rows++;
1208
1209         tch = (it->wd->item_height * rows) + (it->wd->group_item_height * eina_list_count(it->wd->group_items));
1210         alignh = (vh - tch) * it->wd->align_y;
1211
1212         items_col = items_visible;
1213         if (items_col > it->wd->item_count)
1214           items_col = it->wd->item_count;
1215          if (it->wd->filled
1216              && (unsigned int)it->wd->nmax > (unsigned int)it->wd->item_count)
1217            tcw = it->wd->nmax * it->wd->item_width;
1218          else
1219            tcw = items_col * it->wd->item_width;
1220         alignw = (vw - tcw) * it->wd->align_x;
1221      }
1222
1223    if (it->group)
1224      {
1225         if (it->wd->horizontal)
1226           {
1227              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;
1228              y = oy;
1229              iw = it->wd->group_item_width;
1230              ih = vh;
1231           }
1232         else
1233           {
1234              x = ox;
1235              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;
1236              iw = vw;
1237              ih = it->wd->group_item_height;
1238           }
1239         it->item->gx = x;
1240         it->item->gy = y;
1241      }
1242    else
1243      {
1244         if (it->wd->horizontal)
1245           {
1246              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;
1247              y = (cy * it->wd->item_height) - it->wd->pan_y + oy + alignh;
1248           }
1249         else
1250           {
1251              x = (cx * it->wd->item_width) - it->wd->pan_x + ox + alignw;
1252              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;
1253           }
1254         if (elm_widget_mirrored_get(WIDGET(it)))
1255           {  /* Switch items side and componsate for pan_x when in RTL mode */
1256              evas_object_geometry_get(WIDGET(it), NULL, NULL, &ww, NULL);
1257              x = ww - x - it->wd->item_width - it->wd->pan_x - it->wd->pan_x;
1258           }
1259         iw = it->wd->item_width;
1260         ih = it->wd->item_height;
1261      }
1262
1263    Eina_Bool was_realized = it->realized;
1264    if (ELM_RECTS_INTERSECT(x, y, iw, ih, cvx, cvy, cvw, cvh))
1265      {
1266         _item_realize(it);
1267         if (!was_realized)
1268           evas_object_smart_callback_call(WIDGET(it), SIG_REALIZED, it);
1269         if (it->parent)
1270           {
1271              if (it->wd->horizontal)
1272                {
1273                   if (it->parent->item->gx < ox)
1274                     {
1275                        it->parent->item->gx = x + it->wd->item_width - it->wd->group_item_width;
1276                        if (it->parent->item->gx > ox)
1277                          it->parent->item->gx = ox;
1278                     }
1279                   it->parent->item->group_realized = EINA_TRUE;
1280                }
1281              else
1282                {
1283                   if (it->parent->item->gy < oy)
1284                     {
1285                        it->parent->item->gy = y + it->wd->item_height - it->wd->group_item_height;
1286                        if (it->parent->item->gy > oy)
1287                          it->parent->item->gy = oy;
1288                     }
1289                   it->parent->item->group_realized = EINA_TRUE;
1290                }
1291           }
1292         if (it->wd->reorder_mode)
1293           {
1294              if (it->wd->reorder_it)
1295                {
1296                   if (it->item->moving) return;
1297
1298                   if (!it->wd->move_effect_enabled)
1299                     {
1300                        it->item->ox = x;
1301                        it->item->oy = y;
1302                     }
1303                   if (it->wd->reorder_it == it)
1304                     {
1305                        evas_object_move(VIEW(it),
1306                                         it->wd->reorder_item_x, it->wd->reorder_item_y);
1307                        evas_object_resize(VIEW(it), iw, ih);
1308                        return;
1309                     }
1310                   else
1311                     {
1312                        if (it->wd->move_effect_enabled)
1313                          {
1314                             if ((it->item->ox != x) || (it->item->oy != y))
1315                               {
1316                                  if (((it->wd->old_pan_x == it->wd->pan_x) && (it->wd->old_pan_y == it->wd->pan_y)) ||
1317                                      ((it->wd->old_pan_x != it->wd->pan_x) && !(it->item->ox - it->wd->pan_x + it->wd->old_pan_x == x)) ||
1318                                      ((it->wd->old_pan_y != it->wd->pan_y) && !(it->item->oy - it->wd->pan_y + it->wd->old_pan_y == y)))
1319                                    {
1320                                       it->item->tx = x;
1321                                       it->item->ty = y;
1322                                       it->item->rx = it->item->ox;
1323                                       it->item->ry = it->item->oy;
1324                                       it->item->moving = EINA_TRUE;
1325                                       it->item->moving_effect_start_time = ecore_loop_time_get();
1326                                       it->item->item_reorder_move_animator = ecore_animator_add(_reorder_item_move_animator_cb, it);
1327                                       return;
1328                                    }
1329                               }
1330                          }
1331
1332                        /* need fix here */
1333                        Evas_Coord nx, ny, nw, nh;
1334                        if (it->group)
1335                          {
1336                             if (it->wd->horizontal)
1337                               {
1338                                  nx = x + (it->wd->group_item_width / 2);
1339                                  ny = y;
1340                                  nw = 1;
1341                                  nh = vh;
1342                               }
1343                             else
1344                               {
1345                                  nx = x;
1346                                  ny = y + (it->wd->group_item_height / 2);
1347                                  nw = vw;
1348                                  nh = 1;
1349                               }
1350                          }
1351                        else
1352                          {
1353                             nx = x + (it->wd->item_width / 2);
1354                             ny = y + (it->wd->item_height / 2);
1355                             nw = 1;
1356                             nh = 1;
1357                          }
1358
1359                        if ( ELM_RECTS_INTERSECT(it->wd->reorder_item_x, it->wd->reorder_item_y,
1360                                                 it->wd->item_width, it->wd->item_height,
1361                                                 nx, ny, nw, nh))
1362                          {
1363                             if (it->wd->horizontal)
1364                               {
1365                                  if ((it->wd->nmax * it->wd->reorder_it->x + it->wd->reorder_it->y) >
1366                                      (it->wd->nmax * it->x + it->y))
1367                                    reorder_item_move_forward = EINA_TRUE;
1368                               }
1369                             else
1370                               {
1371                                  if ((it->wd->nmax * it->wd->reorder_it->y + it->wd->reorder_it->x) >
1372                                      (it->wd->nmax * it->y + it->x))
1373                                    reorder_item_move_forward = EINA_TRUE;
1374                               }
1375
1376                             it->wd->items = eina_inlist_remove(it->wd->items,
1377                                                                  EINA_INLIST_GET(it->wd->reorder_it));
1378                             if (reorder_item_move_forward)
1379                               it->wd->items = eina_inlist_prepend_relative(it->wd->items,
1380                                                                              EINA_INLIST_GET(it->wd->reorder_it),
1381                                                                              EINA_INLIST_GET(it));
1382                             else
1383                               it->wd->items = eina_inlist_append_relative(it->wd->items,
1384                                                                             EINA_INLIST_GET(it->wd->reorder_it),
1385                                                                             EINA_INLIST_GET(it));
1386
1387                             it->wd->reorder_item_changed = EINA_TRUE;
1388                             it->wd->move_effect_enabled = EINA_TRUE;
1389                             if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
1390                               it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
1391
1392                             return;
1393                          }
1394                     }
1395                }
1396              else if (it->item->item_reorder_move_animator)
1397                {
1398                   ecore_animator_del(it->item->item_reorder_move_animator);
1399                   it->item->item_reorder_move_animator = NULL;
1400                   it->item->moving = EINA_FALSE;
1401                }
1402           }
1403         if (!it->group)
1404           {
1405              evas_object_move(VIEW(it), x, y);
1406              evas_object_resize(VIEW(it), iw, ih);
1407           }
1408         else
1409           it->item->group_realized = EINA_TRUE;
1410      }
1411    else
1412      {
1413         if (!it->group)
1414           _elm_genlist_item_unrealize(it, EINA_FALSE);
1415         else
1416           it->item->group_realized = EINA_FALSE;
1417      }
1418 }
1419
1420 static void
1421 _item_position_update(Eina_Inlist *list, int idx)
1422 {
1423    Elm_Gen_Item *it;
1424
1425    EINA_INLIST_FOREACH(list, it)
1426      {
1427         it->position = idx++;
1428         it->position_update = EINA_TRUE;
1429      }
1430 }
1431
1432 static void
1433 _item_del(Elm_Gen_Item *it)
1434 {
1435    Evas_Object *obj = WIDGET(it);
1436
1437    evas_event_freeze(evas_object_evas_get(obj));
1438    it->wd->selected = eina_list_remove(it->wd->selected, it);
1439    if (it->realized) _elm_genlist_item_unrealize(it, EINA_FALSE);
1440    _elm_genlist_item_del_serious(it);
1441    elm_gengrid_item_class_unref((Elm_Gengrid_Item_Class *)it->itc);
1442    evas_event_thaw(evas_object_evas_get(obj));
1443    evas_event_thaw_eval(evas_object_evas_get(obj));
1444 }
1445
1446 static void
1447 _item_unselect(Elm_Gen_Item *it)
1448 {
1449    if ((it->generation < it->wd->generation) || (!it->highlighted)) return;
1450    edje_object_signal_emit(VIEW(it), "elm,state,unselected", "elm");
1451    it->highlighted = EINA_FALSE;
1452    if (it->selected)
1453      {
1454         it->selected = EINA_FALSE;
1455         it->wd->selected = eina_list_remove(it->wd->selected, it);
1456         evas_object_smart_callback_call(WIDGET(it), SIG_UNSELECTED, it);
1457      }
1458 }
1459
1460 static void
1461 _calc_job(void *data)
1462 {
1463    Widget_Data *wd = data;
1464    Evas_Coord minw = 0, minh = 0, nmax = 0, cvw, cvh;
1465    Elm_Gen_Item *it, *group_item = NULL;
1466    int count_group = 0;
1467    long count = 0;
1468    wd->items_lost = 0;
1469
1470    evas_object_geometry_get(wd->pan_smart, NULL, NULL, &cvw, &cvh);
1471    if ((cvw != 0) || (cvh != 0))
1472      {
1473         if ((wd->horizontal) && (wd->item_height > 0))
1474           nmax = cvh / wd->item_height;
1475         else if (wd->item_width > 0)
1476           nmax = cvw / wd->item_width;
1477
1478         if (nmax < 1)
1479           nmax = 1;
1480
1481         EINA_INLIST_FOREACH(wd->items, it)
1482           {
1483              if (it->item->prev_group != count_group)
1484                it->item->prev_group = count_group;
1485              if (it->group)
1486                {
1487                   count = count % nmax;
1488                   if (count)
1489                     wd->items_lost += nmax - count;
1490                   //printf("%d items and I lost %d\n", count, wd->items_lost);
1491                   count_group++;
1492                   if (count) count = 0;
1493                   group_item = it;
1494                }
1495              else
1496                {
1497                   if (it->parent != group_item)
1498                     it->parent = group_item;
1499                   count++;
1500                }
1501           }
1502         count = wd->item_count + wd->items_lost - count_group;
1503         if (wd->horizontal)
1504           {
1505              minw = (ceil(count / (float)nmax) * wd->item_width) + (count_group * wd->group_item_width);
1506              minh = nmax * wd->item_height;
1507           }
1508         else
1509           {
1510              minw = nmax * wd->item_width;
1511              minh = (ceil(count / (float)nmax) * wd->item_height) + (count_group * wd->group_item_height);
1512           }
1513
1514         if ((minw != wd->minw) || (minh != wd->minh))
1515           {
1516              wd->minh = minh;
1517              wd->minw = minw;
1518              evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1519           }
1520
1521         wd->nmax = nmax;
1522         evas_object_smart_changed(wd->pan_smart);
1523      }
1524    wd->calc_job = NULL;
1525 }
1526
1527 static void
1528 _pan_add(Evas_Object *obj)
1529 {
1530    Pan *sd;
1531    Evas_Object_Smart_Clipped_Data *cd;
1532
1533    _pan_sc.add(obj);
1534    cd = evas_object_smart_data_get(obj);
1535    sd = ELM_NEW(Pan);
1536    if (!sd) return;
1537    sd->__clipped_data = *cd;
1538    free(cd);
1539    evas_object_smart_data_set(obj, sd);
1540 }
1541
1542 static void
1543 _pan_del(Evas_Object *obj)
1544 {
1545    Pan *sd = evas_object_smart_data_get(obj);
1546
1547    if (!sd) return;
1548    _pan_sc.del(obj);
1549 }
1550
1551 static void
1552 _pan_set(Evas_Object *obj,
1553          Evas_Coord   x,
1554          Evas_Coord   y)
1555 {
1556    Pan *sd = evas_object_smart_data_get(obj);
1557    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1558    sd->wd->pan_x = x;
1559    sd->wd->pan_y = y;
1560    evas_object_smart_changed(obj);
1561 }
1562
1563 static void
1564 _pan_get(Evas_Object *obj,
1565          Evas_Coord  *x,
1566          Evas_Coord  *y)
1567 {
1568    Pan *sd = evas_object_smart_data_get(obj);
1569    if (x) *x = sd->wd->pan_x;
1570    if (y) *y = sd->wd->pan_y;
1571 }
1572
1573 static void
1574 _pan_child_size_get(Evas_Object *obj,
1575                     Evas_Coord  *w,
1576                     Evas_Coord  *h)
1577 {
1578    Pan *sd = evas_object_smart_data_get(obj);
1579    if (w) *w = sd->wd->minw;
1580    if (h) *h = sd->wd->minh;
1581 }
1582
1583 static void
1584 _pan_max_get(Evas_Object *obj,
1585              Evas_Coord  *x,
1586              Evas_Coord  *y)
1587 {
1588    Pan *sd = evas_object_smart_data_get(obj);
1589    Evas_Coord ow, oh;
1590
1591    if (!sd) return;
1592    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1593    if (x)
1594      *x = (ow < sd->wd->minw) ? sd->wd->minw - ow : 0;
1595    if (y)
1596      *y = (oh < sd->wd->minh) ? sd->wd->minh - oh : 0;
1597 }
1598
1599 static void
1600 _pan_min_get(Evas_Object *obj,
1601              Evas_Coord  *x,
1602              Evas_Coord  *y)
1603 {
1604    Pan *sd = evas_object_smart_data_get(obj);
1605    Evas_Coord mx = 0, my = 0;
1606
1607    if (!sd) return;
1608    _pan_max_get(obj, &mx, &my);
1609    if (x)
1610      *x = -mx * sd->wd->align_x;
1611    if (y)
1612      *y = -my * sd->wd->align_y;
1613 }
1614
1615 static void
1616 _pan_resize(Evas_Object *obj,
1617             Evas_Coord   w,
1618             Evas_Coord   h)
1619 {
1620    Pan *sd = evas_object_smart_data_get(obj);
1621    Evas_Coord ow, oh;
1622
1623    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1624    if ((ow == w) && (oh == h)) return;
1625    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1626    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1627 }
1628
1629 static void
1630 _pan_calculate(Evas_Object *obj)
1631 {
1632    Pan *sd = evas_object_smart_data_get(obj);
1633    Evas_Coord cx = 0, cy = 0;
1634    Elm_Gen_Item *it;
1635
1636    if (!sd) return;
1637    if (!sd->wd->nmax) return;
1638
1639    sd->wd->reorder_item_changed = EINA_FALSE;
1640
1641    EINA_INLIST_FOREACH(sd->wd->items, it)
1642      {
1643         if (it->group)
1644           {
1645              if (sd->wd->horizontal)
1646                {
1647                   if (cy)
1648                     {
1649                        cx++;
1650                        cy = 0;
1651                     }
1652                }
1653              else
1654                {
1655                   if (cx)
1656                     {
1657                        cx = 0;
1658                        cy++;
1659                     }
1660                }
1661           }
1662         _item_place(it, cx, cy);
1663         if (sd->wd->reorder_item_changed) return;
1664         if (it->group)
1665           {
1666              if (sd->wd->horizontal)
1667                {
1668                   cx++;
1669                   cy = 0;
1670                }
1671              else
1672                {
1673                   cx = 0;
1674                   cy++;
1675                }
1676           }
1677         else
1678           {
1679              if (sd->wd->horizontal)
1680                {
1681                   cy = (cy + 1) % sd->wd->nmax;
1682                   if (!cy) cx++;
1683                }
1684              else
1685                {
1686                   cx = (cx + 1) % sd->wd->nmax;
1687                   if (!cx) cy++;
1688                }
1689           }
1690      }
1691    _group_item_place(sd);
1692
1693
1694    if ((sd->wd->reorder_mode) && (sd->wd->reorder_it))
1695      {
1696         if (!sd->wd->reorder_item_changed)
1697           {
1698              sd->wd->old_pan_x = sd->wd->pan_x;
1699              sd->wd->old_pan_y = sd->wd->pan_y;
1700           }
1701         sd->wd->move_effect_enabled = EINA_FALSE;
1702      }
1703    evas_object_smart_callback_call(sd->wd->obj, SIG_CHANGED, NULL);
1704 }
1705
1706 static void
1707 _pan_move(Evas_Object *obj,
1708           Evas_Coord x __UNUSED__,
1709           Evas_Coord y __UNUSED__)
1710 {
1711    Pan *sd = evas_object_smart_data_get(obj);
1712    if (!sd) return;
1713    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1714    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1715 }
1716
1717 static void
1718 _hold_on(void        *data  __UNUSED__,
1719          Evas_Object *obj,
1720          void        *event_info __UNUSED__)
1721 {
1722    Widget_Data *wd = elm_widget_data_get(obj);
1723    if (!wd) return;
1724    elm_smart_scroller_hold_set(wd->scr, 1);
1725 }
1726
1727 static void
1728 _hold_off(void        *data __UNUSED__,
1729           Evas_Object *obj,
1730           void        *event_info __UNUSED__)
1731 {
1732    Widget_Data *wd = elm_widget_data_get(obj);
1733    if (!wd) return;
1734    elm_smart_scroller_hold_set(wd->scr, 0);
1735 }
1736
1737 static void
1738 _freeze_on(void        *data __UNUSED__,
1739            Evas_Object *obj,
1740            void        *event_info __UNUSED__)
1741 {
1742    Widget_Data *wd = elm_widget_data_get(obj);
1743    if (!wd) return;
1744    elm_smart_scroller_freeze_set(wd->scr, 1);
1745 }
1746
1747 static void
1748 _freeze_off(void *data       __UNUSED__,
1749             Evas_Object     *obj,
1750             void *event_info __UNUSED__)
1751 {
1752    Widget_Data *wd = elm_widget_data_get(obj);
1753    if (!wd) return;
1754    elm_smart_scroller_freeze_set(wd->scr, 0);
1755 }
1756
1757 static void
1758 _scr_anim_start(void        *data,
1759                 Evas_Object *obj __UNUSED__,
1760                 void        *event_info __UNUSED__)
1761 {
1762    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
1763 }
1764
1765 static void
1766 _scr_anim_stop(void        *data,
1767                Evas_Object *obj __UNUSED__,
1768                void        *event_info __UNUSED__)
1769 {
1770    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
1771 }
1772
1773 static void
1774 _scr_drag_start(void            *data,
1775                 Evas_Object *obj __UNUSED__,
1776                 void *event_info __UNUSED__)
1777 {
1778    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1779 }
1780
1781 static void
1782 _scr_drag_stop(void            *data,
1783                Evas_Object *obj __UNUSED__,
1784                void *event_info __UNUSED__)
1785 {
1786    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1787 }
1788
1789 static void
1790 _edge_left(void        *data,
1791            Evas_Object *scr __UNUSED__,
1792            void        *event_info __UNUSED__)
1793 {
1794    evas_object_smart_callback_call(data, SIG_EDGE_LEFT, NULL);
1795 }
1796
1797 static void
1798 _edge_right(void        *data,
1799             Evas_Object *scr __UNUSED__,
1800             void        *event_info __UNUSED__)
1801 {
1802    evas_object_smart_callback_call(data, SIG_EDGE_RIGHT, NULL);
1803 }
1804
1805 static void
1806 _edge_top(void        *data,
1807           Evas_Object *scr __UNUSED__,
1808           void        *event_info __UNUSED__)
1809 {
1810    evas_object_smart_callback_call(data, SIG_EDGE_TOP, NULL);
1811 }
1812
1813 static void
1814 _edge_bottom(void        *data,
1815              Evas_Object *scr __UNUSED__,
1816              void        *event_info __UNUSED__)
1817 {
1818    evas_object_smart_callback_call(data, SIG_EDGE_BOTTOM, NULL);
1819 }
1820
1821 static void
1822 _scr_scroll(void            *data,
1823             Evas_Object *obj __UNUSED__,
1824             void *event_info __UNUSED__)
1825 {
1826    evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1827 }
1828
1829 static int
1830 _elm_gengrid_item_compare(const void *data, const void *data1)
1831 {
1832    Elm_Gen_Item *it, *item1;
1833    it = ELM_GEN_ITEM_FROM_INLIST(data);
1834    item1 = ELM_GEN_ITEM_FROM_INLIST(data1);
1835    return it->wd->item_compare_cb(it, item1);
1836 }
1837
1838 static void
1839 _item_disable_hook(Elm_Object_Item *it)
1840 {
1841    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
1842
1843    if (_it->generation < _it->wd->generation) return;
1844
1845    if (_it->realized)
1846      {
1847         if (elm_widget_item_disabled_get(_it))
1848           edje_object_signal_emit(VIEW(_it), "elm,state,disabled", "elm");
1849         else
1850           edje_object_signal_emit(VIEW(_it), "elm,state,enabled", "elm");
1851      }
1852 }
1853
1854 static void
1855 _item_del_pre_hook(Elm_Object_Item *it)
1856 {
1857    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
1858    if ((_it->relcount > 0) || (_it->walking > 0))
1859      {
1860         _elm_genlist_item_del_notserious(_it);
1861         return;
1862      }
1863
1864    _item_del(_it);
1865 }
1866
1867 static Elm_Gen_Item *
1868 _item_new(Widget_Data                  *wd,
1869           const Elm_Gengrid_Item_Class *itc,
1870           const void                   *data,
1871           Evas_Smart_Cb                 func,
1872           const void                   *func_data)
1873 {
1874    Elm_Gen_Item *it;
1875
1876    it = _elm_genlist_item_new(wd, itc, data, NULL, func, func_data);
1877    if (!it) return NULL;
1878    elm_widget_item_disable_hook_set(it, _item_disable_hook);
1879    elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
1880    elm_gengrid_item_class_ref((Elm_Gengrid_Item_Class *)itc);
1881    it->item = ELM_NEW(Elm_Gen_Item_Type);
1882    wd->item_count++;
1883    it->group = it->itc->item_style && (!strcmp(it->itc->item_style, "group_index"));
1884    ELM_GEN_ITEM_SETUP(it);
1885
1886    return it;
1887 }
1888
1889 EAPI Evas_Object *
1890 elm_gengrid_add(Evas_Object *parent)
1891 {
1892    Evas_Object *obj;
1893    Evas *e;
1894    Widget_Data *wd;
1895    static Evas_Smart *smart = NULL;
1896    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1897
1898    if (!smart)
1899      {
1900         static Evas_Smart_Class sc;
1901
1902         evas_object_smart_clipped_smart_set(&_pan_sc);
1903         sc = _pan_sc;
1904         sc.name = "elm_gengrid_pan";
1905         sc.version = EVAS_SMART_CLASS_VERSION;
1906         sc.add = _pan_add;
1907         sc.del = _pan_del;
1908         sc.resize = _pan_resize;
1909         sc.move = _pan_move;
1910         sc.calculate = _pan_calculate;
1911         if (!(smart = evas_smart_class_new(&sc))) return NULL;
1912      }
1913
1914    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1915
1916    ELM_SET_WIDTYPE(widtype, "gengrid");
1917    ELM_GEN_SETUP(wd);
1918    elm_widget_type_set(obj, "gengrid");
1919    elm_widget_sub_object_add(parent, obj);
1920    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1921    elm_widget_data_set(obj, wd);
1922    elm_widget_del_hook_set(obj, _del_hook);
1923    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1924    elm_widget_theme_hook_set(obj, _theme_hook);
1925    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1926    elm_widget_can_focus_set(obj, EINA_TRUE);
1927    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1928    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1929    elm_widget_event_hook_set(obj, _event_hook);
1930
1931    wd->generation = 1;
1932    wd->scr = elm_smart_scroller_add(e);
1933    elm_smart_scroller_widget_set(wd->scr, obj);
1934    elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
1935                                        "default");
1936    elm_smart_scroller_bounce_allow_set(wd->scr, bounce,
1937                                        _elm_config->thumbscroll_bounce_enable);
1938    elm_widget_resize_object_set(obj, wd->scr);
1939
1940    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1941    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1942    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1943    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1944    evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
1945    evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
1946    evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
1947    evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom,
1948                                   obj);
1949    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1950
1951    wd->obj = obj;
1952    wd->align_x = 0.5;
1953    wd->align_y = 0.5;
1954    wd->h_bounce = bounce;
1955    wd->v_bounce = bounce;
1956    wd->highlight = EINA_TRUE;
1957
1958    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1959    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1960    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1961    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1962
1963    wd->pan_smart = evas_object_smart_add(e, smart);
1964    wd->pan = evas_object_smart_data_get(wd->pan_smart);
1965    wd->pan->wd = wd;
1966
1967    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1968                                      _pan_set, _pan_get, _pan_max_get,
1969                                      _pan_min_get, _pan_child_size_get);
1970
1971    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1972
1973    _mirrored_set(obj, elm_widget_mirrored_get(obj));
1974    return obj;
1975 }
1976
1977 EAPI void
1978 elm_gengrid_item_size_set(Evas_Object *obj,
1979                           Evas_Coord   w,
1980                           Evas_Coord   h)
1981 {
1982    ELM_CHECK_WIDTYPE(obj, widtype);
1983    Widget_Data *wd = elm_widget_data_get(obj);
1984    if (!wd) return;
1985    if ((wd->item_width == w) && (wd->item_height == h)) return;
1986    wd->item_width = w;
1987    wd->item_height = h;
1988    if (wd->calc_job) ecore_job_del(wd->calc_job);
1989    wd->calc_job = ecore_job_add(_calc_job, wd);
1990 }
1991
1992 EAPI void
1993 elm_gengrid_item_size_get(const Evas_Object *obj,
1994                           Evas_Coord        *w,
1995                           Evas_Coord        *h)
1996 {
1997    ELM_CHECK_WIDTYPE(obj, widtype);
1998    Widget_Data *wd = elm_widget_data_get(obj);
1999    if (!wd) return;
2000    if (w) *w = wd->item_width;
2001    if (h) *h = wd->item_height;
2002 }
2003
2004 EAPI void
2005 elm_gengrid_group_item_size_set(Evas_Object *obj,
2006                                 Evas_Coord   w,
2007                                 Evas_Coord   h)
2008 {
2009    ELM_CHECK_WIDTYPE(obj, widtype);
2010    Widget_Data *wd = elm_widget_data_get(obj);
2011    if (!wd) return;
2012    if ((wd->group_item_width == w) && (wd->group_item_height == h)) return;
2013    wd->group_item_width = w;
2014    wd->group_item_height = h;
2015    if (wd->calc_job) ecore_job_del(wd->calc_job);
2016    wd->calc_job = ecore_job_add(_calc_job, wd);
2017 }
2018
2019 EAPI void
2020 elm_gengrid_group_item_size_get(const Evas_Object *obj,
2021                                 Evas_Coord        *w,
2022                                 Evas_Coord        *h)
2023 {
2024    ELM_CHECK_WIDTYPE(obj, widtype);
2025    Widget_Data *wd = elm_widget_data_get(obj);
2026    if (!wd) return;
2027    if (w) *w = wd->group_item_width;
2028    if (h) *h = wd->group_item_height;
2029 }
2030
2031 EAPI void
2032 elm_gengrid_align_set(Evas_Object *obj,
2033                       double       align_x,
2034                       double       align_y)
2035 {
2036    ELM_CHECK_WIDTYPE(obj, widtype);
2037
2038    Widget_Data *wd = elm_widget_data_get(obj);
2039    double old_h = wd->align_x, old_y = wd->align_y;
2040
2041    if (align_x > 1.0)
2042      align_x = 1.0;
2043    else if (align_x < 0.0)
2044      align_x = 0.0;
2045    wd->align_x = align_x;
2046
2047    if (align_y > 1.0)
2048      align_y = 1.0;
2049    else if (align_y < 0.0)
2050      align_y = 0.0;
2051    wd->align_y = align_y;
2052
2053    if ((old_h != wd->align_x) || (old_y != wd->align_y))
2054      evas_object_smart_calculate(wd->pan_smart);
2055 }
2056
2057 EAPI void
2058 elm_gengrid_align_get(const Evas_Object *obj,
2059                       double            *align_x,
2060                       double            *align_y)
2061 {
2062    ELM_CHECK_WIDTYPE(obj, widtype);
2063    Widget_Data *wd = elm_widget_data_get(obj);
2064    if (align_x) *align_x = wd->align_x;
2065    if (align_y) *align_y = wd->align_y;
2066 }
2067
2068 EAPI Elm_Object_Item *
2069 elm_gengrid_item_append(Evas_Object                  *obj,
2070                         const Elm_Gengrid_Item_Class *itc,
2071                         const void                   *data,
2072                         Evas_Smart_Cb                 func,
2073                         const void                   *func_data)
2074 {
2075    Elm_Gen_Item *it;
2076    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2077    Widget_Data *wd = elm_widget_data_get(obj);
2078    if (!wd) return NULL;
2079
2080    it = _item_new(wd, itc, data, func, func_data);
2081    if (!it) return NULL;
2082    wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
2083    it->position = eina_inlist_count(wd->items);
2084    it->position_update = EINA_TRUE;
2085
2086    if (it->group)
2087      wd->group_items = eina_list_prepend(wd->group_items, it);
2088
2089    if (wd->calc_job) ecore_job_del(wd->calc_job);
2090    wd->calc_job = ecore_job_add(_calc_job, wd);
2091
2092    return (Elm_Object_Item *)it;
2093 }
2094
2095 EAPI Elm_Object_Item *
2096 elm_gengrid_item_prepend(Evas_Object                  *obj,
2097                          const Elm_Gengrid_Item_Class *itc,
2098                          const void                   *data,
2099                          Evas_Smart_Cb                 func,
2100                          const void                   *func_data)
2101 {
2102    Elm_Gen_Item *it;
2103    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2104    Widget_Data *wd = elm_widget_data_get(obj);
2105    if (!wd) return NULL;
2106
2107    it = _item_new(wd, itc, data, func, func_data);
2108    if (!it) return NULL;
2109    wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
2110    _item_position_update(wd->items, 0);
2111
2112    if (it->group)
2113      wd->group_items = eina_list_append(wd->group_items, it);
2114
2115    if (wd->calc_job) ecore_job_del(wd->calc_job);
2116    wd->calc_job = ecore_job_add(_calc_job, wd);
2117
2118    return (Elm_Object_Item *)it;
2119 }
2120
2121 EAPI Elm_Object_Item *
2122 elm_gengrid_item_insert_before(Evas_Object                  *obj,
2123                                const Elm_Gengrid_Item_Class *itc,
2124                                const void                   *data,
2125                                Elm_Object_Item              *relative,
2126                                Evas_Smart_Cb                 func,
2127                                const void                   *func_data)
2128 {
2129    Elm_Gen_Item *it;
2130    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2131    ELM_OBJ_ITEM_CHECK_OR_RETURN(relative, NULL);
2132    Widget_Data *wd = elm_widget_data_get(obj);
2133    if (!wd) return NULL;
2134
2135    it = _item_new(wd, itc, data, func, func_data);
2136    if (!it) return NULL;
2137    wd->items = eina_inlist_prepend_relative
2138       (wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET((Elm_Gen_Item *) relative));
2139    Eina_Inlist *tmp = eina_inlist_find(wd->items, EINA_INLIST_GET(it));
2140    _item_position_update(tmp, ((Elm_Gen_Item *)relative)->position);
2141
2142    if (it->group)
2143      wd->group_items = eina_list_append_relative(wd->group_items, it, ((Elm_Gen_Item *) relative)->parent);
2144
2145    if (wd->calc_job) ecore_job_del(wd->calc_job);
2146    wd->calc_job = ecore_job_add(_calc_job, wd);
2147
2148    return (Elm_Object_Item *)it;
2149 }
2150
2151 EAPI Elm_Object_Item *
2152 elm_gengrid_item_insert_after(Evas_Object                  *obj,
2153                               const Elm_Gengrid_Item_Class *itc,
2154                               const void                   *data,
2155                               Elm_Object_Item              *relative,
2156                               Evas_Smart_Cb                 func,
2157                               const void                   *func_data)
2158 {
2159    Elm_Gen_Item *it;
2160    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2161    ELM_OBJ_ITEM_CHECK_OR_RETURN(relative, NULL);
2162    Widget_Data *wd = elm_widget_data_get(obj);
2163    if (!wd) return NULL;
2164
2165    it = _item_new(wd, itc, data, func, func_data);
2166    if (!it) return NULL;
2167    wd->items = eina_inlist_append_relative
2168       (wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET((Elm_Gen_Item *) relative));
2169    Eina_Inlist *tmp = eina_inlist_find(wd->items, EINA_INLIST_GET(it));
2170    _item_position_update(tmp, ((Elm_Gen_Item *)relative)->position+1);
2171
2172    if (it->group)
2173      wd->group_items = eina_list_prepend_relative(wd->group_items, it, ((Elm_Gen_Item *) relative)->parent);
2174
2175    if (wd->calc_job) ecore_job_del(wd->calc_job);
2176    wd->calc_job = ecore_job_add(_calc_job, wd);
2177
2178    return (Elm_Object_Item *)it;
2179 }
2180
2181 EAPI Elm_Object_Item *
2182 elm_gengrid_item_sorted_insert(Evas_Object                  *obj,
2183                                const Elm_Gengrid_Item_Class *itc,
2184                                const void                   *data,
2185                                Eina_Compare_Cb               comp,
2186                                Evas_Smart_Cb                 func,
2187                                const void                   *func_data)
2188 {
2189    Elm_Gen_Item *it;
2190    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2191    Widget_Data *wd = elm_widget_data_get(obj);
2192    if (!wd) return NULL;
2193
2194    it = _item_new(wd, itc, data, func, func_data);
2195    if (!it) return NULL;
2196
2197    if (!wd->state)
2198      wd->state = eina_inlist_sorted_state_new();
2199
2200    wd->item_compare_cb = comp;
2201    wd->items = eina_inlist_sorted_state_insert(wd->items, EINA_INLIST_GET(it),
2202                                          _elm_gengrid_item_compare, wd->state);
2203    _item_position_update(wd->items, 0);
2204
2205    if (wd->calc_job) ecore_job_del(wd->calc_job);
2206    wd->calc_job = ecore_job_add(_calc_job, wd);
2207
2208    return (Elm_Object_Item *)it;
2209 }
2210
2211 EAPI void
2212 elm_gengrid_horizontal_set(Evas_Object *obj,
2213                            Eina_Bool    horizontal)
2214 {
2215    ELM_CHECK_WIDTYPE(obj, widtype);
2216    Widget_Data *wd = elm_widget_data_get(obj);
2217    if (!wd) return;
2218    horizontal = !!horizontal;
2219    if (horizontal == wd->horizontal) return;
2220    wd->horizontal = horizontal;
2221
2222    /* Update the items to conform to the new layout */
2223    if (wd->calc_job) ecore_job_del(wd->calc_job);
2224    wd->calc_job = ecore_job_add(_calc_job, wd);
2225 }
2226
2227 EAPI Eina_Bool
2228 elm_gengrid_horizontal_get(const Evas_Object *obj)
2229 {
2230    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2231    Widget_Data *wd = elm_widget_data_get(obj);
2232    if (!wd) return EINA_FALSE;
2233    return wd->horizontal;
2234 }
2235
2236 EAPI void
2237 elm_gengrid_clear(Evas_Object *obj)
2238 {
2239    elm_genlist_clear(obj);
2240 }
2241
2242 EINA_DEPRECATED EAPI const Evas_Object *
2243 elm_gengrid_item_object_get(const Elm_Object_Item *it)
2244 {
2245    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2246    return VIEW(it);
2247 }
2248
2249 EAPI void
2250 elm_gengrid_item_update(Elm_Object_Item *it)
2251 {
2252    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2253    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2254    if (!_it->realized) return;
2255    if (_it->want_unrealize) return;
2256    _elm_genlist_item_unrealize(_it, EINA_FALSE);
2257    _item_realize(_it);
2258    _item_place(_it, _it->x, _it->y);
2259 }
2260
2261 EAPI const Elm_Gengrid_Item_Class *
2262 elm_gengrid_item_item_class_get(const Elm_Object_Item *it)
2263 {
2264    return (Elm_Gengrid_Item_Class *)elm_genlist_item_item_class_get(it);
2265 }
2266
2267 EAPI void
2268 elm_gengrid_item_item_class_update(Elm_Object_Item *it,
2269                                    const Elm_Gengrid_Item_Class *itc)
2270 {
2271    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2272    EINA_SAFETY_ON_NULL_RETURN(itc);
2273    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2274    if (_it->generation < _it->wd->generation) return;
2275    _it->itc = itc;
2276    elm_gengrid_item_update(it);
2277 }
2278
2279 EAPI void
2280 elm_gengrid_item_pos_get(const Elm_Object_Item *it,
2281                          unsigned int           *x,
2282                          unsigned int           *y)
2283 {
2284    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2285    if (x) *x = ((Elm_Gen_Item *)it)->x;
2286    if (y) *y = ((Elm_Gen_Item *)it)->y;
2287 }
2288
2289 EAPI void
2290 elm_gengrid_multi_select_set(Evas_Object *obj,
2291                              Eina_Bool    multi)
2292 {
2293    ELM_CHECK_WIDTYPE(obj, widtype);
2294    Widget_Data *wd = elm_widget_data_get(obj);
2295    if (!wd) return;
2296    wd->multi = !!multi;
2297 }
2298
2299 EAPI Eina_Bool
2300 elm_gengrid_multi_select_get(const Evas_Object *obj)
2301 {
2302    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2303    Widget_Data *wd = elm_widget_data_get(obj);
2304    if (!wd) return EINA_FALSE;
2305    return wd->multi;
2306 }
2307
2308 EAPI Elm_Object_Item *
2309 elm_gengrid_selected_item_get(const Evas_Object *obj)
2310 {
2311    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2312    Widget_Data *wd = elm_widget_data_get(obj);
2313    if (!wd) return NULL;
2314    if (wd->selected) return wd->selected->data;
2315    return NULL;
2316 }
2317
2318 EAPI const Eina_List *
2319 elm_gengrid_selected_items_get(const Evas_Object *obj)
2320 {
2321    return elm_genlist_selected_items_get(obj);
2322 }
2323
2324 EAPI void
2325 elm_gengrid_item_selected_set(Elm_Object_Item  *it,
2326                               Eina_Bool         selected)
2327 {
2328    elm_genlist_item_selected_set(it, selected);
2329 }
2330
2331 EAPI Eina_Bool
2332 elm_gengrid_item_selected_get(const Elm_Object_Item *it)
2333 {
2334    return elm_genlist_item_selected_get(it);
2335 }
2336
2337 EAPI Eina_List *
2338 elm_gengrid_realized_items_get(const Evas_Object *obj)
2339 {
2340    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2341    Widget_Data *wd = elm_widget_data_get(obj);
2342    Eina_List *list = NULL;
2343    Elm_Gen_Item *it;
2344
2345    EINA_INLIST_FOREACH(wd->items, it)
2346      {
2347         if (it->realized) list = eina_list_append(list, (Elm_Object_Item *)it);
2348      }
2349    return list;
2350 }
2351
2352 EAPI void
2353 elm_gengrid_realized_items_update(Evas_Object *obj)
2354 {
2355    ELM_CHECK_WIDTYPE(obj, widtype);
2356
2357    Eina_List *list, *l;
2358    Elm_Object_Item *it;
2359
2360    list = elm_gengrid_realized_items_get(obj);
2361    EINA_LIST_FOREACH(list, l, it)
2362      elm_gengrid_item_update(it);
2363 }
2364
2365 static Evas_Object *
2366 _elm_gengrid_item_label_create(void        *data,
2367                                Evas_Object *obj __UNUSED__,
2368                                Evas_Object *tooltip,
2369                                void *it   __UNUSED__)
2370 {
2371    Evas_Object *label = elm_label_add(tooltip);
2372    if (!label)
2373      return NULL;
2374    elm_object_style_set(label, "tooltip");
2375    elm_object_text_set(label, data);
2376    return label;
2377 }
2378
2379 static void
2380 _elm_gengrid_item_label_del_cb(void            *data,
2381                                Evas_Object *obj __UNUSED__,
2382                                void *event_info __UNUSED__)
2383 {
2384    eina_stringshare_del(data);
2385 }
2386
2387 EAPI void
2388 elm_gengrid_item_tooltip_text_set(Elm_Object_Item  *it,
2389                                   const char       *text)
2390 {
2391    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2392    text = eina_stringshare_add(text);
2393    elm_gengrid_item_tooltip_content_cb_set(it, _elm_gengrid_item_label_create,
2394                                            text,
2395                                            _elm_gengrid_item_label_del_cb);
2396 }
2397
2398 EAPI void
2399 elm_gengrid_item_tooltip_content_cb_set(Elm_Object_Item            *it,
2400                                         Elm_Tooltip_Item_Content_Cb func,
2401                                         const void                 *data,
2402                                         Evas_Smart_Cb               del_cb)
2403 {
2404    ELM_OBJ_ITEM_CHECK_OR_GOTO(it, error);
2405    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2406
2407    if ((_it->tooltip.content_cb == func) && (_it->tooltip.data == data))
2408      return;
2409
2410    if (_it->tooltip.del_cb)
2411      _it->tooltip.del_cb((void *)_it->tooltip.data, WIDGET(_it), _it);
2412    _it->tooltip.content_cb = func;
2413    _it->tooltip.data = data;
2414    _it->tooltip.del_cb = del_cb;
2415    if (VIEW(_it))
2416      {
2417         elm_widget_item_tooltip_content_cb_set(_it,
2418                                                _it->tooltip.content_cb,
2419                                                _it->tooltip.data, NULL);
2420         elm_widget_item_tooltip_style_set(_it, _it->tooltip.style);
2421         elm_widget_item_tooltip_window_mode_set(_it, _it->tooltip.free_size);
2422      }
2423
2424    return;
2425
2426 error:
2427    if (del_cb) del_cb((void *)data, NULL, NULL);
2428 }
2429
2430 EAPI void
2431 elm_gengrid_item_tooltip_unset(Elm_Object_Item *it)
2432 {
2433    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2434    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2435
2436    if ((VIEW(_it)) && (_it->tooltip.content_cb))
2437      elm_widget_item_tooltip_unset(_it);
2438
2439    if (_it->tooltip.del_cb)
2440      _it->tooltip.del_cb((void *) _it->tooltip.data, WIDGET(_it), _it);
2441    _it->tooltip.del_cb = NULL;
2442    _it->tooltip.content_cb = NULL;
2443    _it->tooltip.data = NULL;
2444    _it->tooltip.free_size = EINA_FALSE;
2445    if (_it->tooltip.style)
2446      elm_gengrid_item_tooltip_style_set(it, NULL);
2447 }
2448
2449 EAPI void
2450 elm_gengrid_item_tooltip_style_set(Elm_Object_Item  *it,
2451                                    const char       *style)
2452 {
2453    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2454    eina_stringshare_replace(&((Elm_Gen_Item *)it)->tooltip.style, style);
2455    if (VIEW(it)) elm_widget_item_tooltip_style_set(it, style);
2456 }
2457
2458 EAPI const char *
2459 elm_gengrid_item_tooltip_style_get(const Elm_Object_Item *it)
2460 {
2461    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2462    return ((Elm_Gen_Item *)it)->tooltip.style;
2463 }
2464
2465 EAPI Eina_Bool
2466 elm_gengrid_item_tooltip_window_mode_set(Elm_Object_Item *it, Eina_Bool disable)
2467 {
2468    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2469    ((Elm_Gen_Item *)it)->tooltip.free_size = disable;
2470    if (VIEW(it)) return elm_widget_item_tooltip_window_mode_set(it, disable);
2471    return EINA_TRUE;
2472 }
2473
2474 EAPI Eina_Bool
2475 elm_gengrid_item_tooltip_window_mode_get(const Elm_Object_Item *it)
2476 {
2477    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2478    return ((Elm_Gen_Item *)it)->tooltip.free_size;
2479 }
2480
2481 EAPI void
2482 elm_gengrid_item_cursor_set(Elm_Object_Item  *it,
2483                             const char       *cursor)
2484 {
2485    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2486    eina_stringshare_replace(&((Elm_Gen_Item *)it)->mouse_cursor, cursor);
2487    if (VIEW(it)) elm_widget_item_cursor_set(it, cursor);
2488 }
2489
2490 EAPI const char *
2491 elm_gengrid_item_cursor_get(const Elm_Object_Item *it)
2492 {
2493    return elm_widget_item_cursor_get(it);
2494 }
2495
2496 EAPI void
2497 elm_gengrid_item_cursor_unset(Elm_Object_Item *it)
2498 {
2499    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2500    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2501    if (!_it->mouse_cursor)
2502      return;
2503
2504    if (VIEW(_it))
2505      elm_widget_item_cursor_unset(_it);
2506
2507    eina_stringshare_del(_it->mouse_cursor);
2508    _it->mouse_cursor = NULL;
2509 }
2510
2511 EAPI void
2512 elm_gengrid_item_cursor_style_set(Elm_Object_Item  *it,
2513                                   const char       *style)
2514 {
2515    elm_widget_item_cursor_style_set(it, style);
2516 }
2517
2518 EAPI const char *
2519 elm_gengrid_item_cursor_style_get(const Elm_Object_Item *it)
2520 {
2521    return elm_widget_item_cursor_style_get(it);
2522 }
2523
2524 EAPI void
2525 elm_gengrid_item_cursor_engine_only_set(Elm_Object_Item  *it,
2526                                         Eina_Bool         engine_only)
2527 {
2528    elm_widget_item_cursor_engine_only_set(it, engine_only);
2529 }
2530
2531 EAPI Eina_Bool
2532 elm_gengrid_item_cursor_engine_only_get(const Elm_Object_Item *it)
2533 {
2534    return elm_widget_item_cursor_engine_only_get(it);
2535 }
2536
2537 EAPI void
2538 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2539                              Eina_Bool    reorder_mode)
2540 {
2541    ELM_CHECK_WIDTYPE(obj, widtype);
2542    Widget_Data *wd = elm_widget_data_get(obj);
2543    if (!wd) return;
2544    wd->reorder_mode = !!reorder_mode;
2545 }
2546
2547 EAPI Eina_Bool
2548 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
2549 {
2550    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2551    Widget_Data *wd = elm_widget_data_get(obj);
2552    if (!wd) return EINA_FALSE;
2553    return wd->reorder_mode;
2554 }
2555
2556 EAPI void
2557 elm_gengrid_bounce_set(Evas_Object *obj,
2558                        Eina_Bool    h_bounce,
2559                        Eina_Bool    v_bounce)
2560 {
2561    elm_genlist_bounce_set(obj, h_bounce, v_bounce);
2562 }
2563
2564 EAPI void
2565 elm_gengrid_bounce_get(const Evas_Object *obj,
2566                        Eina_Bool         *h_bounce,
2567                        Eina_Bool         *v_bounce)
2568 {
2569    elm_genlist_bounce_get(obj, h_bounce, v_bounce);
2570 }
2571
2572 EAPI void
2573 elm_gengrid_page_relative_set(Evas_Object *obj,
2574                               double       h_pagerel,
2575                               double       v_pagerel)
2576 {
2577    _elm_genlist_page_relative_set(obj, h_pagerel, v_pagerel);
2578 }
2579
2580 EAPI void
2581 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
2582 {
2583    _elm_genlist_page_relative_get(obj, h_pagerel, v_pagerel);
2584 }
2585
2586 EAPI void
2587 elm_gengrid_page_size_set(Evas_Object *obj,
2588                           Evas_Coord   h_pagesize,
2589                           Evas_Coord   v_pagesize)
2590 {
2591    _elm_genlist_page_size_set(obj, h_pagesize, v_pagesize);
2592 }
2593
2594 EAPI void
2595 elm_gengrid_current_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2596 {
2597    _elm_genlist_current_page_get(obj, h_pagenumber, v_pagenumber);
2598 }
2599
2600 EAPI void
2601 elm_gengrid_last_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2602 {
2603    _elm_genlist_last_page_get(obj, h_pagenumber, v_pagenumber);
2604 }
2605
2606 EAPI void
2607 elm_gengrid_page_show(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2608 {
2609    _elm_genlist_page_show(obj, h_pagenumber, v_pagenumber);
2610 }
2611
2612 EAPI void
2613 elm_gengrid_page_bring_in(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2614 {
2615    _elm_genlist_page_bring_in(obj, h_pagenumber, v_pagenumber);
2616 }
2617
2618 EAPI void
2619 elm_gengrid_scroller_policy_set(Evas_Object        *obj,
2620                                 Elm_Scroller_Policy policy_h,
2621                                 Elm_Scroller_Policy policy_v)
2622 {
2623    ELM_CHECK_WIDTYPE(obj, widtype);
2624    Widget_Data *wd = elm_widget_data_get(obj);
2625    if ((!wd) || (!wd->scr)) return;
2626    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
2627        (policy_v >= ELM_SCROLLER_POLICY_LAST))
2628      return;
2629    elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
2630 }
2631
2632 EAPI void
2633 elm_gengrid_scroller_policy_get(const Evas_Object   *obj,
2634                                 Elm_Scroller_Policy *policy_h,
2635                                 Elm_Scroller_Policy *policy_v)
2636 {
2637    ELM_CHECK_WIDTYPE(obj, widtype);
2638    Widget_Data *wd = elm_widget_data_get(obj);
2639    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
2640    if ((!wd) || (!wd->scr)) return;
2641    elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
2642    if (policy_h) *policy_h = (Elm_Scroller_Policy)s_policy_h;
2643    if (policy_v) *policy_v = (Elm_Scroller_Policy)s_policy_v;
2644 }
2645
2646 EAPI Elm_Object_Item *
2647 elm_gengrid_first_item_get(const Evas_Object *obj)
2648 {
2649    return elm_genlist_first_item_get(obj);
2650 }
2651
2652 EAPI Elm_Object_Item *
2653 elm_gengrid_last_item_get(const Evas_Object *obj)
2654 {
2655    return elm_genlist_last_item_get(obj);
2656 }
2657
2658 EAPI Elm_Object_Item *
2659 elm_gengrid_item_next_get(const Elm_Object_Item *it)
2660 {
2661    return elm_genlist_item_next_get(it);
2662 }
2663
2664 EAPI Elm_Object_Item *
2665 elm_gengrid_item_prev_get(const Elm_Object_Item *it)
2666 {
2667    return elm_genlist_item_prev_get(it);
2668 }
2669
2670 EAPI void
2671 elm_gengrid_item_show(Elm_Object_Item *it, Elm_Gengrid_Item_Scrollto_Type type)
2672 {
2673    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2674    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2675    Widget_Data *wd = _it->wd;
2676    Evas_Coord minx = 0, miny = 0;
2677
2678    if ((_it->generation < _it->wd->generation)) return;
2679    _pan_min_get(wd->pan_smart, &minx, &miny);
2680
2681    if (type==ELM_GENGRID_ITEM_SCROLLTO_IN)
2682      {
2683         //TODO : type based handling like genlist
2684      }
2685
2686    if (wd->horizontal)
2687      elm_smart_scroller_region_bring_in(_it->wd->scr,
2688                                         ((_it->x - _it->item->prev_group) * wd->item_width) + (_it->item->prev_group * _it->wd->group_item_width) + minx,
2689                                         _it->y * wd->item_height + miny,
2690                                         _it->wd->item_width,
2691                                         _it->wd->item_height);
2692    else
2693      elm_smart_scroller_region_bring_in(_it->wd->scr,
2694                                         _it->x * wd->item_width + minx,
2695                                         ((_it->y - _it->item->prev_group) * wd->item_height) + (_it->item->prev_group * _it->wd->group_item_height) + miny,
2696                                         _it->wd->item_width,
2697                                         _it->wd->item_height);
2698 }
2699
2700 EAPI void
2701 elm_gengrid_item_bring_in(Elm_Object_Item *it, Elm_Gengrid_Item_Scrollto_Type type)
2702 {
2703    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2704    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2705
2706    if (_it->generation < _it->wd->generation) return;
2707
2708    Evas_Coord minx = 0, miny = 0;
2709    Widget_Data *wd = _it->wd;
2710    _pan_min_get(wd->pan_smart, &minx, &miny);
2711
2712    if (type==ELM_GENGRID_ITEM_SCROLLTO_IN)
2713      {
2714         //TODO : type based handling like genlist
2715      }
2716
2717    if (wd->horizontal)
2718      elm_smart_scroller_region_bring_in(_it->wd->scr,
2719                                         ((_it->x - _it->item->prev_group) * wd->item_width) + (_it->item->prev_group * _it->wd->group_item_width) + minx,
2720                                         _it->y * wd->item_height + miny,
2721                                         _it->wd->item_width,
2722                                         _it->wd->item_height);
2723    else
2724      elm_smart_scroller_region_bring_in(_it->wd->scr,
2725                                         _it->x * wd->item_width + minx,
2726                                         ((_it->y - _it->item->prev_group)* wd->item_height) + (_it->item->prev_group * _it->wd->group_item_height) + miny,
2727                                         _it->wd->item_width,
2728                                         _it->wd->item_height);
2729 }
2730
2731 EAPI void
2732 elm_gengrid_filled_set(Evas_Object *obj, Eina_Bool fill)
2733 {
2734    ELM_CHECK_WIDTYPE(obj, widtype);
2735    Widget_Data *wd = elm_widget_data_get(obj);
2736    if (!wd) return;
2737    fill = !!fill;
2738    if (wd->filled != fill)
2739      wd->filled = fill;
2740 }
2741
2742 EAPI Eina_Bool
2743 elm_gengrid_filled_get(const Evas_Object *obj)
2744 {
2745    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2746    Widget_Data *wd = elm_widget_data_get(obj);
2747    if (!wd) return EINA_FALSE;
2748    return wd->filled;
2749 }
2750
2751 EAPI unsigned int
2752 elm_gengrid_items_count(const Evas_Object *obj)
2753 {
2754    ELM_CHECK_WIDTYPE(obj, widtype) 0;
2755    Widget_Data *wd = elm_widget_data_get(obj);
2756    if (!wd) return 0;
2757    return wd->item_count;
2758 }
2759
2760 EAPI Elm_Gengrid_Item_Class *
2761 elm_gengrid_item_class_new(void)
2762 {
2763    Elm_Gengrid_Item_Class *itc;
2764
2765    itc = calloc(1, sizeof(Elm_Gengrid_Item_Class));
2766    if (!itc)
2767      return NULL;
2768    itc->version = CLASS_ALLOCATED;
2769    itc->refcount = 1;
2770    itc->delete_me = EINA_FALSE;
2771
2772    return itc;
2773 }
2774
2775 EAPI void
2776 elm_gengrid_item_class_free(Elm_Gengrid_Item_Class *itc)
2777 {
2778    if (itc && (itc->version == CLASS_ALLOCATED))
2779      {
2780         if (!itc->delete_me) itc->delete_me = EINA_TRUE;
2781         if (itc->refcount > 0) elm_gengrid_item_class_unref(itc);
2782         else
2783           {
2784              itc->version = 0;
2785              free(itc);
2786           }
2787      }
2788 }
2789
2790 EAPI void
2791 elm_gengrid_item_class_ref(Elm_Gengrid_Item_Class *itc)
2792 {
2793    if (itc && (itc->version == CLASS_ALLOCATED))
2794      {
2795         itc->refcount++;
2796         if (itc->refcount == 0) itc->refcount--;
2797      }
2798 }
2799
2800 EAPI void
2801 elm_gengrid_item_class_unref(Elm_Gengrid_Item_Class *itc)
2802 {
2803    if (itc && (itc->version == CLASS_ALLOCATED))
2804      {
2805         if (itc->refcount > 0) itc->refcount--;
2806         if (itc->delete_me && (!itc->refcount))
2807           elm_gengrid_item_class_free(itc);
2808      }
2809 }
2810
2811 EAPI void
2812 elm_gengrid_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
2813 {
2814    elm_genlist_select_mode_set(obj, mode);
2815 }
2816
2817 EAPI Elm_Object_Select_Mode
2818 elm_gengrid_select_mode_get(const Evas_Object *obj)
2819 {
2820    return elm_genlist_select_mode_get(obj);
2821 }
2822
2823 EAPI void
2824 elm_gengrid_highlight_mode_set(Evas_Object *obj,
2825                                Eina_Bool    highlight)
2826 {
2827    elm_genlist_highlight_mode_set(obj, highlight);
2828 }
2829
2830 EAPI Eina_Bool
2831 elm_gengrid_highlight_mode_get(const Evas_Object *obj)
2832 {
2833    return elm_genlist_highlight_mode_get(obj);
2834 }
2835
2836 EAPI int
2837 elm_gengrid_item_index_get(const Elm_Object_Item *it)
2838 {
2839    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, -1);
2840    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2841
2842    return _it->position;
2843 }
2844
2845 EAPI void
2846 elm_gengrid_item_select_mode_set(Elm_Object_Item *it,
2847                                  Elm_Object_Select_Mode mode)
2848 {
2849    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2850    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2851    if (!_it) return;
2852    if (_it->generation < _it->wd->generation) return;
2853    if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
2854      return;
2855    if (_it->select_mode != mode)
2856      _it->select_mode = mode;
2857
2858    if (_it->select_mode == ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY)
2859      elm_gengrid_item_update(it);
2860 }
2861
2862 EAPI Elm_Object_Select_Mode
2863 elm_gengrid_item_select_mode_get(const Elm_Object_Item *it)
2864 {
2865    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, ELM_OBJECT_SELECT_MODE_MAX);
2866    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2867    if (!_it) return ELM_OBJECT_SELECT_MODE_MAX;
2868    return _it->select_mode;
2869 }