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 "FUi_Window.h"
28 #include "FUi_ControlManager.h"
29 #include "FUi_TouchManager.h"
30 #include "FUiAnim_DisplayContextImpl.h"
31 #include "FUiAnim_RootVisualElement.h"
32 #include "FUiAnim_VisualElement.h"
33 #include "FUi_EcoreEvasMgr.h"
34 #include "FUi_EcoreEvas.h"
35 #include "FUiAnim_DisplayManager.h"
36 #include "FUiAnim_EflLayer.h"
37 #include "FUiCtrl_Form.h"
38 #include "FUiCtrl_FormImpl.h"
39 #include "FUiCtrl_FrameImpl.h"
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Ui::Animations;
45 using namespace Tizen::Ui::Controls;
47 namespace Tizen { namespace Ui
51 _Window::CreateWindowN(void)
53 _Window* pWindow = new (std::nothrow) _Window;
54 SysTryReturn(NID_UI, pWindow, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
58 if (IsFailed(GetLastResult()))
63 r = pWindow->CreateRootVisualElement();
64 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
66 pWindow->AcquireHandle();
75 _Window::~_Window(void)
81 if (__pDisplayContext)
83 _DisplayContextImpl::DestroyPublicInstance(*__pDisplayContext);
84 __pDisplayContext = null;
89 //_EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
90 //Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pLayer->GetEcoreEvas());
91 //SysLog(NID_UI, "[Multi_Window] destroy x window(0x%x)", win);
93 if(__pRootVisualElement)
95 __pRootVisualElement->DetachChild(*GetVisualElement());
101 __pRootVisualElement =NULL;
105 _Window::GetWindowDelegate(void) const
109 return const_cast<_Window&>(*this);
112 SysAssert(__pWindowDelegate);
113 return *__pWindowDelegate;
117 _Window::GetDescription(void) const
119 String description = _Control::GetDescription();
120 String descriptionTemp(L"");
122 descriptionTemp.Format(LOG_LEN_MAX, L"_Window: xid(0x%x) owner(0x%x) delegate(0x%x) activated(%d) destroying(%d) displayContext(0x%x)",
123 GetNativeHandle(), __pOwner, __pWindowDelegate, __activated, __destroying, __pDisplayContext);
125 description.Append(descriptionTemp);
131 _Window::SetRootVisualElement(const Tizen::Ui::Animations::_RootVisualElement& rootVisualElement)
133 _RootVisualElement* pRootVE = const_cast<_RootVisualElement*>(&rootVisualElement);
135 __pRootVisualElement = pRootVE;
139 _Window::SetLayer(const Tizen::Ui::Animations::_NativeLayer& layer)
141 _NativeLayer* pLayer = const_cast<_NativeLayer*>(&layer);
147 _Window::IsActivatedOnOpen(void) const
153 _Window::IsActivated(void) const
159 _Window::SetWindowDelegate(_IWindowDelegate& delegate)
162 __pWindowDelegate = &delegate;
166 _Window::ResetWindowDelegate(void)
169 __pWindowDelegate = this;
173 _Window::IsAttached(void) const
175 return _ControlManager::GetInstance()->IsWindowAttached(*this);
179 _Window::Open(bool drawAndShow)
181 bool visibleState = GetVisibleState();
182 if (!__isOpened && visibleState)
184 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
185 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
186 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
188 __isInitialized = true;
189 return _ControlManager::GetInstance()->OpenWindow(*this, drawAndShow);
200 bool visibleState = GetVisibleState();
201 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
202 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
203 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
205 _ControlManager::GetInstance()->CloseWindow(*this);
211 _Window::GetOwner(void) const
218 _Window::SetOwner(_Control* pOwner)
224 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
227 if (__transient == true)
229 pEcoreEvas->SetOwner(*this, *pOwner);
236 if (pOwner == __pOwner)
243 __pOwner->DetachOwnee(*this);
248 pOwner->AttachOwnee(*this);
250 GetWindowDelegate().OnOwnerChanged(__pOwner);
255 _Window::CreateRootVisualElement(void)
257 result r = CreateLayer();
258 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
260 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
261 SysAssert(pEcoreEvas);
262 #if !defined(WINDOW_BASE_ROTATE)
263 pEcoreEvas->SetWindowOrientationEnabled(*this, false);
265 __rotation = pEcoreEvas->GetWindowRotation(*this);
266 pEcoreEvas->RegisterWindowStateCallback(*this);
269 // Get visual element.
270 _VisualElement* pVisualElement = GetVisualElement();
271 SysAssert(pVisualElement);
273 pVisualElement->SetName(L"Window");
274 pVisualElement->SetClipChildrenEnabled(false);
275 pVisualElement->SetRenderOperation(_VisualElement::RENDER_OPERATION_COPY);
277 // Attach visual element to root visual element.
278 __pRootVisualElement->AttachChild(*GetVisualElement());
284 _Window::CreateLayer(void)
286 _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
287 SysAssert(pDisplayManager);
289 __pLayer = _NativeLayer::CreateInstanceN();
291 __pRootVisualElement = __pLayer->GetRootVisualElement();
293 _EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
298 ecore_x_window_size_get(ecore_x_window_root_get((Ecore_X_Window)ecore_evas_window_get(pLayer->GetEcoreEvas())), &rootWindowW, &rootWindowH);
300 pLayer->SetBounds(FloatRectangle(0.0f, 0.0f, (float)rootWindowW, (float)rootWindowH));
301 pLayer->SetOpacity(0);
303 __pRootVisualElement->SetName(L"Root");
309 _Window::IsFocusableDescendant(const _Control* pFocus) const
315 _Window::SetActivationEnabled(bool enable)
317 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
318 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
320 pEcoreEvas->SetWindowActivationEnabled(*GetRootWindow(), enable);
322 SetLastResult(E_SUCCESS);
326 _Window::IsActivationEnabled(void)
328 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
329 SysTryReturn(NID_UI, pEcoreEvas, true, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
331 bool enable = pEcoreEvas->IsWindowActivationEnabled(*GetRootWindow());
333 SetLastResult(E_SUCCESS);
338 #if !defined(WINDOW_BASE_ROTATE)
340 _Window::SetOrientationEnabled(bool enable)
342 __orientationEnabled = enable;
346 _Window::IsOrientationEnabled(void)
348 return __orientationEnabled;
353 _Window::GetRootVisualElement(void) const
355 return __pRootVisualElement;
359 _Window::GetNativeHandle(void) const
361 _RootVisualElement* pRootVE = GetRootVisualElement();
364 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
367 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
368 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
374 _Window::OnActivated(void)
376 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
377 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
379 _Control* focusedControl = GetFocusedControl();
383 focusedControl->SetFocused();
386 if (!isFrameActivated)
391 _Control* pFocus = GetFocused();
394 pFocus->SetFocused();
401 _TouchManager* pTouchMgr = _TouchManager::GetInstance();
404 pTouchMgr->SetTouchCanceled(true);
409 _Window::OnNativeWindowActivated(void)
415 _Window::OnNotifiedN(const _Control& source, IList* pArgs)
417 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
419 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
420 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
422 if (*pType == L"VisibilityEvent")
426 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
427 if (pObscured == null)
429 pArgs->RemoveAll(true);
435 obscured = pObscured->ToInt();
438 GetWindowDelegate().OnNativeWindowActivated();
441 pArgs->RemoveAll(true);
451 _Window::OnDeactivated(void)
453 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
454 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
458 _Window::OnOwnerChanged(_Control* pOldOwner)
464 _Window::OnBoundsChanging(const Rectangle& bounds)
466 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
467 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
469 pEcoreEvas->SetWindowBounds(*GetRootWindow(), bounds);
470 result r = GetLastResult();
471 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
477 _Window::OnVisibleStateChanged(void)
481 bool visibleState = GetVisibleState();
482 if (visibleState == false)
487 result r = GetLastResult();
488 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
490 SetLastResult(E_SUCCESS);
494 _Window::OnAttachingToMainTree(const _Control* pParent)
496 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
498 SetVisibleState(true);
499 pLayer->SetShowState(true);
505 _Window::OnDetachingFromMainTree(void)
507 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
509 pLayer->SetShowState(false);
514 #if defined(WINDOW_BASE_ROTATE)
516 _Window::OnWindowStateChanged(void)
518 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
524 int rotation = pEcoreEvas->GetWindowRotation(*this);
526 Rectangle bounds = GetBounds();
527 SysLog(NID_UI, "[Window-based Rotation][Window : 0x%x, %d, %d, %d, %d] OnWindowStateChanged is called with prev rotation(__rotation) and cur rotation(rotation)",
528 GetNativeHandle(), bounds.x, bounds.y, bounds.width, bounds.height, __rotation, rotation);
530 if (__rotation != rotation)
532 __rotation = rotation;
534 int childCount = GetChildCount();
535 for (int i = childCount; i > 0; i--)
537 _Control* pChild = GetChild(i - 1);
539 _Form* pForm = dynamic_cast<_Form*>(pChild);
542 if (pForm->IsVisible())
545 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pForm->GetUserData());
548 pFormImpl->UpdateOrientation();
556 if (IsOrientationRoot())
558 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
561 pFrameImpl->UpdateOrientation();
566 _ControlOrientation controlOrientation = (rotation == 0 || rotation == 180) ? _CONTROL_ORIENTATION_PORTRAIT : _CONTROL_ORIENTATION_LANDSCAPE;
567 ChangeLayout(controlOrientation);
568 pEcoreEvas->UpdateWindowBounds(*this);
575 _Window::IsLayoutChangable(void) const
581 _Window::OnChangeLayout(_ControlOrientation orientation)
583 SysLog(NID_UI, "[Test] _Window::OnChangeLayout()");
585 // if window, change its size specially for full-screen(Form, Frame, etc.).
586 _Control::OnChangeLayout(orientation); // if called, layout will be changed.
590 _Window::GetWindowState(void) const
593 return __windowState;
597 _Window::SetWindowState(WindowState windowState)
599 __windowState = windowState;
603 _Window::GetDisplayContext(void) const
605 if (!__pDisplayContext)
607 SysTryReturn(NID_UI, __pLayer, null, E_SYSTEM, "[E_SYSTEM] Cannot gain the DisplayContext. This window is not completed.");
609 __pDisplayContext = _DisplayContextImpl::CreatePublicInstance(*__pLayer);
612 result r = GetLastResult();
613 SysTryReturn(NID_UI, __pDisplayContext, null, r, "[%s] Propagating.", GetErrorMessage(r));
615 return __pDisplayContext;
619 _Window::SetZOrderGroup(int windowZOrderGroup)
623 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
624 bool visible = pEcoreEvas->IsWindowVisible(*this);
625 bool activationEnabled = pEcoreEvas->IsWindowActivationEnabled(*this);
627 if ((visible == true) && (activationEnabled == true))
629 pEcoreEvas->ActivateWindow(*this);
636 : __windowState(WINDOW_STATE_INITIALIZED)
638 , __pWindowDelegate(null)
640 , __destroying(false)
641 , __pRootVisualElement(null)
643 , __pDisplayContext(null)
644 , __systemWindow(false)
646 , __isInitialized(false)
647 , __pFocusedControl(null)
649 #if !defined(WINDOW_BASE_ROTATE)
650 , __orientationEnabled(false)
655 SetControlDelegate(*this);
656 SetWindowDelegate(*this);
657 SetClipToParent(false); // [ToDo] exception check.
661 _Window::Activate(void)
669 GetWindowDelegate().OnActivated();
673 _Window::Deactivate(void)
677 if (__destroying == false)
679 GetWindowDelegate().OnDeactivated();
684 _Window::SetSystemWindow(bool systemWindow)
686 __systemWindow = systemWindow;
690 _Window::IsSystemWindow(void) const
692 return __systemWindow;
696 _Window::SetFocusedControl(const _Control* pControl)
698 __pFocusedControl = const_cast<_Control*>(pControl);
702 _Window::GetFocusedControl(void) const
704 return __pFocusedControl;