elm: change elm_object_content_part_set/get/unset to elm_object_part_content_set...
[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
36 void
37 _title_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
38 {
39    printf("Title Clicked!\n");
40 }
41
42 void
43 _title_visible(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
44 {
45    elm_naviframe_item_title_visible_set(data,
46                                !elm_naviframe_item_title_visible_get(data));
47 }
48
49 void
50 _page5(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
51 {
52    Evas_Object *bt, *content, *nf = data;
53    Elm_Object_Item *it;
54
55    bt = elm_button_add(nf);
56    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
57    elm_object_text_set(bt, "Prev");
58
59    content = _content_new(nf, img5);
60    it = elm_naviframe_item_insert_after(elm_naviframe_top_item_get(nf),
61                                         "Page 5",
62                                         bt,
63                                         NULL,
64                                         content,
65                                         NULL);
66
67    evas_object_smart_callback_add(bt, "clicked", _navi_it_del, it);
68 }
69
70 void
71 _page4(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
72 {
73    Evas_Object *bt, *ic, *content, *nf = data;
74    char buf[PATH_MAX];
75    Elm_Object_Item *it;
76
77    ic = elm_icon_add(nf);
78    snprintf(buf, sizeof(buf), "%s/images/icon_right_arrow.png",
79             elm_app_data_dir_get());
80    elm_icon_file_set(ic, buf, NULL);
81    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
82
83    bt = elm_button_add(nf);
84    evas_object_smart_callback_add(bt, "clicked", _page5, nf);
85    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
86    elm_object_part_content_set(bt, "icon", ic);
87
88    content = _content_new(nf, img4);
89
90    it = elm_naviframe_item_push(nf,
91                                 "Page 4",
92                                 NULL,
93                                 bt,
94                                 content,
95                                 NULL);
96    ic = elm_icon_add(nf);
97    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
98             elm_app_data_dir_get());
99    elm_icon_file_set(ic, buf, NULL);
100    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
101    elm_object_item_content_part_set(it, "icon", ic);
102    elm_naviframe_item_title_visible_set(it, EINA_FALSE);
103    evas_object_smart_callback_add(content, "clicked", _title_visible, it);
104 }
105
106 void
107 _page3(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
108 {
109    Evas_Object *bt, *bt2, *ic, *content, *nf = data;
110    char buf[PATH_MAX];
111    Elm_Object_Item *it;
112
113    bt = elm_button_add(nf);
114    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
115    elm_object_text_set(bt, "Prev");
116    evas_object_smart_callback_add(bt, "clicked", _navi_pop, nf);
117
118    bt2 = elm_button_add(nf);
119    evas_object_size_hint_align_set(bt2, EVAS_HINT_FILL, EVAS_HINT_FILL);
120    elm_object_text_set(bt2, "Next");
121    evas_object_smart_callback_add(bt2, "clicked", _page4, nf);
122
123    content = _content_new(nf, img3);
124
125    it = elm_naviframe_item_push(nf,
126                                 "Page 3",
127                                 bt,
128                                 bt2,
129                                 content,
130                                 NULL);
131    ic = elm_icon_add(nf);
132    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
133    elm_icon_file_set(ic, buf, NULL);
134    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
135
136    elm_object_item_content_part_set(it, "icon", ic);
137 }
138
139 void
140 _page2(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
141 {
142    Evas_Object *bt, *content, *ic, *nf = data;
143    char buf[PATH_MAX];
144    Elm_Object_Item *it;
145
146    bt = elm_button_add(nf);
147    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
148    evas_object_smart_callback_add(bt, "clicked", _page3, nf);
149
150    ic = elm_icon_add(nf);
151    snprintf(buf, sizeof(buf), "%s/images/icon_right_arrow.png",
152             elm_app_data_dir_get());
153    elm_icon_file_set(ic, buf, NULL);
154    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
155    elm_object_part_content_set(bt, "icon", ic);
156
157    content = _content_new(nf, img2);
158
159    it = elm_naviframe_item_push(nf, "Page 2", NULL, bt, content,  NULL);
160    elm_object_item_text_part_set(it, "subtitle", "Here is sub-title part!");
161 }
162
163 void
164 test_naviframe(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
165 {
166    Evas_Object *win, *bg, *nf, *btn, *content;
167
168    win = elm_win_add(NULL, "naviframe", ELM_WIN_BASIC);
169    elm_win_title_set(win, "Naviframe");
170    elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
171    elm_win_autodel_set(win, EINA_TRUE);
172
173    bg = elm_bg_add(win);
174    elm_win_resize_object_add(win, bg);
175    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
176    evas_object_show(bg);
177
178    nf = elm_naviframe_add(win);
179    elm_win_resize_object_add(win, nf);
180    evas_object_size_hint_weight_set(nf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
181    evas_object_show(nf);
182    evas_object_smart_callback_add(nf, "title,clicked", _title_clicked, 0);
183
184    btn = elm_button_add(nf);
185    evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
186    evas_object_smart_callback_add(btn, "clicked", _page2, nf);
187    elm_object_text_set(btn, "Next");
188    evas_object_show(btn);
189
190    content = _content_new(nf, img1);
191    elm_naviframe_item_push(nf, "Page 1", NULL, btn, content, NULL);
192
193    evas_object_resize(win, 400, 600);
194    evas_object_show(win);
195 }
196 #endif