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.
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 FrameShowMode showMode = GetCore().GetShowMode();
175 if (showMode != FRAME_SHOW_MODE_FULL_SCREEN)
177 if (showMode == FRAME_SHOW_MODE_MINIMIZED)
179 if (GetCore().GetShowMode(false) != FRAME_SHOW_MODE_FULL_SCREEN)
181 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.");
186 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.");
191 r = MoveChildToTop(*pNewCurForm);
192 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
194 // [ToDo] Change the method to return result. And the arg should be reference.
195 GetCore().SetCurrentForm(&pNewCurForm->GetCore());
197 SysAssert(r == E_SUCCESS); // [ToDo] Exception check.
199 pNewCurForm->UpdateOrientationStatus();
201 // [ToDo] Check last result
202 SysAssert(GetLastResult() == E_SUCCESS);
207 _FrameImpl::SetCurrentForm(_FormImpl* pFormImpl)
209 result r = E_SUCCESS;
211 _FormImpl* pNewCurForm = pFormImpl;
213 SysTryReturn(NID_UI_CTRL,
214 pNewCurForm != null, E_INVALID_ARG,
215 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not initialized.");
217 SysTryReturn(NID_UI_CTRL,
218 IsAncestorOf(pNewCurForm), E_INVALID_ARG,
219 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not the child of this Frame.");
221 if (GetCore().GetShowMode() != FRAME_SHOW_MODE_FULL_SCREEN)
223 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.");
227 r = MoveChildToTop(*pNewCurForm);
228 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
230 // [ToDo] Change the method to return result. And the arg should be reference.
231 GetCore().SetCurrentForm(&pNewCurForm->GetCore());
233 SysAssert(r == E_SUCCESS); // [ToDo] Exception check.
235 pNewCurForm->UpdateOrientationStatus();
237 // [ToDo] Check last result
238 SysAssert(GetLastResult() == E_SUCCESS);
242 // [ToDo] This function should return _FormImpl*.
244 _FrameImpl::GetCurrentForm(void) const
246 _Control* pFormCore = GetCore().GetCurrentForm();
247 SysTryReturn(NID_UI_CTRL, pFormCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
249 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pFormCore->GetUserData());
255 _FrameImpl::CreateFrameImplN(Frame* pPublic)
258 result r = E_SUCCESS;
260 _Frame* pCore = _Frame::CreateFrameN();
261 SysTryReturn(NID_UI_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
263 _FrameImpl* pImpl = new (std::nothrow) _FrameImpl(pPublic, pCore);
264 r = _ControlImpl::CheckConstruction(pCore, pImpl);
265 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
267 pCore->SetSize(_ControlManager::GetInstance()->GetScreenSizeF());
269 pCore->AddFrameEventListener(*pImpl);
271 SetLastResult(E_SUCCESS);
277 _FrameImpl::AddFrameEventListener(IFrameEventListener& listener)
279 result r = __pFrameEvent->AddListener(listener);
280 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
284 _FrameImpl::RemoveFrameEventListener(IFrameEventListener& listener)
286 result r = __pFrameEvent->RemoveListener(listener);
287 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
290 Animations::FrameAnimator*
291 _FrameImpl::GetFrameAnimator(void) const
293 if (__pFrameAnimator == null)
295 FrameAnimator* pFrameAnimator = new (std::nothrow) FrameAnimator();
296 SysTryReturn(NID_UI_CTRL,
297 pFrameAnimator != null, null,
298 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
300 result r = pFrameAnimator->Construct(GetPublic());
303 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] FrameAnimator::Construct failed");
304 delete pFrameAnimator;
308 const_cast<_FrameImpl*>(this)->__pFrameAnimator = pFrameAnimator;
311 SetLastResult(E_SUCCESS);
313 return __pFrameAnimator;
317 _FrameImpl::OnDraw(void)
319 if (__pOrientationAgent)
321 __pOrientationAgent->FireOrientationEvent();
324 _WindowImpl::OnDraw();
328 _FrameImpl::OnChangeLayout(_ControlOrientation orientation)
331 _ContainerImpl::OnChangeLayout(orientation);
332 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
334 bool resizable = IsResizable();
337 _ControlManager* pCoreManager = _ControlManager::GetInstance();
338 SysAssert(pCoreManager);
339 const FloatDimension& screenSize = pCoreManager->GetScreenSizeF();
341 FrameShowMode frameShowMode = GetCore().GetShowMode();
343 if (frameShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
345 GetCore().SetRotation(true);
347 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
353 SetSize(FloatDimension(screenSize.height, screenSize.width));
356 GetCore().SetRotation(false);
358 else if ((frameShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (frameShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
360 bool movable = IsMovable();
363 FloatPoint prevPoint = GetPositionF();
364 FloatPoint curPoint(prevPoint.x, prevPoint.y);
365 float ratio = screenSize.width / screenSize.height;
366 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
368 if (prevPoint.x > 0.0f)
370 curPoint.x = prevPoint.x * ratio;
373 if (prevPoint.y > 0.0f)
375 curPoint.y = prevPoint.y / ratio;
380 if (prevPoint.x > 0.0f)
382 curPoint.x = prevPoint.x / ratio;
385 if (prevPoint.y > 0.0f)
387 curPoint.y = prevPoint.y * ratio;
391 SetPosition(curPoint);
395 SetResizable(resizable);
399 _FrameImpl::OnChildDetaching(const _Control& child)
401 result r = E_SUCCESS;
403 _FormImpl* pFormImpl = static_cast<_FormImpl*>(child.GetUserData());
405 _FormImpl* pCurrentForm = GetCurrentForm();
407 if (pCurrentForm != null)
409 if (pCurrentForm == pFormImpl)
411 // if the given control will be the current form, hide the current form
412 int count = GetChildCount();
415 _ControlImpl* pControlImpl = GetChild(count - 2);
421 Form* pPrevForm = static_cast<Form*>(&pControlImpl->GetPublic());
423 if (pPrevForm != null)
425 r = pPrevForm->SetShowState(true);
428 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
438 _FrameImpl::OnChildDetached(const _Control& child)
440 _ControlImpl::OnChildDetached(child);
442 int childCount = GetCore().GetChildCount();
445 UpdateOrientationStatus();
447 else if (childCount > 0)
449 _Control* pControl = GetCore().GetChild(childCount - 1);
450 _ControlImpl* pControlImpl = static_cast<_ControlImpl*>(pControl->GetUserData());
451 _FormImpl* pCurrentFormImpl = dynamic_cast<_FormImpl*>(pControlImpl);
452 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentFormImpl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
453 pCurrentFormImpl->UpdateOrientationStatus(true);
458 _FrameImpl::OnFrameActivated(const _Frame& source)
462 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_ACTIVATED);
465 __pFrameEvent->Fire(*pEventArg);
471 _FrameImpl::OnFrameDeactivated(const _Frame& source)
475 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_DEACTIVATED);
478 __pFrameEvent->Fire(*pEventArg);
484 _FrameImpl::OnFrameMinimized(const _Frame& source)
488 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_MINIMIZED);
491 __pFrameEvent->Fire(*pEventArg);
497 _FrameImpl::OnFrameRestored(const _Frame& source)
501 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_RESTORED);
504 __pFrameEvent->Fire(*pEventArg);
510 _FrameImpl::OnBoundsChanged(void)
512 int childcount = GetChildCount();
513 FloatRectangle bounds = GetBoundsF();
515 for (int i = 0 ; i < childcount ; i++)
517 _ControlImpl* pChild = GetChild(i);
518 _FormImpl* pForm = dynamic_cast<_FormImpl*>(pChild);
521 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
523 if (pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE)
525 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
529 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.height, bounds.width));
534 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
540 _ContainerImpl::OnBoundsChanged();
545 _FrameImpl::OnAttachedToMainTree(void)
547 result r = _WindowImpl::OnAttachedToMainTree();
548 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
550 if (__pOrientationAgent)
552 __pOrientationAgent->RequestOrientationEvent();
559 _FrameImpl::OnDetachingFromMainTree(void)
561 result r = _WindowImpl::OnDetachingFromMainTree();
562 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
564 delete __pFrameAnimator;
565 __pFrameAnimator = null;
571 _FrameImpl::OnNotifiedN(const _ControlImpl& source, IList* pArgs)
573 String* pString = dynamic_cast <Tizen::Base::String*>(pArgs->GetAt(0));
576 if (*pString == _REQUEST_ORIENTATION_EVENT)
578 if (__pOrientationAgent)
580 __pOrientationAgent->FireOrientationEvent();
583 pArgs->RemoveAll(true);
594 _FrameImpl::AddOrientationEventListener(Tizen::Ui::IOrientationEventListener& listener)
596 if (__pOrientationAgent)
598 __pOrientationAgent->AddListener(listener);
600 else if (__pImeOrientationAgent)
602 __pImeOrientationAgent->AddListener(listener);
607 _FrameImpl::RemoveOrientationEventListener(Tizen::Ui::IOrientationEventListener& listener)
609 if (__pOrientationAgent)
611 __pOrientationAgent->RemoveListener(listener);
613 else if (__pImeOrientationAgent)
615 __pImeOrientationAgent->RemoveListener(listener);
620 _FrameImpl::SetOrientation(Orientation orientation)
622 if (__pOrientationAgent)
624 __pOrientationAgent->SetMode(orientation);
629 _FrameImpl::GetOrientation(void) const
631 if (__pOrientationAgent)
633 return __pOrientationAgent->GetMode();
636 return ORIENTATION_NONE;
640 _FrameImpl::GetOrientationStatus(void) const
642 if (__pOrientationAgent)
644 return __pOrientationAgent->GetStatus();
646 else if (__pImeOrientationAgent)
648 return __pImeOrientationAgent->GetStatus();
651 return ORIENTATION_STATUS_NONE;
655 _FrameImpl::IsChildAttachable(_ControlImpl& child) const
657 return (dynamic_cast<_FormImpl*>(&child) != null);
661 _FrameImpl::UpdateOrientationStatus(void)
663 if (__pOrientationAgent)
665 __pOrientationAgent->Update();
670 _FrameImpl::UpdateOrientation(void)
672 if (__pOrientationAgent)
674 __pOrientationAgent->UpdateOrientation();
679 _FrameImpl::UpdateOrientation(int angle)
681 SysLog(NID_UI_CTRL, "[Ime Rotation]");
683 if (__pImeOrientationAgent)
685 __pImeOrientationAgent->UpdateOrientation(angle);
690 _FrameImpl::IsOpaque(void) const
697 _FrameImpl::SetFloatingBounds(const FloatRectangle& rect)
699 GetCore().SetFloatingBounds(rect);
703 _FrameImpl::SetFloatingBounds(const Rectangle& rect)
705 GetCore().SetFloatingBounds(rect);
709 _FrameImpl::SetShowMode(FrameShowMode showMode)
711 return GetCore().SetShowMode(showMode);
715 _FrameImpl::GetShowMode(void) const
717 return GetCore().GetShowMode();
720 }}} // Tizen::Ui::Controls