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);
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 animate=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");
188 wd->stack = eina_list_remove(wd->stack, wd->top);
190 else if (wd->top->popme)
192 edje_object_signal_emit(o, "elm,action,pop", "elm");
193 wd->stack = eina_list_remove(wd->stack, wd->top);
196 edje_object_signal_emit(o, "elm,action,hide", "elm");
197 onhide = edje_object_data_get(o, "onhide");
200 if (!strcmp(onhide, "raise")) evas_object_raise(o);
201 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
206 animate = EINA_FALSE;
208 wd->oldtop = wd->top;
212 if ((!animate)||(wd->disable_animation))
214 edje_object_signal_emit(o, "elm,action,show,noanimate", "elm");
218 if (elm_object_focus_get(wd->oldtop->content))
219 elm_object_focus(wd->top->content);
220 if (wd->oldtop->popme)
221 edje_object_signal_emit(o, "elm,action,show", "elm");
223 edje_object_signal_emit(o, "elm,action,push", "elm");
226 edje_object_signal_emit(o, "elm,action,push", "elm");
227 onshow = edje_object_data_get(o, "onshow");
230 if (!strcmp(onshow, "raise")) evas_object_raise(o);
231 else if (!strcmp(onshow, "lower")) evas_object_lower(o);
237 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
239 Widget_Data *wd = elm_widget_data_get(data);
244 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
245 EINA_LIST_FOREACH(wd->stack, l, it)
246 evas_object_move(it->base, x, y);
250 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
252 Widget_Data *wd = elm_widget_data_get(data);
256 l = _item_get(data, obj);
259 wd->stack = eina_list_remove_list(wd->stack, l);
260 evas_object_event_callback_del_full
261 (data, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
262 evas_object_del(it->base);
268 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
270 Widget_Data *wd = elm_widget_data_get(data);
275 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
276 EINA_LIST_FOREACH(wd->stack, l, it) evas_object_resize(it->base, w, h);
280 _signal_hide_finished(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
283 Evas_Object *obj2 = it->obj;
284 Evas_Object *content = it->content;
288 evas_object_del(it->base);
289 evas_object_event_callback_del_full(content,
290 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
293 evas_object_event_callback_del(content,
296 evas_object_del(content);
301 evas_object_hide(it->base);
302 edje_object_signal_emit(it->base, "elm,action,reset", "elm");
303 edje_object_message_signal_process(it->base);
304 evas_object_hide(content);
306 evas_object_smart_callback_call(obj2, SIG_HIDE_FINISHED, content);
311 * Add a new pager to the parent
313 * @param parent The parent object
314 * @return The new object or NULL if it cannot be created
319 elm_pager_add(Evas_Object *parent)
325 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
327 ELM_SET_WIDTYPE(widtype, "pager");
328 elm_widget_type_set(obj, "pager");
329 elm_widget_sub_object_add(parent, obj);
330 elm_widget_data_set(obj, wd);
331 elm_widget_del_hook_set(obj, _del_hook);
332 elm_widget_theme_hook_set(obj, _theme_hook);
333 elm_widget_focus_next_hook_set(obj, _elm_pager_focus_next_hook);
334 elm_widget_can_focus_set(obj, EINA_FALSE);
336 wd->clip = evas_object_rectangle_add(e);
337 elm_widget_resize_object_set(obj, wd->clip);
338 elm_widget_sub_object_add(obj, wd->clip);
340 wd->rect = evas_object_rectangle_add(e);
341 elm_widget_sub_object_add(obj, wd->rect);
342 evas_object_color_set(wd->rect, 255, 255, 255, 0);
343 evas_object_clip_set(wd->rect, wd->clip);
345 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, obj);
346 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
348 evas_object_smart_callbacks_descriptions_set(obj, _signals);
350 _mirrored_set(obj, elm_widget_mirrored_get(obj));
356 * Push an object to the top of the pager stack (and show it)
358 * The object pushed becomes a child of the pager and will be controlled
359 * it and deleted when the pager is deleted.
361 * @param obj The pager object
362 * @param content The object to push
365 * @warning It will be failed if the content exists on the stack already.
368 elm_pager_content_push(Evas_Object *obj, Evas_Object *content)
370 ELM_CHECK_WIDTYPE(obj, widtype);
371 Widget_Data *wd = elm_widget_data_get(obj);
372 Evas_Coord x, y, w, h;
375 if ((!wd) || (!content)) return;
376 if (_item_get(obj, content)) return;
381 it->content = content;
382 it->base = edje_object_add(evas_object_evas_get(obj));
383 evas_object_smart_member_add(it->base, obj);
384 evas_object_geometry_get(obj, &x, &y, &w, &h);
385 evas_object_move(it->base, x, y);
386 evas_object_resize(it->base, w, h);
387 evas_object_clip_set(it->base, wd->clip);
388 elm_widget_sub_object_add(obj, it->base);
389 elm_widget_sub_object_add(obj, it->content);
390 _elm_theme_object_set(obj,
394 elm_widget_style_get(obj));
395 edje_object_signal_callback_add(it->base,
396 "elm,action,hide,finished",
398 _signal_hide_finished,
400 evas_object_event_callback_add(it->content,
401 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
404 evas_object_event_callback_add(it->content,
408 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
409 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
410 evas_object_data_set(it->base, "_elm_leaveme", obj);
411 evas_object_show(it->content);
412 wd->stack = eina_list_append(wd->stack, it);
418 * Pop the object that is on top of the stack
420 * This pops the object that is on top (visible) in the pager, makes it
421 * disappear, then deletes the object. The object that was underneath it
422 * on the stack will become visible.
424 * @param obj The pager object
429 elm_pager_content_pop(Evas_Object *obj)
431 ELM_CHECK_WIDTYPE(obj, widtype);
432 Widget_Data *wd = elm_widget_data_get(obj);
436 if (!wd->stack) return;
437 it = eina_list_last(wd->stack)->data;
438 it->popme = EINA_TRUE;
439 ll = eina_list_last(wd->stack);
450 edje_object_signal_emit(o, "elm,action,pop", "elm");
451 wd->stack = eina_list_remove(wd->stack, it);
452 onhide = edje_object_data_get(o, "onhide");
455 if (!strcmp(onhide, "raise")) evas_object_raise(o);
456 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
463 elm_pager_content_promote(obj, it->content);
471 Evas_Object *obj = data;
472 evas_object_del(obj);
476 * Pop to the object that is on the stack
478 * This pops the objects that are on the stack, makes them
479 * disappear, then deletes the objects. The content will become visible.
481 * @param obj The pager object
482 * @param content The object to show
487 elm_pager_to_content_pop(Evas_Object *obj, Evas_Object *content)
489 ELM_CHECK_WIDTYPE(obj, widtype);
490 Widget_Data *wd = elm_widget_data_get(obj);
494 if (!wd->stack) return;
495 it = eina_list_last(wd->stack)->data;
496 it->popme = EINA_TRUE;
497 ll = eina_list_last(wd->stack);
503 if(it->content != content)
505 wd->stack = eina_list_remove_list(wd->stack, ll);
506 ecore_job_add(_del_job, it->content);
519 * Promote an object already in the pager stack to the top of the stack
521 * This will take the indicated object and promote it to the top of the stack
522 * as if it had been pushed there. The object must already be inside the
523 * pager stack to work.
525 * @param obj The pager object
526 * @param content The object to promote
531 elm_pager_content_promote(Evas_Object *obj, Evas_Object *content)
533 ELM_CHECK_WIDTYPE(obj, widtype);
534 Widget_Data *wd = elm_widget_data_get(obj);
538 l = _item_get(obj, content);
542 wd->stack = eina_list_remove_list(wd->stack, l);
543 wd->stack = eina_list_append(wd->stack, it);
548 * Return the object at the bottom of the pager stack
550 * @param obj The pager object
551 * @return The bottom object or NULL if none
556 elm_pager_content_bottom_get(const Evas_Object *obj)
558 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
559 Widget_Data *wd = elm_widget_data_get(obj);
561 if (!wd) return NULL;
562 if (!wd->stack) return NULL;
563 it = wd->stack->data;
568 * Return the object at the top of the pager stack
570 * @param obj The pager object
571 * @return The top object or NULL if none
576 elm_pager_content_top_get(const Evas_Object *obj)
578 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
579 Widget_Data *wd = elm_widget_data_get(obj);
580 if (!wd) return NULL;
581 if (!wd->top) return NULL;
582 return wd->top->content;
586 * This disables content animation on push/pop.
588 * @param obj The pager object
589 * @param disable if EINA_TRUE animation is disabled.
594 elm_pager_animation_disabled_set(Evas_Object *obj, Eina_Bool disable)
596 ELM_CHECK_WIDTYPE(obj, widtype)NULL;
597 Widget_Data *wd = elm_widget_data_get(obj);
598 wd->disable_animation = disable;