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);
254 GetWindowDelegate().OnOwnerChanged(__pOwner);
259 _Window::CreateRootVisualElement(void)
261 result r = CreateLayer();
262 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
264 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
265 SysAssert(pEcoreEvas);
266 #if !defined(WINDOW_BASE_ROTATE)
267 pEcoreEvas->SetWindowOrientationEnabled(*this, false);
269 __rotation = pEcoreEvas->GetWindowRotation(*this);
270 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 defined(WINDOW_BASE_ROTATE)
285 SysLog(NID_UI, "[Window Manager Rotation][Window : 0x%x] Create.", GetNativeHandle());
292 _Window::CreateLayer(void)
294 _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
295 SysAssert(pDisplayManager);
297 __pLayer = _NativeLayer::CreateInstanceN();
299 __pRootVisualElement = __pLayer->GetRootVisualElement();
301 _EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
306 ecore_x_window_size_get(ecore_x_window_root_get((Ecore_X_Window)ecore_evas_window_get(pLayer->GetEcoreEvas())), &rootWindowW, &rootWindowH);
308 pLayer->SetBounds(FloatRectangle(0.0f, 0.0f, (float)rootWindowW, (float)rootWindowH));
309 pLayer->SetOpacity(0);
311 __pRootVisualElement->SetName(L"Root");
317 _Window::IsFocusableDescendant(const _Control* pFocus) const
323 _Window::SetActivationEnabled(bool enable)
325 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
326 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
328 pEcoreEvas->SetWindowActivationEnabled(*GetRootWindow(), enable);
330 SetLastResult(E_SUCCESS);
334 _Window::IsActivationEnabled(void)
336 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
337 SysTryReturn(NID_UI, pEcoreEvas, true, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
339 bool enable = pEcoreEvas->IsWindowActivationEnabled(*GetRootWindow());
341 SetLastResult(E_SUCCESS);
346 #if !defined(WINDOW_BASE_ROTATE)
348 _Window::SetOrientationEnabled(bool enable)
350 __orientationEnabled = enable;
354 _Window::IsOrientationEnabled(void)
356 return __orientationEnabled;
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(true);
417 _Window::OnNativeWindowActivated(void)
423 _Window::OnNotifiedN(const _Control& source, IList* pArgs)
425 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
427 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
428 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
430 if (*pType == L"VisibilityEvent")
434 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
435 if (pObscured == null)
437 pArgs->RemoveAll(true);
443 obscured = pObscured->ToInt();
446 GetWindowDelegate().OnNativeWindowActivated();
449 pArgs->RemoveAll(true);
459 _Window::OnDeactivated(void)
461 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
462 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
466 _Window::OnOwnerChanged(_Control* pOldOwner)
472 _Window::OnBoundsChanging(const FloatRectangle& bounds)
474 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
475 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
477 pEcoreEvas->SetWindowBounds(*GetRootWindow(), bounds);
478 result r = GetLastResult();
479 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
485 _Window::OnVisibleStateChanged(void)
489 bool visibleState = GetVisibleState();
490 if (visibleState == false)
495 result r = GetLastResult();
496 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
498 SetLastResult(E_SUCCESS);
502 _Window::OnAttachingToMainTree(const _Control* pParent)
504 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
506 SetVisibleState(true);
507 pLayer->SetShowState(true);
513 _Window::OnDetachingFromMainTree(void)
515 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
517 pLayer->SetShowState(false);
522 #if defined(WINDOW_BASE_ROTATE)
524 _Window::OnWindowStateChanged(void)
530 // Call UpdateOrientation
532 // Find current frame
533 // Call UpdateOrientation
539 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
545 int rotation = pEcoreEvas->GetWindowRotation(*this);
547 Rectangle winBounds = GetBounds();
548 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);
550 if (rotation == __rotation)
555 __rotation = rotation;
558 int childCount = GetChildCount();
559 for (int i = childCount; i > 0; i--)
561 _Control* pChild = GetChild(i - 1);
563 _Form* pForm = dynamic_cast<_Form*>(pChild);
566 if (pForm->IsVisible())
569 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pForm->GetUserData());
572 pFormImpl->UpdateOrientation();
581 if (IsOrientationRoot())
583 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
586 pFrameImpl->UpdateOrientation();
593 SysLog(NID_UI, "[Window Manager Rotation] ---------- Update Ownee Window : START ----------");
595 _ControlOrientation controlOrientation = (rotation == 0 || rotation == 180) ? _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
596 ChangeLayout(controlOrientation);
598 pEcoreEvas->RotateWindow(*this, __rotation);
602 SysLog(NID_UI, "[Window Manager Rotation] ---------- Update Ownee Window : END ----------");
606 _Window::SetPreferredRotation(bool enable)
608 __preferredRotation = enable;
612 _Window::GetPreferredRotation(void) const
614 return __preferredRotation;
617 #if defined(WINDOW_OWNEE_PREFERRED)
619 _Window::IsRotationSynchronized(void) const
627 _Window::IsLayoutChangable(void) const
632 #if defined(WINDOW_BASE_ROTATE)
634 _Window::SetRotation(int rotation)
636 __rotation = rotation;
641 _Window::OnChangeLayout(_ControlOrientation orientation)
643 _DimmingLayer *pLayer = GetDimmingLayer();
646 result r = GetDimmingLayer()->Rearrange();
647 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
650 // if window, change its size specially for full-screen(Form, Frame, etc.).
651 _Control::OnChangeLayout(orientation); // if called, layout will be changed.
655 _Window::GetWindowState(void) const
658 return __windowState;
662 _Window::SetWindowState(WindowState windowState)
664 __windowState = windowState;
668 _Window::GetDisplayContext(void) const
670 if (!__pDisplayContext)
672 SysTryReturn(NID_UI, __pLayer, null, E_SYSTEM, "[E_SYSTEM] Cannot gain the DisplayContext. This window is not completed.");
674 __pDisplayContext = _DisplayContextImpl::CreatePublicInstance(*__pLayer);
677 result r = GetLastResult();
678 SysTryReturn(NID_UI, __pDisplayContext, null, r, "[%s] Propagating.", GetErrorMessage(r));
680 return __pDisplayContext;
684 _Window::SetZOrderGroup(int windowZOrderGroup)
688 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
689 bool visible = pEcoreEvas->IsWindowVisible(*this);
690 bool activationEnabled = pEcoreEvas->IsWindowActivationEnabled(*this);
692 if ((visible == true) && (activationEnabled == true))
694 pEcoreEvas->ActivateWindow(*this);
701 : __windowState(WINDOW_STATE_INITIALIZED)
703 , __pWindowDelegate(null)
705 , __destroying(false)
706 , __pRootVisualElement(null)
708 , __pDimmingLayer(null)
709 , __pDisplayContext(null)
710 , __systemWindow(false)
712 , __isInitialized(false)
713 , __pFocusedControl(null)
715 , __dimmingEnabled(false)
716 #if !defined(WINDOW_BASE_ROTATE)
717 , __orientationEnabled(false)
719 #if !defined(WINDOW_OWNEE_PREFERRED)
724 , __preferredRotation(false)
727 SetControlDelegate(*this);
728 SetWindowDelegate(*this);
729 SetClipToParent(false); // [ToDo] exception check.
733 _Window::Activate(void)
741 GetWindowDelegate().OnActivated();
745 _Window::Deactivate(void)
749 if (__destroying == false)
751 GetWindowDelegate().OnDeactivated();
756 _Window::SetSystemWindow(bool systemWindow)
758 __systemWindow = systemWindow;
762 _Window::IsSystemWindow(void) const
764 return __systemWindow;
768 _Window::SetFocusedControl(const _Control* pControl)
770 __pFocusedControl = const_cast<_Control*>(pControl);
774 _Window::GetFocusedControl(void) const
776 return __pFocusedControl;
780 _Window::GetFocusList(void) const
782 if(!__pFocusControlList)
784 __pFocusControlList.reset(GetFocusListN());
785 __pFocusControlList->InsertAt(const_cast<_Window*>(this), 0);
787 return __pFocusControlList.get();
791 _Window::ResetFocusList(void)
793 if(__pFocusControlList)
795 __pFocusControlList.reset();
800 _Window::SetDimmingEnabled(bool enabled)
802 __dimmingEnabled = enabled;
808 _Window::IsDimmingEnabled(void) const
810 return __dimmingEnabled;
814 _Window::SetDimmingLayer(_DimmingLayer* pLayer)
816 __pDimmingLayer = pLayer;
820 _Window::GetDimmingLayer(void)
822 return __pDimmingLayer;