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