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";
272 static const Evas_Smart_Cb_Description _signals[] = {
273 {SIG_CLICKED_DOUBLE, ""},
275 {SIG_UNSELECTED, ""},
277 {SIG_UNREALIZED, ""},
279 {SIG_DRAG_START_UP, ""},
280 {SIG_DRAG_START_DOWN, ""},
281 {SIG_DRAG_START_LEFT, ""},
282 {SIG_DRAG_START_RIGHT, ""},
286 {SIG_SCROLL_DRAG_START, ""},
287 {SIG_SCROLL_DRAG_STOP, ""},
294 _event_hook(Evas_Object *obj,
295 Evas_Object *src __UNUSED__,
296 Evas_Callback_Type type,
299 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
300 Evas_Event_Key_Down *ev = event_info;
301 Widget_Data *wd = elm_widget_data_get(obj);
302 if (!wd) return EINA_FALSE;
303 if (!wd->items) return EINA_FALSE;
304 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
305 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
307 Elm_Gengrid_Item *item = NULL;
310 Evas_Coord step_x = 0;
311 Evas_Coord step_y = 0;
314 Evas_Coord page_x = 0;
315 Evas_Coord page_y = 0;
317 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
318 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
319 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
320 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
322 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
324 if ((wd->horizontal) &&
325 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
326 (_item_multi_select_up(wd)))
327 || (_item_single_select_up(wd))))
329 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
332 else if ((!wd->horizontal) &&
333 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
334 (_item_multi_select_left(wd)))
335 || (_item_single_select_left(wd))))
337 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
343 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
345 if ((wd->horizontal) &&
346 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
347 (_item_multi_select_down(wd)))
348 || (_item_single_select_down(wd))))
350 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
353 else if ((!wd->horizontal) &&
354 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
355 (_item_multi_select_right(wd)))
356 || (_item_single_select_right(wd))))
358 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
364 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
366 if ((wd->horizontal) &&
367 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
368 (_item_multi_select_left(wd)))
369 || (_item_single_select_left(wd))))
371 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
374 else if ((!wd->horizontal) &&
375 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
376 (_item_multi_select_up(wd)))
377 || (_item_single_select_up(wd))))
379 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
385 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
387 if ((wd->horizontal) &&
388 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
389 (_item_multi_select_right(wd)))
390 || (_item_single_select_right(wd))))
392 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
395 else if ((!wd->horizontal) &&
396 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
397 (_item_multi_select_down(wd)))
398 || (_item_single_select_down(wd))))
400 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
406 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
408 item = elm_gengrid_first_item_get(obj);
409 elm_gengrid_item_bring_in(item);
410 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
413 else if ((!strcmp(ev->keyname, "End")) || (!strcmp(ev->keyname, "KP_End")))
415 item = elm_gengrid_last_item_get(obj);
416 elm_gengrid_item_bring_in(item);
417 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
420 else if ((!strcmp(ev->keyname, "Prior")) ||
421 (!strcmp(ev->keyname, "KP_Prior")))
426 x -= -(page_x * v_w) / 100;
433 y -= -(page_y * v_h) / 100;
438 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
443 x += -(page_x * v_w) / 100;
450 y += -(page_y * v_h) / 100;
455 else if (!strcmp(ev->keyname, "Escape"))
457 if (!_deselect_all_items(wd)) return EINA_FALSE;
458 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
461 else if ((!strcmp(ev->keyname, "Return")) ||
462 (!strcmp(ev->keyname, "KP_Enter")) ||
463 (!strcmp(ev->keyname, "space")))
465 item = elm_gengrid_selected_item_get(obj);
466 evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
467 evas_object_smart_callback_call(item->wd->self, "clicked", item); // will be removed
469 else return EINA_FALSE;
471 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
472 elm_smart_scroller_child_pos_set(wd->scr, x, y);
477 _deselect_all_items(Widget_Data *wd)
479 if (!wd->selected) return EINA_FALSE;
481 elm_gengrid_item_selected_set(wd->selected->data, EINA_FALSE);
487 _item_multi_select_left(Widget_Data *wd)
489 if (!wd->selected) return EINA_FALSE;
491 Elm_Gengrid_Item *prev = elm_gengrid_item_prev_get(wd->last_selected_item);
492 if (!prev) return EINA_TRUE;
493 if (elm_gengrid_item_selected_get(prev))
495 elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
496 wd->last_selected_item = prev;
497 elm_gengrid_item_show(wd->last_selected_item);
501 elm_gengrid_item_selected_set(prev, EINA_TRUE);
502 elm_gengrid_item_show(prev);
509 _item_multi_select_right(Widget_Data *wd)
511 if (!wd->selected) return EINA_FALSE;
513 Elm_Gengrid_Item *next = elm_gengrid_item_next_get(wd->last_selected_item);
514 if (!next) return EINA_TRUE;
515 if (elm_gengrid_item_selected_get(next))
517 elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
518 wd->last_selected_item = next;
519 elm_gengrid_item_show(wd->last_selected_item);
523 elm_gengrid_item_selected_set(next, EINA_TRUE);
524 elm_gengrid_item_show(next);
531 _item_multi_select_up(Widget_Data *wd)
534 Eina_Bool r = EINA_TRUE;
536 if (!wd->selected) return EINA_FALSE;
538 for (i = 0; (r) && (i < wd->nmax); i++)
539 r &= _item_multi_select_left(wd);
545 _item_multi_select_down(Widget_Data *wd)
548 Eina_Bool r = EINA_TRUE;
550 if (!wd->selected) return EINA_FALSE;
552 for (i = 0; (r) && (i < wd->nmax); i++)
553 r &= _item_multi_select_right(wd);
559 _item_single_select_up(Widget_Data *wd)
563 Elm_Gengrid_Item *prev;
567 prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
568 while ((prev) && (prev->delete_me))
569 prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
570 elm_gengrid_item_selected_set(prev, EINA_TRUE);
571 elm_gengrid_item_show(prev);
574 else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
576 if (!prev) return EINA_FALSE;
578 for (i = 1; i < wd->nmax; i++)
580 Elm_Gengrid_Item *tmp = elm_gengrid_item_prev_get(prev);
581 if (!tmp) return EINA_FALSE;
585 _deselect_all_items(wd);
587 elm_gengrid_item_selected_set(prev, EINA_TRUE);
588 elm_gengrid_item_show(prev);
593 _item_single_select_down(Widget_Data *wd)
597 Elm_Gengrid_Item *next;
601 next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
602 while ((next) && (next->delete_me))
603 next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
604 elm_gengrid_item_selected_set(next, EINA_TRUE);
605 elm_gengrid_item_show(next);
608 else next = elm_gengrid_item_next_get(wd->last_selected_item);
610 if (!next) return EINA_FALSE;
612 for (i = 1; i < wd->nmax; i++)
614 Elm_Gengrid_Item *tmp = elm_gengrid_item_next_get(next);
615 if (!tmp) return EINA_FALSE;
619 _deselect_all_items(wd);
621 elm_gengrid_item_selected_set(next, EINA_TRUE);
622 elm_gengrid_item_show(next);
627 _item_single_select_left(Widget_Data *wd)
629 Elm_Gengrid_Item *prev;
632 prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
633 while ((prev) && (prev->delete_me))
634 prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
636 else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
638 if (!prev) return EINA_FALSE;
640 _deselect_all_items(wd);
642 elm_gengrid_item_selected_set(prev, EINA_TRUE);
643 elm_gengrid_item_show(prev);
648 _item_single_select_right(Widget_Data *wd)
650 Elm_Gengrid_Item *next;
653 next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
654 while ((next) && (next->delete_me))
655 next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
657 else next = elm_gengrid_item_next_get(wd->last_selected_item);
659 if (!next) return EINA_FALSE;
661 _deselect_all_items(wd);
663 elm_gengrid_item_selected_set(next, EINA_TRUE);
664 elm_gengrid_item_show(next);
669 _on_focus_hook(void *data __UNUSED__,
672 Widget_Data *wd = elm_widget_data_get(obj);
674 if (elm_widget_focus_get(obj))
676 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
677 evas_object_focus_set(wd->self, EINA_TRUE);
678 if ((wd->selected) && (!wd->last_selected_item))
679 wd->last_selected_item = eina_list_data_get(wd->selected);
683 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
684 evas_object_focus_set(wd->self, EINA_FALSE);
689 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
691 Widget_Data *wd = elm_widget_data_get(obj);
692 Elm_Gengrid_Item *item;
694 elm_smart_scroller_mirrored_set(wd->scr, rtl);
695 if (!wd->items) return;
696 item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
700 edje_object_mirrored_set(item->base.view, rtl);
701 elm_gengrid_item_update(item);
702 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
707 _theme_hook(Evas_Object *obj)
709 Widget_Data *wd = elm_widget_data_get(obj);
711 _elm_widget_mirrored_reload(obj);
712 _mirrored_set(obj, elm_widget_mirrored_get(obj));
713 elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
714 elm_widget_style_get(obj));
718 _del_pre_hook(Evas_Object *obj)
720 Widget_Data *wd = elm_widget_data_get(obj);
722 elm_gengrid_clear(obj);
723 evas_object_del(wd->pan_smart);
724 wd->pan_smart = NULL;
728 _del_hook(Evas_Object *obj)
730 Widget_Data *wd = elm_widget_data_get(obj);
735 _signal_emit_hook(Evas_Object *obj,
736 const char *emission,
739 Widget_Data *wd = elm_widget_data_get(obj);
741 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
746 _mouse_move(void *data,
747 Evas *evas __UNUSED__,
751 Elm_Gengrid_Item *item = data;
752 Evas_Event_Mouse_Move *ev = event_info;
753 Evas_Coord minw = 0, minh = 0, x, y, dx, dy, adx, ady;
754 Evas_Coord ox, oy, ow, oh, it_scrl_x, it_scrl_y;
756 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
758 if (!item->wd->on_hold)
760 item->wd->on_hold = EINA_TRUE;
761 if (!item->wd->wasselected)
762 _item_unselect(item);
765 if ((item->dragging) && (item->down))
767 if (item->long_timer)
769 ecore_timer_del(item->long_timer);
770 item->long_timer = NULL;
772 evas_object_smart_callback_call(item->wd->self, SIG_DRAG, item);
775 if ((!item->down) || (item->wd->longpressed))
777 if (item->long_timer)
779 ecore_timer_del(item->long_timer);
780 item->long_timer = NULL;
782 if ((item->wd->reorder_mode) && (item->wd->reorder_item))
784 evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &ow, &oh);
786 it_scrl_x = ev->cur.canvas.x - item->wd->reorder_item->dx;
787 it_scrl_y = ev->cur.canvas.y - item->wd->reorder_item->dy;
789 if (it_scrl_x < ox) item->wd->reorder_item_x = ox;
790 else if (it_scrl_x + item->wd->item_width > ox + ow)
791 item->wd->reorder_item_x = ox + ow - item->wd->item_width;
792 else item->wd->reorder_item_x = it_scrl_x;
794 if (it_scrl_y < oy) item->wd->reorder_item_y = oy;
795 else if (it_scrl_y + item->wd->item_height > oy + oh)
796 item->wd->reorder_item_y = oy + oh - item->wd->item_height;
797 else item->wd->reorder_item_y = it_scrl_y;
799 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
800 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
804 if (!item->display_only)
805 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
806 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
807 x = ev->cur.canvas.x - x;
808 y = ev->cur.canvas.y - y;
811 if (adx < 0) adx = -dx;
814 if (ady < 0) ady = -dy;
817 if ((adx > minw) || (ady > minh))
819 const char *left_drag, *right_drag;
820 if (!elm_widget_mirrored_get(item->wd->self))
822 left_drag = SIG_DRAG_START_LEFT;
823 right_drag = SIG_DRAG_START_RIGHT;
827 left_drag = SIG_DRAG_START_RIGHT;
828 right_drag = SIG_DRAG_START_LEFT;
832 if (item->long_timer)
834 ecore_timer_del(item->long_timer);
835 item->long_timer = NULL;
837 if (!item->wd->wasselected)
838 _item_unselect(item);
842 evas_object_smart_callback_call(item->wd->self, SIG_DRAG_START_UP,
847 evas_object_smart_callback_call(item->wd->self,
854 evas_object_smart_callback_call(item->wd->self,
855 SIG_DRAG_START_DOWN, item);
859 evas_object_smart_callback_call(item->wd->self,
862 evas_object_smart_callback_call(item->wd->self,
870 _long_press(void *data)
872 Elm_Gengrid_Item *item = data;
874 item->long_timer = NULL;
875 if ((item->disabled) || (item->dragging)) return ECORE_CALLBACK_CANCEL;
876 item->wd->longpressed = EINA_TRUE;
877 evas_object_smart_callback_call(item->wd->self, "longpressed", item);
878 if (item->wd->reorder_mode)
880 item->wd->reorder_item = item;
881 evas_object_raise(item->base.view);
882 elm_smart_scroller_hold_set(item->wd->scr, EINA_TRUE);
883 elm_smart_scroller_bounce_allow_set(item->wd->scr, EINA_FALSE, EINA_FALSE);
884 edje_object_signal_emit(item->base.view, "elm,state,reorder_enabled", "elm");
886 return ECORE_CALLBACK_CANCEL;
890 _mouse_down(void *data,
891 Evas *evas __UNUSED__,
895 Elm_Gengrid_Item *item = data;
896 Evas_Event_Mouse_Down *ev = event_info;
899 if (ev->button != 1) return;
902 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
903 item->dx = ev->canvas.x - x;
904 item->dy = ev->canvas.y - y;
905 item->wd->longpressed = EINA_FALSE;
906 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
907 else item->wd->on_hold = EINA_FALSE;
908 item->wd->wasselected = item->selected;
910 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
912 evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
913 evas_object_smart_callback_call(item->wd->self, "clicked", item); // will be removed
915 if (item->long_timer) ecore_timer_del(item->long_timer);
917 item->long_timer = ecore_timer_add(_elm_config->longpress_timeout,
920 item->long_timer = NULL;
924 _mouse_up(void *data,
925 Evas *evas __UNUSED__,
926 Evas_Object *obj __UNUSED__,
929 Elm_Gengrid_Item *item = data;
930 Evas_Event_Mouse_Up *ev = event_info;
931 Eina_Bool dragged = EINA_FALSE;
933 if (ev->button != 1) return;
934 item->down = EINA_FALSE;
935 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
936 else item->wd->on_hold = EINA_FALSE;
937 if (item->long_timer)
939 ecore_timer_del(item->long_timer);
940 item->long_timer = NULL;
944 item->dragging = EINA_FALSE;
945 evas_object_smart_callback_call(item->wd->self, SIG_DRAG_STOP, item);
948 if (item->wd->on_hold)
950 item->wd->longpressed = EINA_FALSE;
951 item->wd->on_hold = EINA_FALSE;
954 if ((item->wd->reorder_mode) && (item->wd->reorder_item))
956 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
957 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
959 evas_object_smart_callback_call(item->wd->self, "moved", item->wd->reorder_item);
960 item->wd->reorder_item = NULL;
961 elm_smart_scroller_hold_set(item->wd->scr, EINA_FALSE);
962 elm_smart_scroller_bounce_allow_set(item->wd->scr, item->wd->h_bounce, item->wd->v_bounce);
963 edje_object_signal_emit(item->base.view, "elm,state,reorder_disabled", "elm");
965 if (item->wd->longpressed)
967 item->wd->longpressed = EINA_FALSE;
968 if (!item->wd->wasselected) _item_unselect(item);
969 item->wd->wasselected = EINA_FALSE;
974 if (item->want_unrealize) _item_unrealize(item);
976 if ((item->disabled) || (dragged)) return;
984 else _item_unselect(item);
990 while (item->wd->selected)
991 _item_unselect(item->wd->selected->data);
995 const Eina_List *l, *l_next;
996 Elm_Gengrid_Item *item2;
998 EINA_LIST_FOREACH_SAFE(item->wd->selected, l, l_next, item2)
999 if (item2 != item) _item_unselect(item2);
1001 _item_hilight(item);
1007 _item_hilight(Elm_Gengrid_Item *item)
1009 if ((item->wd->no_select) || (item->delete_me) || (item->hilighted)) return;
1010 edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
1011 item->hilighted = EINA_TRUE;
1015 _item_realize(Elm_Gengrid_Item *item)
1020 if ((item->realized) || (item->delete_me)) return;
1021 item->base.view = edje_object_add(evas_object_evas_get(item->wd->self));
1022 edje_object_scale_set(item->base.view, elm_widget_scale_get(item->wd->self) *
1023 _elm_config->scale);
1024 edje_object_mirrored_set(item->base.view, elm_widget_mirrored_get(item->base.widget));
1025 evas_object_smart_member_add(item->base.view, item->wd->pan_smart);
1026 elm_widget_sub_object_add(item->wd->self, item->base.view);
1027 snprintf(style, sizeof(style), "item/%s",
1028 item->gic->item_style ? item->gic->item_style : "default");
1029 _elm_theme_object_set(item->wd->self, item->base.view, "gengrid", style,
1030 elm_widget_style_get(item->wd->self));
1032 evas_object_rectangle_add(evas_object_evas_get(item->wd->self));
1033 evas_object_color_set(item->spacer, 0, 0, 0, 0);
1034 elm_widget_sub_object_add(item->wd->self, item->spacer);
1035 evas_object_size_hint_min_set(item->spacer, 2 * _elm_config->scale, 1);
1036 edje_object_part_swallow(item->base.view, "elm.swallow.pad", item->spacer);
1038 if (item->gic->func.label_get)
1044 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
1046 EINA_LIST_FOREACH(item->labels, l, key)
1048 char *s = item->gic->func.label_get
1049 ((void *)item->base.data, item->wd->self, l->data);
1052 edje_object_part_text_set(item->base.view, l->data, s);
1058 if (item->gic->func.icon_get)
1064 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
1066 EINA_LIST_FOREACH(item->icons, l, key)
1068 Evas_Object *ic = item->gic->func.icon_get
1069 ((void *)item->base.data, item->wd->self, l->data);
1072 item->icon_objs = eina_list_append(item->icon_objs, ic);
1073 edje_object_part_swallow(item->base.view, key, ic);
1074 evas_object_show(ic);
1075 elm_widget_sub_object_add(item->wd->self, ic);
1080 if (item->gic->func.state_get)
1086 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
1088 EINA_LIST_FOREACH(item->states, l, key)
1090 Eina_Bool on = item->gic->func.state_get
1091 ((void *)item->base.data, item->wd->self, l->data);
1094 snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1095 edje_object_signal_emit(item->base.view, buf, "elm");
1100 if ((!item->wd->item_width) && (!item->wd->item_height))
1102 edje_object_size_min_restricted_calc(item->base.view,
1103 &item->wd->item_width,
1104 &item->wd->item_height,
1105 item->wd->item_width,
1106 item->wd->item_height);
1107 elm_coords_finger_size_adjust(1, &item->wd->item_width,
1108 1, &item->wd->item_height);
1111 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_DOWN,
1113 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_UP,
1115 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_MOVE,
1119 edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
1121 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1123 evas_object_show(item->base.view);
1125 if (item->tooltip.content_cb)
1127 elm_widget_item_tooltip_content_cb_set(item,
1128 item->tooltip.content_cb,
1129 item->tooltip.data, NULL);
1130 elm_widget_item_tooltip_style_set(item, item->tooltip.style);
1133 if (item->mouse_cursor)
1134 elm_widget_item_cursor_set(item, item->mouse_cursor);
1136 item->realized = EINA_TRUE;
1137 item->want_unrealize = EINA_FALSE;
1141 _item_unrealize(Elm_Gengrid_Item *item)
1145 if (!item->realized) return;
1146 if (item->long_timer)
1148 ecore_timer_del(item->long_timer);
1149 item->long_timer = NULL;
1151 evas_object_del(item->base.view);
1152 item->base.view = NULL;
1153 evas_object_del(item->spacer);
1154 item->spacer = NULL;
1155 elm_widget_stringlist_free(item->labels);
1156 item->labels = NULL;
1157 elm_widget_stringlist_free(item->icons);
1159 elm_widget_stringlist_free(item->states);
1160 item->states = NULL;
1162 EINA_LIST_FREE(item->icon_objs, icon)
1163 evas_object_del(icon);
1165 item->realized = EINA_FALSE;
1166 item->want_unrealize = EINA_FALSE;
1170 _item_place(Elm_Gengrid_Item *item,
1174 Evas_Coord x, y, ox, oy, cvx, cvy, cvw, cvh;
1175 Evas_Coord tch, tcw, alignw = 0, alignh = 0, vw, vh;
1176 Eina_Bool reorder_item_move_forward = EINA_FALSE;
1179 evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &vw, &vh);
1181 /* Preload rows/columns at each side of the Gengrid */
1182 cvx = ox - PRELOAD * item->wd->item_width;
1183 cvy = oy - PRELOAD * item->wd->item_height;
1184 cvw = vw + 2 * PRELOAD * item->wd->item_width;
1185 cvh = vh + 2 * PRELOAD * item->wd->item_height;
1190 if (item->wd->horizontal)
1192 int columns, items_visible = 0, items_row;
1194 if (item->wd->item_height > 0)
1195 items_visible = vh / item->wd->item_height;
1196 if (items_visible < 1)
1199 columns = item->wd->count / items_visible;
1200 if (item->wd->count % items_visible)
1203 tcw = item->wd->item_width * columns;
1204 alignw = (vw - tcw) * item->wd->align_x;
1206 items_row = items_visible;
1207 if (items_row > item->wd->count)
1208 items_row = item->wd->count;
1209 tch = items_row * item->wd->item_height;
1210 alignh = (vh - tch) * item->wd->align_y;
1214 int rows, items_visible = 0, items_col;
1216 if (item->wd->item_width > 0)
1217 items_visible = vw / item->wd->item_width;
1218 if (items_visible < 1)
1221 rows = item->wd->count / items_visible;
1222 if (item->wd->count % items_visible)
1225 tch = item->wd->item_height * rows;
1226 alignh = (vh - tch) * item->wd->align_y;
1228 items_col = items_visible;
1229 if (items_col > item->wd->count)
1230 items_col = item->wd->count;
1231 tcw = items_col * item->wd->item_width;
1232 alignw = (vw - tcw) * item->wd->align_x;
1235 x = cx * item->wd->item_width - item->wd->pan_x + ox + alignw;
1236 if (elm_widget_mirrored_get(item->wd->self))
1237 { /* Switch items side and componsate for pan_x when in RTL mode */
1239 evas_object_geometry_get(item->wd->self, NULL, NULL, &ww, NULL);
1240 x = ww - x - item->wd->item_width - item->wd->pan_x - item->wd->pan_x;
1243 y = cy * item->wd->item_height - item->wd->pan_y + oy + alignh;
1245 Eina_Bool was_realized = item->realized;
1246 if (ELM_RECTS_INTERSECT(x, y, item->wd->item_width, item->wd->item_height,
1247 cvx, cvy, cvw, cvh))
1249 _item_realize(item);
1251 evas_object_smart_callback_call(item->wd->self, SIG_REALIZED, item);
1252 if ((item->wd->reorder_mode) && (item->wd->reorder_item))
1254 if (item->wd->reorder_item == item)
1256 evas_object_move(item->base.view,
1257 item->wd->reorder_item_x, item->wd->reorder_item_y);
1258 evas_object_resize(item->base.view,
1259 item->wd->item_width, item->wd->item_height);
1264 if (ELM_RECTS_INTERSECT(item->wd->reorder_item_x, item->wd->reorder_item_y,
1265 item->wd->item_width, item->wd->item_height,
1266 x+(item->wd->item_width/2), y+(item->wd->item_height/2),
1269 if (item->wd->horizontal)
1271 if ((item->wd->nmax * item->wd->reorder_item->x + item->wd->reorder_item->y) >
1272 (item->wd->nmax * item->x + item->y))
1273 reorder_item_move_forward = EINA_TRUE;
1277 if ((item->wd->nmax * item->wd->reorder_item->y + item->wd->reorder_item->x) >
1278 (item->wd->nmax * item->y + item->x))
1279 reorder_item_move_forward = EINA_TRUE;
1282 item->wd->items = eina_inlist_remove(item->wd->items,
1283 EINA_INLIST_GET(item->wd->reorder_item));
1284 if (reorder_item_move_forward)
1285 item->wd->items = eina_inlist_prepend_relative(item->wd->items,
1286 EINA_INLIST_GET(item->wd->reorder_item),
1287 EINA_INLIST_GET(item));
1289 item->wd->items = eina_inlist_append_relative(item->wd->items,
1290 EINA_INLIST_GET(item->wd->reorder_item),
1291 EINA_INLIST_GET(item));
1293 item->wd->reorder_item_changed = EINA_TRUE;
1295 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1296 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1302 evas_object_move(item->base.view, x, y);
1303 evas_object_resize(item->base.view, item->wd->item_width,
1304 item->wd->item_height);
1308 _item_unrealize(item);
1310 evas_object_smart_callback_call(item->wd->self, SIG_UNREALIZED, item);
1314 static Elm_Gengrid_Item *
1315 _item_create(Widget_Data *wd,
1316 const Elm_Gengrid_Item_Class *gic,
1319 const void *func_data)
1321 Elm_Gengrid_Item *item;
1323 item = elm_widget_item_new(wd->self, Elm_Gengrid_Item);
1324 if (!item) return NULL;
1328 item->base.data = data;
1329 item->func.func = func;
1330 item->func.data = func_data;
1331 item->mouse_cursor = NULL;
1336 _item_del(Elm_Gengrid_Item *item)
1338 elm_widget_item_pre_notify_del(item);
1340 item->wd->selected = eina_list_remove(item->wd->selected, item);
1341 if (item->realized) _item_unrealize(item);
1342 if ((!item->delete_me) && (item->gic->func.del))
1343 item->gic->func.del((void *)item->base.data, item->wd->self);
1344 item->delete_me = EINA_TRUE;
1345 item->wd->items = eina_inlist_remove(item->wd->items, EINA_INLIST_GET(item));
1346 if (item->long_timer) ecore_timer_del(item->long_timer);
1347 if (item->tooltip.del_cb)
1348 item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
1349 item->wd->walking -= item->walking;
1351 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1352 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1353 elm_widget_item_del(item);
1357 _item_select(Elm_Gengrid_Item *item)
1359 if ((item->wd->no_select) || (item->delete_me)) return;
1362 if (item->wd->always_select) goto call;
1365 item->selected = EINA_TRUE;
1366 item->wd->selected = eina_list_append(item->wd->selected, item);
1369 item->wd->walking++;
1370 if (item->func.func)
1371 item->func.func((void *)item->func.data, item->wd->self, item);
1372 if (!item->delete_me)
1373 evas_object_smart_callback_call(item->wd->self, SIG_SELECTED, item);
1375 item->wd->walking--;
1376 if ((item->wd->clear_me) && (!item->wd->walking))
1377 elm_gengrid_clear(item->base.widget);
1380 if ((!item->walking) && (item->delete_me))
1381 if (!item->relcount) _item_del(item);
1383 item->wd->last_selected_item = item;
1387 _item_unselect(Elm_Gengrid_Item *item)
1389 if ((item->delete_me) || (!item->hilighted)) return;
1390 edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
1391 item->hilighted = EINA_FALSE;
1394 item->selected = EINA_FALSE;
1395 item->wd->selected = eina_list_remove(item->wd->selected, item);
1396 evas_object_smart_callback_call(item->wd->self, SIG_UNSELECTED, item);
1401 _calc_job(void *data)
1403 Widget_Data *wd = data;
1404 Evas_Coord minw = 0, minh = 0, nmax = 0, cvw, cvh;
1407 evas_object_geometry_get(wd->pan_smart, NULL, NULL, &cvw, &cvh);
1408 if ((cvw != 0) || (cvh != 0))
1410 if ((wd->horizontal) && (wd->item_height > 0))
1411 nmax = cvh / wd->item_height;
1412 else if (wd->item_width > 0)
1413 nmax = cvw / wd->item_width;
1421 minw = ceil(count / (float)nmax) * wd->item_width;
1422 minh = nmax * wd->item_height;
1426 minw = nmax * wd->item_width;
1427 minh = ceil(count / (float)nmax) * wd->item_height;
1430 if ((minw != wd->minw) || (minh != wd->minh))
1434 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1438 evas_object_smart_changed(wd->pan_smart);
1440 wd->calc_job = NULL;
1444 _pan_add(Evas_Object *obj)
1447 Evas_Object_Smart_Clipped_Data *cd;
1450 cd = evas_object_smart_data_get(obj);
1453 sd->__clipped_data = *cd;
1455 evas_object_smart_data_set(obj, sd);
1459 _pan_del(Evas_Object *obj)
1461 Pan *sd = evas_object_smart_data_get(obj);
1468 _pan_set(Evas_Object *obj,
1472 Pan *sd = evas_object_smart_data_get(obj);
1473 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1476 evas_object_smart_changed(obj);
1480 _pan_get(Evas_Object *obj,
1484 Pan *sd = evas_object_smart_data_get(obj);
1485 if (x) *x = sd->wd->pan_x;
1486 if (y) *y = sd->wd->pan_y;
1490 _pan_child_size_get(Evas_Object *obj,
1494 Pan *sd = evas_object_smart_data_get(obj);
1495 if (w) *w = sd->wd->minw;
1496 if (h) *h = sd->wd->minh;
1500 _pan_max_get(Evas_Object *obj,
1504 Pan *sd = evas_object_smart_data_get(obj);
1508 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1510 *x = (ow < sd->wd->minw) ? sd->wd->minw - ow : 0;
1512 *y = (oh < sd->wd->minh) ? sd->wd->minh - oh : 0;
1516 _pan_min_get(Evas_Object *obj,
1520 Pan *sd = evas_object_smart_data_get(obj);
1524 _pan_max_get(obj, &mx, &my);
1526 *x = -mx * sd->wd->align_x;
1528 *y = -my * sd->wd->align_y;
1532 _pan_resize(Evas_Object *obj,
1536 Pan *sd = evas_object_smart_data_get(obj);
1539 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1540 if ((ow == w) && (oh == h)) return;
1541 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1542 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1546 _pan_calculate(Evas_Object *obj)
1548 Pan *sd = evas_object_smart_data_get(obj);
1549 Evas_Coord cx = 0, cy = 0;
1550 Elm_Gengrid_Item *item;
1553 if (!sd->wd->nmax) return;
1555 sd->wd->reorder_item_changed = EINA_FALSE;
1557 EINA_INLIST_FOREACH(sd->wd->items, item)
1559 _item_place(item, cx, cy);
1560 if (sd->wd->reorder_item_changed) return;
1561 if (sd->wd->horizontal)
1563 cy = (cy + 1) % sd->wd->nmax;
1568 cx = (cx + 1) % sd->wd->nmax;
1572 evas_object_smart_callback_call(sd->wd->self, SIG_CHANGED, NULL);
1576 _pan_move(Evas_Object *obj,
1577 Evas_Coord x __UNUSED__,
1578 Evas_Coord y __UNUSED__)
1580 Pan *sd = evas_object_smart_data_get(obj);
1582 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1583 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1587 _hold_on(void *data __UNUSED__,
1589 void *event_info __UNUSED__)
1591 Widget_Data *wd = elm_widget_data_get(obj);
1593 elm_smart_scroller_hold_set(wd->scr, 1);
1597 _hold_off(void *data __UNUSED__,
1599 void *event_info __UNUSED__)
1601 Widget_Data *wd = elm_widget_data_get(obj);
1603 elm_smart_scroller_hold_set(wd->scr, 0);
1607 _freeze_on(void *data __UNUSED__,
1609 void *event_info __UNUSED__)
1611 Widget_Data *wd = elm_widget_data_get(obj);
1613 elm_smart_scroller_freeze_set(wd->scr, 1);
1617 _freeze_off(void *data __UNUSED__,
1619 void *event_info __UNUSED__)
1621 Widget_Data *wd = elm_widget_data_get(obj);
1623 elm_smart_scroller_freeze_set(wd->scr, 0);
1627 _scr_drag_start(void *data,
1628 Evas_Object *obj __UNUSED__,
1629 void *event_info __UNUSED__)
1631 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1635 _scr_drag_stop(void *data,
1636 Evas_Object *obj __UNUSED__,
1637 void *event_info __UNUSED__)
1639 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1643 _scr_scroll(void *data,
1644 Evas_Object *obj __UNUSED__,
1645 void *event_info __UNUSED__)
1647 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1651 * Add a new Gengrid object.
1653 * @param parent The parent object.
1654 * @return The new object or NULL if it cannot be created.
1656 * @see elm_gengrid_item_size_set()
1657 * @see elm_gengrid_horizontal_set()
1658 * @see elm_gengrid_item_append()
1659 * @see elm_gengrid_item_del()
1660 * @see elm_gengrid_clear()
1665 elm_gengrid_add(Evas_Object *parent)
1670 static Evas_Smart *smart = NULL;
1671 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1673 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1675 ELM_SET_WIDTYPE(widtype, "gengrid");
1676 elm_widget_type_set(obj, "gengrid");
1677 elm_widget_sub_object_add(parent, obj);
1678 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1679 elm_widget_data_set(obj, wd);
1680 elm_widget_del_hook_set(obj, _del_hook);
1681 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1682 elm_widget_theme_hook_set(obj, _theme_hook);
1683 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1684 elm_widget_can_focus_set(obj, EINA_TRUE);
1685 elm_widget_event_hook_set(obj, _event_hook);
1687 wd->scr = elm_smart_scroller_add(e);
1688 elm_smart_scroller_widget_set(wd->scr, obj);
1689 elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
1691 elm_widget_resize_object_set(obj, wd->scr);
1693 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1694 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1695 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1697 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1702 wd->h_bounce = bounce;
1703 wd->v_bounce = bounce;
1704 wd->no_select = EINA_FALSE;
1706 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1707 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1708 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1709 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1711 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1715 static Evas_Smart_Class sc;
1717 evas_object_smart_clipped_smart_set(&_pan_sc);
1719 sc.name = "elm_gengrid_pan";
1720 sc.version = EVAS_SMART_CLASS_VERSION;
1723 sc.resize = _pan_resize;
1724 sc.move = _pan_move;
1725 sc.calculate = _pan_calculate;
1726 smart = evas_smart_class_new(&sc);
1730 wd->pan_smart = evas_object_smart_add(e, smart);
1731 wd->pan = evas_object_smart_data_get(wd->pan_smart);
1735 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1736 _pan_set, _pan_get, _pan_max_get,
1737 _pan_min_get, _pan_child_size_get);
1739 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1744 * Set the size for the item of the Gengrid.
1746 * @param obj The Gengrid object.
1747 * @param w The item's width.
1748 * @param h The item's height;
1750 * @see elm_gengrid_item_size_get()
1755 elm_gengrid_item_size_set(Evas_Object *obj,
1759 ELM_CHECK_WIDTYPE(obj, widtype);
1760 Widget_Data *wd = elm_widget_data_get(obj);
1762 if ((wd->item_width == w) && (wd->item_height == h)) return;
1764 wd->item_height = h;
1765 if (wd->calc_job) ecore_job_del(wd->calc_job);
1766 wd->calc_job = ecore_job_add(_calc_job, wd);
1770 * Get the size of the item of the Gengrid.
1772 * @param obj The Gengrid object.
1773 * @param w Pointer to the item's width.
1774 * @param h Pointer to the item's height.
1776 * @see elm_gengrid_item_size_get()
1781 elm_gengrid_item_size_get(const Evas_Object *obj,
1785 ELM_CHECK_WIDTYPE(obj, widtype);
1786 Widget_Data *wd = elm_widget_data_get(obj);
1788 if (w) *w = wd->item_width;
1789 if (h) *h = wd->item_height;
1793 * Set item's alignment within the scroller.
1795 * @param obj The Gengrid object.
1796 * @param align_x The x alignment (0 <= x <= 1).
1797 * @param align_y The y alignment (0 <= y <= 1).
1799 * @see elm_gengrid_align_get()
1804 elm_gengrid_align_set(Evas_Object *obj,
1808 ELM_CHECK_WIDTYPE(obj, widtype);
1809 Widget_Data *wd = elm_widget_data_get(obj);
1813 else if (align_x < 0.0)
1815 wd->align_x = align_x;
1819 else if (align_y < 0.0)
1821 wd->align_y = align_y;
1825 * Get the alignenment set for the Gengrid object.
1827 * @param obj The Gengrid object.
1828 * @param align_x Pointer to x alignenment.
1829 * @param align_y Pointer to y alignenment.
1831 * @see elm_gengrid_align_set()
1836 elm_gengrid_align_get(const Evas_Object *obj,
1840 ELM_CHECK_WIDTYPE(obj, widtype);
1841 Widget_Data *wd = elm_widget_data_get(obj);
1842 if (align_x) *align_x = wd->align_x;
1843 if (align_y) *align_y = wd->align_y;
1847 * Add item to the end of the Gengrid.
1849 * @param obj The Gengrid object.
1850 * @param gic The item class for the item.
1851 * @param data The item data.
1852 * @param func Convenience function called when item is selected.
1853 * @param func_data Data passed to @p func above.
1854 * @return A handle to the item added or NULL if not possible.
1856 * @see elm_gengrid_item_prepend()
1857 * @see elm_gengrid_item_insert_before()
1858 * @see elm_gengrid_item_insert_after()
1859 * @see elm_gengrid_item_del()
1863 EAPI Elm_Gengrid_Item *
1864 elm_gengrid_item_append(Evas_Object *obj,
1865 const Elm_Gengrid_Item_Class *gic,
1868 const void *func_data)
1870 Elm_Gengrid_Item *item;
1871 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1872 Widget_Data *wd = elm_widget_data_get(obj);
1873 if (!wd) return NULL;
1875 item = _item_create(wd, gic, data, func, func_data);
1876 if (!item) return NULL;
1877 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(item));
1879 if (wd->calc_job) ecore_job_del(wd->calc_job);
1880 wd->calc_job = ecore_job_add(_calc_job, wd);
1886 * Add item at start of the Gengrid.
1888 * This adds an item to the beginning of the grid.
1890 * @param obj The Gengrid object.
1891 * @param gic The item class for the item.
1892 * @param data The item data.
1893 * @param func Convenience function called when item is selected.
1894 * @param func_data Data passed to @p func above.
1895 * @return A handle to the item added or NULL if not possible.
1897 * @see elm_gengrid_item_append()
1898 * @see elm_gengrid_item_insert_before()
1899 * @see elm_gengrid_item_insert_after()
1900 * @see elm_gengrid_item_del()
1904 EAPI Elm_Gengrid_Item *
1905 elm_gengrid_item_prepend(Evas_Object *obj,
1906 const Elm_Gengrid_Item_Class *gic,
1909 const void *func_data)
1911 Elm_Gengrid_Item *item;
1912 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1913 Widget_Data *wd = elm_widget_data_get(obj);
1914 if (!wd) return NULL;
1916 item = _item_create(wd, gic, data, func, func_data);
1917 if (!item) return NULL;
1918 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(item));
1920 if (wd->calc_job) ecore_job_del(wd->calc_job);
1921 wd->calc_job = ecore_job_add(_calc_job, wd);
1927 * Insert and item before another in the Gengrid.
1929 * This inserts an item before another in the grid.
1931 * @param obj The Gengrid object.
1932 * @param gic The item class for the item.
1933 * @param data The item data.
1934 * @param relative The item to which insert before.
1935 * @param func Convenience function called when item is selected.
1936 * @param func_data Data passed to @p func above.
1937 * @return A handle to the item added or NULL if not possible.
1939 * @see elm_gengrid_item_append()
1940 * @see elm_gengrid_item_prepend()
1941 * @see elm_gengrid_item_insert_after()
1942 * @see elm_gengrid_item_del()
1946 EAPI Elm_Gengrid_Item *
1947 elm_gengrid_item_insert_before(Evas_Object *obj,
1948 const Elm_Gengrid_Item_Class *gic,
1950 Elm_Gengrid_Item *relative,
1952 const void *func_data)
1954 Elm_Gengrid_Item *item;
1955 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1956 EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
1957 Widget_Data *wd = elm_widget_data_get(obj);
1958 if (!wd) return NULL;
1960 item = _item_create(wd, gic, data, func, func_data);
1961 if (!item) return NULL;
1962 wd->items = eina_inlist_prepend_relative
1963 (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
1965 if (wd->calc_job) ecore_job_del(wd->calc_job);
1966 wd->calc_job = ecore_job_add(_calc_job, wd);
1972 * Insert and item after another in the Gengrid.
1974 * This inserts an item after another in the grid.
1976 * @param obj The Gengrid object.
1977 * @param gic The item class for the item.
1978 * @param data The item data.
1979 * @param relative The item to which insert after.
1980 * @param func Convenience function called when item is selected.
1981 * @param func_data Data passed to @p func above.
1982 * @return A handle to the item added or NULL if not possible.
1984 * @see elm_gengrid_item_append()
1985 * @see elm_gengrid_item_prepend()
1986 * @see elm_gengrid_item_insert_before()
1987 * @see elm_gengrid_item_del()
1991 EAPI Elm_Gengrid_Item *
1992 elm_gengrid_item_insert_after(Evas_Object *obj,
1993 const Elm_Gengrid_Item_Class *gic,
1995 Elm_Gengrid_Item *relative,
1997 const void *func_data)
1999 Elm_Gengrid_Item *item;
2000 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2001 EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
2002 Widget_Data *wd = elm_widget_data_get(obj);
2003 if (!wd) return NULL;
2005 item = _item_create(wd, gic, data, func, func_data);
2006 if (!item) return NULL;
2007 wd->items = eina_inlist_append_relative
2008 (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
2010 if (wd->calc_job) ecore_job_del(wd->calc_job);
2011 wd->calc_job = ecore_job_add(_calc_job, wd);
2017 * Remove an item from the Gengrid.
2019 * @param item The item to be removed.
2020 * @return @c EINA_TRUE on success or @c EINA_FALSE otherwise.
2022 * @see elm_gengrid_clear() to remove all items of the Gengrid.
2027 elm_gengrid_item_del(Elm_Gengrid_Item *item)
2029 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2030 if ((item->relcount > 0) || (item->walking > 0))
2032 item->delete_me = EINA_TRUE;
2033 elm_widget_item_pre_notify_del(item);
2035 item->wd->selected = eina_list_remove(item->wd->selected, item);
2036 if (item->gic->func.del)
2037 item->gic->func.del((void *)item->base.data, item->wd->self);
2045 * Set for what direction the Gengrid will expand.
2047 * @param obj The Gengrid object.
2048 * @param setting If @c EINA_TRUE the Gengrid will expand horizontally
2049 * or vertically if @c EINA_FALSE.
2054 elm_gengrid_horizontal_set(Evas_Object *obj,
2057 ELM_CHECK_WIDTYPE(obj, widtype);
2058 Widget_Data *wd = elm_widget_data_get(obj);
2060 if (setting == wd->horizontal) return;
2061 wd->horizontal = setting;
2063 /* Update the items to conform to the new layout */
2064 if (wd->calc_job) ecore_job_del(wd->calc_job);
2065 wd->calc_job = ecore_job_add(_calc_job, wd);
2069 * Get for what direction the Gengrid is expanded.
2071 * @param obj The Gengrid object.
2072 * @return If the Gengrid is expanded horizontally return @c EINA_TRUE
2073 * else @c EINA_FALSE.
2078 elm_gengrid_horizontal_get(const Evas_Object *obj)
2080 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2081 Widget_Data *wd = elm_widget_data_get(obj);
2082 if (!wd) return EINA_FALSE;
2083 return wd->horizontal;
2089 * This clears all items in the Gengrid, leaving it empty.
2091 * @param obj The Gengrid object.
2093 * @see elm_gengrid_item_del() to remove just one item.
2098 elm_gengrid_clear(Evas_Object *obj)
2100 ELM_CHECK_WIDTYPE(obj, widtype);
2101 Widget_Data *wd = elm_widget_data_get(obj);
2106 ecore_job_del(wd->calc_job);
2107 wd->calc_job = NULL;
2110 if (wd->walking > 0)
2112 Elm_Gengrid_Item *item;
2114 EINA_INLIST_FOREACH(wd->items, item)
2115 item->delete_me = 1;
2121 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
2123 wd->items = eina_inlist_remove(wd->items, wd->items);
2124 elm_widget_item_pre_notify_del(item);
2125 if (item->realized) _item_unrealize(item);
2126 if (item->gic->func.del)
2127 item->gic->func.del((void *)item->base.data, wd->self);
2128 if (item->long_timer) ecore_timer_del(item->long_timer);
2129 elm_widget_item_del(item);
2134 eina_list_free(wd->selected);
2135 wd->selected = NULL;
2143 evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
2144 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2148 * Get the real evas object of the Gengrid item
2150 * This returns the actual evas object used for the specified Gengrid
2151 * item. This may be NULL as it may not be created, and may be
2152 * deleted at any time by Gengrid. Do not modify this object (move,
2153 * resize, show, hide etc.) as Gengrid is controlling it. This
2154 * function is for querying, emitting custom signals or hooking lower
2155 * level callbacks for events. Do not delete this object under any
2158 * @param item The Gengrid item.
2159 * @return the evas object associated to this item.
2161 * @see elm_gengrid_item_data_get()
2165 EAPI const Evas_Object *
2166 elm_gengrid_item_object_get(const Elm_Gengrid_Item *item)
2168 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2169 return item->base.view;
2173 * Update the contents of an item
2175 * This updates an item by calling all the item class functions again
2176 * to get the icons, labels and states. Use this when the original
2177 * item data has changed and the changes are desired to be reflected.
2179 * @param item The item
2184 elm_gengrid_item_update(Elm_Gengrid_Item *item)
2186 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2187 if (!item->realized) return;
2188 if (item->want_unrealize) return;
2189 _item_unrealize(item);
2190 _item_realize(item);
2191 _item_place(item, item->x, item->y);
2195 * Returns the data associated to an item
2197 * This returns the data value passed on the elm_gengrid_item_append()
2198 * and related item addition calls.
2200 * @param item The Gengrid item.
2201 * @return the data associated to this item.
2203 * @see elm_gengrid_item_append()
2204 * @see elm_gengrid_item_object_get()
2209 elm_gengrid_item_data_get(const Elm_Gengrid_Item *item)
2211 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2212 return elm_widget_item_data_get(item);
2216 * Set the datan item from the gengrid item
2218 * This set the data value passed on the elm_gengrid_item_append() and
2219 * related item addition calls. This function will also call
2220 * elm_gengrid_item_update() so the item will be updated to reflect
2223 * @param item The item
2224 * @param data The new data pointer to set
2229 elm_gengrid_item_data_set(Elm_Gengrid_Item *item,
2232 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2233 elm_widget_item_data_set(item, data);
2234 elm_gengrid_item_update(item);
2238 * Get the item's coordinates.
2240 * This returns the logical position of the item whithin the Gengrid.
2242 * @param item The Gengrid item.
2243 * @param x The x-axis coordinate pointer.
2244 * @param y The y-axis coordinate pointer.
2249 elm_gengrid_item_pos_get(const Elm_Gengrid_Item *item,
2253 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2254 if (x) *x = item->x;
2255 if (y) *y = item->y;
2259 * Enable or disable multi-select in the Gengrid.
2261 * This enables (EINA_TRUE) or disables (EINA_FALSE) multi-select in
2262 * the Gengrid. This allows more than 1 item to be selected.
2264 * @param obj The Gengrid object.
2265 * @param multi Multi-select enabled/disabled
2270 elm_gengrid_multi_select_set(Evas_Object *obj,
2273 ELM_CHECK_WIDTYPE(obj, widtype);
2274 Widget_Data *wd = elm_widget_data_get(obj);
2280 * Get if multi-select in Gengrid is enabled or disabled
2282 * @param obj The Gengrid object
2283 * @return Multi-select enable/disable
2284 * (EINA_TRUE = enabled / EINA_FALSE = disabled)
2289 elm_gengrid_multi_select_get(const Evas_Object *obj)
2291 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2292 Widget_Data *wd = elm_widget_data_get(obj);
2293 if (!wd) return EINA_FALSE;
2298 * Get the selected item in the Gengrid
2300 * This gets the selected item in the Gengrid (if multi-select is
2301 * enabled only the first item in the list is selected - which is not
2302 * very useful, so see elm_gengrid_selected_items_get() for when
2303 * multi-select is used).
2305 * If no item is selected, NULL is returned.
2307 * @param obj The Gengrid object.
2308 * @return The selected item, or NULL if none.
2312 EAPI Elm_Gengrid_Item *
2313 elm_gengrid_selected_item_get(const Evas_Object *obj)
2315 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2316 Widget_Data *wd = elm_widget_data_get(obj);
2317 if (!wd) return NULL;
2318 if (wd->selected) return wd->selected->data;
2323 * Get a list of selected items in the Gengrid.
2325 * This returns a list of the selected items. This list pointer is
2326 * only valid so long as no items are selected or unselected (or
2327 * unselected implictly by deletion). The list contains
2328 * Elm_Gengrid_Item pointers.
2330 * @param obj The Gengrid object.
2331 * @return The list of selected items, or NULL if none are selected.
2335 EAPI const Eina_List *
2336 elm_gengrid_selected_items_get(const Evas_Object *obj)
2338 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2339 Widget_Data *wd = elm_widget_data_get(obj);
2340 if (!wd) return NULL;
2341 return wd->selected;
2345 * Set the selected state of an item.
2347 * This sets the selected state of an item. If multi-select is not
2348 * enabled and selected is EINA_TRUE, previously selected items are
2351 * @param item The item
2352 * @param selected The selected state.
2357 elm_gengrid_item_selected_set(Elm_Gengrid_Item *item,
2360 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2361 Widget_Data *wd = item->wd;
2363 if (item->delete_me) return;
2364 selected = !!selected;
2365 if (item->selected == selected) return;
2371 while (wd->selected)
2372 _item_unselect(wd->selected->data);
2374 _item_hilight(item);
2378 _item_unselect(item);
2382 * Get the selected state of an item.
2384 * This gets the selected state of an item (1 selected, 0 not selected).
2386 * @param item The item
2387 * @return The selected state
2392 elm_gengrid_item_selected_get(const Elm_Gengrid_Item *item)
2394 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2395 return item->selected;
2399 * Sets the disabled state of an item.
2401 * A disabled item cannot be selected or unselected. It will also
2402 * change appearance to disabled. This sets the disabled state (1
2403 * disabled, 0 not disabled).
2405 * @param item The item
2406 * @param disabled The disabled state
2411 elm_gengrid_item_disabled_set(Elm_Gengrid_Item *item,
2414 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2415 if (item->disabled == disabled) return;
2416 if (item->delete_me) return;
2417 item->disabled = !!disabled;
2421 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
2423 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
2428 * Get the disabled state of an item.
2430 * This gets the disabled state of the given item.
2432 * @param item The item
2433 * @return The disabled state
2438 elm_gengrid_item_disabled_get(const Elm_Gengrid_Item *item)
2440 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2441 if (item->delete_me) return EINA_FALSE;
2442 return item->disabled;
2445 static Evas_Object *
2446 _elm_gengrid_item_label_create(void *data,
2448 void *item __UNUSED__)
2450 Evas_Object *label = elm_label_add(obj);
2453 elm_object_style_set(label, "tooltip");
2454 elm_label_label_set(label, data);
2459 _elm_gengrid_item_label_del_cb(void *data,
2460 Evas_Object *obj __UNUSED__,
2461 void *event_info __UNUSED__)
2463 eina_stringshare_del(data);
2467 * Set the text to be shown in the gengrid item.
2469 * @param item Target item
2470 * @param text The text to set in the content
2472 * Setup the text as tooltip to object. The item can have only one
2473 * tooltip, so any previous tooltip data is removed.
2478 elm_gengrid_item_tooltip_text_set(Elm_Gengrid_Item *item,
2481 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2482 text = eina_stringshare_add(text);
2483 elm_gengrid_item_tooltip_content_cb_set(item, _elm_gengrid_item_label_create,
2485 _elm_gengrid_item_label_del_cb);
2489 * Set the content to be shown in the tooltip item
2491 * Setup the tooltip to item. The item can have only one tooltip, so
2492 * any previous tooltip data is removed. @p func(with @p data) will be
2493 * called every time that need show the tooltip and it should return a
2494 * valid Evas_Object. This object is then managed fully by tooltip
2495 * system and is deleted when the tooltip is gone.
2497 * @param item the gengrid item being attached a tooltip.
2498 * @param func the function used to create the tooltip contents.
2499 * @param data what to provide to @a func as callback data/context.
2500 * @param del_cb called when data is not needed anymore, either when
2501 * another callback replaces @func, the tooltip is unset with
2502 * elm_gengrid_item_tooltip_unset() or the owner @an item
2503 * dies. This callback receives as the first parameter the
2504 * given @a data, and @c event_info is the item.
2509 elm_gengrid_item_tooltip_content_cb_set(Elm_Gengrid_Item *item,
2510 Elm_Tooltip_Item_Content_Cb func,
2512 Evas_Smart_Cb del_cb)
2514 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
2516 if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
2519 if (item->tooltip.del_cb)
2520 item->tooltip.del_cb((void *)item->tooltip.data,
2521 item->base.widget, item);
2522 item->tooltip.content_cb = func;
2523 item->tooltip.data = data;
2524 item->tooltip.del_cb = del_cb;
2525 if (item->base.view)
2527 elm_widget_item_tooltip_content_cb_set(item,
2528 item->tooltip.content_cb,
2529 item->tooltip.data, NULL);
2530 elm_widget_item_tooltip_style_set(item, item->tooltip.style);
2536 if (del_cb) del_cb((void *)data, NULL, NULL);
2540 * Unset tooltip from item
2542 * @param item gengrid item to remove previously set tooltip.
2544 * Remove tooltip from item. The callback provided as del_cb to
2545 * elm_gengrid_item_tooltip_content_cb_set() will be called to notify
2546 * it is not used anymore.
2548 * @see elm_gengrid_item_tooltip_content_cb_set()
2553 elm_gengrid_item_tooltip_unset(Elm_Gengrid_Item *item)
2555 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2556 if ((item->base.view) && (item->tooltip.content_cb))
2557 elm_widget_item_tooltip_unset(item);
2559 if (item->tooltip.del_cb)
2560 item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
2561 item->tooltip.del_cb = NULL;
2562 item->tooltip.content_cb = NULL;
2563 item->tooltip.data = NULL;
2564 if (item->tooltip.style)
2565 elm_gengrid_item_tooltip_style_set(item, NULL);
2569 * Sets a different style for this item tooltip.
2571 * @note before you set a style you should define a tooltip with
2572 * elm_gengrid_item_tooltip_content_cb_set() or
2573 * elm_gengrid_item_tooltip_text_set()
2575 * @param item gengrid item with tooltip already set.
2576 * @param style the theme style to use (default, transparent, ...)
2581 elm_gengrid_item_tooltip_style_set(Elm_Gengrid_Item *item,
2584 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2585 eina_stringshare_replace(&item->tooltip.style, style);
2586 if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
2590 * Get the style for this item tooltip.
2592 * @param item gengrid item with tooltip already set.
2593 * @return style the theme style in use, defaults to "default". If the
2594 * object does not have a tooltip set, then NULL is returned.
2599 elm_gengrid_item_tooltip_style_get(const Elm_Gengrid_Item *item)
2601 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2602 return item->tooltip.style;
2606 * Set the cursor to be shown when mouse is over the gengrid item
2608 * @param item Target item
2609 * @param cursor the cursor name to be used.
2611 * @see elm_object_cursor_set()
2615 elm_gengrid_item_cursor_set(Elm_Gengrid_Item *item,
2618 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2619 eina_stringshare_replace(&item->mouse_cursor, cursor);
2620 if (item->base.view) elm_widget_item_cursor_set(item, cursor);
2624 * Get the cursor to be shown when mouse is over the gengrid item
2626 * @param item gengrid item with cursor already set.
2627 * @return the cursor name.
2632 elm_gengrid_item_cursor_get(const Elm_Gengrid_Item *item)
2634 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2635 return elm_widget_item_cursor_get(item);
2639 * Unset the cursor to be shown when mouse is over the gengrid item
2641 * @param item Target item
2643 * @see elm_object_cursor_unset()
2647 elm_gengrid_item_cursor_unset(Elm_Gengrid_Item *item)
2649 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2650 if (!item->mouse_cursor)
2653 if (item->base.view)
2654 elm_widget_item_cursor_unset(item);
2656 eina_stringshare_del(item->mouse_cursor);
2657 item->mouse_cursor = NULL;
2661 * Sets a different style for this item cursor.
2663 * @note before you set a style you should define a cursor with
2664 * elm_gengrid_item_cursor_set()
2666 * @param item gengrid item with cursor already set.
2667 * @param style the theme style to use (default, transparent, ...)
2672 elm_gengrid_item_cursor_style_set(Elm_Gengrid_Item *item,
2675 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2676 elm_widget_item_cursor_style_set(item, style);
2680 * Get the style for this item cursor.
2682 * @param item gengrid item with cursor already set.
2683 * @return style the theme style in use, defaults to "default". If the
2684 * object does not have a cursor set, then NULL is returned.
2689 elm_gengrid_item_cursor_style_get(const Elm_Gengrid_Item *item)
2691 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2692 return elm_widget_item_cursor_style_get(item);
2696 * Set if the cursor set should be searched on the theme or should use
2697 * the provided by the engine, only.
2699 * @note before you set if should look on theme you should define a
2700 * cursor with elm_object_cursor_set(). By default it will only look
2701 * for cursors provided by the engine.
2703 * @param item widget item with cursor already set.
2704 * @param engine_only boolean to define it cursors should be looked
2705 * only between the provided by the engine or searched on widget's
2711 elm_gengrid_item_cursor_engine_only_set(Elm_Gengrid_Item *item,
2712 Eina_Bool engine_only)
2714 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2715 elm_widget_item_cursor_engine_only_set(item, engine_only);
2719 * Get the cursor engine only usage for this item cursor.
2721 * @param item widget item with cursor already set.
2722 * @return engine_only boolean to define it cursors should be looked
2723 * only between the provided by the engine or searched on widget's
2724 * theme as well. If the object does not have a cursor set, then
2725 * EINA_FALSE is returned.
2730 elm_gengrid_item_cursor_engine_only_get(const Elm_Gengrid_Item *item)
2732 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2733 return elm_widget_item_cursor_engine_only_get(item);
2737 * Set the reorder mode
2739 * @param obj The Gengrid object
2740 * @param reorder_mode The reorder mode
2741 * (EINA_TRUE = on, EINA_FALSE = off)
2746 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2747 Eina_Bool reorder_mode)
2749 ELM_CHECK_WIDTYPE(obj, widtype);
2750 Widget_Data *wd = elm_widget_data_get(obj);
2752 wd->reorder_mode = reorder_mode;
2756 * Get the reorder mode
2758 * @param obj The Gengrid object
2759 * @return The reorder mode
2760 * (EINA_TRUE = on, EINA_FALSE = off)
2765 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
2767 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2768 Widget_Data *wd = elm_widget_data_get(obj);
2769 if (!wd) return EINA_FALSE;
2770 return wd->reorder_mode;
2774 * Set the always select mode.
2776 * Cells will only call their selection func and callback when first
2777 * becoming selected. Any further clicks will do nothing, unless you
2778 * enable always select with
2779 * elm_gengrid_always_select_mode_set(). This means even if selected,
2780 * every click will make the selected callbacks be called.
2782 * @param obj The Gengrid object
2783 * @param always_select The always select mode (EINA_TRUE = on,
2789 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2790 Eina_Bool always_select)
2792 ELM_CHECK_WIDTYPE(obj, widtype);
2793 Widget_Data *wd = elm_widget_data_get(obj);
2795 wd->always_select = always_select;
2799 * Get the always select mode.
2801 * @param obj The Gengrid object.
2802 * @return The always select mode (EINA_TRUE = on, EINA_FALSE = off)
2807 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2809 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2810 Widget_Data *wd = elm_widget_data_get(obj);
2811 if (!wd) return EINA_FALSE;
2812 return wd->always_select;
2816 * Set no select mode.
2818 * This will turn off the ability to select items entirely and they
2819 * will neither appear selected nor call selected callback functions.
2821 * @param obj The Gengrid object
2822 * @param no_select The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2827 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2828 Eina_Bool no_select)
2830 ELM_CHECK_WIDTYPE(obj, widtype);
2831 Widget_Data *wd = elm_widget_data_get(obj);
2833 wd->no_select = no_select;
2837 * Gets no select mode.
2839 * @param obj The Gengrid object
2840 * @return The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2845 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2847 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2848 Widget_Data *wd = elm_widget_data_get(obj);
2849 if (!wd) return EINA_FALSE;
2850 return wd->no_select;
2856 * This will enable or disable the scroller bounce mode for the
2857 * Gengrid. See elm_scroller_bounce_set() for details.
2859 * @param obj The Gengrid object
2860 * @param h_bounce Allow bounce horizontally
2861 * @param v_bounce Allow bounce vertically
2866 elm_gengrid_bounce_set(Evas_Object *obj,
2870 ELM_CHECK_WIDTYPE(obj, widtype);
2871 Widget_Data *wd = elm_widget_data_get(obj);
2873 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
2874 wd->h_bounce = h_bounce;
2875 wd->v_bounce = v_bounce;
2879 * Get the bounce mode
2881 * @param obj The Gengrid object
2882 * @param h_bounce Allow bounce horizontally
2883 * @param v_bounce Allow bounce vertically
2888 elm_gengrid_bounce_get(const Evas_Object *obj,
2889 Eina_Bool *h_bounce,
2890 Eina_Bool *v_bounce)
2892 ELM_CHECK_WIDTYPE(obj, widtype);
2893 Widget_Data *wd = elm_widget_data_get(obj);
2895 *h_bounce = wd->h_bounce;
2896 *v_bounce = wd->v_bounce;
2900 * Get all items in the Gengrid.
2902 * This returns a list of the Gengrid items. The list contains
2903 * Elm_Gengrid_Item pointers.
2905 * @param obj The Gengrid object.
2906 * @return The list of items, or NULL if none.
2912 * Set gengrid scroll page size relative to viewport size.
2914 * The gengrid scroller is capable of limiting scrolling by the user
2915 * to "pages" That is to jump by and only show a "whole page" at a
2916 * time as if the continuous area of the scroller content is split
2917 * into page sized pieces. This sets the size of a page relative to
2918 * the viewport of the scroller. 1.0 is "1 viewport" is size
2919 * (horizontally or vertically). 0.0 turns it off in that axis. This
2920 * is mutually exclusive with page size (see
2921 * elm_gengrid_page_size_set() for more information). Likewise 0.5 is
2922 * "half a viewport". Sane usable valus are normally between 0.0 and
2923 * 1.0 including 1.0. If you only want 1 axis to be page "limited",
2924 * use 0.0 for the other axis.
2926 * @param obj The gengrid object
2927 * @param h_pagerel The horizontal page relative size
2928 * @param v_pagerel The vertical page relative size
2933 elm_gengrid_page_relative_set(Evas_Object *obj,
2937 Evas_Coord pagesize_h;
2938 Evas_Coord pagesize_v;
2940 ELM_CHECK_WIDTYPE(obj, widtype);
2941 Widget_Data *wd = elm_widget_data_get(obj);
2944 elm_smart_scroller_paging_get(wd->scr, NULL, NULL, &pagesize_h, &pagesize_v);
2945 elm_smart_scroller_paging_set(wd->scr, h_pagerel, v_pagerel, pagesize_h,
2950 * Get gengrid scroll page size relative to viewport size.
2952 * The gengrid scroller is capable of limiting scrolling by the user
2953 * to "pages" That is to jump by and only show a "whole page" at a
2954 * time as if the continuous area of the scroller content is split
2955 * into page sized pieces. This sets the size of a page relative to
2956 * the viewport of the scroller. 1.0 is "1 viewport" is size
2957 * (horizontally or vertically). 0.0 turns it off in that axis. This
2958 * is mutually exclusive with page size (see
2959 * elm_gengrid_page_size_set() for more information). Likewise 0.5 is
2960 * "half a viewport". Sane usable valus are normally between 0.0 and
2961 * 1.0 including 1.0. If you only want 1 axis to be page "limited",
2962 * use 0.0 for the other axis.
2964 * @param obj The gengrid object
2965 * @param h_pagerel The horizontal page relative size
2966 * @param v_pagerel The vertical page relative size
2971 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
2973 ELM_CHECK_WIDTYPE(obj, widtype);
2974 Widget_Data *wd = elm_widget_data_get(obj);
2977 elm_smart_scroller_paging_get(wd->scr, h_pagerel, v_pagerel, NULL, NULL);
2981 * Set gengrid scroll page size.
2983 * See also elm_gengrid_page_relative_set(). This, instead of a page
2984 * size being relative to the viewport, sets it to an absolute fixed
2985 * value, with 0 turning it off for that axis.
2987 * @param obj The gengrid object
2988 * @param h_pagesize The horizontal page size
2989 * @param v_pagesize The vertical page size
2994 elm_gengrid_page_size_set(Evas_Object *obj,
2995 Evas_Coord h_pagesize,
2996 Evas_Coord v_pagesize)
3001 ELM_CHECK_WIDTYPE(obj, widtype);
3002 Widget_Data *wd = elm_widget_data_get(obj);
3004 elm_smart_scroller_paging_get(wd->scr, &pagerel_h, &pagerel_v, NULL, NULL);
3005 elm_smart_scroller_paging_set(wd->scr, pagerel_h, pagerel_v, h_pagesize,
3010 * Get the first item in the gengrid
3012 * This returns the first item in the list.
3014 * @param obj The gengrid object
3015 * @return The first item, or NULL if none
3019 EAPI Elm_Gengrid_Item *
3020 elm_gengrid_first_item_get(const Evas_Object *obj)
3022 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3023 Widget_Data *wd = elm_widget_data_get(obj);
3024 if (!wd) return NULL;
3025 if (!wd->items) return NULL;
3026 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
3027 while ((item) && (item->delete_me))
3028 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
3033 * Get the last item in the gengrid
3035 * This returns the last item in the list.
3037 * @return The last item, or NULL if none
3041 EAPI Elm_Gengrid_Item *
3042 elm_gengrid_last_item_get(const Evas_Object *obj)
3044 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3045 Widget_Data *wd = elm_widget_data_get(obj);
3046 if (!wd) return NULL;
3047 if (!wd->items) return NULL;
3048 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
3049 while ((item) && (item->delete_me))
3050 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
3055 * Get the next item in the gengrid
3057 * This returns the item after the item @p item.
3059 * @param item The item
3060 * @return The item after @p item, or NULL if none
3064 EAPI Elm_Gengrid_Item *
3065 elm_gengrid_item_next_get(const Elm_Gengrid_Item *item)
3067 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
3070 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
3071 if ((item) && (!item->delete_me)) break;
3073 return (Elm_Gengrid_Item *)item;
3077 * Get the previous item in the gengrid
3079 * This returns the item before the item @p item.
3081 * @param item The item
3082 * @return The item before @p item, or NULL if none
3086 EAPI Elm_Gengrid_Item *
3087 elm_gengrid_item_prev_get(const Elm_Gengrid_Item *item)
3089 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
3092 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
3093 if ((item) && (!item->delete_me)) break;
3095 return (Elm_Gengrid_Item *)item;
3099 * Get the gengrid object from an item
3101 * This returns the gengrid object itself that an item belongs to.
3103 * @param item The item
3104 * @return The gengrid object
3109 elm_gengrid_item_gengrid_get(const Elm_Gengrid_Item *item)
3111 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
3112 return item->base.widget;
3116 * Show the given item
3118 * This causes gengrid to jump to the given item @p item and show it
3119 * (by scrolling), if it is not fully visible.
3121 * @param item The item
3126 elm_gengrid_item_show(Elm_Gengrid_Item *item)
3128 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
3129 Widget_Data *wd = elm_widget_data_get(item->wd->self);
3130 Evas_Coord minx = 0, miny = 0;
3133 if ((!item) || (item->delete_me)) return;
3134 _pan_min_get(wd->pan_smart, &minx, &miny);
3136 elm_smart_scroller_child_region_show(item->wd->scr,
3137 item->x * wd->item_width + minx,
3138 item->y * wd->item_height + miny,
3139 item->wd->item_width,
3140 item->wd->item_height);
3144 * Bring in the given item
3146 * This causes gengrig to jump to the given item @p item and show it
3147 * (by scrolling), if it is not fully visible. This may use animation
3148 * to do so and take a period of time
3150 * @param item The item
3155 elm_gengrid_item_bring_in(Elm_Gengrid_Item *item)
3157 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
3158 if (item->delete_me) return;
3160 Evas_Coord minx = 0, miny = 0;
3161 Widget_Data *wd = elm_widget_data_get(item->wd->self);
3163 _pan_min_get(wd->pan_smart, &minx, &miny);
3165 elm_smart_scroller_region_bring_in(item->wd->scr,
3166 item->x * wd->item_width + minx,
3167 item->y * wd->item_height + miny,
3168 item->wd->item_width,
3169 item->wd->item_height);