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 "FUi_Window.h"
29 #include "FUi_ControlManager.h"
30 #include "FUi_TouchManager.h"
31 #include "FUiAnim_DisplayContextImpl.h"
32 #include "FUiAnim_RootVisualElement.h"
33 #include "FUiAnim_VisualElement.h"
34 #include "FUi_EcoreEvasMgr.h"
35 #include "FUi_EcoreEvas.h"
36 #include "FUiAnim_DisplayManager.h"
37 #include "FUiAnim_EflLayer.h"
38 #include "FUiCtrl_Form.h"
39 #include "FUiCtrl_FormImpl.h"
40 #include "FUiCtrl_FrameImpl.h"
42 using namespace Tizen::Base;
43 using namespace Tizen::Base::Collection;
44 using namespace Tizen::Graphics;
45 using namespace Tizen::Ui::Animations;
46 using namespace Tizen::Ui::Controls;
48 namespace Tizen { namespace Ui
52 _Window::CreateWindowN(void)
54 _Window* pWindow = new (std::nothrow) _Window;
55 SysTryReturn(NID_UI, pWindow, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
59 if (IsFailed(GetLastResult()))
64 r = pWindow->CreateRootVisualElement();
65 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
67 pWindow->AcquireHandle();
76 _Window::~_Window(void)
82 if (__pDisplayContext)
84 _DisplayContextImpl::DestroyPublicInstance(*__pDisplayContext);
85 __pDisplayContext = null;
90 //_EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
91 //Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
92 //SysLog(NID_UI, "[Multi_Window] destroy x window(0x%x)", win);
94 if(__pRootVisualElement)
96 __pRootVisualElement->DetachChild(*GetVisualElement());
102 delete __pDimmingLayer;
103 __pDimmingLayer = null;
105 __pRootVisualElement =NULL;
109 _Window::GetWindowDelegate(void) const
113 return const_cast<_Window&>(*this);
116 SysAssert(__pWindowDelegate);
117 return *__pWindowDelegate;
121 _Window::GetDescription(void) const
123 String description = _Control::GetDescription();
124 String descriptionTemp(L"");
126 descriptionTemp.Format(LOG_LEN_MAX, L"_Window: xid(0x%x) owner(0x%x) delegate(0x%x) activated(%d) destroying(%d) displayContext(0x%x)",
127 GetNativeHandle(), __pOwner, __pWindowDelegate, __activated, __destroying, __pDisplayContext);
129 description.Append(descriptionTemp);
135 _Window::SetRootVisualElement(const Tizen::Ui::Animations::_RootVisualElement& rootVisualElement)
137 _RootVisualElement* pRootVE = const_cast<_RootVisualElement*>(&rootVisualElement);
139 __pRootVisualElement = pRootVE;
143 _Window::SetLayer(const Tizen::Ui::Animations::_NativeLayer& layer)
145 _NativeLayer* pLayer = const_cast<_NativeLayer*>(&layer);
151 _Window::IsActivatedOnOpen(void) const
157 _Window::IsActivated(void) const
163 _Window::SetWindowDelegate(_IWindowDelegate& delegate)
166 __pWindowDelegate = &delegate;
170 _Window::ResetWindowDelegate(void)
173 __pWindowDelegate = this;
177 _Window::IsAttached(void) const
179 return _ControlManager::GetInstance()->IsWindowAttached(*this);
183 _Window::Open(bool drawAndShow)
185 bool visibleState = GetVisibleState();
186 if (!__isOpened && visibleState)
188 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
189 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
190 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
192 __isInitialized = true;
193 return _ControlManager::GetInstance()->OpenWindow(*this, drawAndShow);
204 bool visibleState = GetVisibleState();
205 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
206 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
207 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
209 _ControlManager::GetInstance()->CloseWindow(*this);
215 _Window::GetOwner(void) const
222 _Window::SetOwner(_Control* pOwner)
228 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
231 if (__transient == true)
233 pEcoreEvas->SetOwner(*this, *pOwner);
240 if (pOwner == __pOwner)
247 __pOwner->DetachOwnee(*this);
252 pOwner->AttachOwnee(*this);
255 _Control* pOldOwner = __pOwner;
257 GetWindowDelegate().OnOwnerChanged(pOldOwner);
261 _Window::CreateRootVisualElement(_WindowType windowType)
265 result r = CreateLayer();
266 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
268 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
269 SysAssert(pEcoreEvas);
270 __rotation = pEcoreEvas->GetWindowRotation(*this);
271 pEcoreEvas->RegisterWindowStateCallback(*this);
273 // Get visual element.
274 _VisualElement* pVisualElement = GetVisualElement();
275 SysAssert(pVisualElement);
277 pVisualElement->SetName(L"Window");
278 pVisualElement->SetClipChildrenEnabled(false);
279 pVisualElement->SetRenderOperation(_VisualElement::RENDER_OPERATION_COPY);
281 // Attach visual element to root visual element.
282 __pRootVisualElement->AttachChild(*GetVisualElement());
284 if (__type == _WINDOW_TYPE_MAIN)
286 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x, BASIC] Create.", GetNativeHandle());
290 pEcoreEvas->SetWindowType(*this, _WINDOW_TYPE_SUB);
291 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x, UTILITY] Create.", GetNativeHandle());
298 _Window::CreateLayer(void)
300 _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
301 SysAssert(pDisplayManager);
303 if (__type == _WINDOW_TYPE_MAIN)
305 __pLayer = _NativeLayer::CreateInstanceN();
309 __pLayer = _NativeLayer::CreateInstanceN(false);
313 __pRootVisualElement = __pLayer->GetRootVisualElement();
315 _EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
320 ecore_x_window_size_get(ecore_x_window_root_get((Ecore_X_Window)ecore_evas_window_get(pLayer->GetEcoreEvas())), &rootWindowW, &rootWindowH);
322 pLayer->SetBounds(FloatRectangle(0.0f, 0.0f, (float)rootWindowW, (float)rootWindowH));
323 pLayer->SetOpacity(0);
325 __pRootVisualElement->SetName(L"Root");
331 _Window::IsFocusableDescendant(const _Control* pFocus) const
337 _Window::SetActivationEnabled(bool enable)
339 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
340 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
342 pEcoreEvas->SetWindowActivationEnabled(*GetRootWindow(), enable);
344 SetLastResult(E_SUCCESS);
348 _Window::IsActivationEnabled(void)
350 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
351 SysTryReturn(NID_UI, pEcoreEvas, true, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
353 bool enable = pEcoreEvas->IsWindowActivationEnabled(*GetRootWindow());
355 SetLastResult(E_SUCCESS);
361 _Window::GetRootVisualElement(void) const
363 return __pRootVisualElement;
367 _Window::GetNativeHandle(void) const
369 _RootVisualElement* pRootVE = GetRootVisualElement();
372 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
375 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
376 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
382 _Window::OnActivated(void)
384 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
385 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
387 _Control* focusedControl = GetFocusedControl();
391 focusedControl->SetFocused();
394 if (!isFrameActivated)
399 _Control* pFocus = GetFocused();
402 pFocus->SetFocused();
409 _TouchManager* pTouchMgr = _TouchManager::GetInstance();
412 pTouchMgr->SetTouchCanceled(null);
417 _Window::OnNativeWindowActivated(void)
423 _Window::OnFocusableStateChanged(bool focusalbeState)
425 SetActivationEnabled(focusalbeState);
430 _Window::OnNotifiedN(const _Control& source, IList* pArgs)
432 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
434 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
435 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
437 if (*pType == L"VisibilityEvent")
441 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
442 if (pObscured == null)
444 pArgs->RemoveAll(true);
450 obscured = pObscured->ToInt();
453 GetWindowDelegate().OnNativeWindowActivated();
456 pArgs->RemoveAll(true);
466 _Window::OnDeactivated(void)
468 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
469 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
473 _Window::OnOwnerChanged(_Control* pOldOwner)
479 _Window::OnBoundsChanging(const FloatRectangle& bounds)
481 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
482 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
484 pEcoreEvas->SetWindowBounds(*GetRootWindow(), bounds);
485 result r = GetLastResult();
486 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
492 _Window::OnVisibleStateChanged(void)
496 bool visibleState = GetVisibleState();
497 if (visibleState == false)
502 result r = GetLastResult();
503 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
505 SetLastResult(E_SUCCESS);
509 _Window::OnAttachingToMainTree(const _Control* pParent)
511 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
513 SetVisibleState(true);
514 pLayer->SetShowState(true);
520 _Window::OnDetachingFromMainTree(void)
522 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
524 pLayer->SetShowState(false);
530 _Window::OnWindowStateChanged(void)
536 // Call UpdateOrientation
538 // Find current frame
539 // Call UpdateOrientation
545 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
551 int rotation = pEcoreEvas->GetWindowRotation(*this);
553 Rectangle winBounds = GetBounds();
554 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);
556 if (rotation == __rotation)
561 __rotation = rotation;
564 int childCount = GetChildCount();
565 for (int i = childCount; i > 0; i--)
567 _Control* pChild = GetChild(i - 1);
569 _Form* pForm = dynamic_cast<_Form*>(pChild);
572 if (pForm->IsVisible())
575 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pForm->GetUserData());
578 pFormImpl->UpdateOrientation();
587 if (IsOrientationRoot())
589 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
592 pFrameImpl->UpdateOrientation();
599 SysLog(NID_UI, "[Window Manager Rotation] ---------- Update Ownee Window : START ----------");
601 _ControlOrientation controlOrientation = (rotation == 0 || rotation == 180) ? _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
602 ChangeLayout(controlOrientation);
604 pEcoreEvas->RotateWindow(*this, __rotation, false);
608 SysLog(NID_UI, "[Window Manager Rotation] ---------- Update Ownee Window : END ----------");
612 _Window::SetPreferredRotation(bool enable)
614 __preferredRotation = enable;
618 _Window::GetPreferredRotation(void) const
620 return __preferredRotation;
624 _Window::IsRotationSynchronized(void) const
630 _Window::IsLayoutChangable(void) const
636 _Window::SetRotation(int rotation)
638 __rotation = rotation;
642 _Window::OnChangeLayout(_ControlOrientation orientation)
644 _DimmingLayer *pLayer = GetDimmingLayer();
647 result r = GetDimmingLayer()->Rearrange();
648 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
651 // if window, change its size specially for full-screen(Form, Frame, etc.).
652 _Control::OnChangeLayout(orientation); // if called, layout will be changed.
656 _Window::GetWindowState(void) const
659 return __windowState;
663 _Window::SetWindowState(WindowState windowState)
665 __windowState = windowState;
669 _Window::GetDisplayContext(void) const
671 if (!__pDisplayContext)
673 SysTryReturn(NID_UI, __pLayer, null, E_SYSTEM, "[E_SYSTEM] Cannot gain the DisplayContext. This window is not completed.");
675 __pDisplayContext = _DisplayContextImpl::CreatePublicInstance(*__pLayer);
678 result r = GetLastResult();
679 SysTryReturn(NID_UI, __pDisplayContext, null, r, "[%s] Propagating.", GetErrorMessage(r));
681 return __pDisplayContext;
685 _Window::SetZOrderGroup(int windowZOrderGroup)
687 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
689 if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_HIGHEST)
691 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NOTIFICATION_HIGH);
693 else if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_HIGH)
695 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NOTIFICATION_MIDDLE);
697 else if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_NORMAL)
699 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NORMAL);
704 bool visible = pEcoreEvas->IsWindowVisible(*this);
705 bool activationEnabled = pEcoreEvas->IsWindowActivationEnabled(*this);
707 if ((visible == true) && (activationEnabled == true))
709 pEcoreEvas->ActivateWindow(*this);
716 : __type(_WINDOW_TYPE_MAIN)
717 , __windowState(WINDOW_STATE_INITIALIZED)
719 , __pWindowDelegate(null)
721 , __destroying(false)
722 , __pRootVisualElement(null)
724 , __pDimmingLayer(null)
725 , __pDisplayContext(null)
726 , __systemWindow(false)
728 , __isInitialized(false)
729 , __pFocusedControl(null)
731 , __dimmingEnabled(false)
733 , __preferredRotation(false)
734 , __orientationCallbackMode(false)
736 SetControlDelegate(*this);
737 SetWindowDelegate(*this);
738 SetClipToParent(false); // [ToDo] exception check.
742 _Window::Activate(void)
750 GetWindowDelegate().OnActivated();
754 _Window::Deactivate(void)
758 if (__destroying == false)
760 GetWindowDelegate().OnDeactivated();
765 _Window::SetSystemWindow(bool systemWindow)
767 __systemWindow = systemWindow;
771 _Window::IsSystemWindow(void) const
773 return __systemWindow;
777 _Window::SetFocusedControl(const _Control* pControl)
779 __pFocusedControl = const_cast<_Control*>(pControl);
783 _Window::GetFocusedControl(void) const
785 return __pFocusedControl;
789 _Window::GetFocusList(void) const
791 if(!__pFocusControlList)
793 __pFocusControlList.reset(GetFocusListN());
794 __pFocusControlList->InsertAt(const_cast<_Window*>(this), 0);
796 return __pFocusControlList.get();
800 _Window::ResetFocusList(void)
802 if(__pFocusControlList)
804 __pFocusControlList.reset();
809 _Window::SetDimmingEnabled(bool enabled)
811 __dimmingEnabled = enabled;
817 _Window::IsDimmingEnabled(void) const
819 return __dimmingEnabled;
823 _Window::SetDimmingLayer(_DimmingLayer* pLayer)
825 __pDimmingLayer = pLayer;
829 _Window::GetDimmingLayer(void)
831 return __pDimmingLayer;
835 _Window::SetOrientationCallbackModeEnabled(bool enable)
837 __orientationCallbackMode = enable;
841 _Window::IsOrientationCallbackModeEnabled(void) const
843 return __orientationCallbackMode;