e931d9a98c334dc11bbfcd5857692d0ef955913f
[apps/native/volume-app.git] / src / _util_efl.c
1  /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.0 (the License);
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://www.tizenopensource.org/license
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an AS IS BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17 #include "volume.h"
18 #include "_util_log.h"
19
20 Evas_Object *_add_window(const char *name)
21 {
22         Evas_Object *eo;
23         int w, h;
24
25         eo = elm_win_add(NULL, name, ELM_WIN_NOTIFICATION);
26         if (eo) {
27                 elm_win_title_set(eo, name);
28                 elm_win_borderless_set(eo, EINA_TRUE);
29                 elm_win_alpha_set(eo, EINA_TRUE);
30                 ecore_x_window_size_get(
31                                 ecore_x_window_root_first_get(),
32                                 &w, &h);
33                 evas_object_resize(eo, w, h);
34         }
35
36         return eo;
37 }
38
39 Evas_Object *_add_naviframe(Evas_Object *parent)
40 {
41         Evas_Object *nv;
42
43         nv = elm_naviframe_add(parent);
44         if (nv == NULL) {
45                 fprintf(stderr, "[Error] Failed to add naviframe\n");
46                 return NULL;
47         }
48
49         elm_object_part_content_set(parent, "elm.swallow.content", nv);
50         evas_object_size_hint_weight_set(nv, EVAS_HINT_EXPAND,
51                                          EVAS_HINT_EXPAND);
52         evas_object_show(nv);
53         return nv;
54 }
55
56 Evas_Object *_add_bg(Evas_Object *parent, char *style)
57 {
58         Evas_Object *bg;
59
60         bg = elm_bg_add(parent);
61         retvm_if(bg == NULL, NULL, "Failed to add bg\n");
62         if (style)      elm_object_style_set(bg, style);
63         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND,
64                                          EVAS_HINT_EXPAND);
65         evas_object_show(bg);
66         return bg;
67 }
68
69 Evas_Object *_add_layout_main(Evas_Object *parent,
70                 Eina_Bool content, Eina_Bool transparent)
71 {
72         Evas_Object *ly;
73
74         ly = elm_layout_add(parent);
75         retvm_if(ly == NULL, NULL, "Failed to add main layout\n");
76
77         elm_layout_theme_set(ly, "layout", "application", "default");
78         evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND,
79                                          EVAS_HINT_EXPAND);
80         elm_win_resize_object_add(parent, ly);
81         if (content)
82                 elm_object_signal_emit(ly, "elm,state,show,content", "elm");
83         if (transparent)
84                 elm_object_signal_emit(ly, "elm,bg,show,transparent", "elm");
85         evas_object_show(ly);
86
87         return ly;
88 }
89
90
91 Evas_Object *_add_layout(Evas_Object *parent, const char *file,
92                              const char *group)
93 {
94         Evas_Object *eo;
95         int r;
96
97         retvm_if(parent == NULL, NULL, "Invalid argument: parent is NULL\n");
98         retvm_if(file == NULL, NULL, "Invalid argument: file is NULL\n");
99         retvm_if(group == NULL, NULL, "Invalid argument: group is NULL\n");
100
101         eo = elm_layout_add(parent);
102         retvm_if(eo == NULL, NULL, "Failed to add layout\n");
103
104         r = elm_layout_file_set(eo, file, group);
105         if (!r) {
106                 _E("Failed to set file[%s]\n", file);
107                 evas_object_del(eo);
108                 return NULL;
109         }
110
111         evas_object_size_hint_weight_set(eo,
112                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
113         evas_object_show(eo);
114         return eo;
115 }
116
117 Evas_Object *_add_controlbar(Evas_Object *parent, const char *style)
118 {
119         Evas_Object *cb;
120
121         cb = elm_toolbar_add(parent);
122         retvm_if(cb == NULL, NULL, "Failed to add toolbar\n");
123         elm_toolbar_shrink_mode_set(cb, ELM_TOOLBAR_SHRINK_EXPAND);
124         elm_toolbar_select_mode_set(cb, ELM_OBJECT_SELECT_MODE_ALWAYS);
125         elm_toolbar_homogeneous_set(cb, EINA_TRUE);
126         if (style) elm_object_style_set(cb, style);
127         evas_object_show(cb);
128
129         return cb;
130 }
131
132 Evas_Object *_add_scroller(Evas_Object *parent,
133                 Eina_Bool h_bounce, Eina_Bool v_bounce)
134 {
135         Evas_Object *sc;
136
137         sc = elm_scroller_add(parent);
138         evas_object_size_hint_weight_set(sc, EVAS_HINT_EXPAND,
139                                          EVAS_HINT_EXPAND);
140         evas_object_size_hint_align_set(sc, EVAS_HINT_FILL, EVAS_HINT_FILL);
141         elm_scroller_bounce_set(sc, h_bounce, v_bounce);
142         elm_scroller_policy_set(sc,
143                                 h_bounce ? ELM_SCROLLER_POLICY_AUTO :
144                                 ELM_SCROLLER_POLICY_OFF,
145                                 v_bounce ? ELM_SCROLLER_POLICY_AUTO :
146                                 ELM_SCROLLER_POLICY_OFF);
147         evas_object_show(sc);
148         return sc;
149 }
150
151 Evas_Object *_add_genlist(Evas_Object *parent)
152 {
153         Evas_Object *eo;
154
155         eo = elm_genlist_add(parent);
156         elm_genlist_homogeneous_set(eo, EINA_TRUE);
157         if (eo == NULL) {
158                 printf("[Error] Cannot add genlist\n");
159                 return NULL;
160         }
161
162         evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND,
163                                          EVAS_HINT_EXPAND);
164         evas_object_size_hint_align_set(eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
165
166         return eo;
167 }
168
169
170 Evas_Object *_add_button(Evas_Object *parent, const char *style)
171 {
172         Evas_Object *bt;
173         bt = elm_button_add(parent);
174         retvm_if(bt == NULL, NULL, "Failed to add button\n");
175         elm_object_style_set(bt, style);
176         elm_object_focus_set(bt, EINA_FALSE);
177         evas_object_show(bt);
178         return bt;
179 }
180
181 Evas_Object *_add_popup(Evas_Object *parent)
182 {
183         Evas_Object *pu;
184
185         pu = elm_popup_add(parent);
186         if (pu == NULL) {
187                 fprintf(stderr, "[Error] Failed to add popup\n");
188                 return NULL;
189         }
190         evas_object_size_hint_weight_set(pu,
191                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
192         evas_object_show(pu);
193
194         return pu;
195 }
196
197 Evas_Object *_add_progressbar(Evas_Object *parent, const char *style)
198 {
199         Evas_Object *pb;
200
201         pb = elm_progressbar_add(parent);
202         if(style)       elm_object_style_set(pb, style);
203         evas_object_size_hint_weight_set(pb,
204                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
205         evas_object_show(pb);
206
207         return pb;
208 }
209
210 Evas_Object *_add_label(Evas_Object *parent, char *text)
211 {
212         Evas_Object *lb;
213
214         lb = elm_label_add(parent);
215         retvm_if(lb == NULL, NULL, "Failed to add label\n");
216         elm_object_text_set(lb, text);
217         evas_object_size_hint_weight_set(lb,
218                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
219         evas_object_show(lb);
220         return lb;
221 }
222