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"
42 #include "FUi_AccessibilityManager.h"
44 using namespace Tizen::App;
45 using namespace Tizen::Base;
46 using namespace Tizen::Base::Collection;
47 using namespace Tizen::Graphics;
48 using namespace Tizen::Ui::Animations;
49 using namespace Tizen::Ui::Controls;
51 namespace Tizen { namespace Ui
55 _Window::CreateWindowN(void)
57 _Window* pWindow = new (std::nothrow) _Window;
58 SysTryReturn(NID_UI, pWindow, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
62 if (IsFailed(GetLastResult()))
67 r = pWindow->CreateRootVisualElement();
68 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
70 pWindow->AcquireHandle();
79 _Window::~_Window(void)
85 if (__pDisplayContext)
87 _DisplayContextImpl::DestroyPublicInstance(*__pDisplayContext);
88 __pDisplayContext = null;
93 //_EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
94 //Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
95 //SysLog(NID_UI, "[Multi_Window] destroy x window(0x%x)", win);
97 if(__pRootVisualElement)
99 if (GetVisualElement())
101 __pRootVisualElement->DetachChild(*GetVisualElement());
108 delete __pDimmingLayer;
109 __pDimmingLayer = null;
111 __pRootVisualElement =NULL;
113 _ControlManager::GetInstance()->DetachAllWindow(*this);
117 _Window::GetWindowDelegate(void) const
121 return const_cast<_Window&>(*this);
124 SysAssert(__pWindowDelegate);
125 return *__pWindowDelegate;
129 _Window::GetDescription(void) const
131 String description = _Control::GetDescription();
132 String descriptionTemp(L"");
134 descriptionTemp.Format(LOG_LEN_MAX, L"_Window: xid(0x%x) owner(0x%x) delegate(0x%x) activated(%d) destroying(%d) displayContext(0x%x)",
135 GetNativeHandle(), __pOwner, __pWindowDelegate, __activated, __destroying, __pDisplayContext);
137 description.Append(descriptionTemp);
143 _Window::SetRootVisualElement(const Tizen::Ui::Animations::_RootVisualElement& rootVisualElement)
145 _RootVisualElement* pRootVE = const_cast<_RootVisualElement*>(&rootVisualElement);
147 __pRootVisualElement = pRootVE;
151 _Window::SetLayer(const Tizen::Ui::Animations::_NativeLayer& layer)
153 _NativeLayer* pLayer = const_cast<_NativeLayer*>(&layer);
159 _Window::IsActivatedOnOpen(void) const
165 _Window::IsActivated(void) const
171 _Window::SetWindowDelegate(_IWindowDelegate& delegate)
174 __pWindowDelegate = &delegate;
178 _Window::ResetWindowDelegate(void)
181 __pWindowDelegate = this;
185 _Window::IsAttached(void) const
187 return _ControlManager::GetInstance()->IsWindowAttached(*this);
191 _Window::Open(bool drawAndShow)
193 bool visibleState = GetVisibleState();
194 if (!__isOpened && visibleState)
197 __isInitialized = true;
198 result r = _ControlManager::GetInstance()->OpenWindow(*this, drawAndShow);
200 if (__type != _WINDOW_TYPE_VE)
202 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
203 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
204 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
218 if (__type != _WINDOW_TYPE_VE)
220 bool visibleState = GetVisibleState();
221 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
222 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
223 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
226 _ControlManager::GetInstance()->CloseWindow(*this);
232 _Window::GetOwner(void) const
239 _Window::SetOwner(_Control* pOwner)
245 if (__type != _WINDOW_TYPE_VE)
247 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
250 if (__transient == true)
252 pEcoreEvas->SetOwner(*this, *pOwner);
260 if (pOwner == __pOwner)
265 _VisualElement* pVE = GetVisualElement();
269 __pOwner->DetachOwnee(*this);
271 if (__type == _WINDOW_TYPE_VE)
273 _Window* pRootWindow = __pOwner->GetRootWindow();
276 _RootVisualElement* pRootVE = pRootWindow->GetRootVisualElement();
279 pRootVE->DetachChild(*pVE);
287 pOwner->AttachOwnee(*this);
289 if (__type == _WINDOW_TYPE_VE)
291 _Window* pRootWindow = pOwner->GetRootWindow();
294 _RootVisualElement* pRootVE = pRootWindow->GetRootVisualElement();
297 pRootVE->AttachChild(*pVE);
303 _Control* pOldOwner = __pOwner;
305 GetWindowDelegate().OnOwnerChanged(pOldOwner);
309 _Window::CreateRootVisualElement(_WindowType windowType)
313 if (__type == _WINDOW_TYPE_VE)
318 result r = CreateLayer();
319 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
321 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
322 SysAssert(pEcoreEvas);
323 __rotation = pEcoreEvas->GetWindowRotation(*this);
324 pEcoreEvas->RegisterWindowStateCallback(*this);
326 // Get visual element.
327 _VisualElement* pVisualElement = GetVisualElement();
328 SysAssert(pVisualElement);
330 pVisualElement->SetName(L"Window");
331 pVisualElement->SetClipChildrenEnabled(false);
332 pVisualElement->SetRenderOperation(_VisualElement::RENDER_OPERATION_COPY);
334 // Attach visual element to root visual element.
335 __pRootVisualElement->AttachChild(*GetVisualElement());
337 if (__type == _WINDOW_TYPE_MAIN)
339 SysLog(NID_UI, "[WM ROTATION][WIN 0x%x, BASIC] Create.", GetNativeHandle());
343 pEcoreEvas->SetWindowType(*this, _WINDOW_TYPE_SUB);
344 SysLog(NID_UI, "[WM ROTATION][WIN 0x%x, UTILITY] Create.", GetNativeHandle());
351 _Window::CreateLayer(void)
353 _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
354 SysAssert(pDisplayManager);
356 if (__type == _WINDOW_TYPE_MAIN)
358 __pLayer = _NativeLayer::CreateInstanceN();
362 __pLayer = _NativeLayer::CreateInstanceN(false);
366 __pRootVisualElement = __pLayer->GetRootVisualElement();
368 _EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
373 ecore_x_window_size_get(ecore_x_window_root_get((Ecore_X_Window)ecore_evas_window_get(pLayer->GetEcoreEvas())), &rootWindowW, &rootWindowH);
375 pLayer->SetBounds(FloatRectangle(0.0f, 0.0f, (float)rootWindowW, (float)rootWindowH));
376 pLayer->SetOpacity(0);
378 __pRootVisualElement->SetName(L"Root");
380 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
384 String appName = _AppInfo::GetAppName();
387 pEcoreEvas->SetWindowName(*this, osp);
394 _Window::SetActivationEnabled(bool enable)
396 if (__type == _WINDOW_TYPE_VE)
398 SetFocusable(enable);
402 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
403 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
405 pEcoreEvas->SetWindowActivationEnabled(*GetRootWindow(), enable);
407 SetLastResult(E_SUCCESS);
411 _Window::IsActivationEnabled(void)
413 if (__type == _WINDOW_TYPE_VE || IsSystemWindow())
415 return IsFocusable();
418 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
419 SysTryReturn(NID_UI, pEcoreEvas, true, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
421 bool enable = pEcoreEvas->IsWindowActivationEnabled(*GetRootWindow());
423 SetLastResult(E_SUCCESS);
429 _Window::SetNativeWindowActivated(bool activated)
431 __nativeWindowActivated = activated;
435 _Window::GetNativeWindowActivated(void)
437 return __nativeWindowActivated;
441 _Window::GetRootVisualElement(void) const
443 return __pRootVisualElement;
447 _Window::GetNativeHandle(void) const
449 if (__type == _WINDOW_TYPE_VE)
454 _RootVisualElement* pRootVE = GetRootVisualElement();
457 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
460 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
461 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
467 _Window::OnActivated(void)
469 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
470 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
472 _Control* focusedControl = GetCurrentFocusControl();
476 focusedControl->SetFocused();
484 if (!isFrameActivated)
489 _TouchManager* pTouchMgr = _TouchManager::GetInstance();
492 pTouchMgr->SetTouchCanceled(null);
497 _Window::OnNativeWindowActivated(void)
503 _Window::OnFocusableStateChanged(bool focusalbeState)
505 if (__type == _WINDOW_TYPE_VE)
510 SetActivationEnabled(focusalbeState);
514 _Window::OnNotifiedN(const _Control& source, IList* pArgs)
516 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
518 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
519 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
521 if (*pType == L"VisibilityEvent")
525 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
526 if (pObscured == null)
528 pArgs->RemoveAll(true);
534 obscured = pObscured->ToInt();
537 SetNativeWindowActivated(true);
538 GetWindowDelegate().OnNativeWindowActivated();
542 SetNativeWindowActivated(false);
545 pArgs->RemoveAll(true);
555 _Window::OnDeactivated(void)
557 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
558 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
562 _Window::OnOwnerChanged(_Control* pOldOwner)
568 _Window::OnBoundsChanging(const FloatRectangle& bounds)
570 if (__type == _WINDOW_TYPE_VE)
575 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
576 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
578 pEcoreEvas->SetWindowBounds(*GetRootWindow(), bounds);
579 result r = GetLastResult();
580 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
586 _Window::OnVisibleStateChanged(void)
590 bool visibleState = GetVisibleState();
591 if (visibleState == false)
594 if(unlikely((_AccessibilityManager::IsActivated())))
596 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
600 result r = GetLastResult();
601 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
603 SetLastResult(E_SUCCESS);
607 _Window::OnAttachingToMainTree(const _Control* pParent)
609 if (__type == _WINDOW_TYPE_VE)
614 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
616 SetVisibleState(true);
617 pLayer->SetShowState(true);
623 _Window::OnDetachingFromMainTree(void)
625 if (__type == _WINDOW_TYPE_VE)
630 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
632 pLayer->SetShowState(false);
638 _Window::OnWindowStateChanged(void)
644 // Call UpdateOrientation
646 // Find current frame
647 // Call UpdateOrientation
653 SetOrientationCallbackModeEnabled(true);
654 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
660 int rotation = pEcoreEvas->GetWindowRotation(*this);
662 Rectangle winBounds = GetBounds();
663 SysLog(NID_UI, "[WM ROTATION][WIN 0x%x, %d, %d, %d, %d] OnWindowStateChanged : prev ROT %d, cur ROT %d", GetNativeHandle(), winBounds.x, winBounds.y, winBounds.width, winBounds.height, __rotation, rotation);
665 if (rotation == __rotation)
670 __rotation = rotation;
673 int childCount = GetChildCount();
674 for (int i = childCount; i > 0; i--)
676 _Control* pChild = GetChild(i - 1);
678 _Form* pForm = dynamic_cast<_Form*>(pChild);
681 if (pForm->IsVisible())
684 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pForm->GetUserData());
687 pFormImpl->UpdateOrientation();
696 if (IsOrientationRoot())
698 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
701 pFrameImpl->UpdateOrientation();
708 SysLog(NID_UI, "[WM ROTATION] ---------- Update Ownee Window : START ----------");
710 _ControlOrientation controlOrientation = (rotation == 0 || rotation == 180) ? _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
711 ChangeLayout(controlOrientation, false);
713 _ControlRotation controlRotation = _CONTROL_ROTATION_0;
717 controlRotation = _CONTROL_ROTATION_0;
720 controlRotation = _CONTROL_ROTATION_90;
723 controlRotation = _CONTROL_ROTATION_180;
726 controlRotation = _CONTROL_ROTATION_270;
731 ChangeLayout(controlRotation);
733 pEcoreEvas->RotateWindow(*this, __rotation, false);
737 SysLog(NID_UI, "[WM ROTATION] ---------- Update Ownee Window : END ----------");
738 SetOrientationCallbackModeEnabled(false);
742 _Window::OnTouchCaptureGained(void)
748 _Window::OnTouchCaptureLost(void)
753 _Window::SetPreferredRotation(bool enable)
755 __preferredRotation = enable;
759 _Window::GetPreferredRotation(void) const
761 return __preferredRotation;
765 _Window::IsRotationSynchronized(void) const
771 _Window::IsLayoutChangable(void) const
773 if (__type == _WINDOW_TYPE_VE)
782 _Window::SetRotation(int rotation)
784 __rotation = rotation;
788 _Window::GetWindowType(void)
794 _Window::OnChangeLayout(_ControlOrientation orientation)
796 _DimmingLayer *pLayer = GetDimmingLayer();
799 result r = GetDimmingLayer()->Rearrange();
800 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
803 // if window, change its size specially for full-screen(Form, Frame, etc.).
804 _Control::OnChangeLayout(orientation); // if called, layout will be changed.
808 _Window::GetWindowState(void) const
811 return __windowState;
815 _Window::SetWindowState(WindowState windowState)
817 __windowState = windowState;
821 _Window::GetDisplayContext(void) const
823 if (!__pDisplayContext)
825 SysTryReturn(NID_UI, __pLayer, null, E_SYSTEM, "[E_SYSTEM] Cannot gain the DisplayContext. This window is not completed.");
827 __pDisplayContext = _DisplayContextImpl::CreatePublicInstance(*__pLayer);
830 result r = GetLastResult();
831 SysTryReturn(NID_UI, __pDisplayContext, null, r, "[%s] Propagating.", GetErrorMessage(r));
833 return __pDisplayContext;
837 _Window::SetZOrderGroup(int windowZOrderGroup)
839 if (__type == _WINDOW_TYPE_VE)
844 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
846 if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_HIGHEST)
848 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NOTIFICATION_HIGH);
850 else if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_HIGH)
852 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NOTIFICATION_MIDDLE);
854 else if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_NORMAL)
856 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NORMAL);
861 bool visible = pEcoreEvas->IsWindowVisible(*this);
862 bool activationEnabled = pEcoreEvas->IsWindowActivationEnabled(*this);
864 if ((visible == true) && (activationEnabled == true))
866 pEcoreEvas->ActivateWindow(*this);
873 : __type(_WINDOW_TYPE_MAIN)
874 , __windowState(WINDOW_STATE_INITIALIZED)
876 , __pWindowDelegate(null)
878 , __destroying(false)
879 , __pRootVisualElement(null)
881 , __pDimmingLayer(null)
882 , __pDisplayContext(null)
883 , __systemWindow(false)
885 , __isInitialized(false)
886 , __pFocusControl(null)
887 , __pFocusTraversalControl(null)
889 , __dimmingEnabled(false)
891 , __preferredRotation(false)
892 , __orientationCallbackMode(false)
893 , __nativeWindowActivated(false)
895 SetControlDelegate(*this);
896 SetWindowDelegate(*this);
897 SetClipToParent(false); // [ToDo] exception check.
901 _Window::Activate(void)
909 GetWindowDelegate().OnActivated();
913 _Window::Deactivate(void)
917 if (__destroying == false)
919 GetWindowDelegate().OnDeactivated();
924 _Window::SetSystemWindow(bool systemWindow)
926 __systemWindow = systemWindow;
930 _Window::IsSystemWindow(void) const
932 return __systemWindow;
936 _Window::GetFocusList(void) const
938 if(!__pFocusControlList)
940 __pFocusControlList.reset(GetFocusListN());
941 __pFocusControlList->InsertAt(const_cast<_Window*>(this), 0);
943 return __pFocusControlList.get();
947 _Window::ResetFocusList(void)
949 if(__pFocusControlList)
951 __pFocusControlList.reset();
956 _Window::SetDimmingEnabled(bool enabled)
958 __dimmingEnabled = enabled;
964 _Window::IsDimmingEnabled(void) const
966 return __dimmingEnabled;
970 _Window::SetDimmingLayer(_DimmingLayer* pLayer)
972 __pDimmingLayer = pLayer;
976 _Window::GetDimmingLayer(void)
978 return __pDimmingLayer;
982 _Window::SetOrientationCallbackModeEnabled(bool enable)
984 __orientationCallbackMode = enable;
988 _Window::IsOrientationCallbackModeEnabled(void) const
990 return __orientationCallbackMode;
994 _Window::GetFocusTraversalControl(_Control* pControl) const
996 return __pFocusTraversalControl;
1000 _Window::SetFocusTraversalControl(_Control* pControl, bool on)
1004 __pFocusTraversalControl = pControl;
1008 __pFocusTraversalControl = this;
1013 _Window:: SetFocusControl(const _Control* pControl, bool on)
1015 SysTryReturnVoidResult(NID_UI, pControl, E_SYSTEM, "[E_SYSTEM] The pControl cannot be NULL.");
1017 __pFocusControl = const_cast<_Control*>(pControl);
1019 _ControlManager* pControlMgr = _ControlManager::GetInstance();
1020 SysAssert(pControlMgr);
1026 pControlMgr->SetFocusControl(*pControl);
1031 pControlMgr->SetFocusControl(*this, false);
1037 _Window::GetFocusControl(const _Control* pControl) const
1039 return __pFocusControl;
1042 _Window::GetCurrentFocusControl(void) const
1044 return __pFocusControl;