elementary/gengrid - elm_gengrid_item_item_class_set -> elm_gengrid_item_item_class_u...
[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_data(const void *data, const void *data1)
1859 {
1860    const Elm_Gen_Item *it = data;
1861    const Elm_Gen_Item *item1 = data1;
1862
1863    return it->wd->item_compare_data_cb(it->base.data, item1->base.data);
1864 }
1865
1866 static int
1867 _elm_gengrid_item_compare(const void *data, const void *data1)
1868 {
1869    Elm_Gen_Item *it, *item1;
1870    it = ELM_GEN_ITEM_FROM_INLIST(data);
1871    item1 = ELM_GEN_ITEM_FROM_INLIST(data1);
1872    return it->wd->item_compare_cb(it, item1);
1873 }
1874
1875 static void
1876 _item_disable_hook(Elm_Object_Item *it)
1877 {
1878    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
1879
1880    if (_it->generation < _it->wd->generation) return;
1881
1882    if (_it->realized)
1883      {
1884         if (elm_widget_item_disabled_get(_it))
1885           edje_object_signal_emit(VIEW(_it), "elm,state,disabled", "elm");
1886         else
1887           edje_object_signal_emit(VIEW(_it), "elm,state,enabled", "elm");
1888      }
1889 }
1890
1891 static void
1892 _item_del_pre_hook(Elm_Object_Item *it)
1893 {
1894    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
1895    if ((_it->relcount > 0) || (_it->walking > 0))
1896      {
1897         _elm_genlist_item_del_notserious(_it);
1898         return;
1899      }
1900
1901    _item_del(_it);
1902 }
1903
1904 static Elm_Gen_Item *
1905 _item_new(Widget_Data                  *wd,
1906           const Elm_Gengrid_Item_Class *itc,
1907           const void                   *data,
1908           Evas_Smart_Cb                 func,
1909           const void                   *func_data)
1910 {
1911    Elm_Gen_Item *it;
1912
1913    it = _elm_genlist_item_new(wd, itc, data, NULL, func, func_data);
1914    if (!it) return NULL;
1915    elm_widget_item_disable_hook_set(it, _item_disable_hook);
1916    elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
1917    elm_gengrid_item_class_ref((Elm_Gengrid_Item_Class *)itc);
1918    it->item = ELM_NEW(Elm_Gen_Item_Type);
1919    wd->item_count++;
1920    it->group = it->itc->item_style && (!strcmp(it->itc->item_style, "group_index"));
1921    ELM_GEN_ITEM_SETUP(it);
1922
1923    return it;
1924 }
1925
1926 EAPI Evas_Object *
1927 elm_gengrid_add(Evas_Object *parent)
1928 {
1929    Evas_Object *obj;
1930    Evas *e;
1931    Widget_Data *wd;
1932    static Evas_Smart *smart = NULL;
1933    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1934
1935    if (!smart)
1936      {
1937         static Evas_Smart_Class sc;
1938
1939         evas_object_smart_clipped_smart_set(&_pan_sc);
1940         sc = _pan_sc;
1941         sc.name = "elm_gengrid_pan";
1942         sc.version = EVAS_SMART_CLASS_VERSION;
1943         sc.add = _pan_add;
1944         sc.del = _pan_del;
1945         sc.resize = _pan_resize;
1946         sc.move = _pan_move;
1947         sc.calculate = _pan_calculate;
1948         if (!(smart = evas_smart_class_new(&sc))) return NULL;
1949      }
1950
1951    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1952
1953    ELM_SET_WIDTYPE(widtype, "gengrid");
1954    ELM_GEN_SETUP(wd);
1955    elm_widget_type_set(obj, "gengrid");
1956    elm_widget_sub_object_add(parent, obj);
1957    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1958    elm_widget_data_set(obj, wd);
1959    elm_widget_del_hook_set(obj, _del_hook);
1960    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1961    elm_widget_theme_hook_set(obj, _theme_hook);
1962    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1963    elm_widget_can_focus_set(obj, EINA_TRUE);
1964    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1965    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1966    elm_widget_event_hook_set(obj, _event_hook);
1967
1968    wd->generation = 1;
1969    wd->scr = elm_smart_scroller_add(e);
1970    elm_smart_scroller_widget_set(wd->scr, obj);
1971    elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
1972                                        "default");
1973    elm_smart_scroller_bounce_allow_set(wd->scr, bounce,
1974                                        _elm_config->thumbscroll_bounce_enable);
1975    elm_widget_resize_object_set(obj, wd->scr);
1976
1977    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1978    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1979    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1980    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1981    evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
1982    evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
1983    evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
1984    evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom,
1985                                   obj);
1986    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1987
1988    wd->obj = obj;
1989    wd->align_x = 0.5;
1990    wd->align_y = 0.5;
1991    wd->h_bounce = bounce;
1992    wd->v_bounce = bounce;
1993
1994    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1995    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1996    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1997    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1998
1999    wd->pan_smart = evas_object_smart_add(e, smart);
2000    wd->pan = evas_object_smart_data_get(wd->pan_smart);
2001    wd->pan->wd = wd;
2002
2003    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
2004                                      _pan_set, _pan_get, _pan_max_get,
2005                                      _pan_min_get, _pan_child_size_get);
2006
2007    evas_object_smart_callbacks_descriptions_set(obj, _signals);
2008
2009    _mirrored_set(obj, elm_widget_mirrored_get(obj));
2010    return obj;
2011 }
2012
2013 EAPI void
2014 elm_gengrid_item_size_set(Evas_Object *obj,
2015                           Evas_Coord   w,
2016                           Evas_Coord   h)
2017 {
2018    ELM_CHECK_WIDTYPE(obj, widtype);
2019    Widget_Data *wd = elm_widget_data_get(obj);
2020    if (!wd) return;
2021    if ((wd->item_width == w) && (wd->item_height == h)) return;
2022    wd->item_width = w;
2023    wd->item_height = h;
2024    if (wd->calc_job) ecore_job_del(wd->calc_job);
2025    wd->calc_job = ecore_job_add(_calc_job, wd);
2026 }
2027
2028 EAPI void
2029 elm_gengrid_item_size_get(const Evas_Object *obj,
2030                           Evas_Coord        *w,
2031                           Evas_Coord        *h)
2032 {
2033    ELM_CHECK_WIDTYPE(obj, widtype);
2034    Widget_Data *wd = elm_widget_data_get(obj);
2035    if (!wd) return;
2036    if (w) *w = wd->item_width;
2037    if (h) *h = wd->item_height;
2038 }
2039
2040 EAPI void
2041 elm_gengrid_group_item_size_set(Evas_Object *obj,
2042                           Evas_Coord   w,
2043                           Evas_Coord   h)
2044 {
2045    ELM_CHECK_WIDTYPE(obj, widtype);
2046    Widget_Data *wd = elm_widget_data_get(obj);
2047    if (!wd) return;
2048    if ((wd->group_item_width == w) && (wd->group_item_height == h)) return;
2049    wd->group_item_width = w;
2050    wd->group_item_height = h;
2051    if (wd->calc_job) ecore_job_del(wd->calc_job);
2052    wd->calc_job = ecore_job_add(_calc_job, wd);
2053 }
2054
2055 EAPI void
2056 elm_gengrid_group_item_size_get(const Evas_Object *obj,
2057                           Evas_Coord        *w,
2058                           Evas_Coord        *h)
2059 {
2060    ELM_CHECK_WIDTYPE(obj, widtype);
2061    Widget_Data *wd = elm_widget_data_get(obj);
2062    if (!wd) return;
2063    if (w) *w = wd->group_item_width;
2064    if (h) *h = wd->group_item_height;
2065 }
2066
2067 EAPI void
2068 elm_gengrid_align_set(Evas_Object *obj,
2069                       double       align_x,
2070                       double       align_y)
2071 {
2072    ELM_CHECK_WIDTYPE(obj, widtype);
2073
2074    Widget_Data *wd = elm_widget_data_get(obj);
2075    double old_h = wd->align_x, old_y = wd->align_y;
2076
2077    if (align_x > 1.0)
2078      align_x = 1.0;
2079    else if (align_x < 0.0)
2080      align_x = 0.0;
2081    wd->align_x = align_x;
2082
2083    if (align_y > 1.0)
2084      align_y = 1.0;
2085    else if (align_y < 0.0)
2086      align_y = 0.0;
2087    wd->align_y = align_y;
2088
2089    if ((old_h != wd->align_x) || (old_y != wd->align_y))
2090      evas_object_smart_calculate(wd->pan_smart);
2091 }
2092
2093 EAPI void
2094 elm_gengrid_align_get(const Evas_Object *obj,
2095                       double            *align_x,
2096                       double            *align_y)
2097 {
2098    ELM_CHECK_WIDTYPE(obj, widtype);
2099    Widget_Data *wd = elm_widget_data_get(obj);
2100    if (align_x) *align_x = wd->align_x;
2101    if (align_y) *align_y = wd->align_y;
2102 }
2103
2104 EAPI Elm_Object_Item *
2105 elm_gengrid_item_append(Evas_Object                  *obj,
2106                         const Elm_Gengrid_Item_Class *itc,
2107                         const void                   *data,
2108                         Evas_Smart_Cb                 func,
2109                         const void                   *func_data)
2110 {
2111    Elm_Gen_Item *it;
2112    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2113    Widget_Data *wd = elm_widget_data_get(obj);
2114    if (!wd) return NULL;
2115
2116    it = _item_new(wd, itc, data, func, func_data);
2117    if (!it) return NULL;
2118    wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
2119
2120    if (it->group)
2121      wd->group_items = eina_list_prepend(wd->group_items, it);
2122
2123    if (wd->calc_job) ecore_job_del(wd->calc_job);
2124    wd->calc_job = ecore_job_add(_calc_job, wd);
2125
2126    return (Elm_Object_Item *) it;
2127 }
2128
2129 EAPI Elm_Object_Item *
2130 elm_gengrid_item_prepend(Evas_Object                  *obj,
2131                          const Elm_Gengrid_Item_Class *itc,
2132                          const void                   *data,
2133                          Evas_Smart_Cb                 func,
2134                          const void                   *func_data)
2135 {
2136    Elm_Gen_Item *it;
2137    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2138    Widget_Data *wd = elm_widget_data_get(obj);
2139    if (!wd) return NULL;
2140
2141    it = _item_new(wd, itc, data, func, func_data);
2142    if (!it) return NULL;
2143    wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
2144    if (it->group)
2145      wd->group_items = eina_list_append(wd->group_items, it);
2146
2147    if (wd->calc_job) ecore_job_del(wd->calc_job);
2148    wd->calc_job = ecore_job_add(_calc_job, wd);
2149
2150    return (Elm_Object_Item *) it;
2151 }
2152
2153 EAPI Elm_Object_Item *
2154 elm_gengrid_item_insert_before(Evas_Object                  *obj,
2155                                const Elm_Gengrid_Item_Class *itc,
2156                                const void                   *data,
2157                                Elm_Object_Item              *relative,
2158                                Evas_Smart_Cb                 func,
2159                                const void                   *func_data)
2160 {
2161    Elm_Gen_Item *it;
2162    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2163    ELM_OBJ_ITEM_CHECK_OR_RETURN(relative, NULL);
2164    Widget_Data *wd = elm_widget_data_get(obj);
2165    if (!wd) return NULL;
2166
2167    it = _item_new(wd, itc, data, func, func_data);
2168    if (!it) return NULL;
2169    wd->items = eina_inlist_prepend_relative
2170       (wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET((Elm_Gen_Item *) relative));
2171    if (it->group)
2172      wd->group_items = eina_list_append_relative(wd->group_items, it, ((Elm_Gen_Item *) relative)->parent);
2173
2174    if (wd->calc_job) ecore_job_del(wd->calc_job);
2175    wd->calc_job = ecore_job_add(_calc_job, wd);
2176
2177    return (Elm_Object_Item *) it;
2178 }
2179
2180 EAPI Elm_Object_Item *
2181 elm_gengrid_item_insert_after(Evas_Object                  *obj,
2182                               const Elm_Gengrid_Item_Class *itc,
2183                               const void                   *data,
2184                               Elm_Object_Item              *relative,
2185                               Evas_Smart_Cb                 func,
2186                               const void                   *func_data)
2187 {
2188    Elm_Gen_Item *it;
2189    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2190    ELM_OBJ_ITEM_CHECK_OR_RETURN(relative, NULL);
2191    Widget_Data *wd = elm_widget_data_get(obj);
2192    if (!wd) return NULL;
2193
2194    it = _item_new(wd, itc, data, func, func_data);
2195    if (!it) return NULL;
2196    wd->items = eina_inlist_append_relative
2197       (wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET((Elm_Gen_Item *) relative));
2198    if (it->group)
2199      wd->group_items = eina_list_prepend_relative(wd->group_items, it, ((Elm_Gen_Item *) relative)->parent);
2200
2201    if (wd->calc_job) ecore_job_del(wd->calc_job);
2202    wd->calc_job = ecore_job_add(_calc_job, wd);
2203
2204    return (Elm_Object_Item *) it;
2205 }
2206
2207 EAPI Elm_Object_Item *
2208 elm_gengrid_item_direct_sorted_insert(Evas_Object                  *obj,
2209                                       const Elm_Gengrid_Item_Class *itc,
2210                                       const void                   *data,
2211                                       Eina_Compare_Cb               comp,
2212                                       Evas_Smart_Cb                 func,
2213                                       const void                   *func_data)
2214 {
2215    Elm_Gen_Item *it;
2216    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2217    Widget_Data *wd = elm_widget_data_get(obj);
2218    if (!wd) return NULL;
2219
2220    it = _item_new(wd, itc, data, func, func_data);
2221    if (!it) return NULL;
2222
2223    if (!wd->state)
2224      wd->state = eina_inlist_sorted_state_new();
2225
2226    wd->item_compare_cb = comp;
2227    wd->items = eina_inlist_sorted_state_insert(wd->items, EINA_INLIST_GET(it),
2228                                          _elm_gengrid_item_compare, wd->state);
2229    if (wd->calc_job) ecore_job_del(wd->calc_job);
2230    wd->calc_job = ecore_job_add(_calc_job, wd);
2231
2232    return (Elm_Object_Item *) it;
2233 }
2234
2235 EAPI Elm_Object_Item *
2236 elm_gengrid_item_sorted_insert(Evas_Object                  *obj,
2237                                const Elm_Gengrid_Item_Class *itc,
2238                                const void                   *data,
2239                                Eina_Compare_Cb               comp,
2240                                Evas_Smart_Cb                 func,
2241                                const void                   *func_data)
2242 {
2243    Widget_Data *wd = elm_widget_data_get(obj);
2244    wd->item_compare_data_cb = comp;
2245
2246    return elm_gengrid_item_direct_sorted_insert(obj, itc, data, _elm_gengrid_item_compare_data, func, func_data);
2247 }
2248
2249 EAPI void
2250 elm_gengrid_item_del(Elm_Object_Item *it)
2251 {
2252    elm_object_item_del(it);
2253 }
2254
2255 EAPI void
2256 elm_gengrid_horizontal_set(Evas_Object *obj,
2257                            Eina_Bool    horizontal)
2258 {
2259    ELM_CHECK_WIDTYPE(obj, widtype);
2260    Widget_Data *wd = elm_widget_data_get(obj);
2261    if (!wd) return;
2262    horizontal = !!horizontal;
2263    if (horizontal == wd->horizontal) return;
2264    wd->horizontal = horizontal;
2265
2266    /* Update the items to conform to the new layout */
2267    if (wd->calc_job) ecore_job_del(wd->calc_job);
2268    wd->calc_job = ecore_job_add(_calc_job, wd);
2269 }
2270
2271 EAPI Eina_Bool
2272 elm_gengrid_horizontal_get(const Evas_Object *obj)
2273 {
2274    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2275    Widget_Data *wd = elm_widget_data_get(obj);
2276    if (!wd) return EINA_FALSE;
2277    return wd->horizontal;
2278 }
2279
2280 EAPI void
2281 elm_gengrid_clear(Evas_Object *obj)
2282 {
2283    elm_genlist_clear(obj);
2284 }
2285
2286 EINA_DEPRECATED EAPI const Evas_Object *
2287 elm_gengrid_item_object_get(const Elm_Object_Item *it)
2288 {
2289    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2290    return VIEW(it);
2291 }
2292
2293 EAPI void
2294 elm_gengrid_item_update(Elm_Object_Item *it)
2295 {
2296    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2297    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2298    if (!_it->realized) return;
2299    if (_it->want_unrealize) return;
2300    _elm_genlist_item_unrealize(_it, EINA_FALSE);
2301    _item_realize(_it);
2302    _item_place(_it, _it->x, _it->y);
2303 }
2304
2305 EAPI void *
2306 elm_gengrid_item_data_get(const Elm_Object_Item *it)
2307 {
2308    return elm_object_item_data_get(it);
2309 }
2310
2311 EAPI void
2312 elm_gengrid_item_data_set(Elm_Object_Item  *it,
2313                           const void       *data)
2314 {
2315    elm_object_item_data_set(it, (void *) data);
2316 }
2317
2318 EAPI const Elm_Gengrid_Item_Class *
2319 elm_gengrid_item_item_class_get(const Elm_Object_Item *it)
2320 {
2321    return (Elm_Gengrid_Item_Class *) elm_genlist_item_item_class_get(it);
2322 }
2323
2324 EINA_DEPRECATED EAPI void
2325 elm_gengrid_item_item_class_set(Elm_Object_Item *it,
2326                                 const Elm_Gengrid_Item_Class *itc)
2327 {
2328    elm_gengrid_item_item_class_update(it, itc);
2329 }
2330
2331 EAPI void
2332 elm_gengrid_item_item_class_update(Elm_Object_Item *it,
2333                                    const Elm_Gengrid_Item_Class *itc)
2334 {
2335    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2336    EINA_SAFETY_ON_NULL_RETURN(itc);
2337    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2338    if (_it->generation < _it->wd->generation) return;
2339    _it->itc = itc;
2340    elm_gengrid_item_update(it);
2341 }
2342
2343 EAPI void
2344 elm_gengrid_item_pos_get(const Elm_Object_Item *it,
2345                          unsigned int           *x,
2346                          unsigned int           *y)
2347 {
2348    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2349    if (x) *x = ((Elm_Gen_Item *) it)->x;
2350    if (y) *y = ((Elm_Gen_Item *) it)->y;
2351 }
2352
2353 EAPI void
2354 elm_gengrid_multi_select_set(Evas_Object *obj,
2355                              Eina_Bool    multi)
2356 {
2357    ELM_CHECK_WIDTYPE(obj, widtype);
2358    Widget_Data *wd = elm_widget_data_get(obj);
2359    if (!wd) return;
2360    wd->multi = !!multi;
2361 }
2362
2363 EAPI Eina_Bool
2364 elm_gengrid_multi_select_get(const Evas_Object *obj)
2365 {
2366    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2367    Widget_Data *wd = elm_widget_data_get(obj);
2368    if (!wd) return EINA_FALSE;
2369    return wd->multi;
2370 }
2371
2372 EAPI Elm_Object_Item *
2373 elm_gengrid_selected_item_get(const Evas_Object *obj)
2374 {
2375    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2376    Widget_Data *wd = elm_widget_data_get(obj);
2377    if (!wd) return NULL;
2378    if (wd->selected) return wd->selected->data;
2379    return NULL;
2380 }
2381
2382 EAPI const Eina_List *
2383 elm_gengrid_selected_items_get(const Evas_Object *obj)
2384 {
2385    return elm_gengrid_selected_items_get(obj);
2386 }
2387
2388 EAPI void
2389 elm_gengrid_item_selected_set(Elm_Object_Item  *it,
2390                               Eina_Bool         selected)
2391 {
2392    elm_genlist_item_selected_set(it, selected);
2393 }
2394
2395 EAPI Eina_Bool
2396 elm_gengrid_item_selected_get(const Elm_Object_Item *it)
2397 {
2398    return elm_genlist_item_selected_get(it);
2399 }
2400
2401 EAPI void
2402 elm_gengrid_item_disabled_set(Elm_Object_Item  *it,
2403                               Eina_Bool         disabled)
2404 {
2405    elm_object_item_disabled_set(it, disabled);
2406 }
2407
2408 EAPI Eina_Bool
2409 elm_gengrid_item_disabled_get(const Elm_Object_Item *it)
2410 {
2411    return elm_object_item_disabled_get(it);
2412 }
2413
2414 static Evas_Object *
2415 _elm_gengrid_item_label_create(void        *data,
2416                                Evas_Object *obj __UNUSED__,
2417                                Evas_Object *tooltip,
2418                                void *it   __UNUSED__)
2419 {
2420    Evas_Object *label = elm_label_add(tooltip);
2421    if (!label)
2422      return NULL;
2423    elm_object_style_set(label, "tooltip");
2424    elm_object_text_set(label, data);
2425    return label;
2426 }
2427
2428 static void
2429 _elm_gengrid_item_label_del_cb(void            *data,
2430                                Evas_Object *obj __UNUSED__,
2431                                void *event_info __UNUSED__)
2432 {
2433    eina_stringshare_del(data);
2434 }
2435
2436 EAPI void
2437 elm_gengrid_item_tooltip_text_set(Elm_Object_Item  *it,
2438                                   const char       *text)
2439 {
2440    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2441    text = eina_stringshare_add(text);
2442    elm_gengrid_item_tooltip_content_cb_set(it, _elm_gengrid_item_label_create,
2443                                            text,
2444                                            _elm_gengrid_item_label_del_cb);
2445 }
2446
2447 EAPI void
2448 elm_gengrid_item_tooltip_content_cb_set(Elm_Object_Item            *it,
2449                                         Elm_Tooltip_Item_Content_Cb func,
2450                                         const void                 *data,
2451                                         Evas_Smart_Cb               del_cb)
2452 {
2453    ELM_OBJ_ITEM_CHECK_OR_GOTO(it, error);
2454    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2455
2456    if ((_it->tooltip.content_cb == func) && (_it->tooltip.data == data))
2457      return;
2458
2459    if (_it->tooltip.del_cb)
2460      _it->tooltip.del_cb((void *)_it->tooltip.data, WIDGET(_it), _it);
2461    _it->tooltip.content_cb = func;
2462    _it->tooltip.data = data;
2463    _it->tooltip.del_cb = del_cb;
2464    if (VIEW(_it))
2465      {
2466         elm_widget_item_tooltip_content_cb_set(_it,
2467                                                _it->tooltip.content_cb,
2468                                                _it->tooltip.data, NULL);
2469         elm_widget_item_tooltip_style_set(_it, _it->tooltip.style);
2470         elm_widget_item_tooltip_window_mode_set(_it, _it->tooltip.free_size);
2471      }
2472
2473    return;
2474
2475 error:
2476    if (del_cb) del_cb((void *)data, NULL, NULL);
2477 }
2478
2479 EAPI void
2480 elm_gengrid_item_tooltip_unset(Elm_Object_Item *it)
2481 {
2482    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2483    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2484
2485    if ((VIEW(_it)) && (_it->tooltip.content_cb))
2486      elm_widget_item_tooltip_unset(_it);
2487
2488    if (_it->tooltip.del_cb)
2489      _it->tooltip.del_cb((void *) _it->tooltip.data, WIDGET(_it), _it);
2490    _it->tooltip.del_cb = NULL;
2491    _it->tooltip.content_cb = NULL;
2492    _it->tooltip.data = NULL;
2493    _it->tooltip.free_size = EINA_FALSE;
2494    if (_it->tooltip.style)
2495      elm_gengrid_item_tooltip_style_set(it, NULL);
2496 }
2497
2498 EAPI void
2499 elm_gengrid_item_tooltip_style_set(Elm_Object_Item  *it,
2500                                    const char       *style)
2501 {
2502    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2503    eina_stringshare_replace(&((Elm_Gen_Item *) it)->tooltip.style, style);
2504    if (VIEW(it)) elm_widget_item_tooltip_style_set(it, style);
2505 }
2506
2507 EAPI const char *
2508 elm_gengrid_item_tooltip_style_get(const Elm_Object_Item *it)
2509 {
2510    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2511    return ((Elm_Gen_Item *) it)->tooltip.style;
2512 }
2513
2514 EAPI Eina_Bool
2515 elm_gengrid_item_tooltip_window_mode_set(Elm_Object_Item *it, Eina_Bool disable)
2516 {
2517    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2518    ((Elm_Gen_Item *) it)->tooltip.free_size = disable;
2519    if (VIEW(it)) return elm_widget_item_tooltip_window_mode_set(it, disable);
2520    return EINA_TRUE;
2521 }
2522
2523 EAPI Eina_Bool
2524 elm_gengrid_item_tooltip_window_mode_get(const Elm_Object_Item *it)
2525 {
2526    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2527    return ((Elm_Gen_Item *) it)->tooltip.free_size;
2528 }
2529
2530 EAPI void
2531 elm_gengrid_item_cursor_set(Elm_Object_Item  *it,
2532                             const char       *cursor)
2533 {
2534    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2535    eina_stringshare_replace(&((Elm_Gen_Item *) it)->mouse_cursor, cursor);
2536    if (VIEW(it)) elm_widget_item_cursor_set(it, cursor);
2537 }
2538
2539 EAPI const char *
2540 elm_gengrid_item_cursor_get(const Elm_Object_Item *it)
2541 {
2542    return elm_widget_item_cursor_get(it);
2543 }
2544
2545 EAPI void
2546 elm_gengrid_item_cursor_unset(Elm_Object_Item *it)
2547 {
2548    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2549    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2550    if (!_it->mouse_cursor)
2551      return;
2552
2553    if (VIEW(_it))
2554      elm_widget_item_cursor_unset(_it);
2555
2556    eina_stringshare_del(_it->mouse_cursor);
2557    _it->mouse_cursor = NULL;
2558 }
2559
2560 EAPI void
2561 elm_gengrid_item_cursor_style_set(Elm_Object_Item  *it,
2562                                   const char       *style)
2563 {
2564    elm_widget_item_cursor_style_set(it, style);
2565 }
2566
2567 EAPI const char *
2568 elm_gengrid_item_cursor_style_get(const Elm_Object_Item *it)
2569 {
2570    return elm_widget_item_cursor_style_get(it);
2571 }
2572
2573 EAPI void
2574 elm_gengrid_item_cursor_engine_only_set(Elm_Object_Item  *it,
2575                                         Eina_Bool         engine_only)
2576 {
2577    elm_widget_item_cursor_engine_only_set(it, engine_only);
2578 }
2579
2580 EAPI Eina_Bool
2581 elm_gengrid_item_cursor_engine_only_get(const Elm_Object_Item *it)
2582 {
2583    return elm_widget_item_cursor_engine_only_get(it);
2584 }
2585
2586 EAPI void
2587 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2588                              Eina_Bool    reorder_mode)
2589 {
2590    ELM_CHECK_WIDTYPE(obj, widtype);
2591    Widget_Data *wd = elm_widget_data_get(obj);
2592    if (!wd) return;
2593    wd->reorder_mode = !!reorder_mode;
2594 }
2595
2596 EAPI Eina_Bool
2597 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
2598 {
2599    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2600    Widget_Data *wd = elm_widget_data_get(obj);
2601    if (!wd) return EINA_FALSE;
2602    return wd->reorder_mode;
2603 }
2604
2605 EAPI void
2606 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2607                                    Eina_Bool    always_select)
2608 {
2609    elm_genlist_always_select_mode_set(obj, always_select);
2610 }
2611
2612 EAPI Eina_Bool
2613 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2614 {
2615    return elm_genlist_always_select_mode_get(obj);
2616 }
2617
2618 EAPI void
2619 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2620                                Eina_Bool    no_select)
2621 {
2622    elm_genlist_no_select_mode_set(obj, no_select);
2623 }
2624
2625 EAPI Eina_Bool
2626 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2627 {
2628    return elm_genlist_no_select_mode_get(obj);
2629 }
2630
2631 EAPI void
2632 elm_gengrid_bounce_set(Evas_Object *obj,
2633                        Eina_Bool    h_bounce,
2634                        Eina_Bool    v_bounce)
2635 {
2636    elm_genlist_bounce_set(obj, h_bounce, v_bounce);
2637 }
2638
2639 EAPI void
2640 elm_gengrid_bounce_get(const Evas_Object *obj,
2641                        Eina_Bool         *h_bounce,
2642                        Eina_Bool         *v_bounce)
2643 {
2644    elm_genlist_bounce_get(obj, h_bounce, v_bounce);
2645 }
2646
2647 EAPI void
2648 elm_gengrid_page_relative_set(Evas_Object *obj,
2649                               double       h_pagerel,
2650                               double       v_pagerel)
2651 {
2652    _elm_genlist_page_relative_set(obj, h_pagerel, v_pagerel);
2653 }
2654
2655 EAPI void
2656 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
2657 {
2658    _elm_genlist_page_relative_get(obj, h_pagerel, v_pagerel);
2659 }
2660
2661 EAPI void
2662 elm_gengrid_page_size_set(Evas_Object *obj,
2663                           Evas_Coord   h_pagesize,
2664                           Evas_Coord   v_pagesize)
2665 {
2666    _elm_genlist_page_size_set(obj, h_pagesize, v_pagesize);
2667 }
2668
2669 EAPI void
2670 elm_gengrid_current_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2671 {
2672    _elm_genlist_current_page_get(obj, h_pagenumber, v_pagenumber);
2673 }
2674
2675 EAPI void
2676 elm_gengrid_last_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2677 {
2678    _elm_genlist_last_page_get(obj, h_pagenumber, v_pagenumber);
2679 }
2680
2681 EAPI void
2682 elm_gengrid_page_show(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2683 {
2684    _elm_genlist_page_show(obj, h_pagenumber, v_pagenumber);
2685 }
2686
2687 EAPI void
2688 elm_gengrid_page_bring_in(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2689 {
2690    _elm_genlist_page_bring_in(obj, h_pagenumber, v_pagenumber);
2691 }
2692
2693 EAPI Elm_Object_Item *
2694 elm_gengrid_first_item_get(const Evas_Object *obj)
2695 {
2696    return elm_genlist_first_item_get(obj);
2697 }
2698
2699 EAPI Elm_Object_Item *
2700 elm_gengrid_last_item_get(const Evas_Object *obj)
2701 {
2702    return elm_genlist_last_item_get(obj);
2703 }
2704
2705 EAPI Elm_Object_Item *
2706 elm_gengrid_item_next_get(const Elm_Object_Item *it)
2707 {
2708    return elm_genlist_item_next_get(it);
2709 }
2710
2711 EAPI Elm_Object_Item *
2712 elm_gengrid_item_prev_get(const Elm_Object_Item *it)
2713 {
2714    return elm_genlist_item_prev_get(it);
2715 }
2716
2717 EAPI Evas_Object *
2718 elm_gengrid_item_gengrid_get(const Elm_Object_Item *it)
2719 {
2720    return elm_object_item_widget_get(it);
2721 }
2722
2723 EAPI void
2724 elm_gengrid_item_show(Elm_Object_Item *it)
2725 {
2726    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2727    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2728    Widget_Data *wd = _it->wd;
2729    Evas_Coord minx = 0, miny = 0;
2730
2731    if ((_it->generation < _it->wd->generation)) return;
2732    _pan_min_get(wd->pan_smart, &minx, &miny);
2733
2734    if (wd->horizontal)
2735      elm_smart_scroller_region_bring_in(_it->wd->scr,
2736                                         ((_it->x - _it->item->prev_group) * wd->item_width) + (_it->item->prev_group * _it->wd->group_item_width) + minx,
2737                                         _it->y * wd->item_height + miny,
2738                                         _it->wd->item_width,
2739                                         _it->wd->item_height);
2740    else
2741      elm_smart_scroller_region_bring_in(_it->wd->scr,
2742                                         _it->x * wd->item_width + minx,
2743                                         ((_it->y - _it->item->prev_group) * wd->item_height) + (_it->item->prev_group * _it->wd->group_item_height) + miny,
2744                                         _it->wd->item_width,
2745                                         _it->wd->item_height);
2746 }
2747
2748 EAPI void
2749 elm_gengrid_item_bring_in(Elm_Object_Item *it)
2750 {
2751    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2752    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2753
2754    if (_it->generation < _it->wd->generation) return;
2755
2756    Evas_Coord minx = 0, miny = 0;
2757    Widget_Data *wd = _it->wd;
2758    _pan_min_get(wd->pan_smart, &minx, &miny);
2759
2760    if (wd->horizontal)
2761      elm_smart_scroller_region_bring_in(_it->wd->scr,
2762                                         ((_it->x - _it->item->prev_group) * wd->item_width) + (_it->item->prev_group * _it->wd->group_item_width) + minx,
2763                                         _it->y * wd->item_height + miny,
2764                                         _it->wd->item_width,
2765                                         _it->wd->item_height);
2766    else
2767      elm_smart_scroller_region_bring_in(_it->wd->scr,
2768                                         _it->x * wd->item_width + minx,
2769                                         ((_it->y - _it->item->prev_group)* wd->item_height) + (_it->item->prev_group * _it->wd->group_item_height) + miny,
2770                                         _it->wd->item_width,
2771                                         _it->wd->item_height);
2772 }
2773
2774 EAPI void
2775 elm_gengrid_filled_set(Evas_Object *obj, Eina_Bool fill)
2776 {
2777    ELM_CHECK_WIDTYPE(obj, widtype);
2778    Widget_Data *wd = elm_widget_data_get(obj);
2779    if (!wd) return;
2780    fill = !!fill;
2781    if (wd->filled != fill)
2782      wd->filled = fill;
2783 }
2784
2785 EAPI Eina_Bool
2786 elm_gengrid_filled_get(const Evas_Object *obj)
2787 {
2788    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2789    Widget_Data *wd = elm_widget_data_get(obj);
2790    if (!wd) return EINA_FALSE;
2791    return wd->filled;
2792 }
2793
2794 EAPI Elm_Gengrid_Item_Class *
2795 elm_gengrid_item_class_new(void)
2796 {
2797    Elm_Gengrid_Item_Class *itc;
2798
2799    itc = calloc(1, sizeof(Elm_Gengrid_Item_Class));
2800    if (!itc)
2801      return NULL;
2802    itc->version = ELM_GENGRID_ITEM_CLASS_VERSION;
2803    itc->refcount = 1;
2804    itc->delete_me = EINA_FALSE;
2805
2806    return itc;
2807 }
2808
2809 EAPI void
2810 elm_gengrid_item_class_free(Elm_Gengrid_Item_Class *itc)
2811 {
2812    ELM_GENGRID_CHECK_ITC_VER(itc);
2813    if (!itc->delete_me) itc->delete_me = EINA_TRUE;
2814    if (itc->refcount > 0) elm_gengrid_item_class_unref(itc);
2815    else
2816      {
2817         itc->version = 0;
2818         free(itc);
2819      }
2820 }
2821
2822 EAPI void
2823 elm_gengrid_item_class_ref(Elm_Gengrid_Item_Class *itc)
2824 {
2825    ELM_GENGRID_CHECK_ITC_VER(itc);
2826
2827    itc->refcount++;
2828    if (itc->refcount == 0) itc->refcount--;
2829 }
2830
2831 EAPI void
2832 elm_gengrid_item_class_unref(Elm_Gengrid_Item_Class *itc)
2833 {
2834    ELM_GENGRID_CHECK_ITC_VER(itc);
2835
2836    if (itc->refcount > 0) itc->refcount--;
2837    if (itc->delete_me && (!itc->refcount))
2838      elm_gengrid_item_class_free(itc);
2839 }
2840