Source code formating unification
[platform/framework/web/wrt.git] / src / wrt-client / window_data.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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  * @file        window_data.cpp
18  * @author      Jaroslaw Osmanski (j.osmanski@samsung.com)
19  * @version     1.0
20  * @brief       Window data class implementation
21  */
22 #include "window_data.h"
23
24 #include <ui-gadget.h>
25 #include <dpl/log/log.h>
26
27 namespace {
28 char const* const PLATFORM_EDJ_PATH = "/usr/share/edje/wrt/Platform.edj";
29 char const* const DAEMON_EDJ_PATH = "/usr/share/edje/wrt/Daemon.edj";
30 char const* const THEME_EDJ_PATH = "/usr/share/edje/wrt/wrt_theme.edj";
31 char const* const ELM_STATE_SHOW_CONTENT = "elm,state,show,content";
32 char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
33 char const* const ELM_SWALLOW_BACKWARD = "elm.swallow.backward";
34
35 char const* const ELM = "elm";
36 char const* const LAYOUT = "layout";
37 char const* const APPLICATION = "application";
38 char const* const INDICATOR = "indicator";
39 char const* const NOINDICATOR = "noindicator";
40 char const* const INTERNAL_LAYOUT = "internal_layout";
41 char const* const FLOATBACKWARD_BUTTON_STYLE = "wrt/backward";
42 } // anonymous namespace
43
44 WindowData::WindowData(unsigned long pid, bool manualInit) :
45     m_win(NULL),
46     m_naviBackButton(NULL)
47 {
48     m_win = createWindow(pid);
49
50     if (!manualInit) {
51         init();
52     }
53 }
54
55 WindowData::~WindowData()
56 {
57     LogDebug("");
58     evas_object_del(m_win);
59 }
60
61 void WindowData::init()
62 {
63     Assert(m_win != NULL && "m_win is null");
64
65     // import button theme
66     elm_theme_overlay_add(NULL, THEME_EDJ_PATH);
67
68     m_conformant = createConformant(m_win);
69     evas_object_show(m_conformant);
70     m_platform_layout = createPlatformLayout(m_conformant);
71     evas_object_show(m_platform_layout);
72     m_navigation = createNavigationBar(m_platform_layout);
73     evas_object_show(m_navigation);
74     m_user_layout = createUserLayout(m_navigation);
75     evas_object_show(m_user_layout);
76 }
77
78 void WindowData::setEvasObjectForLayout(Evas_Object* evas_object)
79 {
80     elm_object_content_set(m_conformant, evas_object);
81 }
82
83 void WindowData::unsetEvasObjectForLayout()
84 {
85     elm_object_content_unset(m_conformant);
86 }
87
88 void WindowData::toggleIndicator(bool fullscreen)
89 {
90     LogDebug("fullscreen=" << (fullscreen ? "true" : "false"));
91
92     if (!fullscreen) {
93         elm_win_indicator_mode_set(m_win, ELM_WIN_INDICATOR_SHOW);
94     } else {
95         elm_win_indicator_mode_set(m_win, ELM_WIN_INDICATOR_HIDE);
96     }
97 }
98
99 void WindowData::setViewMode(
100     bool fullscreen,
101     bool backbutton)
102 {
103     LogDebug("setViewMode");
104     LogDebug("fullscreen: " << fullscreen);
105     LogDebug("backbutton: " << backbutton);
106
107     m_fullscreen = fullscreen;
108
109     toggleIndicator(m_fullscreen);
110
111     if (backbutton) {
112         createFloatBackButton();
113     }
114 }
115
116 void WindowData::createFloatBackButton()
117 {
118     // Add float backbutton on the left coner
119     m_floatBackButton = elm_button_add(m_user_layout);
120     elm_object_style_set(m_floatBackButton, FLOATBACKWARD_BUTTON_STYLE);
121     elm_object_part_content_set(m_user_layout,
122                                 ELM_SWALLOW_BACKWARD,
123                                 m_floatBackButton);
124     evas_object_show(m_floatBackButton);
125 }
126
127 Evas_Object* WindowData::createWindow(unsigned long pid)
128 {
129     ADD_PROFILING_POINT("elm_win_add", "start");
130     Evas_Object* window = elm_win_add(NULL, "wrt-widget", ELM_WIN_BASIC);
131     ADD_PROFILING_POINT("elm_win_add", "stop");
132     ecore_x_window_prop_property_set(
133         elm_win_xwindow_get(window),
134         ECORE_X_ATOM_NET_WM_PID,
135         ECORE_X_ATOM_CARDINAL, 32, &pid, 1);
136     elm_win_conformant_set(window, EINA_TRUE);
137     int w, h;
138     ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
139     evas_object_resize(window, w, h);
140
141     return window;
142 }
143
144 Evas_Object* WindowData::createConformant(Evas_Object* parent)
145 {
146     Assert(parent != NULL && "Parent is null");
147     Evas_Object* conformant = elm_conformant_add(parent);
148
149     evas_object_size_hint_weight_set(
150         conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
151     evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
152     elm_win_resize_object_add(parent, conformant);
153     return conformant;
154 }
155
156 Evas_Object* WindowData::createPlatformLayout(Evas_Object* parent)
157 {
158     Evas_Object*  platform_layout = elm_layout_add(parent);
159
160     ADD_PROFILING_POINT("elm_layout_theme_set", "start");
161     elm_layout_file_set(platform_layout, PLATFORM_EDJ_PATH, "platformlayout");
162     ADD_PROFILING_POINT("elm_layout_theme_set", "stop");
163
164     evas_object_size_hint_align_set(platform_layout,
165                                     EVAS_HINT_FILL,
166                                     EVAS_HINT_FILL);
167     evas_object_size_hint_weight_set(platform_layout,
168                                      EVAS_HINT_EXPAND,
169                                      EVAS_HINT_EXPAND);
170
171     elm_object_content_set(parent, platform_layout);
172     edje_object_signal_emit(
173         elm_layout_edje_get(platform_layout), ELM_STATE_SHOW_CONTENT, ELM);
174     return platform_layout;
175 }
176
177 Evas_Object* WindowData::createNavigationBar(Evas_Object* parent)
178 {
179     Assert(parent != NULL && "Parent for naviframe is null");
180     Evas_Object* navigation = elm_naviframe_add(parent);
181
182     evas_object_size_hint_align_set(navigation,
183                                     EVAS_HINT_FILL,
184                                     EVAS_HINT_FILL);
185     evas_object_size_hint_weight_set(navigation,
186                                      EVAS_HINT_EXPAND,
187                                      EVAS_HINT_EXPAND);
188     elm_object_part_content_set(parent, ELM_SWALLOW_CONTENT, navigation);
189     //elm_object_content_set(parent, navigation);
190     return navigation;
191 }
192
193 Evas_Object* WindowData::createUserLayout(Evas_Object* parent)
194 {
195     Assert(parent != NULL && "Parent for User Layout is null");
196     Evas_Object* layout = elm_layout_add(parent);
197     elm_layout_file_set(layout, DAEMON_EDJ_PATH, "client");
198     evas_object_size_hint_weight_set(
199         layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
200     evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
201
202     ADD_PROFILING_POINT("elm_naviframe_item_push", "start");
203     Elm_Object_Item* naviIt = elm_naviframe_item_push(
204             /* Evas_Object *obj */
205             parent,
206             /* const char *title_label  */
207             "",
208             /* Evas_Object *prev_btn */
209             NULL,
210             /* Evas_Object *next_btn */
211             NULL,
212             /* Evas_Object *content */
213             layout,
214             /* const char *item_style */
215             NULL);
216
217     elm_naviframe_item_title_visible_set(naviIt, EINA_FALSE);
218
219     return layout;
220 }
221
222 void WindowData::addNaviBackButtonCallback(
223     const char* event,
224     CallbackType callback,
225     const void* data)
226 {
227     Assert(m_naviBackButton != NULL && "m_naviBackButton is null");
228     evas_object_smart_callback_add(m_naviBackButton, event, callback, data);
229 }
230
231 void* WindowData::delNaviBackButtonCallback(
232     const char* event,
233     CallbackType callBack)
234 {
235     Assert(m_naviBackButton != NULL && "m_naviBackButton is null");
236     return evas_object_smart_callback_del(m_naviBackButton, event, callBack);
237 }
238
239 void WindowData::addFloatBackButtonCallback(
240     const char* event,
241     CallbackType callback,
242     const void* data)
243 {
244     Assert(m_floatBackButton != NULL && "m_floatBackButton is null");
245     evas_object_smart_callback_add(m_floatBackButton, event, callback, data);
246 }
247
248 void* WindowData::delFloatBackButtonCallback(
249     const char* event,
250     CallbackType callBack)
251 {
252     Assert(m_floatBackButton != NULL && "m_floatBackButton is null");
253     return evas_object_smart_callback_del(m_floatBackButton, event, callBack);
254 }
255
256 void WindowData::userlayoutCallbackAdd(
257     const Evas_Callback_Type event,
258     EvasCallbackType callback,
259     const void* data)
260 {
261     Assert(m_user_layout != NULL && "m_user_layout is null");
262     evas_object_event_callback_add(m_user_layout, event, callback, data);
263 }
264
265 void* WindowData::userlayoutCallbackDel(
266     const Evas_Callback_Type event,
267     EvasCallbackType callBack)
268 {
269     Assert(m_user_layout != NULL && "m_user_layout is null");
270     return evas_object_event_callback_del(m_user_layout, event, callBack);
271 }
272
273 void WindowData::emitSignalForUserLayout(
274     const char* emission, const char* source)
275 {
276     LogInfo("emitSignalForUserLayout called");
277     Assert(m_user_layout != NULL && "m_user_layout is null");
278     Assert(emission != NULL && "emission is null");
279     Assert(source != NULL && "source is null");
280
281     edje_object_signal_emit(
282         elm_layout_edje_get(m_user_layout), emission, source);
283 }
284
285 void WindowData::toggleFullscreen(bool fullscreen)
286 {
287     LogDebug(__PRETTY_FUNCTION__);
288
289     static bool alreadyFullscreen = false;
290
291     if (alreadyFullscreen == fullscreen) {
292         // window is in fullscreen mode and fullscreen mode is requested, or
293         // window is not in fullscreen and a request is made to exit fullscreen
294         // In these two situations we don't have to do anything here.
295         return;
296     }
297
298     if (!m_fullscreen) { //If ViewMode is not fullscreen, toggle indicator
299         toggleIndicator(fullscreen);
300     }
301
302     alreadyFullscreen = !alreadyFullscreen;
303 }