3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Flora License, Version 1.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <setting-common-draw-widget.h>
23 static void _setting_def_response_cb(void *data, Evas_Object *obj,
32 static void __popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
36 Ecore_X_Display *disp = ecore_x_display_get();
37 Ecore_X_Window xwin = elm_win_xwindow_get(obj);
38 int ret = utilx_ungrab_key(disp, xwin, KEY_HOME);
40 SETTING_TRACE_ERROR("KEY_HOME ungrab error ret[%d]", ret);
46 * @ set the attribution of the specialized progressbar
47 * @See setting_create_custom_progressbar.
49 static void __popup_event_set(Evas_Object *popup, void *data,
50 setting_call_back_func response_cb,
51 int timeout,//to control the timeout time
52 bool blocked_flag,//to control whether to block the screen
53 bool keygrab_flag//to control whether to block the 'Home key'
58 evas_object_smart_callback_add(popup, "timeout", response_cb, data);
60 evas_object_smart_callback_add(popup, "timeout", _setting_def_response_cb, data);
64 if (!blocked_flag) {//not blocked_flag == TRUE !!!
66 evas_object_smart_callback_add(popup, "block,clicked", response_cb, data);
68 evas_object_smart_callback_add(popup, "block,clicked", _setting_def_response_cb, data);
73 Ecore_X_Display *disp = ecore_x_display_get();
74 Ecore_X_Window xwin = elm_win_xwindow_get(popup);
75 int ret = utilx_grab_key(disp, xwin, KEY_HOME, TOP_POSITION_GRAB);
77 SETTING_TRACE_ERROR("KEY_HOME grab error ret[%d]", ret);
79 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, __popup_del_cb, NULL);
82 static Evas_Object *__add_progressbar(void *data, Evas_Object *parent,
83 char *progressbar_style,
84 char *progressbar_title,
85 char *progressbar_lable)
88 Evas_Object *popup = elm_popup_add(parent);
89 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
91 if (progressbar_title) {
92 elm_object_part_text_set(popup, "title,text", progressbar_title);
95 Evas_Object *box = elm_box_add(popup);
96 /* elm_box_horizontal_set(box, 1); */
98 if (progressbar_lable) {
99 Evas_Object *label = elm_label_add(popup);
100 elm_object_text_set(label, progressbar_lable); /* "Loading..." */
101 //elm_label_text_align_set(label, "left");
102 evas_object_show(label);
103 elm_box_pack_end(box, label);
106 if (progressbar_style) {
107 Evas_Object *progressbar = elm_progressbar_add(popup);
108 elm_object_style_set(progressbar, progressbar_style); /* "toolbar_process" or "pending_list" or "list_prosess" */
109 elm_progressbar_pulse(progressbar, EINA_TRUE);
110 evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL,
112 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND,
114 elm_progressbar_pulse(progressbar, EINA_TRUE);
115 evas_object_show(progressbar);
116 elm_box_pack_end(box, progressbar);
119 evas_object_show(box);
120 elm_object_content_set(popup, box);
125 * create a popup window which contents a progressbar
127 * @return a popup window which contents a progressbar
129 Evas_Object *setting_create_popup_with_progressbar(void *data,
131 char *progressbar_style,
134 setting_call_back_func response_cb,
140 Evas_Object *popup = NULL;
141 popup = __add_progressbar(data, parent, progressbar_style,
145 elm_popup_timeout_set(popup, timeout);
147 __popup_event_set(popup, data, response_cb, timeout, blocked_flag, keygrab_flag);
148 evas_object_show(popup);
153 * The general API to create a certain popup window with more than one button.
154 * @return a certain popup window
156 Evas_Object *setting_create_popup_with_btn(void *data,
160 setting_call_back_func response_cb,
165 Evas_Object *popup = elm_popup_add(parent);
166 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
169 char r_str_text[HELP_MSG_BUFF_SIZE] = { 0, };
170 snprintf(r_str_text, HELP_MSG_BUFF_SIZE, "<align=center>");
171 g_strlcat(r_str_text, text, HELP_MSG_BUFF_SIZE);
172 g_strlcat(r_str_text, "</align>", HELP_MSG_BUFF_SIZE);
173 elm_object_text_set(popup, r_str_text);
178 elm_object_part_text_set(popup, "title,text", title);
181 elm_popup_timeout_set(popup, timeout);
184 if (btn_num > 0) { //the case popup has button or buttons
186 va_start(args, btn_num);
190 char *btn_part_str[] = {
191 _("button1"), _("button2"), _("button3")
194 for (; argno < btn_num; argno++) {
195 btn_str = va_arg( args, char *);
196 SETTING_TRACE("Parameter #%d is: %s, btn_part_str;%s", argno, btn_str, btn_part_str[argno]);
198 Evas_Object *btn = setting_create_button(popup, btn_str, NULL, response_cb, data);
199 elm_object_style_set(btn, "popup_button/default");
200 elm_object_part_content_set(popup, btn_part_str[argno], btn);
205 } else { //the case popup doesn't have any button.
206 __popup_event_set(popup, data,response_cb, timeout, FALSE, FALSE);
209 evas_object_show(popup);
215 * The general API to create a certain popup window
217 * @return a certain popup window
219 Evas_Object *setting_create_popup_without_btn(void *data,
223 setting_call_back_func response_cb,
228 Evas_Object *popup = elm_popup_add(parent);
229 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
232 char r_str_text[HELP_MSG_BUFF_SIZE] = { 0, };
233 snprintf(r_str_text, HELP_MSG_BUFF_SIZE, "<align=center>");
234 g_strlcat(r_str_text, text, HELP_MSG_BUFF_SIZE);
235 g_strlcat(r_str_text, "</align>", HELP_MSG_BUFF_SIZE);
236 elm_object_text_set(popup, r_str_text);
241 elm_object_part_text_set(popup, "title,text", title);
244 elm_popup_timeout_set(popup, timeout);
247 __popup_event_set(popup, data,response_cb, timeout, blocked_flag, keygrab_flag);
248 evas_object_show(popup);
253 * The API to create a certain popup window with title
255 * @return a certain popup window with title
258 int setting_create_simple_popup(void *data,
263 setting_create_popup_without_btn(data, parent, title, text,
264 NULL, POPUP_INTERVAL, FALSE, FALSE);
269 #define ADD_POPUP_BTN(btn_num, popup, response_cb, data) \
272 va_start(args, btn_num);\
276 char *btn_part_str[] = {\
277 _("button1"), _("button2"), _("button3")\
280 for (; argno < btn_num; argno++) {\
281 btn_str = va_arg( args, char *);\
282 SETTING_TRACE("Parameter #%d is: %s, btn_part_str;%s", argno, btn_str, btn_part_str[argno]);\
285 Evas_Object *btn = setting_create_button(popup, btn_str, NULL, response_cb, data);\
286 elm_object_style_set(btn, "popup_button/default");\
287 elm_object_part_content_set(popup, btn_part_str[argno], btn);\
293 evas_object_smart_callback_add(popup, "timeout", response_cb, data);\
294 evas_object_smart_callback_add(popup, "block,clicked", response_cb, data);\
296 evas_object_smart_callback_add(popup, "timeout", _setting_def_response_cb, data);\
297 evas_object_smart_callback_add(popup, "block,clicked", _setting_def_response_cb, data);\
301 //1Title-1Description-1Gif-nButton
302 /* @png_list is an array end with 'NULL'. like ,
303 const char *png_list[] = {
304 SETTING_ICON_PATH_CFG"motions/motion_overturn_01.png",
305 SETTING_ICON_PATH_CFG"motions/motion_overturn_02.png",
306 SETTING_ICON_PATH_CFG"motions/motion_overturn_03.png",
307 SETTING_ICON_PATH_CFG"motions/motion_overturn_04.png",
308 SETTING_ICON_PATH_CFG"motions/motion_overturn_05.png",
309 NULL //must end with 'NULL'
312 static void __gif_popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
315 evas_object_data_set(obj, "popup_type", NULL);
318 Evas_Object *setting_create_popup_with_gif(void *data,
322 const char **png_list, //array end with 'NULL'.
323 setting_call_back_func response_cb,
329 Evas_Object *image = NULL;
330 if (png_list && *png_list) {
331 if (png_list[1]) { //png_list is an array end with 'NULL', and it has at least 2 png file,
332 image = setting_create_gif(parent, png_list);
333 } else { //png_list just has one png file,
334 image = setting_create_image(parent, *png_list);
338 Evas_Object *popup = elm_popup_add(parent);
339 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
343 elm_object_part_text_set(popup, "title,text", title);
347 elm_popup_timeout_set(popup, timeout);
351 Evas_Object *content_box = elm_box_add(popup);
352 //instructing of displaying image
354 Evas_Object *lable = setting_create_lable(popup, text,
356 elm_box_pack_end(content_box, lable);
360 elm_box_pack_end(content_box, image);
364 app_device_orientation_e m = elm_win_rotation_get(parent);
365 SETTING_TRACE("m:%d", m);
366 if(APP_DEVICE_ORIENTATION_90 == m || APP_DEVICE_ORIENTATION_270 == m)
368 Evas_Object *scroller = elm_scroller_add(parent);
369 elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
370 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
371 evas_object_show(scroller);
372 elm_object_content_set(scroller, content_box);
374 Evas_Object *checkview = elm_layout_add(parent);
375 elm_layout_file_set(checkview, SETTING_THEME_EDJ_NAME, "popup_checkview_image");
376 evas_object_size_hint_weight_set(checkview, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
377 elm_object_part_content_set(checkview, "elm.swallow.content", scroller);
379 evas_object_data_set(popup, "popup_type", "scroller");
381 elm_object_content_set(popup, checkview);
385 evas_object_data_set(popup, "popup_type", "auto_expand");
386 elm_object_content_set(popup, content_box);
388 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, __gif_popup_del_cb, NULL);
390 ADD_POPUP_BTN(btn_num, popup, response_cb, data);
391 evas_object_show(popup);
396 Evas_Object *setting_create_popup_with_checkview(Evas_Object *parent,
399 Evas_Object *checkview_content,
400 const char *checkview_style,
404 Evas_Object *popup = elm_popup_add(parent);
405 evas_object_show(popup);
406 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
410 elm_object_part_text_set(popup, "title,text", title);
414 elm_popup_timeout_set(popup, timeout);
419 Evas_Object *checkview = elm_layout_add(parent);
420 elm_layout_file_set(checkview, SETTING_THEME_EDJ_NAME, checkview_style);
421 evas_object_size_hint_weight_set(checkview, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
423 //instructing of displaying image
425 edje_object_part_text_set(elm_layout_edje_get(checkview), "elm.text", check_str);
428 *check = elm_check_add(popup);
429 evas_object_size_hint_align_set(*check, EVAS_HINT_FILL,
431 evas_object_size_hint_weight_set(*check, EVAS_HINT_EXPAND,
433 evas_object_show(*check);
434 elm_object_part_content_set(checkview, "elm.swallow.end", *check);
437 if (checkview_content) {
438 elm_object_part_content_set(checkview, "elm.swallow.content", checkview_content);
441 Evas_Object *sub_layout = elm_layout_add(popup);
442 elm_layout_file_set(sub_layout, SETTING_THEME_EDJ_NAME, "screen_mode");
443 evas_object_size_hint_weight_set(sub_layout, EVAS_HINT_EXPAND, 0.0);
444 evas_object_show(sub_layout);
445 elm_object_part_content_set(sub_layout, "content", checkview);
447 elm_object_content_set(popup, sub_layout);
452 * The API to create a certain popup window with a image, a check and some buttons
453 * @return a certain popup window with title
455 Evas_Object *setting_create_popup_with_image_check(void *data,
463 setting_call_back_func response_cb,
469 Evas_Object *lable = NULL;
470 Evas_Object *content_box = elm_box_add(parent);
471 evas_object_size_hint_weight_set(content_box, EVAS_HINT_EXPAND, 0);
473 lable = setting_create_lable(content_box, text1, "entry", "middle");
474 elm_box_pack_end(content_box, lable);
477 Evas_Object *image = setting_create_image(content_box, icon_path);
478 setting_resize_object(image, 100*WIDGET_SCALE_FACTOR, 110*WIDGET_SCALE_FACTOR);
479 elm_box_pack_end(content_box, image);
483 lable = setting_create_lable(content_box, text2, "entry", "middle");
484 elm_box_pack_end(content_box, lable);
487 Evas_Object *scroller = elm_scroller_add(parent);
488 evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, 0);
489 elm_scroller_bounce_set(scroller, EINA_FALSE, EINA_TRUE);
490 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
491 evas_object_show(scroller);
492 elm_object_content_set(scroller, content_box);
494 Evas_Object *popup = setting_create_popup_with_checkview(parent, title, check_str, scroller,
495 "popup_checkview_image", check, timeout);
496 ADD_POPUP_BTN(btn_num, popup, response_cb, data);
497 evas_object_show(popup);
502 * Create selectinfo popup
504 void setting_create_sel_info_popup(Evas_Object *parent,
505 Evas_Object **selInfoPop_layout,
506 Evas_Object **selInfoPop)
509 SETTING_TRACE("*selInfoPop:%p", *selInfoPop);
510 if (!(*selInfoPop)) {
512 *selInfoPop = elm_notify_add(parent);
513 elm_notify_align_set(*selInfoPop, ELM_NOTIFY_ALIGN_FILL, 1.0);
514 elm_notify_timeout_set(*selInfoPop, 3);
516 /* list_data->selInfoPop layout add */
517 *selInfoPop_layout = elm_layout_add(*selInfoPop);
518 elm_layout_theme_set(*selInfoPop_layout, "standard", "selectioninfo", "center_text");
520 /* list_data->selInfoPop layout content set to notify */
521 elm_object_content_set(*selInfoPop, *selInfoPop_layout);
524 evas_object_show(*selInfoPop);
527 #if APPLIED_BACK_KEY_UG
530 * Get the toppest popup in current evas, cross through all the APP and UGs.
534 * @return the toppest popup in current evas
536 Evas_Object *get_toppest_popup_window(Evas *evas)
538 Evas_Object *evas_bottom = evas_object_top_get(evas);
539 /* SETTING_TRACE("evas_bottom:%p", evas_bottom); */
540 Evas_Object *below = evas_bottom;
542 Evas_Object *found = NULL;
543 const char *type = NULL;
545 /* parent = elm_widget_parent_get(parent); */
546 below = evas_object_below_get(below);
550 /* SETTING_TRACE("below:%p", below); */
551 type = elm_widget_type_get(below);
552 /* SETTING_TRACE("below's type:%s", type); */
553 if (type && !safeStrCmp(type, "popup")) {
558 SETTING_TRACE("found:%p", found);