From: Rajeev Ranjan <rajeev.r@samsung.com>
[framework/uifw/elementary.git] / src / bin / test_popup.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 void
8 _response_cb(void *data, Evas_Object *obj __UNUSED__,
9              void *event_info __UNUSED__)
10 {
11    evas_object_hide(data);
12    evas_object_del(data);
13 }
14
15 static void
16 _block_clicked_cb(void *data __UNUSED__, Evas_Object *obj,
17                   void *event_info __UNUSED__)
18 {
19    printf("\nblock,clicked callback\n");
20    evas_object_del(obj);
21 }
22
23 static void
24 _item_selected_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
25                   void *event_info)
26 {
27    printf("popup item selected: %s\n", elm_object_item_text_get(event_info));
28 }
29
30 static void
31 _list_click(void *data __UNUSED__, Evas_Object *obj,
32             void *event_info __UNUSED__)
33 {
34    Elm_Object_Item *it = elm_list_selected_item_get(obj);
35    if (!it) return;
36    elm_list_item_selected_set(it, EINA_FALSE);
37 }
38
39 static void
40 _popup_center_text_cb(void *data, Evas_Object *obj __UNUSED__,
41                       void *event_info __UNUSED__)
42 {
43    Evas_Object *popup;
44
45    popup = elm_popup_add(data);
46    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
47    elm_object_text_set(popup, "This Popup has content area and "
48                        "timeout value is 3 seconds");
49    elm_popup_timeout_set(popup, 3.0);
50    evas_object_smart_callback_add(popup, "timeout", _response_cb, popup);
51    evas_object_show(popup);
52 }
53
54 static void
55 _popup_center_text_1button_cb(void *data, Evas_Object *obj __UNUSED__,
56                               void *event_info __UNUSED__)
57 {
58    Evas_Object *popup;
59    Evas_Object *btn;
60
61    popup = elm_popup_add(data);
62    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
63    elm_object_text_set(popup, "This Popup has content area and "
64                        "action area set, action area has one button Close");
65    btn = elm_button_add(popup);
66    elm_object_text_set(btn, "Close");
67    elm_object_part_content_set(popup, "button1", btn);
68    evas_object_smart_callback_add(btn, "clicked", _response_cb, popup);
69    evas_object_show(popup);
70 }
71
72 static void
73 _popup_center_title_text_1button_cb(void *data, Evas_Object *obj __UNUSED__,
74                                     void *event_info __UNUSED__)
75 {
76    Evas_Object *popup;
77    Evas_Object *btn;
78
79    popup = elm_popup_add(data);
80    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
81    elm_object_text_set(popup, "This Popup has title area, content area and "
82                        "action area set, action area has one button Close");
83    elm_object_part_text_set(popup, "title,text", "Title");
84    btn = elm_button_add(popup);
85    elm_object_text_set(btn, "Close");
86    elm_object_part_content_set(popup, "button1", btn);
87    evas_object_smart_callback_add(btn, "clicked", _response_cb, popup);
88    evas_object_show(popup);
89 }
90
91 static void
92 _popup_center_title_text_block_clicked_event_cb(void *data,
93                                                 Evas_Object *obj __UNUSED__,
94                                                 void *event_info __UNUSED__)
95 {
96    Evas_Object *popup;
97
98    popup = elm_popup_add(data);
99    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100    elm_object_text_set(popup, "This Popup has title area and content area. "
101                        "When clicked on blocked event region, popup gets "
102                        "deleted");
103    elm_object_part_text_set(popup, "title,text", "Title");
104    evas_object_smart_callback_add(popup, "block,clicked", _block_clicked_cb,
105                                   NULL);
106    evas_object_show(popup);
107 }
108
109 static void
110 _popup_bottom_title_text_3button_cb(void *data, Evas_Object *obj __UNUSED__,
111                                     void *event_info __UNUSED__)
112 {
113    Evas_Object *popup;
114    Evas_Object *icon, *btn1, *btn2, *btn3;
115    char buf[256];
116
117    popup = elm_popup_add(data);
118    elm_popup_orient_set(popup, ELM_POPUP_ORIENT_BOTTOM);
119    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
120    elm_object_text_set(popup, "This Popup has title area, content area and "
121                        "action area set with content being character wrapped. "
122                        "action area has three buttons OK, Cancel and Close");
123    elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_CHAR);
124    elm_object_part_text_set(popup, "title,text", "Title");
125    icon = elm_icon_add(popup);
126    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
127             elm_app_data_dir_get());
128    elm_icon_file_set(icon, buf, NULL);
129    elm_object_part_content_set(popup, "title,icon", icon);
130    btn1 = elm_button_add(popup);
131    elm_object_text_set(btn1, "OK");
132    elm_object_part_content_set(popup, "button1", btn1);
133    btn2 = elm_button_add(popup);
134    elm_object_text_set(btn2, "Cancel");
135    elm_object_part_content_set(popup, "button2", btn2);
136    btn3 = elm_button_add(popup);
137    elm_object_text_set(btn3, "Close");
138    elm_object_part_content_set(popup, "button3", btn3);
139    evas_object_smart_callback_add(btn1, "clicked", _response_cb, popup);
140    evas_object_smart_callback_add(btn2, "clicked", _response_cb, popup);
141    evas_object_smart_callback_add(btn3, "clicked", _response_cb, popup);
142    evas_object_show(popup);
143 }
144
145 static void
146 _popup_center_title_content_3button_cb(void *data, Evas_Object *obj __UNUSED__,
147                                        void *event_info __UNUSED__)
148 {
149    Evas_Object *popup;
150    Evas_Object *icon, *btn, *btn1, *btn2, *btn3;
151    char buf[256];
152
153    popup = elm_popup_add(data);
154    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
155    btn = elm_button_add(popup);
156    elm_object_text_set(btn, "Content");
157    icon = elm_icon_add(btn);
158    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
159             elm_app_data_dir_get());
160    elm_icon_file_set(icon, buf, NULL);
161    elm_object_content_set(btn, icon);
162    elm_object_content_set(popup, btn);
163    elm_object_part_text_set(popup, "title,text", "Title");
164    btn1 = elm_button_add(popup);
165    elm_object_text_set(btn1, "OK");
166    elm_object_part_content_set(popup, "button1", btn1);
167    btn2 = elm_button_add(popup);
168    elm_object_text_set(btn2, "Cancel");
169    elm_object_part_content_set(popup, "button2", btn2);
170    btn3 = elm_button_add(popup);
171    elm_object_text_set(btn3, "Close");
172    elm_object_part_content_set(popup, "button3", btn3);
173    evas_object_smart_callback_add(btn1, "clicked", _response_cb, popup);
174    evas_object_smart_callback_add(btn2, "clicked", _response_cb, popup);
175    evas_object_smart_callback_add(btn3, "clicked", _response_cb, popup);
176    evas_object_show(popup);
177 }
178
179 static void
180 _popup_center_title_item_3button_cb(void *data, Evas_Object *obj __UNUSED__,
181                                     void *event_info __UNUSED__)
182 {
183    char buf[256];
184    unsigned int i;
185    Evas_Object *popup, *icon1, *btn1, *btn2, *btn3;
186
187    popup = elm_popup_add(data);
188    evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
189    icon1 = elm_icon_add(popup);
190    elm_object_part_text_set(popup, "title,text", "Title");
191    snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
192             elm_app_data_dir_get());
193    elm_icon_file_set(icon1, buf, NULL);
194    for (i = 0; i < 10; i++)
195      {
196         snprintf(buf, sizeof(buf), "Item%u", i+1);
197         if (i == 3)
198           elm_popup_item_append(popup, buf, icon1, _item_selected_cb, NULL);
199         else
200           elm_popup_item_append(popup, buf, NULL, _item_selected_cb, NULL);
201      }
202    btn1 = elm_button_add(popup);
203    elm_object_text_set(btn1, "OK");
204    elm_object_part_content_set(popup, "button1", btn1);
205    btn2 = elm_button_add(popup);
206    elm_object_text_set(btn2, "Cancel");
207    elm_object_part_content_set(popup, "button2", btn2);
208    btn3 = elm_button_add(popup);
209    elm_object_text_set(btn3, "Close");
210    elm_object_part_content_set(popup, "button3", btn3);
211    evas_object_smart_callback_add(btn1, "clicked", _response_cb, popup);
212    evas_object_smart_callback_add(btn2, "clicked", _response_cb, popup);
213    evas_object_smart_callback_add(btn3, "clicked", _response_cb, popup);
214    evas_object_show(popup);
215 }
216
217 void
218 test_popup(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
219            void *event_info __UNUSED__)
220 {
221    Evas_Object *win, *bg, *list;
222
223    win = elm_win_add(NULL, "popup", ELM_WIN_BASIC);
224    elm_win_title_set(win, "popup");
225    elm_win_autodel_set(win, EINA_TRUE);
226
227    bg = elm_bg_add(win);
228    elm_win_resize_object_add(win, bg);
229    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
230    evas_object_show(bg);
231
232    list = elm_list_add(win);
233    elm_win_resize_object_add(win, list);
234    elm_list_mode_set(list, ELM_LIST_LIMIT);
235    evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
236    evas_object_smart_callback_add(list, "selected", _list_click, NULL);
237
238    elm_list_item_append(list, "popup-center-text", NULL, NULL,
239                         _popup_center_text_cb, win);
240    elm_list_item_append(list, "popup-center-text + 1 button", NULL, NULL,
241                         _popup_center_text_1button_cb, win);
242    elm_list_item_append(list, "popup-center-title + text + 1 button", NULL,
243                         NULL, _popup_center_title_text_1button_cb, win);
244
245    elm_list_item_append(list,
246                         "popup-center-title + text (block,clicked handling)",
247                         NULL, NULL,
248                         _popup_center_title_text_block_clicked_event_cb, win);
249    elm_list_item_append(list, "popup-bottom-title + text + 3 buttons", NULL,
250                         NULL, _popup_bottom_title_text_3button_cb, win);
251    elm_list_item_append(list, "popup-center-title + content + 3 buttons", NULL,
252                         NULL, _popup_center_title_content_3button_cb, win);
253    elm_list_item_append(list, "popup-center-title + items + 3 buttons", NULL,
254                         NULL, _popup_center_title_item_3button_cb, win);
255    elm_list_go(list);
256    evas_object_show(list);
257    evas_object_show(win);
258    evas_object_resize(win, 480, 800);
259 }
260
261 #endif
262