082d94ff3d0ddb80859b2a7da5cb22a4193e4df1
[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->no_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
1950    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1951    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1952    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1953    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1954
1955    wd->pan_smart = evas_object_smart_add(e, smart);
1956    wd->pan = evas_object_smart_data_get(wd->pan_smart);
1957    wd->pan->wd = wd;
1958
1959    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1960                                      _pan_set, _pan_get, _pan_max_get,
1961                                      _pan_min_get, _pan_child_size_get);
1962
1963    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1964
1965    _mirrored_set(obj, elm_widget_mirrored_get(obj));
1966    return obj;
1967 }
1968
1969 EAPI void
1970 elm_gengrid_item_size_set(Evas_Object *obj,
1971                           Evas_Coord   w,
1972                           Evas_Coord   h)
1973 {
1974    ELM_CHECK_WIDTYPE(obj, widtype);
1975    Widget_Data *wd = elm_widget_data_get(obj);
1976    if (!wd) return;
1977    if ((wd->item_width == w) && (wd->item_height == h)) return;
1978    wd->item_width = w;
1979    wd->item_height = h;
1980    if (wd->calc_job) ecore_job_del(wd->calc_job);
1981    wd->calc_job = ecore_job_add(_calc_job, wd);
1982 }
1983
1984 EAPI void
1985 elm_gengrid_item_size_get(const Evas_Object *obj,
1986                           Evas_Coord        *w,
1987                           Evas_Coord        *h)
1988 {
1989    ELM_CHECK_WIDTYPE(obj, widtype);
1990    Widget_Data *wd = elm_widget_data_get(obj);
1991    if (!wd) return;
1992    if (w) *w = wd->item_width;
1993    if (h) *h = wd->item_height;
1994 }
1995
1996 EAPI void
1997 elm_gengrid_group_item_size_set(Evas_Object *obj,
1998                                 Evas_Coord   w,
1999                                 Evas_Coord   h)
2000 {
2001    ELM_CHECK_WIDTYPE(obj, widtype);
2002    Widget_Data *wd = elm_widget_data_get(obj);
2003    if (!wd) return;
2004    if ((wd->group_item_width == w) && (wd->group_item_height == h)) return;
2005    wd->group_item_width = w;
2006    wd->group_item_height = h;
2007    if (wd->calc_job) ecore_job_del(wd->calc_job);
2008    wd->calc_job = ecore_job_add(_calc_job, wd);
2009 }
2010
2011 EAPI void
2012 elm_gengrid_group_item_size_get(const Evas_Object *obj,
2013                                 Evas_Coord        *w,
2014                                 Evas_Coord        *h)
2015 {
2016    ELM_CHECK_WIDTYPE(obj, widtype);
2017    Widget_Data *wd = elm_widget_data_get(obj);
2018    if (!wd) return;
2019    if (w) *w = wd->group_item_width;
2020    if (h) *h = wd->group_item_height;
2021 }
2022
2023 EAPI void
2024 elm_gengrid_align_set(Evas_Object *obj,
2025                       double       align_x,
2026                       double       align_y)
2027 {
2028    ELM_CHECK_WIDTYPE(obj, widtype);
2029
2030    Widget_Data *wd = elm_widget_data_get(obj);
2031    double old_h = wd->align_x, old_y = wd->align_y;
2032
2033    if (align_x > 1.0)
2034      align_x = 1.0;
2035    else if (align_x < 0.0)
2036      align_x = 0.0;
2037    wd->align_x = align_x;
2038
2039    if (align_y > 1.0)
2040      align_y = 1.0;
2041    else if (align_y < 0.0)
2042      align_y = 0.0;
2043    wd->align_y = align_y;
2044
2045    if ((old_h != wd->align_x) || (old_y != wd->align_y))
2046      evas_object_smart_calculate(wd->pan_smart);
2047 }
2048
2049 EAPI void
2050 elm_gengrid_align_get(const Evas_Object *obj,
2051                       double            *align_x,
2052                       double            *align_y)
2053 {
2054    ELM_CHECK_WIDTYPE(obj, widtype);
2055    Widget_Data *wd = elm_widget_data_get(obj);
2056    if (align_x) *align_x = wd->align_x;
2057    if (align_y) *align_y = wd->align_y;
2058 }
2059
2060 EAPI Elm_Object_Item *
2061 elm_gengrid_item_append(Evas_Object                  *obj,
2062                         const Elm_Gengrid_Item_Class *itc,
2063                         const void                   *data,
2064                         Evas_Smart_Cb                 func,
2065                         const void                   *func_data)
2066 {
2067    Elm_Gen_Item *it;
2068    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2069    Widget_Data *wd = elm_widget_data_get(obj);
2070    if (!wd) return NULL;
2071
2072    it = _item_new(wd, itc, data, func, func_data);
2073    if (!it) return NULL;
2074    wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
2075    it->position = eina_inlist_count(wd->items);
2076    it->position_update = EINA_TRUE;
2077
2078    if (it->group)
2079      wd->group_items = eina_list_prepend(wd->group_items, it);
2080
2081    if (wd->calc_job) ecore_job_del(wd->calc_job);
2082    wd->calc_job = ecore_job_add(_calc_job, wd);
2083
2084    return (Elm_Object_Item *)it;
2085 }
2086
2087 EAPI Elm_Object_Item *
2088 elm_gengrid_item_prepend(Evas_Object                  *obj,
2089                          const Elm_Gengrid_Item_Class *itc,
2090                          const void                   *data,
2091                          Evas_Smart_Cb                 func,
2092                          const void                   *func_data)
2093 {
2094    Elm_Gen_Item *it;
2095    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2096    Widget_Data *wd = elm_widget_data_get(obj);
2097    if (!wd) return NULL;
2098
2099    it = _item_new(wd, itc, data, func, func_data);
2100    if (!it) return NULL;
2101    wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
2102    _item_position_update(wd->items, 0);
2103
2104    if (it->group)
2105      wd->group_items = eina_list_append(wd->group_items, it);
2106
2107    if (wd->calc_job) ecore_job_del(wd->calc_job);
2108    wd->calc_job = ecore_job_add(_calc_job, wd);
2109
2110    return (Elm_Object_Item *)it;
2111 }
2112
2113 EAPI Elm_Object_Item *
2114 elm_gengrid_item_insert_before(Evas_Object                  *obj,
2115                                const Elm_Gengrid_Item_Class *itc,
2116                                const void                   *data,
2117                                Elm_Object_Item              *relative,
2118                                Evas_Smart_Cb                 func,
2119                                const void                   *func_data)
2120 {
2121    Elm_Gen_Item *it;
2122    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2123    ELM_OBJ_ITEM_CHECK_OR_RETURN(relative, NULL);
2124    Widget_Data *wd = elm_widget_data_get(obj);
2125    if (!wd) return NULL;
2126
2127    it = _item_new(wd, itc, data, func, func_data);
2128    if (!it) return NULL;
2129    wd->items = eina_inlist_prepend_relative
2130       (wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET((Elm_Gen_Item *) relative));
2131    Eina_Inlist *tmp = eina_inlist_find(wd->items, EINA_INLIST_GET(it));
2132    _item_position_update(tmp, ((Elm_Gen_Item *)relative)->position);
2133
2134    if (it->group)
2135      wd->group_items = eina_list_append_relative(wd->group_items, it, ((Elm_Gen_Item *) relative)->parent);
2136
2137    if (wd->calc_job) ecore_job_del(wd->calc_job);
2138    wd->calc_job = ecore_job_add(_calc_job, wd);
2139
2140    return (Elm_Object_Item *)it;
2141 }
2142
2143 EAPI Elm_Object_Item *
2144 elm_gengrid_item_insert_after(Evas_Object                  *obj,
2145                               const Elm_Gengrid_Item_Class *itc,
2146                               const void                   *data,
2147                               Elm_Object_Item              *relative,
2148                               Evas_Smart_Cb                 func,
2149                               const void                   *func_data)
2150 {
2151    Elm_Gen_Item *it;
2152    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2153    ELM_OBJ_ITEM_CHECK_OR_RETURN(relative, NULL);
2154    Widget_Data *wd = elm_widget_data_get(obj);
2155    if (!wd) return NULL;
2156
2157    it = _item_new(wd, itc, data, func, func_data);
2158    if (!it) return NULL;
2159    wd->items = eina_inlist_append_relative
2160       (wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET((Elm_Gen_Item *) relative));
2161    Eina_Inlist *tmp = eina_inlist_find(wd->items, EINA_INLIST_GET(it));
2162    _item_position_update(tmp, ((Elm_Gen_Item *)relative)->position+1);
2163
2164    if (it->group)
2165      wd->group_items = eina_list_prepend_relative(wd->group_items, it, ((Elm_Gen_Item *) relative)->parent);
2166
2167    if (wd->calc_job) ecore_job_del(wd->calc_job);
2168    wd->calc_job = ecore_job_add(_calc_job, wd);
2169
2170    return (Elm_Object_Item *)it;
2171 }
2172
2173 EAPI Elm_Object_Item *
2174 elm_gengrid_item_sorted_insert(Evas_Object                  *obj,
2175                                const Elm_Gengrid_Item_Class *itc,
2176                                const void                   *data,
2177                                Eina_Compare_Cb               comp,
2178                                Evas_Smart_Cb                 func,
2179                                const void                   *func_data)
2180 {
2181    Elm_Gen_Item *it;
2182    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2183    Widget_Data *wd = elm_widget_data_get(obj);
2184    if (!wd) return NULL;
2185
2186    it = _item_new(wd, itc, data, func, func_data);
2187    if (!it) return NULL;
2188
2189    if (!wd->state)
2190      wd->state = eina_inlist_sorted_state_new();
2191
2192    wd->item_compare_cb = comp;
2193    wd->items = eina_inlist_sorted_state_insert(wd->items, EINA_INLIST_GET(it),
2194                                          _elm_gengrid_item_compare, wd->state);
2195    _item_position_update(wd->items, 0);
2196
2197    if (wd->calc_job) ecore_job_del(wd->calc_job);
2198    wd->calc_job = ecore_job_add(_calc_job, wd);
2199
2200    return (Elm_Object_Item *)it;
2201 }
2202
2203 EINA_DEPRECATED Elm_Object_Item *
2204 elm_gengrid_item_direct_sorted_insert(Evas_Object                  *obj,
2205                                       const Elm_Gengrid_Item_Class *itc,
2206                                       const void                   *data,
2207                                       Eina_Compare_Cb               comp,
2208                                       Evas_Smart_Cb                 func,
2209                                       const void                   *func_data)
2210 {
2211    return elm_gengrid_item_sorted_insert(obj, itc, data, comp, func, func_data);
2212 }
2213
2214 EAPI void
2215 elm_gengrid_item_del(Elm_Object_Item *it)
2216 {
2217    elm_object_item_del(it);
2218 }
2219
2220 EAPI void
2221 elm_gengrid_horizontal_set(Evas_Object *obj,
2222                            Eina_Bool    horizontal)
2223 {
2224    ELM_CHECK_WIDTYPE(obj, widtype);
2225    Widget_Data *wd = elm_widget_data_get(obj);
2226    if (!wd) return;
2227    horizontal = !!horizontal;
2228    if (horizontal == wd->horizontal) return;
2229    wd->horizontal = horizontal;
2230
2231    /* Update the items to conform to the new layout */
2232    if (wd->calc_job) ecore_job_del(wd->calc_job);
2233    wd->calc_job = ecore_job_add(_calc_job, wd);
2234 }
2235
2236 EAPI Eina_Bool
2237 elm_gengrid_horizontal_get(const Evas_Object *obj)
2238 {
2239    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2240    Widget_Data *wd = elm_widget_data_get(obj);
2241    if (!wd) return EINA_FALSE;
2242    return wd->horizontal;
2243 }
2244
2245 EAPI void
2246 elm_gengrid_clear(Evas_Object *obj)
2247 {
2248    elm_genlist_clear(obj);
2249 }
2250
2251 EINA_DEPRECATED EAPI const Evas_Object *
2252 elm_gengrid_item_object_get(const Elm_Object_Item *it)
2253 {
2254    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2255    return VIEW(it);
2256 }
2257
2258 EAPI void
2259 elm_gengrid_item_update(Elm_Object_Item *it)
2260 {
2261    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2262    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2263    if (!_it->realized) return;
2264    if (_it->want_unrealize) return;
2265    _elm_genlist_item_unrealize(_it, EINA_FALSE);
2266    _item_realize(_it);
2267    _item_place(_it, _it->x, _it->y);
2268 }
2269
2270 EAPI void *
2271 elm_gengrid_item_data_get(const Elm_Object_Item *it)
2272 {
2273    return elm_object_item_data_get(it);
2274 }
2275
2276 EAPI void
2277 elm_gengrid_item_data_set(Elm_Object_Item  *it,
2278                           const void       *data)
2279 {
2280    elm_object_item_data_set(it, (void *) data);
2281 }
2282
2283 EAPI const Elm_Gengrid_Item_Class *
2284 elm_gengrid_item_item_class_get(const Elm_Object_Item *it)
2285 {
2286    return (Elm_Gengrid_Item_Class *)elm_genlist_item_item_class_get(it);
2287 }
2288
2289 EINA_DEPRECATED EAPI void
2290 elm_gengrid_item_item_class_set(Elm_Object_Item *it,
2291                                 const Elm_Gengrid_Item_Class *itc)
2292 {
2293    elm_gengrid_item_item_class_update(it, itc);
2294 }
2295
2296 EAPI void
2297 elm_gengrid_item_item_class_update(Elm_Object_Item *it,
2298                                    const Elm_Gengrid_Item_Class *itc)
2299 {
2300    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2301    EINA_SAFETY_ON_NULL_RETURN(itc);
2302    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2303    if (_it->generation < _it->wd->generation) return;
2304    _it->itc = itc;
2305    elm_gengrid_item_update(it);
2306 }
2307
2308 EAPI void
2309 elm_gengrid_item_pos_get(const Elm_Object_Item *it,
2310                          unsigned int           *x,
2311                          unsigned int           *y)
2312 {
2313    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2314    if (x) *x = ((Elm_Gen_Item *)it)->x;
2315    if (y) *y = ((Elm_Gen_Item *)it)->y;
2316 }
2317
2318 EAPI void
2319 elm_gengrid_multi_select_set(Evas_Object *obj,
2320                              Eina_Bool    multi)
2321 {
2322    ELM_CHECK_WIDTYPE(obj, widtype);
2323    Widget_Data *wd = elm_widget_data_get(obj);
2324    if (!wd) return;
2325    wd->multi = !!multi;
2326 }
2327
2328 EAPI Eina_Bool
2329 elm_gengrid_multi_select_get(const Evas_Object *obj)
2330 {
2331    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2332    Widget_Data *wd = elm_widget_data_get(obj);
2333    if (!wd) return EINA_FALSE;
2334    return wd->multi;
2335 }
2336
2337 EAPI Elm_Object_Item *
2338 elm_gengrid_selected_item_get(const Evas_Object *obj)
2339 {
2340    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2341    Widget_Data *wd = elm_widget_data_get(obj);
2342    if (!wd) return NULL;
2343    if (wd->selected) return wd->selected->data;
2344    return NULL;
2345 }
2346
2347 EAPI const Eina_List *
2348 elm_gengrid_selected_items_get(const Evas_Object *obj)
2349 {
2350    return elm_genlist_selected_items_get(obj);
2351 }
2352
2353 EAPI void
2354 elm_gengrid_item_selected_set(Elm_Object_Item  *it,
2355                               Eina_Bool         selected)
2356 {
2357    elm_genlist_item_selected_set(it, selected);
2358 }
2359
2360 EAPI Eina_Bool
2361 elm_gengrid_item_selected_get(const Elm_Object_Item *it)
2362 {
2363    return elm_genlist_item_selected_get(it);
2364 }
2365
2366 EAPI Eina_List *
2367 elm_gengrid_realized_items_get(const Evas_Object *obj)
2368 {
2369    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2370    Widget_Data *wd = elm_widget_data_get(obj);
2371    Eina_List *list = NULL;
2372    Elm_Gen_Item *it;
2373
2374    EINA_INLIST_FOREACH(wd->items, it)
2375      {
2376         if (it->realized) list = eina_list_append(list, (Elm_Object_Item *)it);
2377      }
2378    return list;
2379 }
2380
2381 EAPI void
2382 elm_gengrid_realized_items_update(Evas_Object *obj)
2383 {
2384    ELM_CHECK_WIDTYPE(obj, widtype);
2385
2386    Eina_List *list, *l;
2387    Elm_Object_Item *it;
2388
2389    list = elm_gengrid_realized_items_get(obj);
2390    EINA_LIST_FOREACH(list, l, it)
2391      elm_gengrid_item_update(it);
2392 }
2393
2394 EAPI void
2395 elm_gengrid_item_disabled_set(Elm_Object_Item  *it,
2396                               Eina_Bool         disabled)
2397 {
2398    elm_object_item_disabled_set(it, disabled);
2399 }
2400
2401 EAPI Eina_Bool
2402 elm_gengrid_item_disabled_get(const Elm_Object_Item *it)
2403 {
2404    return elm_object_item_disabled_get(it);
2405 }
2406
2407 static Evas_Object *
2408 _elm_gengrid_item_label_create(void        *data,
2409                                Evas_Object *obj __UNUSED__,
2410                                Evas_Object *tooltip,
2411                                void *it   __UNUSED__)
2412 {
2413    Evas_Object *label = elm_label_add(tooltip);
2414    if (!label)
2415      return NULL;
2416    elm_object_style_set(label, "tooltip");
2417    elm_object_text_set(label, data);
2418    return label;
2419 }
2420
2421 static void
2422 _elm_gengrid_item_label_del_cb(void            *data,
2423                                Evas_Object *obj __UNUSED__,
2424                                void *event_info __UNUSED__)
2425 {
2426    eina_stringshare_del(data);
2427 }
2428
2429 EAPI void
2430 elm_gengrid_item_tooltip_text_set(Elm_Object_Item  *it,
2431                                   const char       *text)
2432 {
2433    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2434    text = eina_stringshare_add(text);
2435    elm_gengrid_item_tooltip_content_cb_set(it, _elm_gengrid_item_label_create,
2436                                            text,
2437                                            _elm_gengrid_item_label_del_cb);
2438 }
2439
2440 EAPI void
2441 elm_gengrid_item_tooltip_content_cb_set(Elm_Object_Item            *it,
2442                                         Elm_Tooltip_Item_Content_Cb func,
2443                                         const void                 *data,
2444                                         Evas_Smart_Cb               del_cb)
2445 {
2446    ELM_OBJ_ITEM_CHECK_OR_GOTO(it, error);
2447    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2448
2449    if ((_it->tooltip.content_cb == func) && (_it->tooltip.data == data))
2450      return;
2451
2452    if (_it->tooltip.del_cb)
2453      _it->tooltip.del_cb((void *)_it->tooltip.data, WIDGET(_it), _it);
2454    _it->tooltip.content_cb = func;
2455    _it->tooltip.data = data;
2456    _it->tooltip.del_cb = del_cb;
2457    if (VIEW(_it))
2458      {
2459         elm_widget_item_tooltip_content_cb_set(_it,
2460                                                _it->tooltip.content_cb,
2461                                                _it->tooltip.data, NULL);
2462         elm_widget_item_tooltip_style_set(_it, _it->tooltip.style);
2463         elm_widget_item_tooltip_window_mode_set(_it, _it->tooltip.free_size);
2464      }
2465
2466    return;
2467
2468 error:
2469    if (del_cb) del_cb((void *)data, NULL, NULL);
2470 }
2471
2472 EAPI void
2473 elm_gengrid_item_tooltip_unset(Elm_Object_Item *it)
2474 {
2475    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2476    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2477
2478    if ((VIEW(_it)) && (_it->tooltip.content_cb))
2479      elm_widget_item_tooltip_unset(_it);
2480
2481    if (_it->tooltip.del_cb)
2482      _it->tooltip.del_cb((void *) _it->tooltip.data, WIDGET(_it), _it);
2483    _it->tooltip.del_cb = NULL;
2484    _it->tooltip.content_cb = NULL;
2485    _it->tooltip.data = NULL;
2486    _it->tooltip.free_size = EINA_FALSE;
2487    if (_it->tooltip.style)
2488      elm_gengrid_item_tooltip_style_set(it, NULL);
2489 }
2490
2491 EAPI void
2492 elm_gengrid_item_tooltip_style_set(Elm_Object_Item  *it,
2493                                    const char       *style)
2494 {
2495    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2496    eina_stringshare_replace(&((Elm_Gen_Item *)it)->tooltip.style, style);
2497    if (VIEW(it)) elm_widget_item_tooltip_style_set(it, style);
2498 }
2499
2500 EAPI const char *
2501 elm_gengrid_item_tooltip_style_get(const Elm_Object_Item *it)
2502 {
2503    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2504    return ((Elm_Gen_Item *)it)->tooltip.style;
2505 }
2506
2507 EAPI Eina_Bool
2508 elm_gengrid_item_tooltip_window_mode_set(Elm_Object_Item *it, Eina_Bool disable)
2509 {
2510    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2511    ((Elm_Gen_Item *)it)->tooltip.free_size = disable;
2512    if (VIEW(it)) return elm_widget_item_tooltip_window_mode_set(it, disable);
2513    return EINA_TRUE;
2514 }
2515
2516 EAPI Eina_Bool
2517 elm_gengrid_item_tooltip_window_mode_get(const Elm_Object_Item *it)
2518 {
2519    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2520    return ((Elm_Gen_Item *)it)->tooltip.free_size;
2521 }
2522
2523 EAPI void
2524 elm_gengrid_item_cursor_set(Elm_Object_Item  *it,
2525                             const char       *cursor)
2526 {
2527    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2528    eina_stringshare_replace(&((Elm_Gen_Item *)it)->mouse_cursor, cursor);
2529    if (VIEW(it)) elm_widget_item_cursor_set(it, cursor);
2530 }
2531
2532 EAPI const char *
2533 elm_gengrid_item_cursor_get(const Elm_Object_Item *it)
2534 {
2535    return elm_widget_item_cursor_get(it);
2536 }
2537
2538 EAPI void
2539 elm_gengrid_item_cursor_unset(Elm_Object_Item *it)
2540 {
2541    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2542    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2543    if (!_it->mouse_cursor)
2544      return;
2545
2546    if (VIEW(_it))
2547      elm_widget_item_cursor_unset(_it);
2548
2549    eina_stringshare_del(_it->mouse_cursor);
2550    _it->mouse_cursor = NULL;
2551 }
2552
2553 EAPI void
2554 elm_gengrid_item_cursor_style_set(Elm_Object_Item  *it,
2555                                   const char       *style)
2556 {
2557    elm_widget_item_cursor_style_set(it, style);
2558 }
2559
2560 EAPI const char *
2561 elm_gengrid_item_cursor_style_get(const Elm_Object_Item *it)
2562 {
2563    return elm_widget_item_cursor_style_get(it);
2564 }
2565
2566 EAPI void
2567 elm_gengrid_item_cursor_engine_only_set(Elm_Object_Item  *it,
2568                                         Eina_Bool         engine_only)
2569 {
2570    elm_widget_item_cursor_engine_only_set(it, engine_only);
2571 }
2572
2573 EAPI Eina_Bool
2574 elm_gengrid_item_cursor_engine_only_get(const Elm_Object_Item *it)
2575 {
2576    return elm_widget_item_cursor_engine_only_get(it);
2577 }
2578
2579 EAPI void
2580 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2581                              Eina_Bool    reorder_mode)
2582 {
2583    ELM_CHECK_WIDTYPE(obj, widtype);
2584    Widget_Data *wd = elm_widget_data_get(obj);
2585    if (!wd) return;
2586    wd->reorder_mode = !!reorder_mode;
2587 }
2588
2589 EAPI Eina_Bool
2590 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
2591 {
2592    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2593    Widget_Data *wd = elm_widget_data_get(obj);
2594    if (!wd) return EINA_FALSE;
2595    return wd->reorder_mode;
2596 }
2597
2598 EINA_DEPRECATED EAPI void
2599 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2600                                    Eina_Bool    always_select)
2601 {
2602    if (always_select)
2603      elm_genlist_select_mode_set(obj, ELM_OBJECT_SELECT_MODE_ALWAYS);
2604    else
2605      {
2606         Elm_Object_Select_Mode oldmode = elm_genlist_select_mode_get(obj);
2607         if (oldmode == ELM_OBJECT_SELECT_MODE_ALWAYS)
2608           elm_genlist_select_mode_set(obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
2609      }
2610 }
2611
2612 EINA_DEPRECATED EAPI Eina_Bool
2613 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2614 {
2615    Elm_Object_Select_Mode oldmode = elm_genlist_select_mode_get(obj);
2616    if (oldmode == ELM_OBJECT_SELECT_MODE_ALWAYS)
2617      return EINA_TRUE;
2618    else
2619      return EINA_FALSE;
2620 }
2621
2622 EINA_DEPRECATED EAPI void
2623 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2624                                Eina_Bool    no_select)
2625 {
2626    if (no_select)
2627      elm_genlist_select_mode_set(obj, ELM_OBJECT_SELECT_MODE_NONE);
2628    else
2629      {
2630         Elm_Object_Select_Mode oldmode = elm_genlist_select_mode_get(obj);
2631         if (oldmode == ELM_OBJECT_SELECT_MODE_NONE)
2632           elm_genlist_select_mode_set(obj, ELM_OBJECT_SELECT_MODE_DEFAULT);
2633      }
2634 }
2635
2636 EINA_DEPRECATED EAPI Eina_Bool
2637 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2638 {
2639    Elm_Object_Select_Mode oldmode = elm_genlist_select_mode_get(obj);
2640    if (oldmode == ELM_OBJECT_SELECT_MODE_NONE)
2641      return EINA_TRUE;
2642    else
2643      return EINA_FALSE;
2644 }
2645
2646 EAPI void
2647 elm_gengrid_bounce_set(Evas_Object *obj,
2648                        Eina_Bool    h_bounce,
2649                        Eina_Bool    v_bounce)
2650 {
2651    elm_genlist_bounce_set(obj, h_bounce, v_bounce);
2652 }
2653
2654 EAPI void
2655 elm_gengrid_bounce_get(const Evas_Object *obj,
2656                        Eina_Bool         *h_bounce,
2657                        Eina_Bool         *v_bounce)
2658 {
2659    elm_genlist_bounce_get(obj, h_bounce, v_bounce);
2660 }
2661
2662 EAPI void
2663 elm_gengrid_page_relative_set(Evas_Object *obj,
2664                               double       h_pagerel,
2665                               double       v_pagerel)
2666 {
2667    _elm_genlist_page_relative_set(obj, h_pagerel, v_pagerel);
2668 }
2669
2670 EAPI void
2671 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
2672 {
2673    _elm_genlist_page_relative_get(obj, h_pagerel, v_pagerel);
2674 }
2675
2676 EAPI void
2677 elm_gengrid_page_size_set(Evas_Object *obj,
2678                           Evas_Coord   h_pagesize,
2679                           Evas_Coord   v_pagesize)
2680 {
2681    _elm_genlist_page_size_set(obj, h_pagesize, v_pagesize);
2682 }
2683
2684 EAPI void
2685 elm_gengrid_current_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2686 {
2687    _elm_genlist_current_page_get(obj, h_pagenumber, v_pagenumber);
2688 }
2689
2690 EAPI void
2691 elm_gengrid_last_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2692 {
2693    _elm_genlist_last_page_get(obj, h_pagenumber, v_pagenumber);
2694 }
2695
2696 EAPI void
2697 elm_gengrid_page_show(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2698 {
2699    _elm_genlist_page_show(obj, h_pagenumber, v_pagenumber);
2700 }
2701
2702 EAPI void
2703 elm_gengrid_page_bring_in(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2704 {
2705    _elm_genlist_page_bring_in(obj, h_pagenumber, v_pagenumber);
2706 }
2707
2708 EAPI void
2709 elm_gengrid_scroller_policy_set(Evas_Object        *obj,
2710                                 Elm_Scroller_Policy policy_h,
2711                                 Elm_Scroller_Policy policy_v)
2712 {
2713    ELM_CHECK_WIDTYPE(obj, widtype);
2714    Widget_Data *wd = elm_widget_data_get(obj);
2715    if ((!wd) || (!wd->scr)) return;
2716    if ((policy_h >= ELM_SCROLLER_POLICY_LAST) ||
2717        (policy_v >= ELM_SCROLLER_POLICY_LAST))
2718      return;
2719    elm_smart_scroller_policy_set(wd->scr, policy_h, policy_v);
2720 }
2721
2722 EAPI void
2723 elm_gengrid_scroller_policy_get(const Evas_Object   *obj,
2724                                 Elm_Scroller_Policy *policy_h,
2725                                 Elm_Scroller_Policy *policy_v)
2726 {
2727    ELM_CHECK_WIDTYPE(obj, widtype);
2728    Widget_Data *wd = elm_widget_data_get(obj);
2729    Elm_Smart_Scroller_Policy s_policy_h, s_policy_v;
2730    if ((!wd) || (!wd->scr)) return;
2731    elm_smart_scroller_policy_get(wd->scr, &s_policy_h, &s_policy_v);
2732    if (policy_h) *policy_h = (Elm_Scroller_Policy)s_policy_h;
2733    if (policy_v) *policy_v = (Elm_Scroller_Policy)s_policy_v;
2734 }
2735
2736 EAPI Elm_Object_Item *
2737 elm_gengrid_first_item_get(const Evas_Object *obj)
2738 {
2739    return elm_genlist_first_item_get(obj);
2740 }
2741
2742 EAPI Elm_Object_Item *
2743 elm_gengrid_last_item_get(const Evas_Object *obj)
2744 {
2745    return elm_genlist_last_item_get(obj);
2746 }
2747
2748 EAPI Elm_Object_Item *
2749 elm_gengrid_item_next_get(const Elm_Object_Item *it)
2750 {
2751    return elm_genlist_item_next_get(it);
2752 }
2753
2754 EAPI Elm_Object_Item *
2755 elm_gengrid_item_prev_get(const Elm_Object_Item *it)
2756 {
2757    return elm_genlist_item_prev_get(it);
2758 }
2759
2760 EAPI Evas_Object *
2761 elm_gengrid_item_gengrid_get(const Elm_Object_Item *it)
2762 {
2763    return elm_object_item_widget_get(it);
2764 }
2765
2766 EAPI void
2767 elm_gengrid_item_show(Elm_Object_Item *it, Elm_Gengrid_Item_Scrollto_Type type)
2768 {
2769    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2770    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2771    Widget_Data *wd = _it->wd;
2772    Evas_Coord minx = 0, miny = 0;
2773
2774    if ((_it->generation < _it->wd->generation)) return;
2775    _pan_min_get(wd->pan_smart, &minx, &miny);
2776
2777    if (type==ELM_GENGRID_ITEM_SCROLLTO_IN)
2778      {
2779         //TODO : type based handling like genlist
2780      }
2781
2782    if (wd->horizontal)
2783      elm_smart_scroller_region_bring_in(_it->wd->scr,
2784                                         ((_it->x - _it->item->prev_group) * wd->item_width) + (_it->item->prev_group * _it->wd->group_item_width) + minx,
2785                                         _it->y * wd->item_height + miny,
2786                                         _it->wd->item_width,
2787                                         _it->wd->item_height);
2788    else
2789      elm_smart_scroller_region_bring_in(_it->wd->scr,
2790                                         _it->x * wd->item_width + minx,
2791                                         ((_it->y - _it->item->prev_group) * wd->item_height) + (_it->item->prev_group * _it->wd->group_item_height) + miny,
2792                                         _it->wd->item_width,
2793                                         _it->wd->item_height);
2794 }
2795
2796 EAPI void
2797 elm_gengrid_item_bring_in(Elm_Object_Item *it, Elm_Gengrid_Item_Scrollto_Type type)
2798 {
2799    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2800    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2801
2802    if (_it->generation < _it->wd->generation) return;
2803
2804    Evas_Coord minx = 0, miny = 0;
2805    Widget_Data *wd = _it->wd;
2806    _pan_min_get(wd->pan_smart, &minx, &miny);
2807
2808    if (type==ELM_GENGRID_ITEM_SCROLLTO_IN)
2809      {
2810         //TODO : type based handling like genlist
2811      }
2812
2813    if (wd->horizontal)
2814      elm_smart_scroller_region_bring_in(_it->wd->scr,
2815                                         ((_it->x - _it->item->prev_group) * wd->item_width) + (_it->item->prev_group * _it->wd->group_item_width) + minx,
2816                                         _it->y * wd->item_height + miny,
2817                                         _it->wd->item_width,
2818                                         _it->wd->item_height);
2819    else
2820      elm_smart_scroller_region_bring_in(_it->wd->scr,
2821                                         _it->x * wd->item_width + minx,
2822                                         ((_it->y - _it->item->prev_group)* wd->item_height) + (_it->item->prev_group * _it->wd->group_item_height) + miny,
2823                                         _it->wd->item_width,
2824                                         _it->wd->item_height);
2825 }
2826
2827 EAPI void
2828 elm_gengrid_filled_set(Evas_Object *obj, Eina_Bool fill)
2829 {
2830    ELM_CHECK_WIDTYPE(obj, widtype);
2831    Widget_Data *wd = elm_widget_data_get(obj);
2832    if (!wd) return;
2833    fill = !!fill;
2834    if (wd->filled != fill)
2835      wd->filled = fill;
2836 }
2837
2838 EAPI Eina_Bool
2839 elm_gengrid_filled_get(const Evas_Object *obj)
2840 {
2841    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2842    Widget_Data *wd = elm_widget_data_get(obj);
2843    if (!wd) return EINA_FALSE;
2844    return wd->filled;
2845 }
2846
2847 EAPI unsigned int
2848 elm_gengrid_items_count(const Evas_Object *obj)
2849 {
2850    ELM_CHECK_WIDTYPE(obj, widtype) 0;
2851    Widget_Data *wd = elm_widget_data_get(obj);
2852    if (!wd) return 0;
2853    return wd->item_count;
2854 }
2855
2856 EAPI Elm_Gengrid_Item_Class *
2857 elm_gengrid_item_class_new(void)
2858 {
2859    Elm_Gengrid_Item_Class *itc;
2860
2861    itc = calloc(1, sizeof(Elm_Gengrid_Item_Class));
2862    if (!itc)
2863      return NULL;
2864    itc->version = CLASS_ALLOCATED;
2865    itc->refcount = 1;
2866    itc->delete_me = EINA_FALSE;
2867
2868    return itc;
2869 }
2870
2871 EAPI void
2872 elm_gengrid_item_class_free(Elm_Gengrid_Item_Class *itc)
2873 {
2874    if (itc && (itc->version == CLASS_ALLOCATED))
2875      {
2876         if (!itc->delete_me) itc->delete_me = EINA_TRUE;
2877         if (itc->refcount > 0) elm_gengrid_item_class_unref(itc);
2878         else
2879           {
2880              itc->version = 0;
2881              free(itc);
2882           }
2883      }
2884 }
2885
2886 EAPI void
2887 elm_gengrid_item_class_ref(Elm_Gengrid_Item_Class *itc)
2888 {
2889    if (itc && (itc->version == CLASS_ALLOCATED))
2890      {
2891         itc->refcount++;
2892         if (itc->refcount == 0) itc->refcount--;
2893      }
2894 }
2895
2896 EAPI void
2897 elm_gengrid_item_class_unref(Elm_Gengrid_Item_Class *itc)
2898 {
2899    if (itc && (itc->version == CLASS_ALLOCATED))
2900      {
2901         if (itc->refcount > 0) itc->refcount--;
2902         if (itc->delete_me && (!itc->refcount))
2903           elm_gengrid_item_class_free(itc);
2904      }
2905 }
2906
2907 EAPI void
2908 elm_gengrid_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
2909 {
2910    elm_genlist_select_mode_set(obj, mode);
2911 }
2912
2913 EAPI Elm_Object_Select_Mode
2914 elm_gengrid_select_mode_get(const Evas_Object *obj)
2915 {
2916    return elm_genlist_select_mode_get(obj);
2917 }
2918
2919 EAPI void
2920 elm_gengrid_highlight_mode_set(Evas_Object *obj,
2921                                Eina_Bool    highlight)
2922 {
2923    elm_genlist_highlight_mode_set(obj, highlight);
2924 }
2925
2926 EAPI Eina_Bool
2927 elm_gengrid_highlight_mode_get(const Evas_Object *obj)
2928 {
2929    return elm_genlist_highlight_mode_get(obj);
2930 }
2931
2932 EAPI int
2933 elm_gengrid_item_index_get(const Elm_Object_Item *it)
2934 {
2935    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, -1);
2936    Elm_Gen_Item *_it = (Elm_Gen_Item *)it;
2937
2938    return _it->position;
2939 }