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 "FUi_UiNotificationEvent.h"
27 #include "FUi_UiEventManager.h"
28 #include "FUi_ControlManager.h"
29 #include "FUi_EcoreEvasMgr.h"
30 #include "FUi_EcoreEvas.h"
31 #include "FUi_TouchManager.h"
32 #include "FUiCtrl_Frame.h"
33 #include "FUiCtrl_FramePresenter.h"
34 #include "FUiCtrl_FrameEvent.h"
35 #include "FUiCtrl_IFrameEventListener.h"
36 #include "FUiCtrl_IFormActivationChangeEventListener.h"
37 #include "FUiCtrl_Form.h"
38 #include "FUiAnim_VisualElement.h"
39 #include "FUiAnim_RootVisualElement.h"
40 #include "FUiAnim_EflLayer.h"
42 using namespace Tizen::Ui::Animations;
43 using namespace Tizen::Ui;
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
46 using namespace Tizen::Base::Runtime;
47 using namespace Tizen::Graphics;
49 namespace Tizen { namespace Ui { namespace Controls {
52 : __pFramePresenter(null)
54 , __floatingBounds(0, 0, 0, 0)
55 , __showMode(FRAME_SHOW_MODE_FULL_SCREEN)
58 , __pFormActivationChangeEventListener(null)
60 _FramePresenter* pPresenter = new (std::nothrow) _FramePresenter(*this);
61 SysTryReturnVoidResult(NID_UI_CTRL, pPresenter, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
63 Dimension screen = _ControlManager::GetInstance()->GetScreenSize();
64 __floatingBounds.width = screen.width;
65 __floatingBounds.height = screen.height;
67 __pFrameEvent = _FrameEvent::CreateInstanceN(*this);
68 SysTryCatch(NID_UI_CTRL, __pFrameEvent, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
70 SetPresenter(*pPresenter);
71 SetClipChildrenEnabled(false);
90 delete __pFramePresenter;
91 __pFramePresenter = null;
97 _Frame::CreateFrameN(void)
99 //_VisualElement* pFrameVE = null;
101 #if defined(MULTI_WINDOW)
102 result r = E_SUCCESS;
103 _RootVisualElement* pRootVE = null;
104 _EflLayer* pLayer = null;
107 _Frame* pFrame = new (std::nothrow) _Frame;
108 SysTryCatch(NID_UI_CTRL, pFrame, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
109 SysTryCatch(NID_UI_CTRL, GetLastResult() == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
111 #if defined(MULTI_WINDOW)
112 r = pFrame->CreateRootVisualElement();
113 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
115 pRootVE = pFrame->GetRootVisualElement();
118 pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
121 pLayer->SetOpacity(1);
124 //pFrameVE = pFrame->GetVisualElement();
125 //pFrameVE->SetRenderOperation(_VisualElement::RENDER_OPERATION_COPY);
127 pFrame->AcquireHandle();
129 SetLastResult(E_SUCCESS);
140 _Frame::SetPresenter(const _FramePresenter& framePresenter)
142 __pFramePresenter = const_cast <_FramePresenter*>(&framePresenter);
150 if (__pFramePresenter)
152 __pFramePresenter->Draw();
157 _Frame::OnActivated(void)
159 SysLog(NID_UI, "activated(%d)", __activated);
166 #if defined(MULTI_WINDOW)
167 _Window::OnActivated();
170 _Form* pCurrentForm = GetCurrentForm();
171 if (pCurrentForm == null)
176 _Control* pFocusedControl = pCurrentForm->GetFocused();
179 pFocusedControl->SetFocused();
183 pCurrentForm->SetFocused();
188 _Frame::OnNotifiedN(const _Control& source, IList* pArgs)
190 SysTryReturn(NID_UI_CTRL, pArgs, false, E_SYSTEM, "[E_SYSTEM] pArgs is null.")
192 String* pType = dynamic_cast <String*>(pArgs->GetAt(0));
193 SysTryReturn(NID_UI_CTRL, pType, false, E_SYSTEM, "[E_SYSTEM] pType is null.")
195 if (*pType == L"VisibilityEvent")
199 Integer* pObscured = dynamic_cast<Integer*>(pArgs->GetAt(1));
200 if (pObscured == null)
202 pArgs->RemoveAll(true);
208 obscured = pObscured->ToInt();
217 OnFrameDeactivated();
220 pArgs->RemoveAll(true);
230 _Frame::OnFrameActivated(void)
232 int childcount = GetChildCount();
234 for (int i = 0 ; i < childcount ; i++)
236 _Control* pChild = GetChild(i);
237 _Form* pForm = dynamic_cast<_Form*>(pChild);
240 pForm->MoveOverlayRegion(true);
245 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_ACTIVATED);
246 __pFrameEvent->Fire(*pArg);
248 if (GetChildCount() < 1)
250 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
251 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
252 #if !defined(MULTI_WINDOW)
253 pEcoreEvas->SetIndicatorShowState(false);
255 if (GetShowMode() == FRAME_SHOW_MODE_FULL_SCREEN)
257 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
264 _Frame::OnFrameDeactivated(void)
266 int childcount = GetChildCount();
268 for (int i = 0 ; i < childcount ; i++)
270 _Control* pChild = GetChild(i);
271 _Form* pForm = dynamic_cast<_Form*>(pChild);
274 pForm->MoveOverlayRegion(false);
279 IEventArg* pArg = _FrameEvent::CreateFrameEventArgN(*this, _FRAME_STATUS_DEACTIVATED);
280 __pFrameEvent->Fire(*pArg);
282 _TouchManager* pTouchManager = _TouchManager::GetInstance();
285 pTouchManager->SetTouchCanceled(true);
290 _Frame::IsFocusableDescendant(const _Control* pFocus) const
292 const _Control* pTopChild = GetChild(GetChildCount() - 1); // Find the current Form.
293 const _Control* pTop = pFocus;
300 // 1. Find the Form of the pFocus.
301 // 2. If the Form is the current Form, then return true.
304 if (pTop == pTopChild)
308 pTop = pTop->GetParent();
315 _Frame::SetFocusOff(_Control* pFocus)
317 _Control* pTopOfFocus = null;
318 _Control* pTemp = pFocus;
320 while (pTemp != this)
323 pTemp = pTemp->GetParent();
326 // [ToDo] If pTem == null???
330 pTopOfFocus->SetFocusOff(pFocus);
335 _Frame::SetCurrentForm(const _Form* pForm)
337 result r = E_SUCCESS;
339 SysTryReturnVoidResult(NID_UI_CTRL, pForm != null, E_INVALID_ARG, "[E_INVALID_ARG] Form to become a new current form is null");
340 _Form* pNewForm = const_cast<_Form*>(pForm);
342 _Form* pCurrentForm = GetCurrentForm();
343 pNewForm->AddIndicatorObject();
345 if (pCurrentForm != null)
347 if (pCurrentForm != pForm)
350 r = MoveChildToTop(*pForm);
351 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
352 pNewForm->MoveOverlayRegion(true);
354 pCurrentForm->SetVisibleState(false);
355 pCurrentForm->MoveOverlayRegion(false);
357 if (__pFormActivationChangeEventListener)
358 __pFormActivationChangeEventListener->OnFormDeactivated(*pCurrentForm);
362 _Control* pFocus = pNewForm->GetFocused();
365 pFocus->SetFocused();
369 pNewForm->SetFocused();
372 pNewForm->SetVisibleState(true);
373 pNewForm->SetUpdateLayoutState(true);
375 if (__pFormActivationChangeEventListener)
376 __pFormActivationChangeEventListener->OnFormActivated(*pNewForm);
378 SetLastResult(E_SUCCESS);
384 _Frame::GetCurrentForm(void) const
386 _Form* pCurrentForm = null;
387 int controlCount = GetChildCount();
389 if (controlCount > 0)
391 for (int i = controlCount; i > 0; i--)
393 pCurrentForm = dynamic_cast<_Form*>(GetChild(i - 1));
394 SysTryReturn(NID_UI_CTRL, pCurrentForm != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
395 if (pCurrentForm->IsVisible())
405 #if !defined(MULTI_WINDOW)
407 _Frame::IsLayoutChangable(void) const
414 _Frame::IsOrientationRoot(void) const
420 _Frame::AddFrameEventListener(const _IFrameEventListener& listener)
422 result r = __pFrameEvent->AddListener(listener);
423 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
427 _Frame::RemoveFrameEventListener(const _IFrameEventListener& listener)
429 result r = __pFrameEvent->RemoveListener(listener);
430 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
434 _Frame::SetFormActivationChangeEventListener(const _IFormActivationChangeEventListener* plistener)
436 __pFormActivationChangeEventListener = const_cast<_IFormActivationChangeEventListener*>(plistener);
441 _Frame::SetFloatingBounds(const Rectangle& rect)
443 __floatingBounds = rect;
447 _Frame::SetShowMode(FrameShowMode showMode)
449 bool changeMode = true;
451 if ((showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN) || (showMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING))
453 _Form* pCurrentForm = GetCurrentForm();
457 if (pCurrentForm->GetFormStyle() & _FORM_STYLE_INDICATOR)
464 SysTryReturnResult(NID_UI_CTRL, changeMode == true, E_SYSTEM, "The method cannot proceed due to a severe system error.");
466 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
467 SysTryReturnResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "The method cannot proceed due to a severe system error.");
469 int oldShowMode = __showMode;
470 __showMode = showMode;
472 result r = E_SUCCESS;
476 case FRAME_SHOW_MODE_FULL_SCREEN:
477 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
479 #if !defined(MULTI_WINDOW)
480 r = pEcoreEvas->SetFloatingMode(false);
482 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
484 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
487 if (oldShowMode != FRAME_SHOW_MODE_FULL_SCREEN)
489 Dimension screen = _ControlManager::GetInstance()->GetScreenSize();
493 if (GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
495 SetBounds(Rectangle(0, 0, screen.width, screen.height));
499 SetBounds(Rectangle(0, 0, screen.height, screen.width));
506 case FRAME_SHOW_MODE_PARTIAL_SCREEN:
507 if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
509 #if !defined(MULTI_WINDOW)
510 r = pEcoreEvas->SetFloatingMode(false);
512 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), false);
514 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
517 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
519 SetBounds(__floatingBounds);
521 else if (oldShowMode == FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
523 #if !defined(MULTI_WINDOW)
524 pEcoreEvas->SetWindowBounds(__floatingBounds);
526 pEcoreEvas->SetWindowBounds(*GetRootWindow(), __floatingBounds);
531 case FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING:
532 if (oldShowMode != FRAME_SHOW_MODE_PARTIAL_SCREEN_FLOATING)
534 #if !defined(MULTI_WINDOW)
535 r = pEcoreEvas->SetFloatingMode(true);
537 r = pEcoreEvas->SetFloatingMode(*GetRootWindow(), true);
539 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
542 if (oldShowMode == FRAME_SHOW_MODE_FULL_SCREEN)
544 SetBounds(__floatingBounds);
556 _Frame::GetShowMode(void) const
562 _Frame::IsActivated(void) const
568 _Frame::OnChildAttached(const _Control& child)
570 _Form* pCurrentForm = GetCurrentForm();
572 if (pCurrentForm == &child)
574 int controlCount = GetChildCount();
576 if (controlCount > 1)
578 _Control* pOldCurrentForm = GetChild(controlCount - 2);
579 SysTryReturnVoidResult(NID_UI_CTRL, pOldCurrentForm != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
580 pOldCurrentForm->SetVisibleState(false);
586 _Frame::OnChildDetached(const _Control& child)
588 int controlCount = GetChildCount();
590 if (controlCount > 0)
592 _Control* pCurrentForm = GetChild(controlCount - 1);
593 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentForm, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
594 pCurrentForm->SetVisibleState(true);
598 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
599 SysTryReturnVoidResult(NID_UI_CTRL, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] Unable to get evas");
600 #if !defined(MULTI_WINDOW)
601 pEcoreEvas->SetIndicatorShowState(false);
603 pEcoreEvas->SetIndicatorShowState(*GetRootWindow(), false);
609 _Frame::OnBoundsChanging(const Rectangle& bounds)
611 if (__restore == false)
613 __floatingBounds = bounds;
616 if ((__showMode == FRAME_SHOW_MODE_FULL_SCREEN) && (__restore == false))
621 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
622 SysTryReturn(NID_UI, pEcoreEvas, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
624 #if !defined(MULTI_WINDOW)
625 pEcoreEvas->SetWindowBounds(bounds);
627 pEcoreEvas->SetWindowBounds(*GetRootWindow(), bounds);
629 result r = GetLastResult();
630 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
637 _Frame::OnAttached(void)
639 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
640 SysAssert(pEcoreEvas);
642 #if !defined(MULTI_WINDOW)
643 pEcoreEvas->SetWindowVisibleState(true);
645 pEcoreEvas->SetWindowVisibleState(*GetRootWindow(), true);
651 #if !defined(MULTI_WINDOW)
653 _Frame::OnAttachedToMainTree(void)
655 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
656 SysAssert(pEcoreEvas);
658 _RootVisualElement* pRootVE = pEcoreEvas->GetRootVisualElement();
661 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
664 pLayer->SetShowState(true);
665 pRootVE->SetShowState(true);
671 _Frame::OnVisibleStateChanged(void)
673 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
674 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
676 bool visibleState = GetVisibleState();
678 pEcoreEvas->SetWindowVisibleState(visibleState);
679 result r = GetLastResult();
680 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
682 SetLastResult(E_SUCCESS);
686 }}} // Tizen::Ui::Controls