EFL migration revision 67547
[framework/uifw/elementary.git] / src / lib / elm_gengrid.c
1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
3 #include "elm_priv.h"
4 #include "els_scroller.h"
5 #include "elm_gen_common.h"
6
7 /* --
8  * TODO:
9  * Handle non-homogeneous objects too.
10  */
11
12 #define PRELOAD 1
13 #define REORDER_EFFECT_TIME 0.5
14
15 #define ELM_GEN_SETUP(wd) \
16    (wd)->calc_cb = (Ecore_Cb)_calc_job
17
18 #define ELM_GEN_ITEM_SETUP(it) \
19    (it)->del_cb = (Ecore_Cb)_item_del; \
20    (it)->highlight_cb = (Ecore_Cb)_item_highlight; \
21    (it)->unsel_cb = (Ecore_Cb)_item_unselect; \
22    (it)->unrealize_cb = (Ecore_Cb)_item_unrealize_cb
23
24 struct Elm_Gen_Item_Type
25 {
26    Elm_Gen_Item   *it;
27    Ecore_Animator *item_moving_effect_timer;
28    Evas_Coord   gx, gy, ox, oy, tx, ty, rx, ry;
29    unsigned int moving_effect_start_time;
30    int          prev_group;
31
32    Eina_Bool   group_realized : 1;
33    Eina_Bool   moving : 1;
34 };
35
36 #if 0
37 struct _Widget_Data
38 {
39    Eina_Inlist_Sorted_State *state;
40    Evas_Object      *obj; /* the gengrid object */
41    Evas_Object      *scr; /* a smart scroller object which is used internally in genlist */
42    Evas_Object      *pan_smart; /* "elm_genlist_pan" evas smart object. this is an extern pan of smart scroller(scr). */
43    Eina_List        *selected;
44    Eina_List        *group_items; /* list of groups index items */
45    Eina_Inlist      *items; /* inlist of all items */
46    Elm_Gen_Item     *reorder_it; /* item currently being repositioned */
47    Elm_Gen_Item     *last_selected_item;
48    Pan              *pan; /* pan_smart object's smart data */
49    Ecore_Job        *calc_job;
50    int               walking;
51    int               item_width, item_height;
52    int               group_item_width, group_item_height;
53    int               minw, minh;
54    long              count;
55    Evas_Coord        pan_x, pan_y;
56    Eina_Bool         reorder_mode : 1;
57    Eina_Bool         on_hold : 1;
58    Eina_Bool         multi : 1;
59    Eina_Bool         no_select : 1;
60    Eina_Bool         wasselected : 1;
61    Eina_Bool         always_select : 1;
62    Eina_Bool         clear_me : 1;
63    Eina_Bool         h_bounce : 1;
64    Eina_Bool         v_bounce : 1;
65    Ecore_Cb          del_cb, calc_cb, sizing_cb;
66    Ecore_Cb          clear_cb;
67    ////////////////////////////////////
68    double            align_x, align_y;
69
70    Evas_Coord        old_pan_x, old_pan_y;
71    Evas_Coord        reorder_item_x, reorder_item_y;
72    unsigned int      nmax;
73    long              items_lost;
74
75    int               generation;
76
77    Eina_Bool         horizontal : 1;
78    Eina_Bool         longpressed : 1;
79    Eina_Bool         reorder_item_changed : 1;
80    Eina_Bool         move_effect_enabled : 1;
81 };
82 #endif
83
84 static const char *widtype = NULL;
85 static void      _item_highlight(Elm_Gen_Item *it);
86 static void      _item_unrealize_cb(Elm_Gen_Item *it);
87 static void      _item_unselect(Elm_Gen_Item *it);
88 static void      _calc_job(void *data);
89 static void      _on_focus_hook(void        *data,
90                                 Evas_Object *obj);
91 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
92 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
93 static Eina_Bool _item_multi_select_left(Widget_Data *wd);
94 static Eina_Bool _item_multi_select_right(Widget_Data *wd);
95 static Eina_Bool _item_single_select_up(Widget_Data *wd);
96 static Eina_Bool _item_single_select_down(Widget_Data *wd);
97 static Eina_Bool _item_single_select_left(Widget_Data *wd);
98 static Eina_Bool _item_single_select_right(Widget_Data *wd);
99 static Eina_Bool _event_hook(Evas_Object       *obj,
100                              Evas_Object       *src,
101                              Evas_Callback_Type type,
102                              void              *event_info);
103 static Eina_Bool _deselect_all_items(Widget_Data *wd);
104 #if 1
105 static void      _elm_gengrid_clear(Evas_Object *obj,
106                                     Eina_Bool    standby);
107 #endif
108
109 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
110 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
111
112 static const char SIG_ACTIVATED[] = "activated";
113 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
114 static const char SIG_LONGPRESSED[] = "longpressed";
115 static const char SIG_SELECTED[] = "selected";
116 static const char SIG_UNSELECTED[] = "unselected";
117 static const char SIG_REALIZED[] = "realized";
118 static const char SIG_UNREALIZED[] = "unrealized";
119 static const char SIG_CHANGED[] = "changed";
120 static const char SIG_DRAG_START_UP[] = "drag,start,up";
121 static const char SIG_DRAG_START_DOWN[] = "drag,start,down";
122 static const char SIG_DRAG_START_LEFT[] = "drag,start,left";
123 static const char SIG_DRAG_START_RIGHT[] = "drag,start,right";
124 static const char SIG_DRAG_STOP[] = "drag,stop";
125 static const char SIG_DRAG[] = "drag";
126 static const char SIG_SCROLL[] = "scroll";
127 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
128 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
129 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
130 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
131 static const char SIG_EDGE_TOP[] = "edge,top";
132 static const char SIG_EDGE_BOTTOM[] = "edge,bottom";
133 static const char SIG_EDGE_LEFT[] = "edge,left";
134 static const char SIG_EDGE_RIGHT[] = "edge,right";
135 static const char SIG_MOVED[] = "moved";
136
137 static const Evas_Smart_Cb_Description _signals[] = {
138    {SIG_ACTIVATED, ""},
139    {SIG_CLICKED_DOUBLE, ""},
140    {SIG_LONGPRESSED, ""},
141    {SIG_SELECTED, ""},
142    {SIG_UNSELECTED, ""},
143    {SIG_REALIZED, ""},
144    {SIG_UNREALIZED, ""},
145    {SIG_CHANGED, ""},
146    {SIG_DRAG_START_UP, ""},
147    {SIG_DRAG_START_DOWN, ""},
148    {SIG_DRAG_START_LEFT, ""},
149    {SIG_DRAG_START_RIGHT, ""},
150    {SIG_DRAG_STOP, ""},
151    {SIG_DRAG, ""},
152    {SIG_SCROLL, ""},
153    {SIG_SCROLL_ANIM_START, ""},
154    {SIG_SCROLL_ANIM_STOP, ""},
155    {SIG_SCROLL_DRAG_START, ""},
156    {SIG_SCROLL_DRAG_STOP, ""},
157    {SIG_EDGE_TOP, ""},
158    {SIG_EDGE_BOTTOM, ""},
159    {SIG_EDGE_LEFT, ""},
160    {SIG_EDGE_RIGHT, ""},
161    {SIG_MOVED, ""},
162    {NULL, NULL}
163 };
164
165 static Eina_Bool
166 _event_hook(Evas_Object        *obj,
167             Evas_Object        *src __UNUSED__,
168             Evas_Callback_Type  type,
169             void               *event_info)
170 {
171    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
172    Evas_Event_Key_Down *ev = event_info;
173    Widget_Data *wd = elm_widget_data_get(obj);
174    if (!wd) return EINA_FALSE;
175    if (!wd->items) return EINA_FALSE;
176    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
177    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
178
179    Elm_Object_Item *it = NULL;
180    Evas_Coord x = 0;
181    Evas_Coord y = 0;
182    Evas_Coord step_x = 0;
183    Evas_Coord step_y = 0;
184    Evas_Coord v_w = 0;
185    Evas_Coord v_h = 0;
186    Evas_Coord page_x = 0;
187    Evas_Coord page_y = 0;
188
189    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
190    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
191    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
192    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
193
194    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
195      {
196         if ((wd->horizontal) &&
197             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
198               (_item_multi_select_up(wd)))
199              || (_item_single_select_up(wd))))
200           {
201              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
202              return EINA_TRUE;
203           }
204         else if ((!wd->horizontal) &&
205                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
206                    (_item_multi_select_left(wd)))
207                   || (_item_single_select_left(wd))))
208           {
209              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
210              return EINA_TRUE;
211           }
212         else
213           x -= step_x;
214      }
215    else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
216      {
217         if ((wd->horizontal) &&
218             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
219               (_item_multi_select_down(wd)))
220              || (_item_single_select_down(wd))))
221           {
222              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
223              return EINA_TRUE;
224           }
225         else if ((!wd->horizontal) &&
226                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
227                    (_item_multi_select_right(wd)))
228                   || (_item_single_select_right(wd))))
229           {
230              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
231              return EINA_TRUE;
232           }
233         else
234           x += step_x;
235      }
236    else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
237      {
238         if ((wd->horizontal) &&
239             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
240               (_item_multi_select_left(wd)))
241              || (_item_single_select_left(wd))))
242           {
243              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
244              return EINA_TRUE;
245           }
246         else if ((!wd->horizontal) &&
247                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
248                    (_item_multi_select_up(wd)))
249                   || (_item_single_select_up(wd))))
250           {
251              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
252              return EINA_TRUE;
253           }
254         else
255           y -= step_y;
256      }
257    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
258      {
259         if ((wd->horizontal) &&
260             (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
261               (_item_multi_select_right(wd)))
262              || (_item_single_select_right(wd))))
263           {
264              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
265              return EINA_TRUE;
266           }
267         else if ((!wd->horizontal) &&
268                  (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
269                    (_item_multi_select_down(wd)))
270                   || (_item_single_select_down(wd))))
271           {
272              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
273              return EINA_TRUE;
274           }
275         else
276           y += step_y;
277      }
278    else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
279      {
280         it = elm_gengrid_first_item_get(obj);
281         elm_gengrid_item_bring_in(it);
282         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
283         return EINA_TRUE;
284      }
285    else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
286      {
287         it = elm_gengrid_last_item_get(obj);
288         elm_gengrid_item_bring_in(it);
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);
371      }
372    else
373      {
374         elm_gengrid_item_selected_set(prev, EINA_TRUE);
375         elm_gengrid_item_show(prev);
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);
394      }
395    else
396      {
397         elm_gengrid_item_selected_set(next, EINA_TRUE);
398         elm_gengrid_item_show(next);
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);
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);
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);
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);
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);
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);
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_gengrid_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->no_select) || (it->generation < it->wd->generation) || (it->highlighted)) return;
921    edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
922    it->highlighted = EINA_TRUE;
923 }
924
925 static void
926 _item_realize(Elm_Gen_Item *it)
927 {
928    char buf[1024];
929    char style[1024];
930
931    if ((it->realized) || (it->generation < it->wd->generation)) return;
932    VIEW(it) = edje_object_add(evas_object_evas_get(WIDGET(it)));
933    edje_object_scale_set(VIEW(it), elm_widget_scale_get(WIDGET(it)) *
934                          _elm_config->scale);
935    edje_object_mirrored_set(VIEW(it), elm_widget_mirrored_get(WIDGET(it)));
936    evas_object_smart_member_add(VIEW(it), it->wd->pan_smart);
937    elm_widget_sub_object_add(WIDGET(it), VIEW(it));
938    snprintf(style, sizeof(style), "item/%s",
939             it->itc->item_style ? it->itc->item_style : "default");
940    _elm_theme_object_set(WIDGET(it), VIEW(it), "gengrid", style,
941                          elm_widget_style_get(WIDGET(it)));
942    it->spacer =
943       evas_object_rectangle_add(evas_object_evas_get(WIDGET(it)));
944    evas_object_color_set(it->spacer, 0, 0, 0, 0);
945    elm_widget_sub_object_add(WIDGET(it), it->spacer);
946    evas_object_size_hint_min_set(it->spacer, 2 * _elm_config->scale, 1);
947    edje_object_part_swallow(VIEW(it), "elm.swallow.pad", it->spacer);
948
949    if (it->itc->func.text_get)
950      {
951         const Eina_List *l;
952         const char *key;
953
954         it->texts =
955            elm_widget_stringlist_get(edje_object_data_get(VIEW(it),
956                                                           "texts"));
957         EINA_LIST_FOREACH(it->texts, l, key)
958           {
959              char *s = it->itc->func.text_get
960                 ((void *)it->base.data, WIDGET(it), key);
961              if (s)
962                {
963                   edje_object_part_text_set(VIEW(it), key, s);
964                   free(s);
965                }
966           }
967      }
968
969    if (it->itc->func.content_get)
970      {
971         const Eina_List *l;
972         const char *key;
973         Evas_Object *ic = NULL;
974
975         it->contents =
976            elm_widget_stringlist_get(edje_object_data_get(VIEW(it),
977                                                           "contents"));
978         EINA_LIST_FOREACH(it->contents, l, key)
979           {
980              if (it->itc->func.content_get)
981                ic = it->itc->func.content_get
982                   ((void *)it->base.data, WIDGET(it), key);
983              if (ic)
984                {
985                   it->content_objs = eina_list_append(it->content_objs, ic);
986                   edje_object_part_swallow(VIEW(it), key, ic);
987                   evas_object_show(ic);
988                   elm_widget_sub_object_add(WIDGET(it), ic);
989                }
990           }
991      }
992
993    if (it->itc->func.state_get)
994      {
995         const Eina_List *l;
996         const char *key;
997
998         it->states =
999            elm_widget_stringlist_get(edje_object_data_get(VIEW(it),
1000                                                           "states"));
1001         EINA_LIST_FOREACH(it->states, l, key)
1002           {
1003              Eina_Bool on = it->itc->func.state_get
1004                 ((void *)it->base.data, WIDGET(it), l->data);
1005              if (on)
1006                {
1007                   snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1008                   edje_object_signal_emit(VIEW(it), buf, "elm");
1009                }
1010           }
1011      }
1012
1013    if (it->group)
1014      {
1015         if ((!it->wd->group_item_width) && (!it->wd->group_item_height))
1016           {
1017              edje_object_size_min_restricted_calc(VIEW(it),
1018                                                   &it->wd->group_item_width,
1019                                                   &it->wd->group_item_height,
1020                                                   it->wd->group_item_width,
1021                                                   it->wd->group_item_height);
1022           }
1023      }
1024    else
1025      {
1026         if ((!it->wd->item_width) && (!it->wd->item_height))
1027           {
1028              edje_object_size_min_restricted_calc(VIEW(it),
1029                                                   &it->wd->item_width,
1030                                                   &it->wd->item_height,
1031                                                   it->wd->item_width,
1032                                                   it->wd->item_height);
1033              elm_coords_finger_size_adjust(1, &it->wd->item_width,
1034                                            1, &it->wd->item_height);
1035           }
1036
1037         evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
1038                                        _mouse_down, it);
1039         evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
1040                                        _mouse_up, it);
1041         evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1042                                        _mouse_move, it);
1043
1044         if (it->selected)
1045           edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
1046         if (elm_widget_item_disabled_get(it))
1047           edje_object_signal_emit(VIEW(it), "elm,state,disabled", "elm");
1048      }
1049    evas_object_show(VIEW(it));
1050
1051    if (it->tooltip.content_cb)
1052      {
1053         elm_widget_item_tooltip_content_cb_set(it,
1054                                                it->tooltip.content_cb,
1055                                                it->tooltip.data, NULL);
1056         elm_widget_item_tooltip_style_set(it, it->tooltip.style);
1057         elm_widget_item_tooltip_window_mode_set(it, it->tooltip.free_size);
1058      }
1059
1060    if (it->mouse_cursor)
1061      elm_widget_item_cursor_set(it, it->mouse_cursor);
1062
1063    it->realized = EINA_TRUE;
1064    it->want_unrealize = EINA_FALSE;
1065 }
1066
1067 static void
1068 _item_unrealize_cb(Elm_Gen_Item *it)
1069 {
1070    evas_object_del(VIEW(it));
1071    VIEW(it) = NULL;
1072    evas_object_del(it->spacer);
1073    it->spacer = NULL;
1074 }
1075
1076 static Eina_Bool
1077 _reorder_item_moving_effect_timer_cb(void *data)
1078 {
1079    Elm_Gen_Item *it = data;
1080    double time, t;
1081    Evas_Coord dx, dy;
1082
1083    time = REORDER_EFFECT_TIME;
1084    t = ((0.0 > (t = ecore_loop_time_get()-it->item->moving_effect_start_time)) ? 0.0 : t);
1085    dx = ((it->item->tx - it->item->ox) / 10) * _elm_config->scale;
1086    dy = ((it->item->ty - it->item->oy) / 10) * _elm_config->scale;
1087
1088    if (t <= time)
1089      {
1090         it->item->rx += (1 * sin((t / time) * (M_PI / 2)) * dx);
1091         it->item->ry += (1 * sin((t / time) * (M_PI / 2)) * dy);
1092      }
1093    else
1094      {
1095         it->item->rx += dx;
1096         it->item->ry += dy;
1097      }
1098
1099    if ((((dx > 0) && (it->item->rx >= it->item->tx)) || ((dx <= 0) && (it->item->rx <= it->item->tx))) &&
1100        (((dy > 0) && (it->item->ry >= it->item->ty)) || ((dy <= 0) && (it->item->ry <= it->item->ty))))
1101      {
1102         evas_object_move(VIEW(it), it->item->tx, it->item->ty);
1103         if (it->group)
1104           {
1105              Evas_Coord vw, vh;
1106              evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &vw, &vh);
1107              if (it->wd->horizontal)
1108                evas_object_resize(VIEW(it), it->wd->group_item_width, vh);
1109              else
1110                evas_object_resize(VIEW(it), vw, it->wd->group_item_height);
1111           }
1112         else
1113           evas_object_resize(VIEW(it), it->wd->item_width, it->wd->item_height);
1114         it->item->moving = EINA_FALSE;
1115         it->item->item_moving_effect_timer = NULL;
1116         return ECORE_CALLBACK_CANCEL;
1117      }
1118
1119    evas_object_move(VIEW(it), it->item->rx, it->item->ry);
1120    if (it->group)
1121      {
1122         Evas_Coord vw, vh;
1123         evas_object_geometry_get(it->wd->pan_smart, NULL, NULL, &vw, &vh);
1124         if (it->wd->horizontal)
1125           evas_object_resize(VIEW(it), it->wd->group_item_width, vh);
1126         else
1127           evas_object_resize(VIEW(it), vw, it->wd->group_item_height);
1128      }
1129    else
1130      evas_object_resize(VIEW(it), it->wd->item_width, it->wd->item_height);
1131
1132    return ECORE_CALLBACK_RENEW;
1133 }
1134
1135 static void
1136 _group_item_place(Pan *sd)
1137 {
1138    Evas_Coord iw, ih, vw, vh;
1139    Eina_List *l;
1140    Eina_Bool was_realized;
1141    Elm_Gen_Item *it;
1142    evas_object_geometry_get(sd->wd->pan_smart, NULL, NULL, &vw, &vh);
1143    if (sd->wd->horizontal)
1144      {
1145         iw = sd->wd->group_item_width;
1146         ih = vh;
1147      }
1148    else
1149      {
1150         iw = vw;
1151         ih = sd->wd->group_item_height;
1152      }
1153    EINA_LIST_FOREACH(sd->wd->group_items, l, it)
1154      {
1155         was_realized = it->realized;
1156         if (it->item->group_realized)
1157           {
1158              _item_realize(it);
1159              if (!was_realized)
1160                evas_object_smart_callback_call(WIDGET(it), SIG_REALIZED, it);
1161              evas_object_move(VIEW(it), it->item->gx, it->item->gy);
1162              evas_object_resize(VIEW(it), iw, ih);
1163              evas_object_raise(VIEW(it));
1164           }
1165         else
1166           _elm_gengrid_item_unrealize(it, EINA_FALSE);
1167      }
1168 }
1169
1170
1171 static void
1172 _item_place(Elm_Gen_Item *it,
1173             Evas_Coord        cx,
1174             Evas_Coord        cy)
1175 {
1176    Evas_Coord x, y, ox, oy, cvx, cvy, cvw, cvh, iw, ih, ww;
1177    Evas_Coord tch, tcw, alignw = 0, alignh = 0, vw, vh;
1178    Eina_Bool reorder_item_move_forward = EINA_FALSE;
1179    long items_count;
1180    it->x = cx;
1181    it->y = cy;
1182    evas_object_geometry_get(it->wd->pan_smart, &ox, &oy, &vw, &vh);
1183
1184    /* Preload rows/columns at each side of the Gengrid */
1185    cvx = ox - PRELOAD * it->wd->item_width;
1186    cvy = oy - PRELOAD * it->wd->item_height;
1187    cvw = vw + 2 * PRELOAD * it->wd->item_width;
1188    cvh = vh + 2 * PRELOAD * it->wd->item_height;
1189
1190    alignh = 0;
1191    alignw = 0;
1192
1193    items_count = it->wd->count - eina_list_count(it->wd->group_items) + it->wd->items_lost;
1194    if (it->wd->horizontal)
1195      {
1196         int columns, items_visible = 0, items_row;
1197
1198         if (it->wd->item_height > 0)
1199           items_visible = vh / it->wd->item_height;
1200         if (items_visible < 1)
1201           items_visible = 1;
1202
1203         columns = items_count / items_visible;
1204         if (items_count % items_visible)
1205           columns++;
1206
1207         tcw = (it->wd->item_width * columns) + (it->wd->group_item_width * eina_list_count(it->wd->group_items));
1208         alignw = (vw - tcw) * it->wd->align_x;
1209
1210         items_row = items_visible;
1211         if (items_row > it->wd->count)
1212           items_row = it->wd->count;
1213          if (it->wd->filled
1214              && (unsigned int)it->wd->nmax > (unsigned int)it->wd->count)
1215            tch = it->wd->nmax * it->wd->item_height;
1216          else
1217            tch = items_row * it->wd->item_height;
1218         alignh = (vh - tch) * it->wd->align_y;
1219      }
1220    else
1221      {
1222         int rows, items_visible = 0, items_col;
1223
1224         if (it->wd->item_width > 0)
1225           items_visible = vw / it->wd->item_width;
1226         if (items_visible < 1)
1227           items_visible = 1;
1228
1229         rows = items_count / items_visible;
1230         if (items_count % items_visible)
1231           rows++;
1232
1233         tch = (it->wd->item_height * rows) + (it->wd->group_item_height * eina_list_count(it->wd->group_items));
1234         alignh = (vh - tch) * it->wd->align_y;
1235
1236         items_col = items_visible;
1237         if (items_col > it->wd->count)
1238           items_col = it->wd->count;
1239          if (it->wd->filled
1240              && (unsigned int)it->wd->nmax > (unsigned int)it->wd->count)
1241            tcw = it->wd->nmax * it->wd->item_width;
1242          else
1243            tcw = items_col * it->wd->item_width;
1244         alignw = (vw - tcw) * it->wd->align_x;
1245      }
1246
1247    if (it->group)
1248      {
1249         if (it->wd->horizontal)
1250           {
1251              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;
1252              y = oy;
1253              iw = it->wd->group_item_width;
1254              ih = vh;
1255           }
1256         else
1257           {
1258              x = ox;
1259              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;
1260              iw = vw;
1261              ih = it->wd->group_item_height;
1262           }
1263         it->item->gx = x;
1264         it->item->gy = y;
1265      }
1266    else
1267      {
1268         if (it->wd->horizontal)
1269           {
1270              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;
1271              y = (cy * it->wd->item_height) - it->wd->pan_y + oy + alignh;
1272           }
1273         else
1274           {
1275              x = (cx * it->wd->item_width) - it->wd->pan_x + ox + alignw;
1276              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;
1277           }
1278         if (elm_widget_mirrored_get(WIDGET(it)))
1279           {  /* Switch items side and componsate for pan_x when in RTL mode */
1280              evas_object_geometry_get(WIDGET(it), NULL, NULL, &ww, NULL);
1281              x = ww - x - it->wd->item_width - it->wd->pan_x - it->wd->pan_x;
1282           }
1283         iw = it->wd->item_width;
1284         ih = it->wd->item_height;
1285      }
1286
1287    Eina_Bool was_realized = it->realized;
1288    if (ELM_RECTS_INTERSECT(x, y, iw, ih, cvx, cvy, cvw, cvh))
1289      {
1290         _item_realize(it);
1291         if (!was_realized)
1292           evas_object_smart_callback_call(WIDGET(it), SIG_REALIZED, it);
1293         if (it->parent)
1294           {
1295              if (it->wd->horizontal)
1296                {
1297                   if (it->parent->item->gx < ox)
1298                     {
1299                        it->parent->item->gx = x + it->wd->item_width - it->wd->group_item_width;
1300                        if (it->parent->item->gx > ox)
1301                          it->parent->item->gx = ox;
1302                     }
1303                   it->parent->item->group_realized = EINA_TRUE;
1304                }
1305              else
1306                {
1307                   if (it->parent->item->gy < oy)
1308                     {
1309                        it->parent->item->gy = y + it->wd->item_height - it->wd->group_item_height;
1310                        if (it->parent->item->gy > oy)
1311                          it->parent->item->gy = oy;
1312                     }
1313                   it->parent->item->group_realized = EINA_TRUE;
1314                }
1315           }
1316         if (it->wd->reorder_mode)
1317           {
1318              if (it->wd->reorder_it)
1319                {
1320                   if (it->item->moving) return;
1321
1322                   if (!it->wd->move_effect_enabled)
1323                     {
1324                        it->item->ox = x;
1325                        it->item->oy = y;
1326                     }
1327                   if (it->wd->reorder_it == it)
1328                     {
1329                        evas_object_move(VIEW(it),
1330                                         it->wd->reorder_item_x, it->wd->reorder_item_y);
1331                        evas_object_resize(VIEW(it), iw, ih);
1332                        return;
1333                     }
1334                   else
1335                     {
1336                        if (it->wd->move_effect_enabled)
1337                          {
1338                             if ((it->item->ox != x) || (it->item->oy != y))
1339                               {
1340                                  if (((it->wd->old_pan_x == it->wd->pan_x) && (it->wd->old_pan_y == it->wd->pan_y)) ||
1341                                      ((it->wd->old_pan_x != it->wd->pan_x) && !(it->item->ox - it->wd->pan_x + it->wd->old_pan_x == x)) ||
1342                                      ((it->wd->old_pan_y != it->wd->pan_y) && !(it->item->oy - it->wd->pan_y + it->wd->old_pan_y == y)))
1343                                    {
1344                                       it->item->tx = x;
1345                                       it->item->ty = y;
1346                                       it->item->rx = it->item->ox;
1347                                       it->item->ry = it->item->oy;
1348                                       it->item->moving = EINA_TRUE;
1349                                       it->item->moving_effect_start_time = ecore_loop_time_get();
1350                                       it->item->item_moving_effect_timer = ecore_animator_add(_reorder_item_moving_effect_timer_cb, it);
1351                                       return;
1352                                    }
1353                               }
1354                          }
1355
1356                        /* need fix here */
1357                        Evas_Coord nx, ny, nw, nh;
1358                        if (it->group)
1359                          {
1360                             if (it->wd->horizontal)
1361                               {
1362                                  nx = x + (it->wd->group_item_width / 2);
1363                                  ny = y;
1364                                  nw = 1;
1365                                  nh = vh;
1366                               }
1367                             else
1368                               {
1369                                  nx = x;
1370                                  ny = y + (it->wd->group_item_height / 2);
1371                                  nw = vw;
1372                                  nh = 1;
1373                               }
1374                          }
1375                        else
1376                          {
1377                             nx = x + (it->wd->item_width / 2);
1378                             ny = y + (it->wd->item_height / 2);
1379                             nw = 1;
1380                             nh = 1;
1381                          }
1382
1383                        if ( ELM_RECTS_INTERSECT(it->wd->reorder_item_x, it->wd->reorder_item_y,
1384                                                 it->wd->item_width, it->wd->item_height,
1385                                                 nx, ny, nw, nh))
1386                          {
1387                             if (it->wd->horizontal)
1388                               {
1389                                  if ((it->wd->nmax * it->wd->reorder_it->x + it->wd->reorder_it->y) >
1390                                      (it->wd->nmax * it->x + it->y))
1391                                    reorder_item_move_forward = EINA_TRUE;
1392                               }
1393                             else
1394                               {
1395                                  if ((it->wd->nmax * it->wd->reorder_it->y + it->wd->reorder_it->x) >
1396                                      (it->wd->nmax * it->y + it->x))
1397                                    reorder_item_move_forward = EINA_TRUE;
1398                               }
1399
1400                             it->wd->items = eina_inlist_remove(it->wd->items,
1401                                                                  EINA_INLIST_GET(it->wd->reorder_it));
1402                             if (reorder_item_move_forward)
1403                               it->wd->items = eina_inlist_prepend_relative(it->wd->items,
1404                                                                              EINA_INLIST_GET(it->wd->reorder_it),
1405                                                                              EINA_INLIST_GET(it));
1406                             else
1407                               it->wd->items = eina_inlist_append_relative(it->wd->items,
1408                                                                             EINA_INLIST_GET(it->wd->reorder_it),
1409                                                                             EINA_INLIST_GET(it));
1410
1411                             it->wd->reorder_item_changed = EINA_TRUE;
1412                             it->wd->move_effect_enabled = EINA_TRUE;
1413                             if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
1414                               it->wd->calc_job = ecore_job_add(_calc_job, it->wd);
1415
1416                             return;
1417                          }
1418                     }
1419                }
1420              else if (it->item->item_moving_effect_timer)
1421                {
1422                   ecore_animator_del(it->item->item_moving_effect_timer);
1423                   it->item->item_moving_effect_timer = NULL;
1424                   it->item->moving = EINA_FALSE;
1425                }
1426           }
1427         if (!it->group)
1428           {
1429              evas_object_move(VIEW(it), x, y);
1430              evas_object_resize(VIEW(it), iw, ih);
1431           }
1432         else
1433           it->item->group_realized = EINA_TRUE;
1434      }
1435    else
1436      {
1437         if (!it->group)
1438           _elm_gengrid_item_unrealize(it, EINA_FALSE);
1439         else
1440           it->item->group_realized = EINA_FALSE;
1441      }
1442 }
1443
1444 static void
1445 _item_del(Elm_Gen_Item *it)
1446 {
1447    Evas_Object *obj = WIDGET(it);
1448
1449    evas_event_freeze(evas_object_evas_get(obj));
1450    it->wd->selected = eina_list_remove(it->wd->selected, it);
1451    if (it->realized) _elm_gengrid_item_unrealize(it, EINA_FALSE);
1452    it->wd->count--;
1453    _elm_gengrid_item_del_serious(it);
1454    evas_event_thaw(evas_object_evas_get(obj));
1455    evas_event_thaw_eval(evas_object_evas_get(obj));
1456 }
1457
1458 static void
1459 _item_unselect(Elm_Gen_Item *it)
1460 {
1461    if ((it->generation < it->wd->generation) || (!it->highlighted)) return;
1462    edje_object_signal_emit(VIEW(it), "elm,state,unselected", "elm");
1463    it->highlighted = EINA_FALSE;
1464    if (it->selected)
1465      {
1466         it->selected = EINA_FALSE;
1467         it->wd->selected = eina_list_remove(it->wd->selected, it);
1468         evas_object_smart_callback_call(WIDGET(it), SIG_UNSELECTED, it);
1469      }
1470 }
1471
1472 static void
1473 _calc_job(void *data)
1474 {
1475    Widget_Data *wd = data;
1476    Evas_Coord minw = 0, minh = 0, nmax = 0, cvw, cvh;
1477    Elm_Gen_Item *it, *group_item = NULL;
1478    int count_group = 0;
1479    long count = 0;
1480    wd->items_lost = 0;
1481
1482    evas_object_geometry_get(wd->pan_smart, NULL, NULL, &cvw, &cvh);
1483    if ((cvw != 0) || (cvh != 0))
1484      {
1485         if ((wd->horizontal) && (wd->item_height > 0))
1486           nmax = cvh / wd->item_height;
1487         else if (wd->item_width > 0)
1488           nmax = cvw / wd->item_width;
1489
1490         if (nmax < 1)
1491           nmax = 1;
1492
1493         EINA_INLIST_FOREACH(wd->items, it)
1494           {
1495              if (it->item->prev_group != count_group)
1496                it->item->prev_group = count_group;
1497              if (it->group)
1498                {
1499                   count = count % nmax;
1500                   if (count)
1501                     wd->items_lost += nmax - count;
1502                   //printf("%d items and I lost %d\n", count, wd->items_lost);
1503                   count_group++;
1504                   if (count) count = 0;
1505                   group_item = it;
1506                }
1507              else
1508                {
1509                   if (it->parent != group_item)
1510                     it->parent = group_item;
1511                   count++;
1512                }
1513           }
1514         count = wd->count + wd->items_lost - count_group;
1515         if (wd->horizontal)
1516           {
1517              minw = (ceil(count / (float)nmax) * wd->item_width) + (count_group * wd->group_item_width);
1518              minh = nmax * wd->item_height;
1519           }
1520         else
1521           {
1522              minw = nmax * wd->item_width;
1523              minh = (ceil(count / (float)nmax) * wd->item_height) + (count_group * wd->group_item_height);
1524           }
1525
1526         if ((minw != wd->minw) || (minh != wd->minh))
1527           {
1528              wd->minh = minh;
1529              wd->minw = minw;
1530              evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1531           }
1532
1533         wd->nmax = nmax;
1534         evas_object_smart_changed(wd->pan_smart);
1535      }
1536    wd->calc_job = NULL;
1537 }
1538
1539 static void
1540 _pan_add(Evas_Object *obj)
1541 {
1542    Pan *sd;
1543    Evas_Object_Smart_Clipped_Data *cd;
1544
1545    _pan_sc.add(obj);
1546    cd = evas_object_smart_data_get(obj);
1547    sd = ELM_NEW(Pan);
1548    if (!sd) return;
1549    sd->__clipped_data = *cd;
1550    free(cd);
1551    evas_object_smart_data_set(obj, sd);
1552 }
1553
1554 static void
1555 _pan_del(Evas_Object *obj)
1556 {
1557    Pan *sd = evas_object_smart_data_get(obj);
1558
1559    if (!sd) return;
1560    _pan_sc.del(obj);
1561 }
1562
1563 static void
1564 _pan_set(Evas_Object *obj,
1565          Evas_Coord   x,
1566          Evas_Coord   y)
1567 {
1568    Pan *sd = evas_object_smart_data_get(obj);
1569    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1570    sd->wd->pan_x = x;
1571    sd->wd->pan_y = y;
1572    evas_object_smart_changed(obj);
1573 }
1574
1575 static void
1576 _pan_get(Evas_Object *obj,
1577          Evas_Coord  *x,
1578          Evas_Coord  *y)
1579 {
1580    Pan *sd = evas_object_smart_data_get(obj);
1581    if (x) *x = sd->wd->pan_x;
1582    if (y) *y = sd->wd->pan_y;
1583 }
1584
1585 static void
1586 _pan_child_size_get(Evas_Object *obj,
1587                     Evas_Coord  *w,
1588                     Evas_Coord  *h)
1589 {
1590    Pan *sd = evas_object_smart_data_get(obj);
1591    if (w) *w = sd->wd->minw;
1592    if (h) *h = sd->wd->minh;
1593 }
1594
1595 static void
1596 _pan_max_get(Evas_Object *obj,
1597              Evas_Coord  *x,
1598              Evas_Coord  *y)
1599 {
1600    Pan *sd = evas_object_smart_data_get(obj);
1601    Evas_Coord ow, oh;
1602
1603    if (!sd) return;
1604    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1605    if (x)
1606      *x = (ow < sd->wd->minw) ? sd->wd->minw - ow : 0;
1607    if (y)
1608      *y = (oh < sd->wd->minh) ? sd->wd->minh - oh : 0;
1609 }
1610
1611 static void
1612 _pan_min_get(Evas_Object *obj,
1613              Evas_Coord  *x,
1614              Evas_Coord  *y)
1615 {
1616    Pan *sd = evas_object_smart_data_get(obj);
1617    Evas_Coord mx = 0, my = 0;
1618
1619    if (!sd) return;
1620    _pan_max_get(obj, &mx, &my);
1621    if (x)
1622      *x = -mx * sd->wd->align_x;
1623    if (y)
1624      *y = -my * sd->wd->align_y;
1625 }
1626
1627 static void
1628 _pan_resize(Evas_Object *obj,
1629             Evas_Coord   w,
1630             Evas_Coord   h)
1631 {
1632    Pan *sd = evas_object_smart_data_get(obj);
1633    Evas_Coord ow, oh;
1634
1635    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1636    if ((ow == w) && (oh == h)) return;
1637    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1638    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1639 }
1640
1641 static void
1642 _pan_calculate(Evas_Object *obj)
1643 {
1644    Pan *sd = evas_object_smart_data_get(obj);
1645    Evas_Coord cx = 0, cy = 0;
1646    Elm_Gen_Item *it;
1647
1648    if (!sd) return;
1649    if (!sd->wd->nmax) return;
1650
1651    sd->wd->reorder_item_changed = EINA_FALSE;
1652
1653    EINA_INLIST_FOREACH(sd->wd->items, it)
1654      {
1655         if (it->group)
1656           {
1657              if (sd->wd->horizontal)
1658                {
1659                   if (cy)
1660                     {
1661                        cx++;
1662                        cy = 0;
1663                     }
1664                }
1665              else
1666                {
1667                   if (cx)
1668                     {
1669                        cx = 0;
1670                        cy++;
1671                     }
1672                }
1673           }
1674         _item_place(it, cx, cy);
1675         if (sd->wd->reorder_item_changed) return;
1676         if (it->group)
1677           {
1678              if (sd->wd->horizontal)
1679                {
1680                   cx++;
1681                   cy = 0;
1682                }
1683              else
1684                {
1685                   cx = 0;
1686                   cy++;
1687                }
1688           }
1689         else
1690           {
1691              if (sd->wd->horizontal)
1692                {
1693                   cy = (cy + 1) % sd->wd->nmax;
1694                   if (!cy) cx++;
1695                }
1696              else
1697                {
1698                   cx = (cx + 1) % sd->wd->nmax;
1699                   if (!cx) cy++;
1700                }
1701           }
1702      }
1703    _group_item_place(sd);
1704
1705
1706    if ((sd->wd->reorder_mode) && (sd->wd->reorder_it))
1707      {
1708         if (!sd->wd->reorder_item_changed)
1709           {
1710              sd->wd->old_pan_x = sd->wd->pan_x;
1711              sd->wd->old_pan_y = sd->wd->pan_y;
1712           }
1713         sd->wd->move_effect_enabled = EINA_FALSE;
1714      }
1715    evas_object_smart_callback_call(sd->wd->obj, SIG_CHANGED, NULL);
1716 }
1717
1718 static void
1719 _pan_move(Evas_Object *obj,
1720           Evas_Coord x __UNUSED__,
1721           Evas_Coord y __UNUSED__)
1722 {
1723    Pan *sd = evas_object_smart_data_get(obj);
1724    if (!sd) return;
1725    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1726    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1727 }
1728
1729 static void
1730 _hold_on(void *data       __UNUSED__,
1731          Evas_Object     *obj,
1732          void *event_info __UNUSED__)
1733 {
1734    Widget_Data *wd = elm_widget_data_get(obj);
1735    if (!wd) return;
1736    elm_smart_scroller_hold_set(wd->scr, 1);
1737 }
1738
1739 static void
1740 _hold_off(void *data       __UNUSED__,
1741           Evas_Object     *obj,
1742           void *event_info __UNUSED__)
1743 {
1744    Widget_Data *wd = elm_widget_data_get(obj);
1745    if (!wd) return;
1746    elm_smart_scroller_hold_set(wd->scr, 0);
1747 }
1748
1749 static void
1750 _freeze_on(void *data       __UNUSED__,
1751            Evas_Object     *obj,
1752            void *event_info __UNUSED__)
1753 {
1754    Widget_Data *wd = elm_widget_data_get(obj);
1755    if (!wd) return;
1756    elm_smart_scroller_freeze_set(wd->scr, 1);
1757 }
1758
1759 static void
1760 _freeze_off(void *data       __UNUSED__,
1761             Evas_Object     *obj,
1762             void *event_info __UNUSED__)
1763 {
1764    Widget_Data *wd = elm_widget_data_get(obj);
1765    if (!wd) return;
1766    elm_smart_scroller_freeze_set(wd->scr, 0);
1767 }
1768
1769 static void
1770 _scr_anim_start(void        *data,
1771                 Evas_Object *obj __UNUSED__,
1772                 void        *event_info __UNUSED__)
1773 {
1774    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
1775 }
1776
1777 static void
1778 _scr_anim_stop(void        *data,
1779                 Evas_Object *obj __UNUSED__,
1780                 void        *event_info __UNUSED__)
1781 {
1782    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
1783 }
1784
1785 static void
1786 _scr_drag_start(void            *data,
1787                 Evas_Object *obj __UNUSED__,
1788                 void *event_info __UNUSED__)
1789 {
1790    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1791 }
1792
1793 static void
1794 _scr_drag_stop(void            *data,
1795                Evas_Object *obj __UNUSED__,
1796                void *event_info __UNUSED__)
1797 {
1798    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1799 }
1800
1801 static void
1802 _edge_left(void        *data,
1803            Evas_Object *scr __UNUSED__,
1804            void        *event_info __UNUSED__)
1805 {
1806    evas_object_smart_callback_call(data, SIG_EDGE_LEFT, NULL);
1807 }
1808
1809 static void
1810 _edge_right(void        *data,
1811             Evas_Object *scr __UNUSED__,
1812             void        *event_info __UNUSED__)
1813 {
1814    evas_object_smart_callback_call(data, SIG_EDGE_RIGHT, NULL);
1815 }
1816
1817 static void
1818 _edge_top(void        *data,
1819           Evas_Object *scr __UNUSED__,
1820           void        *event_info __UNUSED__)
1821 {
1822    evas_object_smart_callback_call(data, SIG_EDGE_TOP, NULL);
1823 }
1824
1825 static void
1826 _edge_bottom(void        *data,
1827              Evas_Object *scr __UNUSED__,
1828              void        *event_info __UNUSED__)
1829 {
1830    evas_object_smart_callback_call(data, SIG_EDGE_BOTTOM, NULL);
1831 }
1832
1833 static void
1834 _scr_scroll(void            *data,
1835             Evas_Object *obj __UNUSED__,
1836             void *event_info __UNUSED__)
1837 {
1838    evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1839 }
1840
1841 static int
1842 _elm_gengrid_item_compare_data(const void *data, const void *data1)
1843 {
1844    const Elm_Gen_Item *it = data;
1845    const Elm_Gen_Item *item1 = data1;
1846
1847    return it->wd->item_compare_data_cb(it->base.data, item1->base.data);
1848 }
1849
1850 static int
1851 _elm_gengrid_item_compare(const void *data, const void *data1)
1852 {
1853    Elm_Gen_Item *it, *item1;
1854    it = ELM_GEN_ITEM_FROM_INLIST(data);
1855    item1 = ELM_GEN_ITEM_FROM_INLIST(data1);
1856    return it->wd->item_compare_cb(it, item1);
1857 }
1858
1859 static void
1860 _item_disable_hook(Elm_Object_Item *it)
1861 {
1862    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1863    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
1864
1865    if (_it->generation < _it->wd->generation) return;
1866
1867    if (_it->realized)
1868      {
1869         if (elm_widget_item_disabled_get(_it))
1870           edje_object_signal_emit(VIEW(_it), "elm,state,disabled", "elm");
1871         else
1872           edje_object_signal_emit(VIEW(_it), "elm,state,enabled", "elm");
1873      }
1874 }
1875
1876 static void
1877 _item_del_pre_hook(Elm_Object_Item *it)
1878 {
1879    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1880    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
1881    if ((_it->relcount > 0) || (_it->walking > 0))
1882      {
1883         _elm_gengrid_item_del_notserious(_it);
1884         return;
1885      }
1886
1887    _item_del(_it);
1888 }
1889
1890 #if 1
1891 void
1892 _item_select(Elm_Gen_Item *it)
1893 {
1894    if ((it->wd->no_select) || (it->generation < it->wd->generation) || (it->mode_set)) return;
1895    if (!it->selected)
1896      {
1897         it->selected = EINA_TRUE;
1898         it->wd->selected = eina_list_append(it->wd->selected, it);
1899      }
1900    else if (!it->wd->always_select) return;
1901
1902    evas_object_ref(WIDGET(it));
1903    it->walking++;
1904    it->wd->walking++;
1905    if (it->func.func) it->func.func((void *)it->func.data, WIDGET(it), it);
1906    if (it->generation == it->wd->generation)
1907      evas_object_smart_callback_call(WIDGET(it), SIG_SELECTED, it);
1908    it->walking--;
1909    it->wd->walking--;
1910    evas_object_unref(WIDGET(it));
1911    if ((it->wd->clear_me) && (!it->wd->walking))
1912      _elm_gengrid_clear(WIDGET(it), EINA_TRUE);
1913    else
1914      {
1915         if ((!it->walking) && (it->generation < it->wd->generation))
1916           {
1917              if (!it->relcount)
1918                {
1919                   it->del_cb(it);
1920                   elm_widget_item_free(it);
1921                }
1922           }
1923         else
1924           it->wd->last_selected_item = (Elm_Object_Item *) it;
1925      }
1926 }
1927
1928 static Evas_Object *
1929 _item_content_get_hook(Elm_Gen_Item *it, const char *part)
1930 {
1931    return edje_object_part_swallow_get(VIEW(it), part);
1932 }
1933
1934 static void
1935 _item_content_set_hook(Elm_Gen_Item *it, const char *part, Evas_Object *content)
1936 {
1937    edje_object_part_swallow(VIEW(it), part, content);
1938 }
1939
1940 static Evas_Object *
1941 _item_content_unset_hook(Elm_Gen_Item *it, const char *part)
1942 {
1943    Evas_Object *obj;
1944
1945    obj = edje_object_part_swallow_get(VIEW(it), part);
1946    if (!obj) return NULL;
1947    edje_object_part_unswallow(VIEW(it), obj);
1948    return obj;
1949 }
1950
1951 static const char *
1952 _item_text_hook(Elm_Gen_Item *it, const char *part)
1953 {
1954    if (!it->itc->func.text_get) return NULL;
1955    return edje_object_part_text_get(VIEW(it), part);
1956 }
1957
1958 Elm_Gen_Item *
1959 _elm_gengrid_item_new(Widget_Data              *wd,
1960                       const Elm_Gen_Item_Class *itc,
1961                       const void               *data,
1962                       Elm_Gen_Item             *parent,
1963                       Evas_Smart_Cb             func,
1964                       const void               *func_data)
1965 {
1966    Elm_Gen_Item *it;
1967
1968    it = elm_widget_item_new(wd->obj, Elm_Gen_Item);
1969    if (!it) return NULL;
1970    it->wd = wd;
1971    it->generation = wd->generation;
1972    it->itc = itc;
1973    it->base.data = data;
1974    it->parent = parent;
1975    it->func.func = func;
1976    it->func.data = func_data;
1977    elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
1978    elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
1979    elm_widget_item_content_unset_hook_set(it, _item_content_unset_hook);
1980    //elm_widget_item_disable_hook_set(it, _item_disable_hook);
1981    //elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
1982    /* TEMPORARY */
1983    it->sel_cb = (Ecore_Cb)_item_select;
1984
1985    elm_widget_item_text_get_hook_set(it, _item_text_hook);
1986    return it;
1987 }
1988 #endif
1989
1990 static Elm_Gen_Item *
1991 _item_new(Widget_Data                  *wd,
1992           const Elm_Gengrid_Item_Class *itc,
1993           const void                   *data,
1994           Evas_Smart_Cb                 func,
1995           const void                   *func_data)
1996 {
1997    Elm_Gen_Item *it;
1998
1999 #if 0
2000    it = _elm_genlist_item_new(wd, itc, data, NULL, func, func_data);
2001 #else
2002    it = _elm_gengrid_item_new(wd, itc, data, NULL, func, func_data);
2003 #endif
2004    if (!it) return NULL;
2005    elm_widget_item_disable_hook_set(it, _item_disable_hook);
2006    elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
2007    it->item = ELM_NEW(Elm_Gen_Item_Type);
2008    wd->count++;
2009    it->group = it->itc->item_style && (!strcmp(it->itc->item_style, "group_index"));
2010    ELM_GEN_ITEM_SETUP(it);
2011
2012    return it;
2013 }
2014
2015 EAPI Evas_Object *
2016 elm_gengrid_add(Evas_Object *parent)
2017 {
2018    Evas_Object *obj;
2019    Evas *e;
2020    Widget_Data *wd;
2021    static Evas_Smart *smart = NULL;
2022    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
2023
2024    if (!smart)
2025      {
2026         static Evas_Smart_Class sc;
2027
2028         evas_object_smart_clipped_smart_set(&_pan_sc);
2029         sc = _pan_sc;
2030         sc.name = "elm_gengrid_pan";
2031         sc.version = EVAS_SMART_CLASS_VERSION;
2032         sc.add = _pan_add;
2033         sc.del = _pan_del;
2034         sc.resize = _pan_resize;
2035         sc.move = _pan_move;
2036         sc.calculate = _pan_calculate;
2037         if (!(smart = evas_smart_class_new(&sc))) return NULL;
2038      }
2039
2040    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2041
2042    ELM_SET_WIDTYPE(widtype, "gengrid");
2043    ELM_GEN_SETUP(wd);
2044    elm_widget_type_set(obj, "gengrid");
2045    elm_widget_sub_object_add(parent, obj);
2046    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2047    elm_widget_data_set(obj, wd);
2048    elm_widget_del_hook_set(obj, _del_hook);
2049    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2050    elm_widget_theme_hook_set(obj, _theme_hook);
2051    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2052    elm_widget_can_focus_set(obj, EINA_TRUE);
2053    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2054    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2055    elm_widget_event_hook_set(obj, _event_hook);
2056
2057    wd->generation = 1;
2058    wd->scr = elm_smart_scroller_add(e);
2059    elm_smart_scroller_widget_set(wd->scr, obj);
2060    elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
2061                                        "default");
2062    elm_smart_scroller_bounce_allow_set(wd->scr, bounce,
2063                                        _elm_config->thumbscroll_bounce_enable);
2064    elm_widget_resize_object_set(obj, wd->scr);
2065
2066    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
2067    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
2068    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
2069    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
2070    evas_object_smart_callback_add(wd->scr, "edge,left", _edge_left, obj);
2071    evas_object_smart_callback_add(wd->scr, "edge,right", _edge_right, obj);
2072    evas_object_smart_callback_add(wd->scr, "edge,top", _edge_top, obj);
2073    evas_object_smart_callback_add(wd->scr, "edge,bottom", _edge_bottom,
2074                                   obj);
2075    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
2076
2077    wd->obj = obj;
2078    wd->align_x = 0.5;
2079    wd->align_y = 0.5;
2080    wd->h_bounce = bounce;
2081    wd->v_bounce = bounce;
2082
2083    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
2084    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
2085    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
2086    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
2087
2088    wd->pan_smart = evas_object_smart_add(e, smart);
2089    wd->pan = evas_object_smart_data_get(wd->pan_smart);
2090    wd->pan->wd = wd;
2091
2092    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
2093                                      _pan_set, _pan_get, _pan_max_get,
2094                                      _pan_min_get, _pan_child_size_get);
2095
2096    evas_object_smart_callbacks_descriptions_set(obj, _signals);
2097
2098    _mirrored_set(obj, elm_widget_mirrored_get(obj));
2099    return obj;
2100 }
2101
2102 EAPI void
2103 elm_gengrid_item_size_set(Evas_Object *obj,
2104                           Evas_Coord   w,
2105                           Evas_Coord   h)
2106 {
2107    ELM_CHECK_WIDTYPE(obj, widtype);
2108    Widget_Data *wd = elm_widget_data_get(obj);
2109    if (!wd) return;
2110    if ((wd->item_width == w) && (wd->item_height == h)) return;
2111    wd->item_width = w;
2112    wd->item_height = h;
2113    if (wd->calc_job) ecore_job_del(wd->calc_job);
2114    wd->calc_job = ecore_job_add(_calc_job, wd);
2115 }
2116
2117 EAPI void
2118 elm_gengrid_item_size_get(const Evas_Object *obj,
2119                           Evas_Coord        *w,
2120                           Evas_Coord        *h)
2121 {
2122    ELM_CHECK_WIDTYPE(obj, widtype);
2123    Widget_Data *wd = elm_widget_data_get(obj);
2124    if (!wd) return;
2125    if (w) *w = wd->item_width;
2126    if (h) *h = wd->item_height;
2127 }
2128
2129 EAPI void
2130 elm_gengrid_group_item_size_set(Evas_Object *obj,
2131                           Evas_Coord   w,
2132                           Evas_Coord   h)
2133 {
2134    ELM_CHECK_WIDTYPE(obj, widtype);
2135    Widget_Data *wd = elm_widget_data_get(obj);
2136    if (!wd) return;
2137    if ((wd->group_item_width == w) && (wd->group_item_height == h)) return;
2138    wd->group_item_width = w;
2139    wd->group_item_height = h;
2140    if (wd->calc_job) ecore_job_del(wd->calc_job);
2141    wd->calc_job = ecore_job_add(_calc_job, wd);
2142 }
2143
2144 EAPI void
2145 elm_gengrid_group_item_size_get(const Evas_Object *obj,
2146                           Evas_Coord        *w,
2147                           Evas_Coord        *h)
2148 {
2149    ELM_CHECK_WIDTYPE(obj, widtype);
2150    Widget_Data *wd = elm_widget_data_get(obj);
2151    if (!wd) return;
2152    if (w) *w = wd->group_item_width;
2153    if (h) *h = wd->group_item_height;
2154 }
2155
2156 EAPI void
2157 elm_gengrid_align_set(Evas_Object *obj,
2158                       double       align_x,
2159                       double       align_y)
2160 {
2161    ELM_CHECK_WIDTYPE(obj, widtype);
2162
2163    Widget_Data *wd = elm_widget_data_get(obj);
2164    double old_h = wd->align_x, old_y = wd->align_y;
2165
2166    if (align_x > 1.0)
2167      align_x = 1.0;
2168    else if (align_x < 0.0)
2169      align_x = 0.0;
2170    wd->align_x = align_x;
2171
2172    if (align_y > 1.0)
2173      align_y = 1.0;
2174    else if (align_y < 0.0)
2175      align_y = 0.0;
2176    wd->align_y = align_y;
2177
2178    if ((old_h != wd->align_x) || (old_y != wd->align_y))
2179      evas_object_smart_calculate(wd->pan_smart);
2180 }
2181
2182 EAPI void
2183 elm_gengrid_align_get(const Evas_Object *obj,
2184                       double            *align_x,
2185                       double            *align_y)
2186 {
2187    ELM_CHECK_WIDTYPE(obj, widtype);
2188    Widget_Data *wd = elm_widget_data_get(obj);
2189    if (align_x) *align_x = wd->align_x;
2190    if (align_y) *align_y = wd->align_y;
2191 }
2192
2193 EAPI Elm_Object_Item *
2194 elm_gengrid_item_append(Evas_Object                  *obj,
2195                         const Elm_Gengrid_Item_Class *itc,
2196                         const void                   *data,
2197                         Evas_Smart_Cb                 func,
2198                         const void                   *func_data)
2199 {
2200    Elm_Gen_Item *it;
2201    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2202    Widget_Data *wd = elm_widget_data_get(obj);
2203    if (!wd) return NULL;
2204
2205    it = _item_new(wd, itc, data, func, func_data);
2206    if (!it) return NULL;
2207    wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
2208
2209    if (it->group)
2210      wd->group_items = eina_list_prepend(wd->group_items, it);
2211
2212    if (wd->calc_job) ecore_job_del(wd->calc_job);
2213    wd->calc_job = ecore_job_add(_calc_job, wd);
2214
2215    return (Elm_Object_Item *) it;
2216 }
2217
2218 EAPI Elm_Object_Item *
2219 elm_gengrid_item_prepend(Evas_Object                  *obj,
2220                          const Elm_Gengrid_Item_Class *itc,
2221                          const void                   *data,
2222                          Evas_Smart_Cb                 func,
2223                          const void                   *func_data)
2224 {
2225    Elm_Gen_Item *it;
2226    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2227    Widget_Data *wd = elm_widget_data_get(obj);
2228    if (!wd) return NULL;
2229
2230    it = _item_new(wd, itc, data, func, func_data);
2231    if (!it) return NULL;
2232    wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
2233    if (it->group)
2234      wd->group_items = eina_list_append(wd->group_items, it);
2235
2236    if (wd->calc_job) ecore_job_del(wd->calc_job);
2237    wd->calc_job = ecore_job_add(_calc_job, wd);
2238
2239    return (Elm_Object_Item *) it;
2240 }
2241
2242 EAPI Elm_Object_Item *
2243 elm_gengrid_item_insert_before(Evas_Object                  *obj,
2244                                const Elm_Gengrid_Item_Class *itc,
2245                                const void                   *data,
2246                                Elm_Object_Item              *relative,
2247                                Evas_Smart_Cb                 func,
2248                                const void                   *func_data)
2249 {
2250    Elm_Gen_Item *it;
2251    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2252    ELM_OBJ_ITEM_CHECK_OR_RETURN(relative, NULL);
2253    Widget_Data *wd = elm_widget_data_get(obj);
2254    if (!wd) return NULL;
2255
2256    it = _item_new(wd, itc, data, func, func_data);
2257    if (!it) return NULL;
2258    wd->items = eina_inlist_prepend_relative
2259       (wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET((Elm_Gen_Item *) relative));
2260    if (it->group)
2261      wd->group_items = eina_list_append_relative(wd->group_items, it, ((Elm_Gen_Item *) relative)->parent);
2262
2263    if (wd->calc_job) ecore_job_del(wd->calc_job);
2264    wd->calc_job = ecore_job_add(_calc_job, wd);
2265
2266    return (Elm_Object_Item *) it;
2267 }
2268
2269 EAPI Elm_Object_Item *
2270 elm_gengrid_item_insert_after(Evas_Object                  *obj,
2271                               const Elm_Gengrid_Item_Class *itc,
2272                               const void                   *data,
2273                               Elm_Object_Item              *relative,
2274                               Evas_Smart_Cb                 func,
2275                               const void                   *func_data)
2276 {
2277    Elm_Gen_Item *it;
2278    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2279    ELM_OBJ_ITEM_CHECK_OR_RETURN(relative, NULL);
2280    Widget_Data *wd = elm_widget_data_get(obj);
2281    if (!wd) return NULL;
2282
2283    it = _item_new(wd, itc, data, func, func_data);
2284    if (!it) return NULL;
2285    wd->items = eina_inlist_append_relative
2286       (wd->items, EINA_INLIST_GET(it), EINA_INLIST_GET((Elm_Gen_Item *) relative));
2287    if (it->group)
2288      wd->group_items = eina_list_prepend_relative(wd->group_items, it, ((Elm_Gen_Item *) relative)->parent);
2289
2290    if (wd->calc_job) ecore_job_del(wd->calc_job);
2291    wd->calc_job = ecore_job_add(_calc_job, wd);
2292
2293    return (Elm_Object_Item *) it;
2294 }
2295
2296 EAPI Elm_Object_Item *
2297 elm_gengrid_item_direct_sorted_insert(Evas_Object                  *obj,
2298                                       const Elm_Gengrid_Item_Class *itc,
2299                                       const void                   *data,
2300                                       Eina_Compare_Cb               comp,
2301                                       Evas_Smart_Cb                 func,
2302                                       const void                   *func_data)
2303 {
2304    Elm_Gen_Item *it;
2305    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2306    Widget_Data *wd = elm_widget_data_get(obj);
2307    if (!wd) return NULL;
2308
2309    it = _item_new(wd, itc, data, func, func_data);
2310    if (!it) return NULL;
2311
2312    if (!wd->state)
2313      wd->state = eina_inlist_sorted_state_new();
2314
2315    wd->item_compare_cb = comp;
2316    wd->items = eina_inlist_sorted_state_insert(wd->items, EINA_INLIST_GET(it),
2317                                          _elm_gengrid_item_compare, wd->state);
2318    if (wd->calc_job) ecore_job_del(wd->calc_job);
2319    wd->calc_job = ecore_job_add(_calc_job, wd);
2320
2321    return (Elm_Object_Item *) it;
2322 }
2323
2324 EAPI Elm_Object_Item *
2325 elm_gengrid_item_sorted_insert(Evas_Object                  *obj,
2326                                const Elm_Gengrid_Item_Class *itc,
2327                                const void                   *data,
2328                                Eina_Compare_Cb               comp,
2329                                Evas_Smart_Cb                 func,
2330                                const void                   *func_data)
2331 {
2332    Widget_Data *wd = elm_widget_data_get(obj);
2333    wd->item_compare_data_cb = comp;
2334
2335    return elm_gengrid_item_direct_sorted_insert(obj, itc, data, _elm_gengrid_item_compare_data, func, func_data);
2336 }
2337
2338 EAPI void
2339 elm_gengrid_item_del(Elm_Object_Item *it)
2340 {
2341    elm_object_item_del(it);
2342 }
2343
2344 EAPI void
2345 elm_gengrid_horizontal_set(Evas_Object *obj,
2346                            Eina_Bool    setting)
2347 {
2348    ELM_CHECK_WIDTYPE(obj, widtype);
2349    Widget_Data *wd = elm_widget_data_get(obj);
2350    if (!wd) return;
2351    if (setting == wd->horizontal) return;
2352    wd->horizontal = setting;
2353
2354    /* Update the items to conform to the new layout */
2355    if (wd->calc_job) ecore_job_del(wd->calc_job);
2356    wd->calc_job = ecore_job_add(_calc_job, wd);
2357 }
2358
2359 EAPI Eina_Bool
2360 elm_gengrid_horizontal_get(const Evas_Object *obj)
2361 {
2362    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2363    Widget_Data *wd = elm_widget_data_get(obj);
2364    if (!wd) return EINA_FALSE;
2365    return wd->horizontal;
2366 }
2367
2368 #if 1
2369 static void
2370 _elm_gengrid_clear(Evas_Object *obj, Eina_Bool standby)
2371 {
2372    Eina_Inlist *next, *l;
2373
2374    ELM_CHECK_WIDTYPE(obj, widtype);
2375    Widget_Data *wd = elm_widget_data_get(obj);
2376    if (!wd) return;
2377
2378    if (!standby) wd->generation++;
2379
2380    if (wd->state)
2381      {
2382         eina_inlist_sorted_state_free(wd->state);
2383         wd->state = NULL;
2384      }
2385
2386    if (wd->walking > 0)
2387      {
2388         wd->clear_me = 1;
2389         return;
2390      }
2391    evas_event_freeze(evas_object_evas_get(wd->obj));
2392    for (l = wd->items, next = l ? l->next : NULL;
2393         l;
2394         l = next, next = next ? next->next : NULL)
2395      {
2396         Elm_Gen_Item *it = ELM_GEN_ITEM_FROM_INLIST(l);
2397
2398         if (it->generation < wd->generation)
2399           {
2400              Elm_Gen_Item *itn = NULL;
2401
2402              if (next) itn = ELM_GEN_ITEM_FROM_INLIST(next);
2403              if (itn) itn->walking++; /* prevent early death of subitem */
2404              it->del_cb(it);
2405              elm_widget_item_free(it);
2406              if (itn) itn->walking--;
2407           }
2408      }
2409    wd->clear_me = 0;
2410    wd->pan_changed = EINA_TRUE;
2411    if (wd->calc_job)
2412      {
2413         ecore_job_del(wd->calc_job);
2414         wd->calc_job = NULL;
2415      }
2416    if (wd->selected) wd->selected = eina_list_free(wd->selected);
2417    if (wd->clear_cb) wd->clear_cb(wd);
2418    wd->pan_x = 0;
2419    wd->pan_y = 0;
2420    wd->minw = 0;
2421    wd->minh = 0;
2422    wd->count = 0;
2423    if (wd->pan_smart)
2424      {
2425         evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
2426         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2427      }
2428    if (wd->sizing_cb) wd->sizing_cb(wd->obj);
2429    elm_smart_scroller_child_region_show(wd->scr, 0, 0, 0, 0);
2430    evas_event_thaw(evas_object_evas_get(wd->obj));
2431    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
2432 }
2433 #endif
2434
2435 EAPI void
2436 elm_gengrid_clear(Evas_Object *obj)
2437 {
2438 #if 0
2439    elm_genlist_clear(obj);
2440 #else
2441    _elm_gengrid_clear(obj, EINA_FALSE);
2442 #endif
2443 }
2444
2445 EAPI const Evas_Object *
2446 elm_gengrid_item_object_get(const Elm_Object_Item *it)
2447 {
2448    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2449    return VIEW(it);
2450 }
2451
2452 EAPI void
2453 elm_gengrid_item_update(Elm_Object_Item *it)
2454 {
2455    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2456    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2457    if (!_it->realized) return;
2458    if (_it->want_unrealize) return;
2459    _elm_gengrid_item_unrealize(_it, EINA_FALSE);
2460    _item_realize(_it);
2461    _item_place(_it, _it->x, _it->y);
2462 }
2463
2464 EAPI void *
2465 elm_gengrid_item_data_get(const Elm_Object_Item *it)
2466 {
2467    return elm_object_item_data_get(it);
2468 }
2469
2470 EAPI void
2471 elm_gengrid_item_data_set(Elm_Object_Item  *it,
2472                           const void       *data)
2473 {
2474    elm_object_item_data_set(it, (void *) data);
2475 }
2476
2477 EAPI const Elm_Gengrid_Item_Class *
2478 elm_gengrid_item_item_class_get(const Elm_Object_Item *it)
2479 {
2480    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2481    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2482    if (_it->generation < _it->wd->generation) return NULL;
2483    return _it->itc;
2484 }
2485
2486 EAPI void
2487 elm_gengrid_item_item_class_set(Elm_Object_Item *it,
2488                                 const Elm_Gengrid_Item_Class *itc)
2489 {
2490    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2491    EINA_SAFETY_ON_NULL_RETURN(itc);
2492    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2493    if (_it->generation < _it->wd->generation) return;
2494    _it->itc = itc;
2495    elm_gengrid_item_update(it);
2496 }
2497
2498 EAPI void
2499 elm_gengrid_item_pos_get(const Elm_Object_Item *it,
2500                          unsigned int           *x,
2501                          unsigned int           *y)
2502 {
2503    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2504    if (x) *x = ((Elm_Gen_Item *) it)->x;
2505    if (y) *y = ((Elm_Gen_Item *) it)->y;
2506 }
2507
2508 EAPI void
2509 elm_gengrid_multi_select_set(Evas_Object *obj,
2510                              Eina_Bool    multi)
2511 {
2512    ELM_CHECK_WIDTYPE(obj, widtype);
2513    Widget_Data *wd = elm_widget_data_get(obj);
2514    if (!wd) return;
2515    wd->multi = multi;
2516 }
2517
2518 EAPI Eina_Bool
2519 elm_gengrid_multi_select_get(const Evas_Object *obj)
2520 {
2521    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2522    Widget_Data *wd = elm_widget_data_get(obj);
2523    if (!wd) return EINA_FALSE;
2524    return wd->multi;
2525 }
2526
2527 EAPI Elm_Object_Item *
2528 elm_gengrid_selected_item_get(const Evas_Object *obj)
2529 {
2530    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2531    Widget_Data *wd = elm_widget_data_get(obj);
2532    if (!wd) return NULL;
2533    if (wd->selected) return wd->selected->data;
2534    return NULL;
2535 }
2536
2537 EAPI const Eina_List *
2538 elm_gengrid_selected_items_get(const Evas_Object *obj)
2539 {
2540    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2541    Widget_Data *wd = elm_widget_data_get(obj);
2542    if (!wd) return NULL;
2543    return wd->selected;
2544 }
2545
2546 EAPI void
2547 elm_gengrid_item_selected_set(Elm_Object_Item  *it,
2548                               Eina_Bool         selected)
2549 {
2550 #if 0
2551    elm_genlist_item_selected_set(it, selected);
2552 #else
2553    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2554    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2555    Widget_Data *wd = _it->wd;
2556    if (!wd) return;
2557    if ((_it->generation < wd->generation) || elm_widget_item_disabled_get(_it))
2558      return;
2559    selected = !!selected;
2560    if (_it->selected == selected) return;
2561
2562    if (selected)
2563      {
2564         if (!wd->multi)
2565           {
2566              while (wd->selected)
2567                {
2568                   if (_it->unhighlight_cb) _it->unhighlight_cb(wd->selected->data);
2569                   _it->unsel_cb(wd->selected->data);
2570                }
2571           }
2572         _it->highlight_cb(_it);
2573         _item_select(_it);
2574         return;
2575      }
2576    if (_it->unhighlight_cb) _it->unhighlight_cb(_it);
2577    _it->unsel_cb(_it);
2578 #endif
2579 }
2580
2581 EAPI Eina_Bool
2582 elm_gengrid_item_selected_get(const Elm_Object_Item *it)
2583 {
2584 #if 0
2585    return elm_genlist_item_selected_get(it);
2586 #else
2587    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2588    return ((Elm_Gen_Item *) it)->selected;
2589 #endif
2590 }
2591
2592 EAPI void
2593 elm_gengrid_item_disabled_set(Elm_Object_Item  *it,
2594                               Eina_Bool         disabled)
2595 {
2596    elm_object_item_disabled_set(it, disabled);
2597 }
2598
2599 EAPI Eina_Bool
2600 elm_gengrid_item_disabled_get(const Elm_Object_Item *it)
2601 {
2602    return elm_object_item_disabled_get(it);
2603 }
2604
2605 static Evas_Object *
2606 _elm_gengrid_item_label_create(void        *data,
2607                                Evas_Object *obj __UNUSED__,
2608                                Evas_Object *tooltip,
2609                                void *it   __UNUSED__)
2610 {
2611    Evas_Object *label = elm_label_add(tooltip);
2612    if (!label)
2613      return NULL;
2614    elm_object_style_set(label, "tooltip");
2615    elm_object_text_set(label, data);
2616    return label;
2617 }
2618
2619 static void
2620 _elm_gengrid_item_label_del_cb(void            *data,
2621                                Evas_Object *obj __UNUSED__,
2622                                void *event_info __UNUSED__)
2623 {
2624    eina_stringshare_del(data);
2625 }
2626
2627 EAPI void
2628 elm_gengrid_item_tooltip_text_set(Elm_Object_Item  *it,
2629                                   const char       *text)
2630 {
2631    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2632    text = eina_stringshare_add(text);
2633    elm_gengrid_item_tooltip_content_cb_set(it, _elm_gengrid_item_label_create,
2634                                            text,
2635                                            _elm_gengrid_item_label_del_cb);
2636 }
2637
2638 EAPI void
2639 elm_gengrid_item_tooltip_content_cb_set(Elm_Object_Item            *it,
2640                                         Elm_Tooltip_Item_Content_Cb func,
2641                                         const void                 *data,
2642                                         Evas_Smart_Cb               del_cb)
2643 {
2644    ELM_OBJ_ITEM_CHECK_OR_GOTO(it, error);
2645    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2646
2647    if ((_it->tooltip.content_cb == func) && (_it->tooltip.data == data))
2648      return;
2649
2650    if (_it->tooltip.del_cb)
2651      _it->tooltip.del_cb((void *)_it->tooltip.data, WIDGET(_it), _it);
2652    _it->tooltip.content_cb = func;
2653    _it->tooltip.data = data;
2654    _it->tooltip.del_cb = del_cb;
2655    if (VIEW(_it))
2656      {
2657         elm_widget_item_tooltip_content_cb_set(_it,
2658                                                _it->tooltip.content_cb,
2659                                                _it->tooltip.data, NULL);
2660         elm_widget_item_tooltip_style_set(_it, _it->tooltip.style);
2661         elm_widget_item_tooltip_window_mode_set(_it, _it->tooltip.free_size);
2662      }
2663
2664    return;
2665
2666 error:
2667    if (del_cb) del_cb((void *)data, NULL, NULL);
2668 }
2669
2670 EAPI void
2671 elm_gengrid_item_tooltip_unset(Elm_Object_Item *it)
2672 {
2673    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2674    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2675
2676    if ((VIEW(_it)) && (_it->tooltip.content_cb))
2677      elm_widget_item_tooltip_unset(_it);
2678
2679    if (_it->tooltip.del_cb)
2680      _it->tooltip.del_cb((void *) _it->tooltip.data, WIDGET(_it), _it);
2681    _it->tooltip.del_cb = NULL;
2682    _it->tooltip.content_cb = NULL;
2683    _it->tooltip.data = NULL;
2684    _it->tooltip.free_size = EINA_FALSE;
2685    if (_it->tooltip.style)
2686      elm_gengrid_item_tooltip_style_set(it, NULL);
2687 }
2688
2689 EAPI void
2690 elm_gengrid_item_tooltip_style_set(Elm_Object_Item  *it,
2691                                    const char       *style)
2692 {
2693    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2694    eina_stringshare_replace(&((Elm_Gen_Item *) it)->tooltip.style, style);
2695    if (VIEW(it)) elm_widget_item_tooltip_style_set(it, style);
2696 }
2697
2698 EAPI const char *
2699 elm_gengrid_item_tooltip_style_get(const Elm_Object_Item *it)
2700 {
2701    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2702    return ((Elm_Gen_Item *) it)->tooltip.style;
2703 }
2704
2705 EAPI Eina_Bool
2706 elm_gengrid_item_tooltip_window_mode_set(Elm_Object_Item *it, Eina_Bool disable)
2707 {
2708    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2709    ((Elm_Gen_Item *) it)->tooltip.free_size = disable;
2710    if (VIEW(it)) return elm_widget_item_tooltip_window_mode_set(it, disable);
2711    return EINA_TRUE;
2712 }
2713
2714 EAPI Eina_Bool
2715 elm_gengrid_item_tooltip_window_mode_get(const Elm_Object_Item *it)
2716 {
2717    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2718    return ((Elm_Gen_Item *) it)->tooltip.free_size;
2719 }
2720
2721 EAPI void
2722 elm_gengrid_item_cursor_set(Elm_Object_Item  *it,
2723                             const char       *cursor)
2724 {
2725    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2726    eina_stringshare_replace(&((Elm_Gen_Item *) it)->mouse_cursor, cursor);
2727    if (VIEW(it)) elm_widget_item_cursor_set(it, cursor);
2728 }
2729
2730 EAPI const char *
2731 elm_gengrid_item_cursor_get(const Elm_Object_Item *it)
2732 {
2733    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2734    return elm_widget_item_cursor_get(it);
2735 }
2736
2737 EAPI void
2738 elm_gengrid_item_cursor_unset(Elm_Object_Item *it)
2739 {
2740    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2741    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2742    if (!_it->mouse_cursor)
2743      return;
2744
2745    if (VIEW(_it))
2746      elm_widget_item_cursor_unset(_it);
2747
2748    eina_stringshare_del(_it->mouse_cursor);
2749    _it->mouse_cursor = NULL;
2750 }
2751
2752 EAPI void
2753 elm_gengrid_item_cursor_style_set(Elm_Object_Item  *it,
2754                                   const char       *style)
2755 {
2756    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2757    elm_widget_item_cursor_style_set(it, style);
2758 }
2759
2760 EAPI const char *
2761 elm_gengrid_item_cursor_style_get(const Elm_Object_Item *it)
2762 {
2763    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2764    return elm_widget_item_cursor_style_get(it);
2765 }
2766
2767 EAPI void
2768 elm_gengrid_item_cursor_engine_only_set(Elm_Object_Item  *it,
2769                                         Eina_Bool         engine_only)
2770 {
2771    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2772    elm_widget_item_cursor_engine_only_set(it, engine_only);
2773 }
2774
2775 EAPI Eina_Bool
2776 elm_gengrid_item_cursor_engine_only_get(const Elm_Object_Item *it)
2777 {
2778    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2779    return elm_widget_item_cursor_engine_only_get(it);
2780 }
2781
2782 EAPI void
2783 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2784                              Eina_Bool    reorder_mode)
2785 {
2786    ELM_CHECK_WIDTYPE(obj, widtype);
2787    Widget_Data *wd = elm_widget_data_get(obj);
2788    if (!wd) return;
2789    wd->reorder_mode = reorder_mode;
2790 }
2791
2792 EAPI Eina_Bool
2793 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
2794 {
2795    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2796    Widget_Data *wd = elm_widget_data_get(obj);
2797    if (!wd) return EINA_FALSE;
2798    return wd->reorder_mode;
2799 }
2800
2801 EAPI void
2802 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2803                                    Eina_Bool    always_select)
2804 {
2805 #if 0
2806    elm_genlist_always_select_mode_set(obj, always_select);
2807 #else
2808    ELM_CHECK_WIDTYPE(obj, widtype);
2809    Widget_Data *wd = elm_widget_data_get(obj);
2810    if (!wd) return;
2811    wd->always_select = always_select;
2812 #endif
2813 }
2814
2815 EAPI Eina_Bool
2816 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2817 {
2818 #if 0
2819    return elm_genlist_always_select_mode_get(obj);
2820 #else
2821    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2822    Widget_Data *wd = elm_widget_data_get(obj);
2823    if (!wd) return EINA_FALSE;
2824    return wd->always_select;
2825 #endif
2826 }
2827
2828 EAPI void
2829 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2830                                Eina_Bool    no_select)
2831 {
2832 #if 0
2833    elm_genlist_no_select_mode_set(obj, no_select);
2834 #else
2835    ELM_CHECK_WIDTYPE(obj, widtype);
2836    Widget_Data *wd = elm_widget_data_get(obj);
2837    if (!wd) return;
2838    wd->no_select = no_select;
2839 #endif
2840 }
2841
2842 EAPI Eina_Bool
2843 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2844 {
2845 #if 0
2846    return elm_genlist_no_select_mode_get(obj);
2847 #else
2848    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2849    Widget_Data *wd = elm_widget_data_get(obj);
2850    if (!wd) return EINA_FALSE;
2851    return wd->no_select;
2852 #endif
2853 }
2854
2855 EAPI void
2856 elm_gengrid_bounce_set(Evas_Object *obj,
2857                        Eina_Bool    h_bounce,
2858                        Eina_Bool    v_bounce)
2859 {
2860 #if 0
2861    elm_genlist_bounce_set(obj, h_bounce, v_bounce);
2862 #else
2863    ELM_CHECK_WIDTYPE(obj, widtype);
2864    Widget_Data *wd = elm_widget_data_get(obj);
2865    if (!wd) return;
2866    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
2867    wd->h_bounce = h_bounce;
2868    wd->v_bounce = v_bounce;
2869 #endif
2870 }
2871
2872 EAPI void
2873 elm_gengrid_bounce_get(const Evas_Object *obj,
2874                        Eina_Bool         *h_bounce,
2875                        Eina_Bool         *v_bounce)
2876 {
2877 #if 0
2878    elm_genlist_bounce_get(obj, h_bounce, v_bounce);
2879 #else
2880    ELM_CHECK_WIDTYPE(obj, widtype);
2881    Widget_Data *wd = elm_widget_data_get(obj);
2882    if (!wd) return;
2883    if (h_bounce) *h_bounce = wd->h_bounce;
2884    if (v_bounce) *v_bounce = wd->v_bounce;
2885 #endif
2886 }
2887
2888 EAPI void
2889 elm_gengrid_page_relative_set(Evas_Object *obj,
2890                               double       h_pagerel,
2891                               double       v_pagerel)
2892 {
2893 #if 0
2894    _elm_genlist_page_relative_set(obj, h_pagerel, v_pagerel);
2895 #else
2896    Evas_Coord pagesize_h;
2897    Evas_Coord pagesize_v;
2898
2899    ELM_CHECK_WIDTYPE(obj, widtype);
2900    Widget_Data *wd = elm_widget_data_get(obj);
2901    if (!wd) return;
2902
2903    elm_smart_scroller_paging_get(wd->scr, NULL, NULL, &pagesize_h, &pagesize_v);
2904    elm_smart_scroller_paging_set(wd->scr, h_pagerel, v_pagerel, pagesize_h,
2905                                  pagesize_v);
2906 #endif
2907 }
2908
2909 EAPI void
2910 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
2911 {
2912 #if 0
2913    _elm_genlist_page_relative_get(obj, h_pagerel, v_pagerel);
2914 #else
2915    ELM_CHECK_WIDTYPE(obj, widtype);
2916    Widget_Data *wd = elm_widget_data_get(obj);
2917    if (!wd) return;
2918
2919    elm_smart_scroller_paging_get(wd->scr, h_pagerel, v_pagerel, NULL, NULL);
2920 #endif
2921 }
2922
2923 EAPI void
2924 elm_gengrid_page_size_set(Evas_Object *obj,
2925                           Evas_Coord   h_pagesize,
2926                           Evas_Coord   v_pagesize)
2927 {
2928 #if 0
2929    _elm_genlist_page_size_set(obj, h_pagesize, v_pagesize);
2930 #else
2931    double pagerel_h;
2932    double pagerel_v;
2933
2934    ELM_CHECK_WIDTYPE(obj, widtype);
2935    Widget_Data *wd = elm_widget_data_get(obj);
2936    if (!wd) return;
2937    elm_smart_scroller_paging_get(wd->scr, &pagerel_h, &pagerel_v, NULL, NULL);
2938    elm_smart_scroller_paging_set(wd->scr, pagerel_h, pagerel_v, h_pagesize,
2939                                  v_pagesize);
2940 #endif
2941 }
2942
2943 EAPI void
2944 elm_gengrid_current_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2945 {
2946 #if 0
2947    _elm_genlist_current_page_get(obj, h_pagenumber, v_pagenumber);
2948 #else
2949    ELM_CHECK_WIDTYPE(obj, widtype);
2950    Widget_Data *wd = elm_widget_data_get(obj);
2951    if (!wd) return;
2952    if (wd->scr)
2953      elm_smart_scroller_current_page_get(wd->scr, h_pagenumber, v_pagenumber);
2954 #endif
2955 }
2956
2957 EAPI void
2958 elm_gengrid_last_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2959 {
2960 #if 0
2961    _elm_genlist_last_page_get(obj, h_pagenumber, v_pagenumber);
2962 #else
2963    ELM_CHECK_WIDTYPE(obj, widtype);
2964    Widget_Data *wd = elm_widget_data_get(obj);
2965    if (!wd) return;
2966    if (wd->scr)
2967      elm_smart_scroller_last_page_get(wd->scr, h_pagenumber, v_pagenumber);
2968 #endif
2969 }
2970
2971 EAPI void
2972 elm_gengrid_page_show(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2973 {
2974 #if 0
2975    _elm_genlist_page_show(obj, h_pagenumber, v_pagenumber);
2976 #else
2977    ELM_CHECK_WIDTYPE(obj, widtype);
2978    Widget_Data *wd = elm_widget_data_get(obj);
2979    if (!wd) return;
2980    if (wd->scr)
2981      elm_smart_scroller_page_show(wd->scr, h_pagenumber, v_pagenumber);
2982 #endif
2983 }
2984
2985 EAPI void
2986 elm_gengrid_page_bring_in(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2987 {
2988 #if 0
2989    _elm_genlist_page_bring_in(obj, h_pagenumber, v_pagenumber);
2990 #else
2991    ELM_CHECK_WIDTYPE(obj, widtype);
2992    Widget_Data *wd = elm_widget_data_get(obj);
2993    if (!wd) return;
2994    if (wd->scr)
2995      elm_smart_scroller_page_bring_in(wd->scr, h_pagenumber, v_pagenumber);
2996 #endif
2997 }
2998
2999 EAPI Elm_Object_Item *
3000 elm_gengrid_first_item_get(const Evas_Object *obj)
3001 {
3002 #if 0
3003    return elm_genlist_first_item_get(obj);
3004 #else
3005    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3006    Widget_Data *wd = elm_widget_data_get(obj);
3007    if (!wd) return NULL;
3008    if (!wd->items) return NULL;
3009    Elm_Gen_Item *it = ELM_GEN_ITEM_FROM_INLIST(wd->items);
3010    while ((it) && (it->generation < wd->generation))
3011      it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
3012    return (Elm_Object_Item *) it;
3013 #endif
3014 }
3015
3016 EAPI Elm_Object_Item *
3017 elm_gengrid_last_item_get(const Evas_Object *obj)
3018 {
3019 #if 0
3020    return elm_genlist_last_item_get(obj);
3021 #else
3022    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3023    Widget_Data *wd = elm_widget_data_get(obj);
3024    if (!wd) return NULL;
3025    if (!wd->items) return NULL;
3026    Elm_Gen_Item *it = ELM_GEN_ITEM_FROM_INLIST(wd->items->last);
3027    while ((it) && (it->generation < wd->generation))
3028      it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
3029    return (Elm_Object_Item *) it;
3030 #endif
3031 }
3032
3033 EAPI Elm_Object_Item *
3034 elm_gengrid_item_next_get(const Elm_Object_Item *it)
3035 {
3036 #if 0
3037    return elm_genlist_item_next_get(it);
3038 #else
3039    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
3040    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
3041    while (_it)
3042      {
3043         _it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(_it)->next);
3044         if ((_it) && (_it->generation == _it->wd->generation)) break;
3045      }
3046    return (Elm_Object_Item *) _it;
3047 #endif
3048 }
3049
3050 EAPI Elm_Object_Item *
3051 elm_gengrid_item_prev_get(const Elm_Object_Item *it)
3052 {
3053 #if 0
3054    return elm_genlist_item_prev_get(it);
3055 #else
3056    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
3057    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
3058    while (_it)
3059      {
3060         _it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(_it)->prev);
3061         if ((_it) && (_it->generation == _it->wd->generation)) break;
3062      }
3063    return (Elm_Object_Item *) _it;
3064 #endif
3065 }
3066
3067 EAPI Evas_Object *
3068 elm_gengrid_item_gengrid_get(const Elm_Object_Item *it)
3069 {
3070    return elm_object_item_widget_get(it);
3071 }
3072
3073 EAPI void
3074 elm_gengrid_item_show(Elm_Object_Item *it)
3075 {
3076    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
3077    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
3078    Widget_Data *wd = _it->wd;
3079    Evas_Coord minx = 0, miny = 0;
3080
3081    if ((_it->generation < _it->wd->generation)) return;
3082    _pan_min_get(wd->pan_smart, &minx, &miny);
3083
3084    if (wd->horizontal)
3085      elm_smart_scroller_region_bring_in(_it->wd->scr,
3086                                         ((_it->x - _it->item->prev_group) * wd->item_width) + (_it->item->prev_group * _it->wd->group_item_width) + minx,
3087                                         _it->y * wd->item_height + miny,
3088                                         _it->wd->item_width,
3089                                         _it->wd->item_height);
3090    else
3091      elm_smart_scroller_region_bring_in(_it->wd->scr,
3092                                         _it->x * wd->item_width + minx,
3093                                         ((_it->y - _it->item->prev_group) * wd->item_height) + (_it->item->prev_group * _it->wd->group_item_height) + miny,
3094                                         _it->wd->item_width,
3095                                         _it->wd->item_height);
3096 }
3097
3098 EAPI void
3099 elm_gengrid_item_bring_in(Elm_Object_Item *it)
3100 {
3101    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
3102    Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
3103
3104    if (_it->generation < _it->wd->generation) return;
3105
3106    Evas_Coord minx = 0, miny = 0;
3107    Widget_Data *wd = _it->wd;
3108    _pan_min_get(wd->pan_smart, &minx, &miny);
3109
3110    if (wd->horizontal)
3111      elm_smart_scroller_region_bring_in(_it->wd->scr,
3112                                         ((_it->x - _it->item->prev_group) * wd->item_width) + (_it->item->prev_group * _it->wd->group_item_width) + minx,
3113                                         _it->y * wd->item_height + miny,
3114                                         _it->wd->item_width,
3115                                         _it->wd->item_height);
3116    else
3117      elm_smart_scroller_region_bring_in(_it->wd->scr,
3118                                         _it->x * wd->item_width + minx,
3119                                         ((_it->y - _it->item->prev_group)* wd->item_height) + (_it->item->prev_group * _it->wd->group_item_height) + miny,
3120                                         _it->wd->item_width,
3121                                         _it->wd->item_height);
3122 }
3123
3124 EAPI void
3125 elm_gengrid_filled_set(Evas_Object *obj, Eina_Bool fill)
3126 {
3127    ELM_CHECK_WIDTYPE(obj, widtype);
3128    Widget_Data *wd = elm_widget_data_get(obj);
3129    if (!wd) return;
3130    fill = !!fill;
3131    if (wd->filled != fill)
3132      wd->filled = fill;
3133 }
3134
3135 EAPI Eina_Bool
3136 elm_gengrid_filled_get(const Evas_Object *obj)
3137 {
3138    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3139    Widget_Data *wd = elm_widget_data_get(obj);
3140    if (!wd) return EINA_FALSE;
3141    return wd->filled;
3142 }
3143
3144 #if 1
3145 void
3146 _elm_gengrid_item_unrealize(Elm_Gen_Item *it,
3147                             Eina_Bool     calc)
3148 {
3149    Evas_Object *content;
3150
3151    if (!it->realized) return;
3152    if (it->wd->reorder_it == it) return;
3153    evas_event_freeze(evas_object_evas_get(WIDGET(it)));
3154    if (!calc)
3155      evas_object_smart_callback_call(WIDGET(it), SIG_UNREALIZED, it);
3156    if (it->long_timer)
3157      {
3158         ecore_timer_del(it->long_timer);
3159         it->long_timer = NULL;
3160      }
3161
3162    elm_widget_stringlist_free(it->texts);
3163    it->texts = NULL;
3164    elm_widget_stringlist_free(it->contents);
3165    it->contents = NULL;
3166    elm_widget_stringlist_free(it->states);
3167    it->states = NULL;
3168
3169    EINA_LIST_FREE(it->content_objs, content)
3170      evas_object_del(content);
3171
3172    it->unrealize_cb(it);
3173
3174    it->realized = EINA_FALSE;
3175    it->want_unrealize = EINA_FALSE;
3176    evas_event_thaw(evas_object_evas_get(WIDGET(it)));
3177    evas_event_thaw_eval(evas_object_evas_get(WIDGET(it)));
3178 }
3179
3180 void
3181 _elm_gengrid_item_del_notserious(Elm_Gen_Item *it)
3182 {
3183    elm_widget_item_pre_notify_del(it);
3184    it->generation = it->wd->generation - 1; /* This means that the item is deleted */
3185    if (it->selected) it->wd->selected = eina_list_remove(it->wd->selected, it);
3186
3187    if (it->itc->func.del)
3188      it->itc->func.del((void *)it->base.data, WIDGET(it));
3189 }
3190
3191 void
3192 _elm_gengrid_item_del_serious(Elm_Gen_Item *it)
3193 {
3194    _elm_gengrid_item_del_notserious(it);
3195    it->wd->items = eina_inlist_remove(it->wd->items, EINA_INLIST_GET(it));
3196    if (it->tooltip.del_cb)
3197      it->tooltip.del_cb((void *)it->tooltip.data, WIDGET(it), it);
3198    it->wd->walking -= it->walking;
3199    if (it->long_timer) ecore_timer_del(it->long_timer);
3200    if (it->group)
3201      it->wd->group_items = eina_list_remove(it->wd->group_items, it);
3202
3203    if (it->wd->state)
3204      {
3205         eina_inlist_sorted_state_free(it->wd->state);
3206         it->wd->state = NULL;
3207      }
3208    if (it->wd->calc_job) ecore_job_del(it->wd->calc_job);
3209    it->wd->calc_job = ecore_job_add(it->wd->calc_cb, it->wd);
3210    free(it->item);
3211
3212    it->item = NULL;
3213    if (it->wd->last_selected_item == (Elm_Object_Item *) it)
3214      it->wd->last_selected_item = NULL;
3215 }
3216 #endif