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