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 #include <FUiCtrlForm.h>
20 #include <FUiAnimFrameAnimator.h>
21 #include <FUiCtrlIFrameEventListener.h>
22 #include <FBaseSysLog.h>
23 #include "FUi_ControlManager.h"
24 #include "FUi_OrientationAgent.h"
25 #include "FUi_CoordinateSystemUtils.h"
26 #include "FUiCtrlForm.h"
27 #include "FUiCtrl_FrameImpl.h"
28 #include "FUiCtrl_FormImpl.h"
29 #include "FUiCtrl_Frame.h"
30 #include "FUiCtrl_PublicFrameEvent.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base::Runtime;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Animations;
39 namespace Tizen { namespace Ui { namespace Controls {
41 const String _REQUEST_ORIENTATION_EVENT = L"RequestOrientationEvent";
44 _FrameImpl::GetInstance(const Frame& frame)
46 return static_cast<const _FrameImpl*> (frame._pControlImpl);
50 _FrameImpl::GetInstance(Frame& frame)
52 return static_cast<_FrameImpl*> (frame._pControlImpl);
56 _FrameImpl::Dispose(void)
58 GetCore().RemoveFrameEventListener(*this);
66 delete __pOrientationAgent;
67 __pOrientationAgent = null;
69 delete __pFrameAnimator;
70 __pFrameAnimator = null;
73 _FrameImpl::_FrameImpl(Frame* pPublic, _Frame* pCore)
74 : _WindowImpl(pPublic, pCore)
76 , __pFrameAnimator(null)
77 , __pOrientationAgent(null)
79 __pFrameEvent = _PublicFrameEvent::CreateInstanceN(*pPublic);
80 SysTryReturnVoidResult(NID_UI_CTRL, __pFrameEvent, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
82 __pOrientationAgent = _OrientationAgent::CreateInstanceN(*pPublic);
83 SysTryCatch(NID_UI_CTRL, __pOrientationAgent != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
91 _FrameImpl::~_FrameImpl(void)
93 // [ToDo] Wrong point to call OnFrameTerminating().
96 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_TERMINATING);
99 __pFrameEvent->Fire(*pEventArg);
108 _FrameImpl::GetPublicClassName(void) const
110 return "Tizen::Ui::Controls::Frame";
114 _FrameImpl::GetPublic(void) const
116 return static_cast<const Frame&>(_ControlImpl::GetPublic());
120 _FrameImpl::GetPublic(void)
122 return static_cast<Frame&>(_ControlImpl::GetPublic());
126 _FrameImpl::GetCore(void) const
128 return static_cast<const _Frame&>(_ControlImpl::GetCore());
132 _FrameImpl::GetCore(void)
134 return static_cast<_Frame&>(_ControlImpl::GetCore());
138 _FrameImpl::SetCurrentForm(const _FormImpl& formImpl)
140 result r = E_SUCCESS;
142 _FormImpl* pNewCurForm = const_cast<_FormImpl*>(&formImpl);
144 SysTryReturn(NID_UI_CTRL,
145 pNewCurForm != null, E_INVALID_ARG,
146 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not initialized.");
148 SysTryReturn(NID_UI_CTRL,
149 IsAncestorOf(pNewCurForm), E_INVALID_ARG,
150 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not the child of this Frame.");
152 if (GetCore().GetShowMode() != FRAME_SHOW_MODE_FULL_SCREEN)
154 SysTryReturn(NID_UI_CTRL, !(pNewCurForm->GetFormStyle() & FORM_STYLE_INDICATOR), E_INVALID_ARG, E_INVALID_ARG, "Only Frame whose show mode is @c FRAME_SHOW_MODE_FULL_SCREEN can set a Form which has the style of @c FORM_STYLE_INDICATOR as the current form.");
158 r = MoveChildToTop(*pNewCurForm);
159 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
161 // [ToDo] Change the method to return result. And the arg should be reference.
162 GetCore().SetCurrentForm(&pNewCurForm->GetCore());
164 SysAssert(r == E_SUCCESS); // [ToDo] Exception check.
166 pNewCurForm->UpdateOrientationStatus();
168 // [ToDo] Check last result
169 SysAssert(GetLastResult() == E_SUCCESS);
174 _FrameImpl::SetCurrentForm(_FormImpl* pFormImpl)
176 result r = E_SUCCESS;
178 _FormImpl* pNewCurForm = pFormImpl;
180 SysTryReturn(NID_UI_CTRL,
181 pNewCurForm != null, E_INVALID_ARG,
182 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not initialized.");
184 SysTryReturn(NID_UI_CTRL,
185 IsAncestorOf(pNewCurForm), E_INVALID_ARG,
186 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not the child of this Frame.");
188 if (GetCore().GetShowMode() != FRAME_SHOW_MODE_FULL_SCREEN)
190 SysTryReturn(NID_UI_CTRL, !(pNewCurForm->GetFormStyle() & FORM_STYLE_INDICATOR), E_INVALID_ARG, E_INVALID_ARG, "Only Frame whose show mode is @c FRAME_SHOW_MODE_FULL_SCREEN can set a Form which has the style of @c FORM_STYLE_INDICATOR as the current form.");
194 r = MoveChildToTop(*pNewCurForm);
195 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
197 // [ToDo] Change the method to return result. And the arg should be reference.
198 GetCore().SetCurrentForm(&pNewCurForm->GetCore());
200 SysAssert(r == E_SUCCESS); // [ToDo] Exception check.
202 pNewCurForm->UpdateOrientationStatus();
204 // [ToDo] Check last result
205 SysAssert(GetLastResult() == E_SUCCESS);
209 // [ToDo] This function should return _FormImpl*.
211 _FrameImpl::GetCurrentForm(void) const
213 _Control* pFormCore = GetCore().GetCurrentForm();
214 SysTryReturn(NID_UI_CTRL, pFormCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
216 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pFormCore->GetUserData());
222 _FrameImpl::CreateFrameImplN(Frame* pPublic)
225 result r = E_SUCCESS;
227 _Frame* pCore = _Frame::CreateFrameN();
228 SysTryReturn(NID_UI_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
230 _FrameImpl* pImpl = new (std::nothrow) _FrameImpl(pPublic, pCore);
231 r = _ControlImpl::CheckConstruction(pCore, pImpl);
232 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
234 pCore->SetSize(_ControlManager::GetInstance()->GetScreenSizeF());
236 pCore->AddFrameEventListener(*pImpl);
238 SetLastResult(E_SUCCESS);
244 _FrameImpl::AddFrameEventListener(IFrameEventListener& listener)
246 result r = __pFrameEvent->AddListener(listener);
247 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
251 _FrameImpl::RemoveFrameEventListener(IFrameEventListener& listener)
253 result r = __pFrameEvent->RemoveListener(listener);
254 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
257 Animations::FrameAnimator*
258 _FrameImpl::GetFrameAnimator(void) const
260 if (__pFrameAnimator == null)
262 FrameAnimator* pFrameAnimator = new (std::nothrow) FrameAnimator();
263 SysTryReturn(NID_UI_CTRL,
264 pFrameAnimator != null, null,
265 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
267 result r = pFrameAnimator->Construct(GetPublic());
270 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] FrameAnimator::Construct failed");
271 delete pFrameAnimator;
275 const_cast<_FrameImpl*>(this)->__pFrameAnimator = pFrameAnimator;
278 SetLastResult(E_SUCCESS);
280 return __pFrameAnimator;
284 _FrameImpl::OnDraw(void)
286 __pOrientationAgent->FireOrientationEvent();
288 _WindowImpl::OnDraw();
292 _FrameImpl::OnChangeLayout(_ControlOrientation orientation)
295 _ContainerImpl::OnChangeLayout(orientation);
296 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
298 bool resizable = IsResizable();
301 _ControlManager* pCoreManager = _ControlManager::GetInstance();
302 SysAssert(pCoreManager);
303 const FloatDimension& screenSize = pCoreManager->GetScreenSizeF();
305 if (GetCore().GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
307 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
313 SetSize(FloatDimension(screenSize.height, screenSize.width));
317 SetResizable(resizable);
321 _FrameImpl::OnChildDetaching(const _Control& child)
323 result r = E_SUCCESS;
325 _FormImpl* pFormImpl = static_cast<_FormImpl*>(child.GetUserData());
327 _FormImpl* pCurrentForm = GetCurrentForm();
329 if (pCurrentForm != null)
331 if (pCurrentForm == pFormImpl)
333 // if the given control will be the current form, hide the current form
334 int count = GetChildCount();
337 _ControlImpl* pControlImpl = GetChild(count - 2);
343 Form* pPrevForm = static_cast<Form*>(&pControlImpl->GetPublic());
345 if (pPrevForm != null)
347 r = pPrevForm->SetShowState(true);
350 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
360 _FrameImpl::OnChildDetached(const _Control& child)
362 _ControlImpl::OnChildDetached(child);
364 int childCount = GetCore().GetChildCount();
367 UpdateOrientationStatus();
369 else if (childCount > 0)
371 _FormImpl* pCurrentForm = dynamic_cast<_FormImpl*>(GetChild(childCount - 1));
372 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
373 pCurrentForm->UpdateOrientationStatus(true);
378 _FrameImpl::OnFrameActivated(const _Frame& source)
382 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_ACTIVATED);
385 __pFrameEvent->Fire(*pEventArg);
391 _FrameImpl::OnFrameDeactivated(const _Frame& source)
395 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_DEACTIVATED);
398 __pFrameEvent->Fire(*pEventArg);
404 _FrameImpl::OnFrameMinimized(const _Frame& source)
408 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_MINIMIZED);
411 __pFrameEvent->Fire(*pEventArg);
417 _FrameImpl::OnFrameRestored(const _Frame& source)
421 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_RESTORED);
424 __pFrameEvent->Fire(*pEventArg);
430 _FrameImpl::OnBoundsChanged(void)
432 int childcount = GetChildCount();
433 FloatRectangle bounds = GetBoundsF();
435 for (int i = 0 ; i < childcount ; i++)
437 _ControlImpl* pChild = GetChild(i);
438 _FormImpl* pForm = dynamic_cast<_FormImpl*>(pChild);
441 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
443 if (pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE)
445 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
449 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.height, bounds.width));
454 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
460 _ContainerImpl::OnBoundsChanged();
465 _FrameImpl::OnAttachedToMainTree(void)
467 result r = _WindowImpl::OnAttachedToMainTree();
468 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
470 __pOrientationAgent->RequestOrientationEvent();
476 _FrameImpl::OnNotifiedN(const _ControlImpl& source, IList* pArgs)
478 String* pString = dynamic_cast <Tizen::Base::String*>(pArgs->GetAt(0));
481 if (*pString == _REQUEST_ORIENTATION_EVENT)
483 __pOrientationAgent->FireOrientationEvent();
485 pArgs->RemoveAll(true);
496 _FrameImpl::AddOrientationEventListener(Tizen::Ui::IOrientationEventListener& listener)
498 __pOrientationAgent->AddListener(listener);
502 _FrameImpl::RemoveOrientationEventListener(Tizen::Ui::IOrientationEventListener& listener)
504 __pOrientationAgent->RemoveListener(listener);
508 _FrameImpl::SetOrientation(Orientation orientation)
510 __pOrientationAgent->SetMode(orientation);
514 _FrameImpl::GetOrientation(void) const
516 return __pOrientationAgent->GetMode();
520 _FrameImpl::GetOrientationStatus(void) const
522 return __pOrientationAgent->GetStatus();
526 _FrameImpl::IsChildAttachable(_ControlImpl& child) const
528 return (dynamic_cast<_FormImpl*>(&child) != null);
532 _FrameImpl::UpdateOrientationStatus(void)
534 __pOrientationAgent->Update();
537 #if defined(WINDOW_BASE_ROTATE)
539 _FrameImpl::UpdateOrientation(void)
541 __pOrientationAgent->UpdateOrientation();
546 _FrameImpl::IsOpaque(void) const
553 _FrameImpl::SetFloatingBounds(const FloatRectangle& rect)
555 GetCore().SetFloatingBounds(rect);
559 _FrameImpl::SetFloatingBounds(const Rectangle& rect)
561 GetCore().SetFloatingBounds(rect);
565 _FrameImpl::SetShowMode(FrameShowMode showMode)
567 return GetCore().SetShowMode(showMode);
571 _FrameImpl::GetShowMode(void) const
573 return GetCore().GetShowMode();
576 }}} // Tizen::Ui::Controls