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;
44 const wchar_t* _REQUEST_ORIENTATION_EVENT = L"RequestOrientationEvent";
47 namespace Tizen { namespace Ui { namespace Controls {
51 _FrameImpl::GetInstance(const Frame& frame)
53 return static_cast<const _FrameImpl*> (frame._pControlImpl);
57 _FrameImpl::GetInstance(Frame& frame)
59 return static_cast<_FrameImpl*> (frame._pControlImpl);
63 _FrameImpl::Dispose(void)
65 GetCore().RemoveFrameEventListener(*this);
73 if (__pOrientationAgent)
75 delete __pOrientationAgent;
76 __pOrientationAgent = null;
79 if (__pImeOrientationAgent)
81 delete __pImeOrientationAgent;
82 __pImeOrientationAgent = null;
85 delete __pFrameAnimator;
86 __pFrameAnimator = null;
89 _FrameImpl::_FrameImpl(Frame* pPublic, _Frame* pCore)
90 : _WindowImpl(pPublic, pCore)
92 , __pFrameAnimator(null)
93 , __pOrientationAgent(null)
94 , __pImeOrientationAgent(null)
96 __pFrameEvent = _PublicFrameEvent::CreateInstanceN(*pPublic);
97 SysTryReturnVoidResult(NID_UI_CTRL, __pFrameEvent, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
99 int appType = _AppInfo::GetAppType();
100 if (appType & _APP_TYPE_IME_APP)
102 __pImeOrientationAgent = _ImeOrientationAgent::CreateInstanceN(*pPublic);
103 SysTryCatch(NID_UI_CTRL, __pImeOrientationAgent != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
107 __pOrientationAgent = _OrientationAgent::CreateInstanceN(*pPublic);
108 SysTryCatch(NID_UI_CTRL, __pOrientationAgent != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
117 _FrameImpl::~_FrameImpl(void)
119 // [ToDo] Wrong point to call OnFrameTerminating().
122 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_TERMINATING);
125 __pFrameEvent->Fire(*pEventArg);
134 _FrameImpl::GetPublicClassName(void) const
136 return "Tizen::Ui::Controls::Frame";
140 _FrameImpl::GetPublic(void) const
142 return static_cast<const Frame&>(_ControlImpl::GetPublic());
146 _FrameImpl::GetPublic(void)
148 return static_cast<Frame&>(_ControlImpl::GetPublic());
152 _FrameImpl::GetCore(void) const
154 return static_cast<const _Frame&>(_ControlImpl::GetCore());
158 _FrameImpl::GetCore(void)
160 return static_cast<_Frame&>(_ControlImpl::GetCore());
164 _FrameImpl::SetCurrentForm(const _FormImpl& formImpl)
166 result r = E_SUCCESS;
168 _FormImpl* pNewCurForm = const_cast<_FormImpl*>(&formImpl);
170 SysTryReturn(NID_UI_CTRL,
171 pNewCurForm != null, E_INVALID_ARG,
172 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not initialized.");
174 SysTryReturn(NID_UI_CTRL,
175 IsAncestorOf(pNewCurForm), E_INVALID_ARG,
176 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not the child of this Frame.");
178 FrameShowMode showMode = GetCore().GetShowMode();
179 if (showMode != FRAME_SHOW_MODE_FULL_SCREEN)
181 if (showMode == FRAME_SHOW_MODE_MINIMIZED)
183 if (GetCore().GetShowMode(false) != FRAME_SHOW_MODE_FULL_SCREEN)
185 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.");
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.");
195 r = MoveChildToTop(*pNewCurForm);
196 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
198 // [ToDo] Change the method to return result. And the arg should be reference.
199 GetCore().SetCurrentForm(&pNewCurForm->GetCore());
201 SysAssert(r == E_SUCCESS); // [ToDo] Exception check.
203 pNewCurForm->UpdateOrientationStatus();
205 // [ToDo] Check last result
206 SysAssert(GetLastResult() == E_SUCCESS);
211 _FrameImpl::SetCurrentForm(_FormImpl* pFormImpl)
213 result r = E_SUCCESS;
215 _FormImpl* pNewCurForm = pFormImpl;
217 SysTryReturn(NID_UI_CTRL,
218 pNewCurForm != null, E_INVALID_ARG,
219 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not initialized.");
221 SysTryReturn(NID_UI_CTRL,
222 IsAncestorOf(pNewCurForm), E_INVALID_ARG,
223 E_INVALID_ARG, "[E_INVALID_ARG] The Form is not the child of this Frame.");
225 if (GetCore().GetShowMode() != FRAME_SHOW_MODE_FULL_SCREEN)
227 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.");
231 r = MoveChildToTop(*pNewCurForm);
232 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
234 // [ToDo] Change the method to return result. And the arg should be reference.
235 GetCore().SetCurrentForm(&pNewCurForm->GetCore());
237 SysAssert(r == E_SUCCESS); // [ToDo] Exception check.
239 pNewCurForm->UpdateOrientationStatus();
241 // [ToDo] Check last result
242 SysAssert(GetLastResult() == E_SUCCESS);
246 // [ToDo] This function should return _FormImpl*.
248 _FrameImpl::GetCurrentForm(void) const
250 _Control* pFormCore = GetCore().GetCurrentForm();
251 SysTryReturn(NID_UI_CTRL, pFormCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
253 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pFormCore->GetUserData());
259 _FrameImpl::CreateFrameImplN(Frame* pPublic)
262 result r = E_SUCCESS;
264 _Frame* pCore = _Frame::CreateFrameN();
265 SysTryReturn(NID_UI_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
267 _FrameImpl* pImpl = new (std::nothrow) _FrameImpl(pPublic, pCore);
268 r = _ControlImpl::CheckConstruction(pCore, pImpl);
269 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
271 pCore->SetSize(_ControlManager::GetInstance()->GetScreenSizeF());
273 pCore->AddFrameEventListener(*pImpl);
275 SetLastResult(E_SUCCESS);
281 _FrameImpl::AddFrameEventListener(IFrameEventListener& listener)
283 result r = __pFrameEvent->AddListener(listener);
284 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
288 _FrameImpl::RemoveFrameEventListener(IFrameEventListener& listener)
290 result r = __pFrameEvent->RemoveListener(listener);
291 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
294 Animations::FrameAnimator*
295 _FrameImpl::GetFrameAnimator(void) const
297 if (__pFrameAnimator == null)
299 FrameAnimator* pFrameAnimator = new (std::nothrow) FrameAnimator();
300 SysTryReturn(NID_UI_CTRL,
301 pFrameAnimator != null, null,
302 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
304 result r = pFrameAnimator->Construct(GetPublic());
307 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] FrameAnimator::Construct failed");
308 delete pFrameAnimator;
312 const_cast<_FrameImpl*>(this)->__pFrameAnimator = pFrameAnimator;
315 SetLastResult(E_SUCCESS);
317 return __pFrameAnimator;
321 _FrameImpl::OnDraw(void)
323 if (__pOrientationAgent)
325 __pOrientationAgent->FireOrientationEvent();
328 _WindowImpl::OnDraw();
332 _FrameImpl::OnChangeLayout(_ControlOrientation orientation)
335 _ContainerImpl::OnChangeLayout(orientation);
336 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
338 bool resizable = IsResizable();
341 _ControlManager* pCoreManager = _ControlManager::GetInstance();
342 SysAssert(pCoreManager);
343 const FloatDimension& screenSize = pCoreManager->GetScreenSizeF();
345 FrameShowMode frameShowMode = GetCore().GetShowMode();
347 if (frameShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
349 GetCore().SetRotation(true);
351 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
357 SetSize(FloatDimension(screenSize.height, screenSize.width));
360 GetCore().SetRotation(false);
362 else if ((frameShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (frameShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
364 bool movable = IsMovable();
367 FloatPoint prevPoint = GetPositionF();
368 FloatPoint curPoint(prevPoint.x, prevPoint.y);
369 float ratio = screenSize.width / screenSize.height;
370 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
372 if (prevPoint.x > 0.0f)
374 curPoint.x = prevPoint.x * ratio;
377 if (prevPoint.y > 0.0f)
379 curPoint.y = prevPoint.y / ratio;
384 if (prevPoint.x > 0.0f)
386 curPoint.x = prevPoint.x / ratio;
389 if (prevPoint.y > 0.0f)
391 curPoint.y = prevPoint.y * ratio;
395 SetPosition(curPoint);
397 GetCore().SetFloatingOrientation(orientation);
400 SetResizable(resizable);
404 _FrameImpl::OnChildDetaching(const _Control& child)
406 result r = E_SUCCESS;
408 _FormImpl* pFormImpl = static_cast<_FormImpl*>(child.GetUserData());
410 _FormImpl* pCurrentForm = GetCurrentForm();
412 if (pCurrentForm != null)
414 if (pCurrentForm == pFormImpl)
416 // if the given control will be the current form, hide the current form
417 int count = GetChildCount();
420 _ControlImpl* pControlImpl = GetChild(count - 2);
426 Form* pPrevForm = static_cast<Form*>(&pControlImpl->GetPublic());
428 if (pPrevForm != null)
430 r = pPrevForm->SetShowState(true);
433 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
443 _FrameImpl::OnChildDetached(const _Control& child)
445 _ControlImpl::OnChildDetached(child);
447 int childCount = GetCore().GetChildCount();
450 UpdateOrientationStatus();
452 else if (childCount > 0)
454 _Control* pControl = GetCore().GetChild(childCount - 1);
455 _ControlImpl* pControlImpl = static_cast<_ControlImpl*>(pControl->GetUserData());
456 _FormImpl* pCurrentFormImpl = dynamic_cast<_FormImpl*>(pControlImpl);
457 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentFormImpl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
458 pCurrentFormImpl->UpdateOrientationStatus(true);
463 _FrameImpl::OnFrameActivated(const _Frame& source)
467 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_ACTIVATED);
470 __pFrameEvent->Fire(*pEventArg);
476 _FrameImpl::OnFrameDeactivated(const _Frame& source)
480 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_DEACTIVATED);
483 __pFrameEvent->Fire(*pEventArg);
489 _FrameImpl::OnFrameMinimized(const _Frame& source)
493 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_MINIMIZED);
496 __pFrameEvent->Fire(*pEventArg);
502 _FrameImpl::OnFrameRestored(const _Frame& source)
506 IEventArg* pEventArg = _PublicFrameEvent::CreateFrameEventArgN(_FrameImpl::GetPublic(), FRAME_STATE_RESTORED);
509 __pFrameEvent->Fire(*pEventArg);
515 _FrameImpl::OnBoundsChanged(void)
517 int childcount = GetChildCount();
518 FloatRectangle bounds = GetBoundsF();
520 for (int i = 0 ; i < childcount ; i++)
522 _ControlImpl* pChild = GetChild(i);
523 _FormImpl* pForm = dynamic_cast<_FormImpl*>(pChild);
526 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
528 if (pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE)
530 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
534 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.height, bounds.width));
539 pForm->SetBounds(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
545 _ContainerImpl::OnBoundsChanged();
550 _FrameImpl::OnAttachedToMainTree(void)
552 result r = _WindowImpl::OnAttachedToMainTree();
553 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
555 if (__pOrientationAgent)
557 __pOrientationAgent->RequestOrientationEvent();
564 _FrameImpl::OnDetachingFromMainTree(void)
566 result r = _WindowImpl::OnDetachingFromMainTree();
567 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
569 delete __pFrameAnimator;
570 __pFrameAnimator = null;
576 _FrameImpl::OnNotifiedN(const _ControlImpl& source, IList* pArgs)
578 String* pString = dynamic_cast <Tizen::Base::String*>(pArgs->GetAt(0));
581 if (*pString == _REQUEST_ORIENTATION_EVENT)
583 if (__pOrientationAgent)
585 __pOrientationAgent->FireOrientationEvent();
588 pArgs->RemoveAll(true);
599 _FrameImpl::AddOrientationEventListener(Tizen::Ui::IOrientationEventListener& listener)
601 if (__pOrientationAgent)
603 __pOrientationAgent->AddListener(listener);
605 else if (__pImeOrientationAgent)
607 __pImeOrientationAgent->AddListener(listener);
612 _FrameImpl::RemoveOrientationEventListener(Tizen::Ui::IOrientationEventListener& listener)
614 if (__pOrientationAgent)
616 __pOrientationAgent->RemoveListener(listener);
618 else if (__pImeOrientationAgent)
620 __pImeOrientationAgent->RemoveListener(listener);
625 _FrameImpl::SetOrientation(Orientation orientation)
627 if (__pOrientationAgent)
629 __pOrientationAgent->SetMode(orientation);
634 _FrameImpl::GetOrientation(void) const
636 if (__pOrientationAgent)
638 return __pOrientationAgent->GetMode();
641 return ORIENTATION_NONE;
645 _FrameImpl::GetOrientationStatus(void) const
647 if (__pOrientationAgent)
649 return __pOrientationAgent->GetStatus();
651 else if (__pImeOrientationAgent)
653 return __pImeOrientationAgent->GetStatus();
656 return ORIENTATION_STATUS_NONE;
660 _FrameImpl::IsChildAttachable(_ControlImpl& child) const
662 return (dynamic_cast<_FormImpl*>(&child) != null);
666 _FrameImpl::UpdateOrientationStatus(void)
668 if (__pOrientationAgent)
670 __pOrientationAgent->Update();
675 _FrameImpl::UpdateOrientation(void)
677 if (__pOrientationAgent)
679 __pOrientationAgent->UpdateOrientation();
684 _FrameImpl::UpdateOrientation(int angle)
686 SysLog(NID_UI_CTRL, "[Ime Rotation]");
688 if (__pImeOrientationAgent)
690 __pImeOrientationAgent->UpdateOrientation(angle);
695 _FrameImpl::IsOpaque(void) const
702 _FrameImpl::SetFloatingBounds(const FloatRectangle& rect)
704 GetCore().SetFloatingBounds(rect);
708 _FrameImpl::SetFloatingBounds(const Rectangle& rect)
710 GetCore().SetFloatingBounds(rect);
714 _FrameImpl::SetShowMode(FrameShowMode showMode)
716 return GetCore().SetShowMode(showMode);
720 _FrameImpl::GetShowMode(void) const
722 return GetCore().GetShowMode();
725 }}} // Tizen::Ui::Controls