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