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.
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 "FUiAnim_VisualElement.h"
41 #include "FUiAnim_RootVisualElement.h"
42 #include "FUiAnim_EflLayer.h"
44 using namespace Tizen::App;
45 using namespace Tizen::Ui::Animations;
46 using namespace Tizen::Ui;
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49 using namespace Tizen::Base::Runtime;
50 using namespace Tizen::Graphics;
52 namespace Tizen { namespace Ui { namespace Controls {
54 const String _ACTIVATE_FRAME = L"ActivateFrame";
57 : __pFramePresenter(null)
59 , __floatingBounds(0.0f, 0.0f, 0.0f, 0.0f)
60 , __showMode(FRAME_SHOW_MODE_FULL_SCREEN)
64 , __constructed(false)
66 , __pFormActivationChangeEventListener(null)
68 _FramePresenter* pPresenter = new (std::nothrow) _FramePresenter(*this);
69 SysTryReturnVoidResult(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
71 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
72 __floatingBounds.width = screen.width;
73 __floatingBounds.height = screen.height;
75 __pFrameEvent = _FrameEvent::CreateInstanceN(*this);
76 SysTryCatch(NID_UI_CTRL, __pFrameEvent, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
78 SetPresenter(*pPresenter);
79 SetClipChildrenEnabled(false);
98 delete __pFramePresenter;
99 __pFramePresenter = null;
105 _Frame::CreateFrameN(void)
107 result r = E_SUCCESS;
108 _RootVisualElement* pRootVE = null;
109 _EflLayer* pLayer = null;
110 int appType = _AppInfo::GetAppType();
112 _Frame* pFrame = new (std::nothrow) _Frame;
113 SysTryCatch(NID_UI_CTRL, pFrame, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
114 SysTryCatch(NID_UI_CTRL, GetLastResult() == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
116 if (appType & _APP_TYPE_IME_APP)
118 SysLog(NID_UI_CTRL, "[Ime Rotation]");
119 r = pFrame->CreateRootVisualElement(_WINDOW_TYPE_SUB);
120 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
124 r = pFrame->CreateRootVisualElement();
125 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
128 pRootVE = pFrame->GetRootVisualElement();
131 pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
134 pLayer->SetOpacity(1);
136 pFrame->AcquireHandle();
138 SetLastResult(E_SUCCESS);
149 _Frame::SetPresenter(const _FramePresenter& framePresenter)
151 __pFramePresenter = const_cast <_FramePresenter*>(&framePresenter);
159 if (__pFramePresenter)
161 __pFramePresenter->Draw();
166 _Frame::OnActivated(void)
168 SysLog(NID_UI, "activated(%d)", __activated);
175 _Window::OnActivated();
177 _Form* pCurrentForm = GetCurrentForm();
178 if (pCurrentForm == null)
183 _Control* pFocusedControl = pCurrentForm->GetFocused();
186 pFocusedControl->SetFocused();
190 pCurrentForm->SetFocused();
195 _Frame::OnNotifiedN(const _Control& source, IList* pArgs)
197 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
199 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
200 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
202 if (*pType == L"VisibilityEvent")
206 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
207 if (pObscured == null)
209 pArgs->RemoveAll(true);
215 obscured = pObscured->ToInt();
224 OnFrameDeactivated();
227 pArgs->RemoveAll(true);
232 else if (*pType == _ACTIVATE_FRAME)
234 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
237 pEcoreEvas->ActivateWindow(*this);
240 pArgs->RemoveAll(true);
250 _Frame::OnFrameActivated(void)
252 int childcount = GetChildCount();
254 for (int i = 0 ; i < childcount ; i++)
256 _Control* pChild = GetChild(i);
257 _Form* pForm = dynamic_cast<_Form*>(pChild);
260 pForm->MoveOverlayRegion(true);
265 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_ACTIVATED);
266 __pFrameEvent->Fire(*pArg);
268 if (GetChildCount() < 1)
270 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
271 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
273 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
275 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
281 _Frame::OnFrameDeactivated(void)
283 int childcount = GetChildCount();
285 for (int i = 0 ; i < childcount ; i++)
287 _Control* pChild = GetChild(i);
288 _Form* pForm = dynamic_cast<_Form*>(pChild);
291 pForm->MoveOverlayRegion(false);
296 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_DEACTIVATED);
297 __pFrameEvent->Fire(*pArg);
299 _TouchManager* pTouchManager = _TouchManager::GetInstance();
302 pTouchManager->SetTouchCanceled(null);
307 _Frame::OnFrameMinimized(void)
309 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_MINIMIZED);
310 __pFrameEvent->Fire(*pArg);
314 _Frame::OnFrameRestored(void)
318 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_RESTORED);
319 __pFrameEvent->Fire(*pArg);
323 _Frame::IsFocusableDescendant(const _Control* pFocus) const
325 const _Control* pTopChild = GetChild(GetChildCount() - 1); // Find the current Form.
326 const _Control* pTop = pFocus;
333 // 1. Find the Form of the pFocus.
334 // 2. If the Form is the current Form, then return true.
337 if (pTop == pTopChild)
341 pTop = pTop->GetParent();
348 _Frame::SetCurrentForm(const _Form* pForm)
350 result r = E_SUCCESS;
352 SysTryReturnVoidResult(NID_UI_CTRL, pForm != null, E_INVALID_ARG, "[E_INVALID_ARG] Form to become a new current form is null");
353 _Form* pNewForm = const_cast<_Form*>(pForm);
355 _Form* pCurrentForm = GetCurrentForm();
356 pNewForm->AddIndicatorObject();
358 if (pCurrentForm != null)
360 if (pCurrentForm != pForm)
363 r = MoveChildToTop(*pForm);
364 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
365 pNewForm->MoveOverlayRegion(true);
367 pCurrentForm->SetVisibleState(false);
368 pCurrentForm->MoveOverlayRegion(false);
370 if (__pFormActivationChangeEventListener)
371 __pFormActivationChangeEventListener->OnFormDeactivated(*pCurrentForm);
375 _Control* pFocus = pNewForm->GetFocused();
378 pFocus->SetFocused();
382 pNewForm->SetFocused();
385 pNewForm->SetVisibleState(true);
386 pNewForm->SetUpdateLayoutState(true);
388 if (__pFormActivationChangeEventListener)
389 __pFormActivationChangeEventListener->OnFormActivated(*pNewForm);
391 SetLastResult(E_SUCCESS);
397 _Frame::GetCurrentForm(void) const
399 _Form* pCurrentForm = null;
400 int controlCount = GetChildCount();
402 if (controlCount > 0)
404 for (int i = controlCount; i > 0; i--)
406 pCurrentForm = dynamic_cast<_Form*>(GetChild(i - 1));
407 SysTryReturn(NID_UI_CTRL, pCurrentForm != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
408 if (pCurrentForm->IsVisible())
419 _Frame::IsOrientationRoot(void) const
425 _Frame::SetRotation(bool rotation)
427 __rotation = rotation;
431 _Frame::AddFrameEventListener(const _IFrameEventListener& listener)
433 __constructed = true;
435 result r = __pFrameEvent->AddListener(listener);
436 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
440 _Frame::RemoveFrameEventListener(const _IFrameEventListener& listener)
442 result r = __pFrameEvent->RemoveListener(listener);
443 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
447 _Frame::SetFormActivationChangeEventListener(const _IFormActivationChangeEventListener* plistener)
449 __pFormActivationChangeEventListener = const_cast<_IFormActivationChangeEventListener*>(plistener);
454 _Frame::SetFloatingBounds(const FloatRectangle& rect)
456 __floatingBounds = rect;
460 _Frame::SetFloatingBounds(const Rectangle& rect)
462 __floatingBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
466 _Frame::SetShowMode(FrameShowMode showMode)
468 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
469 SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "The method cannot proceed due to a severe system error.");
471 if (showMode == FRAME_SHOW_MODE_MINIMIZED)
473 if (__minimized == true)
478 pEcoreEvas->MinimizeWindow(*GetRootWindow());
485 if (__minimized == true)
491 bool changeMode = true;
493 if ((showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
495 _Form* pCurrentForm = GetCurrentForm();
499 if (pCurrentForm->GetFormStyle() & _FORM_STYLE_INDICATOR)
506 SysTryReturnResult(NID_UI_CTRL, changeMode == true, E_SYSTEM, "The method cannot proceed due to a severe system error.");
508 int oldShowMode = __showMode;
509 __showMode = showMode;
511 result r = E_SUCCESS;
515 case FRAME_SHOW_MODE_FULL_SCREEN:
516 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
518 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
519 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
522 if (oldShowMode != FRAME_SHOW_MODE_FULL_SCREEN)
524 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
528 if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
530 SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
534 SetBounds(FloatRectangle(0.0f, 0.0f, screen.height, screen.width));
541 case FRAME_SHOW_MODE_PARTIAL_SCREEN:
542 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
544 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
545 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
548 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
550 SetBounds(__floatingBounds);
552 else if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
554 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(__floatingBounds));
558 case FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING:
559 if (oldShowMode != FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
561 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), true);
562 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
565 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
567 SetBounds(__floatingBounds);
579 _Frame::GetShowMode(void) const
581 if (__minimized == true)
583 return FRAME_SHOW_MODE_MINIMIZED;
592 _Frame::IsActivated(void) const
598 _Frame::OnChildAttached(const _Control& child)
600 _Form* pCurrentForm = GetCurrentForm();
602 if (pCurrentForm == &child)
604 int controlCount = GetChildCount();
606 if (controlCount > 1)
608 _Control* pOldCurrentForm = GetChild(controlCount - 2);
609 SysTryReturnVoidResult(NID_UI_CTRL, pOldCurrentForm != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
610 pOldCurrentForm->SetVisibleState(false);
616 _Frame::OnChildDetached(const _Control& child)
618 int controlCount = GetChildCount();
620 if (controlCount > 0)
622 _Control* pCurrentForm = GetChild(controlCount - 1);
623 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
624 pCurrentForm->SetVisibleState(true);
628 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
629 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
630 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
635 _Frame::OnBoundsChanging(const FloatRectangle& bounds)
637 int appType = _AppInfo::GetAppType();
638 if (appType & _APP_TYPE_IME_APP)
640 SysLog(NID_UI_CTRL, "[Ime Rotation]");
644 if (__restore == false)
646 __floatingBounds = bounds;
649 if ((__showMode == FRAME_SHOW_MODE_FULL_SCREEN) && (__restore == false))
651 if (__constructed == false)
657 if (__rotation == true)
663 return E_UNSUPPORTED_OPERATION;
668 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
669 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
671 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(bounds));
672 result r = GetLastResult();
673 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
680 _Frame::OnAttached(void)
682 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
683 SysAssert(pEcoreEvas);
685 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), true);
691 _Frame::OnBackgroundColorChanged(Color& backgroundColor)
693 _RootVisualElement* pRootVE = GetRootVisualElement();
696 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
699 byte alpha = backgroundColor.GetAlpha();
700 float opacity = static_cast<float>(alpha) / 255.0f;
702 pLayer->SetOpacity(opacity);
706 _Frame::ResetFocusList(void)
708 Tizen::Ui::Controls::_Form* pCurrentForm = GetCurrentForm();
711 pCurrentForm->ResetFocusList();
714 }}} // Tizen::Ui::Controls