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 Eina_Bool ani = EINA_TRUE;
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);
48 static void _signal_hide_finished(void *data, Evas_Object *obj, const char *emission, const char *source);
51 _del_hook(Evas_Object *obj)
53 Widget_Data *wd = elm_widget_data_get(obj);
59 _theme_hook(Evas_Object *obj)
61 Widget_Data *wd = elm_widget_data_get(obj);
65 EINA_LIST_FOREACH(wd->stack, l, it)
66 edje_object_scale_set(it->base, elm_widget_scale_get(obj) *
72 _sizing_eval(Evas_Object *obj)
74 Widget_Data *wd = elm_widget_data_get(obj);
75 Evas_Coord minw = -1, minh = -1;
79 EINA_LIST_FOREACH(wd->stack, l, it)
81 if (it->minw > minw) minw = it->minw;
82 if (it->minh > minh) minh = it->minh;
84 evas_object_size_hint_min_set(obj, minw, minh);
85 evas_object_size_hint_max_set(obj, -1, -1);
89 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
92 Evas_Coord minw = -1, minh = -1;
93 evas_object_size_hint_min_get(it->content, &minw, &minh);
94 // FIXME: why is this needed? how does edje get this unswallowed or
95 // lose its callbacks to edje
96 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
97 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
98 _sizing_eval(it->obj);
102 _complete_cb( void* data )
105 Evas_Object *obj = it->obj;
107 evas_object_hide(it->base);
108 edje_object_signal_emit(it->base, "elm,action,reset", "elm");
109 evas_object_smart_callback_call(obj, "hide,finished", it->content);
110 edje_object_message_signal_process(it->base);
111 if (it->popme) evas_object_del(it->content);
116 _eval_top(Evas_Object *obj)
118 Widget_Data *wd = elm_widget_data_get(obj);
122 if (!wd->stack) return;
123 ittop = eina_list_last(wd->stack)->data;
124 if (ittop != wd->top)
126 Evas_Object *o= NULL, *prev_o = NULL;
127 const char *onshow, *onhide;
128 Eina_Bool pop = EINA_FALSE;
130 Elm_Transit *transit;
132 // transit = elm_transit_add(obj);
133 evas_object_geometry_get( obj, NULL, &y, &w, NULL );
140 if (wd->top->popme) pop = EINA_TRUE;
143 if (pop) evas_object_move( o, w, y );//elm_transit_fx_insert( transit, elm_fx_translation_add(o , 0, y, w, y));
144 else evas_object_move(o, -w, y);//elm_transit_fx_insert( transit, elm_fx_translation_add(o , 0, y, -w, y));
145 //elm_transit_completion_callback_set( transit, _complete_cb, it);
150 _signal_hide_finished(wd->top, o, "elm,action,hide,finished", "");
153 onhide = edje_object_data_get(o, "onhide");
156 if (!strcmp(onhide, "raise")) evas_object_raise(o);
157 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
161 prev_o = wd->top->base;
162 evas_object_show(prev_o);
164 //add show/hide transition direction & animation on/off. 10.04.14 sohyun
167 if (pop) evas_object_move(prev_o, 0, y );//elm_transit_fx_insert( transit, elm_fx_translation_add(prev_o, -w, y, 0, y));
168 else evas_object_move( prev_o, 0, y );//elm_transit_fx_insert( transit, elm_fx_translation_add(prev_o, w, y, 0, y));
169 //elm_transit_run( transit, 0.3 );
171 //elm_transit_del( transit );
173 onshow = edje_object_data_get(prev_o, "onshow");
176 if (!strcmp(onshow, "raise")) evas_object_raise(prev_o);
177 else if (!strcmp(onshow, "lower")) evas_object_lower(prev_o);
183 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
185 Widget_Data *wd = elm_widget_data_get(data);
190 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
191 EINA_LIST_FOREACH(wd->stack, l, it)
192 evas_object_move(it->base, x, y);
196 _sub_del(void *data, Evas_Object *obj __UNUSED__, void *event_info)
198 Widget_Data *wd = elm_widget_data_get(data);
199 Evas_Object *sub = event_info;
203 EINA_LIST_FOREACH(wd->stack, l, it)
205 if (it->content == sub)
207 wd->stack = eina_list_remove_list(wd->stack, l);
208 evas_object_event_callback_del_full
209 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
210 evas_object_del(it->base);
219 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
221 Widget_Data *wd = elm_widget_data_get(data);
226 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
227 EINA_LIST_FOREACH(wd->stack, l, it) evas_object_resize(it->base, w, h);
231 _signal_hide_finished(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
234 Evas_Object *obj2 = it->obj;
235 evas_object_hide(it->base);
236 edje_object_signal_emit(it->base, "elm,action,reset", "elm");
237 evas_object_smart_callback_call(obj2, "hide,finished", it->content);
238 edje_object_message_signal_process(it->base);
239 if (it->popme) evas_object_del(it->content);
244 * Add a new pager to the parent
246 * @param parent The parent object
247 * @return The new object or NULL if it cannot be created
252 elm_pager_add(Evas_Object *parent)
258 wd = ELM_NEW(Widget_Data);
259 e = evas_object_evas_get(parent);
260 obj = elm_widget_add(e);
261 ELM_SET_WIDTYPE(widtype, "pager");
262 elm_widget_type_set(obj, "pager");
263 elm_widget_sub_object_add(parent, obj);
264 elm_widget_data_set(obj, wd);
265 elm_widget_del_hook_set(obj, _del_hook);
266 elm_widget_theme_hook_set(obj, _theme_hook);
268 wd->clip = evas_object_rectangle_add(e);
269 elm_widget_resize_object_set(obj, wd->clip);
270 elm_widget_sub_object_add(obj, wd->clip);
272 wd->rect = evas_object_rectangle_add(e);
273 elm_widget_sub_object_add(obj, wd->rect);
274 evas_object_color_set(wd->rect, 255, 255, 255, 0);
275 evas_object_clip_set(wd->rect, wd->clip);
277 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, obj);
278 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
280 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
287 * Push an object to the top of the pager stack (and show it)
289 * The object pushed becomes a child of the pager and will be controlled
290 * it and deleted when the pager is deleted.
292 * @param obj The pager object
293 * @param content The object to push
298 elm_pager_content_push(Evas_Object *obj, Evas_Object *content)
300 ELM_CHECK_WIDTYPE(obj, widtype);
301 Widget_Data *wd = elm_widget_data_get(obj);
302 Item *it = ELM_NEW(Item);
303 Evas_Coord x, y, w, h;
307 it->content = content;
308 it->base = edje_object_add(evas_object_evas_get(obj));
309 evas_object_smart_member_add(it->base, obj);
310 evas_object_geometry_get(obj, &x, &y, &w, &h);
311 evas_object_move(it->base, x, y);
312 evas_object_resize(it->base, w, h);
313 evas_object_clip_set(it->base, wd->clip);
314 elm_widget_sub_object_add(obj, it->base);
315 if (it->content) elm_widget_sub_object_add(obj, it->content);
316 _elm_theme_object_set(obj, it->base, "pager", "base", elm_widget_style_get(obj));
317 edje_object_signal_callback_add(it->base, "elm,action,hide,finished", "",
318 _signal_hide_finished, it);
319 evas_object_event_callback_add(it->content,
320 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
321 _changed_size_hints, it);
322 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
323 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
324 evas_object_show(it->content);
325 wd->stack = eina_list_append(wd->stack, it);
331 * Pop the object that is on top of the stack
333 * This pops the object that is on top (visible) in the pager, makes it
334 * disappear, then deletes the object. The object that was underneath it
335 * on the stack will become visible.
337 * @param obj The pager object
342 elm_pager_content_pop(Evas_Object *obj)
344 ELM_CHECK_WIDTYPE(obj, widtype);
345 Widget_Data *wd = elm_widget_data_get(obj);
349 if (!wd->stack) return;
350 it = eina_list_last(wd->stack)->data;
351 it->popme = EINA_TRUE;
352 ll = eina_list_last(wd->stack);
368 transit = elm_transit_add(obj);
369 evas_object_geometry_get(obj, NULL, &y, &w, NULL);
370 elm_transit_fx_insert(transit, elm_fx_translation_add(o , 0, y, w, y));
371 elm_transit_completion_callback_set(transit, _complete_cb, it);
372 elm_transit_run(transit, 0.3 );
373 elm_transit_del(transit); */
374 evas_object_move( o, w, y );
379 else _signal_hide_finished(wd->top, o, "elm,action,hide,finished", "");
381 onhide = edje_object_data_get(o, "onhide");
384 if (!strcmp(onhide, "raise")) evas_object_raise(o);
385 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
392 elm_pager_content_promote(obj, it->content);
398 * Pop to the object that is on the stack
400 * This pops the objects that are on the stack, makes them
401 * disappear, then deletes the objects. The content will become visible.
403 * @param obj The pager object
404 * @param content The object to show
409 elm_pager_to_content_pop(Evas_Object *obj, Evas_Object *content)
411 ELM_CHECK_WIDTYPE(obj, widtype);
412 Widget_Data *wd = elm_widget_data_get(obj);
416 if (!wd->stack) return;
417 it = eina_list_last(wd->stack)->data;
418 it->popme = EINA_TRUE;
419 ll = eina_list_last(wd->stack);
422 EINA_LIST_FOREACH(wd->stack, ll, it)
424 if (it->content == content)
426 ll = eina_list_last(wd->stack);
427 while (ll = ll->prev)
429 if (ll->data == it) break;
432 Item *itdel = ll->data;
433 evas_object_del(itdel->content);
436 elm_pager_content_promote(obj, content);
444 * Promote an object already in the pager stack to the top of the stack
446 * This will take the indicated object and promote it to the top of the stack
447 * as if it had been pushed there. The object must already be inside the
448 * pager stack to work.
450 * @param obj The pager object
451 * @param content The object to promote
456 elm_pager_content_promote(Evas_Object *obj, Evas_Object *content)
458 ELM_CHECK_WIDTYPE(obj, widtype);
459 Widget_Data *wd = elm_widget_data_get(obj);
463 EINA_LIST_FOREACH(wd->stack, l, it)
465 if (it->content == content)
467 wd->stack = eina_list_remove_list(wd->stack, l);
468 wd->stack = eina_list_append(wd->stack, it);
476 * Return the object at the bottom of the pager stack
478 * @param obj The pager object
479 * @return The bottom object or NULL if none
484 elm_pager_content_bottom_get(const Evas_Object *obj)
486 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
487 Widget_Data *wd = elm_widget_data_get(obj);
489 if (!wd) return NULL;
490 if (!wd->stack) return NULL;
491 it = wd->stack->data;
496 * Return the object at the top of the pager stack
498 * @param obj The pager object
499 * @return The top object or NULL if none
504 elm_pager_content_top_get(const Evas_Object *obj)
506 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
507 Widget_Data *wd = elm_widget_data_get(obj);
509 if (!wd) return NULL;
510 if (!wd->stack) return NULL;
511 it = eina_list_last(wd->stack)->data;
516 * set animation on/off for content transition effect
518 * @param obj The pager object
519 * @param animation transition when contents are changed (default value : TRUE)
524 elm_pager_animation_set(Evas_Object *obj, Eina_Bool animation)