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.
18 * @file FUiCtrl_Frame.cpp
19 * @brief This is the implementation file for the _Frame class.
23 #include <FBaseErrorDefine.h>
24 #include <FBaseInteger.h>
25 #include <FBaseSysLog.h>
26 #include <FApp_AppInfo.h>
27 #include "FUi_UiNotificationEvent.h"
28 #include "FUi_UiEventManager.h"
29 #include "FUi_ControlManager.h"
30 #include "FUi_EcoreEvasMgr.h"
31 #include "FUi_EcoreEvas.h"
32 #include "FUi_TouchManager.h"
33 #include "FUi_CoordinateSystemUtils.h"
34 #include "FUiCtrl_Frame.h"
35 #include "FUiCtrl_FramePresenter.h"
36 #include "FUiCtrl_FrameEvent.h"
37 #include "FUiCtrl_IFrameEventListener.h"
38 #include "FUiCtrl_IFormActivationChangeEventListener.h"
39 #include "FUiCtrl_Form.h"
40 #include "FUiCtrl_FormImpl.h"
41 #include "FUiCtrl_FrameImpl.h"
42 #include "FUiAnim_VisualElement.h"
43 #include "FUiAnim_RootVisualElement.h"
44 #include "FUiAnim_EflLayer.h"
45 #include "FUi_AccessibilityManager.h"
47 using namespace Tizen::App;
48 using namespace Tizen::Ui::Animations;
49 using namespace Tizen::Ui;
50 using namespace Tizen::Ui::Controls;
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Base::Runtime;
54 using namespace Tizen::Graphics;
56 namespace Tizen { namespace Ui { namespace Controls {
58 const String _ACTIVATE_FRAME = L"ActivateFrame";
61 : __pFramePresenter(null)
63 , __floatingBounds(0.0f, 0.0f, 0.0f, 0.0f)
64 , __showMode(FRAME_SHOW_MODE_FULL_SCREEN)
68 , __constructed(false)
70 , __changingBoundsEnabled(true)
71 , __pFormActivationChangeEventListener(null)
73 _FramePresenter* pPresenter = new (std::nothrow) _FramePresenter(*this);
74 SysTryReturnVoidResult(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
76 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
77 __floatingBounds.width = screen.width;
78 __floatingBounds.height = screen.height;
80 __pFrameEvent = _FrameEvent::CreateInstanceN(*this);
81 SysTryCatch(NID_UI_CTRL, __pFrameEvent, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
83 SetPresenter(*pPresenter);
84 SetClipChildrenEnabled(false);
100 __pFrameEvent = null;
103 delete __pFramePresenter;
104 __pFramePresenter = null;
110 _Frame::CreateFrameN(void)
112 result r = E_SUCCESS;
113 _RootVisualElement* pRootVE = null;
114 _EflLayer* pLayer = null;
115 int appType = _AppInfo::GetAppType();
117 _Frame* pFrame = new (std::nothrow) _Frame;
118 SysTryCatch(NID_UI_CTRL, pFrame, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
119 SysTryCatch(NID_UI_CTRL, GetLastResult() == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
121 if (appType & _APP_TYPE_IME_APP)
123 SysLog(NID_UI_CTRL, "[Ime Rotation]");
124 r = pFrame->CreateRootVisualElement(_WINDOW_TYPE_SUB);
125 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
129 r = pFrame->CreateRootVisualElement();
130 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
133 pRootVE = pFrame->GetRootVisualElement();
136 pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
139 if (!(appType & _APP_TYPE_IME_APP))
141 pLayer->SetOpacity(1);
144 pFrame->AcquireHandle();
146 SetLastResult(E_SUCCESS);
157 _Frame::SetPresenter(const _FramePresenter& framePresenter)
159 __pFramePresenter = const_cast <_FramePresenter*>(&framePresenter);
167 if (__pFramePresenter)
169 __pFramePresenter->Draw();
174 _Frame::OnActivated(void)
176 SysLog(NID_UI, "activated(%d)", __activated);
183 _Window::OnActivated();
185 _Form* pCurrentForm = GetCurrentForm();
186 if (pCurrentForm == null)
191 pCurrentForm->AddIndicatorObject();
193 _Control* pFocusControl = pCurrentForm->GetFocusControl();
196 pFocusControl->SetFocused();
200 pCurrentForm->SetFocused();
202 _AccessibilityManager::GetInstance()->RequestAutoReading(_ACCESSIBILITY_AUTO_READING_MODE_FIRST_ITEM);
206 _Frame::OnNotifiedN(const _Control& source, IList* pArgs)
208 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
210 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
211 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
213 if (*pType == L"VisibilityEvent")
217 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
218 if (pObscured == null)
220 pArgs->RemoveAll(true);
226 obscured = pObscured->ToInt();
235 OnFrameDeactivated();
238 pArgs->RemoveAll(true);
243 else if (*pType == _ACTIVATE_FRAME)
245 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
248 pEcoreEvas->ActivateWindow(*this);
251 pArgs->RemoveAll(true);
261 _Frame::OnFrameActivated(void)
263 int childcount = GetChildCount();
265 for (int i = 0 ; i < childcount ; i++)
267 _Control* pChild = GetChild(i);
268 _Form* pForm = dynamic_cast<_Form*>(pChild);
271 pForm->MoveOverlayRegion(true);
276 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_ACTIVATED);
277 __pFrameEvent->Fire(*pArg);
279 if (GetChildCount() < 1)
281 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
282 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
284 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
286 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
292 _Frame::OnFrameDeactivated(void)
294 int childcount = GetChildCount();
296 for (int i = 0 ; i < childcount ; i++)
298 _Control* pChild = GetChild(i);
299 _Form* pForm = dynamic_cast<_Form*>(pChild);
302 pForm->MoveOverlayRegion(false);
307 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_DEACTIVATED);
308 __pFrameEvent->Fire(*pArg);
310 _TouchManager* pTouchManager = _TouchManager::GetInstance();
313 pTouchManager->SetTouchCanceled(null);
318 _Frame::OnFrameMinimized(void)
320 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_MINIMIZED);
321 __pFrameEvent->Fire(*pArg);
325 _Frame::OnFrameRestored(void)
329 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_RESTORED);
330 __pFrameEvent->Fire(*pArg);
334 _Frame::SetCurrentForm(const _Form* pForm)
336 result r = E_SUCCESS;
338 SysTryReturnVoidResult(NID_UI_CTRL, pForm != null, E_INVALID_ARG, "[E_INVALID_ARG] Form to become a new current form is null");
339 _Form* pNewForm = const_cast<_Form*>(pForm);
341 _Form* pCurrentForm = GetCurrentForm();
342 pNewForm->AddIndicatorObject();
344 if (pCurrentForm != null)
346 if (pCurrentForm != pForm)
349 r = MoveChildToTop(*pForm);
350 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
351 pNewForm->MoveOverlayRegion(true);
353 pCurrentForm->SetVisibleState(false);
354 pCurrentForm->MoveOverlayRegion(false);
356 if (__pFormActivationChangeEventListener)
357 __pFormActivationChangeEventListener->OnFormDeactivated(*pCurrentForm);
361 pNewForm->SetVisibleState(true);
362 _Control* pFocus = pNewForm->GetFocusControl();
365 pFocus->SetFocused();
369 pNewForm->SetFocused();
372 pNewForm->SetUpdateLayoutState(true);
374 if (__pFormActivationChangeEventListener)
375 __pFormActivationChangeEventListener->OnFormActivated(*pNewForm);
377 SetLastResult(E_SUCCESS);
383 _Frame::GetCurrentForm(void) const
385 _Form* pCurrentForm = null;
386 int controlCount = GetChildCount();
388 if (controlCount > 0)
390 for (int i = controlCount; i > 0; i--)
392 pCurrentForm = dynamic_cast<_Form*>(GetChild(i - 1));
393 SysTryReturn(NID_UI_CTRL, pCurrentForm != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
394 if (pCurrentForm->IsVisible())
405 _Frame::IsOrientationRoot(void) const
411 _Frame::SetRotation(bool rotation)
413 __rotation = rotation;
417 _Frame::AddFrameEventListener(const _IFrameEventListener& listener)
419 __constructed = true;
421 result r = __pFrameEvent->AddListener(listener);
422 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
426 _Frame::RemoveFrameEventListener(const _IFrameEventListener& listener)
428 result r = __pFrameEvent->RemoveListener(listener);
429 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
433 _Frame::SetFormActivationChangeEventListener(const _IFormActivationChangeEventListener* plistener)
435 __pFormActivationChangeEventListener = const_cast<_IFormActivationChangeEventListener*>(plistener);
440 _Frame::SetFloatingBounds(const FloatRectangle& rect)
442 __floatingBounds = rect;
446 _Frame::SetFloatingBounds(const Rectangle& rect)
448 __floatingBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
452 _Frame::SetShowMode(FrameShowMode showMode)
454 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
455 SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "The method cannot proceed due to a severe system error.");
457 if (showMode == FRAME_SHOW_MODE_MINIMIZED)
459 if (__minimized == true)
464 pEcoreEvas->MinimizeWindow(*GetRootWindow());
471 if (__minimized == true)
477 bool changeMode = true;
479 if ((showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
481 _Form* pCurrentForm = GetCurrentForm();
485 if (pCurrentForm->GetFormStyle() & _FORM_STYLE_INDICATOR)
492 SysTryReturnResult(NID_UI_CTRL, changeMode == true, E_SYSTEM, "The method cannot proceed due to a severe system error.");
494 int oldShowMode = __showMode;
495 __showMode = showMode;
497 result r = E_SUCCESS;
501 case FRAME_SHOW_MODE_FULL_SCREEN:
502 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
504 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
505 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
508 if (oldShowMode != FRAME_SHOW_MODE_FULL_SCREEN)
510 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
514 if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
516 SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
520 SetBounds(FloatRectangle(0.0f, 0.0f, screen.height, screen.width));
527 case FRAME_SHOW_MODE_PARTIAL_SCREEN:
528 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
530 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
531 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
534 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
536 SetBounds(__floatingBounds);
538 else if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
540 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(__floatingBounds));
544 case FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING:
545 if (oldShowMode != FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
547 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), true);
548 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
551 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
553 SetBounds(__floatingBounds);
565 _Frame::GetShowMode(bool minimize) const
569 if (__minimized == true)
571 return FRAME_SHOW_MODE_MINIMIZED;
585 _Frame::IsActivated(void) const
591 _Frame::OnChildAttached(const _Control& child)
593 _Form* pCurrentForm = GetCurrentForm();
595 if (pCurrentForm == &child)
597 int controlCount = GetChildCount();
599 if (controlCount > 1)
601 _Control* pOldCurrentForm = GetChild(controlCount - 2);
602 SysTryReturnVoidResult(NID_UI_CTRL, pOldCurrentForm != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
603 pOldCurrentForm->SetVisibleState(false);
609 _Frame::OnChildDetached(const _Control& child)
611 int controlCount = GetChildCount();
613 if (controlCount > 0)
615 _Control* pCurrentForm = GetChild(controlCount - 1);
616 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
617 pCurrentForm->SetVisibleState(true);
621 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
622 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
623 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
628 _Frame::OnBoundsChanging(const FloatRectangle& bounds)
630 int appType = _AppInfo::GetAppType();
631 if (appType & _APP_TYPE_IME_APP)
633 SysLog(NID_UI_CTRL, "[Ime Rotation]");
637 if (__restore == false)
639 __floatingBounds = bounds;
642 if ((__showMode == FRAME_SHOW_MODE_FULL_SCREEN) && (__restore == false))
644 if (__constructed == false)
650 if (__rotation == true)
656 return E_UNSUPPORTED_OPERATION;
661 if (__changingBoundsEnabled == false)
666 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
667 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
669 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(bounds));
670 result r = GetLastResult();
671 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
678 _Frame::OnAttached(void)
680 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
681 SysAssert(pEcoreEvas);
683 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), true);
689 _Frame::OnBackgroundColorChanged(Color& backgroundColor)
691 _RootVisualElement* pRootVE = GetRootVisualElement();
694 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
697 byte alpha = backgroundColor.GetAlpha();
698 float opacity = static_cast<float>(alpha) / 255.0f;
700 pLayer->SetOpacity(opacity);
703 FrameShowMode showMode = GetShowMode(false);
704 SetShowMode(FRAME_SHOW_MODE_FULL_SCREEN);
706 SetShowMode(showMode);
708 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
714 Orientation mode = ORIENTATION_PORTRAIT;
716 _Form* pCurrentForm = GetCurrentForm();
719 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pCurrentForm->GetUserData());
722 mode = pFormImpl->GetOrientation();
727 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
730 mode = pFrameImpl->GetOrientation();
736 case ORIENTATION_PORTRAIT:
737 pEcoreEvas->SetWindowPreferredRotation(*this, 0, true);
739 case ORIENTATION_LANDSCAPE:
740 pEcoreEvas->SetWindowPreferredRotation(*this, 270, true);
742 case ORIENTATION_PORTRAIT_REVERSE:
743 pEcoreEvas->SetWindowPreferredRotation(*this, 180, true);
745 case ORIENTATION_LANDSCAPE_REVERSE:
746 pEcoreEvas->SetWindowPreferredRotation(*this, 90, true);
748 case ORIENTATION_AUTOMATIC:
750 pEcoreEvas->SetWindowPreferredRotation(*this, -1);
751 int autoRotation[3] = {0, 90, 270};
752 pEcoreEvas->SetWindowAvailabledRotation(*this, autoRotation, 3, true);
755 case ORIENTATION_AUTOMATIC_FOUR_DIRECTION:
757 pEcoreEvas->SetWindowPreferredRotation(*this, -1);
758 int autoFourRotation[4] = {0, 90, 180, 270};
759 pEcoreEvas->SetWindowAvailabledRotation(*this, autoFourRotation, 4, true);
768 _Frame::ResetFocusList(void)
770 Tizen::Ui::Controls::_Form* pCurrentForm = GetCurrentForm();
773 pCurrentForm->ResetFocusList();
778 _Frame::GetFocusControl(const _Control* pControl) const
780 const _Form* pForm = null;
781 _Frame* pFrame = null;
782 const _Control* pTempControl = pControl;
785 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
789 pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
796 pTempControl = pTempControl->GetParent();
801 pTempControl = pTempControl->GetParent();
806 return pForm->GetFocusControl();
812 _Frame::GetCurrentFocusControl(void) const
814 _Form* pForm = GetCurrentForm();
817 return pForm->GetFocusControl();
822 _Frame::SetFocusControl(const _Control* pControl , bool on)
824 SysTryReturnVoidResult(NID_UI, pControl, E_SYSTEM, "[E_SYSTEM] The pControl cannot be NULL.");
825 _ControlManager* pControlMgr = _ControlManager::GetInstance();
826 SysAssert(pControlMgr);
828 _Form* pCurrentForm = GetCurrentForm();
829 _Frame* pFrame = null;
830 const _Control* pTempControl = pControl;
831 bool isCurrentForm = false;
835 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
839 pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
846 pTempControl = pTempControl->GetParent();
851 pTempControl = pTempControl->GetParent();
855 if (pForm == pCurrentForm)
857 isCurrentForm = true;
864 pForm->SetFocusControl(pControl);
867 pControlMgr->SetFocusControl(*pControl);
872 pControlMgr->SetFocusControl(*this, false);
879 _Frame::SetChangingBoundsEnabled(bool enable)
881 __changingBoundsEnabled = enable;
884 Tizen::Base::Collection::IListT<_Control*>*
885 _Frame::GetFocusList(void) const
887 _Form* pForm = GetCurrentForm();
890 return pForm->GetFocusList();
896 _Frame::GetFocusTraversalControl(_Control* pControl) const
899 _Control* pTempControl = pControl;
900 _Frame* pFrame = null;
903 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
907 pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
914 pTempControl = pTempControl->GetParent();
919 pTempControl = pTempControl->GetParent();
925 return pForm->GetFocusTraversalControl();
931 _Frame::SetFocusTraversalControl(_Control* pControl)
934 _Control* pTempControl = pControl;
935 _Frame* pFrame = null;
938 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
942 pFrame = dynamic_cast<_Frame*>(pForm->GetParent());
949 pTempControl = pTempControl->GetParent();
954 pTempControl = pTempControl->GetParent();
960 pForm->SetFocusTraversalControl(pControl);
963 }}} // Tizen::Ui::Controls