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)
348 _Control* pFocusTraversalControl = pCurrentForm->GetFocusTraversalControl();
349 if (pFocusTraversalControl)
351 pFocusTraversalControl->SetFocusModeStateEnabled(false) ;
354 r = MoveChildToTop(*pForm);
355 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
356 pNewForm->MoveOverlayRegion(true);
358 pCurrentForm->SetVisibleState(false);
359 pCurrentForm->MoveOverlayRegion(false);
361 if (__pFormActivationChangeEventListener)
362 __pFormActivationChangeEventListener->OnFormDeactivated(*pCurrentForm);
366 pNewForm->SetVisibleState(true);
367 _Control* pFocus = pNewForm->GetFocusControl();
370 pFocus->SetFocused();
374 pNewForm->SetFocused();
377 pNewForm->SetUpdateLayoutState(true);
379 if (__pFormActivationChangeEventListener)
380 __pFormActivationChangeEventListener->OnFormActivated(*pNewForm);
382 SetLastResult(E_SUCCESS);
388 _Frame::GetCurrentForm(void) const
390 _Form* pCurrentForm = null;
391 int controlCount = GetChildCount();
393 if (controlCount > 0)
395 for (int i = controlCount; i > 0; i--)
397 pCurrentForm = dynamic_cast<_Form*>(GetChild(i - 1));
398 SysTryReturn(NID_UI_CTRL, pCurrentForm != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
399 if (pCurrentForm->IsVisible())
410 _Frame::IsOrientationRoot(void) const
416 _Frame::SetRotation(bool rotation)
418 __rotation = rotation;
422 _Frame::AddFrameEventListener(const _IFrameEventListener& listener)
424 __constructed = true;
426 result r = __pFrameEvent->AddListener(listener);
427 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
431 _Frame::RemoveFrameEventListener(const _IFrameEventListener& listener)
433 result r = __pFrameEvent->RemoveListener(listener);
434 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
438 _Frame::SetFormActivationChangeEventListener(const _IFormActivationChangeEventListener* plistener)
440 __pFormActivationChangeEventListener = const_cast<_IFormActivationChangeEventListener*>(plistener);
445 _Frame::SetFloatingBounds(const FloatRectangle& rect)
447 __floatingBounds = rect;
451 _Frame::SetFloatingBounds(const Rectangle& rect)
453 __floatingBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
457 _Frame::SetShowMode(FrameShowMode showMode)
459 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
460 SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "The method cannot proceed due to a severe system error.");
462 if (showMode == FRAME_SHOW_MODE_MINIMIZED)
464 if (__minimized == true)
469 pEcoreEvas->MinimizeWindow(*GetRootWindow());
476 if (__minimized == true)
482 bool changeMode = true;
484 if ((showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
486 _Form* pCurrentForm = GetCurrentForm();
490 if (pCurrentForm->GetFormStyle() & _FORM_STYLE_INDICATOR)
497 SysTryReturnResult(NID_UI_CTRL, changeMode == true, E_SYSTEM, "The method cannot proceed due to a severe system error.");
499 int oldShowMode = __showMode;
500 __showMode = showMode;
502 result r = E_SUCCESS;
506 case FRAME_SHOW_MODE_FULL_SCREEN:
507 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
509 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
510 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
513 if (oldShowMode != FRAME_SHOW_MODE_FULL_SCREEN)
515 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
519 if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
521 SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
525 SetBounds(FloatRectangle(0.0f, 0.0f, screen.height, screen.width));
532 case FRAME_SHOW_MODE_PARTIAL_SCREEN:
533 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
535 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
536 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
539 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
541 SetBounds(__floatingBounds);
543 else if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
545 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(__floatingBounds));
549 case FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING:
550 if (oldShowMode != FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
552 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), true);
553 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
556 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
558 SetBounds(__floatingBounds);
570 _Frame::GetShowMode(bool minimize) const
574 if (__minimized == true)
576 return FRAME_SHOW_MODE_MINIMIZED;
590 _Frame::IsActivated(void) const
596 _Frame::OnChildAttached(const _Control& child)
598 _Form* pCurrentForm = GetCurrentForm();
600 if (pCurrentForm == &child)
602 int controlCount = GetChildCount();
604 if (controlCount > 1)
606 _Control* pOldCurrentForm = GetChild(controlCount - 2);
607 SysTryReturnVoidResult(NID_UI_CTRL, pOldCurrentForm != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
608 pOldCurrentForm->SetVisibleState(false);
609 _Form* pOldForm = static_cast<_Form*>(pOldCurrentForm);
612 _Control* pFocusTraversalControl = pOldForm->GetFocusTraversalControl();
613 if (pFocusTraversalControl)
615 pFocusTraversalControl->SetFocusModeStateEnabled(false) ;
623 _Frame::OnChildDetached(const _Control& child)
625 int controlCount = GetChildCount();
627 if (controlCount > 0)
629 _Control* pCurrentForm = GetChild(controlCount - 1);
630 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
631 pCurrentForm->SetVisibleState(true);
635 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
636 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
637 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
642 _Frame::OnBoundsChanging(const FloatRectangle& bounds)
644 int appType = _AppInfo::GetAppType();
645 if (appType & _APP_TYPE_IME_APP)
647 SysLog(NID_UI_CTRL, "[Ime Rotation]");
651 if (__restore == false)
653 __floatingBounds = bounds;
656 if ((__showMode == FRAME_SHOW_MODE_FULL_SCREEN) && (__restore == false))
658 if (__constructed == false)
664 if (__rotation == true)
670 return E_UNSUPPORTED_OPERATION;
675 if (__changingBoundsEnabled == false)
680 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
681 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
683 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(bounds));
684 result r = GetLastResult();
685 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
692 _Frame::OnAttached(void)
694 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
695 SysAssert(pEcoreEvas);
697 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), true);
703 _Frame::OnBackgroundColorChanged(Color& backgroundColor)
705 _RootVisualElement* pRootVE = GetRootVisualElement();
708 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
711 byte alpha = backgroundColor.GetAlpha();
712 float opacity = static_cast<float>(alpha) / 255.0f;
714 pLayer->SetOpacity(opacity);
717 FrameShowMode showMode = GetShowMode(false);
718 SetShowMode(FRAME_SHOW_MODE_FULL_SCREEN);
720 SetShowMode(showMode);
722 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
728 Orientation mode = ORIENTATION_PORTRAIT;
730 _Form* pCurrentForm = GetCurrentForm();
733 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pCurrentForm->GetUserData());
736 mode = pFormImpl->GetOrientation();
741 _FrameImpl* pFrameImpl = static_cast<_FrameImpl*>(GetUserData());
744 mode = pFrameImpl->GetOrientation();
750 case ORIENTATION_PORTRAIT:
751 pEcoreEvas->SetWindowPreferredRotation(*this, 0, true);
753 case ORIENTATION_LANDSCAPE:
754 pEcoreEvas->SetWindowPreferredRotation(*this, 270, true);
756 case ORIENTATION_PORTRAIT_REVERSE:
757 pEcoreEvas->SetWindowPreferredRotation(*this, 180, true);
759 case ORIENTATION_LANDSCAPE_REVERSE:
760 pEcoreEvas->SetWindowPreferredRotation(*this, 90, true);
762 case ORIENTATION_AUTOMATIC:
764 pEcoreEvas->SetWindowPreferredRotation(*this, -1);
765 int autoRotation[3] = {0, 90, 270};
766 pEcoreEvas->SetWindowAvailabledRotation(*this, autoRotation, 3, true);
769 case ORIENTATION_AUTOMATIC_FOUR_DIRECTION:
771 pEcoreEvas->SetWindowPreferredRotation(*this, -1);
772 int autoFourRotation[4] = {0, 90, 180, 270};
773 pEcoreEvas->SetWindowAvailabledRotation(*this, autoFourRotation, 4, true);
782 _Frame::ResetFocusList(void)
784 Tizen::Ui::Controls::_Form* pCurrentForm = GetCurrentForm();
787 pCurrentForm->ResetFocusList();
792 _Frame::GetFocusControl(const _Control* pControl) const
794 const _Form* pForm = null;
797 pForm = dynamic_cast<const _Form*>(pControl);
805 pControl = pControl->GetParent();
810 return pForm->GetFocusControl();
816 _Frame::GetCurrentFocusControl(void) const
818 _Form* pForm = GetCurrentForm();
821 return pForm->GetFocusControl();
826 _Frame::SetFocusControl(const _Control* pControl , bool on)
828 SysTryReturnVoidResult(NID_UI, pControl, E_SYSTEM, "[E_SYSTEM] The pControl cannot be NULL.");
829 _ControlManager* pControlMgr = _ControlManager::GetInstance();
830 SysAssert(pControlMgr);
832 _Form* pCurrentForm = GetCurrentForm();
833 const _Control* pTempControl = pControl;
834 bool isCurrentForm = false;
838 pForm = dynamic_cast<_Form*>(const_cast<_Control*>(pTempControl));
846 pTempControl = pTempControl->GetParent();
850 if (pForm == pCurrentForm)
852 isCurrentForm = true;
859 pForm->SetFocusControl(pControl);
862 pControlMgr->SetFocusControl(*pControl);
867 pControlMgr->SetFocusControl(*this, false);
874 _Frame::SetChangingBoundsEnabled(bool enable)
876 __changingBoundsEnabled = enable;
879 Tizen::Base::Collection::IListT<_Control*>*
880 _Frame::GetFocusList(void) const
882 _Form* pForm = GetCurrentForm();
885 return pForm->GetFocusList();
891 _Frame::GetFocusTraversalControl(void) const
893 _Form* pForm = GetCurrentForm();
896 return pForm->GetFocusTraversalControl();
902 _Frame::SetFocusTraversalControl(_Control* pControl)
904 _Form* pForm = GetCurrentForm();
907 pForm->SetFocusTraversalControl(pControl);
910 }}} // Tizen::Ui::Controls