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.
18 * @file FUi_Window.cpp
19 * @brief This is the implementation file for the _Window class.
22 #include <FBaseSysLog.h>
23 #include <FUiAnimDisplayContext.h>
24 #include <FUiWindow.h>
25 #include <FBase_Log.h>
26 #include "FUi_Window.h"
27 #include "FUi_ControlManager.h"
28 #include "FUi_TouchManager.h"
29 #include "FUiAnim_DisplayContextImpl.h"
30 #include "FUiAnim_RootVisualElement.h"
31 #include "FUiAnim_VisualElement.h"
32 #include "FUi_EcoreEvasMgr.h"
33 #include "FUi_EcoreEvas.h"
34 #if defined(MULTI_WINDOW)
35 #include "FUiAnim_DisplayManager.h"
36 #include "FUiAnim_EflLayer.h"
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Collection;
41 using namespace Tizen::Graphics;
42 using namespace Tizen::Ui::Animations;
44 namespace Tizen { namespace Ui
48 _Window::CreateWindowN(void)
50 _Window* pWindow = new (std::nothrow) _Window;
51 SysTryReturn(NID_UI, pWindow, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
53 #if defined(MULTI_WINDOW)
57 if (IsFailed(GetLastResult()))
62 #if defined(MULTI_WINDOW)
63 r = pWindow->CreateRootVisualElement();
64 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;
88 #if defined(MULTI_WINDOW)
93 if(__pRootVisualElement)
95 __pRootVisualElement->DetachChild(*GetVisualElement());
100 __pRootVisualElement =NULL;
107 _Window::GetWindowDelegate(void) const
111 return const_cast<_Window&>(*this);
114 SysAssert(__pWindowDelegate);
115 return *__pWindowDelegate;
119 _Window::GetDescription(void) const
121 String description = _Control::GetDescription();
122 String descriptionTemp(L"");
124 descriptionTemp.Format(LOG_LEN_MAX, L"_Window: owner(0x%x) delegate(0x%x) activated(%d) destroying(%d) displayContext(0x%x)",
125 __pOwner, __pWindowDelegate, __activated, __destroying, __pDisplayContext);
127 description.Append(descriptionTemp);
132 #if defined(MULTI_WINDOW)
134 _Window::SetRootVisualElement(const Tizen::Ui::Animations::_RootVisualElement& rootVisualElement)
136 _RootVisualElement* pRootVE = const_cast<_RootVisualElement*>(&rootVisualElement);
138 __pRootVisualElement = pRootVE;
143 _Window::IsActivatedOnOpen(void) const
149 _Window::IsActivated(void) const
155 _Window::SetWindowDelegate(_IWindowDelegate& delegate)
158 __pWindowDelegate = &delegate;
162 _Window::ResetWindowDelegate(void)
165 __pWindowDelegate = this;
169 _Window::IsAttached(void) const
171 return _ControlManager::GetInstance()->IsWindowAttached(*this);
175 _Window::Open(bool drawAndShow)
177 bool visibleState = GetVisibleState();
178 if (!__isOpened && visibleState)
180 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
181 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
182 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
184 __isInitialized = true;
185 return _ControlManager::GetInstance()->OpenWindow(*this, drawAndShow);
196 bool visibleState = GetVisibleState();
197 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
198 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
199 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), visibleState);
201 _ControlManager::GetInstance()->CloseWindow(*this);
207 _Window::GetOwner(void) const
214 _Window::SetOwner(_Control* pOwner)
218 if (pOwner == __pOwner)
225 __pOwner->DetachOwnee(*this);
231 pOwner->AttachOwnee(*this);
234 #if defined(MULTI_WINDOW)
235 GetEcoreEvasMgr()->GetEcoreEvas()->SetOwner(*this, *pOwner);
240 #if defined(MULTI_WINDOW)
242 _Window::CreateRootVisualElement(void)
244 result r = CreateLayer();
245 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
247 __pLayer = GetRootVisualElement()->GetNativeLayer();
249 // Get visual element.
250 _VisualElement* pVisualElement = GetVisualElement();
251 SysAssert(pVisualElement);
253 pVisualElement->SetName(L"Window");
254 pVisualElement->SetClipChildrenEnabled(false);
255 pVisualElement->SetRenderOperation(_VisualElement::RENDER_OPERATION_COPY);
257 // Attach visual element to root visual element.
258 __pRootVisualElement->AttachChild(*GetVisualElement());
264 _Window::CreateLayer(void)
266 _DisplayManager* pDisplayManager = _DisplayManager::GetInstance();
267 SysAssert(pDisplayManager);
269 __pLayer = _NativeLayer::CreateInstanceN();
271 __pRootVisualElement = __pLayer->GetRootVisualElement();
273 _EflLayer* pLayer = static_cast<_EflLayer*>(__pLayer);
278 ecore_x_window_size_get(ecore_x_window_root_get((Ecore_X_Window)ecore_evas_window_get(pLayer->GetEcoreEvas())), &rootWindowW, &rootWindowH);
280 pLayer->SetBounds(FloatRectangle(0.0f, 0.0f, (float)rootWindowW, (float)rootWindowH));
281 pLayer->SetOpacity(0);
283 __pRootVisualElement->SetName(L"Root");
290 _Window::IsFocusableDescendant(const _Control* pFocus) const
295 #if defined(MULTI_WINDOW)
297 _Window::SetActivationEnabled(bool enable)
299 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
300 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
302 pEcoreEvas->SetWindowActivationEnabled(*GetRootWindow(), enable);
304 SetLastResult(E_SUCCESS);
308 _Window::IsActivationEnabled(void)
310 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
311 SysTryReturn(NID_UI, pEcoreEvas, true, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
313 bool enable = pEcoreEvas->IsWindowActivationEnabled(*GetRootWindow());
315 SetLastResult(E_SUCCESS);
321 _Window::GetRootVisualElement(void) const
323 return __pRootVisualElement;
327 _Window::GetRootVisualElement(void) const
329 return __pRootVisualElement;
334 _Window::GetNativeHandle(void) const
336 #if defined(MULTI_WINDOW)
337 _RootVisualElement* pRootVE = GetRootVisualElement();
340 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
343 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
344 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
346 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
347 SysAssert(pEcoreEvas);
349 Ecore_X_Window win = pEcoreEvas->GetXWindow();
356 _Window::OnActivated(void)
358 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
359 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
361 if (!isFrameActivated)
366 _Control* pFocus = GetFocused();
369 pFocus->SetFocused();
376 _TouchManager* pTouchMgr = _TouchManager::GetInstance();
379 pTouchMgr->SetTouchCanceled(true);
384 _Window::OnNativeWindowActivated(void)
390 _Window::OnNotifiedN(const _Control& source, IList* pArgs)
392 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
394 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
395 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
397 if (*pType == L"VisibilityEvent")
401 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
402 if (pObscured == null)
404 pArgs->RemoveAll(true);
410 obscured = pObscured->ToInt();
413 GetWindowDelegate().OnNativeWindowActivated();
416 pArgs->RemoveAll(true);
426 _Window::OnDeactivated(void)
428 bool isFrameActivated = _ControlManager::GetInstance()->IsFrameActivated();
429 SysLog(NID_UI, "frameActivated(%d)", isFrameActivated);
432 #if !defined(MULTI_WINDOW)
435 _Window::OnVisibleStateChanged(void)
437 bool visibleState = GetVisibleState();
438 if (visibleState == true)
450 #if defined(MULTI_WINDOW)
452 _Window::OnBoundsChanging(const Rectangle& bounds)
454 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
455 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
457 pEcoreEvas->SetWindowBounds(*GetRootWindow(), bounds);
458 result r = GetLastResult();
459 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
465 _Window::OnVisibleStateChanged(void)
469 bool visibleState = GetVisibleState();
470 if (visibleState == false)
475 result r = GetLastResult();
476 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
478 SetLastResult(E_SUCCESS);
482 _Window::OnAttachingToMainTree(const _Control* pParent)
484 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
486 SetVisibleState(true);
487 pLayer->SetShowState(true);
493 _Window::OnDetachingFromMainTree(void)
495 _EflLayer* pLayer = static_cast<_EflLayer*>(__pRootVisualElement->GetNativeLayer());
497 pLayer->SetShowState(false);
503 _Window::IsLayoutChangable(void) const
510 _Window::OnChangeLayout(_ControlOrientation orientation)
512 SysLog(NID_UI, "[Test] _Window::OnChangeLayout()");
514 // if window, change its size specially for full-screen(Form, Frame, etc.).
515 _Control::OnChangeLayout(orientation); // if called, layout will be changed.
519 _Window::GetWindowState(void) const
522 return __windowState;
526 _Window::SetWindowState(WindowState windowState)
528 __windowState = windowState;
532 _Window::GetDisplayContext(void) const
534 if (!__pDisplayContext)
536 SysTryReturn(NID_UI, __pLayer, null, E_SYSTEM, "[E_SYSTEM] Cannot gain the DisplayContext. This window is not completed.");
538 __pDisplayContext = _DisplayContextImpl::CreatePublicInstance(*__pLayer);
541 result r = GetLastResult();
542 SysTryReturn(NID_UI, __pDisplayContext, null, r, "[%s] Propagating.", GetErrorMessage(r));
544 return __pDisplayContext;
548 _Window::SetZOrderGroup(int windowZOrderGroup)
550 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
551 SysAssert(pEcoreEvas);
553 _WindowLevel windowLevel = _WINDOW_LEVEL_NORMAL;
554 switch (windowZOrderGroup)
556 case WINDOW_Z_ORDER_GROUP_HIGHEST:
557 windowLevel = _WINDOW_LEVEL_NOTIFICATION_HIGH;
559 case WINDOW_Z_ORDER_GROUP_HIGH:
560 windowLevel = _WINDOW_LEVEL_NOTIFICATION_MIDDLE;
566 #if !defined(MULTI_WINDOW)
567 pEcoreEvas->SetWindowLevel(windowLevel);
569 pEcoreEvas->SetWindowLevel(*GetRootWindow(), windowLevel);
576 : __windowState(WINDOW_STATE_INITIALIZED)
578 , __pWindowDelegate(null)
580 , __destroying(false)
581 , __pRootVisualElement(null)
583 , __pDisplayContext(null)
584 , __systemWindow(false)
586 , __isInitialized(false)
588 SetControlDelegate(*this);
589 SetWindowDelegate(*this);
590 SetClipToParent(false); // [ToDo] exception check.
591 #if !defined(MULTI_WINDOW)
592 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
593 SysAssert(pEcoreEvas);
594 __pRootVisualElement = pEcoreEvas->GetRootVisualElement();
595 SysAssert(__pRootVisualElement);
596 __pLayer = __pRootVisualElement->GetNativeLayer();
602 _Window::Activate(void)
610 GetWindowDelegate().OnActivated();
614 _Window::Deactivate(void)
618 if (__destroying == false)
620 GetWindowDelegate().OnDeactivated();
625 _Window::SetSystemWindow(bool systemWindow)
627 __systemWindow = systemWindow;
631 _Window::IsSystemWindow(void) const
633 return __systemWindow;