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