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;
148 #define REORDER_EFFECT_TIME 0.5
150 struct _Elm_Gengrid_Item
152 Elm_Widget_Item base;
155 const Elm_Gengrid_Item_Class *gic;
156 Ecore_Timer *long_timer;
157 Ecore_Animator *item_moving_effect_timer;
159 Eina_List *labels, *icons, *states, *icon_objs;
166 Evas_Coord x, y, dx, dy, ox, oy, tx, ty, rx, ry;
167 unsigned int moving_effect_start_time;
174 Elm_Tooltip_Item_Content_Cb content_cb;
175 Evas_Smart_Cb del_cb;
179 const char *mouse_cursor;
181 Eina_Bool want_unrealize : 1;
182 Eina_Bool realized : 1;
183 Eina_Bool dragging : 1;
185 Eina_Bool delete_me : 1;
186 Eina_Bool display_only : 1;
187 Eina_Bool disabled : 1;
188 Eina_Bool selected : 1;
189 Eina_Bool hilighted : 1;
190 Eina_Bool moving : 1;
195 Evas_Object *self, *scr;
196 Evas_Object *pan_smart;
201 Elm_Gengrid_Item *last_selected_item, *reorder_item;
202 double align_x, align_y;
204 Evas_Coord pan_x, pan_y, old_pan_x, old_pan_y;
205 Evas_Coord item_width, item_height; /* Each item size */
206 Evas_Coord minw, minh; /* Total obj size */
207 Evas_Coord reorder_item_x, reorder_item_y;
212 Eina_Bool horizontal : 1;
213 Eina_Bool on_hold : 1;
214 Eina_Bool longpressed : 1;
216 Eina_Bool no_select : 1;
217 Eina_Bool wasselected : 1;
218 Eina_Bool always_select : 1;
219 Eina_Bool clear_me : 1;
220 Eina_Bool h_bounce : 1;
221 Eina_Bool v_bounce : 1;
222 Eina_Bool reorder_mode : 1;
223 Eina_Bool reorder_item_changed : 1;
224 Eina_Bool move_effect_enabled : 1;
227 #define ELM_GENGRID_ITEM_FROM_INLIST(item) \
228 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Gengrid_Item) : NULL)
232 Evas_Object_Smart_Clipped_Data __clipped_data;
236 static const char *widtype = NULL;
237 static void _item_hilight(Elm_Gengrid_Item *item);
238 static void _item_unrealize(Elm_Gengrid_Item *item);
239 static void _item_select(Elm_Gengrid_Item *item);
240 static void _item_unselect(Elm_Gengrid_Item *item);
241 static void _calc_job(void *data);
242 static void _on_focus_hook(void *data,
244 static Eina_Bool _item_multi_select_up(Widget_Data *wd);
245 static Eina_Bool _item_multi_select_down(Widget_Data *wd);
246 static Eina_Bool _item_multi_select_left(Widget_Data *wd);
247 static Eina_Bool _item_multi_select_right(Widget_Data *wd);
248 static Eina_Bool _item_single_select_up(Widget_Data *wd);
249 static Eina_Bool _item_single_select_down(Widget_Data *wd);
250 static Eina_Bool _item_single_select_left(Widget_Data *wd);
251 static Eina_Bool _item_single_select_right(Widget_Data *wd);
252 static Eina_Bool _event_hook(Evas_Object *obj,
254 Evas_Callback_Type type,
256 static Eina_Bool _deselect_all_items(Widget_Data *wd);
258 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
259 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
261 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
262 static const char SIG_SELECTED[] = "selected";
263 static const char SIG_UNSELECTED[] = "unselected";
264 static const char SIG_REALIZED[] = "realized";
265 static const char SIG_UNREALIZED[] = "unrealized";
266 static const char SIG_CHANGED[] = "changed";
267 static const char SIG_DRAG_START_UP[] = "drag,start,up";
268 static const char SIG_DRAG_START_DOWN[] = "drag,start,down";
269 static const char SIG_DRAG_START_LEFT[] = "drag,start,left";
270 static const char SIG_DRAG_START_RIGHT[] = "drag,start,right";
271 static const char SIG_DRAG_STOP[] = "drag,stop";
272 static const char SIG_DRAG[] = "drag";
273 static const char SIG_SCROLL[] = "scroll";
274 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
275 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
276 static const char SIG_MOVED[] = "moved";
278 static const Evas_Smart_Cb_Description _signals[] = {
279 {SIG_CLICKED_DOUBLE, ""},
281 {SIG_UNSELECTED, ""},
283 {SIG_UNREALIZED, ""},
285 {SIG_DRAG_START_UP, ""},
286 {SIG_DRAG_START_DOWN, ""},
287 {SIG_DRAG_START_LEFT, ""},
288 {SIG_DRAG_START_RIGHT, ""},
292 {SIG_SCROLL_DRAG_START, ""},
293 {SIG_SCROLL_DRAG_STOP, ""},
301 _event_hook(Evas_Object *obj,
302 Evas_Object *src __UNUSED__,
303 Evas_Callback_Type type,
306 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
307 Evas_Event_Key_Down *ev = event_info;
308 Widget_Data *wd = elm_widget_data_get(obj);
309 if (!wd) return EINA_FALSE;
310 if (!wd->items) return EINA_FALSE;
311 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
312 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
314 Elm_Gengrid_Item *item = NULL;
317 Evas_Coord step_x = 0;
318 Evas_Coord step_y = 0;
321 Evas_Coord page_x = 0;
322 Evas_Coord page_y = 0;
324 elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
325 elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
326 elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
327 elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
329 if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
331 if ((wd->horizontal) &&
332 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
333 (_item_multi_select_up(wd)))
334 || (_item_single_select_up(wd))))
336 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
339 else if ((!wd->horizontal) &&
340 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
341 (_item_multi_select_left(wd)))
342 || (_item_single_select_left(wd))))
344 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
350 else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
352 if ((wd->horizontal) &&
353 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
354 (_item_multi_select_down(wd)))
355 || (_item_single_select_down(wd))))
357 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
360 else if ((!wd->horizontal) &&
361 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
362 (_item_multi_select_right(wd)))
363 || (_item_single_select_right(wd))))
365 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
371 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
373 if ((wd->horizontal) &&
374 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
375 (_item_multi_select_left(wd)))
376 || (_item_single_select_left(wd))))
378 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
381 else if ((!wd->horizontal) &&
382 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
383 (_item_multi_select_up(wd)))
384 || (_item_single_select_up(wd))))
386 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
392 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
394 if ((wd->horizontal) &&
395 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
396 (_item_multi_select_right(wd)))
397 || (_item_single_select_right(wd))))
399 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
402 else if ((!wd->horizontal) &&
403 (((evas_key_modifier_is_set(ev->modifiers, "Shift")) &&
404 (_item_multi_select_down(wd)))
405 || (_item_single_select_down(wd))))
407 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
413 else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))
415 item = elm_gengrid_first_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, "End")) || (!strcmp(ev->keyname, "KP_End")))
422 item = elm_gengrid_last_item_get(obj);
423 elm_gengrid_item_bring_in(item);
424 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
427 else if ((!strcmp(ev->keyname, "Prior")) ||
428 (!strcmp(ev->keyname, "KP_Prior")))
433 x -= -(page_x * v_w) / 100;
440 y -= -(page_y * v_h) / 100;
445 else if ((!strcmp(ev->keyname, "Next")) || (!strcmp(ev->keyname, "KP_Next")))
450 x += -(page_x * v_w) / 100;
457 y += -(page_y * v_h) / 100;
462 else if (!strcmp(ev->keyname, "Escape"))
464 if (!_deselect_all_items(wd)) return EINA_FALSE;
465 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
468 else if ((!strcmp(ev->keyname, "Return")) ||
469 (!strcmp(ev->keyname, "KP_Enter")) ||
470 (!strcmp(ev->keyname, "space")))
472 item = elm_gengrid_selected_item_get(obj);
473 evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
474 evas_object_smart_callback_call(item->wd->self, "clicked", item); // will be removed
476 else return EINA_FALSE;
478 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
479 elm_smart_scroller_child_pos_set(wd->scr, x, y);
484 _deselect_all_items(Widget_Data *wd)
486 if (!wd->selected) return EINA_FALSE;
488 elm_gengrid_item_selected_set(wd->selected->data, EINA_FALSE);
494 _item_multi_select_left(Widget_Data *wd)
496 if (!wd->selected) return EINA_FALSE;
498 Elm_Gengrid_Item *prev = elm_gengrid_item_prev_get(wd->last_selected_item);
499 if (!prev) return EINA_TRUE;
500 if (elm_gengrid_item_selected_get(prev))
502 elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
503 wd->last_selected_item = prev;
504 elm_gengrid_item_show(wd->last_selected_item);
508 elm_gengrid_item_selected_set(prev, EINA_TRUE);
509 elm_gengrid_item_show(prev);
516 _item_multi_select_right(Widget_Data *wd)
518 if (!wd->selected) return EINA_FALSE;
520 Elm_Gengrid_Item *next = elm_gengrid_item_next_get(wd->last_selected_item);
521 if (!next) return EINA_TRUE;
522 if (elm_gengrid_item_selected_get(next))
524 elm_gengrid_item_selected_set(wd->last_selected_item, EINA_FALSE);
525 wd->last_selected_item = next;
526 elm_gengrid_item_show(wd->last_selected_item);
530 elm_gengrid_item_selected_set(next, EINA_TRUE);
531 elm_gengrid_item_show(next);
538 _item_multi_select_up(Widget_Data *wd)
541 Eina_Bool r = EINA_TRUE;
543 if (!wd->selected) return EINA_FALSE;
545 for (i = 0; (r) && (i < wd->nmax); i++)
546 r &= _item_multi_select_left(wd);
552 _item_multi_select_down(Widget_Data *wd)
555 Eina_Bool r = EINA_TRUE;
557 if (!wd->selected) return EINA_FALSE;
559 for (i = 0; (r) && (i < wd->nmax); i++)
560 r &= _item_multi_select_right(wd);
566 _item_single_select_up(Widget_Data *wd)
570 Elm_Gengrid_Item *prev;
574 prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
575 while ((prev) && (prev->delete_me))
576 prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
577 elm_gengrid_item_selected_set(prev, EINA_TRUE);
578 elm_gengrid_item_show(prev);
581 else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
583 if (!prev) return EINA_FALSE;
585 for (i = 1; i < wd->nmax; i++)
587 Elm_Gengrid_Item *tmp = elm_gengrid_item_prev_get(prev);
588 if (!tmp) return EINA_FALSE;
592 _deselect_all_items(wd);
594 elm_gengrid_item_selected_set(prev, EINA_TRUE);
595 elm_gengrid_item_show(prev);
600 _item_single_select_down(Widget_Data *wd)
604 Elm_Gengrid_Item *next;
608 next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
609 while ((next) && (next->delete_me))
610 next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
611 elm_gengrid_item_selected_set(next, EINA_TRUE);
612 elm_gengrid_item_show(next);
615 else next = elm_gengrid_item_next_get(wd->last_selected_item);
617 if (!next) return EINA_FALSE;
619 for (i = 1; i < wd->nmax; i++)
621 Elm_Gengrid_Item *tmp = elm_gengrid_item_next_get(next);
622 if (!tmp) return EINA_FALSE;
626 _deselect_all_items(wd);
628 elm_gengrid_item_selected_set(next, EINA_TRUE);
629 elm_gengrid_item_show(next);
634 _item_single_select_left(Widget_Data *wd)
636 Elm_Gengrid_Item *prev;
639 prev = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
640 while ((prev) && (prev->delete_me))
641 prev = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(prev)->prev);
643 else prev = elm_gengrid_item_prev_get(wd->last_selected_item);
645 if (!prev) return EINA_FALSE;
647 _deselect_all_items(wd);
649 elm_gengrid_item_selected_set(prev, EINA_TRUE);
650 elm_gengrid_item_show(prev);
655 _item_single_select_right(Widget_Data *wd)
657 Elm_Gengrid_Item *next;
660 next = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
661 while ((next) && (next->delete_me))
662 next = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(next)->next);
664 else next = elm_gengrid_item_next_get(wd->last_selected_item);
666 if (!next) return EINA_FALSE;
668 _deselect_all_items(wd);
670 elm_gengrid_item_selected_set(next, EINA_TRUE);
671 elm_gengrid_item_show(next);
676 _on_focus_hook(void *data __UNUSED__,
679 Widget_Data *wd = elm_widget_data_get(obj);
681 if (elm_widget_focus_get(obj))
683 edje_object_signal_emit(wd->self, "elm,action,focus", "elm");
684 evas_object_focus_set(wd->self, EINA_TRUE);
685 if ((wd->selected) && (!wd->last_selected_item))
686 wd->last_selected_item = eina_list_data_get(wd->selected);
690 edje_object_signal_emit(wd->self, "elm,action,unfocus", "elm");
691 evas_object_focus_set(wd->self, EINA_FALSE);
696 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
698 Widget_Data *wd = elm_widget_data_get(obj);
699 Elm_Gengrid_Item *item;
701 elm_smart_scroller_mirrored_set(wd->scr, rtl);
702 if (!wd->items) return;
703 item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
707 edje_object_mirrored_set(item->base.view, rtl);
708 elm_gengrid_item_update(item);
709 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
714 _theme_hook(Evas_Object *obj)
716 Widget_Data *wd = elm_widget_data_get(obj);
718 _elm_widget_mirrored_reload(obj);
719 _mirrored_set(obj, elm_widget_mirrored_get(obj));
720 elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
721 elm_widget_style_get(obj));
725 _del_pre_hook(Evas_Object *obj)
727 Widget_Data *wd = elm_widget_data_get(obj);
729 elm_gengrid_clear(obj);
730 evas_object_del(wd->pan_smart);
731 wd->pan_smart = NULL;
735 _del_hook(Evas_Object *obj)
737 Widget_Data *wd = elm_widget_data_get(obj);
742 _signal_emit_hook(Evas_Object *obj,
743 const char *emission,
746 Widget_Data *wd = elm_widget_data_get(obj);
748 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
753 _mouse_move(void *data,
754 Evas *evas __UNUSED__,
758 Elm_Gengrid_Item *item = data;
759 Evas_Event_Mouse_Move *ev = event_info;
760 Evas_Coord minw = 0, minh = 0, x, y, dx, dy, adx, ady;
761 Evas_Coord ox, oy, ow, oh, it_scrl_x, it_scrl_y;
763 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
765 if (!item->wd->on_hold)
767 item->wd->on_hold = EINA_TRUE;
768 if (!item->wd->wasselected)
769 _item_unselect(item);
772 if ((item->dragging) && (item->down))
774 if (item->long_timer)
776 ecore_timer_del(item->long_timer);
777 item->long_timer = NULL;
779 evas_object_smart_callback_call(item->wd->self, SIG_DRAG, item);
782 if ((!item->down) || (item->wd->longpressed))
784 if (item->long_timer)
786 ecore_timer_del(item->long_timer);
787 item->long_timer = NULL;
789 if ((item->wd->reorder_mode) && (item->wd->reorder_item))
791 evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &ow, &oh);
793 it_scrl_x = ev->cur.canvas.x - item->wd->reorder_item->dx;
794 it_scrl_y = ev->cur.canvas.y - item->wd->reorder_item->dy;
796 if (it_scrl_x < ox) item->wd->reorder_item_x = ox;
797 else if (it_scrl_x + item->wd->item_width > ox + ow)
798 item->wd->reorder_item_x = ox + ow - item->wd->item_width;
799 else item->wd->reorder_item_x = it_scrl_x;
801 if (it_scrl_y < oy) item->wd->reorder_item_y = oy;
802 else if (it_scrl_y + item->wd->item_height > oy + oh)
803 item->wd->reorder_item_y = oy + oh - item->wd->item_height;
804 else item->wd->reorder_item_y = it_scrl_y;
806 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
807 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
811 if (!item->display_only)
812 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
813 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
814 x = ev->cur.canvas.x - x;
815 y = ev->cur.canvas.y - y;
818 if (adx < 0) adx = -dx;
821 if (ady < 0) ady = -dy;
824 if ((adx > minw) || (ady > minh))
826 const char *left_drag, *right_drag;
827 if (!elm_widget_mirrored_get(item->wd->self))
829 left_drag = SIG_DRAG_START_LEFT;
830 right_drag = SIG_DRAG_START_RIGHT;
834 left_drag = SIG_DRAG_START_RIGHT;
835 right_drag = SIG_DRAG_START_LEFT;
839 if (item->long_timer)
841 ecore_timer_del(item->long_timer);
842 item->long_timer = NULL;
844 if (!item->wd->wasselected)
845 _item_unselect(item);
849 evas_object_smart_callback_call(item->wd->self, SIG_DRAG_START_UP,
854 evas_object_smart_callback_call(item->wd->self,
861 evas_object_smart_callback_call(item->wd->self,
862 SIG_DRAG_START_DOWN, item);
866 evas_object_smart_callback_call(item->wd->self,
869 evas_object_smart_callback_call(item->wd->self,
877 _long_press(void *data)
879 Elm_Gengrid_Item *item = data;
881 item->long_timer = NULL;
882 if ((item->disabled) || (item->dragging)) return ECORE_CALLBACK_CANCEL;
883 item->wd->longpressed = EINA_TRUE;
884 evas_object_smart_callback_call(item->wd->self, "longpressed", item);
885 if (item->wd->reorder_mode)
887 item->wd->reorder_item = item;
888 evas_object_raise(item->base.view);
889 elm_smart_scroller_hold_set(item->wd->scr, EINA_TRUE);
890 elm_smart_scroller_bounce_allow_set(item->wd->scr, EINA_FALSE, EINA_FALSE);
891 edje_object_signal_emit(item->base.view, "elm,state,reorder,enabled", "elm");
893 return ECORE_CALLBACK_CANCEL;
897 _mouse_down(void *data,
898 Evas *evas __UNUSED__,
902 Elm_Gengrid_Item *item = data;
903 Evas_Event_Mouse_Down *ev = event_info;
906 if (ev->button != 1) return;
909 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
910 item->dx = ev->canvas.x - x;
911 item->dy = ev->canvas.y - y;
912 item->wd->longpressed = EINA_FALSE;
913 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
914 else item->wd->on_hold = EINA_FALSE;
915 item->wd->wasselected = item->selected;
917 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
919 evas_object_smart_callback_call(item->wd->self, SIG_CLICKED_DOUBLE, item);
920 evas_object_smart_callback_call(item->wd->self, "clicked", item); // will be removed
922 if (item->long_timer) ecore_timer_del(item->long_timer);
924 item->long_timer = ecore_timer_add(_elm_config->longpress_timeout,
927 item->long_timer = NULL;
931 _mouse_up(void *data,
932 Evas *evas __UNUSED__,
933 Evas_Object *obj __UNUSED__,
936 Elm_Gengrid_Item *item = data;
937 Evas_Event_Mouse_Up *ev = event_info;
938 Eina_Bool dragged = EINA_FALSE;
940 if (ev->button != 1) return;
941 item->down = EINA_FALSE;
942 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) item->wd->on_hold = EINA_TRUE;
943 else item->wd->on_hold = EINA_FALSE;
944 if (item->long_timer)
946 ecore_timer_del(item->long_timer);
947 item->long_timer = NULL;
951 item->dragging = EINA_FALSE;
952 evas_object_smart_callback_call(item->wd->self, SIG_DRAG_STOP, item);
955 if (item->wd->on_hold)
957 item->wd->longpressed = EINA_FALSE;
958 item->wd->on_hold = EINA_FALSE;
961 if ((item->wd->reorder_mode) && (item->wd->reorder_item))
963 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
964 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
966 evas_object_smart_callback_call(item->wd->self, SIG_MOVED, item->wd->reorder_item);
967 item->wd->reorder_item = NULL;
968 elm_smart_scroller_hold_set(item->wd->scr, EINA_FALSE);
969 elm_smart_scroller_bounce_allow_set(item->wd->scr, item->wd->h_bounce, item->wd->v_bounce);
970 edje_object_signal_emit(item->base.view, "elm,state,reorder,disabled", "elm");
972 if (item->wd->longpressed)
974 item->wd->longpressed = EINA_FALSE;
975 if (!item->wd->wasselected) _item_unselect(item);
976 item->wd->wasselected = EINA_FALSE;
981 if (item->want_unrealize) _item_unrealize(item);
983 if ((item->disabled) || (dragged)) return;
991 else _item_unselect(item);
997 while (item->wd->selected)
998 _item_unselect(item->wd->selected->data);
1002 const Eina_List *l, *l_next;
1003 Elm_Gengrid_Item *item2;
1005 EINA_LIST_FOREACH_SAFE(item->wd->selected, l, l_next, item2)
1006 if (item2 != item) _item_unselect(item2);
1008 _item_hilight(item);
1014 _item_hilight(Elm_Gengrid_Item *item)
1016 if ((item->wd->no_select) || (item->delete_me) || (item->hilighted)) return;
1017 edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
1018 item->hilighted = EINA_TRUE;
1022 _item_realize(Elm_Gengrid_Item *item)
1027 if ((item->realized) || (item->delete_me)) return;
1028 item->base.view = edje_object_add(evas_object_evas_get(item->wd->self));
1029 edje_object_scale_set(item->base.view, elm_widget_scale_get(item->wd->self) *
1030 _elm_config->scale);
1031 edje_object_mirrored_set(item->base.view, elm_widget_mirrored_get(item->base.widget));
1032 evas_object_smart_member_add(item->base.view, item->wd->pan_smart);
1033 elm_widget_sub_object_add(item->wd->self, item->base.view);
1034 snprintf(style, sizeof(style), "item/%s",
1035 item->gic->item_style ? item->gic->item_style : "default");
1036 _elm_theme_object_set(item->wd->self, item->base.view, "gengrid", style,
1037 elm_widget_style_get(item->wd->self));
1039 evas_object_rectangle_add(evas_object_evas_get(item->wd->self));
1040 evas_object_color_set(item->spacer, 0, 0, 0, 0);
1041 elm_widget_sub_object_add(item->wd->self, item->spacer);
1042 evas_object_size_hint_min_set(item->spacer, 2 * _elm_config->scale, 1);
1043 edje_object_part_swallow(item->base.view, "elm.swallow.pad", item->spacer);
1045 if (item->gic->func.label_get)
1051 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
1053 EINA_LIST_FOREACH(item->labels, l, key)
1055 char *s = item->gic->func.label_get
1056 ((void *)item->base.data, item->wd->self, l->data);
1059 edje_object_part_text_set(item->base.view, l->data, s);
1065 if (item->gic->func.icon_get)
1071 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
1073 EINA_LIST_FOREACH(item->icons, l, key)
1075 Evas_Object *ic = item->gic->func.icon_get
1076 ((void *)item->base.data, item->wd->self, l->data);
1079 item->icon_objs = eina_list_append(item->icon_objs, ic);
1080 edje_object_part_swallow(item->base.view, key, ic);
1081 evas_object_show(ic);
1082 elm_widget_sub_object_add(item->wd->self, ic);
1087 if (item->gic->func.state_get)
1093 elm_widget_stringlist_get(edje_object_data_get(item->base.view,
1095 EINA_LIST_FOREACH(item->states, l, key)
1097 Eina_Bool on = item->gic->func.state_get
1098 ((void *)item->base.data, item->wd->self, l->data);
1101 snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
1102 edje_object_signal_emit(item->base.view, buf, "elm");
1107 if ((!item->wd->item_width) && (!item->wd->item_height))
1109 edje_object_size_min_restricted_calc(item->base.view,
1110 &item->wd->item_width,
1111 &item->wd->item_height,
1112 item->wd->item_width,
1113 item->wd->item_height);
1114 elm_coords_finger_size_adjust(1, &item->wd->item_width,
1115 1, &item->wd->item_height);
1118 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_DOWN,
1120 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_UP,
1122 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOUSE_MOVE,
1126 edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
1128 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1130 evas_object_show(item->base.view);
1132 if (item->tooltip.content_cb)
1134 elm_widget_item_tooltip_content_cb_set(item,
1135 item->tooltip.content_cb,
1136 item->tooltip.data, NULL);
1137 elm_widget_item_tooltip_style_set(item, item->tooltip.style);
1140 if (item->mouse_cursor)
1141 elm_widget_item_cursor_set(item, item->mouse_cursor);
1143 item->realized = EINA_TRUE;
1144 item->want_unrealize = EINA_FALSE;
1148 _item_unrealize(Elm_Gengrid_Item *item)
1152 if (!item->realized) return;
1153 if (item->long_timer)
1155 ecore_timer_del(item->long_timer);
1156 item->long_timer = NULL;
1158 evas_object_del(item->base.view);
1159 item->base.view = NULL;
1160 evas_object_del(item->spacer);
1161 item->spacer = NULL;
1162 elm_widget_stringlist_free(item->labels);
1163 item->labels = NULL;
1164 elm_widget_stringlist_free(item->icons);
1166 elm_widget_stringlist_free(item->states);
1167 item->states = NULL;
1169 EINA_LIST_FREE(item->icon_objs, icon)
1170 evas_object_del(icon);
1172 item->realized = EINA_FALSE;
1173 item->want_unrealize = EINA_FALSE;
1177 _reorder_item_moving_effect_timer_cb(void *data)
1179 Elm_Gengrid_Item *item = data;
1183 time = REORDER_EFFECT_TIME;
1184 t = ((0.0 > (t = ecore_loop_time_get()-item->moving_effect_start_time)) ? 0.0 : t);
1185 dx = ((item->tx - item->ox) / 10) * _elm_config->scale;
1186 dy = ((item->ty - item->oy) / 10) * _elm_config->scale;
1190 item->rx += (1 * sin((t / time) * (M_PI / 2)) * dx);
1191 item->ry += (1 * sin((t / time) * (M_PI / 2)) * dy);
1199 if ((((dx > 0) && (item->rx >= item->tx)) || ((dx <= 0) && (item->rx <= item->tx))) &&
1200 (((dy > 0) && (item->ry >= item->ty)) || ((dy <= 0) && (item->ry <= item->ty))))
1202 evas_object_move(item->base.view, item->tx, item->ty);
1203 evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
1204 item->moving = EINA_FALSE;
1205 item->item_moving_effect_timer = NULL;
1206 return ECORE_CALLBACK_CANCEL;
1209 evas_object_move(item->base.view, item->rx, item->ry);
1210 evas_object_resize(item->base.view, item->wd->item_width, item->wd->item_height);
1212 return ECORE_CALLBACK_RENEW;
1216 _item_place(Elm_Gengrid_Item *item,
1220 Evas_Coord x, y, ox, oy, cvx, cvy, cvw, cvh;
1221 Evas_Coord tch, tcw, alignw = 0, alignh = 0, vw, vh;
1222 Eina_Bool reorder_item_move_forward = EINA_FALSE;
1225 evas_object_geometry_get(item->wd->pan_smart, &ox, &oy, &vw, &vh);
1227 /* Preload rows/columns at each side of the Gengrid */
1228 cvx = ox - PRELOAD * item->wd->item_width;
1229 cvy = oy - PRELOAD * item->wd->item_height;
1230 cvw = vw + 2 * PRELOAD * item->wd->item_width;
1231 cvh = vh + 2 * PRELOAD * item->wd->item_height;
1236 if (item->wd->horizontal)
1238 int columns, items_visible = 0, items_row;
1240 if (item->wd->item_height > 0)
1241 items_visible = vh / item->wd->item_height;
1242 if (items_visible < 1)
1245 columns = item->wd->count / items_visible;
1246 if (item->wd->count % items_visible)
1249 tcw = item->wd->item_width * columns;
1250 alignw = (vw - tcw) * item->wd->align_x;
1252 items_row = items_visible;
1253 if (items_row > item->wd->count)
1254 items_row = item->wd->count;
1255 tch = items_row * item->wd->item_height;
1256 alignh = (vh - tch) * item->wd->align_y;
1260 int rows, items_visible = 0, items_col;
1262 if (item->wd->item_width > 0)
1263 items_visible = vw / item->wd->item_width;
1264 if (items_visible < 1)
1267 rows = item->wd->count / items_visible;
1268 if (item->wd->count % items_visible)
1271 tch = item->wd->item_height * rows;
1272 alignh = (vh - tch) * item->wd->align_y;
1274 items_col = items_visible;
1275 if (items_col > item->wd->count)
1276 items_col = item->wd->count;
1277 tcw = items_col * item->wd->item_width;
1278 alignw = (vw - tcw) * item->wd->align_x;
1281 x = cx * item->wd->item_width - item->wd->pan_x + ox + alignw;
1282 if (elm_widget_mirrored_get(item->wd->self))
1283 { /* Switch items side and componsate for pan_x when in RTL mode */
1285 evas_object_geometry_get(item->wd->self, NULL, NULL, &ww, NULL);
1286 x = ww - x - item->wd->item_width - item->wd->pan_x - item->wd->pan_x;
1289 y = cy * item->wd->item_height - item->wd->pan_y + oy + alignh;
1291 Eina_Bool was_realized = item->realized;
1292 if (ELM_RECTS_INTERSECT(x, y, item->wd->item_width, item->wd->item_height,
1293 cvx, cvy, cvw, cvh))
1295 _item_realize(item);
1297 evas_object_smart_callback_call(item->wd->self, SIG_REALIZED, item);
1298 if ((item->wd->reorder_mode) && (item->wd->reorder_item))
1300 if (item->moving) return;
1302 if (!item->wd->move_effect_enabled)
1307 if (item->wd->reorder_item == item)
1309 evas_object_move(item->base.view,
1310 item->wd->reorder_item_x, item->wd->reorder_item_y);
1311 evas_object_resize(item->base.view,
1312 item->wd->item_width, item->wd->item_height);
1317 if (item->wd->move_effect_enabled)
1319 if ((item->ox != x) || (item->oy != y))
1321 if (((item->wd->old_pan_x == item->wd->pan_x) && (item->wd->old_pan_y == item->wd->pan_y)) ||
1322 ((item->wd->old_pan_x != item->wd->pan_x) && !(item->ox - item->wd->pan_x + item->wd->old_pan_x == x)) ||
1323 ((item->wd->old_pan_y != item->wd->pan_y) && !(item->oy - item->wd->pan_y + item->wd->old_pan_y == y)))
1327 item->rx = item->ox;
1328 item->ry = item->oy;
1329 item->moving = EINA_TRUE;
1330 item->moving_effect_start_time = ecore_loop_time_get();
1331 item->item_moving_effect_timer = ecore_animator_add(_reorder_item_moving_effect_timer_cb, item);
1337 if (ELM_RECTS_INTERSECT(item->wd->reorder_item_x, item->wd->reorder_item_y,
1338 item->wd->item_width, item->wd->item_height,
1339 x+(item->wd->item_width/2), y+(item->wd->item_height/2),
1342 if (item->wd->horizontal)
1344 if ((item->wd->nmax * item->wd->reorder_item->x + item->wd->reorder_item->y) >
1345 (item->wd->nmax * item->x + item->y))
1346 reorder_item_move_forward = EINA_TRUE;
1350 if ((item->wd->nmax * item->wd->reorder_item->y + item->wd->reorder_item->x) >
1351 (item->wd->nmax * item->y + item->x))
1352 reorder_item_move_forward = EINA_TRUE;
1355 item->wd->items = eina_inlist_remove(item->wd->items,
1356 EINA_INLIST_GET(item->wd->reorder_item));
1357 if (reorder_item_move_forward)
1358 item->wd->items = eina_inlist_prepend_relative(item->wd->items,
1359 EINA_INLIST_GET(item->wd->reorder_item),
1360 EINA_INLIST_GET(item));
1362 item->wd->items = eina_inlist_append_relative(item->wd->items,
1363 EINA_INLIST_GET(item->wd->reorder_item),
1364 EINA_INLIST_GET(item));
1366 item->wd->reorder_item_changed = EINA_TRUE;
1367 item->wd->move_effect_enabled = EINA_TRUE;
1368 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1369 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1375 evas_object_move(item->base.view, x, y);
1376 evas_object_resize(item->base.view, item->wd->item_width,
1377 item->wd->item_height);
1381 _item_unrealize(item);
1383 evas_object_smart_callback_call(item->wd->self, SIG_UNREALIZED, item);
1387 static Elm_Gengrid_Item *
1388 _item_create(Widget_Data *wd,
1389 const Elm_Gengrid_Item_Class *gic,
1392 const void *func_data)
1394 Elm_Gengrid_Item *item;
1396 item = elm_widget_item_new(wd->self, Elm_Gengrid_Item);
1397 if (!item) return NULL;
1401 item->base.data = data;
1402 item->func.func = func;
1403 item->func.data = func_data;
1404 item->mouse_cursor = NULL;
1409 _item_del(Elm_Gengrid_Item *item)
1411 elm_widget_item_pre_notify_del(item);
1413 item->wd->selected = eina_list_remove(item->wd->selected, item);
1414 if (item->realized) _item_unrealize(item);
1415 if ((!item->delete_me) && (item->gic->func.del))
1416 item->gic->func.del((void *)item->base.data, item->wd->self);
1417 item->delete_me = EINA_TRUE;
1418 item->wd->items = eina_inlist_remove(item->wd->items, EINA_INLIST_GET(item));
1419 if (item->long_timer) ecore_timer_del(item->long_timer);
1420 if (item->tooltip.del_cb)
1421 item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
1422 item->wd->walking -= item->walking;
1424 if (item->wd->calc_job) ecore_job_del(item->wd->calc_job);
1425 item->wd->calc_job = ecore_job_add(_calc_job, item->wd);
1426 elm_widget_item_del(item);
1430 _item_select(Elm_Gengrid_Item *item)
1432 if ((item->wd->no_select) || (item->delete_me)) return;
1435 if (item->wd->always_select) goto call;
1438 item->selected = EINA_TRUE;
1439 item->wd->selected = eina_list_append(item->wd->selected, item);
1442 item->wd->walking++;
1443 if (item->func.func)
1444 item->func.func((void *)item->func.data, item->wd->self, item);
1445 if (!item->delete_me)
1446 evas_object_smart_callback_call(item->wd->self, SIG_SELECTED, item);
1448 item->wd->walking--;
1449 if ((item->wd->clear_me) && (!item->wd->walking))
1450 elm_gengrid_clear(item->base.widget);
1453 if ((!item->walking) && (item->delete_me))
1454 if (!item->relcount) _item_del(item);
1456 item->wd->last_selected_item = item;
1460 _item_unselect(Elm_Gengrid_Item *item)
1462 if ((item->delete_me) || (!item->hilighted)) return;
1463 edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
1464 item->hilighted = EINA_FALSE;
1467 item->selected = EINA_FALSE;
1468 item->wd->selected = eina_list_remove(item->wd->selected, item);
1469 evas_object_smart_callback_call(item->wd->self, SIG_UNSELECTED, item);
1474 _calc_job(void *data)
1476 Widget_Data *wd = data;
1477 Evas_Coord minw = 0, minh = 0, nmax = 0, cvw, cvh;
1480 evas_object_geometry_get(wd->pan_smart, NULL, NULL, &cvw, &cvh);
1481 if ((cvw != 0) || (cvh != 0))
1483 if ((wd->horizontal) && (wd->item_height > 0))
1484 nmax = cvh / wd->item_height;
1485 else if (wd->item_width > 0)
1486 nmax = cvw / wd->item_width;
1494 minw = ceil(count / (float)nmax) * wd->item_width;
1495 minh = nmax * wd->item_height;
1499 minw = nmax * wd->item_width;
1500 minh = ceil(count / (float)nmax) * wd->item_height;
1503 if ((minw != wd->minw) || (minh != wd->minh))
1507 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
1511 evas_object_smart_changed(wd->pan_smart);
1513 wd->calc_job = NULL;
1517 _pan_add(Evas_Object *obj)
1520 Evas_Object_Smart_Clipped_Data *cd;
1523 cd = evas_object_smart_data_get(obj);
1526 sd->__clipped_data = *cd;
1528 evas_object_smart_data_set(obj, sd);
1532 _pan_del(Evas_Object *obj)
1534 Pan *sd = evas_object_smart_data_get(obj);
1541 _pan_set(Evas_Object *obj,
1545 Pan *sd = evas_object_smart_data_get(obj);
1546 if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
1549 evas_object_smart_changed(obj);
1553 _pan_get(Evas_Object *obj,
1557 Pan *sd = evas_object_smart_data_get(obj);
1558 if (x) *x = sd->wd->pan_x;
1559 if (y) *y = sd->wd->pan_y;
1563 _pan_child_size_get(Evas_Object *obj,
1567 Pan *sd = evas_object_smart_data_get(obj);
1568 if (w) *w = sd->wd->minw;
1569 if (h) *h = sd->wd->minh;
1573 _pan_max_get(Evas_Object *obj,
1577 Pan *sd = evas_object_smart_data_get(obj);
1581 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1583 *x = (ow < sd->wd->minw) ? sd->wd->minw - ow : 0;
1585 *y = (oh < sd->wd->minh) ? sd->wd->minh - oh : 0;
1589 _pan_min_get(Evas_Object *obj,
1593 Pan *sd = evas_object_smart_data_get(obj);
1597 _pan_max_get(obj, &mx, &my);
1599 *x = -mx * sd->wd->align_x;
1601 *y = -my * sd->wd->align_y;
1605 _pan_resize(Evas_Object *obj,
1609 Pan *sd = evas_object_smart_data_get(obj);
1612 evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
1613 if ((ow == w) && (oh == h)) return;
1614 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1615 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1619 _pan_calculate(Evas_Object *obj)
1621 Pan *sd = evas_object_smart_data_get(obj);
1622 Evas_Coord cx = 0, cy = 0;
1623 Elm_Gengrid_Item *item;
1626 if (!sd->wd->nmax) return;
1628 sd->wd->reorder_item_changed = EINA_FALSE;
1630 EINA_INLIST_FOREACH(sd->wd->items, item)
1632 _item_place(item, cx, cy);
1633 if (sd->wd->reorder_item_changed) return;
1634 if (sd->wd->horizontal)
1636 cy = (cy + 1) % sd->wd->nmax;
1641 cx = (cx + 1) % sd->wd->nmax;
1646 if ((sd->wd->reorder_mode) && (sd->wd->reorder_item))
1648 if (!sd->wd->reorder_item_changed)
1650 sd->wd->old_pan_x = sd->wd->pan_x;
1651 sd->wd->old_pan_y = sd->wd->pan_y;
1653 sd->wd->move_effect_enabled = EINA_FALSE;
1655 evas_object_smart_callback_call(sd->wd->self, SIG_CHANGED, NULL);
1659 _pan_move(Evas_Object *obj,
1660 Evas_Coord x __UNUSED__,
1661 Evas_Coord y __UNUSED__)
1663 Pan *sd = evas_object_smart_data_get(obj);
1665 if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
1666 sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
1670 _hold_on(void *data __UNUSED__,
1672 void *event_info __UNUSED__)
1674 Widget_Data *wd = elm_widget_data_get(obj);
1676 elm_smart_scroller_hold_set(wd->scr, 1);
1680 _hold_off(void *data __UNUSED__,
1682 void *event_info __UNUSED__)
1684 Widget_Data *wd = elm_widget_data_get(obj);
1686 elm_smart_scroller_hold_set(wd->scr, 0);
1690 _freeze_on(void *data __UNUSED__,
1692 void *event_info __UNUSED__)
1694 Widget_Data *wd = elm_widget_data_get(obj);
1696 elm_smart_scroller_freeze_set(wd->scr, 1);
1700 _freeze_off(void *data __UNUSED__,
1702 void *event_info __UNUSED__)
1704 Widget_Data *wd = elm_widget_data_get(obj);
1706 elm_smart_scroller_freeze_set(wd->scr, 0);
1710 _scr_drag_start(void *data,
1711 Evas_Object *obj __UNUSED__,
1712 void *event_info __UNUSED__)
1714 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1718 _scr_drag_stop(void *data,
1719 Evas_Object *obj __UNUSED__,
1720 void *event_info __UNUSED__)
1722 evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1726 _scr_scroll(void *data,
1727 Evas_Object *obj __UNUSED__,
1728 void *event_info __UNUSED__)
1730 evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1734 * Add a new Gengrid object.
1736 * @param parent The parent object.
1737 * @return The new object or NULL if it cannot be created.
1739 * @see elm_gengrid_item_size_set()
1740 * @see elm_gengrid_horizontal_set()
1741 * @see elm_gengrid_item_append()
1742 * @see elm_gengrid_item_del()
1743 * @see elm_gengrid_clear()
1748 elm_gengrid_add(Evas_Object *parent)
1753 static Evas_Smart *smart = NULL;
1754 Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1756 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1758 ELM_SET_WIDTYPE(widtype, "gengrid");
1759 elm_widget_type_set(obj, "gengrid");
1760 elm_widget_sub_object_add(parent, obj);
1761 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1762 elm_widget_data_set(obj, wd);
1763 elm_widget_del_hook_set(obj, _del_hook);
1764 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1765 elm_widget_theme_hook_set(obj, _theme_hook);
1766 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1767 elm_widget_can_focus_set(obj, EINA_TRUE);
1768 elm_widget_event_hook_set(obj, _event_hook);
1770 wd->scr = elm_smart_scroller_add(e);
1771 elm_smart_scroller_widget_set(wd->scr, obj);
1772 elm_smart_scroller_object_theme_set(obj, wd->scr, "gengrid", "base",
1774 elm_widget_resize_object_set(obj, wd->scr);
1776 evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1777 evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1778 evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1780 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1785 wd->h_bounce = bounce;
1786 wd->v_bounce = bounce;
1787 wd->no_select = EINA_FALSE;
1789 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1790 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1791 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1792 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1794 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1798 static Evas_Smart_Class sc;
1800 evas_object_smart_clipped_smart_set(&_pan_sc);
1802 sc.name = "elm_gengrid_pan";
1803 sc.version = EVAS_SMART_CLASS_VERSION;
1806 sc.resize = _pan_resize;
1807 sc.move = _pan_move;
1808 sc.calculate = _pan_calculate;
1809 smart = evas_smart_class_new(&sc);
1813 wd->pan_smart = evas_object_smart_add(e, smart);
1814 wd->pan = evas_object_smart_data_get(wd->pan_smart);
1818 elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1819 _pan_set, _pan_get, _pan_max_get,
1820 _pan_min_get, _pan_child_size_get);
1822 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1827 * Set the size for the item of the Gengrid.
1829 * @param obj The Gengrid object.
1830 * @param w The item's width.
1831 * @param h The item's height;
1833 * @see elm_gengrid_item_size_get()
1838 elm_gengrid_item_size_set(Evas_Object *obj,
1842 ELM_CHECK_WIDTYPE(obj, widtype);
1843 Widget_Data *wd = elm_widget_data_get(obj);
1845 if ((wd->item_width == w) && (wd->item_height == h)) return;
1847 wd->item_height = h;
1848 if (wd->calc_job) ecore_job_del(wd->calc_job);
1849 wd->calc_job = ecore_job_add(_calc_job, wd);
1853 * Get the size of the item of the Gengrid.
1855 * @param obj The Gengrid object.
1856 * @param w Pointer to the item's width.
1857 * @param h Pointer to the item's height.
1859 * @see elm_gengrid_item_size_get()
1864 elm_gengrid_item_size_get(const Evas_Object *obj,
1868 ELM_CHECK_WIDTYPE(obj, widtype);
1869 Widget_Data *wd = elm_widget_data_get(obj);
1871 if (w) *w = wd->item_width;
1872 if (h) *h = wd->item_height;
1876 * Set item's alignment within the scroller.
1878 * @param obj The Gengrid object.
1879 * @param align_x The x alignment (0 <= x <= 1).
1880 * @param align_y The y alignment (0 <= y <= 1).
1882 * @see elm_gengrid_align_get()
1887 elm_gengrid_align_set(Evas_Object *obj,
1891 ELM_CHECK_WIDTYPE(obj, widtype);
1892 Widget_Data *wd = elm_widget_data_get(obj);
1896 else if (align_x < 0.0)
1898 wd->align_x = align_x;
1902 else if (align_y < 0.0)
1904 wd->align_y = align_y;
1908 * Get the alignenment set for the Gengrid object.
1910 * @param obj The Gengrid object.
1911 * @param align_x Pointer to x alignenment.
1912 * @param align_y Pointer to y alignenment.
1914 * @see elm_gengrid_align_set()
1919 elm_gengrid_align_get(const Evas_Object *obj,
1923 ELM_CHECK_WIDTYPE(obj, widtype);
1924 Widget_Data *wd = elm_widget_data_get(obj);
1925 if (align_x) *align_x = wd->align_x;
1926 if (align_y) *align_y = wd->align_y;
1930 * Add item to the end of the Gengrid.
1932 * @param obj The Gengrid object.
1933 * @param gic The item class for the item.
1934 * @param data The item data.
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_prepend()
1940 * @see elm_gengrid_item_insert_before()
1941 * @see elm_gengrid_item_insert_after()
1942 * @see elm_gengrid_item_del()
1946 EAPI Elm_Gengrid_Item *
1947 elm_gengrid_item_append(Evas_Object *obj,
1948 const Elm_Gengrid_Item_Class *gic,
1951 const void *func_data)
1953 Elm_Gengrid_Item *item;
1954 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1955 Widget_Data *wd = elm_widget_data_get(obj);
1956 if (!wd) return NULL;
1958 item = _item_create(wd, gic, data, func, func_data);
1959 if (!item) return NULL;
1960 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(item));
1962 if (wd->calc_job) ecore_job_del(wd->calc_job);
1963 wd->calc_job = ecore_job_add(_calc_job, wd);
1969 * Add item at start of the Gengrid.
1971 * This adds an item to the beginning of the grid.
1973 * @param obj The Gengrid object.
1974 * @param gic The item class for the item.
1975 * @param data The item data.
1976 * @param func Convenience function called when item is selected.
1977 * @param func_data Data passed to @p func above.
1978 * @return A handle to the item added or NULL if not possible.
1980 * @see elm_gengrid_item_append()
1981 * @see elm_gengrid_item_insert_before()
1982 * @see elm_gengrid_item_insert_after()
1983 * @see elm_gengrid_item_del()
1987 EAPI Elm_Gengrid_Item *
1988 elm_gengrid_item_prepend(Evas_Object *obj,
1989 const Elm_Gengrid_Item_Class *gic,
1992 const void *func_data)
1994 Elm_Gengrid_Item *item;
1995 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1996 Widget_Data *wd = elm_widget_data_get(obj);
1997 if (!wd) return NULL;
1999 item = _item_create(wd, gic, data, func, func_data);
2000 if (!item) return NULL;
2001 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(item));
2003 if (wd->calc_job) ecore_job_del(wd->calc_job);
2004 wd->calc_job = ecore_job_add(_calc_job, wd);
2010 * Insert and item before another in the Gengrid.
2012 * This inserts an item before another in the grid.
2014 * @param obj The Gengrid object.
2015 * @param gic The item class for the item.
2016 * @param data The item data.
2017 * @param relative The item to which insert before.
2018 * @param func Convenience function called when item is selected.
2019 * @param func_data Data passed to @p func above.
2020 * @return A handle to the item added or NULL if not possible.
2022 * @see elm_gengrid_item_append()
2023 * @see elm_gengrid_item_prepend()
2024 * @see elm_gengrid_item_insert_after()
2025 * @see elm_gengrid_item_del()
2029 EAPI Elm_Gengrid_Item *
2030 elm_gengrid_item_insert_before(Evas_Object *obj,
2031 const Elm_Gengrid_Item_Class *gic,
2033 Elm_Gengrid_Item *relative,
2035 const void *func_data)
2037 Elm_Gengrid_Item *item;
2038 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2039 EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
2040 Widget_Data *wd = elm_widget_data_get(obj);
2041 if (!wd) return NULL;
2043 item = _item_create(wd, gic, data, func, func_data);
2044 if (!item) return NULL;
2045 wd->items = eina_inlist_prepend_relative
2046 (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
2048 if (wd->calc_job) ecore_job_del(wd->calc_job);
2049 wd->calc_job = ecore_job_add(_calc_job, wd);
2055 * Insert and item after another in the Gengrid.
2057 * This inserts an item after another in the grid.
2059 * @param obj The Gengrid object.
2060 * @param gic The item class for the item.
2061 * @param data The item data.
2062 * @param relative The item to which insert after.
2063 * @param func Convenience function called when item is selected.
2064 * @param func_data Data passed to @p func above.
2065 * @return A handle to the item added or NULL if not possible.
2067 * @see elm_gengrid_item_append()
2068 * @see elm_gengrid_item_prepend()
2069 * @see elm_gengrid_item_insert_before()
2070 * @see elm_gengrid_item_del()
2074 EAPI Elm_Gengrid_Item *
2075 elm_gengrid_item_insert_after(Evas_Object *obj,
2076 const Elm_Gengrid_Item_Class *gic,
2078 Elm_Gengrid_Item *relative,
2080 const void *func_data)
2082 Elm_Gengrid_Item *item;
2083 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2084 EINA_SAFETY_ON_NULL_RETURN_VAL(relative, NULL);
2085 Widget_Data *wd = elm_widget_data_get(obj);
2086 if (!wd) return NULL;
2088 item = _item_create(wd, gic, data, func, func_data);
2089 if (!item) return NULL;
2090 wd->items = eina_inlist_append_relative
2091 (wd->items, EINA_INLIST_GET(item), EINA_INLIST_GET(relative));
2093 if (wd->calc_job) ecore_job_del(wd->calc_job);
2094 wd->calc_job = ecore_job_add(_calc_job, wd);
2100 * Remove an item from the Gengrid.
2102 * @param item The item to be removed.
2103 * @return @c EINA_TRUE on success or @c EINA_FALSE otherwise.
2105 * @see elm_gengrid_clear() to remove all items of the Gengrid.
2110 elm_gengrid_item_del(Elm_Gengrid_Item *item)
2112 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2113 if ((item->relcount > 0) || (item->walking > 0))
2115 item->delete_me = EINA_TRUE;
2116 elm_widget_item_pre_notify_del(item);
2118 item->wd->selected = eina_list_remove(item->wd->selected, item);
2119 if (item->gic->func.del)
2120 item->gic->func.del((void *)item->base.data, item->wd->self);
2128 * Set for what direction the Gengrid will expand.
2130 * @param obj The Gengrid object.
2131 * @param setting If @c EINA_TRUE the Gengrid will expand horizontally
2132 * or vertically if @c EINA_FALSE.
2137 elm_gengrid_horizontal_set(Evas_Object *obj,
2140 ELM_CHECK_WIDTYPE(obj, widtype);
2141 Widget_Data *wd = elm_widget_data_get(obj);
2143 if (setting == wd->horizontal) return;
2144 wd->horizontal = setting;
2146 /* Update the items to conform to the new layout */
2147 if (wd->calc_job) ecore_job_del(wd->calc_job);
2148 wd->calc_job = ecore_job_add(_calc_job, wd);
2152 * Get for what direction the Gengrid is expanded.
2154 * @param obj The Gengrid object.
2155 * @return If the Gengrid is expanded horizontally return @c EINA_TRUE
2156 * else @c EINA_FALSE.
2161 elm_gengrid_horizontal_get(const Evas_Object *obj)
2163 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2164 Widget_Data *wd = elm_widget_data_get(obj);
2165 if (!wd) return EINA_FALSE;
2166 return wd->horizontal;
2172 * This clears all items in the Gengrid, leaving it empty.
2174 * @param obj The Gengrid object.
2176 * @see elm_gengrid_item_del() to remove just one item.
2181 elm_gengrid_clear(Evas_Object *obj)
2183 ELM_CHECK_WIDTYPE(obj, widtype);
2184 Widget_Data *wd = elm_widget_data_get(obj);
2189 ecore_job_del(wd->calc_job);
2190 wd->calc_job = NULL;
2193 if (wd->walking > 0)
2195 Elm_Gengrid_Item *item;
2197 EINA_INLIST_FOREACH(wd->items, item)
2198 item->delete_me = 1;
2204 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
2206 wd->items = eina_inlist_remove(wd->items, wd->items);
2207 elm_widget_item_pre_notify_del(item);
2208 if (item->realized) _item_unrealize(item);
2209 if (item->gic->func.del)
2210 item->gic->func.del((void *)item->base.data, wd->self);
2211 if (item->long_timer) ecore_timer_del(item->long_timer);
2212 elm_widget_item_del(item);
2217 eina_list_free(wd->selected);
2218 wd->selected = NULL;
2226 evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
2227 evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
2231 * Get the real evas object of the Gengrid item
2233 * This returns the actual evas object used for the specified Gengrid
2234 * item. This may be NULL as it may not be created, and may be
2235 * deleted at any time by Gengrid. Do not modify this object (move,
2236 * resize, show, hide etc.) as Gengrid is controlling it. This
2237 * function is for querying, emitting custom signals or hooking lower
2238 * level callbacks for events. Do not delete this object under any
2241 * @param item The Gengrid item.
2242 * @return the evas object associated to this item.
2244 * @see elm_gengrid_item_data_get()
2248 EAPI const Evas_Object *
2249 elm_gengrid_item_object_get(const Elm_Gengrid_Item *item)
2251 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2252 return item->base.view;
2256 * Update the contents of an item
2258 * This updates an item by calling all the item class functions again
2259 * to get the icons, labels and states. Use this when the original
2260 * item data has changed and the changes are desired to be reflected.
2262 * @param item The item
2267 elm_gengrid_item_update(Elm_Gengrid_Item *item)
2269 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2270 if (!item->realized) return;
2271 if (item->want_unrealize) return;
2272 _item_unrealize(item);
2273 _item_realize(item);
2274 _item_place(item, item->x, item->y);
2278 * Returns the data associated to an item
2280 * This returns the data value passed on the elm_gengrid_item_append()
2281 * and related item addition calls.
2283 * @param item The Gengrid item.
2284 * @return the data associated to this item.
2286 * @see elm_gengrid_item_append()
2287 * @see elm_gengrid_item_object_get()
2292 elm_gengrid_item_data_get(const Elm_Gengrid_Item *item)
2294 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2295 return elm_widget_item_data_get(item);
2299 * Set the datan item from the gengrid item
2301 * This set the data value passed on the elm_gengrid_item_append() and
2302 * related item addition calls. This function will also call
2303 * elm_gengrid_item_update() so the item will be updated to reflect
2306 * @param item The item
2307 * @param data The new data pointer to set
2312 elm_gengrid_item_data_set(Elm_Gengrid_Item *item,
2315 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2316 elm_widget_item_data_set(item, data);
2317 elm_gengrid_item_update(item);
2321 * Get the item's coordinates.
2323 * This returns the logical position of the item whithin the Gengrid.
2325 * @param item The Gengrid item.
2326 * @param x The x-axis coordinate pointer.
2327 * @param y The y-axis coordinate pointer.
2332 elm_gengrid_item_pos_get(const Elm_Gengrid_Item *item,
2336 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2337 if (x) *x = item->x;
2338 if (y) *y = item->y;
2342 * Enable or disable multi-select in the Gengrid.
2344 * This enables (EINA_TRUE) or disables (EINA_FALSE) multi-select in
2345 * the Gengrid. This allows more than 1 item to be selected.
2347 * @param obj The Gengrid object.
2348 * @param multi Multi-select enabled/disabled
2353 elm_gengrid_multi_select_set(Evas_Object *obj,
2356 ELM_CHECK_WIDTYPE(obj, widtype);
2357 Widget_Data *wd = elm_widget_data_get(obj);
2363 * Get if multi-select in Gengrid is enabled or disabled
2365 * @param obj The Gengrid object
2366 * @return Multi-select enable/disable
2367 * (EINA_TRUE = enabled / EINA_FALSE = disabled)
2372 elm_gengrid_multi_select_get(const Evas_Object *obj)
2374 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2375 Widget_Data *wd = elm_widget_data_get(obj);
2376 if (!wd) return EINA_FALSE;
2381 * Get the selected item in the Gengrid
2383 * This gets the selected item in the Gengrid (if multi-select is
2384 * enabled only the first item in the list is selected - which is not
2385 * very useful, so see elm_gengrid_selected_items_get() for when
2386 * multi-select is used).
2388 * If no item is selected, NULL is returned.
2390 * @param obj The Gengrid object.
2391 * @return The selected item, or NULL if none.
2395 EAPI Elm_Gengrid_Item *
2396 elm_gengrid_selected_item_get(const Evas_Object *obj)
2398 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2399 Widget_Data *wd = elm_widget_data_get(obj);
2400 if (!wd) return NULL;
2401 if (wd->selected) return wd->selected->data;
2406 * Get a list of selected items in the Gengrid.
2408 * This returns a list of the selected items. This list pointer is
2409 * only valid so long as no items are selected or unselected (or
2410 * unselected implictly by deletion). The list contains
2411 * Elm_Gengrid_Item pointers.
2413 * @param obj The Gengrid object.
2414 * @return The list of selected items, or NULL if none are selected.
2418 EAPI const Eina_List *
2419 elm_gengrid_selected_items_get(const Evas_Object *obj)
2421 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2422 Widget_Data *wd = elm_widget_data_get(obj);
2423 if (!wd) return NULL;
2424 return wd->selected;
2428 * Set the selected state of an item.
2430 * This sets the selected state of an item. If multi-select is not
2431 * enabled and selected is EINA_TRUE, previously selected items are
2434 * @param item The item
2435 * @param selected The selected state.
2440 elm_gengrid_item_selected_set(Elm_Gengrid_Item *item,
2443 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2444 Widget_Data *wd = item->wd;
2446 if (item->delete_me) return;
2447 selected = !!selected;
2448 if (item->selected == selected) return;
2454 while (wd->selected)
2455 _item_unselect(wd->selected->data);
2457 _item_hilight(item);
2461 _item_unselect(item);
2465 * Get the selected state of an item.
2467 * This gets the selected state of an item (1 selected, 0 not selected).
2469 * @param item The item
2470 * @return The selected state
2475 elm_gengrid_item_selected_get(const Elm_Gengrid_Item *item)
2477 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2478 return item->selected;
2482 * Sets the disabled state of an item.
2484 * A disabled item cannot be selected or unselected. It will also
2485 * change appearance to disabled. This sets the disabled state (1
2486 * disabled, 0 not disabled).
2488 * @param item The item
2489 * @param disabled The disabled state
2494 elm_gengrid_item_disabled_set(Elm_Gengrid_Item *item,
2497 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2498 if (item->disabled == disabled) return;
2499 if (item->delete_me) return;
2500 item->disabled = !!disabled;
2504 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
2506 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
2511 * Get the disabled state of an item.
2513 * This gets the disabled state of the given item.
2515 * @param item The item
2516 * @return The disabled state
2521 elm_gengrid_item_disabled_get(const Elm_Gengrid_Item *item)
2523 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2524 if (item->delete_me) return EINA_FALSE;
2525 return item->disabled;
2528 static Evas_Object *
2529 _elm_gengrid_item_label_create(void *data,
2531 void *item __UNUSED__)
2533 Evas_Object *label = elm_label_add(obj);
2536 elm_object_style_set(label, "tooltip");
2537 elm_label_label_set(label, data);
2542 _elm_gengrid_item_label_del_cb(void *data,
2543 Evas_Object *obj __UNUSED__,
2544 void *event_info __UNUSED__)
2546 eina_stringshare_del(data);
2550 * Set the text to be shown in the gengrid item.
2552 * @param item Target item
2553 * @param text The text to set in the content
2555 * Setup the text as tooltip to object. The item can have only one
2556 * tooltip, so any previous tooltip data is removed.
2561 elm_gengrid_item_tooltip_text_set(Elm_Gengrid_Item *item,
2564 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2565 text = eina_stringshare_add(text);
2566 elm_gengrid_item_tooltip_content_cb_set(item, _elm_gengrid_item_label_create,
2568 _elm_gengrid_item_label_del_cb);
2572 * Set the content to be shown in the tooltip item
2574 * Setup the tooltip to item. The item can have only one tooltip, so
2575 * any previous tooltip data is removed. @p func(with @p data) will be
2576 * called every time that need show the tooltip and it should return a
2577 * valid Evas_Object. This object is then managed fully by tooltip
2578 * system and is deleted when the tooltip is gone.
2580 * @param item the gengrid item being attached a tooltip.
2581 * @param func the function used to create the tooltip contents.
2582 * @param data what to provide to @a func as callback data/context.
2583 * @param del_cb called when data is not needed anymore, either when
2584 * another callback replaces @func, the tooltip is unset with
2585 * elm_gengrid_item_tooltip_unset() or the owner @an item
2586 * dies. This callback receives as the first parameter the
2587 * given @a data, and @c event_info is the item.
2592 elm_gengrid_item_tooltip_content_cb_set(Elm_Gengrid_Item *item,
2593 Elm_Tooltip_Item_Content_Cb func,
2595 Evas_Smart_Cb del_cb)
2597 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_GOTO(item, error);
2599 if ((item->tooltip.content_cb == func) && (item->tooltip.data == data))
2602 if (item->tooltip.del_cb)
2603 item->tooltip.del_cb((void *)item->tooltip.data,
2604 item->base.widget, item);
2605 item->tooltip.content_cb = func;
2606 item->tooltip.data = data;
2607 item->tooltip.del_cb = del_cb;
2608 if (item->base.view)
2610 elm_widget_item_tooltip_content_cb_set(item,
2611 item->tooltip.content_cb,
2612 item->tooltip.data, NULL);
2613 elm_widget_item_tooltip_style_set(item, item->tooltip.style);
2619 if (del_cb) del_cb((void *)data, NULL, NULL);
2623 * Unset tooltip from item
2625 * @param item gengrid item to remove previously set tooltip.
2627 * Remove tooltip from item. The callback provided as del_cb to
2628 * elm_gengrid_item_tooltip_content_cb_set() will be called to notify
2629 * it is not used anymore.
2631 * @see elm_gengrid_item_tooltip_content_cb_set()
2636 elm_gengrid_item_tooltip_unset(Elm_Gengrid_Item *item)
2638 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2639 if ((item->base.view) && (item->tooltip.content_cb))
2640 elm_widget_item_tooltip_unset(item);
2642 if (item->tooltip.del_cb)
2643 item->tooltip.del_cb((void *)item->tooltip.data, item->base.widget, item);
2644 item->tooltip.del_cb = NULL;
2645 item->tooltip.content_cb = NULL;
2646 item->tooltip.data = NULL;
2647 if (item->tooltip.style)
2648 elm_gengrid_item_tooltip_style_set(item, NULL);
2652 * Sets a different style for this item tooltip.
2654 * @note before you set a style you should define a tooltip with
2655 * elm_gengrid_item_tooltip_content_cb_set() or
2656 * elm_gengrid_item_tooltip_text_set()
2658 * @param item gengrid item with tooltip already set.
2659 * @param style the theme style to use (default, transparent, ...)
2664 elm_gengrid_item_tooltip_style_set(Elm_Gengrid_Item *item,
2667 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2668 eina_stringshare_replace(&item->tooltip.style, style);
2669 if (item->base.view) elm_widget_item_tooltip_style_set(item, style);
2673 * Get the style for this item tooltip.
2675 * @param item gengrid item with tooltip already set.
2676 * @return style the theme style in use, defaults to "default". If the
2677 * object does not have a tooltip set, then NULL is returned.
2682 elm_gengrid_item_tooltip_style_get(const Elm_Gengrid_Item *item)
2684 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2685 return item->tooltip.style;
2689 * Set the cursor to be shown when mouse is over the gengrid item
2691 * @param item Target item
2692 * @param cursor the cursor name to be used.
2694 * @see elm_object_cursor_set()
2698 elm_gengrid_item_cursor_set(Elm_Gengrid_Item *item,
2701 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2702 eina_stringshare_replace(&item->mouse_cursor, cursor);
2703 if (item->base.view) elm_widget_item_cursor_set(item, cursor);
2707 * Get the cursor to be shown when mouse is over the gengrid item
2709 * @param item gengrid item with cursor already set.
2710 * @return the cursor name.
2715 elm_gengrid_item_cursor_get(const Elm_Gengrid_Item *item)
2717 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2718 return elm_widget_item_cursor_get(item);
2722 * Unset the cursor to be shown when mouse is over the gengrid item
2724 * @param item Target item
2726 * @see elm_object_cursor_unset()
2730 elm_gengrid_item_cursor_unset(Elm_Gengrid_Item *item)
2732 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2733 if (!item->mouse_cursor)
2736 if (item->base.view)
2737 elm_widget_item_cursor_unset(item);
2739 eina_stringshare_del(item->mouse_cursor);
2740 item->mouse_cursor = NULL;
2744 * Sets a different style for this item cursor.
2746 * @note before you set a style you should define a cursor with
2747 * elm_gengrid_item_cursor_set()
2749 * @param item gengrid item with cursor already set.
2750 * @param style the theme style to use (default, transparent, ...)
2755 elm_gengrid_item_cursor_style_set(Elm_Gengrid_Item *item,
2758 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2759 elm_widget_item_cursor_style_set(item, style);
2763 * Get the style for this item cursor.
2765 * @param item gengrid item with cursor already set.
2766 * @return style the theme style in use, defaults to "default". If the
2767 * object does not have a cursor set, then NULL is returned.
2772 elm_gengrid_item_cursor_style_get(const Elm_Gengrid_Item *item)
2774 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2775 return elm_widget_item_cursor_style_get(item);
2779 * Set if the cursor set should be searched on the theme or should use
2780 * the provided by the engine, only.
2782 * @note before you set if should look on theme you should define a
2783 * cursor with elm_object_cursor_set(). By default it will only look
2784 * for cursors provided by the engine.
2786 * @param item widget item with cursor already set.
2787 * @param engine_only boolean to define it cursors should be looked
2788 * only between the provided by the engine or searched on widget's
2794 elm_gengrid_item_cursor_engine_only_set(Elm_Gengrid_Item *item,
2795 Eina_Bool engine_only)
2797 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2798 elm_widget_item_cursor_engine_only_set(item, engine_only);
2802 * Get the cursor engine only usage for this item cursor.
2804 * @param item widget item with cursor already set.
2805 * @return engine_only boolean to define it cursors should be looked
2806 * only between the provided by the engine or searched on widget's
2807 * theme as well. If the object does not have a cursor set, then
2808 * EINA_FALSE is returned.
2813 elm_gengrid_item_cursor_engine_only_get(const Elm_Gengrid_Item *item)
2815 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2816 return elm_widget_item_cursor_engine_only_get(item);
2820 * Set the reorder mode
2822 * @param obj The Gengrid object
2823 * @param reorder_mode The reorder mode
2824 * (EINA_TRUE = on, EINA_FALSE = off)
2829 elm_gengrid_reorder_mode_set(Evas_Object *obj,
2830 Eina_Bool reorder_mode)
2832 ELM_CHECK_WIDTYPE(obj, widtype);
2833 Widget_Data *wd = elm_widget_data_get(obj);
2835 wd->reorder_mode = reorder_mode;
2839 * Get the reorder mode
2841 * @param obj The Gengrid object
2842 * @return The reorder mode
2843 * (EINA_TRUE = on, EINA_FALSE = off)
2848 elm_gengrid_reorder_mode_get(const Evas_Object *obj)
2850 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2851 Widget_Data *wd = elm_widget_data_get(obj);
2852 if (!wd) return EINA_FALSE;
2853 return wd->reorder_mode;
2857 * Set the always select mode.
2859 * Cells will only call their selection func and callback when first
2860 * becoming selected. Any further clicks will do nothing, unless you
2861 * enable always select with
2862 * elm_gengrid_always_select_mode_set(). This means even if selected,
2863 * every click will make the selected callbacks be called.
2865 * @param obj The Gengrid object
2866 * @param always_select The always select mode (EINA_TRUE = on,
2872 elm_gengrid_always_select_mode_set(Evas_Object *obj,
2873 Eina_Bool always_select)
2875 ELM_CHECK_WIDTYPE(obj, widtype);
2876 Widget_Data *wd = elm_widget_data_get(obj);
2878 wd->always_select = always_select;
2882 * Get the always select mode.
2884 * @param obj The Gengrid object.
2885 * @return The always select mode (EINA_TRUE = on, EINA_FALSE = off)
2890 elm_gengrid_always_select_mode_get(const Evas_Object *obj)
2892 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2893 Widget_Data *wd = elm_widget_data_get(obj);
2894 if (!wd) return EINA_FALSE;
2895 return wd->always_select;
2899 * Set no select mode.
2901 * This will turn off the ability to select items entirely and they
2902 * will neither appear selected nor call selected callback functions.
2904 * @param obj The Gengrid object
2905 * @param no_select The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2910 elm_gengrid_no_select_mode_set(Evas_Object *obj,
2911 Eina_Bool no_select)
2913 ELM_CHECK_WIDTYPE(obj, widtype);
2914 Widget_Data *wd = elm_widget_data_get(obj);
2916 wd->no_select = no_select;
2920 * Gets no select mode.
2922 * @param obj The Gengrid object
2923 * @return The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2928 elm_gengrid_no_select_mode_get(const Evas_Object *obj)
2930 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2931 Widget_Data *wd = elm_widget_data_get(obj);
2932 if (!wd) return EINA_FALSE;
2933 return wd->no_select;
2939 * This will enable or disable the scroller bounce mode for the
2940 * Gengrid. See elm_scroller_bounce_set() for details.
2942 * @param obj The Gengrid object
2943 * @param h_bounce Allow bounce horizontally
2944 * @param v_bounce Allow bounce vertically
2949 elm_gengrid_bounce_set(Evas_Object *obj,
2953 ELM_CHECK_WIDTYPE(obj, widtype);
2954 Widget_Data *wd = elm_widget_data_get(obj);
2956 elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
2957 wd->h_bounce = h_bounce;
2958 wd->v_bounce = v_bounce;
2962 * Get the bounce mode
2964 * @param obj The Gengrid object
2965 * @param h_bounce Allow bounce horizontally
2966 * @param v_bounce Allow bounce vertically
2971 elm_gengrid_bounce_get(const Evas_Object *obj,
2972 Eina_Bool *h_bounce,
2973 Eina_Bool *v_bounce)
2975 ELM_CHECK_WIDTYPE(obj, widtype);
2976 Widget_Data *wd = elm_widget_data_get(obj);
2978 *h_bounce = wd->h_bounce;
2979 *v_bounce = wd->v_bounce;
2983 * Get all items in the Gengrid.
2985 * This returns a list of the Gengrid items. The list contains
2986 * Elm_Gengrid_Item pointers.
2988 * @param obj The Gengrid object.
2989 * @return The list of items, or NULL if none.
2995 * Set gengrid scroll page size relative to viewport size.
2997 * The gengrid scroller is capable of limiting scrolling by the user
2998 * to "pages" That is to jump by and only show a "whole page" at a
2999 * time as if the continuous area of the scroller content is split
3000 * into page sized pieces. This sets the size of a page relative to
3001 * the viewport of the scroller. 1.0 is "1 viewport" is size
3002 * (horizontally or vertically). 0.0 turns it off in that axis. This
3003 * is mutually exclusive with page size (see
3004 * elm_gengrid_page_size_set() for more information). Likewise 0.5 is
3005 * "half a viewport". Sane usable valus are normally between 0.0 and
3006 * 1.0 including 1.0. If you only want 1 axis to be page "limited",
3007 * use 0.0 for the other axis.
3009 * @param obj The gengrid object
3010 * @param h_pagerel The horizontal page relative size
3011 * @param v_pagerel The vertical page relative size
3016 elm_gengrid_page_relative_set(Evas_Object *obj,
3020 Evas_Coord pagesize_h;
3021 Evas_Coord pagesize_v;
3023 ELM_CHECK_WIDTYPE(obj, widtype);
3024 Widget_Data *wd = elm_widget_data_get(obj);
3027 elm_smart_scroller_paging_get(wd->scr, NULL, NULL, &pagesize_h, &pagesize_v);
3028 elm_smart_scroller_paging_set(wd->scr, h_pagerel, v_pagerel, pagesize_h,
3033 * Get gengrid scroll page size relative to viewport size.
3035 * The gengrid scroller is capable of limiting scrolling by the user
3036 * to "pages" That is to jump by and only show a "whole page" at a
3037 * time as if the continuous area of the scroller content is split
3038 * into page sized pieces. This sets the size of a page relative to
3039 * the viewport of the scroller. 1.0 is "1 viewport" is size
3040 * (horizontally or vertically). 0.0 turns it off in that axis. This
3041 * is mutually exclusive with page size (see
3042 * elm_gengrid_page_size_set() for more information). Likewise 0.5 is
3043 * "half a viewport". Sane usable valus are normally between 0.0 and
3044 * 1.0 including 1.0. If you only want 1 axis to be page "limited",
3045 * use 0.0 for the other axis.
3047 * @param obj The gengrid object
3048 * @param h_pagerel The horizontal page relative size
3049 * @param v_pagerel The vertical page relative size
3054 elm_gengrid_page_relative_get(const Evas_Object *obj, double *h_pagerel, double *v_pagerel)
3056 ELM_CHECK_WIDTYPE(obj, widtype);
3057 Widget_Data *wd = elm_widget_data_get(obj);
3060 elm_smart_scroller_paging_get(wd->scr, h_pagerel, v_pagerel, NULL, NULL);
3064 * Set gengrid scroll page size.
3066 * See also elm_gengrid_page_relative_set(). This, instead of a page
3067 * size being relative to the viewport, sets it to an absolute fixed
3068 * value, with 0 turning it off for that axis.
3070 * @param obj The gengrid object
3071 * @param h_pagesize The horizontal page size
3072 * @param v_pagesize The vertical page size
3077 elm_gengrid_page_size_set(Evas_Object *obj,
3078 Evas_Coord h_pagesize,
3079 Evas_Coord v_pagesize)
3084 ELM_CHECK_WIDTYPE(obj, widtype);
3085 Widget_Data *wd = elm_widget_data_get(obj);
3087 elm_smart_scroller_paging_get(wd->scr, &pagerel_h, &pagerel_v, NULL, NULL);
3088 elm_smart_scroller_paging_set(wd->scr, pagerel_h, pagerel_v, h_pagesize,
3093 * Get the first item in the gengrid
3095 * This returns the first item in the list.
3097 * @param obj The gengrid object
3098 * @return The first item, or NULL if none
3102 EAPI Elm_Gengrid_Item *
3103 elm_gengrid_first_item_get(const Evas_Object *obj)
3105 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3106 Widget_Data *wd = elm_widget_data_get(obj);
3107 if (!wd) return NULL;
3108 if (!wd->items) return NULL;
3109 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items);
3110 while ((item) && (item->delete_me))
3111 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
3116 * Get the last item in the gengrid
3118 * This returns the last item in the list.
3120 * @return The last item, or NULL if none
3124 EAPI Elm_Gengrid_Item *
3125 elm_gengrid_last_item_get(const Evas_Object *obj)
3127 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3128 Widget_Data *wd = elm_widget_data_get(obj);
3129 if (!wd) return NULL;
3130 if (!wd->items) return NULL;
3131 Elm_Gengrid_Item *item = ELM_GENGRID_ITEM_FROM_INLIST(wd->items->last);
3132 while ((item) && (item->delete_me))
3133 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
3138 * Get the next item in the gengrid
3140 * This returns the item after the item @p item.
3142 * @param item The item
3143 * @return The item after @p item, or NULL if none
3147 EAPI Elm_Gengrid_Item *
3148 elm_gengrid_item_next_get(const Elm_Gengrid_Item *item)
3150 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
3153 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
3154 if ((item) && (!item->delete_me)) break;
3156 return (Elm_Gengrid_Item *)item;
3160 * Get the previous item in the gengrid
3162 * This returns the item before the item @p item.
3164 * @param item The item
3165 * @return The item before @p item, or NULL if none
3169 EAPI Elm_Gengrid_Item *
3170 elm_gengrid_item_prev_get(const Elm_Gengrid_Item *item)
3172 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
3175 item = ELM_GENGRID_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
3176 if ((item) && (!item->delete_me)) break;
3178 return (Elm_Gengrid_Item *)item;
3182 * Get the gengrid object from an item
3184 * This returns the gengrid object itself that an item belongs to.
3186 * @param item The item
3187 * @return The gengrid object
3192 elm_gengrid_item_gengrid_get(const Elm_Gengrid_Item *item)
3194 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
3195 return item->base.widget;
3199 * Show the given item
3201 * This causes gengrid to jump to the given item @p item and show it
3202 * (by scrolling), if it is not fully visible.
3204 * @param item The item
3209 elm_gengrid_item_show(Elm_Gengrid_Item *item)
3211 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
3212 Widget_Data *wd = elm_widget_data_get(item->wd->self);
3213 Evas_Coord minx = 0, miny = 0;
3216 if ((!item) || (item->delete_me)) return;
3217 _pan_min_get(wd->pan_smart, &minx, &miny);
3219 elm_smart_scroller_child_region_show(item->wd->scr,
3220 item->x * wd->item_width + minx,
3221 item->y * wd->item_height + miny,
3222 item->wd->item_width,
3223 item->wd->item_height);
3227 * Bring in the given item
3229 * This causes gengrig to jump to the given item @p item and show it
3230 * (by scrolling), if it is not fully visible. This may use animation
3231 * to do so and take a period of time
3233 * @param item The item
3238 elm_gengrid_item_bring_in(Elm_Gengrid_Item *item)
3240 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
3241 if (item->delete_me) return;
3243 Evas_Coord minx = 0, miny = 0;
3244 Widget_Data *wd = elm_widget_data_get(item->wd->self);
3246 _pan_min_get(wd->pan_smart, &minx, &miny);
3248 elm_smart_scroller_region_bring_in(item->wd->scr,
3249 item->x * wd->item_width + minx,
3250 item->y * wd->item_height + miny,
3251 item->wd->item_width,
3252 item->wd->item_height);