merge with master
[apps/native/volume-app.git] / src / _util_efl.c
1 /*
2  * org.tizen.volume
3  * Copyright 2012  Samsung Electronics Co., Ltd
4  *
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
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
19 #include <Ecore.h>
20 #include <Ecore_X.h>
21 #include <system_info.h>
22
23 #include "volume.h"
24 #include "_util_log.h"
25
26 Ecore_X_Window _add_input_window(void)
27 {
28         Ecore_X_Window win = 0;
29         win = ecore_x_window_input_new(0, 0, 0, 1, 1);
30         if(win){
31                 ecore_x_event_mask_unset(win, ECORE_X_EVENT_MASK_NONE);
32                 ecore_x_icccm_title_set(win, "volumekey-input-window");
33                 ecore_x_netwm_name_set(win, "volumekey-input-window");
34                 ecore_x_netwm_pid_set(win, getpid());
35                 return win;
36         }
37         else{
38                 _E("%s() is failed\n", __func__);
39                 return 0;
40         }
41 }
42
43 Evas_Object *_add_window(const char *name)
44 {
45         Evas_Object *eo = NULL;
46         int w = -1, h = -1;
47         eo = elm_win_add(NULL, name, ELM_WIN_NOTIFICATION);
48         if (eo) {
49                 elm_win_title_set(eo, name);
50                 elm_win_borderless_set(eo, EINA_TRUE);
51                 elm_win_alpha_set(eo, EINA_TRUE);
52                 system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &w);
53                 system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_HEIGHT, &h);
54                 if(w == -1 || h == -1){
55                         _E("ecore_x_window_seiz_get() is failed\n");
56                         return NULL;
57                 }
58                 evas_object_resize(eo, w, h);
59         }
60         return eo;
61 }
62
63 Evas_Object *_add_slider(Evas_Object *parent, int min, int max, int val)
64 {
65         Evas_Object *sl = NULL;
66         sl = elm_slider_add(parent);
67         retvm_if(sl == NULL, NULL, "Failed to add slider\n");
68         elm_slider_horizontal_set(sl, EINA_TRUE);
69         elm_slider_indicator_show_set(sl, EINA_TRUE);
70         elm_slider_indicator_format_set(sl, "%.0f");
71         evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.0);
72         evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
73         elm_slider_min_max_set(sl, min, max);
74         elm_slider_value_set(sl, val);
75         return sl;
76 }
77
78 Evas_Object *_add_layout(Evas_Object *parent, const char *file,
79                              const char *group)
80 {
81         Evas_Object *eo = NULL;
82         int r = -1;
83
84         retvm_if(parent == NULL, NULL, "Invalid argument: parent is NULL\n");
85         retvm_if(file == NULL, NULL, "Invalid argument: file is NULL\n");
86         retvm_if(group == NULL, NULL, "Invalid argument: group is NULL\n");
87
88         eo = elm_layout_add(parent);
89         retvm_if(eo == NULL, NULL, "Failed to add layout\n");
90
91         r = elm_layout_file_set(eo, file, group);
92         if (!r) {
93                 _E("Failed to set file[%s]\n", file);
94                 evas_object_del(eo);
95                 return NULL;
96         }
97
98         evas_object_size_hint_weight_set(eo,
99                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100         evas_object_show(eo);
101         return eo;
102 }
103
104 Evas_Object *_add_button(Evas_Object *parent, const char *style, const char *text)
105 {
106         Evas_Object *bt = NULL;
107         bt = elm_button_add(parent);
108         retvm_if(bt == NULL, NULL, "Failed to add button\n");
109         if (style) elm_object_style_set(bt, style);
110         elm_object_focus_set(bt, EINA_FALSE);
111         elm_object_text_set(bt, text);
112         evas_object_show(bt);
113         return bt;
114 }
115
116 Evas_Object *_add_popup(Evas_Object *parent, const char *style)
117 {
118         Evas_Object *pu = NULL;
119         pu = elm_popup_add(parent);
120         retvm_if(pu == NULL, NULL, "[Error] Failed to add popup\n");
121         evas_object_size_hint_weight_set(pu, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
122         if (style) elm_object_style_set(pu, style);
123         evas_object_show(pu);
124         return pu;
125 }
126 Evas_Object *_add_label(Evas_Object *parent, const char *style, const char *text)
127 {
128         Evas_Object *lb = NULL;
129         lb = elm_label_add(parent);
130         retvm_if(lb == NULL, NULL, "Failed to add label\n");
131         elm_object_style_set(lb, style);
132         evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
133         evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
134         elm_label_line_wrap_set(lb, ELM_WRAP_MIXED);
135         elm_object_text_set(lb, text);
136         return lb;
137 }
138