2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file window_data.cpp
18 * @author Jaroslaw Osmanski (j.osmanski@samsung.com)
20 * @brief Window data class implementation
22 #include "window_data.h"
24 #include <ui-gadget.h>
25 #include <dpl/log/log.h>
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";
35 const char *ELM_EVENT_PROFILE_CHANGED = "profile,changed";
37 char const* const ELM = "elm";
38 char const* const LAYOUT = "layout";
39 char const* const APPLICATION = "application";
40 char const* const INDICATOR = "indicator";
41 char const* const NOINDICATOR = "noindicator";
42 char const* const INTERNAL_LAYOUT = "internal_layout";
43 char const* const FLOATBACKWARD_BUTTON_STYLE = "wrt/backward";
44 const std::string DESKTOP_PROFILE("desktop");
45 } // anonymous namespace
47 WindowData::WindowData(unsigned long pid, bool manualInit) :
49 m_naviBackButton(NULL),
52 m_win = createWindow(pid);
59 WindowData::~WindowData()
62 evas_object_del(m_win);
65 void WindowData::init()
67 Assert(m_win != NULL && "m_win is null");
69 if (m_initialized == true)
71 LogInfo("Already initilized");
75 // import button theme
76 elm_theme_overlay_add(NULL, THEME_EDJ_PATH);
78 m_conformant = createConformant(m_win);
79 evas_object_show(m_conformant);
80 m_platform_layout = createPlatformLayout(m_conformant);
81 evas_object_show(m_platform_layout);
82 m_navigation = createNavigationBar(m_platform_layout);
83 evas_object_show(m_navigation);
84 m_user_layout = createUserLayout(m_navigation);
85 evas_object_show(m_user_layout);
90 void WindowData::setEvasObjectForLayout(Evas_Object* evas_object)
92 elm_object_content_set(m_conformant, evas_object);
95 void WindowData::unsetEvasObjectForLayout()
97 elm_object_content_unset(m_conformant);
100 void WindowData::toggleIndicator(bool fullscreen)
102 LogDebug("fullscreen=" << (fullscreen ? "true" : "false"));
105 elm_win_indicator_mode_set(m_win, ELM_WIN_INDICATOR_SHOW);
107 elm_win_indicator_mode_set(m_win, ELM_WIN_INDICATOR_HIDE);
111 void WindowData::setViewMode(
115 LogDebug("setViewMode");
116 LogDebug("fullscreen: " << fullscreen);
117 LogDebug("backbutton: " << backbutton);
119 m_fullscreen = fullscreen;
121 toggleIndicator(m_fullscreen);
124 createFloatBackButton();
128 void WindowData::createFloatBackButton()
130 // Add float backbutton on the left coner
131 m_floatBackButton = elm_button_add(m_user_layout);
132 elm_object_style_set(m_floatBackButton, FLOATBACKWARD_BUTTON_STYLE);
133 elm_object_part_content_set(m_user_layout,
134 ELM_SWALLOW_BACKWARD,
136 evas_object_show(m_floatBackButton);
139 Evas_Object* WindowData::createWindow(unsigned long pid)
141 ADD_PROFILING_POINT("elm_win_add", "start");
142 Evas_Object* window = elm_win_add(NULL, "wrt-widget", ELM_WIN_BASIC);
143 ADD_PROFILING_POINT("elm_win_add", "stop");
144 ecore_x_window_prop_property_set(
145 elm_win_xwindow_get(window),
146 ECORE_X_ATOM_NET_WM_PID,
147 ECORE_X_ATOM_CARDINAL, 32, &pid, 1);
148 elm_win_conformant_set(window, EINA_TRUE);
150 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
151 evas_object_resize(window, w, h);
153 evas_object_smart_callback_add(window,
154 ELM_EVENT_PROFILE_CHANGED,
155 winProfileChangedCallback,
160 Evas_Object* WindowData::createConformant(Evas_Object* parent)
162 Assert(parent != NULL && "Parent is null");
163 Evas_Object* conformant = elm_conformant_add(parent);
165 evas_object_size_hint_weight_set(
166 conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
167 evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
168 elm_win_resize_object_add(parent, conformant);
172 Evas_Object* WindowData::createPlatformLayout(Evas_Object* parent)
174 Evas_Object* platform_layout = elm_layout_add(parent);
176 ADD_PROFILING_POINT("elm_layout_theme_set", "start");
177 elm_layout_file_set(platform_layout, PLATFORM_EDJ_PATH, "platformlayout");
178 ADD_PROFILING_POINT("elm_layout_theme_set", "stop");
180 evas_object_size_hint_align_set(platform_layout,
183 evas_object_size_hint_weight_set(platform_layout,
187 elm_object_content_set(parent, platform_layout);
188 edje_object_signal_emit(
189 elm_layout_edje_get(platform_layout), ELM_STATE_SHOW_CONTENT, ELM);
190 return platform_layout;
193 Evas_Object* WindowData::createNavigationBar(Evas_Object* parent)
195 Assert(parent != NULL && "Parent for naviframe is null");
196 Evas_Object* navigation = elm_naviframe_add(parent);
198 evas_object_size_hint_align_set(navigation,
201 evas_object_size_hint_weight_set(navigation,
204 elm_object_part_content_set(parent, ELM_SWALLOW_CONTENT, navigation);
205 //elm_object_content_set(parent, navigation);
209 Evas_Object* WindowData::createUserLayout(Evas_Object* parent)
211 Assert(parent != NULL && "Parent for User Layout is null");
212 Evas_Object* layout = elm_layout_add(parent);
213 elm_layout_file_set(layout, DAEMON_EDJ_PATH, "client");
214 evas_object_size_hint_weight_set(
215 layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
216 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
218 ADD_PROFILING_POINT("elm_naviframe_item_push", "start");
219 Elm_Object_Item* naviIt = elm_naviframe_item_push(
220 /* Evas_Object *obj */
222 /* const char *title_label */
224 /* Evas_Object *prev_btn */
226 /* Evas_Object *next_btn */
228 /* Evas_Object *content */
230 /* const char *item_style */
232 ADD_PROFILING_POINT("elm_naviframe_item_push", "stop");
234 elm_naviframe_item_title_visible_set(naviIt, EINA_FALSE);
239 void WindowData::setDesktopIcon()
242 Evas_Object *icon = evas_object_image_add(evas_object_evas_get(m_win));
243 evas_object_image_file_set(icon,
244 "/opt/share/icons/default/small/tizenScmgz.png",
246 elm_win_icon_object_set(m_win, icon);
249 void WindowData::addNaviBackButtonCallback(
251 CallbackType callback,
254 Assert(m_naviBackButton != NULL && "m_naviBackButton is null");
255 evas_object_smart_callback_add(m_naviBackButton, event, callback, data);
258 void* WindowData::delNaviBackButtonCallback(
260 CallbackType callBack)
262 Assert(m_naviBackButton != NULL && "m_naviBackButton is null");
263 return evas_object_smart_callback_del(m_naviBackButton, event, callBack);
266 void WindowData::addFloatBackButtonCallback(
268 CallbackType callback,
271 Assert(m_floatBackButton != NULL && "m_floatBackButton is null");
272 evas_object_smart_callback_add(m_floatBackButton, event, callback, data);
275 void* WindowData::delFloatBackButtonCallback(
277 CallbackType callBack)
279 Assert(m_floatBackButton != NULL && "m_floatBackButton is null");
280 return evas_object_smart_callback_del(m_floatBackButton, event, callBack);
283 void WindowData::userlayoutCallbackAdd(
284 const Evas_Callback_Type event,
285 EvasCallbackType callback,
288 Assert(m_user_layout != NULL && "m_user_layout is null");
289 evas_object_event_callback_add(m_user_layout, event, callback, data);
292 void* WindowData::userlayoutCallbackDel(
293 const Evas_Callback_Type event,
294 EvasCallbackType callBack)
296 Assert(m_user_layout != NULL && "m_user_layout is null");
297 return evas_object_event_callback_del(m_user_layout, event, callBack);
300 void WindowData::emitSignalForUserLayout(
301 const char* emission, const char* source)
303 LogInfo("emitSignalForUserLayout called");
304 Assert(m_user_layout != NULL && "m_user_layout is null");
305 Assert(emission != NULL && "emission is null");
306 Assert(source != NULL && "source is null");
308 edje_object_signal_emit(
309 elm_layout_edje_get(m_user_layout), emission, source);
312 void WindowData::toggleFullscreen(bool fullscreen)
314 LogDebug(__PRETTY_FUNCTION__);
316 static bool alreadyFullscreen = false;
318 if (alreadyFullscreen == fullscreen) {
319 // window is in fullscreen mode and fullscreen mode is requested, or
320 // window is not in fullscreen and a request is made to exit fullscreen
321 // In these two situations we don't have to do anything here.
325 if (!m_fullscreen) { //If ViewMode is not fullscreen, toggle indicator
326 toggleIndicator(fullscreen);
329 alreadyFullscreen = !alreadyFullscreen;
332 void WindowData::winProfileChangedCallback(void *data,
333 Evas_Object* /*obj*/,
336 LogDebug("winProfileChangedCallback");
340 WindowData* This = static_cast<WindowData *>(data);
341 const char *profile = elm_config_profile_get();
343 if (DESKTOP_PROFILE == profile) {
344 elm_win_indicator_mode_set(This->m_win, ELM_WIN_INDICATOR_HIDE);
345 This->setDesktopIcon();