2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUi_Window.cpp
20 * @brief This is the implementation file for the _Window class.
23 #include <FBaseSysLog.h>
24 #include <FUiAnimDisplayContext.h>
25 #include <FUiWindow.h>
26 #include <FBase_Log.h>
27 #include <FBaseColArrayListT.h>
28 #include <FApp_AppInfo.h>
29 #include "FUi_Window.h"
30 #include "FUi_ControlManager.h"
31 #include "FUi_TouchManager.h"
32 #include "FUiAnim_DisplayContextImpl.h"
33 #include "FUiAnim_RootVisualElement.h"
34 #include "FUiAnim_VisualElement.h"
35 #include "FUi_EcoreEvasMgr.h"
36 #include "FUi_EcoreEvas.h"
37 #include "FUiAnim_DisplayManager.h"
38 #include "FUiAnim_EflLayer.h"
39 #include "FUiCtrl_Form.h"
40 #include "FUiCtrl_FormImpl.h"
41 #include "FUiCtrl_FrameImpl.h"
43 using namespace Tizen::App;
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
46 using namespace Tizen::Graphics;
47 using namespace Tizen::Ui::Animations;
48 using namespace Tizen::Ui::Controls;
50 namespace Tizen { namespace Ui
54 _Window::CreateWindowN(void)
56 _Window* pWindow = new (std::nothrow) _Window;
57 SysTryReturn(NID_UI, pWindow, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
61 if (IsFailed(GetLastResult()))
66 r = pWindow->CreateRootVisualElement();
67 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
69 pWindow->AcquireHandle();
78 _Window::~_Window(void)
84 if (__pDisplayContext)
86 _DisplayContextImpl::DestroyPublicInstance(*__pDisplayContext);
87 __pDisplayContext = null;
92 //_EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
93 //Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
94 //SysLog(NID_UI, "[Multi_Window] destroy x window(0x%x)", win);
96 if(__pRootVisualElement)
98 __pRootVisualElement->DetachChild(*GetVisualElement());
104 delete __pDimmingLayer;
105 __pDimmingLayer = null;
107 __pRootVisualElement =NULL;
111 _Window::GetWindowDelegate(void) const
115 return const_cast<_Window&>(*this);
118 SysAssert(__pWindowDelegate);
119 return *__pWindowDelegate;
123 _Window::GetDescription(void) const
125 String description = _Control::GetDescription();
126 String descriptionTemp(L"");
128 descriptionTemp.Format(LOG_LEN_MAX, L"_Window: xid(0x%x) owner(0x%x) delegate(0x%x) activated(%d) destroying(%d) displayContext(0x%x)",
129 GetNativeHandle(), __pOwner, __pWindowDelegate, __activated, __destroying, __pDisplayContext);
131 description.Append(descriptionTemp);
137 _Window::SetRootVisualElement(const Tizen::Ui::Animations::_RootVisualElement& rootVisualElement)
139 _RootVisualElement* pRootVE = const_cast<_RootVisualElement*>(&rootVisualElement);
141 __pRootVisualElement = pRootVE;
145 _Window::SetLayer(const Tizen::Ui::Animations::_NativeLayer& layer)
147 _NativeLayer* pLayer = const_cast<_NativeLayer*>(&layer);
153 _Window::IsActivatedOnOpen(void) const
159 _Window::IsActivated(void) const
165 _Window::SetWindowDelegate(_IWindowDelegate& delegate)
168 __pWindowDelegate = &delegate;
172 _Window::ResetWindowDelegate(void)
175 __pWindowDelegate = this;
179 _Window::IsAttached(void) const
181 return _ControlManager::GetInstance()->IsWindowAttached(*this);
185 _Window::Open(bool drawAndShow)
187 bool visibleState = GetVisibleState();
188 if (!__isOpened && visibleState)
190 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
191 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
192 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
194 __isInitialized = true;
195 return _ControlManager::GetInstance()->OpenWindow(*this, drawAndShow);
206 bool visibleState = GetVisibleState();
207 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
208 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
209 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
211 _ControlManager::GetInstance()->CloseWindow(*this);
217 _Window::GetOwner(void) const
224 _Window::SetOwner(_Control* pOwner)
230 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
233 if (__transient == true)
235 pEcoreEvas->SetOwner(*this, *pOwner);
242 if (pOwner == __pOwner)
249 __pOwner->DetachOwnee(*this);
254 pOwner->AttachOwnee(*this);
257 _Control* pOldOwner = __pOwner;
259 GetWindowDelegate().OnOwnerChanged(pOldOwner);
263 _Window::CreateRootVisualElement(_WindowType windowType)
267 result r = CreateLayer();
268 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
270 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
271 SysAssert(pEcoreEvas);
272 __rotation = pEcoreEvas->GetWindowRotation(*this);
273 pEcoreEvas->RegisterWindowStateCallback(*this);
275 // Get visual element.
276 _VisualElement* pVisualElement = GetVisualElement();
277 SysAssert(pVisualElement);
279 pVisualElement->SetName(L"Window");
280 pVisualElement->SetClipChildrenEnabled(false);
281 pVisualElement->SetRenderOperation(_VisualElement::RENDER_OPERATION_COPY);
283 // Attach visual element to root visual element.
284 __pRootVisualElement->AttachChild(*GetVisualElement());
286 if (__type == _WINDOW_TYPE_MAIN)
288 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x, BASIC] Create.", GetNativeHandle());
292 pEcoreEvas->SetWindowType(*this, _WINDOW_TYPE_SUB);
293 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x, UTILITY] Create.", GetNativeHandle());
300 _Window::CreateLayer(void)
302 _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
303 SysAssert(pDisplayManager);
305 if (__type == _WINDOW_TYPE_MAIN)
307 __pLayer = _NativeLayer::CreateInstanceN();
311 __pLayer = _NativeLayer::CreateInstanceN(false);
315 __pRootVisualElement = __pLayer->GetRootVisualElement();
317 _EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
322 ecore_x_window_size_get(ecore_x_window_root_get((Ecore_X_Window)ecore_evas_window_get(pLayer->GetEcoreEvas())), &rootWindowW, &rootWindowH);
324 pLayer->SetBounds(FloatRectangle(0.0f, 0.0f, (float)rootWindowW, (float)rootWindowH));
325 pLayer->SetOpacity(0);
327 __pRootVisualElement->SetName(L"Root");
329 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
333 String appName = _AppInfo::GetAppName();
336 pEcoreEvas->SetWindowName(*this, osp);
343 _Window::IsFocusableDescendant(const _Control* pFocus) const
349 _Window::SetActivationEnabled(bool enable)
351 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
352 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
354 pEcoreEvas->SetWindowActivationEnabled(*GetRootWindow(), enable);
356 SetLastResult(E_SUCCESS);
360 _Window::IsActivationEnabled(void)
362 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
363 SysTryReturn(NID_UI, pEcoreEvas, true, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
365 bool enable = pEcoreEvas->IsWindowActivationEnabled(*GetRootWindow());
367 SetLastResult(E_SUCCESS);
373 _Window::GetRootVisualElement(void) const
375 return __pRootVisualElement;
379 _Window::GetNativeHandle(void) const
381 _RootVisualElement* pRootVE = GetRootVisualElement();
384 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
387 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
388 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
394 _Window::OnActivated(void)
396 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
397 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
399 _Control* focusedControl = GetFocusedControl();
403 focusedControl->SetFocused();
406 if (!isFrameActivated)
411 _Control* pFocus = GetFocused();
414 pFocus->SetFocused();
421 _TouchManager* pTouchMgr = _TouchManager::GetInstance();
424 pTouchMgr->SetTouchCanceled(null);
429 _Window::OnNativeWindowActivated(void)
435 _Window::OnFocusableStateChanged(bool focusalbeState)
437 SetActivationEnabled(focusalbeState);
442 _Window::OnNotifiedN(const _Control& source, IList* pArgs)
444 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
446 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
447 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
449 if (*pType == L"VisibilityEvent")
453 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
454 if (pObscured == null)
456 pArgs->RemoveAll(true);
462 obscured = pObscured->ToInt();
465 GetWindowDelegate().OnNativeWindowActivated();
468 pArgs->RemoveAll(true);
478 _Window::OnDeactivated(void)
480 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
481 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
485 _Window::OnOwnerChanged(_Control* pOldOwner)
491 _Window::OnBoundsChanging(const FloatRectangle& bounds)
493 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
494 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
496 pEcoreEvas->SetWindowBounds(*GetRootWindow(), bounds);
497 result r = GetLastResult();
498 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
504 _Window::OnVisibleStateChanged(void)
508 bool visibleState = GetVisibleState();
509 if (visibleState == false)
514 result r = GetLastResult();
515 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
517 SetLastResult(E_SUCCESS);
521 _Window::OnAttachingToMainTree(const _Control* pParent)
523 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
525 SetVisibleState(true);
526 pLayer->SetShowState(true);
532 _Window::OnDetachingFromMainTree(void)
534 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
536 pLayer->SetShowState(false);
542 _Window::OnWindowStateChanged(void)
548 // Call UpdateOrientation
550 // Find current frame
551 // Call UpdateOrientation
557 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
563 int rotation = pEcoreEvas->GetWindowRotation(*this);
565 Rectangle winBounds = GetBounds();
566 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x, %d, %d, %d, %d] OnWindowStateChanged : prev rot = %d, cur rot = %d", GetNativeHandle(), winBounds.x, winBounds.y, winBounds.width, winBounds.height, __rotation, rotation);
568 if (rotation == __rotation)
573 __rotation = rotation;
576 int childCount = GetChildCount();
577 for (int i = childCount; i > 0; i--)
579 _Control* pChild = GetChild(i - 1);
581 _Form* pForm = dynamic_cast<_Form*>(pChild);
584 if (pForm->IsVisible())
587 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pForm->GetUserData());
590 pFormImpl->UpdateOrientation();
599 if (IsOrientationRoot())
601 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
604 pFrameImpl->UpdateOrientation();
611 SysLog(NID_UI, "[Window Manager Rotation] ---------- Update Ownee Window : START ----------");
613 _ControlOrientation controlOrientation = (rotation == 0 || rotation == 180) ? _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
614 ChangeLayout(controlOrientation);
616 pEcoreEvas->RotateWindow(*this, __rotation, false);
620 SysLog(NID_UI, "[Window Manager Rotation] ---------- Update Ownee Window : END ----------");
624 _Window::SetPreferredRotation(bool enable)
626 __preferredRotation = enable;
630 _Window::GetPreferredRotation(void) const
632 return __preferredRotation;
636 _Window::IsRotationSynchronized(void) const
642 _Window::IsLayoutChangable(void) const
648 _Window::SetRotation(int rotation)
650 __rotation = rotation;
654 _Window::OnChangeLayout(_ControlOrientation orientation)
656 _DimmingLayer *pLayer = GetDimmingLayer();
659 result r = GetDimmingLayer()->Rearrange();
660 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
663 // if window, change its size specially for full-screen(Form, Frame, etc.).
664 _Control::OnChangeLayout(orientation); // if called, layout will be changed.
668 _Window::GetWindowState(void) const
671 return __windowState;
675 _Window::SetWindowState(WindowState windowState)
677 __windowState = windowState;
681 _Window::GetDisplayContext(void) const
683 if (!__pDisplayContext)
685 SysTryReturn(NID_UI, __pLayer, null, E_SYSTEM, "[E_SYSTEM] Cannot gain the DisplayContext. This window is not completed.");
687 __pDisplayContext = _DisplayContextImpl::CreatePublicInstance(*__pLayer);
690 result r = GetLastResult();
691 SysTryReturn(NID_UI, __pDisplayContext, null, r, "[%s] Propagating.", GetErrorMessage(r));
693 return __pDisplayContext;
697 _Window::SetZOrderGroup(int windowZOrderGroup)
699 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
701 if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_HIGHEST)
703 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NOTIFICATION_HIGH);
705 else if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_HIGH)
707 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NOTIFICATION_MIDDLE);
709 else if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_NORMAL)
711 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NORMAL);
716 bool visible = pEcoreEvas->IsWindowVisible(*this);
717 bool activationEnabled = pEcoreEvas->IsWindowActivationEnabled(*this);
719 if ((visible == true) && (activationEnabled == true))
721 pEcoreEvas->ActivateWindow(*this);
728 : __type(_WINDOW_TYPE_MAIN)
729 , __windowState(WINDOW_STATE_INITIALIZED)
731 , __pWindowDelegate(null)
733 , __destroying(false)
734 , __pRootVisualElement(null)
736 , __pDimmingLayer(null)
737 , __pDisplayContext(null)
738 , __systemWindow(false)
740 , __isInitialized(false)
741 , __pFocusedControl(null)
743 , __dimmingEnabled(false)
745 , __preferredRotation(false)
746 , __orientationCallbackMode(false)
748 SetControlDelegate(*this);
749 SetWindowDelegate(*this);
750 SetClipToParent(false); // [ToDo] exception check.
754 _Window::Activate(void)
762 GetWindowDelegate().OnActivated();
766 _Window::Deactivate(void)
770 if (__destroying == false)
772 GetWindowDelegate().OnDeactivated();
777 _Window::SetSystemWindow(bool systemWindow)
779 __systemWindow = systemWindow;
783 _Window::IsSystemWindow(void) const
785 return __systemWindow;
789 _Window::SetFocusedControl(const _Control* pControl)
791 __pFocusedControl = const_cast<_Control*>(pControl);
795 _Window::GetFocusedControl(void) const
797 return __pFocusedControl;
801 _Window::GetFocusList(void) const
803 if(!__pFocusControlList)
805 __pFocusControlList.reset(GetFocusListN());
806 __pFocusControlList->InsertAt(const_cast<_Window*>(this), 0);
808 return __pFocusControlList.get();
812 _Window::ResetFocusList(void)
814 if(__pFocusControlList)
816 __pFocusControlList.reset();
821 _Window::SetDimmingEnabled(bool enabled)
823 __dimmingEnabled = enabled;
829 _Window::IsDimmingEnabled(void) const
831 return __dimmingEnabled;
835 _Window::SetDimmingLayer(_DimmingLayer* pLayer)
837 __pDimmingLayer = pLayer;
841 _Window::GetDimmingLayer(void)
843 return __pDimmingLayer;
847 _Window::SetOrientationCallbackModeEnabled(bool enable)
849 __orientationCallbackMode = enable;
853 _Window::IsOrientationCallbackModeEnabled(void) const
855 return __orientationCallbackMode;