2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #if !defined(WINDOW_BASE_ROTATE)
271 pEcoreEvas->SetWindowOrientationEnabled(*this, false);
273 __rotation = pEcoreEvas->GetWindowRotation(*this);
274 pEcoreEvas->RegisterWindowStateCallback(*this);
277 // Get visual element.
278 _VisualElement* pVisualElement = GetVisualElement();
279 SysAssert(pVisualElement);
281 pVisualElement->SetName(L"Window");
282 pVisualElement->SetClipChildrenEnabled(false);
283 pVisualElement->SetRenderOperation(_VisualElement::RENDER_OPERATION_COPY);
285 // Attach visual element to root visual element.
286 __pRootVisualElement->AttachChild(*GetVisualElement());
288 #if defined(WINDOW_BASE_ROTATE)
289 if (__type == _WINDOW_TYPE_MAIN)
291 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x, BASIC] Create.", GetNativeHandle());
295 pEcoreEvas->SetWindowType(*this, _WINDOW_TYPE_SUB);
296 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x, UTILITY] Create.", GetNativeHandle());
304 _Window::CreateLayer(void)
306 _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
307 SysAssert(pDisplayManager);
309 if (__type == _WINDOW_TYPE_MAIN)
311 __pLayer = _NativeLayer::CreateInstanceN();
315 __pLayer = _NativeLayer::CreateInstanceN(false);
319 __pRootVisualElement = __pLayer->GetRootVisualElement();
321 _EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
326 ecore_x_window_size_get(ecore_x_window_root_get((Ecore_X_Window)ecore_evas_window_get(pLayer->GetEcoreEvas())), &rootWindowW, &rootWindowH);
328 pLayer->SetBounds(FloatRectangle(0.0f, 0.0f, (float)rootWindowW, (float)rootWindowH));
329 pLayer->SetOpacity(0);
331 __pRootVisualElement->SetName(L"Root");
337 _Window::IsFocusableDescendant(const _Control* pFocus) const
343 _Window::SetActivationEnabled(bool enable)
345 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
346 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
348 pEcoreEvas->SetWindowActivationEnabled(*GetRootWindow(), enable);
350 SetLastResult(E_SUCCESS);
354 _Window::IsActivationEnabled(void)
356 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
357 SysTryReturn(NID_UI, pEcoreEvas, true, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
359 bool enable = pEcoreEvas->IsWindowActivationEnabled(*GetRootWindow());
361 SetLastResult(E_SUCCESS);
366 #if !defined(WINDOW_BASE_ROTATE)
368 _Window::SetOrientationEnabled(bool enable)
370 __orientationEnabled = enable;
374 _Window::IsOrientationEnabled(void)
376 return __orientationEnabled;
381 _Window::GetRootVisualElement(void) const
383 return __pRootVisualElement;
387 _Window::GetNativeHandle(void) const
389 _RootVisualElement* pRootVE = GetRootVisualElement();
392 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
395 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
396 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
402 _Window::OnActivated(void)
404 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
405 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
407 _Control* focusedControl = GetFocusedControl();
411 focusedControl->SetFocused();
414 if (!isFrameActivated)
419 _Control* pFocus = GetFocused();
422 pFocus->SetFocused();
429 _TouchManager* pTouchMgr = _TouchManager::GetInstance();
432 pTouchMgr->SetTouchCanceled(null);
437 _Window::OnNativeWindowActivated(void)
443 _Window::OnNotifiedN(const _Control& source, IList* pArgs)
445 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
447 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
448 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
450 if (*pType == L"VisibilityEvent")
454 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
455 if (pObscured == null)
457 pArgs->RemoveAll(true);
463 obscured = pObscured->ToInt();
466 GetWindowDelegate().OnNativeWindowActivated();
469 pArgs->RemoveAll(true);
479 _Window::OnDeactivated(void)
481 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
482 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
486 _Window::OnOwnerChanged(_Control* pOldOwner)
492 _Window::OnBoundsChanging(const FloatRectangle& bounds)
494 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
495 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
497 pEcoreEvas->SetWindowBounds(*GetRootWindow(), bounds);
498 result r = GetLastResult();
499 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
505 _Window::OnVisibleStateChanged(void)
509 bool visibleState = GetVisibleState();
510 if (visibleState == false)
515 result r = GetLastResult();
516 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
518 SetLastResult(E_SUCCESS);
522 _Window::OnAttachingToMainTree(const _Control* pParent)
524 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
526 SetVisibleState(true);
527 pLayer->SetShowState(true);
533 _Window::OnDetachingFromMainTree(void)
535 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
537 pLayer->SetShowState(false);
542 #if defined(WINDOW_BASE_ROTATE)
544 _Window::OnWindowStateChanged(void)
550 // Call UpdateOrientation
552 // Find current frame
553 // Call UpdateOrientation
559 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
565 int rotation = pEcoreEvas->GetWindowRotation(*this);
567 Rectangle winBounds = GetBounds();
568 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);
570 if (rotation == __rotation)
575 __rotation = rotation;
578 int childCount = GetChildCount();
579 for (int i = childCount; i > 0; i--)
581 _Control* pChild = GetChild(i - 1);
583 _Form* pForm = dynamic_cast<_Form*>(pChild);
586 if (pForm->IsVisible())
589 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pForm->GetUserData());
592 pFormImpl->UpdateOrientation();
601 if (IsOrientationRoot())
603 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
606 pFrameImpl->UpdateOrientation();
613 SysLog(NID_UI, "[Window Manager Rotation] ---------- Update Ownee Window : START ----------");
615 _ControlOrientation controlOrientation = (rotation == 0 || rotation == 180) ? _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
616 ChangeLayout(controlOrientation);
618 pEcoreEvas->RotateWindow(*this, __rotation);
622 SysLog(NID_UI, "[Window Manager Rotation] ---------- Update Ownee Window : END ----------");
626 _Window::SetPreferredRotation(bool enable)
628 __preferredRotation = enable;
632 _Window::GetPreferredRotation(void) const
634 return __preferredRotation;
637 #if defined(WINDOW_OWNEE_PREFERRED)
639 _Window::IsRotationSynchronized(void) const
647 _Window::IsLayoutChangable(void) const
652 #if defined(WINDOW_BASE_ROTATE)
654 _Window::SetRotation(int rotation)
656 __rotation = rotation;
661 _Window::OnChangeLayout(_ControlOrientation orientation)
663 _DimmingLayer *pLayer = GetDimmingLayer();
666 result r = GetDimmingLayer()->Rearrange();
667 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
670 // if window, change its size specially for full-screen(Form, Frame, etc.).
671 _Control::OnChangeLayout(orientation); // if called, layout will be changed.
675 _Window::GetWindowState(void) const
678 return __windowState;
682 _Window::SetWindowState(WindowState windowState)
684 __windowState = windowState;
688 _Window::GetDisplayContext(void) const
690 if (!__pDisplayContext)
692 SysTryReturn(NID_UI, __pLayer, null, E_SYSTEM, "[E_SYSTEM] Cannot gain the DisplayContext. This window is not completed.");
694 __pDisplayContext = _DisplayContextImpl::CreatePublicInstance(*__pLayer);
697 result r = GetLastResult();
698 SysTryReturn(NID_UI, __pDisplayContext, null, r, "[%s] Propagating.", GetErrorMessage(r));
700 return __pDisplayContext;
704 _Window::SetZOrderGroup(int windowZOrderGroup)
706 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
708 if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_HIGHEST)
710 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NOTIFICATION_HIGH);
712 else if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_HIGH)
714 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NOTIFICATION_MIDDLE);
716 else if (windowZOrderGroup == WINDOW_Z_ORDER_GROUP_NORMAL)
718 pEcoreEvas->SetWindowLevel(*this, _WINDOW_LEVEL_NORMAL);
723 bool visible = pEcoreEvas->IsWindowVisible(*this);
724 bool activationEnabled = pEcoreEvas->IsWindowActivationEnabled(*this);
726 if ((visible == true) && (activationEnabled == true))
728 pEcoreEvas->ActivateWindow(*this);
735 : __type(_WINDOW_TYPE_MAIN)
736 , __windowState(WINDOW_STATE_INITIALIZED)
738 , __pWindowDelegate(null)
740 , __destroying(false)
741 , __pRootVisualElement(null)
743 , __pDimmingLayer(null)
744 , __pDisplayContext(null)
745 , __systemWindow(false)
747 , __isInitialized(false)
748 , __pFocusedControl(null)
750 , __dimmingEnabled(false)
751 #if !defined(WINDOW_BASE_ROTATE)
752 , __orientationEnabled(false)
754 #if !defined(WINDOW_OWNEE_PREFERRED)
759 , __preferredRotation(false)
762 SetControlDelegate(*this);
763 SetWindowDelegate(*this);
764 SetClipToParent(false); // [ToDo] exception check.
768 _Window::Activate(void)
776 GetWindowDelegate().OnActivated();
780 _Window::Deactivate(void)
784 if (__destroying == false)
786 GetWindowDelegate().OnDeactivated();
791 _Window::SetSystemWindow(bool systemWindow)
793 __systemWindow = systemWindow;
797 _Window::IsSystemWindow(void) const
799 return __systemWindow;
803 _Window::SetFocusedControl(const _Control* pControl)
805 __pFocusedControl = const_cast<_Control*>(pControl);
809 _Window::GetFocusedControl(void) const
811 return __pFocusedControl;
815 _Window::GetFocusList(void) const
817 if(!__pFocusControlList)
819 __pFocusControlList.reset(GetFocusListN());
820 __pFocusControlList->InsertAt(const_cast<_Window*>(this), 0);
822 return __pFocusControlList.get();
826 _Window::ResetFocusList(void)
828 if(__pFocusControlList)
830 __pFocusControlList.reset();
835 _Window::SetDimmingEnabled(bool enabled)
837 __dimmingEnabled = enabled;
843 _Window::IsDimmingEnabled(void) const
845 return __dimmingEnabled;
849 _Window::SetDimmingLayer(_DimmingLayer* pLayer)
851 __pDimmingLayer = pLayer;
855 _Window::GetDimmingLayer(void)
857 return __pDimmingLayer;