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 if (!(appType & _APP_TYPE_IME_APP))
136 pLayer->SetOpacity(1);
139 pFrame->AcquireHandle();
141 SetLastResult(E_SUCCESS);
152 _Frame::SetPresenter(const _FramePresenter& framePresenter)
154 __pFramePresenter = const_cast <_FramePresenter*>(&framePresenter);
162 if (__pFramePresenter)
164 __pFramePresenter->Draw();
169 _Frame::OnActivated(void)
171 SysLog(NID_UI, "activated(%d)", __activated);
178 _Window::OnActivated();
180 _Form* pCurrentForm = GetCurrentForm();
181 if (pCurrentForm == null)
186 _Control* pFocusedControl = pCurrentForm->GetFocused();
189 pFocusedControl->SetFocused();
193 pCurrentForm->SetFocused();
198 _Frame::OnNotifiedN(const _Control& source, IList* pArgs)
200 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
202 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
203 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
205 if (*pType == L"VisibilityEvent")
209 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
210 if (pObscured == null)
212 pArgs->RemoveAll(true);
218 obscured = pObscured->ToInt();
227 OnFrameDeactivated();
230 pArgs->RemoveAll(true);
235 else if (*pType == _ACTIVATE_FRAME)
237 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
240 pEcoreEvas->ActivateWindow(*this);
243 pArgs->RemoveAll(true);
253 _Frame::OnFrameActivated(void)
255 int childcount = GetChildCount();
257 for (int i = 0 ; i < childcount ; i++)
259 _Control* pChild = GetChild(i);
260 _Form* pForm = dynamic_cast<_Form*>(pChild);
263 pForm->MoveOverlayRegion(true);
268 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_ACTIVATED);
269 __pFrameEvent->Fire(*pArg);
271 if (GetChildCount() < 1)
273 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
274 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
276 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
278 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
284 _Frame::OnFrameDeactivated(void)
286 int childcount = GetChildCount();
288 for (int i = 0 ; i < childcount ; i++)
290 _Control* pChild = GetChild(i);
291 _Form* pForm = dynamic_cast<_Form*>(pChild);
294 pForm->MoveOverlayRegion(false);
299 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_DEACTIVATED);
300 __pFrameEvent->Fire(*pArg);
302 _TouchManager* pTouchManager = _TouchManager::GetInstance();
305 pTouchManager->SetTouchCanceled(null);
310 _Frame::OnFrameMinimized(void)
312 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_MINIMIZED);
313 __pFrameEvent->Fire(*pArg);
317 _Frame::OnFrameRestored(void)
321 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_RESTORED);
322 __pFrameEvent->Fire(*pArg);
326 _Frame::IsFocusableDescendant(const _Control* pFocus) const
328 const _Control* pTopChild = GetChild(GetChildCount() - 1); // Find the current Form.
329 const _Control* pTop = pFocus;
336 // 1. Find the Form of the pFocus.
337 // 2. If the Form is the current Form, then return true.
340 if (pTop == pTopChild)
344 pTop = pTop->GetParent();
351 _Frame::SetCurrentForm(const _Form* pForm)
353 result r = E_SUCCESS;
355 SysTryReturnVoidResult(NID_UI_CTRL, pForm != null, E_INVALID_ARG, "[E_INVALID_ARG] Form to become a new current form is null");
356 _Form* pNewForm = const_cast<_Form*>(pForm);
358 _Form* pCurrentForm = GetCurrentForm();
359 pNewForm->AddIndicatorObject();
361 if (pCurrentForm != null)
363 if (pCurrentForm != pForm)
366 r = MoveChildToTop(*pForm);
367 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
368 pNewForm->MoveOverlayRegion(true);
370 pCurrentForm->SetVisibleState(false);
371 pCurrentForm->MoveOverlayRegion(false);
373 if (__pFormActivationChangeEventListener)
374 __pFormActivationChangeEventListener->OnFormDeactivated(*pCurrentForm);
378 _Control* pFocus = pNewForm->GetFocused();
381 pFocus->SetFocused();
385 pNewForm->SetFocused();
388 pNewForm->SetVisibleState(true);
389 pNewForm->SetUpdateLayoutState(true);
391 if (__pFormActivationChangeEventListener)
392 __pFormActivationChangeEventListener->OnFormActivated(*pNewForm);
394 SetLastResult(E_SUCCESS);
400 _Frame::GetCurrentForm(void) const
402 _Form* pCurrentForm = null;
403 int controlCount = GetChildCount();
405 if (controlCount > 0)
407 for (int i = controlCount; i > 0; i--)
409 pCurrentForm = dynamic_cast<_Form*>(GetChild(i - 1));
410 SysTryReturn(NID_UI_CTRL, pCurrentForm != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
411 if (pCurrentForm->IsVisible())
422 _Frame::IsOrientationRoot(void) const
428 _Frame::SetRotation(bool rotation)
430 __rotation = rotation;
434 _Frame::AddFrameEventListener(const _IFrameEventListener& listener)
436 __constructed = true;
438 result r = __pFrameEvent->AddListener(listener);
439 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
443 _Frame::RemoveFrameEventListener(const _IFrameEventListener& listener)
445 result r = __pFrameEvent->RemoveListener(listener);
446 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
450 _Frame::SetFormActivationChangeEventListener(const _IFormActivationChangeEventListener* plistener)
452 __pFormActivationChangeEventListener = const_cast<_IFormActivationChangeEventListener*>(plistener);
457 _Frame::SetFloatingBounds(const FloatRectangle& rect)
459 __floatingBounds = rect;
463 _Frame::SetFloatingBounds(const Rectangle& rect)
465 __floatingBounds = _CoordinateSystemUtils::ConvertToFloat(rect);
469 _Frame::SetShowMode(FrameShowMode showMode)
471 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
472 SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "The method cannot proceed due to a severe system error.");
474 if (showMode == FRAME_SHOW_MODE_MINIMIZED)
476 if (__minimized == true)
481 pEcoreEvas->MinimizeWindow(*GetRootWindow());
488 if (__minimized == true)
494 bool changeMode = true;
496 if ((showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
498 _Form* pCurrentForm = GetCurrentForm();
502 if (pCurrentForm->GetFormStyle() & _FORM_STYLE_INDICATOR)
509 SysTryReturnResult(NID_UI_CTRL, changeMode == true, E_SYSTEM, "The method cannot proceed due to a severe system error.");
511 int oldShowMode = __showMode;
512 __showMode = showMode;
514 result r = E_SUCCESS;
518 case FRAME_SHOW_MODE_FULL_SCREEN:
519 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
521 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
522 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
525 if (oldShowMode != FRAME_SHOW_MODE_FULL_SCREEN)
527 FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
531 if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
533 SetBounds(FloatRectangle(0.0f, 0.0f, screen.width, screen.height));
537 SetBounds(FloatRectangle(0.0f, 0.0f, screen.height, screen.width));
544 case FRAME_SHOW_MODE_PARTIAL_SCREEN:
545 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
547 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
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);
555 else if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
557 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(__floatingBounds));
561 case FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING:
562 if (oldShowMode != FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
564 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), true);
565 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
568 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
570 SetBounds(__floatingBounds);
582 _Frame::GetShowMode(void) const
584 if (__minimized == true)
586 return FRAME_SHOW_MODE_MINIMIZED;
595 _Frame::IsActivated(void) const
601 _Frame::OnChildAttached(const _Control& child)
603 _Form* pCurrentForm = GetCurrentForm();
605 if (pCurrentForm == &child)
607 int controlCount = GetChildCount();
609 if (controlCount > 1)
611 _Control* pOldCurrentForm = GetChild(controlCount - 2);
612 SysTryReturnVoidResult(NID_UI_CTRL, pOldCurrentForm != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
613 pOldCurrentForm->SetVisibleState(false);
619 _Frame::OnChildDetached(const _Control& child)
621 int controlCount = GetChildCount();
623 if (controlCount > 0)
625 _Control* pCurrentForm = GetChild(controlCount - 1);
626 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
627 pCurrentForm->SetVisibleState(true);
631 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
632 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
633 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
638 _Frame::OnBoundsChanging(const FloatRectangle& bounds)
640 int appType = _AppInfo::GetAppType();
641 if (appType & _APP_TYPE_IME_APP)
643 SysLog(NID_UI_CTRL, "[Ime Rotation]");
647 if (__restore == false)
649 __floatingBounds = bounds;
652 if ((__showMode == FRAME_SHOW_MODE_FULL_SCREEN) && (__restore == false))
654 if (__constructed == false)
660 if (__rotation == true)
666 return E_UNSUPPORTED_OPERATION;
671 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
672 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
674 pEcoreEvas->SetWindowBounds(*GetRootWindow(), _CoordinateSystemUtils::ConvertToInteger(bounds));
675 result r = GetLastResult();
676 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
683 _Frame::OnAttached(void)
685 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
686 SysAssert(pEcoreEvas);
688 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), true);
694 _Frame::OnBackgroundColorChanged(Color& backgroundColor)
696 _RootVisualElement* pRootVE = GetRootVisualElement();
699 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
702 byte alpha = backgroundColor.GetAlpha();
703 float opacity = static_cast<float>(alpha) / 255.0f;
705 pLayer->SetOpacity(opacity);
709 _Frame::ResetFocusList(void)
711 Tizen::Ui::Controls::_Form* pCurrentForm = GetCurrentForm();
714 pCurrentForm->ResetFocusList();
717 }}} // Tizen::Ui::Controls