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;
36 Evas_Object *obj, *base, *content;
37 Evas_Coord minw, minh;
41 static const char *widtype = NULL;
42 static void _del_hook(Evas_Object *obj);
43 static void _theme_hook(Evas_Object *obj);
44 static void _sizing_eval(Evas_Object *obj);
45 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
46 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
49 _del_hook(Evas_Object *obj)
51 Widget_Data *wd = elm_widget_data_get(obj);
57 _theme_hook(Evas_Object *obj)
59 Widget_Data *wd = elm_widget_data_get(obj);
63 EINA_LIST_FOREACH(wd->stack, l, it)
64 edje_object_scale_set(it->base, elm_widget_scale_get(obj) *
70 _sizing_eval(Evas_Object *obj)
72 Widget_Data *wd = elm_widget_data_get(obj);
73 Evas_Coord minw = -1, minh = -1;
77 EINA_LIST_FOREACH(wd->stack, l, it)
79 if (it->minw > minw) minw = it->minw;
80 if (it->minh > minh) minh = it->minh;
82 evas_object_size_hint_min_set(obj, minw, minh);
83 evas_object_size_hint_max_set(obj, -1, -1);
87 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
90 Evas_Coord minw = -1, minh = -1;
91 evas_object_size_hint_min_get(it->content, &minw, &minh);
92 // FIXME: why is this needed? how does edje get this unswallowed or
93 // lose its callbacks to edje
94 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
95 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
96 _sizing_eval(it->obj);
100 _eval_top(Evas_Object *obj)
102 Widget_Data *wd = elm_widget_data_get(obj);
103 Eina_Bool animate=EINA_TRUE;
106 if (!wd->stack) return;
107 ittop = eina_list_last(wd->stack)->data;
108 if (ittop != wd->top)
111 const char *onshow, *onhide;
116 edje_object_signal_emit(o, "elm,action,hide", "elm");
117 onhide = edje_object_data_get(o, "onhide");
120 if (!strcmp(onhide, "raise")) evas_object_raise(o);
121 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
126 animate = EINA_FALSE;
132 edje_object_signal_emit(o, "elm,action,show", "elm");
134 edje_object_signal_emit(o, "elm,action,show,noanimate", "elm");
135 onshow = edje_object_data_get(o, "onshow");
138 if (!strcmp(onshow, "raise")) evas_object_raise(o);
139 else if (!strcmp(onshow, "lower")) evas_object_lower(o);
145 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
147 Widget_Data *wd = elm_widget_data_get(data);
152 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
153 EINA_LIST_FOREACH(wd->stack, l, it)
154 evas_object_move(it->base, x, y);
158 _sub_del(void *data, Evas_Object *obj __UNUSED__, void *event_info)
160 Widget_Data *wd = elm_widget_data_get(data);
161 Evas_Object *sub = event_info;
165 EINA_LIST_FOREACH(wd->stack, l, it)
167 if (it->content == sub)
169 wd->stack = eina_list_remove_list(wd->stack, l);
170 evas_object_event_callback_del_full
171 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
172 evas_object_del(it->base);
181 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
183 Widget_Data *wd = elm_widget_data_get(data);
188 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
189 EINA_LIST_FOREACH(wd->stack, l, it) evas_object_resize(it->base, w, h);
193 _signal_hide_finished(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
196 Evas_Object *obj2 = it->obj;
197 evas_object_hide(it->base);
198 edje_object_signal_emit(it->base, "elm,action,reset", "elm");
199 evas_object_smart_callback_call(obj2, "hide,finished", it->content);
200 edje_object_message_signal_process(it->base);
201 if (it->popme) evas_object_del(it->content);
206 * Add a new pager to the parent
208 * @param parent The parent object
209 * @return The new object or NULL if it cannot be created
214 elm_pager_add(Evas_Object *parent)
220 wd = ELM_NEW(Widget_Data);
221 e = evas_object_evas_get(parent);
222 obj = elm_widget_add(e);
223 ELM_SET_WIDTYPE(widtype, "pager");
224 elm_widget_type_set(obj, "pager");
225 elm_widget_sub_object_add(parent, obj);
226 elm_widget_data_set(obj, wd);
227 elm_widget_del_hook_set(obj, _del_hook);
228 elm_widget_theme_hook_set(obj, _theme_hook);
230 wd->clip = evas_object_rectangle_add(e);
231 elm_widget_resize_object_set(obj, wd->clip);
232 elm_widget_sub_object_add(obj, wd->clip);
234 wd->rect = evas_object_rectangle_add(e);
235 elm_widget_sub_object_add(obj, wd->rect);
236 evas_object_color_set(wd->rect, 255, 255, 255, 0);
237 evas_object_clip_set(wd->rect, wd->clip);
239 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, obj);
240 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
242 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
249 * Push an object to the top of the pager stack (and show it)
251 * The object pushed becomes a child of the pager and will be controlled
252 * it and deleted when the pager is deleted.
254 * @param obj The pager object
255 * @param content The object to push
260 elm_pager_content_push(Evas_Object *obj, Evas_Object *content)
262 ELM_CHECK_WIDTYPE(obj, widtype);
263 Widget_Data *wd = elm_widget_data_get(obj);
264 Item *it = ELM_NEW(Item);
265 Evas_Coord x, y, w, h;
269 it->content = content;
270 it->base = edje_object_add(evas_object_evas_get(obj));
271 evas_object_smart_member_add(it->base, obj);
272 evas_object_geometry_get(obj, &x, &y, &w, &h);
273 evas_object_move(it->base, x, y);
274 evas_object_resize(it->base, w, h);
275 evas_object_clip_set(it->base, wd->clip);
276 elm_widget_sub_object_add(obj, it->base);
277 elm_widget_sub_object_add(obj, it->content);
278 _elm_theme_object_set(obj, it->base, "pager", "base", elm_widget_style_get(obj));
279 edje_object_signal_callback_add(it->base, "elm,action,hide,finished", "",
280 _signal_hide_finished, it);
281 evas_object_event_callback_add(it->content,
282 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
283 _changed_size_hints, it);
284 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
285 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
286 evas_object_show(it->content);
287 wd->stack = eina_list_append(wd->stack, it);
293 * Pop the object that is on top of the stack
295 * This pops the object that is on top (visible) in the pager, makes it
296 * disappear, then deletes the object. The object that was underneath it
297 * on the stack will become visible.
299 * @param obj The pager object
304 elm_pager_content_pop(Evas_Object *obj)
306 ELM_CHECK_WIDTYPE(obj, widtype);
307 Widget_Data *wd = elm_widget_data_get(obj);
311 if (!wd->stack) return;
312 it = eina_list_last(wd->stack)->data;
313 it->popme = EINA_TRUE;
314 ll = eina_list_last(wd->stack);
325 edje_object_signal_emit(o, "elm,action,hide", "elm");
326 onhide = edje_object_data_get(o, "onhide");
329 if (!strcmp(onhide, "raise")) evas_object_raise(o);
330 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
337 elm_pager_content_promote(obj, it->content);
343 * Pop to the object that is on the stack
345 * This pops the objects that are on the stack, makes them
346 * disappear, then deletes the objects. The content will become visible.
348 * @param obj The pager object
349 * @param content The object to show
354 elm_pager_to_content_pop(Evas_Object *obj, Evas_Object *content)
356 ELM_CHECK_WIDTYPE(obj, widtype);
357 Widget_Data *wd = elm_widget_data_get(obj);
361 if (!wd->stack) return;
362 it = eina_list_last(wd->stack)->data;
363 it->popme = EINA_TRUE;
364 ll = eina_list_last(wd->stack);
367 EINA_LIST_FOREACH(wd->stack, ll, it)
369 if (it->content == content)
371 ll = eina_list_last(wd->stack);
372 while (ll = ll->prev)
374 if (ll->data == it) break;
377 Item *itdel = ll->data;
378 evas_object_del(itdel->content);
381 elm_pager_content_promote(obj, content);
389 * Promote an object already in the pager stack to the top of the stack
391 * This will take the indicated object and promote it to the top of the stack
392 * as if it had been pushed there. The object must already be inside the
393 * pager stack to work.
395 * @param obj The pager object
396 * @param content The object to promote
401 elm_pager_content_promote(Evas_Object *obj, Evas_Object *content)
403 ELM_CHECK_WIDTYPE(obj, widtype);
404 Widget_Data *wd = elm_widget_data_get(obj);
408 EINA_LIST_FOREACH(wd->stack, l, it)
410 if (it->content == content)
412 wd->stack = eina_list_remove_list(wd->stack, l);
413 wd->stack = eina_list_append(wd->stack, it);
421 * Return the object at the bottom of the pager stack
423 * @param obj The pager object
424 * @return The bottom object or NULL if none
429 elm_pager_content_bottom_get(const Evas_Object *obj)
431 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
432 Widget_Data *wd = elm_widget_data_get(obj);
434 if (!wd) return NULL;
435 if (!wd->stack) return NULL;
436 it = wd->stack->data;
441 * Return the object at the top of the pager stack
443 * @param obj The pager object
444 * @return The top object or NULL if none
449 elm_pager_content_top_get(const Evas_Object *obj)
451 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
452 Widget_Data *wd = elm_widget_data_get(obj);
454 if (!wd) return NULL;
455 if (!wd->stack) return NULL;
456 it = eina_list_last(wd->stack)->data;