elm: change elm_object_content_part_set/get/unset to elm_object_part_content_set...
[framework/uifw/elementary.git] / src / bin / test_pager.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6 typedef struct _Pginfo Pginfo;
7
8 struct _Pginfo
9 {
10     Evas_Object *win, *pager, *pg1, *pg2, *pg3, *pg4;
11 };
12
13 static void
14 my_pager_1(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
15 {
16    Pginfo *info = data;
17    elm_pager_content_promote(info->pager, info->pg2);
18 }
19
20 static void
21 my_pager_2(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
22 {
23    Pginfo *info = data;
24    elm_pager_content_promote(info->pager, info->pg3);
25 }
26
27 static void
28 my_pager_3(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
29 {
30    Pginfo *info = data;
31    elm_pager_content_promote(info->pager, info->pg4);
32 }
33
34
35 static void
36 my_pager_4(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
37 {
38    Pginfo *info = data;
39    elm_pager_content_promote(info->pager, info->pg1);
40 }
41
42
43 static void
44 my_pager_pop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
45 {
46    Pginfo *info = data;
47    elm_pager_content_pop(info->pager);
48 }
49
50 struct style_tuple {
51      const char *label;
52      const char *name;
53 };
54 static const struct style_tuple styles[] = {
55        { "Default", "default"},
56        { "Slide", "slide"},
57        { "Slide Invisible", "slide_invisible"},
58        { "Fade", "fade"},
59        { "Fade Translucide", "fade_translucide"},
60        { "Fade Invisible", "fade_invisible"},
61        { "Flip", "flip"},
62 };
63
64 static void
65 _style(void *data, Evas_Object *obj, void *event_info __UNUSED__)
66 {
67    Evas_Object *pg = data;
68    elm_object_style_set(pg, styles[elm_radio_value_get(obj)].name);
69 }
70
71 void
72 test_pager(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
73 {
74    Evas_Object *win, *bg, *pg, *bx, *lb, *bt;
75    static Pginfo info;
76
77    win = elm_win_add(NULL, "pager", ELM_WIN_BASIC);
78    elm_win_title_set(win, "Pager");
79    elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
80    elm_win_autodel_set(win, EINA_TRUE);
81    info.win = win;
82
83    bg = elm_bg_add(win);
84    elm_win_resize_object_add(win, bg);
85    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
86    evas_object_show(bg);
87
88    pg = elm_pager_add(win);
89    evas_object_size_hint_weight_set(pg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
90    elm_win_resize_object_add(win, pg);
91    evas_object_show(pg);
92
93    info.pager = pg;
94
95    bx = elm_box_add(win);
96    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
97    evas_object_show(bx);
98
99    lb = elm_label_add(win);
100    elm_object_text_set(lb,
101                        "This is page 1 in a pager stack.<br>"
102                        "<br>"
103                        "So what is a pager stack? It is a stack<br>"
104                        "of pages that hold widgets in it. The<br>"
105                        "pages can be pushed and popped on and<br>"
106                        "off the stack, activated and otherwise<br>"
107                        "activated if already in the stack<br>"
108                        "(activated means promoted to the top of<br>"
109                        "the stack).<br>"
110                        "<br>"
111                        "The theme may define the animation how<br>"
112                        "show and hide of pages. Select one theme style:");
113    elm_box_pack_end(bx, lb);
114    evas_object_show(lb);
115
116    unsigned int i = 0;
117    Evas_Object *rdg = NULL, *rd;
118    for (i = 0; i < (sizeof(styles) / sizeof(struct style_tuple)); i++)
119      {
120         rd = elm_radio_add(win);
121         elm_object_text_set(rd, styles[i].label);
122         elm_radio_state_value_set(rd, i);
123         if (rdg)
124           elm_radio_group_add(rd, rdg);
125         else
126           rdg = rd;
127         evas_object_smart_callback_add(rd, "changed", _style, pg);
128         elm_box_pack_end(bx, rd);
129         evas_object_show(rd);
130      }
131    elm_radio_value_set(rd, 0);
132
133    bt = elm_button_add(win);
134    elm_object_text_set(bt, "Flip to 2");
135    evas_object_smart_callback_add(bt, "clicked", my_pager_1, &info);
136    elm_box_pack_end(bx, bt);
137    evas_object_show(bt);
138
139    bt = elm_button_add(win);
140    elm_object_text_set(bt, "Popme");
141    evas_object_smart_callback_add(bt, "clicked", my_pager_pop, &info);
142    elm_box_pack_end(bx, bt);
143    evas_object_show(bt);
144    elm_pager_content_push(pg, bx);
145    info.pg1 = bx;
146
147    bx = elm_box_add(win);
148    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
149    evas_object_show(bx);
150
151    lb = elm_label_add(win);
152    elm_object_text_set(lb,
153                        "This is page 2 in a pager stack.<br>"
154                        "<br>"
155                        "This is just like the previous page in<br>"
156                        "the pager stack."
157                        );
158    elm_box_pack_end(bx, lb);
159    evas_object_show(lb);
160
161    bt = elm_button_add(win);
162    elm_object_text_set(bt, "Flip to 3");
163    evas_object_smart_callback_add(bt, "clicked", my_pager_2, &info);
164    elm_box_pack_end(bx, bt);
165    evas_object_show(bt);
166
167    bt = elm_button_add(win);
168    elm_object_text_set(bt, "Popme");
169    evas_object_smart_callback_add(bt, "clicked", my_pager_pop, &info);
170    elm_box_pack_end(bx, bt);
171    evas_object_show(bt);
172    elm_pager_content_push(pg, bx);
173    info.pg2 = bx;
174
175    bx = elm_box_add(win);
176    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
177    evas_object_show(bx);
178
179    lb = elm_label_add(win);
180    elm_object_text_set(lb,
181                        "This is page 3 in a pager stack.<br>"
182                        "<br>"
183                        "This is just like the previous page in<br>"
184                        "the pager stack.");
185    elm_box_pack_end(bx, lb);
186    evas_object_show(lb);
187
188    bt = elm_button_add(win);
189    elm_object_text_set(bt, "Flip to 1");
190    evas_object_smart_callback_add(bt, "clicked", my_pager_3, &info);
191    elm_box_pack_end(bx, bt);
192    evas_object_show(bt);
193
194    bt = elm_button_add(win);
195    elm_object_text_set(bt, "Popme");
196    evas_object_smart_callback_add(bt, "clicked", my_pager_pop, &info);
197    elm_box_pack_end(bx, bt);
198    evas_object_show(bt);
199    elm_pager_content_push(pg, bx);
200    info.pg3 = bx;
201
202    Evas_Object *ly, *ly2;
203    char buf[4096];
204
205    ly = elm_layout_add(win);
206    snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
207    elm_layout_file_set(ly, buf, "test/layout");
208    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
209    evas_object_show(ly);
210
211    ly2 = elm_layout_add(win);
212    snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
213    elm_layout_file_set(ly2, buf, "layout2");
214    evas_object_size_hint_weight_set(ly2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
215    //elm_win_resize_object_add(win, ly2);
216    evas_object_show(ly2);
217
218
219
220
221    bt = elm_button_add(win);
222    elm_object_text_set(bt, "Flip to 1");
223    evas_object_smart_callback_add(bt, "clicked", my_pager_4, &info);
224    elm_object_part_content_set(ly2, "element1", bt);
225    evas_object_show(bt);
226
227    bt = elm_button_add(win);
228    elm_object_text_set(bt, "Popme");
229    evas_object_smart_callback_add(bt, "clicked", my_pager_pop, &info);
230    evas_object_show(bt);
231    elm_object_part_content_set(ly2, "element2", bt);
232
233    elm_object_part_content_set(ly, "swallow", ly2);
234    evas_object_show(ly);
235
236    elm_pager_content_push(pg, ly);
237    info.pg4 = ly2;
238
239
240    evas_object_show(win);
241 }
242
243 static void
244 my_pager_push(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
245 {
246    Pginfo *info = data;
247    Evas_Object *bx, *bt, *lb;
248    static int count = 2;
249    char buf[32];
250
251    bx = elm_box_add(info->win);
252    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
253    evas_object_show(bx);
254
255    lb = elm_label_add(info->win);
256    snprintf(buf, sizeof(buf), "This is page %d in the slide pager<br><br>", count++);
257    elm_object_text_set(lb, buf);
258    elm_box_pack_end(bx, lb);
259    evas_object_show(lb);
260
261    bt = elm_button_add(info->win);
262    elm_object_text_set(bt, "Push a new page");
263    evas_object_smart_callback_add(bt, "clicked", my_pager_push, info);
264    elm_box_pack_end(bx, bt);
265    evas_object_show(bt);
266
267    bt = elm_button_add(info->win);
268    elm_object_text_set(bt, "Go back (pop)");
269    evas_object_smart_callback_add(bt, "clicked", my_pager_pop, info);
270    elm_box_pack_end(bx, bt);
271    evas_object_show(bt);
272    elm_pager_content_push(info->pager, bx);
273 }
274
275 void
276 test_pager_slide(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
277 {
278    Evas_Object *win, *bg, *pg, *bx, *lb, *bt;
279    static Pginfo info;
280
281    win = elm_win_add(NULL, "pager", ELM_WIN_BASIC);
282    elm_win_title_set(win, "Pager Slide");
283    elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
284    elm_win_autodel_set(win, EINA_TRUE);
285    info.win = win;
286
287    bg = elm_bg_add(win);
288    elm_win_resize_object_add(win, bg);
289    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
290    evas_object_show(bg);
291
292    pg = elm_pager_add(win);
293    elm_win_resize_object_add(win, pg);
294    elm_object_style_set(pg, "slide");
295    evas_object_show(pg);
296    info.pager = pg;
297
298    bx = elm_box_add(win);
299    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
300    evas_object_show(bx);
301
302    lb = elm_label_add(win);
303    elm_object_text_set(lb,
304                        "This is page 1 in a slide pager.<br>"
305                        "<br>"
306                        "The slide pager style is useful for browsing<br>"
307                        "a hierarchy of objects, as it makes clear<br>"
308                        "the direction of the browse.<br>"
309                        "This is the 'slide' style, also available<br>"
310                        "a fully transparent style named 'slide_invisble'.<br>"
311                        "<br>");
312    elm_box_pack_end(bx, lb);
313    evas_object_show(lb);
314
315    bt = elm_button_add(win);
316    elm_object_text_set(bt, "Push a new page");
317    evas_object_smart_callback_add(bt, "clicked", my_pager_push, &info);
318    elm_box_pack_end(bx, bt);
319    evas_object_show(bt);
320
321    bt = elm_button_add(win);
322    elm_object_text_set(bt, "Go back (pop)");
323    evas_object_smart_callback_add(bt, "clicked", my_pager_pop, &info);
324    elm_box_pack_end(bx, bt);
325    evas_object_show(bt);
326    elm_pager_content_push(pg, bx);
327
328    evas_object_show(win);
329 }
330 #endif