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 <FApp_AppInfo.h>
24 #include "FUi_ControlManager.h"
25 #include "FUi_OrientationAgent.h"
26 #include "FUi_ImeOrientationAgent.h"
27 #include "FUi_CoordinateSystemUtils.h"
28 #include "FUiCtrlForm.h"
29 #include "FUiCtrl_FrameImpl.h"
30 #include "FUiCtrl_FormImpl.h"
31 #include "FUiCtrl_Frame.h"
32 #include "FUiCtrl_PublicFrameEvent.h"
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Base::Runtime;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Ui::Animations;
42 namespace Tizen { namespace Ui { namespace Controls {
44 const String _REQUEST_ORIENTATION_EVENT = L"RequestOrientationEvent";
47 _FrameImpl::GetInstance(const Frame& frame)
49 return static_cast<const _FrameImpl*> (frame._pControlImpl);
53 _FrameImpl::GetInstance(Frame& frame)
55 return static_cast<_FrameImpl*> (frame._pControlImpl);
59 _FrameImpl::Dispose(void)
61 GetCore().RemoveFrameEventListener(*this);
69 if (__pOrientationAgent)
71 delete __pOrientationAgent;
72 __pOrientationAgent = null;
75 if (__pImeOrientationAgent)
77 delete __pImeOrientationAgent;
78 __pImeOrientationAgent = null;
81 delete __pFrameAnimator;
82 __pFrameAnimator = null;
85 _FrameImpl::_FrameImpl(Frame* pPublic, _Frame* pCore)
86 : _WindowImpl(pPublic, pCore)
88 , __pFrameAnimator(null)
89 , __pOrientationAgent(null)
90 , __pImeOrientationAgent(null)
92 __pFrameEvent = _PublicFrameEvent::CreateInstanceN(*pPublic);
93 SysTryReturnVoidResult(NID_UI_CTRL, __pFrameEvent, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
95 int appType = _AppInfo::GetAppType();
96 if (appType & _APP_TYPE_IME_APP)
98 __pImeOrientationAgent = _ImeOrientationAgent::CreateInstanceN(*pPublic);
99 SysTryCatch(NID_UI_CTRL, __pImeOrientationAgent != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
103 __pOrientationAgent = _OrientationAgent::CreateInstanceN(*pPublic);
104 SysTryCatch(NID_UI_CTRL, __pOrientationAgent != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
113 _FrameImpl::~_FrameImpl(void)
115 // [ToDo] Wrong point to call OnFrameTerminating().
118 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_TERMINATING);
121 __pFrameEvent->Fire(*pEventArg);
130 _FrameImpl::GetPublicClassName(void) const
132 return "Tizen::Ui::Controls::Frame";
136 _FrameImpl::GetPublic(void) const
138 return static_cast<const Frame&>(_ControlImpl::GetPublic());
142 _FrameImpl::GetPublic(void)
144 return static_cast<Frame&>(_ControlImpl::GetPublic());
148 _FrameImpl::GetCore(void) const
150 return static_cast<const _Frame&>(_ControlImpl::GetCore());
154 _FrameImpl::GetCore(void)
156 return static_cast<_Frame&>(_ControlImpl::GetCore());
160 _FrameImpl::SetCurrentForm(const _FormImpl& formImpl)
162 result r = E_SUCCESS;
164 _FormImpl* pNewCurForm = const_cast<_FormImpl*>(&formImpl);
166 SysTryReturn(NID_UI_CTRL,
167 pNewCurForm != null, E_INVALID_ARG,
168 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not initialized.");
170 SysTryReturn(NID_UI_CTRL,
171 IsAncestorOf(pNewCurForm), E_INVALID_ARG,
172 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not the child of this Frame.");
174 if (GetCore().GetShowMode() != FRAME_SHOW_MODE_FULL_SCREEN)
176 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.");
180 r = MoveChildToTop(*pNewCurForm);
181 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
183 // [ToDo] Change the method to return result. And the arg should be reference.
184 GetCore().SetCurrentForm(&pNewCurForm->GetCore());
186 SysAssert(r == E_SUCCESS); // [ToDo] Exception check.
188 pNewCurForm->UpdateOrientationStatus();
190 // [ToDo] Check last result
191 SysAssert(GetLastResult() == E_SUCCESS);
196 _FrameImpl::SetCurrentForm(_FormImpl* pFormImpl)
198 result r = E_SUCCESS;
200 _FormImpl* pNewCurForm = pFormImpl;
202 SysTryReturn(NID_UI_CTRL,
203 pNewCurForm != null, E_INVALID_ARG,
204 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not initialized.");
206 SysTryReturn(NID_UI_CTRL,
207 IsAncestorOf(pNewCurForm), E_INVALID_ARG,
208 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not the child of this Frame.");
210 if (GetCore().GetShowMode() != FRAME_SHOW_MODE_FULL_SCREEN)
212 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.");
216 r = MoveChildToTop(*pNewCurForm);
217 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
219 // [ToDo] Change the method to return result. And the arg should be reference.
220 GetCore().SetCurrentForm(&pNewCurForm->GetCore());
222 SysAssert(r == E_SUCCESS); // [ToDo] Exception check.
224 pNewCurForm->UpdateOrientationStatus();
226 // [ToDo] Check last result
227 SysAssert(GetLastResult() == E_SUCCESS);
231 // [ToDo] This function should return _FormImpl*.
233 _FrameImpl::GetCurrentForm(void) const
235 _Control* pFormCore = GetCore().GetCurrentForm();
236 SysTryReturn(NID_UI_CTRL, pFormCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
238 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pFormCore->GetUserData());
244 _FrameImpl::CreateFrameImplN(Frame* pPublic)
247 result r = E_SUCCESS;
249 _Frame* pCore = _Frame::CreateFrameN();
250 SysTryReturn(NID_UI_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
252 _FrameImpl* pImpl = new (std::nothrow) _FrameImpl(pPublic, pCore);
253 r = _ControlImpl::CheckConstruction(pCore, pImpl);
254 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
256 pCore->SetSize(_ControlManager::GetInstance()->GetScreenSizeF());
258 pCore->AddFrameEventListener(*pImpl);
260 SetLastResult(E_SUCCESS);
266 _FrameImpl::AddFrameEventListener(IFrameEventListener& listener)
268 result r = __pFrameEvent->AddListener(listener);
269 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
273 _FrameImpl::RemoveFrameEventListener(IFrameEventListener& listener)
275 result r = __pFrameEvent->RemoveListener(listener);
276 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
279 Animations::FrameAnimator*
280 _FrameImpl::GetFrameAnimator(void) const
282 if (__pFrameAnimator == null)
284 FrameAnimator* pFrameAnimator = new (std::nothrow) FrameAnimator();
285 SysTryReturn(NID_UI_CTRL,
286 pFrameAnimator != null, null,
287 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
289 result r = pFrameAnimator->Construct(GetPublic());
292 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] FrameAnimator::Construct failed");
293 delete pFrameAnimator;
297 const_cast<_FrameImpl*>(this)->__pFrameAnimator = pFrameAnimator;
300 SetLastResult(E_SUCCESS);
302 return __pFrameAnimator;
306 _FrameImpl::OnDraw(void)
308 if (__pOrientationAgent)
310 __pOrientationAgent->FireOrientationEvent();
313 _WindowImpl::OnDraw();
317 _FrameImpl::OnChangeLayout(_ControlOrientation orientation)
320 _ContainerImpl::OnChangeLayout(orientation);
321 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
323 bool resizable = IsResizable();
326 _ControlManager* pCoreManager = _ControlManager::GetInstance();
327 SysAssert(pCoreManager);
328 const FloatDimension& screenSize = pCoreManager->GetScreenSizeF();
330 FrameShowMode frameShowMode = GetCore().GetShowMode();
332 if (frameShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
334 GetCore().SetRotation(true);
336 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
342 SetSize(FloatDimension(screenSize.height, screenSize.width));
345 GetCore().SetRotation(false);
347 else if ((frameShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (frameShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
349 // Adjust the position of the partial Frame.
350 bool movable = IsMovable();
353 FloatPoint prevPoint = GetPositionF();
354 FloatPoint curPoint(0.0f, 0.0f);
356 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
358 curPoint.x = screenSize.width / screenSize.height * prevPoint.x;
359 curPoint.y = screenSize.height / screenSize.width * prevPoint.y;
363 curPoint.x = screenSize.height / screenSize.width * prevPoint.x;
364 curPoint.y = screenSize.width / screenSize.height * prevPoint.y;
367 SetPosition(curPoint);
372 SetResizable(resizable);
376 _FrameImpl::OnChildDetaching(const _Control& child)
378 result r = E_SUCCESS;
380 _FormImpl* pFormImpl = static_cast<_FormImpl*>(child.GetUserData());
382 _FormImpl* pCurrentForm = GetCurrentForm();
384 if (pCurrentForm != null)
386 if (pCurrentForm == pFormImpl)
388 // if the given control will be the current form, hide the current form
389 int count = GetChildCount();
392 _ControlImpl* pControlImpl = GetChild(count - 2);
398 Form* pPrevForm = static_cast<Form*>(&pControlImpl->GetPublic());
400 if (pPrevForm != null)
402 r = pPrevForm->SetShowState(true);
405 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
415 _FrameImpl::OnChildDetached(const _Control& child)
417 _ControlImpl::OnChildDetached(child);
419 int childCount = GetCore().GetChildCount();
422 UpdateOrientationStatus();
424 else if (childCount > 0)
426 _Control* pControl = GetCore().GetChild(childCount - 1);
427 _ControlImpl* pControlImpl = static_cast<_ControlImpl*>(pControl->GetUserData());
428 _FormImpl* pCurrentFormImpl = dynamic_cast<_FormImpl*>(pControlImpl);
429 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentFormImpl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
430 pCurrentFormImpl->UpdateOrientationStatus(true);
435 _FrameImpl::OnFrameActivated(const _Frame& source)
439 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_ACTIVATED);
442 __pFrameEvent->Fire(*pEventArg);
448 _FrameImpl::OnFrameDeactivated(const _Frame& source)
452 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_DEACTIVATED);
455 __pFrameEvent->Fire(*pEventArg);
461 _FrameImpl::OnFrameMinimized(const _Frame& source)
465 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_MINIMIZED);
468 __pFrameEvent->Fire(*pEventArg);
474 _FrameImpl::OnFrameRestored(const _Frame& source)
478 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_RESTORED);
481 __pFrameEvent->Fire(*pEventArg);
487 _FrameImpl::OnBoundsChanged(void)
489 int childcount = GetChildCount();
490 FloatRectangle bounds = GetBoundsF();
492 for (int i = 0 ; i < childcount ; i++)
494 _ControlImpl* pChild = GetChild(i);
495 _FormImpl* pForm = dynamic_cast<_FormImpl*>(pChild);
498 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
500 if (pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE)
502 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
506 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.height, bounds.width));
511 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
517 _ContainerImpl::OnBoundsChanged();
522 _FrameImpl::OnAttachedToMainTree(void)
524 result r = _WindowImpl::OnAttachedToMainTree();
525 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
527 if (__pOrientationAgent)
529 __pOrientationAgent->RequestOrientationEvent();
536 _FrameImpl::OnNotifiedN(const _ControlImpl& source, IList* pArgs)
538 String* pString = dynamic_cast <Tizen::Base::String*>(pArgs->GetAt(0));
541 if (*pString == _REQUEST_ORIENTATION_EVENT)
543 if (__pOrientationAgent)
545 __pOrientationAgent->FireOrientationEvent();
548 pArgs->RemoveAll(true);
559 _FrameImpl::AddOrientationEventListener(Tizen::Ui::IOrientationEventListener& listener)
561 if (__pOrientationAgent)
563 __pOrientationAgent->AddListener(listener);
565 else if (__pImeOrientationAgent)
567 __pImeOrientationAgent->AddListener(listener);
572 _FrameImpl::RemoveOrientationEventListener(Tizen::Ui::IOrientationEventListener& listener)
574 if (__pOrientationAgent)
576 __pOrientationAgent->RemoveListener(listener);
578 else if (__pImeOrientationAgent)
580 __pImeOrientationAgent->RemoveListener(listener);
585 _FrameImpl::SetOrientation(Orientation orientation)
587 if (__pOrientationAgent)
589 __pOrientationAgent->SetMode(orientation);
594 _FrameImpl::GetOrientation(void) const
596 if (__pOrientationAgent)
598 return __pOrientationAgent->GetMode();
601 return ORIENTATION_NONE;
605 _FrameImpl::GetOrientationStatus(void) const
607 if (__pOrientationAgent)
609 return __pOrientationAgent->GetStatus();
612 return ORIENTATION_STATUS_NONE;
616 _FrameImpl::IsChildAttachable(_ControlImpl& child) const
618 return (dynamic_cast<_FormImpl*>(&child) != null);
622 _FrameImpl::UpdateOrientationStatus(void)
624 if (__pOrientationAgent)
626 __pOrientationAgent->Update();
630 #if defined(WINDOW_BASE_ROTATE)
632 _FrameImpl::UpdateOrientation(void)
634 if (__pOrientationAgent)
636 __pOrientationAgent->UpdateOrientation();
642 _FrameImpl::UpdateOrientation(int angle)
644 SysLog(NID_UI_CTRL, "[Ime Rotation]");
646 if (__pImeOrientationAgent)
648 __pImeOrientationAgent->UpdateOrientation(angle);
653 _FrameImpl::IsOpaque(void) const
660 _FrameImpl::SetFloatingBounds(const FloatRectangle& rect)
662 GetCore().SetFloatingBounds(rect);
666 _FrameImpl::SetFloatingBounds(const Rectangle& rect)
668 GetCore().SetFloatingBounds(rect);
672 _FrameImpl::SetShowMode(FrameShowMode showMode)
674 return GetCore().SetShowMode(showMode);
678 _FrameImpl::GetShowMode(void) const
680 return GetCore().GetShowMode();
683 }}} // Tizen::Ui::Controls