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