[naviframe] Sync test with upstream
[framework/uifw/elementary.git] / src / bin / test_naviframe.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 static const char *img1 = PACKAGE_DATA_DIR"/images/logo.png";
8 static const char *img2 = PACKAGE_DATA_DIR"/images/plant_01.jpg";
9 static const char *img3 = PACKAGE_DATA_DIR"/images/rock_01.jpg";
10 static const char *img4 = PACKAGE_DATA_DIR"/images/rock_02.jpg";
11 static const char *img5 = PACKAGE_DATA_DIR"/images/sky_01.jpg";
12
13 Evas_Object *
14 _content_new(Evas_Object *parent, const char *img)
15 {
16    Evas_Object *photo = elm_photo_add(parent);
17    elm_photo_file_set(photo, img);
18    elm_photo_fill_inside_set(photo, EINA_TRUE);
19    elm_object_style_set(photo, "shadow");
20    return photo;
21 }
22
23 void
24 _navi_pop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
25 {
26    elm_naviframe_item_pop(data);
27 }
28
29 void
30 _navi_it_del(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
31 {
32    elm_naviframe_item_del(data);
33 }
34
35 void
36 _title_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
37 {
38    printf("Title Clicked!\n");
39 }
40
41 void
42 _title_visible(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
43 {
44    elm_naviframe_item_title_visible_set(data,
45                                !elm_naviframe_item_title_visible_get(data));
46 }
47
48 void
49 _promote(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
50 {
51    elm_naviframe_item_promote(data);
52 }
53
54 void
55 _page5(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
56 {
57    Evas_Object *bt, *bt2, *content, *nf = data;
58    Elm_Object_Item *it;
59
60    bt = elm_button_add(nf);
61    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
62    elm_object_text_set(bt, "Prev");
63
64    bt2 = elm_button_add(nf);
65    evas_object_size_hint_align_set(bt2, EVAS_HINT_FILL, EVAS_HINT_FILL);
66    elm_object_text_set(bt2, "Page 1");
67    evas_object_smart_callback_add(bt2, "clicked", _promote,
68                                   evas_object_data_get(nf, "page1"));
69
70    content = _content_new(nf, img5);
71    it = elm_naviframe_item_insert_after(elm_naviframe_top_item_get(nf),
72                                         "Page 5",
73                                         bt,
74                                         bt2,
75                                         content,
76                                         NULL);
77
78    evas_object_smart_callback_add(bt, "clicked", _navi_it_del, it);
79 }
80
81 void
82 _page4(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
83 {
84    Evas_Object *bt, *ic, *content, *nf = data;
85    char buf[PATH_MAX];
86    Elm_Object_Item *it;
87
88    ic = elm_icon_add(nf);
89    snprintf(buf, sizeof(buf), "%s/images/icon_right_arrow.png",
90             elm_app_data_dir_get());
91    elm_icon_file_set(ic, buf, NULL);
92    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
93
94    bt = elm_button_add(nf);
95    evas_object_smart_callback_add(bt, "clicked", _page5, nf);
96    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
97    elm_object_part_content_set(bt, "icon", ic);
98
99    content = _content_new(nf, img4);
100
101    it = elm_naviframe_item_push(nf,
102                                 "Page 4",
103                                 NULL,
104                                 bt,
105                                 content,
106                                 NULL);
107
108    ic = elm_icon_add(nf);
109    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
110             elm_app_data_dir_get());
111    elm_icon_file_set(ic, buf, NULL);
112    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
113    elm_object_item_part_content_set(it, "icon", ic);
114    elm_naviframe_item_title_visible_set(it, EINA_FALSE);
115    evas_object_smart_callback_add(content, "clicked", _title_visible, it);
116 }
117
118 void
119 _page3(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
120 {
121    Evas_Object *bt, *bt2, *ic, *content, *nf = data;
122    char buf[PATH_MAX];
123    Elm_Object_Item *it;
124
125    bt = elm_button_add(nf);
126    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
127    elm_object_text_set(bt, "Prev");
128    evas_object_smart_callback_add(bt, "clicked", _navi_pop, nf);
129
130    bt2 = elm_button_add(nf);
131    evas_object_size_hint_align_set(bt2, EVAS_HINT_FILL, EVAS_HINT_FILL);
132    elm_object_text_set(bt2, "Next");
133    evas_object_smart_callback_add(bt2, "clicked", _page4, nf);
134
135    content = _content_new(nf, img3);
136
137    it = elm_naviframe_item_push(nf,
138                                 "Page 3",
139                                 bt,
140                                 bt2,
141                                 content,
142                                 NULL);
143    ic = elm_icon_add(nf);
144    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
145    elm_icon_file_set(ic, buf, NULL);
146    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
147
148    elm_object_item_part_content_set(it, "icon", ic);
149 }
150
151 void
152 _page2(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
153 {
154    Evas_Object *bt, *content, *ic, *nf = data;
155    char buf[PATH_MAX];
156    Elm_Object_Item *it;
157
158    bt = elm_button_add(nf);
159    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
160    evas_object_smart_callback_add(bt, "clicked", _page3, nf);
161
162    ic = elm_icon_add(nf);
163    snprintf(buf, sizeof(buf), "%s/images/icon_right_arrow.png",
164             elm_app_data_dir_get());
165    elm_icon_file_set(ic, buf, NULL);
166    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
167    elm_object_part_content_set(bt, "icon", ic);
168
169    content = _content_new(nf, img2);
170
171    it = elm_naviframe_item_push(nf, "Page 2", NULL, bt, content,  NULL);
172    elm_object_item_part_text_set(it, "subtitle", "Here is sub-title part!");
173 }
174
175 void
176 test_naviframe(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
177 {
178    Evas_Object *win, *bg, *nf, *btn, *content;
179    Elm_Object_Item *it;
180
181    win = elm_win_add(NULL, "naviframe", ELM_WIN_BASIC);
182    elm_win_title_set(win, "Naviframe");
183    elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
184    elm_win_autodel_set(win, EINA_TRUE);
185
186    bg = elm_bg_add(win);
187    elm_win_resize_object_add(win, bg);
188    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
189    evas_object_show(bg);
190
191    nf = elm_naviframe_add(win);
192    elm_win_resize_object_add(win, nf);
193    evas_object_size_hint_weight_set(nf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
194    evas_object_show(nf);
195    evas_object_smart_callback_add(nf, "title,clicked", _title_clicked, 0);
196
197    btn = elm_button_add(nf);
198    evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
199    evas_object_smart_callback_add(btn, "clicked", _page2, nf);
200    elm_object_text_set(btn, "Next");
201    evas_object_show(btn);
202
203    content = _content_new(nf, img1);
204    it = elm_naviframe_item_push(nf, "Page 1", NULL, btn, content, NULL);
205    evas_object_data_set(nf, "page1", it);
206
207    evas_object_resize(win, 400, 600);
208    evas_object_show(win);
209 }
210 #endif