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 "FUiCtrlForm.h"
26 #include "FUiCtrl_FrameImpl.h"
27 #include "FUiCtrl_FormImpl.h"
28 #include "FUiCtrl_Frame.h"
29 #include "FUiCtrl_PublicFrameEvent.h"
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Runtime;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Animations;
37 namespace Tizen { namespace Ui { namespace Controls {
40 _FrameImpl::GetInstance(const Frame& frame)
42 return static_cast<const _FrameImpl*> (frame._pControlImpl);
46 _FrameImpl::GetInstance(Frame& frame)
48 return static_cast<_FrameImpl*> (frame._pControlImpl);
52 _FrameImpl::Dispose(void)
54 GetCore().RemoveFrameEventListener(*this);
62 delete __pOrientationAgent;
63 __pOrientationAgent = null;
65 delete __pFrameAnimator;
66 __pFrameAnimator = null;
69 _FrameImpl::_FrameImpl(Frame* pPublic, _Frame* pCore)
70 : _WindowImpl(pPublic, pCore)
72 , __pFrameAnimator(null)
73 , __pOrientationAgent(null)
75 __pFrameEvent = _PublicFrameEvent::CreateInstanceN(*pPublic);
76 SysTryReturnVoidResult(NID_UI_CTRL, __pFrameEvent, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
78 __pOrientationAgent = _OrientationAgent::CreateInstanceN(*pPublic);
79 SysTryCatch(NID_UI_CTRL, __pOrientationAgent != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
87 _FrameImpl::~_FrameImpl(void)
89 // [ToDo] Wrong point to call OnFrameTerminating().
92 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_TERMINATING);
95 __pFrameEvent->Fire(*pEventArg);
104 _FrameImpl::GetPublicClassName(void) const
106 return "Tizen::Ui::Controls::Frame";
110 _FrameImpl::GetPublic(void) const
112 return static_cast<const Frame&>(_ControlImpl::GetPublic());
116 _FrameImpl::GetPublic(void)
118 return static_cast<Frame&>(_ControlImpl::GetPublic());
122 _FrameImpl::GetCore(void) const
124 return static_cast<const _Frame&>(_ControlImpl::GetCore());
128 _FrameImpl::GetCore(void)
130 return static_cast<_Frame&>(_ControlImpl::GetCore());
134 _FrameImpl::SetCurrentForm(const _FormImpl& formImpl)
136 result r = E_SUCCESS;
138 _FormImpl* pNewCurForm = const_cast<_FormImpl*>(&formImpl);
140 SysTryReturn(NID_UI_CTRL,
141 pNewCurForm != null, E_INVALID_ARG,
142 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not initialized.");
144 SysTryReturn(NID_UI_CTRL,
145 IsAncestorOf(pNewCurForm), E_INVALID_ARG,
146 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not the child of this Frame.");
148 if (GetCore().GetShowMode() != FRAME_SHOW_MODE_FULL_SCREEN)
150 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.");
154 r = MoveChildToTop(*pNewCurForm);
155 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
157 // [ToDo] Change the method to return result. And the arg should be reference.
158 GetCore().SetCurrentForm(&pNewCurForm->GetCore());
160 SysAssert(r == E_SUCCESS); // [ToDo] Exception check.
162 pNewCurForm->UpdateOrientationStatus();
164 // [ToDo] Check last result
165 SysAssert(GetLastResult() == E_SUCCESS);
169 // [ToDo] This function should return _FormImpl*.
171 _FrameImpl::GetCurrentForm(void) const
173 _Control* pFormCore = GetCore().GetCurrentForm();
174 SysTryReturn(NID_UI_CTRL, pFormCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
176 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pFormCore->GetUserData());
182 _FrameImpl::CreateFrameImplN(Frame* pPublic)
185 result r = E_SUCCESS;
187 _Frame* pCore = _Frame::CreateFrameN();
188 SysTryReturn(NID_UI_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
190 _FrameImpl* pImpl = new (std::nothrow) _FrameImpl(pPublic, pCore);
191 r = _ControlImpl::CheckConstruction(pCore, pImpl);
192 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
194 pCore->SetSize(_ControlManager::GetInstance()->GetScreenSize());
196 pCore->AddFrameEventListener(*pImpl);
198 SetLastResult(E_SUCCESS);
204 _FrameImpl::AddFrameEventListener(IFrameEventListener& listener)
206 result r = __pFrameEvent->AddListener(listener);
207 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
211 _FrameImpl::RemoveFrameEventListener(IFrameEventListener& listener)
213 result r = __pFrameEvent->RemoveListener(listener);
214 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
217 Animations::FrameAnimator*
218 _FrameImpl::GetFrameAnimator(void) const
220 if (__pFrameAnimator == null)
222 FrameAnimator* pFrameAnimator = new (std::nothrow) FrameAnimator();
223 SysTryReturn(NID_UI_CTRL,
224 pFrameAnimator != null, null,
225 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
227 result r = pFrameAnimator->Construct(GetPublic());
230 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] FrameAnimator::Construct failed");
231 delete pFrameAnimator;
235 const_cast<_FrameImpl*>(this)->__pFrameAnimator = pFrameAnimator;
238 SetLastResult(E_SUCCESS);
240 return __pFrameAnimator;
244 _FrameImpl::OnDraw(void)
246 __pOrientationAgent->FireOrientationEvent();
248 _WindowImpl::OnDraw();
252 _FrameImpl::OnChangeLayout(_ControlOrientation orientation)
255 _ContainerImpl::OnChangeLayout(orientation);
256 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
258 bool resizable = IsResizable();
261 _ControlManager* pCoreManager = _ControlManager::GetInstance();
262 SysAssert(pCoreManager);
263 const Dimension& screenSize = pCoreManager->GetScreenSize();
265 #if !defined(MULTI_WINDOW)
266 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
272 SetSize(Dimension(screenSize.height, screenSize.width));
275 if (GetCore().GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
277 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
283 SetSize(Dimension(screenSize.height, screenSize.width));
288 SetResizable(resizable);
292 _FrameImpl::OnChildDetaching(const _Control& child)
294 result r = E_SUCCESS;
296 _FormImpl* pFormImpl = static_cast<_FormImpl*>(child.GetUserData());
298 _FormImpl* pCurrentForm = GetCurrentForm();
300 if (pCurrentForm != null)
302 if (pCurrentForm == pFormImpl)
304 // if the given control will be the current form, hide the current form
305 int count = GetChildCount();
308 _ControlImpl* pControlImpl = GetChild(count - 2);
314 Form* pPrevForm = static_cast<Form*>(&pControlImpl->GetPublic());
316 if (pPrevForm != null)
318 r = pPrevForm->SetShowState(true);
321 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
331 _FrameImpl::OnChildDetached(const _Control& child)
333 _ControlImpl::OnChildDetached(child);
335 int childCount = GetCore().GetChildCount();
338 UpdateOrientationStatus();
343 _FrameImpl::OnFrameActivated(const _Frame& source)
347 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_ACTIVATED);
350 __pFrameEvent->Fire(*pEventArg);
356 _FrameImpl::OnFrameDeactivated(const _Frame& source)
360 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_DEACTIVATED);
363 __pFrameEvent->Fire(*pEventArg);
369 _FrameImpl::OnBoundsChanged(void)
371 int childcount = GetChildCount();
372 Rectangle bounds = GetBounds();
374 for (int i = 0 ; i < childcount ; i++)
376 _ControlImpl* pChild = GetChild(i);
377 _FormImpl* pForm = dynamic_cast<_FormImpl*>(pChild);
380 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
382 if (pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE)
384 pForm->SetBounds(Rectangle(0, 0, GetBounds().width, GetBounds().height));
388 pForm->SetBounds(Rectangle(0, 0, GetBounds().height, GetBounds().width));
393 pForm->SetBounds(Rectangle(0, 0, GetBounds().width, GetBounds().height));
399 _ContainerImpl::OnBoundsChanged();
405 _FrameImpl::AddOrientationEventListener(Tizen::Ui::IOrientationEventListener& listener)
407 __pOrientationAgent->AddListener(listener);
411 _FrameImpl::RemoveOrientationEventListener(Tizen::Ui::IOrientationEventListener& listener)
413 __pOrientationAgent->RemoveListener(listener);
417 _FrameImpl::SetOrientation(Orientation orientation)
419 __pOrientationAgent->SetMode(orientation);
423 _FrameImpl::GetOrientation(void) const
425 return __pOrientationAgent->GetMode();
429 _FrameImpl::GetOrientationStatus(void) const
431 return __pOrientationAgent->GetStatus();
435 _FrameImpl::IsChildAttachable(_ControlImpl& child) const
437 return (dynamic_cast<_FormImpl*>(&child) != null);
441 _FrameImpl::UpdateOrientationStatus(void)
443 __pOrientationAgent->Update();
447 _FrameImpl::IsOpaque(void) const
453 _FrameImpl::SetFloatingBounds(const Rectangle& rect)
455 GetCore().SetFloatingBounds(rect);
459 _FrameImpl::SetShowMode(FrameShowMode showMode)
461 return GetCore().SetShowMode(showMode);
465 _FrameImpl::GetShowMode(void) const
467 return GetCore().GetShowMode();
470 }}} // Tizen::Ui::Controls