1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
7 * Handle non-homogeneous objects too.
10 typedef struct _Widget_Data Widget_Data;
11 typedef struct _Pan Pan;
14 #define REORDER_EFFECT_TIME 0.5
16 struct _Elm_Gengrid_Item
21 const Elm_Gengrid_Item_Class *gic;
22 Elm_Gengrid_Item *parent_group_item;
23 Ecore_Timer *long_timer;
24 Ecore_Animator *item_moving_effect_timer;
26 Eina_List *labels, *icons, *states, *icon_objs;
33 Evas_Coord x, y, gx, gy, dx, dy, ox, oy, tx, ty, rx, ry;
34 unsigned int moving_effect_start_time;
42 Elm_Tooltip_Item_Content_Cb content_cb;
45 Eina_Bool free_size : 1;
48 const char *mouse_cursor;
50 Eina_Bool is_group : 1;
51 Eina_Bool want_unrealize : 1;
52 Eina_Bool group_realized : 1;
53 Eina_Bool realized : 1;
54 Eina_Bool dragging : 1;
56 Eina_Bool delete_me : 1;
57 Eina_Bool display_only : 1;
58 Eina_Bool disabled : 1;
59 Eina_Bool selected : 1;
60 Eina_Bool highlighted : 1;
66 Eina_Inlist_Sorted_State *state;
67 Evas_Object *self, *scr;
68 Evas_Object *pan_smart;
71 Eina_List *group_items;
74 Elm_Gengrid_Item *last_selected_item, *reorder_item;
75 double align_x, align_y;
77 Evas_Coord pan_x, pan_y, old_pan_x, old_pan_y;
78 Evas_Coord item_width, item_height; /* Each item size */
79 Evas_Coord group_item_width, group_item_height; /* Each group item size */
80 Evas_Coord minw, minh; /* Total obj size */
81 Evas_Coord reorder_item_x, reorder_item_y;
87 Eina_Bool horizontal : 1;
88 Eina_Bool on_hold : 1;
89 Eina_Bool longpressed : 1;
91 Eina_Bool no_select : 1;
92 Eina_Bool wasselected : 1;
93 Eina_Bool always_select : 1;
94 Eina_Bool clear_me : 1;
95 Eina_Bool h_bounce : 1;
96 Eina_Bool v_bounce : 1;
97 Eina_Bool reorder_mode : 1;
98 Eina_Bool reorder_item_changed : 1;
99 Eina_Bool move_effect_enabled : 1;
102 #define ELM_GENGRID_ITEM_FROM_INLIST(item) \
103 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Gengrid_Item) : NULL)
107 Evas_Object_Smart_Clipped_Data __clipped_data;
111 static const char *widtype = NULL;
112 static void _item_highlight(Elm_Gengrid_Item *item);
113 static void _item_unrealize(Elm_Gengrid_Item *item);
114 static void _item_select(Elm_Gengrid_Item *item);
115 static void _item_unselect(Elm_Gengrid_Item *item);
116 static void _calc_job(void *data);
117 static void _on_focus_hook(void *data,
119 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
120 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
121 static Eina_Bool _item_multi_select_left(Widget_Data *wd);
122 static Eina_Bool _item_multi_select_right(Widget_Data *wd);
123 static Eina_Bool _item_single_select_up(Widget_Data *wd);
124 static Eina_Bool _item_single_select_down(Widget_Data *wd);
125 static Eina_Bool _item_single_select_left(Widget_Data *wd);
126 static Eina_Bool _item_single_select_right(Widget_Data *wd);
127 static Eina_Bool _event_hook(Evas_Object *obj,
129 Evas_Callback_Type type,
131 static Eina_Bool _deselect_all_items(Widget_Data *wd);
133 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
134 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
136 static const char SIG_ACTIVATED[] = "activated";
137 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
138 static const char SIG_LONGPRESSED[] = "longpressed";
139 static const char SIG_SELECTED[] = "selected";
140 static const char SIG_UNSELECTED[] = "unselected";
141 static const char SIG_REALIZED[] = "realized";
142 static const char SIG_UNREALIZED[] = "unrealized";
143 static const char SIG_CHANGED[] = "changed";
144 static const char SIG_DRAG_START_UP[] = "drag,start,up";
145 static const char SIG_DRAG_START_DOWN[] = "drag,start,down";
146 static const char SIG_DRAG_START_LEFT[] = "drag,start,left";
147 static const char SIG_DRAG_START_RIGHT[] = "drag,start,right";
148 static const char SIG_DRAG_STOP[] = "drag,stop";
149 static const char SIG_DRAG[] = "drag";
150 static const char SIG_SCROLL[] = "scroll";
151 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
152 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
153 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
154 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
155 static const char SIG_SCROLL_EDGE_TOP[] = "scroll,edge,top";
156 static const char SIG_SCROLL_EDGE_BOTTOM[] = "scroll,edge,bottom";
157 static const char SIG_SCROLL_EDGE_LEFT[] = "scroll,edge,left";
158 static const char SIG_SCROLL_EDGE_RIGHT[] = "scroll,edge,right";
159 static const char SIG_MOVED[] = "moved";
161 static const Evas_Smart_Cb_Description _signals[] = {
163 {SIG_CLICKED_DOUBLE, ""},
164 {SIG_LONGPRESSED, ""},
166 {SIG_UNSELECTED, ""},
168 {SIG_UNREALIZED, ""},
170 {SIG_DRAG_START_UP, ""},
171 {SIG_DRAG_START_DOWN, ""},
172 {SIG_DRAG_START_LEFT, ""},
173 {SIG_DRAG_START_RIGHT, ""},
177 {SIG_SCROLL_ANIM_START, ""},
178 {SIG_SCROLL_ANIM_STOP, ""},
179 {SIG_SCROLL_DRAG_START, ""},
180 {SIG_SCROLL_DRAG_STOP, ""},
181 {SIG_SCROLL_EDGE_TOP, ""},
182 {SIG_SCROLL_EDGE_BOTTOM, ""},
183 {SIG_SCROLL_EDGE_LEFT, ""},
184 {SIG_SCROLL_EDGE_RIGHT, ""},
189 static Eina_Compare_Cb _elm_gengrid_item_compare_cb;
190 static Eina_Compare_Cb _elm_gengrid_item_compare_data_cb;
193 _event_hook(Evas_Object *obj,
194 Evas_Object *src __UNUSED__,
195 Evas_Callback_Type type,
198 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
199 Evas_Event_Key_Down *ev = event_info;
200 Widget_Data *wd = elm_widget_data_get(obj);
201 if (!wd) return EINA_FALSE;
202 if (!wd->items) return EINA_FALSE;
203 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
204 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
206 Elm_Gengrid_Item *item = NULL;
209 Evas_Coord step_x = 0;
210 Evas_Coord step_y = 0;
213 Evas_Coord page_x = 0;
214 Evas_Coord page_y = 0;
216 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
217 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
218 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
219 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
221 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
223 if ((wd->horizontal) &&
224 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
225 (_item_multi_select_up(wd)))
226 || (_item_single_select_up(wd))))
228 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
231 else if ((!wd->horizontal) &&
232 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
233 (_item_multi_select_left(wd)))
234 || (_item_single_select_left(wd))))
236 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
242 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
244 if ((wd->horizontal) &&
245 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
246 (_item_multi_select_down(wd)))
247 || (_item_single_select_down(wd))))
249 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
252 else if ((!wd->horizontal) &&
253 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
254 (_item_multi_select_right(wd)))
255 || (_item_single_select_right(wd))))
257 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
263 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
265 if ((wd->horizontal) &&
266 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
267 (_item_multi_select_left(wd)))
268 || (_item_single_select_left(wd))))
270 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
273 else if ((!wd->horizontal) &&
274 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
275 (_item_multi_select_up(wd)))
276 || (_item_single_select_up(wd))))
278 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
284 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
286 if ((wd->horizontal) &&
287 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
288 (_item_multi_select_right(wd)))
289 || (_item_single_select_right(wd))))
291 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
294 else if ((!wd->horizontal) &&
295 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
296 (_item_multi_select_down(wd)))
297 || (_item_single_select_down(wd))))
299 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
305 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
307 item = elm_gengrid_first_item_get(obj);
308 elm_gengrid_item_bring_in(item);
309 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
312 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
314 item = elm_gengrid_last_item_get(obj);
315 elm_gengrid_item_bring_in(item);
316 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
319 else if ((!strcmp(ev->keyname, "Prior")) ||
320 (!strcmp(ev->keyname, "KP_Prior")))
325 x -= -(page_x * v_w) / 100;
332 y -= -(page_y * v_h) / 100;
337 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
342 x += -(page_x * v_w) / 100;
349 y += -(page_y * v_h) / 100;
354 else if (!strcmp(ev->keyname, "Escape"))
356 if (!_deselect_all_items(wd)) return EINA_FALSE;
357 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
360 else if ((!strcmp(ev->keyname, "Return")) ||
361 (!strcmp(ev->keyname, "KP_Enter")) ||
362 (!strcmp(ev->keyname, "space")))
364 item = elm_gengrid_selected_item_get(obj);
365 evas_object_smart_callback_call(item->wd->self, SIG_ACTIVATED, item);
367 else return EINA_FALSE;
369 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
370 elm_smart_scroller_child_pos_set(wd->scr, x, y);
375 _deselect_all_items(Widget_Data *wd)
377 if (!wd->selected) return EINA_FALSE;
379 elm_gengrid_item_selected_set(wd->selected->data, EINA_FALSE);
385 _item_multi_select_left(Widget_Data *wd)
387 if (!wd->selected) return EINA_FALSE;
389 Elm_Gengrid_Item *prev = elm_gengrid_item_prev_get(wd->last_selected_item);
390 if (!prev) return EINA_TRUE;
391 if (elm_gengrid_item_selected_get(prev))
393 elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
394 wd->last_selected_item = prev;
395 elm_gengrid_item_show(wd->last_selected_item);
399 elm_gengrid_item_selected_set(prev, EINA_TRUE);
400 elm_gengrid_item_show(prev);
407 _item_multi_select_right(Widget_Data *wd)
409 if (!wd->selected) return EINA_FALSE;
411 Elm_Gengrid_Item *next = elm_gengrid_item_next_get(wd->last_selected_item);
412 if (!next) return EINA_TRUE;
413 if (elm_gengrid_item_selected_get(next))
415 elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
416 wd->last_selected_item = next;
417 elm_gengrid_item_show(wd->last_selected_item);
421 elm_gengrid_item_selected_set(next, EINA_TRUE);
422 elm_gengrid_item_show(next);
429 _item_multi_select_up(Widget_Data *wd)
432 Eina_Bool r = EINA_TRUE;
434 if (!wd->selected) return EINA_FALSE;
436 for (i = 0; (r) && (i < wd->nmax); i++)
437 r &= _item_multi_select_left(wd);
443 _item_multi_select_down(Widget_Data *wd)
446 Eina_Bool r = EINA_TRUE;
448 if (!wd->selected) return EINA_FALSE;
450 for (i = 0; (r) && (i < wd->nmax); i++)
451 r &= _item_multi_select_right(wd);
457 _item_single_select_up(Widget_Data *wd)
461 Elm_Gengrid_Item *prev;
465 prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
466 while ((prev) && (prev->delete_me))
467 prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
468 elm_gengrid_item_selected_set(prev, EINA_TRUE);
469 elm_gengrid_item_show(prev);
472 else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
474 if (!prev) return EINA_FALSE;
476 for (i = 1; i < wd->nmax; i++)
478 Elm_Gengrid_Item *tmp = elm_gengrid_item_prev_get(prev);
479 if (!tmp) return EINA_FALSE;
483 _deselect_all_items(wd);
485 elm_gengrid_item_selected_set(prev, EINA_TRUE);
486 elm_gengrid_item_show(prev);
491 _item_single_select_down(Widget_Data *wd)
495 Elm_Gengrid_Item *next;
499 next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
500 while ((next) && (next->delete_me))
501 next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
502 elm_gengrid_item_selected_set(next, EINA_TRUE);
503 elm_gengrid_item_show(next);
506 else next = elm_gengrid_item_next_get(wd->last_selected_item);
508 if (!next) return EINA_FALSE;
510 for (i = 1; i < wd->nmax; i++)
512 Elm_Gengrid_Item *tmp = elm_gengrid_item_next_get(next);
513 if (!tmp) return EINA_FALSE;
517 _deselect_all_items(wd);
519 elm_gengrid_item_selected_set(next, EINA_TRUE);
520 elm_gengrid_item_show(next);
525 _item_single_select_left(Widget_Data *wd)
527 Elm_Gengrid_Item *prev;
530 prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
531 while ((prev) && (prev->delete_me))
532 prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
534 else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
536 if (!prev) return EINA_FALSE;
538 _deselect_all_items(wd);
540 elm_gengrid_item_selected_set(prev, EINA_TRUE);
541 elm_gengrid_item_show(prev);
546 _item_single_select_right(Widget_Data *wd)
548 Elm_Gengrid_Item *next;
551 next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
552 while ((next) && (next->delete_me))
553 next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
555 else next = elm_gengrid_item_next_get(wd->last_selected_item);
557 if (!next) return EINA_FALSE;
559 _deselect_all_items(wd);
561 elm_gengrid_item_selected_set(next, EINA_TRUE);
562 elm_gengrid_item_show(next);
567 _on_focus_hook(void *data __UNUSED__,
570 Widget_Data *wd = elm_widget_data_get(obj);
572 if (elm_widget_focus_get(obj))
574 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
575 evas_object_focus_set(wd->self, EINA_TRUE);
576 if ((wd->selected) && (!wd->last_selected_item))
577 wd->last_selected_item = eina_list_data_get(wd->selected);
581 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
582 evas_object_focus_set(wd->self, EINA_FALSE);
587 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
589 Widget_Data *wd = elm_widget_data_get(obj);
590 Elm_Gengrid_Item *item;
592 elm_smart_scroller_mirrored_set(wd->scr, rtl);
593 if (!wd->items) return;
594 item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
598 edje_object_mirrored_set(item->base.view, rtl);
599 elm_gengrid_item_update(item);
600 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
605 _theme_hook(Evas_Object *obj)
607 Widget_Data *wd = elm_widget_data_get(obj);
609 _elm_widget_mirrored_reload(obj);
610 _mirrored_set(obj, elm_widget_mirrored_get(obj));
611 elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
612 elm_widget_style_get(obj));
616 _del_pre_hook(Evas_Object *obj)
618 Widget_Data *wd = elm_widget_data_get(obj);
620 elm_gengrid_clear(obj);
621 evas_object_del(wd->pan_smart);
622 wd->pan_smart = NULL;
626 _del_hook(Evas_Object *obj)
628 Widget_Data *wd = elm_widget_data_get(obj);
633 _signal_emit_hook(Evas_Object *obj,
634 const char *emission,
637 Widget_Data *wd = elm_widget_data_get(obj);
639 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
644 _signal_callback_add_hook(Evas_Object *obj,
645 const char *emission,
647 Edje_Signal_Cb func_cb,
650 Widget_Data *wd = elm_widget_data_get(obj);
652 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
653 emission, source, func_cb, data);
657 _signal_callback_del_hook(Evas_Object *obj,
658 const char *emission,
660 Edje_Signal_Cb func_cb,
663 Widget_Data *wd = elm_widget_data_get(obj);
665 edje_object_signal_callback_del_full(elm_smart_scroller_edje_object_get(wd->scr),
666 emission, source, func_cb, data);
670 _mouse_move(void *data,
671 Evas *evas __UNUSED__,
675 Elm_Gengrid_Item *item = data;
676 Evas_Event_Mouse_Move *ev = event_info;
677 Evas_Coord minw = 0, minh = 0, x, y, dx, dy, adx, ady;
678 Evas_Coord ox, oy, ow, oh, it_scrl_x, it_scrl_y;
680 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
682 if (!item->wd->on_hold)
684 item->wd->on_hold = EINA_TRUE;
685 if (!item->wd->wasselected)
686 _item_unselect(item);
689 if ((item->dragging) && (item->down))
691 if (item->long_timer)
693 ecore_timer_del(item->long_timer);
694 item->long_timer = NULL;
696 evas_object_smart_callback_call(item->wd->self, SIG_DRAG, item);
699 if ((!item->down) || (item->wd->longpressed))
701 if (item->long_timer)
703 ecore_timer_del(item->long_timer);
704 item->long_timer = NULL;
706 if ((item->wd->reorder_mode) && (item->wd->reorder_item))
708 evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &ow, &oh);
710 it_scrl_x = ev->cur.canvas.x - item->wd->reorder_item->dx;
711 it_scrl_y = ev->cur.canvas.y - item->wd->reorder_item->dy;
713 if (it_scrl_x < ox) item->wd->reorder_item_x = ox;
714 else if (it_scrl_x + item->wd->item_width > ox + ow)
715 item->wd->reorder_item_x = ox + ow - item->wd->item_width;
716 else item->wd->reorder_item_x = it_scrl_x;
718 if (it_scrl_y < oy) item->wd->reorder_item_y = oy;
719 else if (it_scrl_y + item->wd->item_height > oy + oh)
720 item->wd->reorder_item_y = oy + oh - item->wd->item_height;
721 else item->wd->reorder_item_y = it_scrl_y;
723 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
724 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
728 if (!item->display_only)
729 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
730 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
731 x = ev->cur.canvas.x - x;
732 y = ev->cur.canvas.y - y;
735 if (adx < 0) adx = -dx;
738 if (ady < 0) ady = -dy;
741 if ((adx > minw) || (ady > minh))
743 const char *left_drag, *right_drag;
744 if (!elm_widget_mirrored_get(item->wd->self))
746 left_drag = SIG_DRAG_START_LEFT;
747 right_drag = SIG_DRAG_START_RIGHT;
751 left_drag = SIG_DRAG_START_RIGHT;
752 right_drag = SIG_DRAG_START_LEFT;
756 if (item->long_timer)
758 ecore_timer_del(item->long_timer);
759 item->long_timer = NULL;
761 if (!item->wd->wasselected)
762 _item_unselect(item);
766 evas_object_smart_callback_call(item->wd->self, SIG_DRAG_START_UP,
771 evas_object_smart_callback_call(item->wd->self,
778 evas_object_smart_callback_call(item->wd->self,
779 SIG_DRAG_START_DOWN, item);
783 evas_object_smart_callback_call(item->wd->self,
786 evas_object_smart_callback_call(item->wd->self,
794 _long_press(void *data)
796 Elm_Gengrid_Item *item = data;
798 item->long_timer = NULL;
799 if ((item->disabled) || (item->dragging)) return ECORE_CALLBACK_CANCEL;
800 item->wd->longpressed = EINA_TRUE;
801 evas_object_smart_callback_call(item->wd->self, SIG_LONGPRESSED, item);
802 if (item->wd->reorder_mode)
804 item->wd->reorder_item = item;
805 evas_object_raise(item->base.view);
806 elm_smart_scroller_hold_set(item->wd->scr, EINA_TRUE);
807 elm_smart_scroller_bounce_allow_set(item->wd->scr, EINA_FALSE, EINA_FALSE);
808 edje_object_signal_emit(item->base.view, "elm,state,reorder,enabled", "elm");
810 return ECORE_CALLBACK_CANCEL;
814 _mouse_down(void *data,
815 Evas *evas __UNUSED__,
819 Elm_Gengrid_Item *item = data;
820 Evas_Event_Mouse_Down *ev = event_info;
823 if (ev->button != 1) return;
826 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
827 item->dx = ev->canvas.x - x;
828 item->dy = ev->canvas.y - y;
829 item->wd->longpressed = EINA_FALSE;
830 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
831 else item->wd->on_hold = EINA_FALSE;
832 item->wd->wasselected = item->selected;
833 _item_highlight(item);
834 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
836 evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
837 evas_object_smart_callback_call(item->wd->self, SIG_ACTIVATED, item);
839 if (item->long_timer) ecore_timer_del(item->long_timer);
841 item->long_timer = ecore_timer_add(_elm_config->longpress_timeout,
844 item->long_timer = NULL;
848 _mouse_up(void *data,
849 Evas *evas __UNUSED__,
850 Evas_Object *obj __UNUSED__,
853 Elm_Gengrid_Item *item = data;
854 Evas_Event_Mouse_Up *ev = event_info;
855 Eina_Bool dragged = EINA_FALSE;
857 if (ev->button != 1) return;
858 item->down = EINA_FALSE;
859 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
860 else item->wd->on_hold = EINA_FALSE;
861 if (item->long_timer)
863 ecore_timer_del(item->long_timer);
864 item->long_timer = NULL;
868 item->dragging = EINA_FALSE;
869 evas_object_smart_callback_call(item->wd->self, SIG_DRAG_STOP, item);
872 if (item->wd->on_hold)
874 item->wd->longpressed = EINA_FALSE;
875 item->wd->on_hold = EINA_FALSE;
878 if ((item->wd->reorder_mode) && (item->wd->reorder_item))
880 evas_object_smart_callback_call(item->wd->self, SIG_MOVED, item->wd->reorder_item);
881 item->wd->reorder_item = NULL;
882 item->wd->move_effect_enabled = EINA_FALSE;
883 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
884 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
886 elm_smart_scroller_hold_set(item->wd->scr, EINA_FALSE);
887 elm_smart_scroller_bounce_allow_set(item->wd->scr, item->wd->h_bounce, item->wd->v_bounce);
888 edje_object_signal_emit(item->base.view, "elm,state,reorder,disabled", "elm");
890 if (item->wd->longpressed)
892 item->wd->longpressed = EINA_FALSE;
893 if (!item->wd->wasselected) _item_unselect(item);
894 item->wd->wasselected = EINA_FALSE;
899 if (item->want_unrealize) _item_unrealize(item);
901 if ((item->disabled) || (dragged)) return;
906 _item_highlight(item);
909 else _item_unselect(item);
915 while (item->wd->selected)
916 _item_unselect(item->wd->selected->data);
920 const Eina_List *l, *l_next;
921 Elm_Gengrid_Item *item2;
923 EINA_LIST_FOREACH_SAFE(item->wd->selected, l, l_next, item2)
924 if (item2 != item) _item_unselect(item2);
926 _item_highlight(item);
932 _item_highlight(Elm_Gengrid_Item *item)
934 if ((item->wd->no_select) || (item->delete_me) || (item->highlighted)) return;
935 edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
936 item->highlighted = EINA_TRUE;
940 _item_realize(Elm_Gengrid_Item *item)
945 if ((item->realized) || (item->delete_me)) return;
946 item->base.view = edje_object_add(evas_object_evas_get(item->wd->self));
947 edje_object_scale_set(item->base.view, elm_widget_scale_get(item->wd->self) *
949 edje_object_mirrored_set(item->base.view, elm_widget_mirrored_get(item->base.widget));
950 evas_object_smart_member_add(item->base.view, item->wd->pan_smart);
951 elm_widget_sub_object_add(item->wd->self, item->base.view);
952 snprintf(style, sizeof(style), "item/%s",
953 item->gic->item_style ? item->gic->item_style : "default");
954 _elm_theme_object_set(item->wd->self, item->base.view, "gengrid", style,
955 elm_widget_style_get(item->wd->self));
957 evas_object_rectangle_add(evas_object_evas_get(item->wd->self));
958 evas_object_color_set(item->spacer, 0, 0, 0, 0);
959 elm_widget_sub_object_add(item->wd->self, item->spacer);
960 evas_object_size_hint_min_set(item->spacer, 2 * _elm_config->scale, 1);
961 edje_object_part_swallow(item->base.view, "elm.swallow.pad", item->spacer);
963 if (item->gic->func.label_get)
969 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
971 EINA_LIST_FOREACH(item->labels, l, key)
973 char *s = item->gic->func.label_get
974 ((void *)item->base.data, item->wd->self, l->data);
977 edje_object_part_text_set(item->base.view, l->data, s);
983 if (item->gic->func.icon_get)
989 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
991 EINA_LIST_FOREACH(item->icons, l, key)
993 Evas_Object *ic = item->gic->func.icon_get
994 ((void *)item->base.data, item->wd->self, l->data);
997 item->icon_objs = eina_list_append(item->icon_objs, ic);
998 edje_object_part_swallow(item->base.view, key, ic);
999 evas_object_show(ic);
1000 elm_widget_sub_object_add(item->wd->self, ic);
1005 if (item->gic->func.state_get)
1011 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
1013 EINA_LIST_FOREACH(item->states, l, key)
1015 Eina_Bool on = item->gic->func.state_get
1016 ((void *)item->base.data, item->wd->self, l->data);
1019 snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1020 edje_object_signal_emit(item->base.view, buf, "elm");
1027 if ((!item->wd->group_item_width) && (!item->wd->group_item_height))
1029 edje_object_size_min_restricted_calc(item->base.view,
1030 &item->wd->group_item_width,
1031 &item->wd->group_item_height,
1032 item->wd->group_item_width,
1033 item->wd->group_item_height);
1038 if ((!item->wd->item_width) && (!item->wd->item_height))
1040 edje_object_size_min_restricted_calc(item->base.view,
1041 &item->wd->item_width,
1042 &item->wd->item_height,
1043 item->wd->item_width,
1044 item->wd->item_height);
1045 elm_coords_finger_size_adjust(1, &item->wd->item_width,
1046 1, &item->wd->item_height);
1049 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_DOWN,
1051 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_UP,
1053 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_MOVE,
1057 edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
1059 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1061 evas_object_show(item->base.view);
1063 if (item->tooltip.content_cb)
1065 elm_widget_item_tooltip_content_cb_set(item,
1066 item->tooltip.content_cb,
1067 item->tooltip.data, NULL);
1068 elm_widget_item_tooltip_style_set(item, item->tooltip.style);
1069 elm_widget_item_tooltip_size_restrict_disable(item, item->tooltip.free_size);
1072 if (item->mouse_cursor)
1073 elm_widget_item_cursor_set(item, item->mouse_cursor);
1075 item->realized = EINA_TRUE;
1076 item->want_unrealize = EINA_FALSE;
1080 _item_unrealize(Elm_Gengrid_Item *item)
1084 if (!item->realized) return;
1085 if (item->long_timer)
1087 ecore_timer_del(item->long_timer);
1088 item->long_timer = NULL;
1090 evas_object_del(item->base.view);
1091 item->base.view = NULL;
1092 evas_object_del(item->spacer);
1093 item->spacer = NULL;
1094 elm_widget_stringlist_free(item->labels);
1095 item->labels = NULL;
1096 elm_widget_stringlist_free(item->icons);
1098 elm_widget_stringlist_free(item->states);
1099 item->states = NULL;
1101 EINA_LIST_FREE(item->icon_objs, icon)
1102 evas_object_del(icon);
1104 item->realized = EINA_FALSE;
1105 item->want_unrealize = EINA_FALSE;
1109 _reorder_item_moving_effect_timer_cb(void *data)
1111 Elm_Gengrid_Item *item = data;
1115 time = REORDER_EFFECT_TIME;
1116 t = ((0.0 > (t = ecore_loop_time_get()-item->moving_effect_start_time)) ? 0.0 : t);
1117 dx = ((item->tx - item->ox) / 10) * _elm_config->scale;
1118 dy = ((item->ty - item->oy) / 10) * _elm_config->scale;
1122 item->rx += (1 * sin((t / time) * (M_PI / 2)) * dx);
1123 item->ry += (1 * sin((t / time) * (M_PI / 2)) * dy);
1131 if ((((dx > 0) && (item->rx >= item->tx)) || ((dx <= 0) && (item->rx <= item->tx))) &&
1132 (((dy > 0) && (item->ry >= item->ty)) || ((dy <= 0) && (item->ry <= item->ty))))
1134 evas_object_move(item->base.view, item->tx, item->ty);
1138 evas_object_geometry_get(item->wd->pan_smart, NULL, NULL, &vw, &vh);
1139 if (item->wd->horizontal)
1140 evas_object_resize(item->base.view, item->wd->group_item_width, vh);
1142 evas_object_resize(item->base.view, vw, item->wd->group_item_height);
1145 evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
1146 item->moving = EINA_FALSE;
1147 item->item_moving_effect_timer = NULL;
1148 return ECORE_CALLBACK_CANCEL;
1151 evas_object_move(item->base.view, item->rx, item->ry);
1155 evas_object_geometry_get(item->wd->pan_smart, NULL, NULL, &vw, &vh);
1156 if (item->wd->horizontal)
1157 evas_object_resize(item->base.view, item->wd->group_item_width, vh);
1159 evas_object_resize(item->base.view, vw, item->wd->group_item_height);
1162 evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
1164 return ECORE_CALLBACK_RENEW;
1168 _group_item_place(Pan *sd)
1170 Evas_Coord iw, ih, vw, vh;
1172 Eina_Bool was_realized;
1173 Elm_Gengrid_Item *it;
1174 evas_object_geometry_get(sd->wd->pan_smart, NULL, NULL, &vw, &vh);
1175 if (sd->wd->horizontal)
1177 iw = sd->wd->group_item_width;
1183 ih = sd->wd->group_item_height;
1185 EINA_LIST_FOREACH(sd->wd->group_items, l, it)
1187 was_realized = it->realized;
1188 if (it->group_realized)
1192 evas_object_smart_callback_call(it->wd->self, SIG_REALIZED, it);
1193 evas_object_move(it->base.view, it->gx, it->gy);
1194 evas_object_resize(it->base.view, iw, ih);
1195 evas_object_raise(it->base.view);
1199 _item_unrealize(it);
1201 evas_object_smart_callback_call(it->wd->self, SIG_UNREALIZED, it);
1208 _item_place(Elm_Gengrid_Item *item,
1212 Evas_Coord x, y, ox, oy, cvx, cvy, cvw, cvh, iw, ih, ww;
1213 Evas_Coord tch, tcw, alignw = 0, alignh = 0, vw, vh;
1214 Eina_Bool reorder_item_move_forward = EINA_FALSE;
1218 evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &vw, &vh);
1220 /* Preload rows/columns at each side of the Gengrid */
1221 cvx = ox - PRELOAD * item->wd->item_width;
1222 cvy = oy - PRELOAD * item->wd->item_height;
1223 cvw = vw + 2 * PRELOAD * item->wd->item_width;
1224 cvh = vh + 2 * PRELOAD * item->wd->item_height;
1229 items_count = item->wd->count - eina_list_count(item->wd->group_items) + item->wd->items_lost;
1230 if (item->wd->horizontal)
1232 int columns, items_visible = 0, items_row;
1234 if (item->wd->item_height > 0)
1235 items_visible = vh / item->wd->item_height;
1236 if (items_visible < 1)
1239 columns = items_count / items_visible;
1240 if (items_count % items_visible)
1243 tcw = (item->wd->item_width * columns) + (item->wd->group_item_width * eina_list_count(item->wd->group_items));
1244 alignw = (vw - tcw) * item->wd->align_x;
1246 items_row = items_visible;
1247 if (items_row > item->wd->count)
1248 items_row = item->wd->count;
1249 tch = items_row * item->wd->item_height;
1250 alignh = (vh - tch) * item->wd->align_y;
1254 int rows, items_visible = 0, items_col;
1256 if (item->wd->item_width > 0)
1257 items_visible = vw / item->wd->item_width;
1258 if (items_visible < 1)
1261 rows = items_count / items_visible;
1262 if (items_count % items_visible)
1265 tch = (item->wd->item_height * rows) + (item->wd->group_item_height * eina_list_count(item->wd->group_items));
1266 alignh = (vh - tch) * item->wd->align_y;
1268 items_col = items_visible;
1269 if (items_col > item->wd->count)
1270 items_col = item->wd->count;
1271 tcw = items_col * item->wd->item_width;
1272 alignw = (vw - tcw) * item->wd->align_x;
1277 if (item->wd->horizontal)
1279 x = (((cx - item->prev_group) * item->wd->item_width) + (item->prev_group * item->wd->group_item_width)) - item->wd->pan_x + ox + alignw;
1281 iw = item->wd->group_item_width;
1287 y = (((cy - item->prev_group) * item->wd->item_height) + (item->prev_group * item->wd->group_item_height)) - item->wd->pan_y + oy + alignh;
1289 ih = item->wd->group_item_height;
1296 if (item->wd->horizontal)
1298 x = (((cx - item->prev_group) * item->wd->item_width) + (item->prev_group * item->wd->group_item_width)) - item->wd->pan_x + ox + alignw;
1299 y = (cy * item->wd->item_height) - item->wd->pan_y + oy + alignh;
1303 x = (cx * item->wd->item_height) - item->wd->pan_x + ox + alignw;
1304 y = (((cy - item->prev_group) * item->wd->item_height) + (item->prev_group * item->wd->group_item_height)) - item->wd->pan_y + oy + alignh;
1306 if (elm_widget_mirrored_get(item->wd->self))
1307 { /* Switch items side and componsate for pan_x when in RTL mode */
1308 evas_object_geometry_get(item->wd->self, NULL, NULL, &ww, NULL);
1309 x = ww - x - item->wd->item_width - item->wd->pan_x - item->wd->pan_x;
1311 iw = item->wd->item_width;
1312 ih = item->wd->item_height;
1315 Eina_Bool was_realized = item->realized;
1316 if (ELM_RECTS_INTERSECT(x, y, iw, ih, cvx, cvy, cvw, cvh))
1318 _item_realize(item);
1320 evas_object_smart_callback_call(item->wd->self, SIG_REALIZED, item);
1321 if (item->parent_group_item)
1323 if (item->wd->horizontal)
1325 if (item->parent_group_item->gx < 0)
1327 item->parent_group_item->gx = x + item->wd->item_width - item->wd->group_item_width;
1328 if (item->parent_group_item->gx > 0)
1329 item->parent_group_item->gx = 0;
1334 if (item->parent_group_item->gy < 0)
1336 item->parent_group_item->gy = y + item->wd->item_height - item->wd->group_item_height;
1337 if (item->parent_group_item->gy > 0)
1338 item->parent_group_item->gy = 0;
1340 item->parent_group_item->group_realized = EINA_TRUE;
1343 if (item->wd->reorder_mode)
1345 if (item->wd->reorder_item)
1347 if (item->moving) return;
1349 if (!item->wd->move_effect_enabled)
1354 if (item->wd->reorder_item == item)
1356 evas_object_move(item->base.view,
1357 item->wd->reorder_item_x, item->wd->reorder_item_y);
1358 evas_object_resize(item->base.view, iw, ih);
1363 if (item->wd->move_effect_enabled)
1365 if ((item->ox != x) || (item->oy != y))
1367 if (((item->wd->old_pan_x == item->wd->pan_x) && (item->wd->old_pan_y == item->wd->pan_y)) ||
1368 ((item->wd->old_pan_x != item->wd->pan_x) && !(item->ox - item->wd->pan_x + item->wd->old_pan_x == x)) ||
1369 ((item->wd->old_pan_y != item->wd->pan_y) && !(item->oy - item->wd->pan_y + item->wd->old_pan_y == y)))
1373 item->rx = item->ox;
1374 item->ry = item->oy;
1375 item->moving = EINA_TRUE;
1376 item->moving_effect_start_time = ecore_loop_time_get();
1377 item->item_moving_effect_timer = ecore_animator_add(_reorder_item_moving_effect_timer_cb, item);
1384 Evas_Coord nx, ny, nw, nh;
1387 if (item->wd->horizontal)
1389 nx = x + (item->wd->group_item_width / 2);
1397 ny = y + (item->wd->group_item_height / 2);
1404 nx = x + (item->wd->item_width / 2);
1405 ny = y + (item->wd->item_height / 2);
1410 if ( ELM_RECTS_INTERSECT(item->wd->reorder_item_x, item->wd->reorder_item_y,
1411 item->wd->item_width, item->wd->item_height,
1414 if (item->wd->horizontal)
1416 if ((item->wd->nmax * item->wd->reorder_item->x + item->wd->reorder_item->y) >
1417 (item->wd->nmax * item->x + item->y))
1418 reorder_item_move_forward = EINA_TRUE;
1422 if ((item->wd->nmax * item->wd->reorder_item->y + item->wd->reorder_item->x) >
1423 (item->wd->nmax * item->y + item->x))
1424 reorder_item_move_forward = EINA_TRUE;
1427 item->wd->items = eina_inlist_remove(item->wd->items,
1428 EINA_INLIST_GET(item->wd->reorder_item));
1429 if (reorder_item_move_forward)
1430 item->wd->items = eina_inlist_prepend_relative(item->wd->items,
1431 EINA_INLIST_GET(item->wd->reorder_item),
1432 EINA_INLIST_GET(item));
1434 item->wd->items = eina_inlist_append_relative(item->wd->items,
1435 EINA_INLIST_GET(item->wd->reorder_item),
1436 EINA_INLIST_GET(item));
1438 item->wd->reorder_item_changed = EINA_TRUE;
1439 item->wd->move_effect_enabled = EINA_TRUE;
1440 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1441 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1447 else if (item->item_moving_effect_timer)
1449 ecore_animator_del(item->item_moving_effect_timer);
1450 item->item_moving_effect_timer = NULL;
1451 item->moving = EINA_FALSE;
1454 if (!item->is_group)
1456 evas_object_move(item->base.view, x, y);
1457 evas_object_resize(item->base.view, iw, ih);
1460 item->group_realized = EINA_TRUE;
1464 if (!item->is_group)
1466 _item_unrealize(item);
1468 evas_object_smart_callback_call(item->wd->self, SIG_UNREALIZED, item);
1471 item->group_realized = EINA_FALSE;
1476 _item_label_hook(Elm_Gengrid_Item *it, const char *part)
1478 if (!it->gic->func.label_get) return NULL;
1479 return edje_object_part_text_get(it->base.view, part);
1482 static Elm_Gengrid_Item *
1483 _item_create(Widget_Data *wd,
1484 const Elm_Gengrid_Item_Class *gic,
1487 const void *func_data)
1489 Elm_Gengrid_Item *item;
1491 item = elm_widget_item_new(wd->self, Elm_Gengrid_Item);
1492 if (!item) return NULL;
1496 item->base.data = data;
1497 item->func.func = func;
1498 item->func.data = func_data;
1499 item->mouse_cursor = NULL;
1500 item->is_group = !strcmp(item->gic->item_style, "group_index");
1501 elm_widget_item_text_get_hook_set(item, _item_label_hook);
1507 _item_del(Elm_Gengrid_Item *item)
1509 elm_widget_item_pre_notify_del(item);
1511 item->wd->selected = eina_list_remove(item->wd->selected, item);
1512 if (item->realized) _item_unrealize(item);
1513 if ((!item->delete_me) && (item->gic->func.del))
1514 item->gic->func.del((void *)item->base.data, item->wd->self);
1515 item->delete_me = EINA_TRUE;
1516 item->wd->items = eina_inlist_remove(item->wd->items, EINA_INLIST_GET(item));
1517 if (item->long_timer) ecore_timer_del(item->long_timer);
1518 if (item->tooltip.del_cb)
1519 item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
1520 item->wd->walking -= item->walking;
1523 item->wd->group_items = eina_list_remove(item->wd->group_items, item);
1524 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1525 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1526 elm_widget_item_del(item);
1530 _item_select(Elm_Gengrid_Item *item)
1532 if ((item->wd->no_select) || (item->delete_me)) return;
1535 if (item->wd->always_select) goto call;
1538 item->selected = EINA_TRUE;
1539 item->wd->selected = eina_list_append(item->wd->selected, item);
1542 item->wd->walking++;
1543 if (item->func.func)
1544 item->func.func((void *)item->func.data, item->wd->self, item);
1545 if (!item->delete_me)
1546 evas_object_smart_callback_call(item->wd->self, SIG_SELECTED, item);
1548 item->wd->walking--;
1549 item->wd->last_selected_item = item;
1550 if ((item->wd->clear_me) && (!item->wd->walking))
1551 elm_gengrid_clear(item->base.widget);
1554 if ((!item->walking) && (item->delete_me))
1555 if (!item->relcount) _item_del(item);
1560 _item_unselect(Elm_Gengrid_Item *item)
1562 if ((item->delete_me) || (!item->highlighted)) return;
1563 edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
1564 item->highlighted = EINA_FALSE;
1567 item->selected = EINA_FALSE;
1568 item->wd->selected = eina_list_remove(item->wd->selected, item);
1569 evas_object_smart_callback_call(item->wd->self, SIG_UNSELECTED, item);
1574 _calc_job(void *data)
1576 Widget_Data *wd = data;
1577 Evas_Coord minw = 0, minh = 0, nmax = 0, cvw, cvh;
1578 Elm_Gengrid_Item *item, *group_item = NULL;
1579 int count_group = 0;
1583 evas_object_geometry_get(wd->pan_smart, NULL, NULL, &cvw, &cvh);
1584 if ((cvw != 0) || (cvh != 0))
1586 if ((wd->horizontal) && (wd->item_height > 0))
1587 nmax = cvh / wd->item_height;
1588 else if (wd->item_width > 0)
1589 nmax = cvw / wd->item_width;
1594 EINA_INLIST_FOREACH(wd->items, item)
1596 if (item->prev_group != count_group)
1597 item->prev_group = count_group;
1600 count = count % nmax;
1602 wd->items_lost += nmax - count;
1603 //printf("%d items and I lost %d\n", count, wd->items_lost);
1605 if (count) count = 0;
1610 if (item->parent_group_item != group_item)
1611 item->parent_group_item = group_item;
1615 count = wd->count + wd->items_lost - count_group;
1618 minw = (ceil(count / (float)nmax) * wd->item_width) + (count_group * wd->group_item_height);
1619 minh = nmax * wd->item_height;
1623 minw = nmax * wd->item_width;
1624 minh = (ceil(count / (float)nmax) * wd->item_height) + (count_group * wd->group_item_height);
1627 if ((minw != wd->minw) || (minh != wd->minh))
1631 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1635 evas_object_smart_changed(wd->pan_smart);
1637 wd->calc_job = NULL;
1641 _pan_add(Evas_Object *obj)
1644 Evas_Object_Smart_Clipped_Data *cd;
1647 cd = evas_object_smart_data_get(obj);
1650 sd->__clipped_data = *cd;
1652 evas_object_smart_data_set(obj, sd);
1656 _pan_del(Evas_Object *obj)
1658 Pan *sd = evas_object_smart_data_get(obj);
1665 _pan_set(Evas_Object *obj,
1669 Pan *sd = evas_object_smart_data_get(obj);
1670 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1673 evas_object_smart_changed(obj);
1677 _pan_get(Evas_Object *obj,
1681 Pan *sd = evas_object_smart_data_get(obj);
1682 if (x) *x = sd->wd->pan_x;
1683 if (y) *y = sd->wd->pan_y;
1687 _pan_child_size_get(Evas_Object *obj,
1691 Pan *sd = evas_object_smart_data_get(obj);
1692 if (w) *w = sd->wd->minw;
1693 if (h) *h = sd->wd->minh;
1697 _pan_max_get(Evas_Object *obj,
1701 Pan *sd = evas_object_smart_data_get(obj);
1705 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1707 *x = (ow < sd->wd->minw) ? sd->wd->minw - ow : 0;
1709 *y = (oh < sd->wd->minh) ? sd->wd->minh - oh : 0;
1713 _pan_min_get(Evas_Object *obj,
1717 Pan *sd = evas_object_smart_data_get(obj);
1721 _pan_max_get(obj, &mx, &my);
1723 *x = -mx * sd->wd->align_x;
1725 *y = -my * sd->wd->align_y;
1729 _pan_resize(Evas_Object *obj,
1733 Pan *sd = evas_object_smart_data_get(obj);
1736 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1737 if ((ow == w) && (oh == h)) return;
1738 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1739 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1743 _pan_calculate(Evas_Object *obj)
1745 Pan *sd = evas_object_smart_data_get(obj);
1746 Evas_Coord cx = 0, cy = 0;
1747 Elm_Gengrid_Item *item;
1750 if (!sd->wd->nmax) return;
1752 sd->wd->reorder_item_changed = EINA_FALSE;
1754 EINA_INLIST_FOREACH(sd->wd->items, item)
1758 if (sd->wd->horizontal)
1775 _item_place(item, cx, cy);
1776 if (sd->wd->reorder_item_changed) return;
1779 if (sd->wd->horizontal)
1792 if (sd->wd->horizontal)
1794 cy = (cy + 1) % sd->wd->nmax;
1799 cx = (cx + 1) % sd->wd->nmax;
1804 _group_item_place(sd);
1807 if ((sd->wd->reorder_mode) && (sd->wd->reorder_item))
1809 if (!sd->wd->reorder_item_changed)
1811 sd->wd->old_pan_x = sd->wd->pan_x;
1812 sd->wd->old_pan_y = sd->wd->pan_y;
1814 sd->wd->move_effect_enabled = EINA_FALSE;
1816 evas_object_smart_callback_call(sd->wd->self, SIG_CHANGED, NULL);
1820 _pan_move(Evas_Object *obj,
1821 Evas_Coord x __UNUSED__,
1822 Evas_Coord y __UNUSED__)
1824 Pan *sd = evas_object_smart_data_get(obj);
1826 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1827 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1831 _hold_on(void *data __UNUSED__,
1833 void *event_info __UNUSED__)
1835 Widget_Data *wd = elm_widget_data_get(obj);
1837 elm_smart_scroller_hold_set(wd->scr, 1);
1841 _hold_off(void *data __UNUSED__,
1843 void *event_info __UNUSED__)
1845 Widget_Data *wd = elm_widget_data_get(obj);
1847 elm_smart_scroller_hold_set(wd->scr, 0);
1851 _freeze_on(void *data __UNUSED__,
1853 void *event_info __UNUSED__)
1855 Widget_Data *wd = elm_widget_data_get(obj);
1857 elm_smart_scroller_freeze_set(wd->scr, 1);
1861 _freeze_off(void *data __UNUSED__,
1863 void *event_info __UNUSED__)
1865 Widget_Data *wd = elm_widget_data_get(obj);
1867 elm_smart_scroller_freeze_set(wd->scr, 0);
1871 _scr_anim_start(void *data,
1872 Evas_Object *obj __UNUSED__,
1873 void *event_info __UNUSED__)
1875 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
1879 _scr_anim_stop(void *data,
1880 Evas_Object *obj __UNUSED__,
1881 void *event_info __UNUSED__)
1883 evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
1887 _scr_drag_start(void *data,
1888 Evas_Object *obj __UNUSED__,
1889 void *event_info __UNUSED__)
1891 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1895 _scr_drag_stop(void *data,
1896 Evas_Object *obj __UNUSED__,
1897 void *event_info __UNUSED__)
1899 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1903 _scr_edge_left(void *data,
1904 Evas_Object *scr __UNUSED__,
1905 void *event_info __UNUSED__)
1907 evas_object_smart_callback_call(data, SIG_SCROLL_EDGE_LEFT, NULL);
1911 _scr_edge_right(void *data,
1912 Evas_Object *scr __UNUSED__,
1913 void *event_info __UNUSED__)
1915 evas_object_smart_callback_call(data, SIG_SCROLL_EDGE_RIGHT, NULL);
1919 _scr_edge_top(void *data,
1920 Evas_Object *scr __UNUSED__,
1921 void *event_info __UNUSED__)
1923 evas_object_smart_callback_call(data, SIG_SCROLL_EDGE_TOP, NULL);
1927 _scr_edge_bottom(void *data,
1928 Evas_Object *scr __UNUSED__,
1929 void *event_info __UNUSED__)
1931 evas_object_smart_callback_call(data, SIG_SCROLL_EDGE_BOTTOM, NULL);
1935 _scr_scroll(void *data,
1936 Evas_Object *obj __UNUSED__,
1937 void *event_info __UNUSED__)
1939 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1943 _elm_gengrid_item_compare_data(const void *data, const void *data1)
1945 const Elm_Gengrid_Item *item = data;
1946 const Elm_Gengrid_Item *item1 = data1;
1948 return _elm_gengrid_item_compare_data_cb(item->base.data, item1->base.data);
1952 _elm_gengrid_item_compare(const void *data, const void *data1)
1954 Elm_Gengrid_Item *item, *item1;
1955 item = ELM_GENGRID_ITEM_FROM_INLIST(data);
1956 item1 = ELM_GENGRID_ITEM_FROM_INLIST(data1);
1957 return _elm_gengrid_item_compare_cb(item, item1);
1961 elm_gengrid_add(Evas_Object *parent)
1966 static Evas_Smart *smart = NULL;
1967 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1969 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1971 ELM_SET_WIDTYPE(widtype, "gengrid");
1972 elm_widget_type_set(obj, "gengrid");
1973 elm_widget_sub_object_add(parent, obj);
1974 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1975 elm_widget_data_set(obj, wd);
1976 elm_widget_del_hook_set(obj, _del_hook);
1977 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1978 elm_widget_theme_hook_set(obj, _theme_hook);
1979 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1980 elm_widget_can_focus_set(obj, EINA_TRUE);
1981 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1982 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1983 elm_widget_event_hook_set(obj, _event_hook);
1985 wd->scr = elm_smart_scroller_add(e);
1986 elm_smart_scroller_widget_set(wd->scr, obj);
1987 elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
1989 elm_widget_resize_object_set(obj, wd->scr);
1991 evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1992 evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1993 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1994 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1995 evas_object_smart_callback_add(wd->scr, "edge,left", _scr_edge_left, obj);
1996 evas_object_smart_callback_add(wd->scr, "edge,right", _scr_edge_right, obj);
1997 evas_object_smart_callback_add(wd->scr, "edge,top", _scr_edge_top, obj);
1998 evas_object_smart_callback_add(wd->scr, "edge,bottom", _scr_edge_bottom,
2000 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
2002 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
2007 wd->h_bounce = bounce;
2008 wd->v_bounce = bounce;
2009 wd->no_select = EINA_FALSE;
2011 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
2012 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
2013 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
2014 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
2016 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2020 static Evas_Smart_Class sc;
2022 evas_object_smart_clipped_smart_set(&_pan_sc);
2024 sc.name = "elm_gengrid_pan";
2025 sc.version = EVAS_SMART_CLASS_VERSION;
2028 sc.resize = _pan_resize;
2029 sc.move = _pan_move;
2030 sc.calculate = _pan_calculate;
2031 smart = evas_smart_class_new(&sc);
2035 wd->pan_smart = evas_object_smart_add(e, smart);
2036 wd->pan = evas_object_smart_data_get(wd->pan_smart);
2040 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
2041 _pan_set, _pan_get, _pan_max_get,
2042 _pan_min_get, _pan_child_size_get);
2044 _mirrored_set(obj, elm_widget_mirrored_get(obj));
2049 elm_gengrid_item_size_set(Evas_Object *obj,
2053 ELM_CHECK_WIDTYPE(obj, widtype);
2054 Widget_Data *wd = elm_widget_data_get(obj);
2056 if ((wd->item_width == w) && (wd->item_height == h)) return;
2058 wd->item_height = h;
2059 if (wd->calc_job) ecore_job_del(wd->calc_job);
2060 wd->calc_job = ecore_job_add(_calc_job, wd);
2064 elm_gengrid_item_size_get(const Evas_Object *obj,
2068 ELM_CHECK_WIDTYPE(obj, widtype);
2069 Widget_Data *wd = elm_widget_data_get(obj);
2071 if (w) *w = wd->item_width;
2072 if (h) *h = wd->item_height;
2076 elm_gengrid_group_item_size_set(Evas_Object *obj,
2080 ELM_CHECK_WIDTYPE(obj, widtype);
2081 Widget_Data *wd = elm_widget_data_get(obj);
2083 if ((wd->group_item_width == w) && (wd->group_item_height == h)) return;
2084 wd->group_item_width = w;
2085 wd->group_item_height = h;
2086 if (wd->calc_job) ecore_job_del(wd->calc_job);
2087 wd->calc_job = ecore_job_add(_calc_job, wd);
2091 elm_gengrid_group_item_size_get(const Evas_Object *obj,
2095 ELM_CHECK_WIDTYPE(obj, widtype);
2096 Widget_Data *wd = elm_widget_data_get(obj);
2098 if (w) *w = wd->group_item_width;
2099 if (h) *h = wd->group_item_height;
2103 elm_gengrid_align_set(Evas_Object *obj,
2107 ELM_CHECK_WIDTYPE(obj, widtype);
2109 Widget_Data *wd = elm_widget_data_get(obj);
2110 double old_h = wd->align_x, old_y = wd->align_y;
2114 else if (align_x < 0.0)
2116 wd->align_x = align_x;
2120 else if (align_y < 0.0)
2122 wd->align_y = align_y;
2124 if ((old_h != wd->align_x) || (old_y != wd->align_y))
2125 evas_object_smart_calculate(wd->pan_smart);
2129 elm_gengrid_align_get(const Evas_Object *obj,
2133 ELM_CHECK_WIDTYPE(obj, widtype);
2134 Widget_Data *wd = elm_widget_data_get(obj);
2135 if (align_x) *align_x = wd->align_x;
2136 if (align_y) *align_y = wd->align_y;
2139 EAPI Elm_Gengrid_Item *
2140 elm_gengrid_item_append(Evas_Object *obj,
2141 const Elm_Gengrid_Item_Class *gic,
2144 const void *func_data)
2146 Elm_Gengrid_Item *item;
2147 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2148 Widget_Data *wd = elm_widget_data_get(obj);
2149 if (!wd) return NULL;
2151 item = _item_create(wd, gic, data, func, func_data);
2152 if (!item) return NULL;
2153 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(item));
2156 wd->group_items = eina_list_prepend(wd->group_items, item);
2158 if (wd->calc_job) ecore_job_del(wd->calc_job);
2159 wd->calc_job = ecore_job_add(_calc_job, wd);
2164 EAPI Elm_Gengrid_Item *
2165 elm_gengrid_item_prepend(Evas_Object *obj,
2166 const Elm_Gengrid_Item_Class *gic,
2169 const void *func_data)
2171 Elm_Gengrid_Item *item;
2172 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2173 Widget_Data *wd = elm_widget_data_get(obj);
2174 if (!wd) return NULL;
2176 item = _item_create(wd, gic, data, func, func_data);
2177 if (!item) return NULL;
2178 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(item));
2180 wd->group_items = eina_list_append(wd->group_items, item);
2182 if (wd->calc_job) ecore_job_del(wd->calc_job);
2183 wd->calc_job = ecore_job_add(_calc_job, wd);
2188 EAPI Elm_Gengrid_Item *
2189 elm_gengrid_item_insert_before(Evas_Object *obj,
2190 const Elm_Gengrid_Item_Class *gic,
2192 Elm_Gengrid_Item *relative,
2194 const void *func_data)
2196 Elm_Gengrid_Item *item;
2197 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2198 EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
2199 Widget_Data *wd = elm_widget_data_get(obj);
2200 if (!wd) return NULL;
2202 item = _item_create(wd, gic, data, func, func_data);
2203 if (!item) return NULL;
2204 wd->items = eina_inlist_prepend_relative
2205 (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
2207 wd->group_items = eina_list_append_relative(wd->group_items, item, relative->parent_group_item);
2209 if (wd->calc_job) ecore_job_del(wd->calc_job);
2210 wd->calc_job = ecore_job_add(_calc_job, wd);
2215 EAPI Elm_Gengrid_Item *
2216 elm_gengrid_item_insert_after(Evas_Object *obj,
2217 const Elm_Gengrid_Item_Class *gic,
2219 Elm_Gengrid_Item *relative,
2221 const void *func_data)
2223 Elm_Gengrid_Item *item;
2224 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2225 EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
2226 Widget_Data *wd = elm_widget_data_get(obj);
2227 if (!wd) return NULL;
2229 item = _item_create(wd, gic, data, func, func_data);
2230 if (!item) return NULL;
2231 wd->items = eina_inlist_append_relative
2232 (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
2234 wd->group_items = eina_list_prepend_relative(wd->group_items, item, relative->parent_group_item);
2236 if (wd->calc_job) ecore_job_del(wd->calc_job);
2237 wd->calc_job = ecore_job_add(_calc_job, wd);
2242 EAPI Elm_Gengrid_Item *
2243 elm_gengrid_item_direct_sorted_insert(Evas_Object *obj,
2244 const Elm_Gengrid_Item_Class *gic,
2246 Eina_Compare_Cb comp,
2248 const void *func_data)
2250 Elm_Gengrid_Item *item;
2251 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2252 Widget_Data *wd = elm_widget_data_get(obj);
2253 if (!wd) return NULL;
2255 item = _item_create(wd, gic, data, func, func_data);
2256 if (!item) return NULL;
2259 wd->state = eina_inlist_sorted_state_new();
2261 _elm_gengrid_item_compare_cb = comp;
2262 wd->items = eina_inlist_sorted_state_insert(wd->items, EINA_INLIST_GET(item),
2263 _elm_gengrid_item_compare, wd->state);
2264 if (wd->calc_job) ecore_job_del(wd->calc_job);
2265 wd->calc_job = ecore_job_add(_calc_job, wd);
2270 EAPI Elm_Gengrid_Item *
2271 elm_gengrid_item_sorted_insert(Evas_Object *obj,
2272 const Elm_Gengrid_Item_Class *gic,
2274 Eina_Compare_Cb comp,
2276 const void *func_data)
2278 _elm_gengrid_item_compare_data_cb = comp;
2280 return elm_gengrid_item_direct_sorted_insert(obj, gic, data, _elm_gengrid_item_compare_data, func, func_data);
2284 elm_gengrid_item_del(Elm_Gengrid_Item *item)
2286 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2287 if ((item->relcount > 0) || (item->walking > 0))
2289 item->delete_me = EINA_TRUE;
2290 elm_widget_item_pre_notify_del(item);
2292 item->wd->selected = eina_list_remove(item->wd->selected, item);
2293 if (item->gic->func.del)
2294 item->gic->func.del((void *)item->base.data, item->wd->self);
2302 elm_gengrid_horizontal_set(Evas_Object *obj,
2305 ELM_CHECK_WIDTYPE(obj, widtype);
2306 Widget_Data *wd = elm_widget_data_get(obj);
2308 if (setting == wd->horizontal) return;
2309 wd->horizontal = setting;
2311 /* Update the items to conform to the new layout */
2312 if (wd->calc_job) ecore_job_del(wd->calc_job);
2313 wd->calc_job = ecore_job_add(_calc_job, wd);
2317 elm_gengrid_horizontal_get(const Evas_Object *obj)
2319 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2320 Widget_Data *wd = elm_widget_data_get(obj);
2321 if (!wd) return EINA_FALSE;
2322 return wd->horizontal;
2326 elm_gengrid_clear(Evas_Object *obj)
2328 ELM_CHECK_WIDTYPE(obj, widtype);
2329 Widget_Data *wd = elm_widget_data_get(obj);
2334 eina_inlist_sorted_state_free(wd->state);
2339 ecore_job_del(wd->calc_job);
2340 wd->calc_job = NULL;
2343 if (wd->walking > 0)
2345 Elm_Gengrid_Item *item;
2347 EINA_INLIST_FOREACH(wd->items, item)
2348 item->delete_me = 1;
2354 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
2356 wd->items = eina_inlist_remove(wd->items, wd->items);
2357 elm_widget_item_pre_notify_del(item);
2358 if (item->realized) _item_unrealize(item);
2359 if (item->gic->func.del)
2360 item->gic->func.del((void *)item->base.data, wd->self);
2361 if (item->long_timer) ecore_timer_del(item->long_timer);
2362 elm_widget_item_del(item);
2367 eina_list_free(wd->selected);
2368 wd->selected = NULL;
2376 evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
2377 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2380 EAPI const Evas_Object *
2381 elm_gengrid_item_object_get(const Elm_Gengrid_Item *item)
2383 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2384 return item->base.view;
2388 elm_gengrid_item_update(Elm_Gengrid_Item *item)
2390 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2391 if (!item->realized) return;
2392 if (item->want_unrealize) return;
2393 _item_unrealize(item);
2394 _item_realize(item);
2395 _item_place(item, item->x, item->y);
2399 elm_gengrid_item_data_get(const Elm_Gengrid_Item *item)
2401 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2402 return elm_widget_item_data_get(item);
2406 elm_gengrid_item_data_set(Elm_Gengrid_Item *item,
2409 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2410 elm_widget_item_data_set(item, data);
2413 EAPI const Elm_Gengrid_Item_Class *
2414 elm_gengrid_item_item_class_get(const Elm_Gengrid_Item *item)
2416 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2417 if (item->delete_me) return NULL;
2422 elm_gengrid_item_item_class_set(Elm_Gengrid_Item *item,
2423 const Elm_Gengrid_Item_Class *gic)
2425 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2426 EINA_SAFETY_ON_NULL_RETURN(gic);
2427 if (item->delete_me) return;
2429 elm_gengrid_item_update(item);
2433 elm_gengrid_item_pos_get(const Elm_Gengrid_Item *item,
2437 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2438 if (x) *x = item->x;
2439 if (y) *y = item->y;
2443 elm_gengrid_multi_select_set(Evas_Object *obj,
2446 ELM_CHECK_WIDTYPE(obj, widtype);
2447 Widget_Data *wd = elm_widget_data_get(obj);
2453 elm_gengrid_multi_select_get(const Evas_Object *obj)
2455 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2456 Widget_Data *wd = elm_widget_data_get(obj);
2457 if (!wd) return EINA_FALSE;
2461 EAPI Elm_Gengrid_Item *
2462 elm_gengrid_selected_item_get(const Evas_Object *obj)
2464 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2465 Widget_Data *wd = elm_widget_data_get(obj);
2466 if (!wd) return NULL;
2467 if (wd->selected) return wd->selected->data;
2471 EAPI const Eina_List *
2472 elm_gengrid_selected_items_get(const Evas_Object *obj)
2474 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2475 Widget_Data *wd = elm_widget_data_get(obj);
2476 if (!wd) return NULL;
2477 return wd->selected;
2481 elm_gengrid_item_selected_set(Elm_Gengrid_Item *item,
2484 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2485 Widget_Data *wd = item->wd;
2487 if (item->delete_me) return;
2488 selected = !!selected;
2489 if (item->selected == selected) return;
2495 while (wd->selected)
2496 _item_unselect(wd->selected->data);
2498 _item_highlight(item);
2502 _item_unselect(item);
2506 elm_gengrid_item_selected_get(const Elm_Gengrid_Item *item)
2508 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2509 return item->selected;
2513 elm_gengrid_item_disabled_set(Elm_Gengrid_Item *item,
2516 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2517 if (item->disabled == disabled) return;
2518 if (item->delete_me) return;
2519 item->disabled = !!disabled;
2523 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
2525 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
2530 elm_gengrid_item_disabled_get(const Elm_Gengrid_Item *item)
2532 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2533 if (item->delete_me) return EINA_FALSE;
2534 return item->disabled;
2537 static Evas_Object *
2538 _elm_gengrid_item_label_create(void *data,
2539 Evas_Object *obj __UNUSED__,
2540 Evas_Object *tooltip,
2541 void *item __UNUSED__)
2543 Evas_Object *label = elm_label_add(tooltip);
2546 elm_object_style_set(label, "tooltip");
2547 elm_object_text_set(label, data);
2552 _elm_gengrid_item_label_del_cb(void *data,
2553 Evas_Object *obj __UNUSED__,
2554 void *event_info __UNUSED__)
2556 eina_stringshare_del(data);
2560 elm_gengrid_item_tooltip_text_set(Elm_Gengrid_Item *item,
2563 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2564 text = eina_stringshare_add(text);
2565 elm_gengrid_item_tooltip_content_cb_set(item, _elm_gengrid_item_label_create,
2567 _elm_gengrid_item_label_del_cb);
2571 elm_gengrid_item_tooltip_content_cb_set(Elm_Gengrid_Item *item,
2572 Elm_Tooltip_Item_Content_Cb func,
2574 Evas_Smart_Cb del_cb)
2576 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
2578 if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
2581 if (item->tooltip.del_cb)
2582 item->tooltip.del_cb((void *)item->tooltip.data,
2583 item->base.widget, item);
2584 item->tooltip.content_cb = func;
2585 item->tooltip.data = data;
2586 item->tooltip.del_cb = del_cb;
2587 if (item->base.view)
2589 elm_widget_item_tooltip_content_cb_set(item,
2590 item->tooltip.content_cb,
2591 item->tooltip.data, NULL);
2592 elm_widget_item_tooltip_style_set(item, item->tooltip.style);
2593 elm_widget_item_tooltip_size_restrict_disable(item, item->tooltip.free_size);
2599 if (del_cb) del_cb((void *)data, NULL, NULL);
2603 elm_gengrid_item_tooltip_unset(Elm_Gengrid_Item *item)
2605 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2606 if ((item->base.view) && (item->tooltip.content_cb))
2607 elm_widget_item_tooltip_unset(item);
2609 if (item->tooltip.del_cb)
2610 item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
2611 item->tooltip.del_cb = NULL;
2612 item->tooltip.content_cb = NULL;
2613 item->tooltip.data = NULL;
2614 item->tooltip.free_size = EINA_FALSE;
2615 if (item->tooltip.style)
2616 elm_gengrid_item_tooltip_style_set(item, NULL);
2620 elm_gengrid_item_tooltip_style_set(Elm_Gengrid_Item *item,
2623 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2624 eina_stringshare_replace(&item->tooltip.style, style);
2625 if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
2629 elm_gengrid_item_tooltip_style_get(const Elm_Gengrid_Item *item)
2631 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2632 return item->tooltip.style;
2636 elm_gengrid_item_tooltip_size_restrict_disable(Elm_Gengrid_Item *item, Eina_Bool disable)
2638 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2639 item->tooltip.free_size = disable;
2640 if (item->base.view) return elm_widget_item_tooltip_size_restrict_disable(item, disable);
2645 elm_gengrid_item_tooltip_size_restrict_disabled_get(const Elm_Gengrid_Item *item)
2647 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2648 return item->tooltip.free_size;
2652 elm_gengrid_item_cursor_set(Elm_Gengrid_Item *item,
2655 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2656 eina_stringshare_replace(&item->mouse_cursor, cursor);
2657 if (item->base.view) elm_widget_item_cursor_set(item, cursor);
2661 elm_gengrid_item_cursor_get(const Elm_Gengrid_Item *item)
2663 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2664 return elm_widget_item_cursor_get(item);
2668 elm_gengrid_item_cursor_unset(Elm_Gengrid_Item *item)
2670 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2671 if (!item->mouse_cursor)
2674 if (item->base.view)
2675 elm_widget_item_cursor_unset(item);
2677 eina_stringshare_del(item->mouse_cursor);
2678 item->mouse_cursor = NULL;
2682 elm_gengrid_item_cursor_style_set(Elm_Gengrid_Item *item,
2685 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2686 elm_widget_item_cursor_style_set(item, style);
2690 elm_gengrid_item_cursor_style_get(const Elm_Gengrid_Item *item)
2692 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2693 return elm_widget_item_cursor_style_get(item);
2697 elm_gengrid_item_cursor_engine_only_set(Elm_Gengrid_Item *item,
2698 Eina_Bool engine_only)
2700 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2701 elm_widget_item_cursor_engine_only_set(item, engine_only);
2705 elm_gengrid_item_cursor_engine_only_get(const Elm_Gengrid_Item *item)
2707 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2708 return elm_widget_item_cursor_engine_only_get(item);
2712 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2713 Eina_Bool reorder_mode)
2715 ELM_CHECK_WIDTYPE(obj, widtype);
2716 Widget_Data *wd = elm_widget_data_get(obj);
2718 wd->reorder_mode = reorder_mode;
2722 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
2724 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2725 Widget_Data *wd = elm_widget_data_get(obj);
2726 if (!wd) return EINA_FALSE;
2727 return wd->reorder_mode;
2731 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2732 Eina_Bool always_select)
2734 ELM_CHECK_WIDTYPE(obj, widtype);
2735 Widget_Data *wd = elm_widget_data_get(obj);
2737 wd->always_select = always_select;
2741 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2743 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2744 Widget_Data *wd = elm_widget_data_get(obj);
2745 if (!wd) return EINA_FALSE;
2746 return wd->always_select;
2750 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2751 Eina_Bool no_select)
2753 ELM_CHECK_WIDTYPE(obj, widtype);
2754 Widget_Data *wd = elm_widget_data_get(obj);
2756 wd->no_select = no_select;
2760 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2762 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2763 Widget_Data *wd = elm_widget_data_get(obj);
2764 if (!wd) return EINA_FALSE;
2765 return wd->no_select;
2769 elm_gengrid_bounce_set(Evas_Object *obj,
2773 ELM_CHECK_WIDTYPE(obj, widtype);
2774 Widget_Data *wd = elm_widget_data_get(obj);
2776 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
2777 wd->h_bounce = h_bounce;
2778 wd->v_bounce = v_bounce;
2782 elm_gengrid_bounce_get(const Evas_Object *obj,
2783 Eina_Bool *h_bounce,
2784 Eina_Bool *v_bounce)
2786 ELM_CHECK_WIDTYPE(obj, widtype);
2787 Widget_Data *wd = elm_widget_data_get(obj);
2789 if (h_bounce) *h_bounce = wd->h_bounce;
2790 if (v_bounce) *v_bounce = wd->v_bounce;
2794 elm_gengrid_page_relative_set(Evas_Object *obj,
2798 Evas_Coord pagesize_h;
2799 Evas_Coord pagesize_v;
2801 ELM_CHECK_WIDTYPE(obj, widtype);
2802 Widget_Data *wd = elm_widget_data_get(obj);
2805 elm_smart_scroller_paging_get(wd->scr, NULL, NULL, &pagesize_h, &pagesize_v);
2806 elm_smart_scroller_paging_set(wd->scr, h_pagerel, v_pagerel, pagesize_h,
2811 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
2813 ELM_CHECK_WIDTYPE(obj, widtype);
2814 Widget_Data *wd = elm_widget_data_get(obj);
2817 elm_smart_scroller_paging_get(wd->scr, h_pagerel, v_pagerel, NULL, NULL);
2821 elm_gengrid_page_size_set(Evas_Object *obj,
2822 Evas_Coord h_pagesize,
2823 Evas_Coord v_pagesize)
2828 ELM_CHECK_WIDTYPE(obj, widtype);
2829 Widget_Data *wd = elm_widget_data_get(obj);
2831 elm_smart_scroller_paging_get(wd->scr, &pagerel_h, &pagerel_v, NULL, NULL);
2832 elm_smart_scroller_paging_set(wd->scr, pagerel_h, pagerel_v, h_pagesize,
2837 elm_gengrid_current_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2839 ELM_CHECK_WIDTYPE(obj, widtype);
2840 Widget_Data *wd = elm_widget_data_get(obj);
2843 elm_smart_scroller_current_page_get(wd->scr, h_pagenumber, v_pagenumber);
2847 elm_gengrid_last_page_get(const Evas_Object *obj, int *h_pagenumber, int *v_pagenumber)
2849 ELM_CHECK_WIDTYPE(obj, widtype);
2850 Widget_Data *wd = elm_widget_data_get(obj);
2853 elm_smart_scroller_last_page_get(wd->scr, h_pagenumber, v_pagenumber);
2857 elm_gengrid_page_show(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2859 ELM_CHECK_WIDTYPE(obj, widtype);
2860 Widget_Data *wd = elm_widget_data_get(obj);
2863 elm_smart_scroller_page_show(wd->scr, h_pagenumber, v_pagenumber);
2867 elm_gengrid_page_bring_in(const Evas_Object *obj, int h_pagenumber, int v_pagenumber)
2869 ELM_CHECK_WIDTYPE(obj, widtype);
2870 Widget_Data *wd = elm_widget_data_get(obj);
2873 elm_smart_scroller_page_bring_in(wd->scr, h_pagenumber, v_pagenumber);
2876 EAPI Elm_Gengrid_Item *
2877 elm_gengrid_first_item_get(const Evas_Object *obj)
2879 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2880 Widget_Data *wd = elm_widget_data_get(obj);
2881 if (!wd) return NULL;
2882 if (!wd->items) return NULL;
2883 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
2884 while ((item) && (item->delete_me))
2885 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
2889 EAPI Elm_Gengrid_Item *
2890 elm_gengrid_last_item_get(const Evas_Object *obj)
2892 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2893 Widget_Data *wd = elm_widget_data_get(obj);
2894 if (!wd) return NULL;
2895 if (!wd->items) return NULL;
2896 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
2897 while ((item) && (item->delete_me))
2898 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
2902 EAPI Elm_Gengrid_Item *
2903 elm_gengrid_item_next_get(const Elm_Gengrid_Item *item)
2905 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2908 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
2909 if ((item) && (!item->delete_me)) break;
2911 return (Elm_Gengrid_Item *)item;
2914 EAPI Elm_Gengrid_Item *
2915 elm_gengrid_item_prev_get(const Elm_Gengrid_Item *item)
2917 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2920 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
2921 if ((item) && (!item->delete_me)) break;
2923 return (Elm_Gengrid_Item *)item;
2927 elm_gengrid_item_gengrid_get(const Elm_Gengrid_Item *item)
2929 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2930 return item->base.widget;
2934 elm_gengrid_item_show(Elm_Gengrid_Item *item)
2936 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2937 Widget_Data *wd = elm_widget_data_get(item->wd->self);
2938 Evas_Coord minx = 0, miny = 0;
2941 if ((!item) || (item->delete_me)) return;
2942 _pan_min_get(wd->pan_smart, &minx, &miny);
2945 elm_smart_scroller_region_bring_in(item->wd->scr,
2946 ((item->x - item->prev_group) * wd->item_width) + (item->prev_group * item->wd->group_item_width) + minx,
2947 item->y * wd->item_height + miny,
2948 item->wd->item_width,
2949 item->wd->item_height);
2951 elm_smart_scroller_region_bring_in(item->wd->scr,
2952 item->x * wd->item_width + minx,
2953 ((item->y - item->prev_group)* wd->item_height) + (item->prev_group * item->wd->group_item_height) + miny,
2954 item->wd->item_width,
2955 item->wd->item_height);
2959 elm_gengrid_item_bring_in(Elm_Gengrid_Item *item)
2961 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2962 if (item->delete_me) return;
2964 Evas_Coord minx = 0, miny = 0;
2965 Widget_Data *wd = elm_widget_data_get(item->wd->self);
2967 _pan_min_get(wd->pan_smart, &minx, &miny);
2970 elm_smart_scroller_region_bring_in(item->wd->scr,
2971 ((item->x - item->prev_group) * wd->item_width) + (item->prev_group * item->wd->group_item_width) + minx,
2972 item->y * wd->item_height + miny,
2973 item->wd->item_width,
2974 item->wd->item_height);
2976 elm_smart_scroller_region_bring_in(item->wd->scr,
2977 item->x * wd->item_width + minx,
2978 ((item->y - item->prev_group)* wd->item_height) + (item->prev_group * item->wd->group_item_height) + miny,
2979 item->wd->item_width,
2980 item->wd->item_height);