1 #include <Elementary.h>
5 * @defgroup Pager Pager
7 * The pager is an object that allows flipping (with animation) between 1 or
8 * more ?
\9cpages??of objects, much like a stack of windows within the window.
10 * Objects can be pushed or popped from he 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().
23 typedef struct _Widget_Data Widget_Data;
24 typedef struct _Item Item;
30 Evas_Object *rect, *clip;
35 Evas_Object *obj, *base, *content;
36 Evas_Coord minw, minh;
40 static Eina_Bool ani = EINA_TRUE;
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);
47 static void _signal_hide_finished(void *data, Evas_Object *obj, const char *emission, const char *source);
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)
65 edje_object_scale_set(it->base, elm_widget_scale_get(obj) *
71 _sizing_eval(Evas_Object *obj)
73 Widget_Data *wd = elm_widget_data_get(obj);
74 Evas_Coord minw = -1, minh = -1;
78 EINA_LIST_FOREACH(wd->stack, l, it)
80 if (it->minw > minw) minw = it->minw;
81 if (it->minh > minh) minh = it->minh;
83 evas_object_size_hint_min_set(obj, minw, minh);
84 evas_object_size_hint_max_set(obj, -1, -1);
88 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
91 Evas_Coord minw = -1, minh = -1;
92 evas_object_size_hint_min_get(it->content, &minw, &minh);
93 // FIXME: why is this needed? how does edje get this unswallowed or
94 // lose its callbacks to edje
95 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
96 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
97 _sizing_eval(it->obj);
101 _complete_cb( void* data )
104 Evas_Object *obj = it->obj;
106 evas_object_hide(it->base);
107 edje_object_signal_emit(it->base, "elm,action,reset", "elm");
108 evas_object_smart_callback_call(obj, "hide,finished", it->content);
109 edje_object_message_signal_process(it->base);
110 if (it->popme) evas_object_del(it->content);
115 _eval_top(Evas_Object *obj)
117 Widget_Data *wd = elm_widget_data_get(obj);
121 if (!wd->stack) return;
122 ittop = eina_list_last(wd->stack)->data;
123 if (ittop != wd->top)
125 Evas_Object *o= NULL, *prev_o = NULL;
126 const char *onshow, *onhide;
127 Eina_Bool pop = EINA_FALSE;
129 Elm_Transit *transit;
131 transit = elm_transit_add(obj);
132 evas_object_geometry_get( obj, NULL, &y, &w, NULL );
139 if (wd->top->popme) pop = EINA_TRUE;
142 if (pop) elm_transit_fx_insert( transit, elm_fx_transfer_add(o , 0, y, w, y));
143 else elm_transit_fx_insert( transit, elm_fx_transfer_add(o , 0, y, -w, y));
144 elm_transit_completion_set( transit, _complete_cb, it);
148 _signal_hide_finished(wd->top, o, "elm,action,hide,finished", "");
151 onhide = edje_object_data_get(o, "onhide");
154 if (!strcmp(onhide, "raise")) evas_object_raise(o);
155 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
159 prev_o = wd->top->base;
160 evas_object_show(prev_o);
162 //add show/hide transition direction & animation on/off. 10.04.14 sohyun
165 if (pop) elm_transit_fx_insert( transit, elm_fx_transfer_add(prev_o, -w, y, 0, y));
166 else elm_transit_fx_insert( transit, elm_fx_transfer_add(prev_o, w, y, 0, y));
167 elm_transit_run( transit, 0.3 );
169 elm_transit_del( transit );
171 onshow = edje_object_data_get(prev_o, "onshow");
174 if (!strcmp(onshow, "raise")) evas_object_raise(prev_o);
175 else if (!strcmp(onshow, "lower")) evas_object_lower(prev_o);
181 _move(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, &x, &y, NULL, NULL);
189 EINA_LIST_FOREACH(wd->stack, l, it)
190 evas_object_move(it->base, x, y);
194 _sub_del(void *data, Evas_Object *obj __UNUSED__, void *event_info)
196 Widget_Data *wd = elm_widget_data_get(data);
197 Evas_Object *sub = event_info;
201 EINA_LIST_FOREACH(wd->stack, l, it)
203 if (it->content == sub)
205 wd->stack = eina_list_remove_list(wd->stack, l);
206 evas_object_event_callback_del_full
207 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
208 evas_object_del(it->base);
217 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
219 Widget_Data *wd = elm_widget_data_get(data);
224 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
225 EINA_LIST_FOREACH(wd->stack, l, it) evas_object_resize(it->base, w, h);
229 _signal_hide_finished(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
232 Evas_Object *obj2 = it->obj;
233 evas_object_hide(it->base);
234 edje_object_signal_emit(it->base, "elm,action,reset", "elm");
235 evas_object_smart_callback_call(obj2, "hide,finished", it->content);
236 edje_object_message_signal_process(it->base);
237 if (it->popme) evas_object_del(it->content);
242 * Add a new pager to the parent
244 * @param parent The parent object
245 * @return The new object or NULL if it cannot be created
250 elm_pager_add(Evas_Object *parent)
256 wd = ELM_NEW(Widget_Data);
257 e = evas_object_evas_get(parent);
258 obj = elm_widget_add(e);
259 ELM_SET_WIDTYPE(widtype, "pager");
260 elm_widget_type_set(obj, "pager");
261 elm_widget_sub_object_add(parent, obj);
262 elm_widget_data_set(obj, wd);
263 elm_widget_del_hook_set(obj, _del_hook);
264 elm_widget_theme_hook_set(obj, _theme_hook);
266 wd->clip = evas_object_rectangle_add(e);
267 elm_widget_resize_object_set(obj, wd->clip);
268 elm_widget_sub_object_add(obj, wd->clip);
270 wd->rect = evas_object_rectangle_add(e);
271 elm_widget_sub_object_add(obj, wd->rect);
272 evas_object_color_set(wd->rect, 255, 255, 255, 0);
273 evas_object_clip_set(wd->rect, wd->clip);
275 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, obj);
276 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
278 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
285 * Push an object to the top of the pager stack (and show it)
287 * The object pushed becomes a child of the pager and will be controlled
288 * it and deleted when the pager is deleted.
290 * @param obj The pager object
291 * @param content The object to push
296 elm_pager_content_push(Evas_Object *obj, Evas_Object *content)
298 ELM_CHECK_WIDTYPE(obj, widtype);
299 Widget_Data *wd = elm_widget_data_get(obj);
300 Item *it = ELM_NEW(Item);
301 Evas_Coord x, y, w, h;
305 it->content = content;
306 it->base = edje_object_add(evas_object_evas_get(obj));
307 evas_object_smart_member_add(it->base, obj);
308 evas_object_geometry_get(obj, &x, &y, &w, &h);
309 evas_object_move(it->base, x, y);
310 evas_object_resize(it->base, w, h);
311 evas_object_clip_set(it->base, wd->clip);
312 elm_widget_sub_object_add(obj, it->base);
313 if (it->content) elm_widget_sub_object_add(obj, it->content);
314 _elm_theme_object_set(obj, it->base, "pager", "base", elm_widget_style_get(obj));
315 edje_object_signal_callback_add(it->base, "elm,action,hide,finished", "",
316 _signal_hide_finished, it);
317 evas_object_event_callback_add(it->content,
318 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
319 _changed_size_hints, it);
320 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
321 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
322 evas_object_show(it->content);
323 wd->stack = eina_list_append(wd->stack, it);
329 * Pop the object that is on top of the stack
331 * This pops the object that is on top (visible) in the pager, makes it
332 * disappear, then deletes the object. The object that was underneath it
333 * on the stack will become visible.
335 * @param obj The pager object
340 elm_pager_content_pop(Evas_Object *obj)
342 ELM_CHECK_WIDTYPE(obj, widtype);
343 Widget_Data *wd = elm_widget_data_get(obj);
347 if (!wd->stack) return;
348 it = eina_list_last(wd->stack)->data;
349 it->popme = EINA_TRUE;
350 ll = eina_list_last(wd->stack);
366 transit = elm_transit_add(obj);
367 evas_object_geometry_get(obj, NULL, &y, &w, NULL);
368 elm_transit_fx_insert(transit, elm_fx_transfer_add(o , 0, y, w, y));
369 elm_transit_completion_set(transit, _complete_cb, it);
370 elm_transit_run(transit, 0.3 );
371 elm_transit_del(transit);
373 else _signal_hide_finished(wd->top, o, "elm,action,hide,finished", "");
375 onhide = edje_object_data_get(o, "onhide");
378 if (!strcmp(onhide, "raise")) evas_object_raise(o);
379 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
386 elm_pager_content_promote(obj, it->content);
392 * Promote an object already in the pager stack to the top of the stack
394 * This will take the indicated object and promote it to the top of the stack
395 * as if it had been pushed there. The object must already be inside the
396 * pager stack to work.
398 * @param obj The pager object
399 * @param content The object to promote
404 elm_pager_content_promote(Evas_Object *obj, Evas_Object *content)
406 ELM_CHECK_WIDTYPE(obj, widtype);
407 Widget_Data *wd = elm_widget_data_get(obj);
411 EINA_LIST_FOREACH(wd->stack, l, it)
413 if (it->content == content)
415 wd->stack = eina_list_remove_list(wd->stack, l);
416 wd->stack = eina_list_append(wd->stack, it);
424 * Return the object at the bottom of the pager stack
426 * @param obj The pager object
427 * @return The bottom object or NULL if none
432 elm_pager_content_bottom_get(const Evas_Object *obj)
434 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
435 Widget_Data *wd = elm_widget_data_get(obj);
437 if (!wd) return NULL;
438 if (!wd->stack) return NULL;
439 it = wd->stack->data;
444 * Return the object at the top of the pager stack
446 * @param obj The pager object
447 * @return The top object or NULL if none
452 elm_pager_content_top_get(const Evas_Object *obj)
454 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
455 Widget_Data *wd = elm_widget_data_get(obj);
457 if (!wd) return NULL;
458 if (!wd->stack) return NULL;
459 it = eina_list_last(wd->stack)->data;
464 * set animation on/off for content transition effect
466 * @param obj The pager object
467 * @param animation transition when contents are changed (default value : TRUE)
472 elm_pager_animation_set(Evas_Object *obj, Eina_Bool animation)