1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Item Item;
11 Evas_Object *rect, *clip;
16 Evas_Object *obj, *base, *content;
17 Evas_Coord minw, minh;
21 static const char *widtype = NULL;
22 static void _del_hook(Evas_Object *obj);
23 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
24 static void _theme_hook(Evas_Object *obj);
25 static void _sizing_eval(Evas_Object *obj);
26 static void _changed_size_hints(void *data,
30 static void _content_del(void *data,
34 static Eina_List *_item_get(Evas_Object *obj, Evas_Object *content);
36 static const char SIG_HIDE_FINISHED[] = "hide,finished";
37 static const char SIG_SHOW_FINISHED[] = "show,finished";
39 static const Evas_Smart_Cb_Description _signals[] = {
40 {SIG_HIDE_FINISHED, ""},
41 {SIG_SHOW_FINISHED, ""},
46 _del_hook(Evas_Object *obj)
48 Widget_Data *wd = elm_widget_data_get(obj);
54 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
56 Widget_Data *wd = elm_widget_data_get(obj);
60 EINA_LIST_FOREACH(wd->stack, l, it)
61 edje_object_mirrored_set(it->base, rtl);
65 _theme_hook(Evas_Object *obj)
67 Widget_Data *wd = elm_widget_data_get(obj);
71 _elm_widget_mirrored_reload(obj);
72 _mirrored_set(obj, elm_widget_mirrored_get(obj));
73 EINA_LIST_FOREACH(wd->stack, l, it)
75 _elm_theme_object_set(obj, it->base, "pager", "base",
76 elm_widget_style_get(obj));
77 edje_object_scale_set(it->base, elm_widget_scale_get(obj) *
84 _item_get(Evas_Object *obj, Evas_Object *content)
86 Widget_Data *wd = elm_widget_data_get(obj);
91 EINA_LIST_FOREACH(wd->stack, l, it)
93 if (it->content == content)
101 _elm_pager_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
103 Widget_Data *wd = elm_widget_data_get(obj);
106 if ((!wd) || (!wd->top))
109 cur = wd->top->content;
111 /* Try Focus cycle in subitem */
112 return elm_widget_focus_next_get(cur, dir, next);
116 _sizing_eval(Evas_Object *obj)
118 Widget_Data *wd = elm_widget_data_get(obj);
119 Evas_Coord minw = -1, minh = -1;
123 EINA_LIST_FOREACH(wd->stack, l, it)
125 if (it->minw > minw) minw = it->minw;
126 if (it->minh > minh) minh = it->minh;
128 evas_object_size_hint_min_set(obj, minw, minh);
129 evas_object_size_hint_max_set(obj, -1, -1);
133 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
136 Evas_Coord minw = -1, minh = -1;
137 evas_object_size_hint_min_get(it->content, &minw, &minh);
138 // FIXME: why is this needed? how does edje get this unswallowed or
139 // lose its callbacks to edje
140 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
141 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
142 _sizing_eval(it->obj);
146 _eval_top(Evas_Object *obj)
148 Widget_Data *wd = elm_widget_data_get(obj);
151 if (!wd->stack) return;
152 ittop = eina_list_last(wd->stack)->data;
153 if (ittop != wd->top)
156 const char *onshow, *onhide;
163 edje_object_signal_emit(o, "elm,action,pop", "elm");
164 wd->stack = eina_list_remove(wd->stack, wd->top);
167 edje_object_signal_emit(o, "elm,action,hide", "elm");
168 onhide = edje_object_data_get(o, "onhide");
171 if (!strcmp(onhide, "raise")) evas_object_raise(o);
172 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
175 wd->oldtop = wd->top;
181 if (elm_object_focus_get(wd->oldtop->content))
182 elm_widget_focused_object_clear(wd->oldtop->content);
183 if (wd->oldtop->popme)
184 edje_object_signal_emit(o, "elm,action,show", "elm");
186 edje_object_signal_emit(o, "elm,action,push", "elm");
189 edje_object_signal_emit(o, "elm,action,push", "elm");
190 onshow = edje_object_data_get(o, "onshow");
193 if (!strcmp(onshow, "raise")) evas_object_raise(o);
194 else if (!strcmp(onshow, "lower")) evas_object_lower(o);
200 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
202 Widget_Data *wd = elm_widget_data_get(data);
207 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
208 EINA_LIST_FOREACH(wd->stack, l, it)
209 evas_object_move(it->base, x, y);
213 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
215 Widget_Data *wd = elm_widget_data_get(data);
219 l = _item_get(data, obj);
222 wd->stack = eina_list_remove_list(wd->stack, l);
223 evas_object_event_callback_del_full
224 (obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, it);
225 evas_object_del(it->base);
231 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
233 Widget_Data *wd = elm_widget_data_get(data);
238 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
239 EINA_LIST_FOREACH(wd->stack, l, it) evas_object_resize(it->base, w, h);
243 _show_finished_cb(void *data, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
246 Evas_Object *obj = it->obj;
247 Evas_Object *content = it->content;
249 evas_object_smart_callback_call(obj, SIG_SHOW_FINISHED, content);
253 _hide_finished_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
256 Evas_Object *obj2 = it->obj;
257 Evas_Object *content = it->content;
261 evas_object_del(it->base);
262 evas_object_event_callback_del_full(content,
263 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
266 evas_object_event_callback_del(content,
269 evas_object_del(content);
274 evas_object_hide(it->base);
275 edje_object_signal_emit(it->base, "elm,action,reset", "elm");
276 edje_object_message_signal_process(it->base);
277 evas_object_hide(content);
279 evas_object_smart_callback_call(obj2, SIG_HIDE_FINISHED, content);
284 elm_pager_add(Evas_Object *parent)
290 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
292 ELM_SET_WIDTYPE(widtype, "pager");
293 elm_widget_type_set(obj, "pager");
294 elm_widget_sub_object_add(parent, obj);
295 elm_widget_data_set(obj, wd);
296 elm_widget_del_hook_set(obj, _del_hook);
297 elm_widget_theme_hook_set(obj, _theme_hook);
298 elm_widget_focus_next_hook_set(obj, _elm_pager_focus_next_hook);
299 elm_widget_can_focus_set(obj, EINA_FALSE);
301 wd->clip = evas_object_rectangle_add(e);
302 elm_widget_resize_object_set(obj, wd->clip);
303 elm_widget_sub_object_add(obj, wd->clip);
305 wd->rect = evas_object_rectangle_add(e);
306 elm_widget_sub_object_add(obj, wd->rect);
307 evas_object_color_set(wd->rect, 255, 255, 255, 0);
308 evas_object_clip_set(wd->rect, wd->clip);
310 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, obj);
311 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
313 evas_object_smart_callbacks_descriptions_set(obj, _signals);
315 _mirrored_set(obj, elm_widget_mirrored_get(obj));
321 elm_pager_content_push(Evas_Object *obj, Evas_Object *content)
323 ELM_CHECK_WIDTYPE(obj, widtype);
324 Widget_Data *wd = elm_widget_data_get(obj);
325 Evas_Coord x, y, w, h;
328 if ((!wd) || (!content)) return;
329 if (_item_get(obj, content)) return;
334 it->content = content;
335 it->base = edje_object_add(evas_object_evas_get(obj));
336 evas_object_smart_member_add(it->base, obj);
337 evas_object_geometry_get(obj, &x, &y, &w, &h);
338 evas_object_move(it->base, x, y);
339 evas_object_resize(it->base, w, h);
340 evas_object_clip_set(it->base, wd->clip);
341 elm_widget_sub_object_add(obj, it->base);
342 elm_widget_sub_object_add(obj, it->content);
343 _elm_theme_object_set(obj,
347 elm_widget_style_get(obj));
348 edje_object_signal_callback_add
349 (it->base, "elm,action,show,finished", "", _show_finished_cb, it);
350 edje_object_signal_callback_add(it->base,
351 "elm,action,hide,finished",
355 evas_object_event_callback_add(it->content,
356 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
359 evas_object_event_callback_add(it->content,
363 edje_object_part_swallow(it->base, "elm.swallow.content", it->content);
364 edje_object_size_min_calc(it->base, &it->minw, &it->minh);
365 evas_object_data_set(it->base, "_elm_leaveme", obj);
366 evas_object_show(it->content);
367 wd->stack = eina_list_append(wd->stack, it);
373 elm_pager_content_pop(Evas_Object *obj)
375 ELM_CHECK_WIDTYPE(obj, widtype);
376 Widget_Data *wd = elm_widget_data_get(obj);
380 if (!wd->stack) return;
381 it = eina_list_last(wd->stack)->data;
382 it->popme = EINA_TRUE;
383 ll = eina_list_last(wd->stack);
394 edje_object_signal_emit(o, "elm,action,pop", "elm");
395 wd->stack = eina_list_remove(wd->stack, it);
396 onhide = edje_object_data_get(o, "onhide");
399 if (!strcmp(onhide, "raise")) evas_object_raise(o);
400 else if (!strcmp(onhide, "lower")) evas_object_lower(o);
407 elm_pager_content_promote(obj, it->content);
413 elm_pager_content_promote(Evas_Object *obj, Evas_Object *content)
415 ELM_CHECK_WIDTYPE(obj, widtype);
416 Widget_Data *wd = elm_widget_data_get(obj);
419 l = _item_get(obj, content);
422 wd->stack = eina_list_demote_list(wd->stack, l);
427 elm_pager_content_bottom_get(const Evas_Object *obj)
429 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
430 Widget_Data *wd = elm_widget_data_get(obj);
432 if (!wd) return NULL;
433 if (!wd->stack) return NULL;
434 it = wd->stack->data;
439 elm_pager_content_top_get(const Evas_Object *obj)
441 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
442 Widget_Data *wd = elm_widget_data_get(obj);
443 if (!wd) return NULL;
444 if (!wd->top) return NULL;
445 return wd->top->content;