1 #include <Elementary.h>
5 * @defgroup Pager Pager
8 * The pager is an object that allows flipping (with animation) between 1 or
9 * more “pages” of objects, much like a stack of windows within the window.
11 * Objects can be pushed or popped from the stack or deleted as normal.
12 * Pushes and pops will animate (and a pop will delete the object once the
13 * animation is finished). Any object in the pager can be promoted to the top
14 * (from its current stacking position) as well. Objects are pushed to the
15 * top with elm_pager_content_push() and when the top item is no longer
16 * wanted, simply pop it with elm_pager_content_pop() and it will also be
17 * deleted. Any object you wish to promote to the top that is already in the
18 * pager, simply use elm_pager_content_promote(). If an object is no longer
19 * needed and is not the top item, just delete it as normal. You can query
20 * which objects are the top and bottom with elm_pager_content_bottom_get()
21 * and elm_pager_content_top_get().
24 typedef struct _Widget_Data Widget_Data;
25 typedef struct _Item Item;
31 Evas_Object *rect, *clip;
32 Eina_Bool disable_animation: 1;
37 Evas_Object *obj, *base, *content;
38 Evas_Coord minw, minh;
42 static const char *widtype = NULL;
43 static void _del_hook(Evas_Object *obj);
44 static void _theme_hook(Evas_Object *obj);
45 static void _sizing_eval(Evas_Object *obj);
46 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
47 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
50 _del_hook(Evas_Object *obj)
52 Widget_Data *wd = elm_widget_data_get(obj);
58 _theme_hook(Evas_Object *obj)
60 Widget_Data *wd = elm_widget_data_get(obj);
64 EINA_LIST_FOREACH(wd->stack, l, it)
66 _elm_theme_object_set(obj, it->base, "pager", "base",
67 elm_widget_style_get(obj));
68 edje_object_scale_set(it->base, elm_widget_scale_get(obj) *
75 _elm_pager_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
77 Widget_Data *wd = elm_widget_data_get(obj);
80 if ((!wd) || (!wd->top))
83 cur = wd->top->content;
85 /* Try Focus cycle in subitem */
86 return elm_widget_focus_next_get(cur, dir, next);
90 _sizing_eval(Evas_Object *obj)
92 Widget_Data *wd = elm_widget_data_get(obj);
93 Evas_Coord minw = -1, minh = -1;
97 EINA_LIST_FOREACH(wd->stack, l, it)
99 if (it->minw > minw) minw = it->minw;
100 if (it->minh > minh) minh = it->minh;
102 evas_object_size_hint_min_set(obj, minw, minh);
103 evas_object_size_hint_max_set(obj, -1, -1);
107 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
110 Evas_Coord minw = -1, minh = -1;
111 evas_object_size_hint_min_get(it->content, &minw, &minh);
112 // FIXME: why is this needed? how does edje get this unswallowed or
113 // lose its callbacks to edje
114 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
115 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
116 _sizing_eval(it->obj);
120 _eval_top(Evas_Object *obj)
122 Widget_Data *wd = elm_widget_data_get(obj);
123 Eina_Bool animate=EINA_TRUE;
126 if (!wd->stack) return;
127 ittop = eina_list_last(wd->stack)->data;
128 if (ittop != wd->top)
131 const char *onshow, *onhide;
136 if(wd->disable_animation)
138 edje_object_signal_emit(o, "elm,action,hide,noanimate", "elm");
140 else if (wd->top->popme)
141 edje_object_signal_emit(o, "elm,action,pop", "elm");
143 edje_object_signal_emit(o, "elm,action,hide", "elm");
144 onhide = edje_object_data_get(o, "onhide");
147 if (!strcmp(onhide, "raise")) evas_object_raise(o);
148 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
153 animate = EINA_FALSE;
155 wd->oldtop = wd->top;
159 if ((!animate)||(wd->disable_animation))
161 edje_object_signal_emit(o, "elm,action,show,noanimate", "elm");
165 if (elm_object_focus_get(wd->oldtop->content))
166 elm_object_focus(wd->top->content);
167 if (wd->oldtop->popme)
168 edje_object_signal_emit(o, "elm,action,show", "elm");
170 edje_object_signal_emit(o, "elm,action,push", "elm");
173 edje_object_signal_emit(o, "elm,action,push", "elm");
174 onshow = edje_object_data_get(o, "onshow");
177 if (!strcmp(onshow, "raise")) evas_object_raise(o);
178 else if (!strcmp(onshow, "lower")) evas_object_lower(o);
184 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
186 Widget_Data *wd = elm_widget_data_get(data);
191 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
192 EINA_LIST_FOREACH(wd->stack, l, it)
193 evas_object_move(it->base, x, y);
197 _sub_del(void *data, Evas_Object *obj __UNUSED__, void *event_info)
199 Widget_Data *wd = elm_widget_data_get(data);
200 Evas_Object *sub = event_info;
204 EINA_LIST_FOREACH(wd->stack, l, it)
206 if (it->content == sub)
208 wd->stack = eina_list_remove_list(wd->stack, l);
209 evas_object_event_callback_del_full
210 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
211 evas_object_del(it->base);
220 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
222 Widget_Data *wd = elm_widget_data_get(data);
227 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
228 EINA_LIST_FOREACH(wd->stack, l, it) evas_object_resize(it->base, w, h);
232 _signal_hide_finished(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
235 Evas_Object *obj2 = it->obj;
236 evas_object_hide(it->base);
237 edje_object_signal_emit(it->base, "elm,action,reset", "elm");
238 evas_object_smart_callback_call(obj2, "hide,finished", it->content);
239 edje_object_message_signal_process(it->base);
240 if (it->popme) evas_object_del(it->content);
241 evas_object_hide(it->content);
246 * Add a new pager to the parent
248 * @param parent The parent object
249 * @return The new object or NULL if it cannot be created
254 elm_pager_add(Evas_Object *parent)
260 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
262 wd = ELM_NEW(Widget_Data);
263 e = evas_object_evas_get(parent);
265 obj = elm_widget_add(e);
266 ELM_SET_WIDTYPE(widtype, "pager");
267 elm_widget_type_set(obj, "pager");
268 elm_widget_sub_object_add(parent, obj);
269 elm_widget_data_set(obj, wd);
270 elm_widget_del_hook_set(obj, _del_hook);
271 elm_widget_theme_hook_set(obj, _theme_hook);
272 elm_widget_focus_next_hook_set(obj, _elm_pager_focus_next_hook);
273 elm_widget_can_focus_set(obj, EINA_FALSE);
275 wd->clip = evas_object_rectangle_add(e);
276 elm_widget_resize_object_set(obj, wd->clip);
277 elm_widget_sub_object_add(obj, wd->clip);
279 wd->rect = evas_object_rectangle_add(e);
280 elm_widget_sub_object_add(obj, wd->rect);
281 evas_object_color_set(wd->rect, 255, 255, 255, 0);
282 evas_object_clip_set(wd->rect, wd->clip);
284 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, obj);
285 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
287 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
294 * Push an object to the top of the pager stack (and show it)
296 * The object pushed becomes a child of the pager and will be controlled
297 * it and deleted when the pager is deleted.
299 * @param obj The pager object
300 * @param content The object to push
305 elm_pager_content_push(Evas_Object *obj, Evas_Object *content)
307 ELM_CHECK_WIDTYPE(obj, widtype);
308 Widget_Data *wd = elm_widget_data_get(obj);
309 Item *it = ELM_NEW(Item);
310 Evas_Coord x, y, w, h;
314 it->content = content;
315 it->base = edje_object_add(evas_object_evas_get(obj));
316 evas_object_smart_member_add(it->base, obj);
317 evas_object_geometry_get(obj, &x, &y, &w, &h);
318 evas_object_move(it->base, x, y);
319 evas_object_resize(it->base, w, h);
320 evas_object_clip_set(it->base, wd->clip);
321 elm_widget_sub_object_add(obj, it->base);
322 elm_widget_sub_object_add(obj, it->content);
323 _elm_theme_object_set(obj, it->base, "pager", "base", elm_widget_style_get(obj));
324 edje_object_signal_callback_add(it->base, "elm,action,hide,finished", "",
325 _signal_hide_finished, it);
326 evas_object_event_callback_add(it->content,
327 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
328 _changed_size_hints, it);
329 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
330 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
331 evas_object_data_set(it->base, "_elm_leaveme", obj);
332 evas_object_show(it->content);
333 wd->stack = eina_list_append(wd->stack, it);
339 * Pop the object that is on top of the stack
341 * This pops the object that is on top (visible) in the pager, makes it
342 * disappear, then deletes the object. The object that was underneath it
343 * on the stack will become visible.
345 * @param obj The pager object
350 elm_pager_content_pop(Evas_Object *obj)
352 ELM_CHECK_WIDTYPE(obj, widtype);
353 Widget_Data *wd = elm_widget_data_get(obj);
357 if (!wd->stack) return;
358 it = eina_list_last(wd->stack)->data;
359 it->popme = EINA_TRUE;
360 ll = eina_list_last(wd->stack);
371 edje_object_signal_emit(o, "elm,action,pop", "elm");
372 onhide = edje_object_data_get(o, "onhide");
375 if (!strcmp(onhide, "raise")) evas_object_raise(o);
376 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
383 elm_pager_content_promote(obj, it->content);
391 Evas_Object *obj = data;
392 evas_object_del(obj);
396 * Pop to the object that is on the stack
398 * This pops the objects that are on the stack, makes them
399 * disappear, then deletes the objects. The content will become visible.
401 * @param obj The pager object
402 * @param content The object to show
407 elm_pager_to_content_pop(Evas_Object *obj, Evas_Object *content)
409 ELM_CHECK_WIDTYPE(obj, widtype);
410 Widget_Data *wd = elm_widget_data_get(obj);
414 if (!wd->stack) return;
415 it = eina_list_last(wd->stack)->data;
416 it->popme = EINA_TRUE;
417 ll = eina_list_last(wd->stack);
423 if(it->content != content)
425 wd->stack = eina_list_remove_list(wd->stack, ll);
426 ecore_job_add(_del_job, it->content);
438 * Promote an object already in the pager stack to the top of the stack
440 * This will take the indicated object and promote it to the top of the stack
441 * as if it had been pushed there. The object must already be inside the
442 * pager stack to work.
444 * @param obj The pager object
445 * @param content The object to promote
450 elm_pager_content_promote(Evas_Object *obj, Evas_Object *content)
452 ELM_CHECK_WIDTYPE(obj, widtype);
453 Widget_Data *wd = elm_widget_data_get(obj);
457 EINA_LIST_FOREACH(wd->stack, l, it)
459 if (it->content == content)
461 wd->stack = eina_list_remove_list(wd->stack, l);
462 wd->stack = eina_list_append(wd->stack, it);
470 * Return the object at the bottom of the pager stack
472 * @param obj The pager object
473 * @return The bottom object or NULL if none
478 elm_pager_content_bottom_get(const Evas_Object *obj)
480 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
481 Widget_Data *wd = elm_widget_data_get(obj);
483 if (!wd) return NULL;
484 if (!wd->stack) return NULL;
485 it = wd->stack->data;
490 * Return the object at the top of the pager stack
492 * @param obj The pager object
493 * @return The top object or NULL if none
498 elm_pager_content_top_get(const Evas_Object *obj)
500 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
501 Widget_Data *wd = elm_widget_data_get(obj);
502 if (!wd) return NULL;
503 if (!wd->top) return NULL;
504 return wd->top->content;
508 * This disables content animation on push/pop.
510 * @param obj The pager object
511 * @param disable if EINA_TRUE animation is disabled.
516 elm_pager_animation_disabled_set(Evas_Object *obj, Eina_Bool disable)
518 ELM_CHECK_WIDTYPE(obj, widtype)NULL;
519 Widget_Data *wd = elm_widget_data_get(obj);
520 wd->disable_animation = disable;