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