1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
6 * @defgroup Gengrid Gengrid
8 * This widget aims to position objects in a grid layout while
9 * actually building only the visible ones, using the same idea as
10 * genlist: the user define a class for each item, specifying
11 * functions that will be called at object creation and deletion.
13 * A item in the Gengrid can have 0 or more text labels (they can be
14 * regular text or textblock - that's up to the style to determine), 0
15 * or more icons (which are simply objects swallowed into the Gengrid
16 * item) and 0 or more boolean states that can be used for check,
17 * radio or other indicators by the edje theme style. A item may be
18 * one of several styles (Elementary provides 1 by default -
19 * "default", but this can be extended by system or application custom
20 * themes/overlays/extensions).
22 * In order to implement the ability to add and delete items on the
23 * fly, Gengrid implements a class/callback system where the
24 * application provides a structure with information about that type
25 * of item (Gengrid may contain multiple different items with
26 * different classes, states and styles). Gengrid will call the
27 * functions in this struct (methods) when an item is "realized" (that
28 * is created dynamically while scrolling). All objects will simply be
29 * deleted when no longer needed with evas_object_del(). The
30 * Elm_GenGrid_Item_Class structure contains the following members:
32 * item_style - This is a constant string and simply defines the name
33 * of the item style. It must be specified and the default should be
36 * func.label_get - This function is called when an actual item object
37 * is created. The data parameter is the one passed to
38 * elm_gengrid_item_append() and related item creation functions. The
39 * obj parameter is the Gengrid object and the part parameter is the
40 * string name of the text part in the edje design that is listed as
41 * one of the possible labels that can be set. This function must
42 * return a strdup'()ed string as the caller will free() it when done.
44 * func.icon_get - This function is called when an actual item object
45 * is created. The data parameter is the one passed to
46 * elm_gengrid_item_append() and related item creation functions. The
47 * obj parameter is the Gengrid object and the part parameter is the
48 * string name of the icon part in the edje design that is listed as
49 * one of the possible icons that can be set. This must return NULL
50 * for no object or a valid object. The object will be deleted by
51 * Gengrid on shutdown or when the item is unrealized.
53 * func.state_get - This function is called when an actual item object
54 * is created. The data parameter is the one passed to
55 * elm_gengrid_item_append() and related item creation functions. The
56 * obj parameter is the Gengrid object and the part parameter is the
57 * string name of th state part in the edje design that is listed as
58 * one of the possible states that can be set. Return 0 for false and
59 * 1 for true. Gengrid will emit a signal to the edje object with
60 * "elm,state,XXX,active" "elm" when true (the default is false),
61 * where XXX is the name of the part.
63 * func.del - This is called when elm_gengrid_item_del() is called on
64 * an item or elm_gengrid_clear() is called on the Gengrid. This is
65 * intended for use when actual Gengrid items are deleted, so any
66 * backing data attached to the item (e.g. its data parameter on
67 * creation) can be deleted.
69 * If the application wants multiple items to be able to be selected,
70 * elm_gengrid_multi_select_set() can enable this. If the Gengrid is
71 * single-selection only (the default), then
72 * elm_gengrid_select_item_get() will return the selected item, if
73 * any, or NULL if none is selected. If the Gengrid is multi-select
74 * then elm_gengrid_selected_items_get() will return a list (that is
75 * only valid as long as no items are modified (added, deleted,
76 * selected or unselected).
78 * If an item changes (state of boolean changes, label or icons
79 * change), then use elm_gengrid_item_update() to have Gengrid update
80 * the item with the new state. Gengrid will re-realize the item thus
81 * call the functions in the _Elm_Gengrid_Item_Class for that item.
83 * To programmatically (un)select an item use
84 * elm_gengrid_item_selected_set(). To get its selected state use
85 * elm_gengrid_item_selected_get(). To make an item disabled (unable to
86 * be selected and appear differently) use
87 * elm_gengrid_item_disabled_set() to set this and
88 * elm_gengrid_item_disabled_get() to get the disabled state.
90 * Cells will only call their selection func and callback when first
91 * becoming selected. Any further clicks will do nothing, unless you
92 * enable always select with
93 * elm_gengrid_always_select_mode_set(). This means event if selected,
94 * every click will make the selected callbacks be called.
95 * elm_gengrid_no_select_mode_set() will turn off the ability to
96 * select items entirely and they will neither appear selected nor
97 * call selected callback function.
99 * Remember that you can create new styles and add your own theme
100 * augmentation per application with elm_theme_extension_add(). If you
101 * absolutely must have a specific style that overrides any theme the
102 * user or system sets up you can use elm_theme_overlay_add() to add
105 * Signals that you can add callbacks for are:
107 * "clicked,double" - The user has double-clicked or pressed enter on
108 * an item. The event_infoparameter is the Gengrid item
109 * that was double-clicked.
110 * "selected" - The user has made an item selected. The event_info
111 * parameter is the Gengrid item that was selected.
112 * "unselected" - The user has made an item unselected. The event_info
113 * parameter is the Gengrid item that was unselected.
114 * "realized" - This is called when the item in the Gengrid is created
115 * as a real evas object. event_info is the Gengrid item that was
116 * created. The object may be deleted at any time, so it is up to
117 * the caller to not use the object pointer from
118 * elm_gengrid_item_object_get() in a way where it may point to
120 * "unrealized" - This is called when the real evas object for this item
121 * is deleted. event_info is the Gengrid item that was created.
122 * "changed" - Called when an item is added, removed, resized or moved
123 * and when gengrid is resized or horizontal property changes.
124 * "drag,start,up" - Called when the item in the Gengrid has been
125 * dragged (not scrolled) up.
126 * "drag,start,down" - Called when the item in the Gengrid has been
127 * dragged (not scrolled) down.
128 * "drag,start,left" - Called when the item in the Gengrid has been
129 * dragged (not scrolled) left.
130 * "drag,start,right" - Called when the item in the Gengrid has been
131 * dragged (not scrolled) right.
132 * "drag,stop" - Called when the item in the Gengrid has stopped being
134 * "drag" - Called when the item in the Gengrid is being dragged.
135 * "scroll" - called when the content has been scrolled (moved).
136 * "scroll,drag,start" - called when dragging the content has started.
137 * "scroll,drag,stop" - called when dragging the content has stopped.
141 * Handle non-homogeneous objects too.
144 typedef struct _Widget_Data Widget_Data;
145 typedef struct _Pan Pan;
149 struct _Elm_Gengrid_Item
151 Elm_Widget_Item base;
154 const Elm_Gengrid_Item_Class *gic;
155 Ecore_Timer *long_timer;
157 Eina_List *labels, *icons, *states, *icon_objs;
164 Evas_Coord x, y, dx, dy;
171 Elm_Tooltip_Item_Content_Cb content_cb;
172 Evas_Smart_Cb del_cb;
176 const char *mouse_cursor;
178 Eina_Bool want_unrealize : 1;
179 Eina_Bool realized : 1;
180 Eina_Bool dragging : 1;
182 Eina_Bool delete_me : 1;
183 Eina_Bool display_only : 1;
184 Eina_Bool disabled : 1;
185 Eina_Bool selected : 1;
186 Eina_Bool hilighted : 1;
191 Evas_Object *self, *scr;
192 Evas_Object *pan_smart;
197 Elm_Gengrid_Item *last_selected_item, *reorder_item;
198 double align_x, align_y;
200 Evas_Coord pan_x, pan_y;
201 Evas_Coord item_width, item_height; /* Each item size */
202 Evas_Coord minw, minh; /* Total obj size */
203 Evas_Coord reorder_item_x, reorder_item_y;
208 Eina_Bool horizontal : 1;
209 Eina_Bool on_hold : 1;
210 Eina_Bool longpressed : 1;
212 Eina_Bool no_select : 1;
213 Eina_Bool wasselected : 1;
214 Eina_Bool always_select : 1;
215 Eina_Bool clear_me : 1;
216 Eina_Bool h_bounce : 1;
217 Eina_Bool v_bounce : 1;
218 Eina_Bool reorder_mode : 1;
219 Eina_Bool reorder_item_changed : 1;
222 #define ELM_GENGRID_ITEM_FROM_INLIST(item) \
223 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Gengrid_Item) : NULL)
227 Evas_Object_Smart_Clipped_Data __clipped_data;
231 static const char *widtype = NULL;
232 static void _item_hilight(Elm_Gengrid_Item *item);
233 static void _item_unrealize(Elm_Gengrid_Item *item);
234 static void _item_select(Elm_Gengrid_Item *item);
235 static void _item_unselect(Elm_Gengrid_Item *item);
236 static void _calc_job(void *data);
237 static void _on_focus_hook(void *data,
239 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
240 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
241 static Eina_Bool _item_multi_select_left(Widget_Data *wd);
242 static Eina_Bool _item_multi_select_right(Widget_Data *wd);
243 static Eina_Bool _item_single_select_up(Widget_Data *wd);
244 static Eina_Bool _item_single_select_down(Widget_Data *wd);
245 static Eina_Bool _item_single_select_left(Widget_Data *wd);
246 static Eina_Bool _item_single_select_right(Widget_Data *wd);
247 static Eina_Bool _event_hook(Evas_Object *obj,
249 Evas_Callback_Type type,
251 static Eina_Bool _deselect_all_items(Widget_Data *wd);
253 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
254 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
256 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
257 static const char SIG_SELECTED[] = "selected";
258 static const char SIG_UNSELECTED[] = "unselected";
259 static const char SIG_REALIZED[] = "realized";
260 static const char SIG_UNREALIZED[] = "unrealized";
261 static const char SIG_CHANGED[] = "changed";
262 static const char SIG_DRAG_START_UP[] = "drag,start,up";
263 static const char SIG_DRAG_START_DOWN[] = "drag,start,down";
264 static const char SIG_DRAG_START_LEFT[] = "drag,start,left";
265 static const char SIG_DRAG_START_RIGHT[] = "drag,start,right";
266 static const char SIG_DRAG_STOP[] = "drag,stop";
267 static const char SIG_DRAG[] = "drag";
268 static const char SIG_SCROLL[] = "scroll";
269 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
270 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
271 static const char SIG_MOVED[] = "moved";
273 static const Evas_Smart_Cb_Description _signals[] = {
274 {SIG_CLICKED_DOUBLE, ""},
276 {SIG_UNSELECTED, ""},
278 {SIG_UNREALIZED, ""},
280 {SIG_DRAG_START_UP, ""},
281 {SIG_DRAG_START_DOWN, ""},
282 {SIG_DRAG_START_LEFT, ""},
283 {SIG_DRAG_START_RIGHT, ""},
287 {SIG_SCROLL_DRAG_START, ""},
288 {SIG_SCROLL_DRAG_STOP, ""},
296 _event_hook(Evas_Object *obj,
297 Evas_Object *src __UNUSED__,
298 Evas_Callback_Type type,
301 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
302 Evas_Event_Key_Down *ev = event_info;
303 Widget_Data *wd = elm_widget_data_get(obj);
304 if (!wd) return EINA_FALSE;
305 if (!wd->items) return EINA_FALSE;
306 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
307 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
309 Elm_Gengrid_Item *item = NULL;
312 Evas_Coord step_x = 0;
313 Evas_Coord step_y = 0;
316 Evas_Coord page_x = 0;
317 Evas_Coord page_y = 0;
319 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
320 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
321 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
322 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
324 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
326 if ((wd->horizontal) &&
327 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
328 (_item_multi_select_up(wd)))
329 || (_item_single_select_up(wd))))
331 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
334 else if ((!wd->horizontal) &&
335 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
336 (_item_multi_select_left(wd)))
337 || (_item_single_select_left(wd))))
339 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
345 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
347 if ((wd->horizontal) &&
348 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
349 (_item_multi_select_down(wd)))
350 || (_item_single_select_down(wd))))
352 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
355 else if ((!wd->horizontal) &&
356 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
357 (_item_multi_select_right(wd)))
358 || (_item_single_select_right(wd))))
360 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
366 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
368 if ((wd->horizontal) &&
369 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
370 (_item_multi_select_left(wd)))
371 || (_item_single_select_left(wd))))
373 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
376 else if ((!wd->horizontal) &&
377 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
378 (_item_multi_select_up(wd)))
379 || (_item_single_select_up(wd))))
381 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
387 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
389 if ((wd->horizontal) &&
390 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
391 (_item_multi_select_right(wd)))
392 || (_item_single_select_right(wd))))
394 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
397 else if ((!wd->horizontal) &&
398 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
399 (_item_multi_select_down(wd)))
400 || (_item_single_select_down(wd))))
402 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
408 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
410 item = elm_gengrid_first_item_get(obj);
411 elm_gengrid_item_bring_in(item);
412 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
415 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
417 item = elm_gengrid_last_item_get(obj);
418 elm_gengrid_item_bring_in(item);
419 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
422 else if ((!strcmp(ev->keyname, "Prior")) ||
423 (!strcmp(ev->keyname, "KP_Prior")))
428 x -= -(page_x * v_w) / 100;
435 y -= -(page_y * v_h) / 100;
440 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
445 x += -(page_x * v_w) / 100;
452 y += -(page_y * v_h) / 100;
457 else if (!strcmp(ev->keyname, "Escape"))
459 if (!_deselect_all_items(wd)) return EINA_FALSE;
460 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
463 else if ((!strcmp(ev->keyname, "Return")) ||
464 (!strcmp(ev->keyname, "KP_Enter")) ||
465 (!strcmp(ev->keyname, "space")))
467 item = elm_gengrid_selected_item_get(obj);
468 evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
469 evas_object_smart_callback_call(item->wd->self, "clicked", item); // will be removed
471 else return EINA_FALSE;
473 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
474 elm_smart_scroller_child_pos_set(wd->scr, x, y);
479 _deselect_all_items(Widget_Data *wd)
481 if (!wd->selected) return EINA_FALSE;
483 elm_gengrid_item_selected_set(wd->selected->data, EINA_FALSE);
489 _item_multi_select_left(Widget_Data *wd)
491 if (!wd->selected) return EINA_FALSE;
493 Elm_Gengrid_Item *prev = elm_gengrid_item_prev_get(wd->last_selected_item);
494 if (!prev) return EINA_TRUE;
495 if (elm_gengrid_item_selected_get(prev))
497 elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
498 wd->last_selected_item = prev;
499 elm_gengrid_item_show(wd->last_selected_item);
503 elm_gengrid_item_selected_set(prev, EINA_TRUE);
504 elm_gengrid_item_show(prev);
511 _item_multi_select_right(Widget_Data *wd)
513 if (!wd->selected) return EINA_FALSE;
515 Elm_Gengrid_Item *next = elm_gengrid_item_next_get(wd->last_selected_item);
516 if (!next) return EINA_TRUE;
517 if (elm_gengrid_item_selected_get(next))
519 elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
520 wd->last_selected_item = next;
521 elm_gengrid_item_show(wd->last_selected_item);
525 elm_gengrid_item_selected_set(next, EINA_TRUE);
526 elm_gengrid_item_show(next);
533 _item_multi_select_up(Widget_Data *wd)
536 Eina_Bool r = EINA_TRUE;
538 if (!wd->selected) return EINA_FALSE;
540 for (i = 0; (r) && (i < wd->nmax); i++)
541 r &= _item_multi_select_left(wd);
547 _item_multi_select_down(Widget_Data *wd)
550 Eina_Bool r = EINA_TRUE;
552 if (!wd->selected) return EINA_FALSE;
554 for (i = 0; (r) && (i < wd->nmax); i++)
555 r &= _item_multi_select_right(wd);
561 _item_single_select_up(Widget_Data *wd)
565 Elm_Gengrid_Item *prev;
569 prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
570 while ((prev) && (prev->delete_me))
571 prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
572 elm_gengrid_item_selected_set(prev, EINA_TRUE);
573 elm_gengrid_item_show(prev);
576 else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
578 if (!prev) return EINA_FALSE;
580 for (i = 1; i < wd->nmax; i++)
582 Elm_Gengrid_Item *tmp = elm_gengrid_item_prev_get(prev);
583 if (!tmp) return EINA_FALSE;
587 _deselect_all_items(wd);
589 elm_gengrid_item_selected_set(prev, EINA_TRUE);
590 elm_gengrid_item_show(prev);
595 _item_single_select_down(Widget_Data *wd)
599 Elm_Gengrid_Item *next;
603 next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
604 while ((next) && (next->delete_me))
605 next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
606 elm_gengrid_item_selected_set(next, EINA_TRUE);
607 elm_gengrid_item_show(next);
610 else next = elm_gengrid_item_next_get(wd->last_selected_item);
612 if (!next) return EINA_FALSE;
614 for (i = 1; i < wd->nmax; i++)
616 Elm_Gengrid_Item *tmp = elm_gengrid_item_next_get(next);
617 if (!tmp) return EINA_FALSE;
621 _deselect_all_items(wd);
623 elm_gengrid_item_selected_set(next, EINA_TRUE);
624 elm_gengrid_item_show(next);
629 _item_single_select_left(Widget_Data *wd)
631 Elm_Gengrid_Item *prev;
634 prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
635 while ((prev) && (prev->delete_me))
636 prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
638 else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
640 if (!prev) return EINA_FALSE;
642 _deselect_all_items(wd);
644 elm_gengrid_item_selected_set(prev, EINA_TRUE);
645 elm_gengrid_item_show(prev);
650 _item_single_select_right(Widget_Data *wd)
652 Elm_Gengrid_Item *next;
655 next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
656 while ((next) && (next->delete_me))
657 next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
659 else next = elm_gengrid_item_next_get(wd->last_selected_item);
661 if (!next) return EINA_FALSE;
663 _deselect_all_items(wd);
665 elm_gengrid_item_selected_set(next, EINA_TRUE);
666 elm_gengrid_item_show(next);
671 _on_focus_hook(void *data __UNUSED__,
674 Widget_Data *wd = elm_widget_data_get(obj);
676 if (elm_widget_focus_get(obj))
678 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
679 evas_object_focus_set(wd->self, EINA_TRUE);
680 if ((wd->selected) && (!wd->last_selected_item))
681 wd->last_selected_item = eina_list_data_get(wd->selected);
685 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
686 evas_object_focus_set(wd->self, EINA_FALSE);
691 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
693 Widget_Data *wd = elm_widget_data_get(obj);
694 Elm_Gengrid_Item *item;
696 elm_smart_scroller_mirrored_set(wd->scr, rtl);
697 if (!wd->items) return;
698 item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
702 edje_object_mirrored_set(item->base.view, rtl);
703 elm_gengrid_item_update(item);
704 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
709 _theme_hook(Evas_Object *obj)
711 Widget_Data *wd = elm_widget_data_get(obj);
713 _elm_widget_mirrored_reload(obj);
714 _mirrored_set(obj, elm_widget_mirrored_get(obj));
715 elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
716 elm_widget_style_get(obj));
720 _del_pre_hook(Evas_Object *obj)
722 Widget_Data *wd = elm_widget_data_get(obj);
724 elm_gengrid_clear(obj);
725 evas_object_del(wd->pan_smart);
726 wd->pan_smart = NULL;
730 _del_hook(Evas_Object *obj)
732 Widget_Data *wd = elm_widget_data_get(obj);
737 _signal_emit_hook(Evas_Object *obj,
738 const char *emission,
741 Widget_Data *wd = elm_widget_data_get(obj);
743 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
748 _mouse_move(void *data,
749 Evas *evas __UNUSED__,
753 Elm_Gengrid_Item *item = data;
754 Evas_Event_Mouse_Move *ev = event_info;
755 Evas_Coord minw = 0, minh = 0, x, y, dx, dy, adx, ady;
756 Evas_Coord ox, oy, ow, oh, it_scrl_x, it_scrl_y;
758 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
760 if (!item->wd->on_hold)
762 item->wd->on_hold = EINA_TRUE;
763 if (!item->wd->wasselected)
764 _item_unselect(item);
767 if ((item->dragging) && (item->down))
769 if (item->long_timer)
771 ecore_timer_del(item->long_timer);
772 item->long_timer = NULL;
774 evas_object_smart_callback_call(item->wd->self, SIG_DRAG, item);
777 if ((!item->down) || (item->wd->longpressed))
779 if (item->long_timer)
781 ecore_timer_del(item->long_timer);
782 item->long_timer = NULL;
784 if ((item->wd->reorder_mode) && (item->wd->reorder_item))
786 evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &ow, &oh);
788 it_scrl_x = ev->cur.canvas.x - item->wd->reorder_item->dx;
789 it_scrl_y = ev->cur.canvas.y - item->wd->reorder_item->dy;
791 if (it_scrl_x < ox) item->wd->reorder_item_x = ox;
792 else if (it_scrl_x + item->wd->item_width > ox + ow)
793 item->wd->reorder_item_x = ox + ow - item->wd->item_width;
794 else item->wd->reorder_item_x = it_scrl_x;
796 if (it_scrl_y < oy) item->wd->reorder_item_y = oy;
797 else if (it_scrl_y + item->wd->item_height > oy + oh)
798 item->wd->reorder_item_y = oy + oh - item->wd->item_height;
799 else item->wd->reorder_item_y = it_scrl_y;
801 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
802 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
806 if (!item->display_only)
807 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
808 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
809 x = ev->cur.canvas.x - x;
810 y = ev->cur.canvas.y - y;
813 if (adx < 0) adx = -dx;
816 if (ady < 0) ady = -dy;
819 if ((adx > minw) || (ady > minh))
821 const char *left_drag, *right_drag;
822 if (!elm_widget_mirrored_get(item->wd->self))
824 left_drag = SIG_DRAG_START_LEFT;
825 right_drag = SIG_DRAG_START_RIGHT;
829 left_drag = SIG_DRAG_START_RIGHT;
830 right_drag = SIG_DRAG_START_LEFT;
834 if (item->long_timer)
836 ecore_timer_del(item->long_timer);
837 item->long_timer = NULL;
839 if (!item->wd->wasselected)
840 _item_unselect(item);
844 evas_object_smart_callback_call(item->wd->self, SIG_DRAG_START_UP,
849 evas_object_smart_callback_call(item->wd->self,
856 evas_object_smart_callback_call(item->wd->self,
857 SIG_DRAG_START_DOWN, item);
861 evas_object_smart_callback_call(item->wd->self,
864 evas_object_smart_callback_call(item->wd->self,
872 _long_press(void *data)
874 Elm_Gengrid_Item *item = data;
876 item->long_timer = NULL;
877 if ((item->disabled) || (item->dragging)) return ECORE_CALLBACK_CANCEL;
878 item->wd->longpressed = EINA_TRUE;
879 evas_object_smart_callback_call(item->wd->self, "longpressed", item);
880 if (item->wd->reorder_mode)
882 item->wd->reorder_item = item;
883 evas_object_raise(item->base.view);
884 elm_smart_scroller_hold_set(item->wd->scr, EINA_TRUE);
885 elm_smart_scroller_bounce_allow_set(item->wd->scr, EINA_FALSE, EINA_FALSE);
886 edje_object_signal_emit(item->base.view, "elm,state,reorder,enabled", "elm");
888 return ECORE_CALLBACK_CANCEL;
892 _mouse_down(void *data,
893 Evas *evas __UNUSED__,
897 Elm_Gengrid_Item *item = data;
898 Evas_Event_Mouse_Down *ev = event_info;
901 if (ev->button != 1) return;
904 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
905 item->dx = ev->canvas.x - x;
906 item->dy = ev->canvas.y - y;
907 item->wd->longpressed = EINA_FALSE;
908 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
909 else item->wd->on_hold = EINA_FALSE;
910 item->wd->wasselected = item->selected;
912 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
914 evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
915 evas_object_smart_callback_call(item->wd->self, "clicked", item); // will be removed
917 if (item->long_timer) ecore_timer_del(item->long_timer);
919 item->long_timer = ecore_timer_add(_elm_config->longpress_timeout,
922 item->long_timer = NULL;
926 _mouse_up(void *data,
927 Evas *evas __UNUSED__,
928 Evas_Object *obj __UNUSED__,
931 Elm_Gengrid_Item *item = data;
932 Evas_Event_Mouse_Up *ev = event_info;
933 Eina_Bool dragged = EINA_FALSE;
935 if (ev->button != 1) return;
936 item->down = EINA_FALSE;
937 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
938 else item->wd->on_hold = EINA_FALSE;
939 if (item->long_timer)
941 ecore_timer_del(item->long_timer);
942 item->long_timer = NULL;
946 item->dragging = EINA_FALSE;
947 evas_object_smart_callback_call(item->wd->self, SIG_DRAG_STOP, item);
950 if (item->wd->on_hold)
952 item->wd->longpressed = EINA_FALSE;
953 item->wd->on_hold = EINA_FALSE;
956 if ((item->wd->reorder_mode) && (item->wd->reorder_item))
958 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
959 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
961 evas_object_smart_callback_call(item->wd->self, SIG_MOVED, item->wd->reorder_item);
962 item->wd->reorder_item = NULL;
963 elm_smart_scroller_hold_set(item->wd->scr, EINA_FALSE);
964 elm_smart_scroller_bounce_allow_set(item->wd->scr, item->wd->h_bounce, item->wd->v_bounce);
965 edje_object_signal_emit(item->base.view, "elm,state,reorder,disabled", "elm");
967 if (item->wd->longpressed)
969 item->wd->longpressed = EINA_FALSE;
970 if (!item->wd->wasselected) _item_unselect(item);
971 item->wd->wasselected = EINA_FALSE;
976 if (item->want_unrealize) _item_unrealize(item);
978 if ((item->disabled) || (dragged)) return;
986 else _item_unselect(item);
992 while (item->wd->selected)
993 _item_unselect(item->wd->selected->data);
997 const Eina_List *l, *l_next;
998 Elm_Gengrid_Item *item2;
1000 EINA_LIST_FOREACH_SAFE(item->wd->selected, l, l_next, item2)
1001 if (item2 != item) _item_unselect(item2);
1003 _item_hilight(item);
1009 _item_hilight(Elm_Gengrid_Item *item)
1011 if ((item->wd->no_select) || (item->delete_me) || (item->hilighted)) return;
1012 edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
1013 item->hilighted = EINA_TRUE;
1017 _item_realize(Elm_Gengrid_Item *item)
1022 if ((item->realized) || (item->delete_me)) return;
1023 item->base.view = edje_object_add(evas_object_evas_get(item->wd->self));
1024 edje_object_scale_set(item->base.view, elm_widget_scale_get(item->wd->self) *
1025 _elm_config->scale);
1026 edje_object_mirrored_set(item->base.view, elm_widget_mirrored_get(item->base.widget));
1027 evas_object_smart_member_add(item->base.view, item->wd->pan_smart);
1028 elm_widget_sub_object_add(item->wd->self, item->base.view);
1029 snprintf(style, sizeof(style), "item/%s",
1030 item->gic->item_style ? item->gic->item_style : "default");
1031 _elm_theme_object_set(item->wd->self, item->base.view, "gengrid", style,
1032 elm_widget_style_get(item->wd->self));
1034 evas_object_rectangle_add(evas_object_evas_get(item->wd->self));
1035 evas_object_color_set(item->spacer, 0, 0, 0, 0);
1036 elm_widget_sub_object_add(item->wd->self, item->spacer);
1037 evas_object_size_hint_min_set(item->spacer, 2 * _elm_config->scale, 1);
1038 edje_object_part_swallow(item->base.view, "elm.swallow.pad", item->spacer);
1040 if (item->gic->func.label_get)
1046 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
1048 EINA_LIST_FOREACH(item->labels, l, key)
1050 char *s = item->gic->func.label_get
1051 ((void *)item->base.data, item->wd->self, l->data);
1054 edje_object_part_text_set(item->base.view, l->data, s);
1060 if (item->gic->func.icon_get)
1066 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
1068 EINA_LIST_FOREACH(item->icons, l, key)
1070 Evas_Object *ic = item->gic->func.icon_get
1071 ((void *)item->base.data, item->wd->self, l->data);
1074 item->icon_objs = eina_list_append(item->icon_objs, ic);
1075 edje_object_part_swallow(item->base.view, key, ic);
1076 evas_object_show(ic);
1077 elm_widget_sub_object_add(item->wd->self, ic);
1082 if (item->gic->func.state_get)
1088 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
1090 EINA_LIST_FOREACH(item->states, l, key)
1092 Eina_Bool on = item->gic->func.state_get
1093 ((void *)item->base.data, item->wd->self, l->data);
1096 snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1097 edje_object_signal_emit(item->base.view, buf, "elm");
1102 if ((!item->wd->item_width) && (!item->wd->item_height))
1104 edje_object_size_min_restricted_calc(item->base.view,
1105 &item->wd->item_width,
1106 &item->wd->item_height,
1107 item->wd->item_width,
1108 item->wd->item_height);
1109 elm_coords_finger_size_adjust(1, &item->wd->item_width,
1110 1, &item->wd->item_height);
1113 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_DOWN,
1115 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_UP,
1117 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_MOVE,
1121 edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
1123 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1125 evas_object_show(item->base.view);
1127 if (item->tooltip.content_cb)
1129 elm_widget_item_tooltip_content_cb_set(item,
1130 item->tooltip.content_cb,
1131 item->tooltip.data, NULL);
1132 elm_widget_item_tooltip_style_set(item, item->tooltip.style);
1135 if (item->mouse_cursor)
1136 elm_widget_item_cursor_set(item, item->mouse_cursor);
1138 item->realized = EINA_TRUE;
1139 item->want_unrealize = EINA_FALSE;
1143 _item_unrealize(Elm_Gengrid_Item *item)
1147 if (!item->realized) return;
1148 if (item->long_timer)
1150 ecore_timer_del(item->long_timer);
1151 item->long_timer = NULL;
1153 evas_object_del(item->base.view);
1154 item->base.view = NULL;
1155 evas_object_del(item->spacer);
1156 item->spacer = NULL;
1157 elm_widget_stringlist_free(item->labels);
1158 item->labels = NULL;
1159 elm_widget_stringlist_free(item->icons);
1161 elm_widget_stringlist_free(item->states);
1162 item->states = NULL;
1164 EINA_LIST_FREE(item->icon_objs, icon)
1165 evas_object_del(icon);
1167 item->realized = EINA_FALSE;
1168 item->want_unrealize = EINA_FALSE;
1172 _item_place(Elm_Gengrid_Item *item,
1176 Evas_Coord x, y, ox, oy, cvx, cvy, cvw, cvh;
1177 Evas_Coord tch, tcw, alignw = 0, alignh = 0, vw, vh;
1178 Eina_Bool reorder_item_move_forward = EINA_FALSE;
1181 evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &vw, &vh);
1183 /* Preload rows/columns at each side of the Gengrid */
1184 cvx = ox - PRELOAD * item->wd->item_width;
1185 cvy = oy - PRELOAD * item->wd->item_height;
1186 cvw = vw + 2 * PRELOAD * item->wd->item_width;
1187 cvh = vh + 2 * PRELOAD * item->wd->item_height;
1192 if (item->wd->horizontal)
1194 int columns, items_visible = 0, items_row;
1196 if (item->wd->item_height > 0)
1197 items_visible = vh / item->wd->item_height;
1198 if (items_visible < 1)
1201 columns = item->wd->count / items_visible;
1202 if (item->wd->count % items_visible)
1205 tcw = item->wd->item_width * columns;
1206 alignw = (vw - tcw) * item->wd->align_x;
1208 items_row = items_visible;
1209 if (items_row > item->wd->count)
1210 items_row = item->wd->count;
1211 tch = items_row * item->wd->item_height;
1212 alignh = (vh - tch) * item->wd->align_y;
1216 int rows, items_visible = 0, items_col;
1218 if (item->wd->item_width > 0)
1219 items_visible = vw / item->wd->item_width;
1220 if (items_visible < 1)
1223 rows = item->wd->count / items_visible;
1224 if (item->wd->count % items_visible)
1227 tch = item->wd->item_height * rows;
1228 alignh = (vh - tch) * item->wd->align_y;
1230 items_col = items_visible;
1231 if (items_col > item->wd->count)
1232 items_col = item->wd->count;
1233 tcw = items_col * item->wd->item_width;
1234 alignw = (vw - tcw) * item->wd->align_x;
1237 x = cx * item->wd->item_width - item->wd->pan_x + ox + alignw;
1238 if (elm_widget_mirrored_get(item->wd->self))
1239 { /* Switch items side and componsate for pan_x when in RTL mode */
1241 evas_object_geometry_get(item->wd->self, NULL, NULL, &ww, NULL);
1242 x = ww - x - item->wd->item_width - item->wd->pan_x - item->wd->pan_x;
1245 y = cy * item->wd->item_height - item->wd->pan_y + oy + alignh;
1247 Eina_Bool was_realized = item->realized;
1248 if (ELM_RECTS_INTERSECT(x, y, item->wd->item_width, item->wd->item_height,
1249 cvx, cvy, cvw, cvh))
1251 _item_realize(item);
1253 evas_object_smart_callback_call(item->wd->self, SIG_REALIZED, item);
1254 if ((item->wd->reorder_mode) && (item->wd->reorder_item))
1256 if (item->wd->reorder_item == item)
1258 evas_object_move(item->base.view,
1259 item->wd->reorder_item_x, item->wd->reorder_item_y);
1260 evas_object_resize(item->base.view,
1261 item->wd->item_width, item->wd->item_height);
1266 if (ELM_RECTS_INTERSECT(item->wd->reorder_item_x, item->wd->reorder_item_y,
1267 item->wd->item_width, item->wd->item_height,
1268 x+(item->wd->item_width/2), y+(item->wd->item_height/2),
1271 if (item->wd->horizontal)
1273 if ((item->wd->nmax * item->wd->reorder_item->x + item->wd->reorder_item->y) >
1274 (item->wd->nmax * item->x + item->y))
1275 reorder_item_move_forward = EINA_TRUE;
1279 if ((item->wd->nmax * item->wd->reorder_item->y + item->wd->reorder_item->x) >
1280 (item->wd->nmax * item->y + item->x))
1281 reorder_item_move_forward = EINA_TRUE;
1284 item->wd->items = eina_inlist_remove(item->wd->items,
1285 EINA_INLIST_GET(item->wd->reorder_item));
1286 if (reorder_item_move_forward)
1287 item->wd->items = eina_inlist_prepend_relative(item->wd->items,
1288 EINA_INLIST_GET(item->wd->reorder_item),
1289 EINA_INLIST_GET(item));
1291 item->wd->items = eina_inlist_append_relative(item->wd->items,
1292 EINA_INLIST_GET(item->wd->reorder_item),
1293 EINA_INLIST_GET(item));
1295 item->wd->reorder_item_changed = EINA_TRUE;
1297 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1298 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1304 evas_object_move(item->base.view, x, y);
1305 evas_object_resize(item->base.view, item->wd->item_width,
1306 item->wd->item_height);
1310 _item_unrealize(item);
1312 evas_object_smart_callback_call(item->wd->self, SIG_UNREALIZED, item);
1316 static Elm_Gengrid_Item *
1317 _item_create(Widget_Data *wd,
1318 const Elm_Gengrid_Item_Class *gic,
1321 const void *func_data)
1323 Elm_Gengrid_Item *item;
1325 item = elm_widget_item_new(wd->self, Elm_Gengrid_Item);
1326 if (!item) return NULL;
1330 item->base.data = data;
1331 item->func.func = func;
1332 item->func.data = func_data;
1333 item->mouse_cursor = NULL;
1338 _item_del(Elm_Gengrid_Item *item)
1340 elm_widget_item_pre_notify_del(item);
1342 item->wd->selected = eina_list_remove(item->wd->selected, item);
1343 if (item->realized) _item_unrealize(item);
1344 if ((!item->delete_me) && (item->gic->func.del))
1345 item->gic->func.del((void *)item->base.data, item->wd->self);
1346 item->delete_me = EINA_TRUE;
1347 item->wd->items = eina_inlist_remove(item->wd->items, EINA_INLIST_GET(item));
1348 if (item->long_timer) ecore_timer_del(item->long_timer);
1349 if (item->tooltip.del_cb)
1350 item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
1351 item->wd->walking -= item->walking;
1353 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1354 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1355 elm_widget_item_del(item);
1359 _item_select(Elm_Gengrid_Item *item)
1361 if ((item->wd->no_select) || (item->delete_me)) return;
1364 if (item->wd->always_select) goto call;
1367 item->selected = EINA_TRUE;
1368 item->wd->selected = eina_list_append(item->wd->selected, item);
1371 item->wd->walking++;
1372 if (item->func.func)
1373 item->func.func((void *)item->func.data, item->wd->self, item);
1374 if (!item->delete_me)
1375 evas_object_smart_callback_call(item->wd->self, SIG_SELECTED, item);
1377 item->wd->walking--;
1378 if ((item->wd->clear_me) && (!item->wd->walking))
1379 elm_gengrid_clear(item->base.widget);
1382 if ((!item->walking) && (item->delete_me))
1383 if (!item->relcount) _item_del(item);
1385 item->wd->last_selected_item = item;
1389 _item_unselect(Elm_Gengrid_Item *item)
1391 if ((item->delete_me) || (!item->hilighted)) return;
1392 edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
1393 item->hilighted = EINA_FALSE;
1396 item->selected = EINA_FALSE;
1397 item->wd->selected = eina_list_remove(item->wd->selected, item);
1398 evas_object_smart_callback_call(item->wd->self, SIG_UNSELECTED, item);
1403 _calc_job(void *data)
1405 Widget_Data *wd = data;
1406 Evas_Coord minw = 0, minh = 0, nmax = 0, cvw, cvh;
1409 evas_object_geometry_get(wd->pan_smart, NULL, NULL, &cvw, &cvh);
1410 if ((cvw != 0) || (cvh != 0))
1412 if ((wd->horizontal) && (wd->item_height > 0))
1413 nmax = cvh / wd->item_height;
1414 else if (wd->item_width > 0)
1415 nmax = cvw / wd->item_width;
1423 minw = ceil(count / (float)nmax) * wd->item_width;
1424 minh = nmax * wd->item_height;
1428 minw = nmax * wd->item_width;
1429 minh = ceil(count / (float)nmax) * wd->item_height;
1432 if ((minw != wd->minw) || (minh != wd->minh))
1436 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1440 evas_object_smart_changed(wd->pan_smart);
1442 wd->calc_job = NULL;
1446 _pan_add(Evas_Object *obj)
1449 Evas_Object_Smart_Clipped_Data *cd;
1452 cd = evas_object_smart_data_get(obj);
1455 sd->__clipped_data = *cd;
1457 evas_object_smart_data_set(obj, sd);
1461 _pan_del(Evas_Object *obj)
1463 Pan *sd = evas_object_smart_data_get(obj);
1470 _pan_set(Evas_Object *obj,
1474 Pan *sd = evas_object_smart_data_get(obj);
1475 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1478 evas_object_smart_changed(obj);
1482 _pan_get(Evas_Object *obj,
1486 Pan *sd = evas_object_smart_data_get(obj);
1487 if (x) *x = sd->wd->pan_x;
1488 if (y) *y = sd->wd->pan_y;
1492 _pan_child_size_get(Evas_Object *obj,
1496 Pan *sd = evas_object_smart_data_get(obj);
1497 if (w) *w = sd->wd->minw;
1498 if (h) *h = sd->wd->minh;
1502 _pan_max_get(Evas_Object *obj,
1506 Pan *sd = evas_object_smart_data_get(obj);
1510 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1512 *x = (ow < sd->wd->minw) ? sd->wd->minw - ow : 0;
1514 *y = (oh < sd->wd->minh) ? sd->wd->minh - oh : 0;
1518 _pan_min_get(Evas_Object *obj,
1522 Pan *sd = evas_object_smart_data_get(obj);
1526 _pan_max_get(obj, &mx, &my);
1528 *x = -mx * sd->wd->align_x;
1530 *y = -my * sd->wd->align_y;
1534 _pan_resize(Evas_Object *obj,
1538 Pan *sd = evas_object_smart_data_get(obj);
1541 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1542 if ((ow == w) && (oh == h)) return;
1543 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1544 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1548 _pan_calculate(Evas_Object *obj)
1550 Pan *sd = evas_object_smart_data_get(obj);
1551 Evas_Coord cx = 0, cy = 0;
1552 Elm_Gengrid_Item *item;
1555 if (!sd->wd->nmax) return;
1557 sd->wd->reorder_item_changed = EINA_FALSE;
1559 EINA_INLIST_FOREACH(sd->wd->items, item)
1561 _item_place(item, cx, cy);
1562 if (sd->wd->reorder_item_changed) return;
1563 if (sd->wd->horizontal)
1565 cy = (cy + 1) % sd->wd->nmax;
1570 cx = (cx + 1) % sd->wd->nmax;
1574 evas_object_smart_callback_call(sd->wd->self, SIG_CHANGED, NULL);
1578 _pan_move(Evas_Object *obj,
1579 Evas_Coord x __UNUSED__,
1580 Evas_Coord y __UNUSED__)
1582 Pan *sd = evas_object_smart_data_get(obj);
1584 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1585 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1589 _hold_on(void *data __UNUSED__,
1591 void *event_info __UNUSED__)
1593 Widget_Data *wd = elm_widget_data_get(obj);
1595 elm_smart_scroller_hold_set(wd->scr, 1);
1599 _hold_off(void *data __UNUSED__,
1601 void *event_info __UNUSED__)
1603 Widget_Data *wd = elm_widget_data_get(obj);
1605 elm_smart_scroller_hold_set(wd->scr, 0);
1609 _freeze_on(void *data __UNUSED__,
1611 void *event_info __UNUSED__)
1613 Widget_Data *wd = elm_widget_data_get(obj);
1615 elm_smart_scroller_freeze_set(wd->scr, 1);
1619 _freeze_off(void *data __UNUSED__,
1621 void *event_info __UNUSED__)
1623 Widget_Data *wd = elm_widget_data_get(obj);
1625 elm_smart_scroller_freeze_set(wd->scr, 0);
1629 _scr_drag_start(void *data,
1630 Evas_Object *obj __UNUSED__,
1631 void *event_info __UNUSED__)
1633 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1637 _scr_drag_stop(void *data,
1638 Evas_Object *obj __UNUSED__,
1639 void *event_info __UNUSED__)
1641 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1645 _scr_scroll(void *data,
1646 Evas_Object *obj __UNUSED__,
1647 void *event_info __UNUSED__)
1649 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1653 * Add a new Gengrid object.
1655 * @param parent The parent object.
1656 * @return The new object or NULL if it cannot be created.
1658 * @see elm_gengrid_item_size_set()
1659 * @see elm_gengrid_horizontal_set()
1660 * @see elm_gengrid_item_append()
1661 * @see elm_gengrid_item_del()
1662 * @see elm_gengrid_clear()
1667 elm_gengrid_add(Evas_Object *parent)
1672 static Evas_Smart *smart = NULL;
1673 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1675 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1677 ELM_SET_WIDTYPE(widtype, "gengrid");
1678 elm_widget_type_set(obj, "gengrid");
1679 elm_widget_sub_object_add(parent, obj);
1680 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1681 elm_widget_data_set(obj, wd);
1682 elm_widget_del_hook_set(obj, _del_hook);
1683 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1684 elm_widget_theme_hook_set(obj, _theme_hook);
1685 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1686 elm_widget_can_focus_set(obj, EINA_TRUE);
1687 elm_widget_event_hook_set(obj, _event_hook);
1689 wd->scr = elm_smart_scroller_add(e);
1690 elm_smart_scroller_widget_set(wd->scr, obj);
1691 elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
1693 elm_widget_resize_object_set(obj, wd->scr);
1695 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1696 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1697 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1699 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1704 wd->h_bounce = bounce;
1705 wd->v_bounce = bounce;
1706 wd->no_select = EINA_FALSE;
1708 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1709 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1710 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1711 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1713 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1717 static Evas_Smart_Class sc;
1719 evas_object_smart_clipped_smart_set(&_pan_sc);
1721 sc.name = "elm_gengrid_pan";
1722 sc.version = EVAS_SMART_CLASS_VERSION;
1725 sc.resize = _pan_resize;
1726 sc.move = _pan_move;
1727 sc.calculate = _pan_calculate;
1728 smart = evas_smart_class_new(&sc);
1732 wd->pan_smart = evas_object_smart_add(e, smart);
1733 wd->pan = evas_object_smart_data_get(wd->pan_smart);
1737 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1738 _pan_set, _pan_get, _pan_max_get,
1739 _pan_min_get, _pan_child_size_get);
1741 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1746 * Set the size for the item of the Gengrid.
1748 * @param obj The Gengrid object.
1749 * @param w The item's width.
1750 * @param h The item's height;
1752 * @see elm_gengrid_item_size_get()
1757 elm_gengrid_item_size_set(Evas_Object *obj,
1761 ELM_CHECK_WIDTYPE(obj, widtype);
1762 Widget_Data *wd = elm_widget_data_get(obj);
1764 if ((wd->item_width == w) && (wd->item_height == h)) return;
1766 wd->item_height = h;
1767 if (wd->calc_job) ecore_job_del(wd->calc_job);
1768 wd->calc_job = ecore_job_add(_calc_job, wd);
1772 * Get the size of the item of the Gengrid.
1774 * @param obj The Gengrid object.
1775 * @param w Pointer to the item's width.
1776 * @param h Pointer to the item's height.
1778 * @see elm_gengrid_item_size_get()
1783 elm_gengrid_item_size_get(const Evas_Object *obj,
1787 ELM_CHECK_WIDTYPE(obj, widtype);
1788 Widget_Data *wd = elm_widget_data_get(obj);
1790 if (w) *w = wd->item_width;
1791 if (h) *h = wd->item_height;
1795 * Set item's alignment within the scroller.
1797 * @param obj The Gengrid object.
1798 * @param align_x The x alignment (0 <= x <= 1).
1799 * @param align_y The y alignment (0 <= y <= 1).
1801 * @see elm_gengrid_align_get()
1806 elm_gengrid_align_set(Evas_Object *obj,
1810 ELM_CHECK_WIDTYPE(obj, widtype);
1811 Widget_Data *wd = elm_widget_data_get(obj);
1815 else if (align_x < 0.0)
1817 wd->align_x = align_x;
1821 else if (align_y < 0.0)
1823 wd->align_y = align_y;
1827 * Get the alignenment set for the Gengrid object.
1829 * @param obj The Gengrid object.
1830 * @param align_x Pointer to x alignenment.
1831 * @param align_y Pointer to y alignenment.
1833 * @see elm_gengrid_align_set()
1838 elm_gengrid_align_get(const Evas_Object *obj,
1842 ELM_CHECK_WIDTYPE(obj, widtype);
1843 Widget_Data *wd = elm_widget_data_get(obj);
1844 if (align_x) *align_x = wd->align_x;
1845 if (align_y) *align_y = wd->align_y;
1849 * Add item to the end of the Gengrid.
1851 * @param obj The Gengrid object.
1852 * @param gic The item class for the item.
1853 * @param data The item data.
1854 * @param func Convenience function called when item is selected.
1855 * @param func_data Data passed to @p func above.
1856 * @return A handle to the item added or NULL if not possible.
1858 * @see elm_gengrid_item_prepend()
1859 * @see elm_gengrid_item_insert_before()
1860 * @see elm_gengrid_item_insert_after()
1861 * @see elm_gengrid_item_del()
1865 EAPI Elm_Gengrid_Item *
1866 elm_gengrid_item_append(Evas_Object *obj,
1867 const Elm_Gengrid_Item_Class *gic,
1870 const void *func_data)
1872 Elm_Gengrid_Item *item;
1873 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1874 Widget_Data *wd = elm_widget_data_get(obj);
1875 if (!wd) return NULL;
1877 item = _item_create(wd, gic, data, func, func_data);
1878 if (!item) return NULL;
1879 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(item));
1881 if (wd->calc_job) ecore_job_del(wd->calc_job);
1882 wd->calc_job = ecore_job_add(_calc_job, wd);
1888 * Add item at start of the Gengrid.
1890 * This adds an item to the beginning of the grid.
1892 * @param obj The Gengrid object.
1893 * @param gic The item class for the item.
1894 * @param data The item data.
1895 * @param func Convenience function called when item is selected.
1896 * @param func_data Data passed to @p func above.
1897 * @return A handle to the item added or NULL if not possible.
1899 * @see elm_gengrid_item_append()
1900 * @see elm_gengrid_item_insert_before()
1901 * @see elm_gengrid_item_insert_after()
1902 * @see elm_gengrid_item_del()
1906 EAPI Elm_Gengrid_Item *
1907 elm_gengrid_item_prepend(Evas_Object *obj,
1908 const Elm_Gengrid_Item_Class *gic,
1911 const void *func_data)
1913 Elm_Gengrid_Item *item;
1914 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1915 Widget_Data *wd = elm_widget_data_get(obj);
1916 if (!wd) return NULL;
1918 item = _item_create(wd, gic, data, func, func_data);
1919 if (!item) return NULL;
1920 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(item));
1922 if (wd->calc_job) ecore_job_del(wd->calc_job);
1923 wd->calc_job = ecore_job_add(_calc_job, wd);
1929 * Insert and item before another in the Gengrid.
1931 * This inserts an item before another in the grid.
1933 * @param obj The Gengrid object.
1934 * @param gic The item class for the item.
1935 * @param data The item data.
1936 * @param relative The item to which insert before.
1937 * @param func Convenience function called when item is selected.
1938 * @param func_data Data passed to @p func above.
1939 * @return A handle to the item added or NULL if not possible.
1941 * @see elm_gengrid_item_append()
1942 * @see elm_gengrid_item_prepend()
1943 * @see elm_gengrid_item_insert_after()
1944 * @see elm_gengrid_item_del()
1948 EAPI Elm_Gengrid_Item *
1949 elm_gengrid_item_insert_before(Evas_Object *obj,
1950 const Elm_Gengrid_Item_Class *gic,
1952 Elm_Gengrid_Item *relative,
1954 const void *func_data)
1956 Elm_Gengrid_Item *item;
1957 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1958 EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
1959 Widget_Data *wd = elm_widget_data_get(obj);
1960 if (!wd) return NULL;
1962 item = _item_create(wd, gic, data, func, func_data);
1963 if (!item) return NULL;
1964 wd->items = eina_inlist_prepend_relative
1965 (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
1967 if (wd->calc_job) ecore_job_del(wd->calc_job);
1968 wd->calc_job = ecore_job_add(_calc_job, wd);
1974 * Insert and item after another in the Gengrid.
1976 * This inserts an item after another in the grid.
1978 * @param obj The Gengrid object.
1979 * @param gic The item class for the item.
1980 * @param data The item data.
1981 * @param relative The item to which insert after.
1982 * @param func Convenience function called when item is selected.
1983 * @param func_data Data passed to @p func above.
1984 * @return A handle to the item added or NULL if not possible.
1986 * @see elm_gengrid_item_append()
1987 * @see elm_gengrid_item_prepend()
1988 * @see elm_gengrid_item_insert_before()
1989 * @see elm_gengrid_item_del()
1993 EAPI Elm_Gengrid_Item *
1994 elm_gengrid_item_insert_after(Evas_Object *obj,
1995 const Elm_Gengrid_Item_Class *gic,
1997 Elm_Gengrid_Item *relative,
1999 const void *func_data)
2001 Elm_Gengrid_Item *item;
2002 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2003 EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
2004 Widget_Data *wd = elm_widget_data_get(obj);
2005 if (!wd) return NULL;
2007 item = _item_create(wd, gic, data, func, func_data);
2008 if (!item) return NULL;
2009 wd->items = eina_inlist_append_relative
2010 (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
2012 if (wd->calc_job) ecore_job_del(wd->calc_job);
2013 wd->calc_job = ecore_job_add(_calc_job, wd);
2019 * Remove an item from the Gengrid.
2021 * @param item The item to be removed.
2022 * @return @c EINA_TRUE on success or @c EINA_FALSE otherwise.
2024 * @see elm_gengrid_clear() to remove all items of the Gengrid.
2029 elm_gengrid_item_del(Elm_Gengrid_Item *item)
2031 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2032 if ((item->relcount > 0) || (item->walking > 0))
2034 item->delete_me = EINA_TRUE;
2035 elm_widget_item_pre_notify_del(item);
2037 item->wd->selected = eina_list_remove(item->wd->selected, item);
2038 if (item->gic->func.del)
2039 item->gic->func.del((void *)item->base.data, item->wd->self);
2047 * Set for what direction the Gengrid will expand.
2049 * @param obj The Gengrid object.
2050 * @param setting If @c EINA_TRUE the Gengrid will expand horizontally
2051 * or vertically if @c EINA_FALSE.
2056 elm_gengrid_horizontal_set(Evas_Object *obj,
2059 ELM_CHECK_WIDTYPE(obj, widtype);
2060 Widget_Data *wd = elm_widget_data_get(obj);
2062 if (setting == wd->horizontal) return;
2063 wd->horizontal = setting;
2065 /* Update the items to conform to the new layout */
2066 if (wd->calc_job) ecore_job_del(wd->calc_job);
2067 wd->calc_job = ecore_job_add(_calc_job, wd);
2071 * Get for what direction the Gengrid is expanded.
2073 * @param obj The Gengrid object.
2074 * @return If the Gengrid is expanded horizontally return @c EINA_TRUE
2075 * else @c EINA_FALSE.
2080 elm_gengrid_horizontal_get(const Evas_Object *obj)
2082 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2083 Widget_Data *wd = elm_widget_data_get(obj);
2084 if (!wd) return EINA_FALSE;
2085 return wd->horizontal;
2091 * This clears all items in the Gengrid, leaving it empty.
2093 * @param obj The Gengrid object.
2095 * @see elm_gengrid_item_del() to remove just one item.
2100 elm_gengrid_clear(Evas_Object *obj)
2102 ELM_CHECK_WIDTYPE(obj, widtype);
2103 Widget_Data *wd = elm_widget_data_get(obj);
2108 ecore_job_del(wd->calc_job);
2109 wd->calc_job = NULL;
2112 if (wd->walking > 0)
2114 Elm_Gengrid_Item *item;
2116 EINA_INLIST_FOREACH(wd->items, item)
2117 item->delete_me = 1;
2123 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
2125 wd->items = eina_inlist_remove(wd->items, wd->items);
2126 elm_widget_item_pre_notify_del(item);
2127 if (item->realized) _item_unrealize(item);
2128 if (item->gic->func.del)
2129 item->gic->func.del((void *)item->base.data, wd->self);
2130 if (item->long_timer) ecore_timer_del(item->long_timer);
2131 elm_widget_item_del(item);
2136 eina_list_free(wd->selected);
2137 wd->selected = NULL;
2145 evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
2146 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2150 * Get the real evas object of the Gengrid item
2152 * This returns the actual evas object used for the specified Gengrid
2153 * item. This may be NULL as it may not be created, and may be
2154 * deleted at any time by Gengrid. Do not modify this object (move,
2155 * resize, show, hide etc.) as Gengrid is controlling it. This
2156 * function is for querying, emitting custom signals or hooking lower
2157 * level callbacks for events. Do not delete this object under any
2160 * @param item The Gengrid item.
2161 * @return the evas object associated to this item.
2163 * @see elm_gengrid_item_data_get()
2167 EAPI const Evas_Object *
2168 elm_gengrid_item_object_get(const Elm_Gengrid_Item *item)
2170 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2171 return item->base.view;
2175 * Update the contents of an item
2177 * This updates an item by calling all the item class functions again
2178 * to get the icons, labels and states. Use this when the original
2179 * item data has changed and the changes are desired to be reflected.
2181 * @param item The item
2186 elm_gengrid_item_update(Elm_Gengrid_Item *item)
2188 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2189 if (!item->realized) return;
2190 if (item->want_unrealize) return;
2191 _item_unrealize(item);
2192 _item_realize(item);
2193 _item_place(item, item->x, item->y);
2197 * Returns the data associated to an item
2199 * This returns the data value passed on the elm_gengrid_item_append()
2200 * and related item addition calls.
2202 * @param item The Gengrid item.
2203 * @return the data associated to this item.
2205 * @see elm_gengrid_item_append()
2206 * @see elm_gengrid_item_object_get()
2211 elm_gengrid_item_data_get(const Elm_Gengrid_Item *item)
2213 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2214 return elm_widget_item_data_get(item);
2218 * Set the datan item from the gengrid item
2220 * This set the data value passed on the elm_gengrid_item_append() and
2221 * related item addition calls. This function will also call
2222 * elm_gengrid_item_update() so the item will be updated to reflect
2225 * @param item The item
2226 * @param data The new data pointer to set
2231 elm_gengrid_item_data_set(Elm_Gengrid_Item *item,
2234 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2235 elm_widget_item_data_set(item, data);
2236 elm_gengrid_item_update(item);
2240 * Get the item's coordinates.
2242 * This returns the logical position of the item whithin the Gengrid.
2244 * @param item The Gengrid item.
2245 * @param x The x-axis coordinate pointer.
2246 * @param y The y-axis coordinate pointer.
2251 elm_gengrid_item_pos_get(const Elm_Gengrid_Item *item,
2255 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2256 if (x) *x = item->x;
2257 if (y) *y = item->y;
2261 * Enable or disable multi-select in the Gengrid.
2263 * This enables (EINA_TRUE) or disables (EINA_FALSE) multi-select in
2264 * the Gengrid. This allows more than 1 item to be selected.
2266 * @param obj The Gengrid object.
2267 * @param multi Multi-select enabled/disabled
2272 elm_gengrid_multi_select_set(Evas_Object *obj,
2275 ELM_CHECK_WIDTYPE(obj, widtype);
2276 Widget_Data *wd = elm_widget_data_get(obj);
2282 * Get if multi-select in Gengrid is enabled or disabled
2284 * @param obj The Gengrid object
2285 * @return Multi-select enable/disable
2286 * (EINA_TRUE = enabled / EINA_FALSE = disabled)
2291 elm_gengrid_multi_select_get(const Evas_Object *obj)
2293 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2294 Widget_Data *wd = elm_widget_data_get(obj);
2295 if (!wd) return EINA_FALSE;
2300 * Get the selected item in the Gengrid
2302 * This gets the selected item in the Gengrid (if multi-select is
2303 * enabled only the first item in the list is selected - which is not
2304 * very useful, so see elm_gengrid_selected_items_get() for when
2305 * multi-select is used).
2307 * If no item is selected, NULL is returned.
2309 * @param obj The Gengrid object.
2310 * @return The selected item, or NULL if none.
2314 EAPI Elm_Gengrid_Item *
2315 elm_gengrid_selected_item_get(const Evas_Object *obj)
2317 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2318 Widget_Data *wd = elm_widget_data_get(obj);
2319 if (!wd) return NULL;
2320 if (wd->selected) return wd->selected->data;
2325 * Get a list of selected items in the Gengrid.
2327 * This returns a list of the selected items. This list pointer is
2328 * only valid so long as no items are selected or unselected (or
2329 * unselected implictly by deletion). The list contains
2330 * Elm_Gengrid_Item pointers.
2332 * @param obj The Gengrid object.
2333 * @return The list of selected items, or NULL if none are selected.
2337 EAPI const Eina_List *
2338 elm_gengrid_selected_items_get(const Evas_Object *obj)
2340 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2341 Widget_Data *wd = elm_widget_data_get(obj);
2342 if (!wd) return NULL;
2343 return wd->selected;
2347 * Set the selected state of an item.
2349 * This sets the selected state of an item. If multi-select is not
2350 * enabled and selected is EINA_TRUE, previously selected items are
2353 * @param item The item
2354 * @param selected The selected state.
2359 elm_gengrid_item_selected_set(Elm_Gengrid_Item *item,
2362 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2363 Widget_Data *wd = item->wd;
2365 if (item->delete_me) return;
2366 selected = !!selected;
2367 if (item->selected == selected) return;
2373 while (wd->selected)
2374 _item_unselect(wd->selected->data);
2376 _item_hilight(item);
2380 _item_unselect(item);
2384 * Get the selected state of an item.
2386 * This gets the selected state of an item (1 selected, 0 not selected).
2388 * @param item The item
2389 * @return The selected state
2394 elm_gengrid_item_selected_get(const Elm_Gengrid_Item *item)
2396 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2397 return item->selected;
2401 * Sets the disabled state of an item.
2403 * A disabled item cannot be selected or unselected. It will also
2404 * change appearance to disabled. This sets the disabled state (1
2405 * disabled, 0 not disabled).
2407 * @param item The item
2408 * @param disabled The disabled state
2413 elm_gengrid_item_disabled_set(Elm_Gengrid_Item *item,
2416 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2417 if (item->disabled == disabled) return;
2418 if (item->delete_me) return;
2419 item->disabled = !!disabled;
2423 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
2425 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
2430 * Get the disabled state of an item.
2432 * This gets the disabled state of the given item.
2434 * @param item The item
2435 * @return The disabled state
2440 elm_gengrid_item_disabled_get(const Elm_Gengrid_Item *item)
2442 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2443 if (item->delete_me) return EINA_FALSE;
2444 return item->disabled;
2447 static Evas_Object *
2448 _elm_gengrid_item_label_create(void *data,
2450 void *item __UNUSED__)
2452 Evas_Object *label = elm_label_add(obj);
2455 elm_object_style_set(label, "tooltip");
2456 elm_label_label_set(label, data);
2461 _elm_gengrid_item_label_del_cb(void *data,
2462 Evas_Object *obj __UNUSED__,
2463 void *event_info __UNUSED__)
2465 eina_stringshare_del(data);
2469 * Set the text to be shown in the gengrid item.
2471 * @param item Target item
2472 * @param text The text to set in the content
2474 * Setup the text as tooltip to object. The item can have only one
2475 * tooltip, so any previous tooltip data is removed.
2480 elm_gengrid_item_tooltip_text_set(Elm_Gengrid_Item *item,
2483 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2484 text = eina_stringshare_add(text);
2485 elm_gengrid_item_tooltip_content_cb_set(item, _elm_gengrid_item_label_create,
2487 _elm_gengrid_item_label_del_cb);
2491 * Set the content to be shown in the tooltip item
2493 * Setup the tooltip to item. The item can have only one tooltip, so
2494 * any previous tooltip data is removed. @p func(with @p data) will be
2495 * called every time that need show the tooltip and it should return a
2496 * valid Evas_Object. This object is then managed fully by tooltip
2497 * system and is deleted when the tooltip is gone.
2499 * @param item the gengrid item being attached a tooltip.
2500 * @param func the function used to create the tooltip contents.
2501 * @param data what to provide to @a func as callback data/context.
2502 * @param del_cb called when data is not needed anymore, either when
2503 * another callback replaces @func, the tooltip is unset with
2504 * elm_gengrid_item_tooltip_unset() or the owner @an item
2505 * dies. This callback receives as the first parameter the
2506 * given @a data, and @c event_info is the item.
2511 elm_gengrid_item_tooltip_content_cb_set(Elm_Gengrid_Item *item,
2512 Elm_Tooltip_Item_Content_Cb func,
2514 Evas_Smart_Cb del_cb)
2516 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
2518 if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
2521 if (item->tooltip.del_cb)
2522 item->tooltip.del_cb((void *)item->tooltip.data,
2523 item->base.widget, item);
2524 item->tooltip.content_cb = func;
2525 item->tooltip.data = data;
2526 item->tooltip.del_cb = del_cb;
2527 if (item->base.view)
2529 elm_widget_item_tooltip_content_cb_set(item,
2530 item->tooltip.content_cb,
2531 item->tooltip.data, NULL);
2532 elm_widget_item_tooltip_style_set(item, item->tooltip.style);
2538 if (del_cb) del_cb((void *)data, NULL, NULL);
2542 * Unset tooltip from item
2544 * @param item gengrid item to remove previously set tooltip.
2546 * Remove tooltip from item. The callback provided as del_cb to
2547 * elm_gengrid_item_tooltip_content_cb_set() will be called to notify
2548 * it is not used anymore.
2550 * @see elm_gengrid_item_tooltip_content_cb_set()
2555 elm_gengrid_item_tooltip_unset(Elm_Gengrid_Item *item)
2557 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2558 if ((item->base.view) && (item->tooltip.content_cb))
2559 elm_widget_item_tooltip_unset(item);
2561 if (item->tooltip.del_cb)
2562 item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
2563 item->tooltip.del_cb = NULL;
2564 item->tooltip.content_cb = NULL;
2565 item->tooltip.data = NULL;
2566 if (item->tooltip.style)
2567 elm_gengrid_item_tooltip_style_set(item, NULL);
2571 * Sets a different style for this item tooltip.
2573 * @note before you set a style you should define a tooltip with
2574 * elm_gengrid_item_tooltip_content_cb_set() or
2575 * elm_gengrid_item_tooltip_text_set()
2577 * @param item gengrid item with tooltip already set.
2578 * @param style the theme style to use (default, transparent, ...)
2583 elm_gengrid_item_tooltip_style_set(Elm_Gengrid_Item *item,
2586 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2587 eina_stringshare_replace(&item->tooltip.style, style);
2588 if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
2592 * Get the style for this item tooltip.
2594 * @param item gengrid item with tooltip already set.
2595 * @return style the theme style in use, defaults to "default". If the
2596 * object does not have a tooltip set, then NULL is returned.
2601 elm_gengrid_item_tooltip_style_get(const Elm_Gengrid_Item *item)
2603 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2604 return item->tooltip.style;
2608 * Set the cursor to be shown when mouse is over the gengrid item
2610 * @param item Target item
2611 * @param cursor the cursor name to be used.
2613 * @see elm_object_cursor_set()
2617 elm_gengrid_item_cursor_set(Elm_Gengrid_Item *item,
2620 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2621 eina_stringshare_replace(&item->mouse_cursor, cursor);
2622 if (item->base.view) elm_widget_item_cursor_set(item, cursor);
2626 * Get the cursor to be shown when mouse is over the gengrid item
2628 * @param item gengrid item with cursor already set.
2629 * @return the cursor name.
2634 elm_gengrid_item_cursor_get(const Elm_Gengrid_Item *item)
2636 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2637 return elm_widget_item_cursor_get(item);
2641 * Unset the cursor to be shown when mouse is over the gengrid item
2643 * @param item Target item
2645 * @see elm_object_cursor_unset()
2649 elm_gengrid_item_cursor_unset(Elm_Gengrid_Item *item)
2651 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2652 if (!item->mouse_cursor)
2655 if (item->base.view)
2656 elm_widget_item_cursor_unset(item);
2658 eina_stringshare_del(item->mouse_cursor);
2659 item->mouse_cursor = NULL;
2663 * Sets a different style for this item cursor.
2665 * @note before you set a style you should define a cursor with
2666 * elm_gengrid_item_cursor_set()
2668 * @param item gengrid item with cursor already set.
2669 * @param style the theme style to use (default, transparent, ...)
2674 elm_gengrid_item_cursor_style_set(Elm_Gengrid_Item *item,
2677 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2678 elm_widget_item_cursor_style_set(item, style);
2682 * Get the style for this item cursor.
2684 * @param item gengrid item with cursor already set.
2685 * @return style the theme style in use, defaults to "default". If the
2686 * object does not have a cursor set, then NULL is returned.
2691 elm_gengrid_item_cursor_style_get(const Elm_Gengrid_Item *item)
2693 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2694 return elm_widget_item_cursor_style_get(item);
2698 * Set if the cursor set should be searched on the theme or should use
2699 * the provided by the engine, only.
2701 * @note before you set if should look on theme you should define a
2702 * cursor with elm_object_cursor_set(). By default it will only look
2703 * for cursors provided by the engine.
2705 * @param item widget item with cursor already set.
2706 * @param engine_only boolean to define it cursors should be looked
2707 * only between the provided by the engine or searched on widget's
2713 elm_gengrid_item_cursor_engine_only_set(Elm_Gengrid_Item *item,
2714 Eina_Bool engine_only)
2716 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2717 elm_widget_item_cursor_engine_only_set(item, engine_only);
2721 * Get the cursor engine only usage for this item cursor.
2723 * @param item widget item with cursor already set.
2724 * @return engine_only boolean to define it cursors should be looked
2725 * only between the provided by the engine or searched on widget's
2726 * theme as well. If the object does not have a cursor set, then
2727 * EINA_FALSE is returned.
2732 elm_gengrid_item_cursor_engine_only_get(const Elm_Gengrid_Item *item)
2734 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2735 return elm_widget_item_cursor_engine_only_get(item);
2739 * Set the reorder mode
2741 * @param obj The Gengrid object
2742 * @param reorder_mode The reorder mode
2743 * (EINA_TRUE = on, EINA_FALSE = off)
2748 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2749 Eina_Bool reorder_mode)
2751 ELM_CHECK_WIDTYPE(obj, widtype);
2752 Widget_Data *wd = elm_widget_data_get(obj);
2754 wd->reorder_mode = reorder_mode;
2758 * Get the reorder mode
2760 * @param obj The Gengrid object
2761 * @return The reorder mode
2762 * (EINA_TRUE = on, EINA_FALSE = off)
2767 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
2769 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2770 Widget_Data *wd = elm_widget_data_get(obj);
2771 if (!wd) return EINA_FALSE;
2772 return wd->reorder_mode;
2776 * Set the always select mode.
2778 * Cells will only call their selection func and callback when first
2779 * becoming selected. Any further clicks will do nothing, unless you
2780 * enable always select with
2781 * elm_gengrid_always_select_mode_set(). This means even if selected,
2782 * every click will make the selected callbacks be called.
2784 * @param obj The Gengrid object
2785 * @param always_select The always select mode (EINA_TRUE = on,
2791 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2792 Eina_Bool always_select)
2794 ELM_CHECK_WIDTYPE(obj, widtype);
2795 Widget_Data *wd = elm_widget_data_get(obj);
2797 wd->always_select = always_select;
2801 * Get the always select mode.
2803 * @param obj The Gengrid object.
2804 * @return The always select mode (EINA_TRUE = on, EINA_FALSE = off)
2809 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2811 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2812 Widget_Data *wd = elm_widget_data_get(obj);
2813 if (!wd) return EINA_FALSE;
2814 return wd->always_select;
2818 * Set no select mode.
2820 * This will turn off the ability to select items entirely and they
2821 * will neither appear selected nor call selected callback functions.
2823 * @param obj The Gengrid object
2824 * @param no_select The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2829 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2830 Eina_Bool no_select)
2832 ELM_CHECK_WIDTYPE(obj, widtype);
2833 Widget_Data *wd = elm_widget_data_get(obj);
2835 wd->no_select = no_select;
2839 * Gets no select mode.
2841 * @param obj The Gengrid object
2842 * @return The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2847 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2849 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2850 Widget_Data *wd = elm_widget_data_get(obj);
2851 if (!wd) return EINA_FALSE;
2852 return wd->no_select;
2858 * This will enable or disable the scroller bounce mode for the
2859 * Gengrid. See elm_scroller_bounce_set() for details.
2861 * @param obj The Gengrid object
2862 * @param h_bounce Allow bounce horizontally
2863 * @param v_bounce Allow bounce vertically
2868 elm_gengrid_bounce_set(Evas_Object *obj,
2872 ELM_CHECK_WIDTYPE(obj, widtype);
2873 Widget_Data *wd = elm_widget_data_get(obj);
2875 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
2876 wd->h_bounce = h_bounce;
2877 wd->v_bounce = v_bounce;
2881 * Get the bounce mode
2883 * @param obj The Gengrid object
2884 * @param h_bounce Allow bounce horizontally
2885 * @param v_bounce Allow bounce vertically
2890 elm_gengrid_bounce_get(const Evas_Object *obj,
2891 Eina_Bool *h_bounce,
2892 Eina_Bool *v_bounce)
2894 ELM_CHECK_WIDTYPE(obj, widtype);
2895 Widget_Data *wd = elm_widget_data_get(obj);
2897 *h_bounce = wd->h_bounce;
2898 *v_bounce = wd->v_bounce;
2902 * Get all items in the Gengrid.
2904 * This returns a list of the Gengrid items. The list contains
2905 * Elm_Gengrid_Item pointers.
2907 * @param obj The Gengrid object.
2908 * @return The list of items, or NULL if none.
2914 * Set gengrid scroll page size relative to viewport size.
2916 * The gengrid scroller is capable of limiting scrolling by the user
2917 * to "pages" That is to jump by and only show a "whole page" at a
2918 * time as if the continuous area of the scroller content is split
2919 * into page sized pieces. This sets the size of a page relative to
2920 * the viewport of the scroller. 1.0 is "1 viewport" is size
2921 * (horizontally or vertically). 0.0 turns it off in that axis. This
2922 * is mutually exclusive with page size (see
2923 * elm_gengrid_page_size_set() for more information). Likewise 0.5 is
2924 * "half a viewport". Sane usable valus are normally between 0.0 and
2925 * 1.0 including 1.0. If you only want 1 axis to be page "limited",
2926 * use 0.0 for the other axis.
2928 * @param obj The gengrid object
2929 * @param h_pagerel The horizontal page relative size
2930 * @param v_pagerel The vertical page relative size
2935 elm_gengrid_page_relative_set(Evas_Object *obj,
2939 Evas_Coord pagesize_h;
2940 Evas_Coord pagesize_v;
2942 ELM_CHECK_WIDTYPE(obj, widtype);
2943 Widget_Data *wd = elm_widget_data_get(obj);
2946 elm_smart_scroller_paging_get(wd->scr, NULL, NULL, &pagesize_h, &pagesize_v);
2947 elm_smart_scroller_paging_set(wd->scr, h_pagerel, v_pagerel, pagesize_h,
2952 * Get gengrid scroll page size relative to viewport size.
2954 * The gengrid scroller is capable of limiting scrolling by the user
2955 * to "pages" That is to jump by and only show a "whole page" at a
2956 * time as if the continuous area of the scroller content is split
2957 * into page sized pieces. This sets the size of a page relative to
2958 * the viewport of the scroller. 1.0 is "1 viewport" is size
2959 * (horizontally or vertically). 0.0 turns it off in that axis. This
2960 * is mutually exclusive with page size (see
2961 * elm_gengrid_page_size_set() for more information). Likewise 0.5 is
2962 * "half a viewport". Sane usable valus are normally between 0.0 and
2963 * 1.0 including 1.0. If you only want 1 axis to be page "limited",
2964 * use 0.0 for the other axis.
2966 * @param obj The gengrid object
2967 * @param h_pagerel The horizontal page relative size
2968 * @param v_pagerel The vertical page relative size
2973 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
2975 ELM_CHECK_WIDTYPE(obj, widtype);
2976 Widget_Data *wd = elm_widget_data_get(obj);
2979 elm_smart_scroller_paging_get(wd->scr, h_pagerel, v_pagerel, NULL, NULL);
2983 * Set gengrid scroll page size.
2985 * See also elm_gengrid_page_relative_set(). This, instead of a page
2986 * size being relative to the viewport, sets it to an absolute fixed
2987 * value, with 0 turning it off for that axis.
2989 * @param obj The gengrid object
2990 * @param h_pagesize The horizontal page size
2991 * @param v_pagesize The vertical page size
2996 elm_gengrid_page_size_set(Evas_Object *obj,
2997 Evas_Coord h_pagesize,
2998 Evas_Coord v_pagesize)
3003 ELM_CHECK_WIDTYPE(obj, widtype);
3004 Widget_Data *wd = elm_widget_data_get(obj);
3006 elm_smart_scroller_paging_get(wd->scr, &pagerel_h, &pagerel_v, NULL, NULL);
3007 elm_smart_scroller_paging_set(wd->scr, pagerel_h, pagerel_v, h_pagesize,
3012 * Get the first item in the gengrid
3014 * This returns the first item in the list.
3016 * @param obj The gengrid object
3017 * @return The first item, or NULL if none
3021 EAPI Elm_Gengrid_Item *
3022 elm_gengrid_first_item_get(const Evas_Object *obj)
3024 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3025 Widget_Data *wd = elm_widget_data_get(obj);
3026 if (!wd) return NULL;
3027 if (!wd->items) return NULL;
3028 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
3029 while ((item) && (item->delete_me))
3030 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
3035 * Get the last item in the gengrid
3037 * This returns the last item in the list.
3039 * @return The last item, or NULL if none
3043 EAPI Elm_Gengrid_Item *
3044 elm_gengrid_last_item_get(const Evas_Object *obj)
3046 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3047 Widget_Data *wd = elm_widget_data_get(obj);
3048 if (!wd) return NULL;
3049 if (!wd->items) return NULL;
3050 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
3051 while ((item) && (item->delete_me))
3052 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
3057 * Get the next item in the gengrid
3059 * This returns the item after the item @p item.
3061 * @param item The item
3062 * @return The item after @p item, or NULL if none
3066 EAPI Elm_Gengrid_Item *
3067 elm_gengrid_item_next_get(const Elm_Gengrid_Item *item)
3069 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
3072 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
3073 if ((item) && (!item->delete_me)) break;
3075 return (Elm_Gengrid_Item *)item;
3079 * Get the previous item in the gengrid
3081 * This returns the item before the item @p item.
3083 * @param item The item
3084 * @return The item before @p item, or NULL if none
3088 EAPI Elm_Gengrid_Item *
3089 elm_gengrid_item_prev_get(const Elm_Gengrid_Item *item)
3091 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
3094 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
3095 if ((item) && (!item->delete_me)) break;
3097 return (Elm_Gengrid_Item *)item;
3101 * Get the gengrid object from an item
3103 * This returns the gengrid object itself that an item belongs to.
3105 * @param item The item
3106 * @return The gengrid object
3111 elm_gengrid_item_gengrid_get(const Elm_Gengrid_Item *item)
3113 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
3114 return item->base.widget;
3118 * Show the given item
3120 * This causes gengrid to jump to the given item @p item and show it
3121 * (by scrolling), if it is not fully visible.
3123 * @param item The item
3128 elm_gengrid_item_show(Elm_Gengrid_Item *item)
3130 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
3131 Widget_Data *wd = elm_widget_data_get(item->wd->self);
3132 Evas_Coord minx = 0, miny = 0;
3135 if ((!item) || (item->delete_me)) return;
3136 _pan_min_get(wd->pan_smart, &minx, &miny);
3138 elm_smart_scroller_child_region_show(item->wd->scr,
3139 item->x * wd->item_width + minx,
3140 item->y * wd->item_height + miny,
3141 item->wd->item_width,
3142 item->wd->item_height);
3146 * Bring in the given item
3148 * This causes gengrig to jump to the given item @p item and show it
3149 * (by scrolling), if it is not fully visible. This may use animation
3150 * to do so and take a period of time
3152 * @param item The item
3157 elm_gengrid_item_bring_in(Elm_Gengrid_Item *item)
3159 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
3160 if (item->delete_me) return;
3162 Evas_Coord minx = 0, miny = 0;
3163 Widget_Data *wd = elm_widget_data_get(item->wd->self);
3165 _pan_min_get(wd->pan_smart, &minx, &miny);
3167 elm_smart_scroller_region_bring_in(item->wd->scr,
3168 item->x * wd->item_width + minx,
3169 item->y * wd->item_height + miny,
3170 item->wd->item_width,
3171 item->wd->item_height);