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_TOOLBAR = "elm.swallow.toolbar";
34 char const* const ELM_RECT_HIDDENOPTION = "elm.rect.hiddenOption";
36 const char *EDJE_SHOW_TOOLBAR_SIGNAL = "show,toolbar,signal";
37 const char *EDJE_HIDE_TOOLBAR_SIGNAL = "hide,toolbar,signal";
38 const char *EDJE_SHOW_HIDDENOPTION_SIGNAL = "show,hiddenOption,signal";
39 const char *EDJE_HIDE_HIDDENOPTION_SIGNAL = "hide,hiddenOption,signal";
41 char const* const ELM = "elm";
42 char const* const LAYOUT = "layout";
43 char const* const APPLICATION = "application";
44 char const* const INDICATOR = "indicator";
45 char const* const NOINDICATOR = "noindicator";
46 char const* const INTERNAL_LAYOUT = "internal_layout";
47 char const* const FLOATBACKWARD_BUTTON_STYLE = "wrt/backward";
48 } // anonymous namespace
50 WindowData::WindowData(unsigned long pid, bool manualInit) :
51 m_win(NULL), m_naviBackButton(NULL),
55 m_win = createWindow(pid);
63 WindowData::~WindowData()
66 evas_object_del(m_win);
69 void WindowData::init()
71 Assert(m_win != NULL && "m_win is null");
73 // import button theme
74 elm_theme_overlay_add(NULL, THEME_EDJ_PATH);
76 m_conformant = createConformant(m_win);
77 evas_object_show(m_conformant);
78 m_platform_layout = createPlatformLayout(m_conformant);
79 evas_object_show(m_platform_layout);
80 m_navigation = createNavigationBar(m_platform_layout);
81 evas_object_show(m_navigation);
82 m_user_layout = createUserLayout(m_navigation);
83 evas_object_show(m_user_layout);
87 void WindowData::setEvasObjectForLayout(Evas_Object* evas_object)
89 elm_object_content_set(m_conformant, evas_object);
92 void WindowData::unsetEvasObjectForLayout()
94 elm_object_content_unset(m_conformant);
97 void WindowData::toggleIndicator(bool fullscreen)
99 LogDebug(__PRETTY_FUNCTION__);
101 elm_win_indicator_mode_set(m_win, ELM_WIN_INDICATOR_HIDE);
104 elm_win_indicator_mode_set(m_win, ELM_WIN_INDICATOR_SHOW);
109 void WindowData::setViewMode(
111 CtxMenuItems ctxMenuItems)
113 LogDebug("setViewMode");
114 LogDebug("fullscreen: " << fullscreen );
116 m_fullscreen = fullscreen;
118 toggleIndicator(m_fullscreen);
120 m_ctxMenuItems = ctxMenuItems;
123 showHiddenOption(m_user_layout);
124 createToolbar(m_ctxMenuItems);
128 void WindowData::createToolbar(CtxMenuItems ctxMenuItems)
130 Elm_Object_Item *toolbarIt;
131 Evas_Object *toolbarButton;
132 Evas_Object *toolbar;
135 toolbar = elm_toolbar_add(m_user_layout);
139 elm_object_style_set(toolbar, "naviframe");
140 elm_object_part_content_set(m_user_layout,
144 std::list<CtxMenuItem>::iterator itor;
145 for (itor = ctxMenuItems.begin(); itor != ctxMenuItems.end(); ++itor) {
146 toolbarButton = elm_button_add(toolbar);
150 evas_object_size_hint_align_set(toolbarButton,
153 evas_object_size_hint_weight_set(toolbarButton,
157 Evas_Object *ic = elm_icon_add(toolbar);
158 snprintf(buf, sizeof(buf), (*itor).icon.c_str());
159 elm_icon_file_set(ic, buf, NULL);
160 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
161 elm_icon_resizable_set(ic, EINA_TRUE, EINA_TRUE);
162 elm_object_part_content_set(toolbarButton, "icon", ic);
164 evas_object_smart_callback_add(toolbarButton,
168 toolbarIt = elm_toolbar_item_append(toolbar, NULL, NULL, NULL, NULL);
169 elm_object_item_part_content_set(toolbarIt, "object", toolbarButton);
171 //for margin button between buttons
172 toolbarButton = elm_button_add(toolbar);
175 evas_object_color_set(
181 toolbarIt = elm_toolbar_item_append(toolbar, NULL, NULL, NULL, NULL);
182 elm_object_item_part_content_set(toolbarIt, "object", toolbarButton);
185 optionheaderClose = TRUE;
187 elm_object_part_content_set(m_user_layout,
192 void WindowData::showToolbar()
194 emitSignalForUserLayout(EDJE_SHOW_TOOLBAR_SIGNAL, "");
195 m_toolbarTimer = ecore_timer_add(10.0, hideToolbarCallback, this);
198 void WindowData::hideToolbar()
200 emitSignalForUserLayout(EDJE_HIDE_TOOLBAR_SIGNAL, "");
202 ecore_timer_del(m_toolbarTimer);
203 m_toolbarTimer = NULL;
207 Evas_Object* WindowData::createWindow(unsigned long pid)
209 Evas_Object* window = elm_win_add(NULL, "wrt-widget", ELM_WIN_BASIC);
210 ecore_x_window_prop_property_set(
211 elm_win_xwindow_get(window),
212 ECORE_X_ATOM_NET_WM_PID,
213 ECORE_X_ATOM_CARDINAL, 32, &pid, 1);
214 elm_win_title_set(window, "wrt-widget");
215 elm_win_borderless_set(window, EINA_TRUE);
216 elm_win_conformant_set(window, EINA_TRUE);
218 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
219 evas_object_resize(window, w, h);
224 Evas_Object* WindowData::createConformant(Evas_Object* parent)
226 Assert(parent != NULL && "Parent is null");
227 Evas_Object* conformant = elm_conformant_add(parent);
229 evas_object_size_hint_weight_set(
230 conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
231 evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
232 elm_win_resize_object_add(parent, conformant);
236 Evas_Object* WindowData::createPlatformLayout(Evas_Object* parent)
238 Evas_Object* platform_layout = elm_layout_add(parent);
240 elm_layout_file_set(platform_layout, PLATFORM_EDJ_PATH, "platformlayout");
242 evas_object_size_hint_align_set(platform_layout,
245 evas_object_size_hint_weight_set(platform_layout,
249 elm_object_content_set(parent, platform_layout);
250 edje_object_signal_emit(
251 elm_layout_edje_get(platform_layout), ELM_STATE_SHOW_CONTENT, ELM);
252 return platform_layout;
255 Evas_Object* WindowData::createNavigationBar(Evas_Object* parent)
257 Assert(parent != NULL && "Parent for naviframe is null");
258 Evas_Object* navigation = elm_naviframe_add(parent);
260 evas_object_size_hint_align_set(navigation,
263 evas_object_size_hint_weight_set(navigation,
266 elm_object_part_content_set(parent, ELM_SWALLOW_CONTENT, navigation);
267 //elm_object_content_set(parent, navigation);
271 Evas_Object* WindowData::createUserLayout(Evas_Object* parent)
273 Assert(parent != NULL && "Parent for User Layout is null");
274 Evas_Object* layout = elm_layout_add(parent);
275 elm_layout_file_set(layout, DAEMON_EDJ_PATH, "client");
276 evas_object_size_hint_weight_set(
277 layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
278 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
280 Elm_Object_Item* naviIt = elm_naviframe_item_push(
281 /* Evas_Object *obj */
283 /* const char *title_label */
285 /* Evas_Object *prev_btn */
287 /* Evas_Object *next_btn */
289 /* Evas_Object *content */
291 /* const char *item_style */
294 elm_naviframe_item_title_visible_set(naviIt, EINA_FALSE);
299 void WindowData::showHiddenOption(Evas_Object* parent)
301 Assert(parent != NULL && "Parent for Hiden Option");
303 emitSignalForUserLayout(EDJE_SHOW_HIDDENOPTION_SIGNAL, "");
305 edje_object_signal_callback_add(elm_layout_edje_get(parent),
307 "elm.rect.hiddenOption",
308 controlHiddenOptionCallback,
312 void WindowData::hideHiddenOption(Evas_Object* parent)
314 Assert(parent != NULL && "Parent for Hiden Option");
316 emitSignalForUserLayout(EDJE_HIDE_HIDDENOPTION_SIGNAL, "");
318 edje_object_signal_callback_del(elm_layout_edje_get(parent),
320 "elm.rect.hiddenOption",
321 controlHiddenOptionCallback);
324 void WindowData::initFullViewMode ()
327 showHiddenOption(m_user_layout);
330 void WindowData::addNaviBackButtonCallback(
332 CallbackType callback,
335 Assert(m_naviBackButton != NULL && "m_naviBackButton is null");
336 evas_object_smart_callback_add(m_naviBackButton, event, callback, data);
339 void* WindowData::delNaviBackButtonCallback(
341 CallbackType callBack)
343 Assert(m_naviBackButton != NULL && "m_naviBackButton is null");
344 return evas_object_smart_callback_del(m_naviBackButton, event, callBack);
347 void WindowData::userlayoutCallbackAdd(
348 const Evas_Callback_Type event,
349 EvasCallbackType callback,
352 Assert(m_user_layout != NULL && "m_user_layout is null");
353 evas_object_event_callback_add(m_user_layout, event, callback, data);
356 void* WindowData::userlayoutCallbackDel(
357 const Evas_Callback_Type event,
358 EvasCallbackType callBack)
360 Assert(m_user_layout != NULL && "m_user_layout is null");
361 return evas_object_event_callback_del(m_user_layout, event, callBack);
364 void WindowData::emitSignalForUserLayout(
365 const char* emission, const char* source)
367 LogInfo("emitSignalForUserLayout called");
368 Assert(m_user_layout != NULL && "m_user_layout is null");
369 Assert(emission != NULL && "emission is null");
370 Assert(source != NULL && "source is null");
372 edje_object_signal_emit(
373 elm_layout_edje_get(m_user_layout), emission, source);
376 void WindowData::moreButtonCallback(void *data,
377 Evas_Object */*obj*/,
378 void */*event_info*/)
380 WindowData* This = static_cast<WindowData*>(data);
381 Elm_Object_Item *naviIt = elm_naviframe_top_item_get(This->m_navigation);
383 if (This->optionheaderClose)
384 elm_object_item_signal_emit(naviIt, "elm,state,optionheader,open", "");
386 elm_object_item_signal_emit(naviIt, "elm,state,optionheader,close", "");
388 This->optionheaderClose = !This->optionheaderClose;
392 void WindowData::changeViewModeCallback(void *data,
393 Evas_Object */*obj*/,
394 void */*event_info*/)
396 WindowData* This = static_cast<WindowData*>(data);
397 Elm_Object_Item *naviIt = elm_naviframe_top_item_get(This->m_navigation);
399 if(elm_naviframe_item_title_visible_get(naviIt)) {
400 This->showHiddenOption(This->m_user_layout);
403 This ->hideToolbar();
407 void WindowData::controlHiddenOptionCallback(void *data,
408 Evas_Object */*obj*/,
409 const char */*emission*/,
410 const char */*source*/)
412 LogDebug("controlHiddenOptionCallback");
413 WindowData* This = static_cast<WindowData *>(data);
414 Elm_Object_Item *naviIt = elm_naviframe_top_item_get(This->m_navigation);
416 const char* state = edje_object_part_state_get(
417 elm_layout_edje_get(This->m_user_layout),
418 "elm.swallow.toolbar",
421 if (state && !strncmp(state, "default", strlen("default"))) {
423 This->hideHiddenOption(This->m_user_layout);
426 This->initFullViewMode();
430 Eina_Bool WindowData::hideToolbarCallback(void *data)
432 WindowData *This = static_cast<WindowData *>(data);
434 This->initFullViewMode();
438 void WindowData::toggleFullscreen(bool fullscreen)
440 LogDebug(__PRETTY_FUNCTION__);
442 static bool alreadyFullscreen = false;
444 if (alreadyFullscreen == fullscreen) {
445 // window is in fullscreen mode and fullscreen mode is requested, or
446 // window is not in fullscreen and a request is made to exit fullscreen
447 // In these two situations we don't have to do anything here.
451 if (m_indicator) //If indicator is shown by default, toggle it.
452 toggleIndicator(!fullscreen);
454 alreadyFullscreen = !alreadyFullscreen;