1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
4 #include "els_scroller.h"
5 #include "elm_gen_common.h"
9 * Handle non-homogeneous objects too.
13 #define REORDER_EFFECT_TIME 0.5
15 #define ELM_GEN_SETUP(wd) \
16 (wd)->calc_cb = (Ecore_Cb)_calc_job
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
24 struct Elm_Gen_Item_Type
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;
32 Eina_Bool group_realized : 1;
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). */
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 */
51 int item_width, item_height;
52 int group_item_width, group_item_height;
55 Evas_Coord pan_x, pan_y;
56 Eina_Bool reorder_mode : 1;
57 Eina_Bool on_hold : 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;
67 ////////////////////////////////////
68 double align_x, align_y;
70 Evas_Coord old_pan_x, old_pan_y;
71 Evas_Coord reorder_item_x, reorder_item_y;
77 Eina_Bool horizontal : 1;
78 Eina_Bool longpressed : 1;
79 Eina_Bool reorder_item_changed : 1;
80 Eina_Bool move_effect_enabled : 1;
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,
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,
101 Evas_Callback_Type type,
103 static Eina_Bool _deselect_all_items(Widget_Data *wd);
105 static void _elm_gengrid_clear(Evas_Object *obj,
109 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
110 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
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";
137 static const Evas_Smart_Cb_Description _signals[] = {
139 {SIG_CLICKED_DOUBLE, ""},
140 {SIG_LONGPRESSED, ""},
142 {SIG_UNSELECTED, ""},
144 {SIG_UNREALIZED, ""},
146 {SIG_DRAG_START_UP, ""},
147 {SIG_DRAG_START_DOWN, ""},
148 {SIG_DRAG_START_LEFT, ""},
149 {SIG_DRAG_START_RIGHT, ""},
153 {SIG_SCROLL_ANIM_START, ""},
154 {SIG_SCROLL_ANIM_STOP, ""},
155 {SIG_SCROLL_DRAG_START, ""},
156 {SIG_SCROLL_DRAG_STOP, ""},
158 {SIG_EDGE_BOTTOM, ""},
160 {SIG_EDGE_RIGHT, ""},
166 _event_hook(Evas_Object *obj,
167 Evas_Object *src __UNUSED__,
168 Evas_Callback_Type type,
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;
179 Elm_Object_Item *it = NULL;
182 Evas_Coord step_x = 0;
183 Evas_Coord step_y = 0;
186 Evas_Coord page_x = 0;
187 Evas_Coord page_y = 0;
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);
194 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
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))))
201 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
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))))
209 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
215 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
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))))
222 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
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))))
230 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
236 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
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))))
243 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
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))))
251 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
257 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
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))))
264 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
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))))
272 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
278 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
280 it = elm_gengrid_first_item_get(obj);
281 elm_gengrid_item_bring_in(it);
282 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
285 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
287 it = elm_gengrid_last_item_get(obj);
288 elm_gengrid_item_bring_in(it);
289 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
292 else if ((!strcmp(ev->keyname, "Prior")) || (!strcmp(ev->keyname, "KP_Prior")))
297 x -= -(page_x * v_w) / 100;
304 y -= -(page_y * v_h) / 100;
309 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
314 x += -(page_x * v_w) / 100;
321 y += -(page_y * v_h) / 100;
326 else if (!strcmp(ev->keyname, "Escape"))
328 if (!_deselect_all_items(wd)) return EINA_FALSE;
329 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
332 else if (((!strcmp(ev->keyname, "Return")) ||
333 (!strcmp(ev->keyname, "KP_Enter")) ||
334 (!strcmp(ev->keyname, "space")))
335 && (!wd->multi) && (wd->selected))
337 it = elm_gengrid_selected_item_get(obj);
338 evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it);
340 else return EINA_FALSE;
342 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
343 elm_smart_scroller_child_pos_set(wd->scr, x, y);
348 _deselect_all_items(Widget_Data *wd)
350 if (!wd->selected) return EINA_FALSE;
352 elm_gengrid_item_selected_set((Elm_Object_Item *) wd->selected->data,
359 _item_multi_select_left(Widget_Data *wd)
361 if (!wd->selected) return EINA_FALSE;
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))
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);
374 elm_gengrid_item_selected_set(prev, EINA_TRUE);
375 elm_gengrid_item_show(prev);
382 _item_multi_select_right(Widget_Data *wd)
384 if (!wd->selected) return EINA_FALSE;
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))
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);
397 elm_gengrid_item_selected_set(next, EINA_TRUE);
398 elm_gengrid_item_show(next);
405 _item_multi_select_up(Widget_Data *wd)
408 Eina_Bool r = EINA_TRUE;
410 if (!wd->selected) return EINA_FALSE;
412 for (i = 0; (r) && (i < wd->nmax); i++)
413 r &= _item_multi_select_left(wd);
419 _item_multi_select_down(Widget_Data *wd)
422 Eina_Bool r = EINA_TRUE;
424 if (!wd->selected) return EINA_FALSE;
426 for (i = 0; (r) && (i < wd->nmax); i++)
427 r &= _item_multi_select_right(wd);
433 _item_single_select_up(Widget_Data *wd)
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);
449 prev = (Elm_Gen_Item *) elm_gengrid_item_prev_get(wd->last_selected_item);
451 if (!prev) return EINA_FALSE;
453 for (i = 1; i < wd->nmax; i++)
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;
461 _deselect_all_items(wd);
463 elm_gengrid_item_selected_set((Elm_Object_Item *) prev, EINA_TRUE);
464 elm_gengrid_item_show((Elm_Object_Item *) prev);
469 _item_single_select_down(Widget_Data *wd)
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);
485 next = (Elm_Gen_Item *) elm_gengrid_item_next_get(wd->last_selected_item);
487 if (!next) return EINA_FALSE;
489 for (i = 1; i < wd->nmax; i++)
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;
497 _deselect_all_items(wd);
499 elm_gengrid_item_selected_set((Elm_Object_Item *) next, EINA_TRUE);
500 elm_gengrid_item_show((Elm_Object_Item *) next);
505 _item_single_select_left(Widget_Data *wd)
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);
515 prev = (Elm_Gen_Item *) elm_gengrid_item_prev_get(wd->last_selected_item);
517 if (!prev) return EINA_FALSE;
519 _deselect_all_items(wd);
521 elm_gengrid_item_selected_set((Elm_Object_Item *) prev, EINA_TRUE);
522 elm_gengrid_item_show((Elm_Object_Item *) prev);
527 _item_single_select_right(Widget_Data *wd)
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);
537 next = (Elm_Gen_Item *) elm_gengrid_item_next_get(wd->last_selected_item);
539 if (!next) return EINA_FALSE;
541 _deselect_all_items(wd);
543 elm_gengrid_item_selected_set((Elm_Object_Item *) next, EINA_TRUE);
544 elm_gengrid_item_show((Elm_Object_Item *) next);
549 _on_focus_hook(void *data __UNUSED__,
552 Widget_Data *wd = elm_widget_data_get(obj);
554 if (elm_widget_focus_get(obj))
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);
563 edje_object_signal_emit(wd->obj, "elm,action,unfocus", "elm");
564 evas_object_focus_set(wd->obj, EINA_FALSE);
569 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
571 Widget_Data *wd = elm_widget_data_get(obj);
574 elm_smart_scroller_mirrored_set(wd->scr, rtl);
575 if (!wd->items) return;
576 it = ELM_GEN_ITEM_FROM_INLIST(wd->items);
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);
587 _theme_hook(Evas_Object *obj)
589 Widget_Data *wd = elm_widget_data_get(obj);
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));
598 _del_pre_hook(Evas_Object *obj)
600 Widget_Data *wd = elm_widget_data_get(obj);
602 elm_gengrid_clear(obj);
603 evas_object_del(wd->pan_smart);
604 wd->pan_smart = NULL;
608 _del_hook(Evas_Object *obj)
610 Widget_Data *wd = elm_widget_data_get(obj);
611 if (wd->calc_job) ecore_job_del(wd->calc_job);
616 _signal_emit_hook(Evas_Object *obj,
617 const char *emission,
620 Widget_Data *wd = elm_widget_data_get(obj);
622 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
627 _signal_callback_add_hook(Evas_Object *obj,
628 const char *emission,
630 Edje_Signal_Cb func_cb,
633 Widget_Data *wd = elm_widget_data_get(obj);
635 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
636 emission, source, func_cb, data);
640 _signal_callback_del_hook(Evas_Object *obj,
641 const char *emission,
643 Edje_Signal_Cb func_cb,
646 Widget_Data *wd = elm_widget_data_get(obj);
648 edje_object_signal_callback_del_full(elm_smart_scroller_edje_object_get(wd->scr),
649 emission, source, func_cb, data);
653 _mouse_move(void *data,
654 Evas *evas __UNUSED__,
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;
663 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
665 if (!it->wd->on_hold)
667 it->wd->on_hold = EINA_TRUE;
668 if (!it->wd->wasselected)
672 if ((it->dragging) && (it->down))
676 ecore_timer_del(it->long_timer);
677 it->long_timer = NULL;
679 evas_object_smart_callback_call(WIDGET(it), SIG_DRAG, it);
682 if ((!it->down) || (it->wd->longpressed))
686 ecore_timer_del(it->long_timer);
687 it->long_timer = NULL;
689 if ((it->wd->reorder_mode) && (it->wd->reorder_it))
691 evas_object_geometry_get(it->wd->pan_smart, &ox, &oy, &ow, &oh);
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;
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;
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;
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);
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;
718 if (adx < 0) adx = -dx;
721 if (ady < 0) ady = -dy;
724 if ((adx > minw) || (ady > minh))
726 const char *left_drag, *right_drag;
727 if (!elm_widget_mirrored_get(WIDGET(it)))
729 left_drag = SIG_DRAG_START_LEFT;
730 right_drag = SIG_DRAG_START_RIGHT;
734 left_drag = SIG_DRAG_START_RIGHT;
735 right_drag = SIG_DRAG_START_LEFT;
741 ecore_timer_del(it->long_timer);
742 it->long_timer = NULL;
744 if (!it->wd->wasselected)
749 evas_object_smart_callback_call(WIDGET(it), SIG_DRAG_START_UP,
754 evas_object_smart_callback_call(WIDGET(it),
761 evas_object_smart_callback_call(WIDGET(it),
762 SIG_DRAG_START_DOWN, it);
766 evas_object_smart_callback_call(WIDGET(it),
769 evas_object_smart_callback_call(WIDGET(it),
777 _long_press(void *data)
779 Elm_Gen_Item *it = data;
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)
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");
794 return ECORE_CALLBACK_CANCEL;
798 _mouse_down(void *data,
799 Evas *evas __UNUSED__,
803 Elm_Gen_Item *it = data;
804 Evas_Event_Mouse_Down *ev = event_info;
807 if (ev->button != 1) return;
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;
819 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
821 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
822 evas_object_smart_callback_call(WIDGET(it), SIG_ACTIVATED, it);
824 if (it->long_timer) ecore_timer_del(it->long_timer);
826 it->long_timer = ecore_timer_add(_elm_config->longpress_timeout,
829 it->long_timer = NULL;
833 _mouse_up(void *data,
834 Evas *evas __UNUSED__,
835 Evas_Object *obj __UNUSED__,
838 Elm_Gen_Item *it = data;
839 Evas_Event_Mouse_Up *ev = event_info;
840 Eina_Bool dragged = EINA_FALSE;
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;
848 ecore_timer_del(it->long_timer);
849 it->long_timer = NULL;
853 it->dragging = EINA_FALSE;
854 evas_object_smart_callback_call(WIDGET(it), SIG_DRAG_STOP, it);
859 it->wd->longpressed = EINA_FALSE;
860 it->wd->on_hold = EINA_FALSE;
863 if ((it->wd->reorder_mode) && (it->wd->reorder_it))
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);
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");
875 if (it->wd->longpressed)
877 it->wd->longpressed = EINA_FALSE;
878 if (!it->wd->wasselected) _item_unselect(it);
879 it->wd->wasselected = EINA_FALSE;
884 if (it->want_unrealize)
885 _elm_gengrid_item_unrealize(it, EINA_FALSE);
887 if (elm_widget_item_disabled_get(it) || (dragged)) return;
895 else _item_unselect(it);
901 while (it->wd->selected)
902 _item_unselect(it->wd->selected->data);
906 const Eina_List *l, *l_next;
909 EINA_LIST_FOREACH_SAFE(it->wd->selected, l, l_next, item2)
910 if (item2 != it) _item_unselect(item2);
918 _item_highlight(Elm_Gen_Item *it)
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;
926 _item_realize(Elm_Gen_Item *it)
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)) *
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)));
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);
949 if (it->itc->func.text_get)
955 elm_widget_stringlist_get(edje_object_data_get(VIEW(it),
957 EINA_LIST_FOREACH(it->texts, l, key)
959 char *s = it->itc->func.text_get
960 ((void *)it->base.data, WIDGET(it), key);
963 edje_object_part_text_set(VIEW(it), key, s);
969 if (it->itc->func.content_get)
973 Evas_Object *ic = NULL;
976 elm_widget_stringlist_get(edje_object_data_get(VIEW(it),
978 EINA_LIST_FOREACH(it->contents, l, key)
980 if (it->itc->func.content_get)
981 ic = it->itc->func.content_get
982 ((void *)it->base.data, WIDGET(it), key);
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);
993 if (it->itc->func.state_get)
999 elm_widget_stringlist_get(edje_object_data_get(VIEW(it),
1001 EINA_LIST_FOREACH(it->states, l, key)
1003 Eina_Bool on = it->itc->func.state_get
1004 ((void *)it->base.data, WIDGET(it), l->data);
1007 snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1008 edje_object_signal_emit(VIEW(it), buf, "elm");
1015 if ((!it->wd->group_item_width) && (!it->wd->group_item_height))
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);
1026 if ((!it->wd->item_width) && (!it->wd->item_height))
1028 edje_object_size_min_restricted_calc(VIEW(it),
1029 &it->wd->item_width,
1030 &it->wd->item_height,
1032 it->wd->item_height);
1033 elm_coords_finger_size_adjust(1, &it->wd->item_width,
1034 1, &it->wd->item_height);
1037 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
1039 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
1041 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
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");
1049 evas_object_show(VIEW(it));
1051 if (it->tooltip.content_cb)
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);
1060 if (it->mouse_cursor)
1061 elm_widget_item_cursor_set(it, it->mouse_cursor);
1063 it->realized = EINA_TRUE;
1064 it->want_unrealize = EINA_FALSE;
1068 _item_unrealize_cb(Elm_Gen_Item *it)
1070 evas_object_del(VIEW(it));
1072 evas_object_del(it->spacer);
1077 _reorder_item_moving_effect_timer_cb(void *data)
1079 Elm_Gen_Item *it = data;
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;
1090 it->item->rx += (1 * sin((t / time) * (M_PI / 2)) * dx);
1091 it->item->ry += (1 * sin((t / time) * (M_PI / 2)) * dy);
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))))
1102 evas_object_move(VIEW(it), it->item->tx, it->item->ty);
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);
1110 evas_object_resize(VIEW(it), vw, it->wd->group_item_height);
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;
1119 evas_object_move(VIEW(it), it->item->rx, it->item->ry);
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);
1127 evas_object_resize(VIEW(it), vw, it->wd->group_item_height);
1130 evas_object_resize(VIEW(it), it->wd->item_width, it->wd->item_height);
1132 return ECORE_CALLBACK_RENEW;
1136 _group_item_place(Pan *sd)
1138 Evas_Coord iw, ih, vw, vh;
1140 Eina_Bool was_realized;
1142 evas_object_geometry_get(sd->wd->pan_smart, NULL, NULL, &vw, &vh);
1143 if (sd->wd->horizontal)
1145 iw = sd->wd->group_item_width;
1151 ih = sd->wd->group_item_height;
1153 EINA_LIST_FOREACH(sd->wd->group_items, l, it)
1155 was_realized = it->realized;
1156 if (it->item->group_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));
1166 _elm_gengrid_item_unrealize(it, EINA_FALSE);
1172 _item_place(Elm_Gen_Item *it,
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;
1182 evas_object_geometry_get(it->wd->pan_smart, &ox, &oy, &vw, &vh);
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;
1193 items_count = it->wd->count - eina_list_count(it->wd->group_items) + it->wd->items_lost;
1194 if (it->wd->horizontal)
1196 int columns, items_visible = 0, items_row;
1198 if (it->wd->item_height > 0)
1199 items_visible = vh / it->wd->item_height;
1200 if (items_visible < 1)
1203 columns = items_count / items_visible;
1204 if (items_count % items_visible)
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;
1210 items_row = items_visible;
1211 if (items_row > it->wd->count)
1212 items_row = it->wd->count;
1214 && (unsigned int)it->wd->nmax > (unsigned int)it->wd->count)
1215 tch = it->wd->nmax * it->wd->item_height;
1217 tch = items_row * it->wd->item_height;
1218 alignh = (vh - tch) * it->wd->align_y;
1222 int rows, items_visible = 0, items_col;
1224 if (it->wd->item_width > 0)
1225 items_visible = vw / it->wd->item_width;
1226 if (items_visible < 1)
1229 rows = items_count / items_visible;
1230 if (items_count % items_visible)
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;
1236 items_col = items_visible;
1237 if (items_col > it->wd->count)
1238 items_col = it->wd->count;
1240 && (unsigned int)it->wd->nmax > (unsigned int)it->wd->count)
1241 tcw = it->wd->nmax * it->wd->item_width;
1243 tcw = items_col * it->wd->item_width;
1244 alignw = (vw - tcw) * it->wd->align_x;
1249 if (it->wd->horizontal)
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;
1253 iw = it->wd->group_item_width;
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;
1261 ih = it->wd->group_item_height;
1268 if (it->wd->horizontal)
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;
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;
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;
1283 iw = it->wd->item_width;
1284 ih = it->wd->item_height;
1287 Eina_Bool was_realized = it->realized;
1288 if (ELM_RECTS_INTERSECT(x, y, iw, ih, cvx, cvy, cvw, cvh))
1292 evas_object_smart_callback_call(WIDGET(it), SIG_REALIZED, it);
1295 if (it->wd->horizontal)
1297 if (it->parent->item->gx < ox)
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;
1303 it->parent->item->group_realized = EINA_TRUE;
1307 if (it->parent->item->gy < oy)
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;
1313 it->parent->item->group_realized = EINA_TRUE;
1316 if (it->wd->reorder_mode)
1318 if (it->wd->reorder_it)
1320 if (it->item->moving) return;
1322 if (!it->wd->move_effect_enabled)
1327 if (it->wd->reorder_it == it)
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);
1336 if (it->wd->move_effect_enabled)
1338 if ((it->item->ox != x) || (it->item->oy != y))
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)))
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);
1357 Evas_Coord nx, ny, nw, nh;
1360 if (it->wd->horizontal)
1362 nx = x + (it->wd->group_item_width / 2);
1370 ny = y + (it->wd->group_item_height / 2);
1377 nx = x + (it->wd->item_width / 2);
1378 ny = y + (it->wd->item_height / 2);
1383 if ( ELM_RECTS_INTERSECT(it->wd->reorder_item_x, it->wd->reorder_item_y,
1384 it->wd->item_width, it->wd->item_height,
1387 if (it->wd->horizontal)
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;
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;
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));
1407 it->wd->items = eina_inlist_append_relative(it->wd->items,
1408 EINA_INLIST_GET(it->wd->reorder_it),
1409 EINA_INLIST_GET(it));
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);
1420 else if (it->item->item_moving_effect_timer)
1422 ecore_animator_del(it->item->item_moving_effect_timer);
1423 it->item->item_moving_effect_timer = NULL;
1424 it->item->moving = EINA_FALSE;
1429 evas_object_move(VIEW(it), x, y);
1430 evas_object_resize(VIEW(it), iw, ih);
1433 it->item->group_realized = EINA_TRUE;
1438 _elm_gengrid_item_unrealize(it, EINA_FALSE);
1440 it->item->group_realized = EINA_FALSE;
1445 _item_del(Elm_Gen_Item *it)
1447 Evas_Object *obj = WIDGET(it);
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);
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));
1459 _item_unselect(Elm_Gen_Item *it)
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;
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);
1473 _calc_job(void *data)
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;
1482 evas_object_geometry_get(wd->pan_smart, NULL, NULL, &cvw, &cvh);
1483 if ((cvw != 0) || (cvh != 0))
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;
1493 EINA_INLIST_FOREACH(wd->items, it)
1495 if (it->item->prev_group != count_group)
1496 it->item->prev_group = count_group;
1499 count = count % nmax;
1501 wd->items_lost += nmax - count;
1502 //printf("%d items and I lost %d\n", count, wd->items_lost);
1504 if (count) count = 0;
1509 if (it->parent != group_item)
1510 it->parent = group_item;
1514 count = wd->count + wd->items_lost - count_group;
1517 minw = (ceil(count / (float)nmax) * wd->item_width) + (count_group * wd->group_item_width);
1518 minh = nmax * wd->item_height;
1522 minw = nmax * wd->item_width;
1523 minh = (ceil(count / (float)nmax) * wd->item_height) + (count_group * wd->group_item_height);
1526 if ((minw != wd->minw) || (minh != wd->minh))
1530 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1534 evas_object_smart_changed(wd->pan_smart);
1536 wd->calc_job = NULL;
1540 _pan_add(Evas_Object *obj)
1543 Evas_Object_Smart_Clipped_Data *cd;
1546 cd = evas_object_smart_data_get(obj);
1549 sd->__clipped_data = *cd;
1551 evas_object_smart_data_set(obj, sd);
1555 _pan_del(Evas_Object *obj)
1557 Pan *sd = evas_object_smart_data_get(obj);
1564 _pan_set(Evas_Object *obj,
1568 Pan *sd = evas_object_smart_data_get(obj);
1569 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1572 evas_object_smart_changed(obj);
1576 _pan_get(Evas_Object *obj,
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;
1586 _pan_child_size_get(Evas_Object *obj,
1590 Pan *sd = evas_object_smart_data_get(obj);
1591 if (w) *w = sd->wd->minw;
1592 if (h) *h = sd->wd->minh;
1596 _pan_max_get(Evas_Object *obj,
1600 Pan *sd = evas_object_smart_data_get(obj);
1604 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1606 *x = (ow < sd->wd->minw) ? sd->wd->minw - ow : 0;
1608 *y = (oh < sd->wd->minh) ? sd->wd->minh - oh : 0;
1612 _pan_min_get(Evas_Object *obj,
1616 Pan *sd = evas_object_smart_data_get(obj);
1617 Evas_Coord mx = 0, my = 0;
1620 _pan_max_get(obj, &mx, &my);
1622 *x = -mx * sd->wd->align_x;
1624 *y = -my * sd->wd->align_y;
1628 _pan_resize(Evas_Object *obj,
1632 Pan *sd = evas_object_smart_data_get(obj);
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);
1642 _pan_calculate(Evas_Object *obj)
1644 Pan *sd = evas_object_smart_data_get(obj);
1645 Evas_Coord cx = 0, cy = 0;
1649 if (!sd->wd->nmax) return;
1651 sd->wd->reorder_item_changed = EINA_FALSE;
1653 EINA_INLIST_FOREACH(sd->wd->items, it)
1657 if (sd->wd->horizontal)
1674 _item_place(it, cx, cy);
1675 if (sd->wd->reorder_item_changed) return;
1678 if (sd->wd->horizontal)
1691 if (sd->wd->horizontal)
1693 cy = (cy + 1) % sd->wd->nmax;
1698 cx = (cx + 1) % sd->wd->nmax;
1703 _group_item_place(sd);
1706 if ((sd->wd->reorder_mode) && (sd->wd->reorder_it))
1708 if (!sd->wd->reorder_item_changed)
1710 sd->wd->old_pan_x = sd->wd->pan_x;
1711 sd->wd->old_pan_y = sd->wd->pan_y;
1713 sd->wd->move_effect_enabled = EINA_FALSE;
1715 evas_object_smart_callback_call(sd->wd->obj, SIG_CHANGED, NULL);
1719 _pan_move(Evas_Object *obj,
1720 Evas_Coord x __UNUSED__,
1721 Evas_Coord y __UNUSED__)
1723 Pan *sd = evas_object_smart_data_get(obj);
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);
1730 _hold_on(void *data __UNUSED__,
1732 void *event_info __UNUSED__)
1734 Widget_Data *wd = elm_widget_data_get(obj);
1736 elm_smart_scroller_hold_set(wd->scr, 1);
1740 _hold_off(void *data __UNUSED__,
1742 void *event_info __UNUSED__)
1744 Widget_Data *wd = elm_widget_data_get(obj);
1746 elm_smart_scroller_hold_set(wd->scr, 0);
1750 _freeze_on(void *data __UNUSED__,
1752 void *event_info __UNUSED__)
1754 Widget_Data *wd = elm_widget_data_get(obj);
1756 elm_smart_scroller_freeze_set(wd->scr, 1);
1760 _freeze_off(void *data __UNUSED__,
1762 void *event_info __UNUSED__)
1764 Widget_Data *wd = elm_widget_data_get(obj);
1766 elm_smart_scroller_freeze_set(wd->scr, 0);
1770 _scr_anim_start(void *data,
1771 Evas_Object *obj __UNUSED__,
1772 void *event_info __UNUSED__)
1774 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
1778 _scr_anim_stop(void *data,
1779 Evas_Object *obj __UNUSED__,
1780 void *event_info __UNUSED__)
1782 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
1786 _scr_drag_start(void *data,
1787 Evas_Object *obj __UNUSED__,
1788 void *event_info __UNUSED__)
1790 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1794 _scr_drag_stop(void *data,
1795 Evas_Object *obj __UNUSED__,
1796 void *event_info __UNUSED__)
1798 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1802 _edge_left(void *data,
1803 Evas_Object *scr __UNUSED__,
1804 void *event_info __UNUSED__)
1806 evas_object_smart_callback_call(data, SIG_EDGE_LEFT, NULL);
1810 _edge_right(void *data,
1811 Evas_Object *scr __UNUSED__,
1812 void *event_info __UNUSED__)
1814 evas_object_smart_callback_call(data, SIG_EDGE_RIGHT, NULL);
1818 _edge_top(void *data,
1819 Evas_Object *scr __UNUSED__,
1820 void *event_info __UNUSED__)
1822 evas_object_smart_callback_call(data, SIG_EDGE_TOP, NULL);
1826 _edge_bottom(void *data,
1827 Evas_Object *scr __UNUSED__,
1828 void *event_info __UNUSED__)
1830 evas_object_smart_callback_call(data, SIG_EDGE_BOTTOM, NULL);
1834 _scr_scroll(void *data,
1835 Evas_Object *obj __UNUSED__,
1836 void *event_info __UNUSED__)
1838 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1842 _elm_gengrid_item_compare_data(const void *data, const void *data1)
1844 const Elm_Gen_Item *it = data;
1845 const Elm_Gen_Item *item1 = data1;
1847 return it->wd->item_compare_data_cb(it->base.data, item1->base.data);
1851 _elm_gengrid_item_compare(const void *data, const void *data1)
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);
1860 _item_disable_hook(Elm_Object_Item *it)
1862 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1863 Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
1865 if (_it->generation < _it->wd->generation) return;
1869 if (elm_widget_item_disabled_get(_it))
1870 edje_object_signal_emit(VIEW(_it), "elm,state,disabled", "elm");
1872 edje_object_signal_emit(VIEW(_it), "elm,state,enabled", "elm");
1877 _item_del_pre_hook(Elm_Object_Item *it)
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))
1883 _elm_gengrid_item_del_notserious(_it);
1892 _item_select(Elm_Gen_Item *it)
1894 if ((it->wd->no_select) || (it->generation < it->wd->generation) || (it->mode_set)) return;
1897 it->selected = EINA_TRUE;
1898 it->wd->selected = eina_list_append(it->wd->selected, it);
1900 else if (!it->wd->always_select) return;
1902 evas_object_ref(WIDGET(it));
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);
1910 evas_object_unref(WIDGET(it));
1911 if ((it->wd->clear_me) && (!it->wd->walking))
1912 _elm_gengrid_clear(WIDGET(it), EINA_TRUE);
1915 if ((!it->walking) && (it->generation < it->wd->generation))
1920 elm_widget_item_free(it);
1924 it->wd->last_selected_item = (Elm_Object_Item *) it;
1928 static Evas_Object *
1929 _item_content_get_hook(Elm_Gen_Item *it, const char *part)
1931 return edje_object_part_swallow_get(VIEW(it), part);
1935 _item_content_set_hook(Elm_Gen_Item *it, const char *part, Evas_Object *content)
1937 edje_object_part_swallow(VIEW(it), part, content);
1940 static Evas_Object *
1941 _item_content_unset_hook(Elm_Gen_Item *it, const char *part)
1945 obj = edje_object_part_swallow_get(VIEW(it), part);
1946 if (!obj) return NULL;
1947 edje_object_part_unswallow(VIEW(it), obj);
1952 _item_text_hook(Elm_Gen_Item *it, const char *part)
1954 if (!it->itc->func.text_get) return NULL;
1955 return edje_object_part_text_get(VIEW(it), part);
1959 _elm_gengrid_item_new(Widget_Data *wd,
1960 const Elm_Gen_Item_Class *itc,
1962 Elm_Gen_Item *parent,
1964 const void *func_data)
1968 it = elm_widget_item_new(wd->obj, Elm_Gen_Item);
1969 if (!it) return NULL;
1971 it->generation = wd->generation;
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);
1983 it->sel_cb = (Ecore_Cb)_item_select;
1985 elm_widget_item_text_get_hook_set(it, _item_text_hook);
1990 static Elm_Gen_Item *
1991 _item_new(Widget_Data *wd,
1992 const Elm_Gengrid_Item_Class *itc,
1995 const void *func_data)
2000 it = _elm_genlist_item_new(wd, itc, data, NULL, func, func_data);
2002 it = _elm_gengrid_item_new(wd, itc, data, NULL, func, func_data);
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);
2009 it->group = it->itc->item_style && (!strcmp(it->itc->item_style, "group_index"));
2010 ELM_GEN_ITEM_SETUP(it);
2016 elm_gengrid_add(Evas_Object *parent)
2021 static Evas_Smart *smart = NULL;
2022 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
2026 static Evas_Smart_Class sc;
2028 evas_object_smart_clipped_smart_set(&_pan_sc);
2030 sc.name = "elm_gengrid_pan";
2031 sc.version = EVAS_SMART_CLASS_VERSION;
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;
2040 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2042 ELM_SET_WIDTYPE(widtype, "gengrid");
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);
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",
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);
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,
2075 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
2080 wd->h_bounce = bounce;
2081 wd->v_bounce = bounce;
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);
2088 wd->pan_smart = evas_object_smart_add(e, smart);
2089 wd->pan = evas_object_smart_data_get(wd->pan_smart);
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);
2096 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2098 _mirrored_set(obj, elm_widget_mirrored_get(obj));
2103 elm_gengrid_item_size_set(Evas_Object *obj,
2107 ELM_CHECK_WIDTYPE(obj, widtype);
2108 Widget_Data *wd = elm_widget_data_get(obj);
2110 if ((wd->item_width == w) && (wd->item_height == h)) return;
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);
2118 elm_gengrid_item_size_get(const Evas_Object *obj,
2122 ELM_CHECK_WIDTYPE(obj, widtype);
2123 Widget_Data *wd = elm_widget_data_get(obj);
2125 if (w) *w = wd->item_width;
2126 if (h) *h = wd->item_height;
2130 elm_gengrid_group_item_size_set(Evas_Object *obj,
2134 ELM_CHECK_WIDTYPE(obj, widtype);
2135 Widget_Data *wd = elm_widget_data_get(obj);
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);
2145 elm_gengrid_group_item_size_get(const Evas_Object *obj,
2149 ELM_CHECK_WIDTYPE(obj, widtype);
2150 Widget_Data *wd = elm_widget_data_get(obj);
2152 if (w) *w = wd->group_item_width;
2153 if (h) *h = wd->group_item_height;
2157 elm_gengrid_align_set(Evas_Object *obj,
2161 ELM_CHECK_WIDTYPE(obj, widtype);
2163 Widget_Data *wd = elm_widget_data_get(obj);
2164 double old_h = wd->align_x, old_y = wd->align_y;
2168 else if (align_x < 0.0)
2170 wd->align_x = align_x;
2174 else if (align_y < 0.0)
2176 wd->align_y = align_y;
2178 if ((old_h != wd->align_x) || (old_y != wd->align_y))
2179 evas_object_smart_calculate(wd->pan_smart);
2183 elm_gengrid_align_get(const Evas_Object *obj,
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;
2193 EAPI Elm_Object_Item *
2194 elm_gengrid_item_append(Evas_Object *obj,
2195 const Elm_Gengrid_Item_Class *itc,
2198 const void *func_data)
2201 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2202 Widget_Data *wd = elm_widget_data_get(obj);
2203 if (!wd) return NULL;
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));
2210 wd->group_items = eina_list_prepend(wd->group_items, it);
2212 if (wd->calc_job) ecore_job_del(wd->calc_job);
2213 wd->calc_job = ecore_job_add(_calc_job, wd);
2215 return (Elm_Object_Item *) it;
2218 EAPI Elm_Object_Item *
2219 elm_gengrid_item_prepend(Evas_Object *obj,
2220 const Elm_Gengrid_Item_Class *itc,
2223 const void *func_data)
2226 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2227 Widget_Data *wd = elm_widget_data_get(obj);
2228 if (!wd) return NULL;
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));
2234 wd->group_items = eina_list_append(wd->group_items, it);
2236 if (wd->calc_job) ecore_job_del(wd->calc_job);
2237 wd->calc_job = ecore_job_add(_calc_job, wd);
2239 return (Elm_Object_Item *) it;
2242 EAPI Elm_Object_Item *
2243 elm_gengrid_item_insert_before(Evas_Object *obj,
2244 const Elm_Gengrid_Item_Class *itc,
2246 Elm_Object_Item *relative,
2248 const void *func_data)
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;
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));
2261 wd->group_items = eina_list_append_relative(wd->group_items, it, ((Elm_Gen_Item *) relative)->parent);
2263 if (wd->calc_job) ecore_job_del(wd->calc_job);
2264 wd->calc_job = ecore_job_add(_calc_job, wd);
2266 return (Elm_Object_Item *) it;
2269 EAPI Elm_Object_Item *
2270 elm_gengrid_item_insert_after(Evas_Object *obj,
2271 const Elm_Gengrid_Item_Class *itc,
2273 Elm_Object_Item *relative,
2275 const void *func_data)
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;
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));
2288 wd->group_items = eina_list_prepend_relative(wd->group_items, it, ((Elm_Gen_Item *) relative)->parent);
2290 if (wd->calc_job) ecore_job_del(wd->calc_job);
2291 wd->calc_job = ecore_job_add(_calc_job, wd);
2293 return (Elm_Object_Item *) it;
2296 EAPI Elm_Object_Item *
2297 elm_gengrid_item_direct_sorted_insert(Evas_Object *obj,
2298 const Elm_Gengrid_Item_Class *itc,
2300 Eina_Compare_Cb comp,
2302 const void *func_data)
2305 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2306 Widget_Data *wd = elm_widget_data_get(obj);
2307 if (!wd) return NULL;
2309 it = _item_new(wd, itc, data, func, func_data);
2310 if (!it) return NULL;
2313 wd->state = eina_inlist_sorted_state_new();
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);
2321 return (Elm_Object_Item *) it;
2324 EAPI Elm_Object_Item *
2325 elm_gengrid_item_sorted_insert(Evas_Object *obj,
2326 const Elm_Gengrid_Item_Class *itc,
2328 Eina_Compare_Cb comp,
2330 const void *func_data)
2332 Widget_Data *wd = elm_widget_data_get(obj);
2333 wd->item_compare_data_cb = comp;
2335 return elm_gengrid_item_direct_sorted_insert(obj, itc, data, _elm_gengrid_item_compare_data, func, func_data);
2339 elm_gengrid_item_del(Elm_Object_Item *it)
2341 elm_object_item_del(it);
2345 elm_gengrid_horizontal_set(Evas_Object *obj,
2348 ELM_CHECK_WIDTYPE(obj, widtype);
2349 Widget_Data *wd = elm_widget_data_get(obj);
2351 if (setting == wd->horizontal) return;
2352 wd->horizontal = setting;
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);
2360 elm_gengrid_horizontal_get(const Evas_Object *obj)
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;
2370 _elm_gengrid_clear(Evas_Object *obj, Eina_Bool standby)
2372 Eina_Inlist *next, *l;
2374 ELM_CHECK_WIDTYPE(obj, widtype);
2375 Widget_Data *wd = elm_widget_data_get(obj);
2378 if (!standby) wd->generation++;
2382 eina_inlist_sorted_state_free(wd->state);
2386 if (wd->walking > 0)
2391 evas_event_freeze(evas_object_evas_get(wd->obj));
2392 for (l = wd->items, next = l ? l->next : NULL;
2394 l = next, next = next ? next->next : NULL)
2396 Elm_Gen_Item *it = ELM_GEN_ITEM_FROM_INLIST(l);
2398 if (it->generation < wd->generation)
2400 Elm_Gen_Item *itn = NULL;
2402 if (next) itn = ELM_GEN_ITEM_FROM_INLIST(next);
2403 if (itn) itn->walking++; /* prevent early death of subitem */
2405 elm_widget_item_free(it);
2406 if (itn) itn->walking--;
2410 wd->pan_changed = EINA_TRUE;
2413 ecore_job_del(wd->calc_job);
2414 wd->calc_job = NULL;
2416 if (wd->selected) wd->selected = eina_list_free(wd->selected);
2417 if (wd->clear_cb) wd->clear_cb(wd);
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);
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));
2436 elm_gengrid_clear(Evas_Object *obj)
2439 elm_genlist_clear(obj);
2441 _elm_gengrid_clear(obj, EINA_FALSE);
2445 EAPI const Evas_Object *
2446 elm_gengrid_item_object_get(const Elm_Object_Item *it)
2448 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2453 elm_gengrid_item_update(Elm_Object_Item *it)
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);
2461 _item_place(_it, _it->x, _it->y);
2465 elm_gengrid_item_data_get(const Elm_Object_Item *it)
2467 return elm_object_item_data_get(it);
2471 elm_gengrid_item_data_set(Elm_Object_Item *it,
2474 elm_object_item_data_set(it, (void *) data);
2477 EAPI const Elm_Gengrid_Item_Class *
2478 elm_gengrid_item_item_class_get(const Elm_Object_Item *it)
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;
2487 elm_gengrid_item_item_class_set(Elm_Object_Item *it,
2488 const Elm_Gengrid_Item_Class *itc)
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;
2495 elm_gengrid_item_update(it);
2499 elm_gengrid_item_pos_get(const Elm_Object_Item *it,
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;
2509 elm_gengrid_multi_select_set(Evas_Object *obj,
2512 ELM_CHECK_WIDTYPE(obj, widtype);
2513 Widget_Data *wd = elm_widget_data_get(obj);
2519 elm_gengrid_multi_select_get(const Evas_Object *obj)
2521 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2522 Widget_Data *wd = elm_widget_data_get(obj);
2523 if (!wd) return EINA_FALSE;
2527 EAPI Elm_Object_Item *
2528 elm_gengrid_selected_item_get(const Evas_Object *obj)
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;
2537 EAPI const Eina_List *
2538 elm_gengrid_selected_items_get(const Evas_Object *obj)
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;
2547 elm_gengrid_item_selected_set(Elm_Object_Item *it,
2551 elm_genlist_item_selected_set(it, selected);
2553 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2554 Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2555 Widget_Data *wd = _it->wd;
2557 if ((_it->generation < wd->generation) || elm_widget_item_disabled_get(_it))
2559 selected = !!selected;
2560 if (_it->selected == selected) return;
2566 while (wd->selected)
2568 if (_it->unhighlight_cb) _it->unhighlight_cb(wd->selected->data);
2569 _it->unsel_cb(wd->selected->data);
2572 _it->highlight_cb(_it);
2576 if (_it->unhighlight_cb) _it->unhighlight_cb(_it);
2582 elm_gengrid_item_selected_get(const Elm_Object_Item *it)
2585 return elm_genlist_item_selected_get(it);
2587 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2588 return ((Elm_Gen_Item *) it)->selected;
2593 elm_gengrid_item_disabled_set(Elm_Object_Item *it,
2596 elm_object_item_disabled_set(it, disabled);
2600 elm_gengrid_item_disabled_get(const Elm_Object_Item *it)
2602 return elm_object_item_disabled_get(it);
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__)
2611 Evas_Object *label = elm_label_add(tooltip);
2614 elm_object_style_set(label, "tooltip");
2615 elm_object_text_set(label, data);
2620 _elm_gengrid_item_label_del_cb(void *data,
2621 Evas_Object *obj __UNUSED__,
2622 void *event_info __UNUSED__)
2624 eina_stringshare_del(data);
2628 elm_gengrid_item_tooltip_text_set(Elm_Object_Item *it,
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,
2635 _elm_gengrid_item_label_del_cb);
2639 elm_gengrid_item_tooltip_content_cb_set(Elm_Object_Item *it,
2640 Elm_Tooltip_Item_Content_Cb func,
2642 Evas_Smart_Cb del_cb)
2644 ELM_OBJ_ITEM_CHECK_OR_GOTO(it, error);
2645 Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2647 if ((_it->tooltip.content_cb == func) && (_it->tooltip.data == data))
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;
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);
2667 if (del_cb) del_cb((void *)data, NULL, NULL);
2671 elm_gengrid_item_tooltip_unset(Elm_Object_Item *it)
2673 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2674 Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2676 if ((VIEW(_it)) && (_it->tooltip.content_cb))
2677 elm_widget_item_tooltip_unset(_it);
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);
2690 elm_gengrid_item_tooltip_style_set(Elm_Object_Item *it,
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);
2699 elm_gengrid_item_tooltip_style_get(const Elm_Object_Item *it)
2701 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2702 return ((Elm_Gen_Item *) it)->tooltip.style;
2706 elm_gengrid_item_tooltip_window_mode_set(Elm_Object_Item *it, Eina_Bool disable)
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);
2715 elm_gengrid_item_tooltip_window_mode_get(const Elm_Object_Item *it)
2717 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2718 return ((Elm_Gen_Item *) it)->tooltip.free_size;
2722 elm_gengrid_item_cursor_set(Elm_Object_Item *it,
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);
2731 elm_gengrid_item_cursor_get(const Elm_Object_Item *it)
2733 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2734 return elm_widget_item_cursor_get(it);
2738 elm_gengrid_item_cursor_unset(Elm_Object_Item *it)
2740 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2741 Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
2742 if (!_it->mouse_cursor)
2746 elm_widget_item_cursor_unset(_it);
2748 eina_stringshare_del(_it->mouse_cursor);
2749 _it->mouse_cursor = NULL;
2753 elm_gengrid_item_cursor_style_set(Elm_Object_Item *it,
2756 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2757 elm_widget_item_cursor_style_set(it, style);
2761 elm_gengrid_item_cursor_style_get(const Elm_Object_Item *it)
2763 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2764 return elm_widget_item_cursor_style_get(it);
2768 elm_gengrid_item_cursor_engine_only_set(Elm_Object_Item *it,
2769 Eina_Bool engine_only)
2771 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2772 elm_widget_item_cursor_engine_only_set(it, engine_only);
2776 elm_gengrid_item_cursor_engine_only_get(const Elm_Object_Item *it)
2778 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2779 return elm_widget_item_cursor_engine_only_get(it);
2783 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2784 Eina_Bool reorder_mode)
2786 ELM_CHECK_WIDTYPE(obj, widtype);
2787 Widget_Data *wd = elm_widget_data_get(obj);
2789 wd->reorder_mode = reorder_mode;
2793 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
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;
2802 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2803 Eina_Bool always_select)
2806 elm_genlist_always_select_mode_set(obj, always_select);
2808 ELM_CHECK_WIDTYPE(obj, widtype);
2809 Widget_Data *wd = elm_widget_data_get(obj);
2811 wd->always_select = always_select;
2816 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2819 return elm_genlist_always_select_mode_get(obj);
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;
2829 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2830 Eina_Bool no_select)
2833 elm_genlist_no_select_mode_set(obj, no_select);
2835 ELM_CHECK_WIDTYPE(obj, widtype);
2836 Widget_Data *wd = elm_widget_data_get(obj);
2838 wd->no_select = no_select;
2843 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2846 return elm_genlist_no_select_mode_get(obj);
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;
2856 elm_gengrid_bounce_set(Evas_Object *obj,
2861 elm_genlist_bounce_set(obj, h_bounce, v_bounce);
2863 ELM_CHECK_WIDTYPE(obj, widtype);
2864 Widget_Data *wd = elm_widget_data_get(obj);
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;
2873 elm_gengrid_bounce_get(const Evas_Object *obj,
2874 Eina_Bool *h_bounce,
2875 Eina_Bool *v_bounce)
2878 elm_genlist_bounce_get(obj, h_bounce, v_bounce);
2880 ELM_CHECK_WIDTYPE(obj, widtype);
2881 Widget_Data *wd = elm_widget_data_get(obj);
2883 if (h_bounce) *h_bounce = wd->h_bounce;
2884 if (v_bounce) *v_bounce = wd->v_bounce;
2889 elm_gengrid_page_relative_set(Evas_Object *obj,
2894 _elm_genlist_page_relative_set(obj, h_pagerel, v_pagerel);
2896 Evas_Coord pagesize_h;
2897 Evas_Coord pagesize_v;
2899 ELM_CHECK_WIDTYPE(obj, widtype);
2900 Widget_Data *wd = elm_widget_data_get(obj);
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,
2910 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
2913 _elm_genlist_page_relative_get(obj, h_pagerel, v_pagerel);
2915 ELM_CHECK_WIDTYPE(obj, widtype);
2916 Widget_Data *wd = elm_widget_data_get(obj);
2919 elm_smart_scroller_paging_get(wd->scr, h_pagerel, v_pagerel, NULL, NULL);
2924 elm_gengrid_page_size_set(Evas_Object *obj,
2925 Evas_Coord h_pagesize,
2926 Evas_Coord v_pagesize)
2929 _elm_genlist_page_size_set(obj, h_pagesize, v_pagesize);
2934 ELM_CHECK_WIDTYPE(obj, widtype);
2935 Widget_Data *wd = elm_widget_data_get(obj);
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,
2944 elm_gengrid_current_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2947 _elm_genlist_current_page_get(obj, h_pagenumber, v_pagenumber);
2949 ELM_CHECK_WIDTYPE(obj, widtype);
2950 Widget_Data *wd = elm_widget_data_get(obj);
2953 elm_smart_scroller_current_page_get(wd->scr, h_pagenumber, v_pagenumber);
2958 elm_gengrid_last_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2961 _elm_genlist_last_page_get(obj, h_pagenumber, v_pagenumber);
2963 ELM_CHECK_WIDTYPE(obj, widtype);
2964 Widget_Data *wd = elm_widget_data_get(obj);
2967 elm_smart_scroller_last_page_get(wd->scr, h_pagenumber, v_pagenumber);
2972 elm_gengrid_page_show(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2975 _elm_genlist_page_show(obj, h_pagenumber, v_pagenumber);
2977 ELM_CHECK_WIDTYPE(obj, widtype);
2978 Widget_Data *wd = elm_widget_data_get(obj);
2981 elm_smart_scroller_page_show(wd->scr, h_pagenumber, v_pagenumber);
2986 elm_gengrid_page_bring_in(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2989 _elm_genlist_page_bring_in(obj, h_pagenumber, v_pagenumber);
2991 ELM_CHECK_WIDTYPE(obj, widtype);
2992 Widget_Data *wd = elm_widget_data_get(obj);
2995 elm_smart_scroller_page_bring_in(wd->scr, h_pagenumber, v_pagenumber);
2999 EAPI Elm_Object_Item *
3000 elm_gengrid_first_item_get(const Evas_Object *obj)
3003 return elm_genlist_first_item_get(obj);
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;
3016 EAPI Elm_Object_Item *
3017 elm_gengrid_last_item_get(const Evas_Object *obj)
3020 return elm_genlist_last_item_get(obj);
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;
3033 EAPI Elm_Object_Item *
3034 elm_gengrid_item_next_get(const Elm_Object_Item *it)
3037 return elm_genlist_item_next_get(it);
3039 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
3040 Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
3043 _it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(_it)->next);
3044 if ((_it) && (_it->generation == _it->wd->generation)) break;
3046 return (Elm_Object_Item *) _it;
3050 EAPI Elm_Object_Item *
3051 elm_gengrid_item_prev_get(const Elm_Object_Item *it)
3054 return elm_genlist_item_prev_get(it);
3056 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
3057 Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
3060 _it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(_it)->prev);
3061 if ((_it) && (_it->generation == _it->wd->generation)) break;
3063 return (Elm_Object_Item *) _it;
3068 elm_gengrid_item_gengrid_get(const Elm_Object_Item *it)
3070 return elm_object_item_widget_get(it);
3074 elm_gengrid_item_show(Elm_Object_Item *it)
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;
3081 if ((_it->generation < _it->wd->generation)) return;
3082 _pan_min_get(wd->pan_smart, &minx, &miny);
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);
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);
3099 elm_gengrid_item_bring_in(Elm_Object_Item *it)
3101 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
3102 Elm_Gen_Item *_it = (Elm_Gen_Item *) it;
3104 if (_it->generation < _it->wd->generation) return;
3106 Evas_Coord minx = 0, miny = 0;
3107 Widget_Data *wd = _it->wd;
3108 _pan_min_get(wd->pan_smart, &minx, &miny);
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);
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);
3125 elm_gengrid_filled_set(Evas_Object *obj, Eina_Bool fill)
3127 ELM_CHECK_WIDTYPE(obj, widtype);
3128 Widget_Data *wd = elm_widget_data_get(obj);
3131 if (wd->filled != fill)
3136 elm_gengrid_filled_get(const Evas_Object *obj)
3138 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3139 Widget_Data *wd = elm_widget_data_get(obj);
3140 if (!wd) return EINA_FALSE;
3146 _elm_gengrid_item_unrealize(Elm_Gen_Item *it,
3149 Evas_Object *content;
3151 if (!it->realized) return;
3152 if (it->wd->reorder_it == it) return;
3153 evas_event_freeze(evas_object_evas_get(WIDGET(it)));
3155 evas_object_smart_callback_call(WIDGET(it), SIG_UNREALIZED, it);
3158 ecore_timer_del(it->long_timer);
3159 it->long_timer = NULL;
3162 elm_widget_stringlist_free(it->texts);
3164 elm_widget_stringlist_free(it->contents);
3165 it->contents = NULL;
3166 elm_widget_stringlist_free(it->states);
3169 EINA_LIST_FREE(it->content_objs, content)
3170 evas_object_del(content);
3172 it->unrealize_cb(it);
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)));
3181 _elm_gengrid_item_del_notserious(Elm_Gen_Item *it)
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);
3187 if (it->itc->func.del)
3188 it->itc->func.del((void *)it->base.data, WIDGET(it));
3192 _elm_gengrid_item_del_serious(Elm_Gen_Item *it)
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);
3201 it->wd->group_items = eina_list_remove(it->wd->group_items, it);
3205 eina_inlist_sorted_state_free(it->wd->state);
3206 it->wd->state = NULL;
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);
3213 if (it->wd->last_selected_item == (Elm_Object_Item *) it)
3214 it->wd->last_selected_item = NULL;