Fix build x86_64, fix elementary call
[apps/core/preloaded/settings.git] / setting-common / src / setting-common-draw-popup.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.1 (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
8  *
9  *     http://floralicense.org/license/
10  *
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.
16  */
17
18 #include <setting-common-draw-widget.h>
19 #include <glib.h>
20 #include <utilX.h>
21 #include <Ecore_X.h>
22
23 static void _setting_def_response_cb(void *data, Evas_Object *obj,
24                                      void *event_info)
25 {
26         if (obj) {
27                 evas_object_del(obj);
28                 obj = NULL;
29         }
30 }
31
32 static void __popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
33
34 {
35         SETTING_TRACE_BEGIN;
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);
39         if (ret) {
40                 SETTING_TRACE_ERROR("KEY_HOME ungrab error ret[%d]", ret);
41         }
42
43 }
44
45 /**
46 * @ set the attribution of the specialized progressbar
47 * @See setting_create_custom_progressbar.
48 */
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'
54                                          )
55 {
56         if (timeout > 0) {
57                 if (response_cb) {
58                         evas_object_smart_callback_add(popup, "timeout", response_cb, data);
59                 } else {
60                         evas_object_smart_callback_add(popup, "timeout", _setting_def_response_cb, data);
61                 }
62         }
63
64         if (!blocked_flag) {//not blocked_flag == TRUE !!!
65                 if (response_cb) {
66                         evas_object_smart_callback_add(popup, "block,clicked", response_cb, data);
67                 } else {
68                         evas_object_smart_callback_add(popup, "block,clicked", _setting_def_response_cb, data);
69                 }
70         }
71
72         if (keygrab_flag) {
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);
76                 if (ret) {
77                         SETTING_TRACE_ERROR("KEY_HOME grab error ret[%d]", ret);
78                 }
79                 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, __popup_del_cb, NULL);
80         }
81 }
82 static Evas_Object *__add_progressbar(void *data, Evas_Object *parent,
83                                           char *progressbar_style,
84                                           char *progressbar_title,
85                                           char *progressbar_lable)
86 {
87         SETTING_TRACE_BEGIN;
88         Evas_Object *popup = elm_popup_add(parent);
89         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
90                                          EVAS_HINT_EXPAND);
91         if (progressbar_title) {
92                 elm_object_part_text_set(popup, "title,text", progressbar_title);
93         }
94
95         Evas_Object *box = elm_box_add(popup);
96         /* elm_box_horizontal_set(box, 1); */
97
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);
104         }
105
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,
111                                                 0.5);
112                 evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND,
113                                                  EVAS_HINT_EXPAND);
114                 elm_progressbar_pulse(progressbar, EINA_TRUE);
115                 evas_object_show(progressbar);
116                 elm_box_pack_end(box, progressbar);
117         }
118
119         evas_object_show(box);
120         elm_object_content_set(popup, box);
121         return popup;
122 }
123
124 /**
125 * create a popup window which contents a progressbar
126 *
127 * @return a popup window which contents a progressbar
128 */
129 Evas_Object *setting_create_popup_with_progressbar(void *data,
130                                                   Evas_Object *parent,
131                                                   char *progressbar_style,
132                                                   char *title,
133                                                   char *text,
134                                                   setting_call_back_func response_cb,
135                                                   int timeout,
136                                                   bool blocked_flag,
137                                                   bool keygrab_flag)
138 {
139         SETTING_TRACE_BEGIN;
140         Evas_Object *popup = NULL;
141         popup = __add_progressbar(data, parent, progressbar_style,
142                                   title, text);
143
144         if (timeout > 0) {
145                 elm_popup_timeout_set(popup, timeout);
146         }
147         __popup_event_set(popup, data, response_cb, timeout, blocked_flag, keygrab_flag);
148         evas_object_show(popup);
149         return popup;
150 }
151
152 /**
153 * The general API to create a certain popup window with more than one button.
154 * @return a certain popup window
155 */
156 Evas_Object *setting_create_popup_with_btn(void *data,
157                                           Evas_Object *parent,
158                                           char *title,
159                                           char *text,
160                                           setting_call_back_func response_cb,
161                                           int timeout,
162                                           int btn_num, ...)
163 {
164         SETTING_TRACE_BEGIN;
165         Evas_Object *popup = elm_popup_add(parent);
166         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
167                                          EVAS_HINT_EXPAND);
168         if (text) {
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);
174
175         }
176
177         if (title) {
178                 elm_object_part_text_set(popup, "title,text", title);
179         }
180         if (timeout > 0) {
181                 elm_popup_timeout_set(popup, timeout);
182         }
183
184         if (btn_num > 0) { //the case popup has button or buttons
185                 va_list args;
186                 va_start(args, btn_num);
187
188                 char *btn_str;
189                 int argno = 0;
190                 char *btn_part_str[] = {
191                         _("button1"), _("button2"), _("button3")
192                 };
193
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]);
197                         if (btn_str) {
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);
201                         }
202                 }
203
204                 va_end(args);
205         } else { //the case popup doesn't have any button.
206                 __popup_event_set(popup, data,response_cb, timeout, FALSE, FALSE);
207         }
208
209         evas_object_show(popup);
210         SETTING_TRACE_END;
211         return popup;
212  }
213
214 /**
215 * The general API to create a certain popup window
216 *
217 * @return a certain popup window
218 */
219 Evas_Object *setting_create_popup_without_btn(void *data,
220                                         Evas_Object *parent,
221                                         char *title,
222                                         char *text,
223                                         setting_call_back_func response_cb,
224                                         int timeout,
225                                         bool blocked_flag,
226                                         bool keygrab_flag)
227 {
228         Evas_Object *popup = elm_popup_add(parent);
229         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
230                                          EVAS_HINT_EXPAND);
231         if (text) {
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);
237
238         }
239
240         if (title) {
241                 elm_object_part_text_set(popup, "title,text", title);
242         }
243         if (timeout > 0) {
244                 elm_popup_timeout_set(popup, timeout);
245         }
246
247         __popup_event_set(popup, data,response_cb, timeout, blocked_flag, keygrab_flag);
248         evas_object_show(popup);
249         return popup;
250 }
251
252 /**
253 * The API to create a certain popup window with title
254 *
255 * @return a certain popup window with title
256 * not used now
257 */
258 int setting_create_simple_popup(void *data,
259                                    Evas_Object *parent,
260                                    char *title,
261                                    char *text)
262 {
263         setting_create_popup_without_btn(data, parent, title, text,
264                                          NULL, POPUP_INTERVAL, FALSE, FALSE);
265         return 0;
266 }
267
268
269 #define ADD_POPUP_BTN(btn_num, popup, response_cb, data) \
270         if (btn_num > 0) {\
271                 va_list args;\
272                 va_start(args, btn_num);\
273                 \
274                 char *btn_str;\
275                 int argno = 0;\
276                 char *btn_part_str[] = {\
277                         _("button1"), _("button2"), _("button3")\
278                 };\
279                 \
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]);\
283                         if (btn_str)\
284                         {\
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);\
288                         }\
289                 }\
290                 va_end(args);\
291         } else {\
292                 if (response_cb) {\
293                         evas_object_smart_callback_add(popup, "timeout", response_cb, data);\
294                         evas_object_smart_callback_add(popup, "block,clicked", response_cb, data);\
295                 } else {\
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);\
298                 }\
299         }
300
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'
310                 };
311 */
312 static void __gif_popup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
313 {
314         SETTING_TRACE_BEGIN;
315         evas_object_data_set(obj, "popup_type", NULL);
316 }
317
318 Evas_Object *setting_create_popup_with_gif(void *data,
319                                            Evas_Object *parent,
320                                            char *title,
321                                            char *text,
322                                            const char **png_list,       //array end with 'NULL'.
323                                            setting_call_back_func response_cb,
324                                            int timeout,
325                                            int btn_num, ...)
326 {
327         SETTING_TRACE_BEGIN;
328         //displaying image
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);
335                 }
336         }
337
338         Evas_Object *popup = elm_popup_add(parent);
339         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
340                                          EVAS_HINT_EXPAND);
341         //title
342         if (title) {
343                 elm_object_part_text_set(popup, "title,text", title);
344         }
345
346         if (timeout > 0) {
347                 elm_popup_timeout_set(popup, timeout);
348         }
349
350         //content
351         Evas_Object *content_box = elm_box_add(popup);
352         //instructing of displaying image
353         if (text) {
354                 Evas_Object *lable = setting_create_lable(popup, text,
355                                                           "entry", "middle");
356                 elm_box_pack_end(content_box, lable);
357         }
358         //displaying image
359         if (image) {
360                 elm_box_pack_end(content_box, image);
361         }
362
363
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)
367         {
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);
373
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);
378
379                 evas_object_data_set(popup, "popup_type", "scroller");
380                 //set box into popup
381                 elm_object_content_set(popup, checkview);
382         }
383         else
384         {
385                 evas_object_data_set(popup, "popup_type", "auto_expand");
386                 elm_object_content_set(popup, content_box);
387         }
388         evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, __gif_popup_del_cb, NULL);
389
390         ADD_POPUP_BTN(btn_num, popup, response_cb, data);
391         evas_object_show(popup);
392         return popup;
393
394 }
395
396 Evas_Object *setting_create_popup_with_checkview(Evas_Object *parent,
397                                                  char *title,
398                                                  char *check_str,
399                                                  Evas_Object *checkview_content,
400                                                  const char *checkview_style,
401                                                  Evas_Object **check,
402                                                  int timeout)
403 {
404         Evas_Object *popup = elm_popup_add(parent);
405         evas_object_show(popup);
406         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
407                                          EVAS_HINT_EXPAND);
408         //title
409         if (title) {
410                 elm_object_part_text_set(popup, "title,text", title);
411         }
412
413         if (timeout > 0) {
414                 elm_popup_timeout_set(popup, timeout);
415         }
416
417         //set box into popup
418
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);
422
423         //instructing of displaying image
424         if (check_str) {
425                 edje_object_part_text_set(elm_layout_edje_get(checkview), "elm.text", check_str);
426         }
427         if (check) {
428                 *check = elm_check_add(popup);
429                 evas_object_size_hint_align_set(*check, EVAS_HINT_FILL,
430                                                 EVAS_HINT_FILL);
431                 evas_object_size_hint_weight_set(*check, EVAS_HINT_EXPAND,
432                                                  EVAS_HINT_EXPAND);
433                 evas_object_show(*check);
434                 elm_object_part_content_set(checkview, "elm.swallow.end", *check);
435         }
436         //content
437         if (checkview_content) {
438                 elm_object_part_content_set(checkview, "elm.swallow.content", checkview_content);
439         }
440
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);
446
447         elm_object_content_set(popup, sub_layout);
448         return popup;
449 }
450
451 /**
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
454 */
455 Evas_Object *setting_create_popup_with_image_check(void *data,
456                                              Evas_Object *parent,
457                                              char *title,
458                                              char *text1,
459                                              char *text2,
460                                              char *icon_path,
461                                              char *check_str,
462                                              Evas_Object **check,
463                                              setting_call_back_func response_cb,
464                                              int timeout,
465                                              int btn_num, ...)
466 {
467         SETTING_TRACE_BEGIN;
468         //content
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);
472         if (text1) {
473                 lable = setting_create_lable(content_box, text1, "entry", "middle");
474                 elm_box_pack_end(content_box, lable);
475         }
476         if (icon_path) {
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);
480         }
481
482         if (text2) {
483                 lable = setting_create_lable(content_box, text2, "entry", "middle");
484                 elm_box_pack_end(content_box, lable);
485         }
486
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);
493
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);
498         return popup;
499 }
500
501 /**
502 * Create selectinfo popup
503 */
504 void setting_create_sel_info_popup(Evas_Object *parent,
505                                    Evas_Object **selInfoPop_layout,
506                                    Evas_Object **selInfoPop)
507 {
508         SETTING_TRACE_BEGIN;
509         SETTING_TRACE("*selInfoPop:%p", *selInfoPop);
510         if (!(*selInfoPop)) {
511                 /*  Add notify */
512                 *selInfoPop = elm_notify_add(parent);
513                 elm_notify_orient_set(*selInfoPop, ELM_NOTIFY_ORIENT_BOTTOM);
514                 elm_notify_timeout_set(*selInfoPop, 3);
515
516                 /*  list_data->selInfoPop layout add */
517                 *selInfoPop_layout = elm_layout_add(*selInfoPop);
518                 elm_layout_theme_set(*selInfoPop_layout, "standard", "selectioninfo", "center_text");
519
520                 /*  list_data->selInfoPop layout content set to notify */
521                 elm_object_content_set(*selInfoPop, *selInfoPop_layout);
522         }
523
524         evas_object_show(*selInfoPop);
525 }
526
527 #if APPLIED_BACK_KEY_UG
528
529 /**
530 * Get the toppest popup in current evas, cross through all the APP and UGs.
531 *
532 * @param[in] evas
533 *
534 * @return the toppest popup in current evas
535 */
536 Evas_Object *get_toppest_popup_window(Evas *evas)
537 {
538         Evas_Object *evas_bottom = evas_object_top_get(evas);
539         /* SETTING_TRACE("evas_bottom:%p", evas_bottom); */
540         Evas_Object *below = evas_bottom;
541
542         Evas_Object *found = NULL;
543         const char *type = NULL;
544         while (1) {
545                 /* parent = elm_widget_parent_get(parent); */
546                 below = evas_object_below_get(below);
547                 if (!below) {
548                         break;
549                 }
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")) {
554                         found = below;
555                         break;
556                 }
557         }
558         SETTING_TRACE("found:%p", found);
559         return found;
560 }
561 #endif
562
563
564