1 #include <Elementary.h>
5 * @defgroup Pager Pager
8 * The pager is an object that allows flipping (with animation) between 1 or
9 * more ?
\9cpages??of objects, much like a stack of windows within the window.
11 * Objects can be pushed or popped from he 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) *
76 _sizing_eval(Evas_Object *obj)
78 Widget_Data *wd = elm_widget_data_get(obj);
79 Evas_Coord minw = -1, minh = -1;
83 EINA_LIST_FOREACH(wd->stack, l, it)
85 if (it->minw > minw) minw = it->minw;
86 if (it->minh > minh) minh = it->minh;
88 evas_object_size_hint_min_set(obj, minw, minh);
89 evas_object_size_hint_max_set(obj, -1, -1);
93 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
96 Evas_Coord minw = -1, minh = -1;
97 evas_object_size_hint_min_get(it->content, &minw, &minh);
98 // FIXME: why is this needed? how does edje get this unswallowed or
99 // lose its callbacks to edje
100 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
101 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
102 _sizing_eval(it->obj);
106 _eval_top(Evas_Object *obj)
108 Widget_Data *wd = elm_widget_data_get(obj);
109 Eina_Bool animate=EINA_TRUE;
112 if (!wd->stack) return;
113 ittop = eina_list_last(wd->stack)->data;
114 if (ittop != wd->top)
117 const char *onshow, *onhide;
122 if(wd->disable_animation)
124 edje_object_signal_emit(o, "elm,action,hide,noanimate", "elm");
126 else if (wd->top->popme)
127 edje_object_signal_emit(o, "elm,action,pop", "elm");
129 edje_object_signal_emit(o, "elm,action,hide", "elm");
130 onhide = edje_object_data_get(o, "onhide");
133 if (!strcmp(onhide, "raise")) evas_object_raise(o);
134 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
139 animate = EINA_FALSE;
141 wd->oldtop = wd->top;
145 if ((!animate)||(wd->disable_animation))
147 edje_object_signal_emit(o, "elm,action,show,noanimate", "elm");
151 if (elm_object_focus_get(wd->oldtop->content))
152 elm_object_focus(wd->top->content);
153 if (wd->oldtop->popme)
154 edje_object_signal_emit(o, "elm,action,show", "elm");
156 edje_object_signal_emit(o, "elm,action,push", "elm");
159 edje_object_signal_emit(o, "elm,action,push", "elm");
160 onshow = edje_object_data_get(o, "onshow");
163 if (!strcmp(onshow, "raise")) evas_object_raise(o);
164 else if (!strcmp(onshow, "lower")) evas_object_lower(o);
170 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
172 Widget_Data *wd = elm_widget_data_get(data);
177 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
178 EINA_LIST_FOREACH(wd->stack, l, it)
179 evas_object_move(it->base, x, y);
183 _sub_del(void *data, Evas_Object *obj __UNUSED__, void *event_info)
185 Widget_Data *wd = elm_widget_data_get(data);
186 Evas_Object *sub = event_info;
190 EINA_LIST_FOREACH(wd->stack, l, it)
192 if (it->content == sub)
194 wd->stack = eina_list_remove_list(wd->stack, l);
195 evas_object_event_callback_del_full
196 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
197 evas_object_del(it->base);
206 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
208 Widget_Data *wd = elm_widget_data_get(data);
213 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
214 EINA_LIST_FOREACH(wd->stack, l, it) evas_object_resize(it->base, w, h);
218 _signal_hide_finished(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
221 Evas_Object *obj2 = it->obj;
222 evas_object_hide(it->base);
223 edje_object_signal_emit(it->base, "elm,action,reset", "elm");
224 evas_object_smart_callback_call(obj2, "hide,finished", it->content);
225 edje_object_message_signal_process(it->base);
226 if (it->popme) evas_object_del(it->content);
227 evas_object_hide(it->content);
232 * Add a new pager to the parent
234 * @param parent The parent object
235 * @return The new object or NULL if it cannot be created
240 elm_pager_add(Evas_Object *parent)
246 wd = ELM_NEW(Widget_Data);
247 e = evas_object_evas_get(parent);
248 obj = elm_widget_add(e);
249 ELM_SET_WIDTYPE(widtype, "pager");
250 elm_widget_type_set(obj, "pager");
251 elm_widget_sub_object_add(parent, obj);
252 elm_widget_data_set(obj, wd);
253 elm_widget_del_hook_set(obj, _del_hook);
254 elm_widget_theme_hook_set(obj, _theme_hook);
255 elm_widget_can_focus_set(obj, EINA_FALSE);
257 wd->clip = evas_object_rectangle_add(e);
258 elm_widget_resize_object_set(obj, wd->clip);
259 elm_widget_sub_object_add(obj, wd->clip);
261 wd->rect = evas_object_rectangle_add(e);
262 elm_widget_sub_object_add(obj, wd->rect);
263 evas_object_color_set(wd->rect, 255, 255, 255, 0);
264 evas_object_clip_set(wd->rect, wd->clip);
266 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, obj);
267 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
269 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
276 * Push an object to the top of the pager stack (and show it)
278 * The object pushed becomes a child of the pager and will be controlled
279 * it and deleted when the pager is deleted.
281 * @param obj The pager object
282 * @param content The object to push
287 elm_pager_content_push(Evas_Object *obj, Evas_Object *content)
289 ELM_CHECK_WIDTYPE(obj, widtype);
290 Widget_Data *wd = elm_widget_data_get(obj);
291 Item *it = ELM_NEW(Item);
292 Evas_Coord x, y, w, h;
296 it->content = content;
297 it->base = edje_object_add(evas_object_evas_get(obj));
298 evas_object_smart_member_add(it->base, obj);
299 evas_object_geometry_get(obj, &x, &y, &w, &h);
300 evas_object_move(it->base, x, y);
301 evas_object_resize(it->base, w, h);
302 evas_object_clip_set(it->base, wd->clip);
303 elm_widget_sub_object_add(obj, it->base);
304 elm_widget_sub_object_add(obj, it->content);
305 _elm_theme_object_set(obj, it->base, "pager", "base", elm_widget_style_get(obj));
306 edje_object_signal_callback_add(it->base, "elm,action,hide,finished", "",
307 _signal_hide_finished, it);
308 evas_object_event_callback_add(it->content,
309 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
310 _changed_size_hints, it);
311 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
312 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
313 evas_object_data_set(it->base, "_elm_leaveme", obj);
314 evas_object_show(it->content);
315 wd->stack = eina_list_append(wd->stack, it);
321 * Pop the object that is on top of the stack
323 * This pops the object that is on top (visible) in the pager, makes it
324 * disappear, then deletes the object. The object that was underneath it
325 * on the stack will become visible.
327 * @param obj The pager object
332 elm_pager_content_pop(Evas_Object *obj)
334 ELM_CHECK_WIDTYPE(obj, widtype);
335 Widget_Data *wd = elm_widget_data_get(obj);
339 if (!wd->stack) return;
340 it = eina_list_last(wd->stack)->data;
341 it->popme = EINA_TRUE;
342 ll = eina_list_last(wd->stack);
353 edje_object_signal_emit(o, "elm,action,pop", "elm");
354 onhide = edje_object_data_get(o, "onhide");
357 if (!strcmp(onhide, "raise")) evas_object_raise(o);
358 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
365 elm_pager_content_promote(obj, it->content);
373 Evas_Object *obj = data;
374 evas_object_del(obj);
378 * Pop to the object that is on the stack
380 * This pops the objects that are on the stack, makes them
381 * disappear, then deletes the objects. The content will become visible.
383 * @param obj The pager object
384 * @param content The object to show
389 elm_pager_to_content_pop(Evas_Object *obj, Evas_Object *content)
391 ELM_CHECK_WIDTYPE(obj, widtype);
392 Widget_Data *wd = elm_widget_data_get(obj);
396 if (!wd->stack) return;
397 it = eina_list_last(wd->stack)->data;
398 it->popme = EINA_TRUE;
399 ll = eina_list_last(wd->stack);
405 if(it->content != content)
407 wd->stack = eina_list_remove_list(wd->stack, ll);
408 ecore_job_add(_del_job, it->content);
420 * Promote an object already in the pager stack to the top of the stack
422 * This will take the indicated object and promote it to the top of the stack
423 * as if it had been pushed there. The object must already be inside the
424 * pager stack to work.
426 * @param obj The pager object
427 * @param content The object to promote
432 elm_pager_content_promote(Evas_Object *obj, Evas_Object *content)
434 ELM_CHECK_WIDTYPE(obj, widtype);
435 Widget_Data *wd = elm_widget_data_get(obj);
439 EINA_LIST_FOREACH(wd->stack, l, it)
441 if (it->content == content)
443 wd->stack = eina_list_remove_list(wd->stack, l);
444 wd->stack = eina_list_append(wd->stack, it);
452 * Return the object at the bottom of the pager stack
454 * @param obj The pager object
455 * @return The bottom object or NULL if none
460 elm_pager_content_bottom_get(const Evas_Object *obj)
462 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
463 Widget_Data *wd = elm_widget_data_get(obj);
465 if (!wd) return NULL;
466 if (!wd->stack) return NULL;
467 it = wd->stack->data;
472 * Return the object at the top of the pager stack
474 * @param obj The pager object
475 * @return The top object or NULL if none
480 elm_pager_content_top_get(const Evas_Object *obj)
482 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
483 Widget_Data *wd = elm_widget_data_get(obj);
484 if (!wd) return NULL;
485 if (!wd->top) return NULL;
486 return wd->top->content;
490 * This disables content animation on push/pop.
492 * @param obj The pager object
493 * @param disable if EINA_TRUE animation is disabled.
498 elm_pager_animation_disable_set(Evas_Object *obj, Eina_Bool disable)
500 ELM_CHECK_WIDTYPE(obj, widtype)NULL;
501 Widget_Data *wd = elm_widget_data_get(obj);
502 wd->disable_animation = disable;