54ee314a99c59b7e52b728889a244362a24c08ed
[framework/uifw/elementary.git] / src / bin / test_popup.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 #include <Elementary.h>
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 static void
8 _response_cb(void *data, Evas_Object *obj __UNUSED__,
9              void *event_info __UNUSED__)
10 {
11    Evas_Object *popup_data = evas_object_data_get(data, "im");
12    if (popup_data) evas_object_del(popup_data);
13    evas_object_hide(data);
14    evas_object_del(data);
15 }
16
17 static void
18 _block_clicked_cb(void *data __UNUSED__, Evas_Object *obj,
19                   void *event_info __UNUSED__)
20 {
21    printf("\nblock,clicked callback\n");
22    Evas_Object *popup_data = evas_object_data_get(obj, "im");
23    if (popup_data) evas_object_del(popup_data);
24    evas_object_del(obj);
25 }
26
27 static void
28 _item_selected_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
29                   void *event_info)
30 {
31    printf("popup item selected: %s\n", elm_object_item_text_get(event_info));
32 }
33
34 static void
35 _list_click(void *data __UNUSED__, Evas_Object *obj,
36             void *event_info __UNUSED__)
37 {
38    Elm_Object_Item *it = elm_list_selected_item_get(obj);
39    if (!it) return;
40    elm_list_item_selected_set(it, EINA_FALSE);
41 }
42
43 static void
44 _popup_center_text_cb(void *data, Evas_Object *obj __UNUSED__,
45                       void *event_info __UNUSED__)
46 {
47    Evas_Object *popup;
48
49    popup = elm_popup_add(data);
50    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
51    elm_object_text_set(popup, "This Popup has content area and "
52                        "timeout value is 3 seconds");
53    elm_popup_timeout_set(popup, 3.0);
54    evas_object_smart_callback_add(popup, "timeout", _response_cb, popup);
55    evas_object_show(popup);
56 }
57
58 static void
59 _popup_center_text_1button_cb(void *data, Evas_Object *obj __UNUSED__,
60                               void *event_info __UNUSED__)
61 {
62    Evas_Object *popup;
63    Evas_Object *btn;
64
65    popup = elm_popup_add(data);
66    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
67    elm_object_text_set(popup, "This Popup has content area and "
68                        "action area set, action area has one button Close");
69    btn = elm_button_add(popup);
70    elm_object_text_set(btn, "Close");
71    elm_object_part_content_set(popup, "button1", btn);
72    evas_object_smart_callback_add(btn, "clicked", _response_cb, popup);
73    evas_object_show(popup);
74 }
75
76 static void
77 _popup_center_title_text_1button_cb(void *data, Evas_Object *obj __UNUSED__,
78                                     void *event_info __UNUSED__)
79 {
80    Evas_Object *popup;
81    Evas_Object *btn;
82
83    popup = elm_popup_add(data);
84    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
85    elm_object_text_set(popup, "This Popup has title area, content area and "
86                        "action area set, action area has one button Close");
87    elm_object_part_text_set(popup, "title,text", "Title");
88    btn = elm_button_add(popup);
89    elm_object_text_set(btn, "Close");
90    elm_object_part_content_set(popup, "button1", btn);
91    evas_object_smart_callback_add(btn, "clicked", _response_cb, popup);
92    evas_object_show(popup);
93 }
94
95 static void
96 _popup_center_title_text_block_clicked_event_cb(void *data,
97                                                 Evas_Object *obj __UNUSED__,
98                                                 void *event_info __UNUSED__)
99 {
100    Evas_Object *popup;
101
102    popup = elm_popup_add(data);
103    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
104    elm_object_text_set(popup, "This Popup has title area and content area. "
105                        "When clicked on blocked event region, popup gets "
106                        "deleted");
107    elm_object_part_text_set(popup, "title,text", "Title");
108    evas_object_smart_callback_add(popup, "block,clicked", _block_clicked_cb,
109                                   NULL);
110    evas_object_show(popup);
111 }
112
113 static void
114 _popup_bottom_title_text_3button_cb(void *data, Evas_Object *obj __UNUSED__,
115                                     void *event_info __UNUSED__)
116 {
117    Evas_Object *popup;
118    Evas_Object *icon, *btn1, *btn2, *btn3;
119    char buf[256];
120
121    popup = elm_popup_add(data);
122    elm_popup_orient_set(popup, ELM_POPUP_ORIENT_BOTTOM);
123    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
124    elm_object_text_set(popup, "This Popup has title area, content area and "
125                        "action area set with content being character wrapped. "
126                        "action area has three buttons OK, Cancel and Close");
127    elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_CHAR);
128    elm_object_part_text_set(popup, "title,text", "Title");
129    icon = elm_icon_add(popup);
130    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
131             elm_app_data_dir_get());
132    elm_icon_file_set(icon, buf, NULL);
133    elm_object_part_content_set(popup, "title,icon", icon);
134    btn1 = elm_button_add(popup);
135    elm_object_text_set(btn1, "OK");
136    elm_object_part_content_set(popup, "button1", btn1);
137    btn2 = elm_button_add(popup);
138    elm_object_text_set(btn2, "Cancel");
139    elm_object_part_content_set(popup, "button2", btn2);
140    btn3 = elm_button_add(popup);
141    elm_object_text_set(btn3, "Close");
142    elm_object_part_content_set(popup, "button3", btn3);
143    evas_object_smart_callback_add(btn1, "clicked", _response_cb, popup);
144    evas_object_smart_callback_add(btn2, "clicked", _response_cb, popup);
145    evas_object_smart_callback_add(btn3, "clicked", _response_cb, popup);
146    evas_object_show(popup);
147 }
148
149 static void
150 _popup_center_title_content_3button_cb(void *data, Evas_Object *obj __UNUSED__,
151                                        void *event_info __UNUSED__)
152 {
153    Evas_Object *popup;
154    Evas_Object *icon, *btn, *btn1, *btn2, *btn3;
155    char buf[256];
156
157    popup = elm_popup_add(data);
158    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
159    btn = elm_button_add(popup);
160    elm_object_text_set(btn, "Content");
161    icon = elm_icon_add(btn);
162    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
163             elm_app_data_dir_get());
164    elm_icon_file_set(icon, buf, NULL);
165    elm_object_content_set(btn, icon);
166    elm_object_content_set(popup, btn);
167    elm_object_part_text_set(popup, "title,text", "Title");
168    btn1 = elm_button_add(popup);
169    elm_object_text_set(btn1, "OK");
170    elm_object_part_content_set(popup, "button1", btn1);
171    btn2 = elm_button_add(popup);
172    elm_object_text_set(btn2, "Cancel");
173    elm_object_part_content_set(popup, "button2", btn2);
174    btn3 = elm_button_add(popup);
175    elm_object_text_set(btn3, "Close");
176    elm_object_part_content_set(popup, "button3", btn3);
177    evas_object_smart_callback_add(btn1, "clicked", _response_cb, popup);
178    evas_object_smart_callback_add(btn2, "clicked", _response_cb, popup);
179    evas_object_smart_callback_add(btn3, "clicked", _response_cb, popup);
180    evas_object_show(popup);
181 }
182
183 static void
184 _popup_center_title_item_3button_cb(void *data, Evas_Object *obj __UNUSED__,
185                                     void *event_info __UNUSED__)
186 {
187    char buf[256];
188    unsigned int i;
189    Evas_Object *popup, *icon1, *btn1, *btn2, *btn3;
190
191    popup = elm_popup_add(data);
192    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
193    icon1 = elm_icon_add(popup);
194    elm_object_part_text_set(popup, "title,text", "Title");
195    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
196             elm_app_data_dir_get());
197    elm_icon_file_set(icon1, buf, NULL);
198    for (i = 0; i < 10; i++)
199      {
200         snprintf(buf, sizeof(buf), "Item%u", i+1);
201         if (i == 3)
202           elm_popup_item_append(popup, buf, icon1, _item_selected_cb, NULL);
203         else
204           elm_popup_item_append(popup, buf, NULL, _item_selected_cb, NULL);
205      }
206    btn1 = elm_button_add(popup);
207    elm_object_text_set(btn1, "OK");
208    elm_object_part_content_set(popup, "button1", btn1);
209    btn2 = elm_button_add(popup);
210    elm_object_text_set(btn2, "Cancel");
211    elm_object_part_content_set(popup, "button2", btn2);
212    btn3 = elm_button_add(popup);
213    elm_object_text_set(btn3, "Close");
214    elm_object_part_content_set(popup, "button3", btn3);
215    evas_object_smart_callback_add(btn1, "clicked", _response_cb, popup);
216    evas_object_smart_callback_add(btn2, "clicked", _response_cb, popup);
217    evas_object_smart_callback_add(btn3, "clicked", _response_cb, popup);
218    evas_object_show(popup);
219 }
220
221 static void
222 _restack_btn_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
223 {
224    Evas_Object *im;
225    char buf[PATH_MAX];
226    void *popup_data;
227
228    popup_data = evas_object_data_get(data, "im");
229    if (popup_data) return;
230
231    im = evas_object_image_filled_add(evas_object_evas_get(obj));
232    snprintf(buf, sizeof(buf), "%s/images/%s",
233             elm_app_data_dir_get(), "twofish.jpg");
234    evas_object_image_file_set(im, buf, NULL);
235    evas_object_move(im, 40, 40);
236    evas_object_resize(im, 320, 320);
237    evas_object_show(im);
238    evas_object_data_set((Evas_Object *)data, "im", im);
239
240    evas_object_raise((Evas_Object *)data);
241 }
242
243 static void
244 _popup_center_title_text_2button_restack_cb(void *data, Evas_Object *obj __UNUSED__,
245                                     void *event_info __UNUSED__)
246 {
247    Evas_Object *popup;
248    Evas_Object *btn, *btn2;
249
250    popup = elm_popup_add(data);
251    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
252    elm_object_text_set(popup, "When you click the 'Restack' button, "
253                        "an image will be located under this popup");
254    elm_object_part_text_set(popup, "title,text", "Title");
255    btn = elm_button_add(popup);
256    elm_object_text_set(btn, "Restack");
257    elm_object_part_content_set(popup, "button1", btn);
258    evas_object_smart_callback_add(btn, "clicked", _restack_btn_clicked, popup);
259    evas_object_smart_callback_add(popup, "block,clicked", _block_clicked_cb,
260                                   NULL);
261
262    btn2 = elm_button_add(popup);
263    elm_object_text_set(btn2, "Close");
264    elm_object_part_content_set(popup, "button2", btn2);
265    evas_object_smart_callback_add(btn2, "clicked", _response_cb, popup);
266
267    evas_object_show(popup);
268 }
269
270 void
271 test_popup(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
272            void *event_info __UNUSED__)
273 {
274    Evas_Object *win, *list;
275
276    win = elm_win_util_standard_add("popup", "Popup");
277    elm_win_autodel_set(win, EINA_TRUE);
278
279    list = elm_list_add(win);
280    elm_win_resize_object_add(win, list);
281    elm_list_mode_set(list, ELM_LIST_LIMIT);
282    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
283    evas_object_smart_callback_add(list, "selected", _list_click, NULL);
284
285    elm_list_item_append(list, "popup-center-text", NULL, NULL,
286                         _popup_center_text_cb, win);
287    elm_list_item_append(list, "popup-center-text + 1 button", NULL, NULL,
288                         _popup_center_text_1button_cb, win);
289    elm_list_item_append(list, "popup-center-title + text + 1 button", NULL,
290                         NULL, _popup_center_title_text_1button_cb, win);
291
292    elm_list_item_append(list,
293                         "popup-center-title + text (block,clicked handling)",
294                         NULL, NULL,
295                         _popup_center_title_text_block_clicked_event_cb, win);
296    elm_list_item_append(list, "popup-bottom-title + text + 3 buttons", NULL,
297                         NULL, _popup_bottom_title_text_3button_cb, win);
298    elm_list_item_append(list, "popup-center-title + content + 3 buttons", NULL,
299                         NULL, _popup_center_title_content_3button_cb, win);
300    elm_list_item_append(list, "popup-center-title + items + 3 buttons", NULL,
301                         NULL, _popup_center_title_item_3button_cb, win);
302    elm_list_item_append(list, "popup-center-title + text + 2 buttons (check restacking)", NULL, NULL,
303                         _popup_center_title_text_2button_restack_cb, win);
304    elm_list_go(list);
305    evas_object_show(list);
306    evas_object_show(win);
307    evas_object_resize(win, 480, 800);
308 }
309
310 #endif
311