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.
18 * @file FUi_WindowImpl.cpp
19 * @brief This is the implementation file for the _WindowImpl class.
23 #include <FBaseSysLog.h>
24 #include <FUiWindow.h>
25 #include "FUi_WindowImpl.h"
26 #include "FUi_Window.h"
27 #include "FUi_ErrorMessages.h"
28 #include "FUi_UiManagerProxy.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Ui::Animations;
36 namespace Tizen { namespace Ui
39 class _WindowImpl::WindowImplDelegate
40 : public _IWindowDelegate
43 WindowImplDelegate(_WindowImpl& impl)
45 , __core(impl.GetCore())
46 , __public(impl.GetPublic())
50 virtual void OnActivated(void)
52 IEnumeratorT <Runtime::IEventListener*>* pEnumerator = __impl.__pPublicWindowEventListeners->GetEnumeratorN();
54 while (pEnumerator->MoveNext() == E_SUCCESS)
56 Runtime::IEventListener* pListener = null;
57 pEnumerator->GetCurrent(pListener);
58 IWindowEventListener* pWindowEventListener = dynamic_cast <IWindowEventListener*>(pListener);
59 if (!pWindowEventListener)
64 pWindowEventListener->OnWindowActivated(__public);
69 __impl.SetWindowState(WINDOW_STATE_ACTIVATED);
78 virtual void OnNativeWindowActivated(void)
80 __impl.OnNativeWindowActivated();
81 __core.OnNativeWindowActivated();
84 virtual void OnDeactivated(void)
86 IEnumeratorT <Runtime::IEventListener*>* pEnumerator = __impl.__pPublicWindowEventListeners->GetEnumeratorN();
89 while (pEnumerator->MoveNext() == E_SUCCESS)
91 Runtime::IEventListener* pListener = null;
92 pEnumerator->GetCurrent(pListener);
93 IWindowEventListener* pWindowEventListener = dynamic_cast <IWindowEventListener*>(pListener);
94 if (!pWindowEventListener)
99 pWindowEventListener->OnWindowDeactivated(__public);
104 __impl.SetWindowState(WINDOW_STATE_DEACTIVATED);
107 __impl.OnDeactivated();
110 __core.OnDeactivated();
113 virtual void OnOwnerChanged(_Control* pOldOwner)
115 __impl.OnOwnerChanged(pOldOwner);
116 __core.OnOwnerChanged(pOldOwner);
120 WindowImplDelegate(const WindowImplDelegate& rhs);
121 WindowImplDelegate& operator =(const WindowImplDelegate& rhs);
127 }; // WindowImplDelegate
131 _WindowImpl::GetErrorWindowState(void)
133 return WINDOW_STATE_INITIALIZED; // [ToDo] Not good choice. But no option.
137 _WindowImpl::GetInstance(Window& window)
139 return static_cast <_WindowImpl*> (window._pControlImpl);
143 _WindowImpl::GetInstance(const Window& window)
145 return static_cast <const _WindowImpl*> (window._pControlImpl);
149 _WindowImpl::CreateWindowImplN(Window* pPublic, const Rectangle& bounds,
150 const Layout* pPublicPortraitLayout, const Layout* pPublicLandscapeLayout,
151 bool resizable, bool movable)
153 result r = E_SUCCESS;
155 _Window* pCore = _Window::CreateWindowN();
156 SysTryReturn(NID_UI, pCore, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
159 new (std::nothrow) _WindowImpl(pPublic, pCore, bounds,
160 pPublicPortraitLayout, pPublicLandscapeLayout,
162 r = CheckConstruction(pCore, pImpl);
163 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
171 _WindowImpl::CreateWindowImplN(Window* pPublic, const FloatRectangle& bounds,
172 const Layout* pPublicPortraitLayout, const Layout* pPublicLandscapeLayout,
173 bool resizable, bool movable)
175 result r = E_SUCCESS;
177 _Window* pCore = _Window::CreateWindowN();
178 SysTryReturn(NID_UI, pCore, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
181 new (std::nothrow) _WindowImpl(pPublic, pCore, bounds,
182 pPublicPortraitLayout, pPublicLandscapeLayout,
184 r = CheckConstruction(pCore, pImpl);
185 SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
192 _WindowImpl::~_WindowImpl(void)
194 _WindowImpl::GetCore().ResetWindowDelegate();
196 delete __pImplDelegate;
197 __pImplDelegate = null;
201 delete __pPublicWindowEventListeners;
202 __pPublicWindowEventListeners = null;
206 _WindowImpl::GetPublicClassName(void) const
208 return "Tizen::Ui::Window";
212 _WindowImpl::GetPublic(void) const
214 return static_cast <const Window&>(_ControlImpl::GetPublic());
218 _WindowImpl::GetPublic(void)
220 return static_cast <Window&>(_ControlImpl::GetPublic());
224 _WindowImpl::GetCore(void) const
226 return static_cast <const _Window&>(_ControlImpl::GetCore());
230 _WindowImpl::GetCore(void)
232 return static_cast <_Window&>(_ControlImpl::GetCore());
236 _WindowImpl::AddWindowEventListener(Tizen::Ui::IWindowEventListener& listener)
239 SysTryReturnVoidResult(NID_UI,
240 __pPublicWindowEventListeners->Add(&listener) == E_SUCCESS,
241 E_SYSTEM, _UiError::SYSTEM);
245 _WindowImpl::RemoveWindowEventListener(Tizen::Ui::IWindowEventListener& listener)
248 SysTryReturnVoidResult(NID_UI,
249 __pPublicWindowEventListeners->Remove(&listener) == E_SUCCESS,
250 E_SYSTEM, _UiError::SYSTEM);
254 _WindowImpl::OnActivated(void)
260 _WindowImpl::OnNativeWindowActivated(void)
266 _WindowImpl::OnDeactivated(void)
272 _WindowImpl::OnOwnerChanged(_Control* pOldOwner)
278 _WindowImpl::OnBoundsChanging(const Rectangle& bounds)
280 result r = E_SUCCESS;
281 r = _ControlImpl::OnBoundsChanging(bounds);
284 if (_WindowImpl::GetInstance(GetPublic()) == null)
286 r = CallOnBoundsChanging(bounds);
294 _WindowImpl::OnRotated(_ControlRotation rotation)
300 _WindowImpl::Open(bool drawAndShow)
302 return GetCore().Open(drawAndShow);
306 _WindowImpl::Close(void)
312 _WindowImpl::GetWindowState(void) const
315 return GetCore().GetWindowState();
319 _WindowImpl::SetWindowState(WindowState windowState)
321 GetCore().SetWindowState(windowState);
325 _WindowImpl::GetDisplayContext(void) const
327 return GetCore().GetDisplayContext();
331 _WindowImpl::SetZOrderGroup(WindowZOrderGroup windowZOrderGroup)
333 _UiManagerProxy uiManagerProxy;
334 result r = uiManagerProxy.Construct();
335 SysTryReturnResult(NID_UI, r == E_SUCCESS, r, "Propagating.");
337 NativeWindowHandle handle = GetCore().GetNativeHandle();
338 r = uiManagerProxy.SetZOrderGroup(handle, static_cast<int>(windowZOrderGroup));
339 SysTryReturnResult(NID_UI, r == E_SUCCESS, r, "Propagating.");
341 return GetCore().SetZOrderGroup(windowZOrderGroup);
345 _WindowImpl::GetOwner(void) const
347 _Control* pOwner = GetCore().GetOwner();
350 _ControlImpl* pImpl = static_cast<_ControlImpl*>(pOwner->GetUserData());
353 return (&pImpl->GetPublic());
361 _WindowImpl::SetOwner(Tizen::Ui::Control *pControl)
363 _ControlImpl* pImpl = _ControlImpl::GetInstance(*pControl);
364 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
366 GetCore().SetOwner(&pImpl->GetCore());
370 _WindowImpl::GetNativeHandle(void) const
372 return GetCore().GetNativeHandle();
376 _WindowImpl::Destroy(void)
378 result r = E_SUCCESS;
380 SetDestroyingFlag(true);
382 Control* pOwner = GetOwner();
385 _ControlImpl* pImpl = _ControlImpl::GetInstance(*pOwner);
386 pImpl->GetCore().DetachOwnee(GetCore());
388 RemoveAllChildren(true, true);
389 Window* pWindow = &GetPublic();
397 _WindowImpl::Initialize(Window* pPublic, _Window* pCore, const Layout* pPublicPortraitLayout, const Layout* pPublicLandscapeLayout)
403 __pImplDelegate = new (std::nothrow) WindowImplDelegate(*this);
404 SysTryReturnVoidResult(NID_UI, __pImplDelegate, E_OUT_OF_MEMORY, _UiError::OUT_OF_MEMORY);
406 __pPublicWindowEventListeners = CreatePublicEventListenerListN();
407 result r = GetLastResult();
408 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
410 pCore->SetWindowDelegate(*__pImplDelegate);
412 SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
417 delete __pPublicWindowEventListeners;
418 __pPublicWindowEventListeners = null;
421 _WindowImpl::_WindowImpl(Window* pPublic, _Window* pCore, const Layout* pPublicPortraitLayout, const Layout* pPublicLandscapeLayout)
422 : _ContainerImpl(pPublic, pCore, pPublicPortraitLayout, pPublicLandscapeLayout)
423 , __pPublicWindowEventListeners(null)
424 , __pImplDelegate(null)
426 Initialize(pPublic, pCore, pPublicPortraitLayout, pPublicLandscapeLayout);
429 _WindowImpl::_WindowImpl(Window* pPublic, _Window* pCore, const Rectangle& bounds, const Layout* pPublicPortraitLayout, const Layout* pPublicLandscapeLayout, bool resizable, bool movable)
430 : _ContainerImpl(pPublic, pCore, pPublicPortraitLayout, pPublicLandscapeLayout)
432 result r = E_SUCCESS;
434 Initialize(pPublic, pCore, pPublicPortraitLayout, pPublicLandscapeLayout);
442 bool allOrNone = (pPublicPortraitLayout && pPublicLandscapeLayout) || (!pPublicPortraitLayout && !pPublicLandscapeLayout);
443 SysAssert(allOrNone);
445 r = SetBounds(bounds);
446 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
448 pCore->SetResizable(resizable);
449 pCore->SetMovable(movable);
452 _WindowImpl::_WindowImpl(Window* pPublic, _Window* pCore, const FloatRectangle& bounds, const Layout* pPublicPortraitLayout, const Layout* pPublicLandscapeLayout, bool resizable, bool movable)
453 : _ContainerImpl(pPublic, pCore, pPublicPortraitLayout, pPublicLandscapeLayout)
455 result r = E_SUCCESS;
457 Initialize(pPublic, pCore, pPublicPortraitLayout, pPublicLandscapeLayout);
465 bool allOrNone = (pPublicPortraitLayout && pPublicLandscapeLayout) || (!pPublicPortraitLayout && !pPublicLandscapeLayout);
466 SysAssert(allOrNone);
468 r = SetBounds(bounds);
469 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
471 pCore->SetResizable(resizable);
472 pCore->SetMovable(movable);