1 #include <Elementary.h>
5 * @defgroup Pager Pager
7 * The pager is an object that allows flipping (with animation) between 1 or
8 * more “pages” of objects, much like a stack of windows within the window.
10 * Objects can be pushed or popped from the stack or deleted as normal.
11 * Pushes and pops will animate (and a pop will delete the object once the
12 * animation is finished). Any object in the pager can be promoted to the top
13 * (from its current stacking position) as well. Objects are pushed to the
14 * top with elm_pager_content_push() and when the top item is no longer
15 * wanted, simply pop it with elm_pager_content_pop() and it will also be
16 * deleted. Any object you wish to promote to the top that is already in the
17 * pager, simply use elm_pager_content_promote(). If an object is no longer
18 * needed and is not the top item, just delete it as normal. You can query
19 * which objects are the top and bottom with elm_pager_content_bottom_get()
20 * and elm_pager_content_top_get().
22 * Signals that you can add callbacks for are:
24 * "hide,finished" - when the previous page is hided
28 typedef struct _Widget_Data Widget_Data;
29 typedef struct _Item Item;
35 Evas_Object *rect, *clip;
36 Eina_Bool disable_animation: 1;
41 Evas_Object *obj, *base, *content;
42 Evas_Coord minw, minh;
46 static const char *widtype = NULL;
47 static void _del_hook(Evas_Object *obj);
48 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
49 static void _theme_hook(Evas_Object *obj);
50 static void _sizing_eval(Evas_Object *obj);
51 static void _changed_size_hints(void *data,
55 static void _content_del(void *data,
59 static Eina_List *_item_get(Evas_Object *obj, Evas_Object *content);
61 static const char SIG_HIDE_FINISHED[] = "hide,finished";
63 static const Evas_Smart_Cb_Description _signals[] = {
64 {SIG_HIDE_FINISHED, ""},
69 _del_hook(Evas_Object *obj)
71 Widget_Data *wd = elm_widget_data_get(obj);
77 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
79 Widget_Data *wd = elm_widget_data_get(obj);
83 EINA_LIST_FOREACH(wd->stack, l, it)
84 edje_object_mirrored_set(it->base, rtl);
88 _theme_hook(Evas_Object *obj)
90 Widget_Data *wd = elm_widget_data_get(obj);
94 _elm_widget_mirrored_reload(obj);
95 _mirrored_set(obj, elm_widget_mirrored_get(obj));
96 EINA_LIST_FOREACH(wd->stack, l, it)
98 _elm_theme_object_set(obj, it->base, "pager", "base",
99 elm_widget_style_get(obj));
100 edje_object_scale_set(it->base, elm_widget_scale_get(obj) *
107 _item_get(Evas_Object *obj, Evas_Object *content)
109 Widget_Data *wd = elm_widget_data_get(obj);
112 if (!wd) return NULL;
114 EINA_LIST_FOREACH(wd->stack, l, it)
116 if (it->content == content)
124 _elm_pager_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
126 Widget_Data *wd = elm_widget_data_get(obj);
129 if ((!wd) || (!wd->top))
132 cur = wd->top->content;
134 /* Try Focus cycle in subitem */
135 return elm_widget_focus_next_get(cur, dir, next);
139 _sizing_eval(Evas_Object *obj)
141 Widget_Data *wd = elm_widget_data_get(obj);
142 Evas_Coord minw = -1, minh = -1;
146 EINA_LIST_FOREACH(wd->stack, l, it)
148 if (it->minw > minw) minw = it->minw;
149 if (it->minh > minh) minh = it->minh;
151 evas_object_size_hint_min_set(obj, minw, minh);
152 evas_object_size_hint_max_set(obj, -1, -1);
156 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
159 Evas_Coord minw = -1, minh = -1;
160 evas_object_size_hint_min_get(it->content, &minw, &minh);
161 // FIXME: why is this needed? how does edje get this unswallowed or
162 // lose its callbacks to edje
163 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
164 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
165 _sizing_eval(it->obj);
169 _eval_top(Evas_Object *obj)
171 Widget_Data *wd = elm_widget_data_get(obj);
172 Eina_Bool show_noanimate = EINA_TRUE;
175 if (!wd->stack) return;
176 ittop = eina_list_last(wd->stack)->data;
177 if (ittop != wd->top)
180 const char *onshow, *onhide;
185 if(wd->disable_animation)
187 edje_object_signal_emit(o, "elm,action,hide,noanimate", "elm");
189 wd->stack = eina_list_remove(wd->stack, wd->top);
191 else if (wd->top->popme)
193 edje_object_signal_emit(o, "elm,action,pop", "elm");
194 wd->stack = eina_list_remove(wd->stack, wd->top);
197 edje_object_signal_emit(o, "elm,action,hide", "elm");
198 onhide = edje_object_data_get(o, "onhide");
201 if (!strcmp(onhide, "raise")) evas_object_raise(o);
202 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
207 show_noanimate = EINA_FALSE;
209 wd->oldtop = wd->top;
213 if ((!show_noanimate)||(wd->disable_animation))
215 edje_object_signal_emit(o, "elm,action,show,noanimate", "elm");
219 if (elm_object_focus_get(wd->oldtop->content))
220 elm_object_focus(wd->top->content);
221 if (wd->oldtop->popme)
222 edje_object_signal_emit(o, "elm,action,show", "elm");
224 edje_object_signal_emit(o, "elm,action,push", "elm");
227 edje_object_signal_emit(o, "elm,action,push", "elm");
228 onshow = edje_object_data_get(o, "onshow");
231 if (!strcmp(onshow, "raise")) evas_object_raise(o);
232 else if (!strcmp(onshow, "lower")) evas_object_lower(o);
238 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
240 Widget_Data *wd = elm_widget_data_get(data);
245 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
246 EINA_LIST_FOREACH(wd->stack, l, it)
247 evas_object_move(it->base, x, y);
251 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
253 Widget_Data *wd = elm_widget_data_get(data);
257 l = _item_get(data, obj);
260 wd->stack = eina_list_remove_list(wd->stack, l);
261 evas_object_event_callback_del_full
262 (obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
263 evas_object_del(it->base);
269 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
271 Widget_Data *wd = elm_widget_data_get(data);
276 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
277 EINA_LIST_FOREACH(wd->stack, l, it) evas_object_resize(it->base, w, h);
281 _signal_hide_finished(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
284 Evas_Object *obj2 = it->obj;
285 Evas_Object *content = it->content;
289 evas_object_del(it->base);
290 evas_object_event_callback_del_full(content,
291 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
294 evas_object_event_callback_del(content,
297 evas_object_del(content);
302 evas_object_hide(it->base);
303 edje_object_signal_emit(it->base, "elm,action,reset", "elm");
304 edje_object_message_signal_process(it->base);
305 evas_object_hide(content);
307 evas_object_smart_callback_call(obj2, SIG_HIDE_FINISHED, content);
312 * Add a new pager to the parent
314 * @param parent The parent object
315 * @return The new object or NULL if it cannot be created
320 elm_pager_add(Evas_Object *parent)
326 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
328 ELM_SET_WIDTYPE(widtype, "pager");
329 elm_widget_type_set(obj, "pager");
330 elm_widget_sub_object_add(parent, obj);
331 elm_widget_data_set(obj, wd);
332 elm_widget_del_hook_set(obj, _del_hook);
333 elm_widget_theme_hook_set(obj, _theme_hook);
334 elm_widget_focus_next_hook_set(obj, _elm_pager_focus_next_hook);
335 elm_widget_can_focus_set(obj, EINA_FALSE);
337 wd->clip = evas_object_rectangle_add(e);
338 elm_widget_resize_object_set(obj, wd->clip);
339 elm_widget_sub_object_add(obj, wd->clip);
341 wd->rect = evas_object_rectangle_add(e);
342 elm_widget_sub_object_add(obj, wd->rect);
343 evas_object_color_set(wd->rect, 255, 255, 255, 0);
344 evas_object_clip_set(wd->rect, wd->clip);
346 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, obj);
347 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
349 evas_object_smart_callbacks_descriptions_set(obj, _signals);
351 _mirrored_set(obj, elm_widget_mirrored_get(obj));
357 * Push an object to the top of the pager stack (and show it)
359 * The object pushed becomes a child of the pager and will be controlled
360 * it and deleted when the pager is deleted.
362 * @param obj The pager object
363 * @param content The object to push
366 * @warning It will be failed if the content exists on the stack already.
369 elm_pager_content_push(Evas_Object *obj, Evas_Object *content)
371 ELM_CHECK_WIDTYPE(obj, widtype);
372 Widget_Data *wd = elm_widget_data_get(obj);
373 Evas_Coord x, y, w, h;
376 if ((!wd) || (!content)) return;
377 if (_item_get(obj, content)) return;
382 it->content = content;
383 it->base = edje_object_add(evas_object_evas_get(obj));
384 evas_object_smart_member_add(it->base, obj);
385 evas_object_geometry_get(obj, &x, &y, &w, &h);
386 evas_object_move(it->base, x, y);
387 evas_object_resize(it->base, w, h);
388 evas_object_clip_set(it->base, wd->clip);
389 elm_widget_sub_object_add(obj, it->base);
390 elm_widget_sub_object_add(obj, it->content);
391 _elm_theme_object_set(obj,
395 elm_widget_style_get(obj));
396 edje_object_signal_callback_add(it->base,
397 "elm,action,hide,finished",
399 _signal_hide_finished,
401 evas_object_event_callback_add(it->content,
402 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
405 evas_object_event_callback_add(it->content,
409 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
410 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
411 evas_object_data_set(it->base, "_elm_leaveme", obj);
412 evas_object_show(it->content);
413 wd->stack = eina_list_append(wd->stack, it);
419 * Pop the object that is on top of the stack
421 * This pops the object that is on top (visible) in the pager, makes it
422 * disappear, then deletes the object. The object that was underneath it
423 * on the stack will become visible.
425 * @param obj The pager object
430 elm_pager_content_pop(Evas_Object *obj)
432 ELM_CHECK_WIDTYPE(obj, widtype);
433 Widget_Data *wd = elm_widget_data_get(obj);
437 if (!wd->stack) return;
438 it = eina_list_last(wd->stack)->data;
439 it->popme = EINA_TRUE;
440 ll = eina_list_last(wd->stack);
451 edje_object_signal_emit(o, "elm,action,pop", "elm");
452 wd->stack = eina_list_remove(wd->stack, it);
453 onhide = edje_object_data_get(o, "onhide");
456 if (!strcmp(onhide, "raise")) evas_object_raise(o);
457 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
464 elm_pager_content_promote(obj, it->content);
472 Evas_Object *obj = data;
473 evas_object_del(obj);
477 * Pop to the object that is on the stack
479 * This pops the objects that are on the stack, makes them
480 * disappear, then deletes the objects. The content will become visible.
482 * @param obj The pager object
483 * @param content The object to show
488 elm_pager_to_content_pop(Evas_Object *obj, Evas_Object *content)
490 ELM_CHECK_WIDTYPE(obj, widtype);
491 Widget_Data *wd = elm_widget_data_get(obj);
495 if (!wd->stack) return;
496 it = eina_list_last(wd->stack)->data;
497 it->popme = EINA_TRUE;
498 ll = eina_list_last(wd->stack);
504 if(it->content != content)
506 wd->stack = eina_list_remove_list(wd->stack, ll);
507 ecore_job_add(_del_job, it->content);
520 * Promote an object already in the pager stack to the top of the stack
522 * This will take the indicated object and promote it to the top of the stack
523 * as if it had been pushed there. The object must already be inside the
524 * pager stack to work.
526 * @param obj The pager object
527 * @param content The object to promote
532 elm_pager_content_promote(Evas_Object *obj, Evas_Object *content)
534 ELM_CHECK_WIDTYPE(obj, widtype);
535 Widget_Data *wd = elm_widget_data_get(obj);
539 l = _item_get(obj, content);
543 wd->stack = eina_list_remove_list(wd->stack, l);
544 wd->stack = eina_list_append(wd->stack, it);
549 * Return the object at the bottom of the pager stack
551 * @param obj The pager object
552 * @return The bottom object or NULL if none
557 elm_pager_content_bottom_get(const Evas_Object *obj)
559 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
560 Widget_Data *wd = elm_widget_data_get(obj);
562 if (!wd) return NULL;
563 if (!wd->stack) return NULL;
564 it = wd->stack->data;
569 * Return the object at the top of the pager stack
571 * @param obj The pager object
572 * @return The top object or NULL if none
577 elm_pager_content_top_get(const Evas_Object *obj)
579 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
580 Widget_Data *wd = elm_widget_data_get(obj);
581 if (!wd) return NULL;
582 if (!wd->top) return NULL;
583 return wd->top->content;
587 * This disables content animation on push/pop.
589 * @param obj The pager object
590 * @param disable if EINA_TRUE animation is disabled.
595 elm_pager_animation_disabled_set(Evas_Object *obj, Eina_Bool disable)
597 ELM_CHECK_WIDTYPE(obj, widtype)NULL;
598 Widget_Data *wd = elm_widget_data_get(obj);
599 wd->disable_animation = disable;