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.
19 * @file FUi_ControlManager.cpp
20 * @brief This is the implementation file for the _ControlManager class.
25 #include <runtime_info.h>
27 #include <Elementary.h>
28 #include <FBaseInt8.h>
29 #include <FBaseSysLog.h>
30 #include <FGrpRectangle.h>
31 #include <FApp_AppInfo.h>
32 #include <FAppPkg_PackageInfoImpl.h>
33 #include <FGrp_Screen.h>
34 #include <FGrp_FontImpl.h>
35 #include <FSys_SettingInfoImpl.h>
36 #include <FSys_SystemInfoImpl.h>
37 #include "FUi_ControlManager.h"
38 #include "FUi_Control.h"
39 #include "FUi_Window.h"
40 #include "FUi_WindowImpl.h"
41 #include "FUi_EcoreEvas.h"
42 #include "FUi_EcoreEvasMgr.h"
43 #include "FUi_EflWindow.h"
44 #include "FUi_ResourceManager.h"
45 #include "FUi_Clipboard.h"
46 #include "FUi_UiFocusEvent.h"
47 #include "FUi_UiEventManager.h"
48 #include "FUi_TouchManager.h"
49 #include "FUi_TouchLongPressGestureDetector.h"
50 #include "FUi_TouchTapGestureDetector.h"
51 #include "FUi_KeyEventManager.h"
52 #include "FUi_CoordinateSystemUtils.h"
53 #include "FUiAnim_RootVisualElement.h"
54 #include "FUiAnim_AnimationManager.h"
55 #include "FUiAnim_DisplayManager.h"
56 #include "FUi_AccessibilityManager.h"
57 #include "FUiAnim_VisualElement.h"
58 #include "FUiAnim_EflLayer.h"
59 #include "FUiCtrl_FrameImpl.h"
60 #include "FUiCtrl_FormImpl.h"
61 #include "FUiCtrl_Frame.h"
62 #include "FUiCtrl_IndicatorManager.h"
64 using namespace Tizen::App;
65 using namespace Tizen::App::Package;
66 using namespace Tizen::Base;
67 using namespace Tizen::Base::Collection;
68 using namespace Tizen::Graphics;
69 using namespace Tizen::Ui;
70 using namespace Tizen::Ui::Animations;
71 using namespace Tizen::Ui::Controls;
72 using namespace Tizen::System;
76 _ControlRotation Convert(int rotationDegree)
78 switch (rotationDegree)
81 return _CONTROL_ROTATION_0;
83 return _CONTROL_ROTATION_90;
85 return _CONTROL_ROTATION_180;
87 return _CONTROL_ROTATION_270;
89 return _CONTROL_ROTATION_0;
93 int Convert(_ControlRotation rotation)
97 case _CONTROL_ROTATION_0:
99 case _CONTROL_ROTATION_90:
101 case _CONTROL_ROTATION_180:
103 case _CONTROL_ROTATION_270:
113 _UiPrintControl(const _Control& control, bool printChildren, int level)
115 const_cast<_Control&>(control).PrintDescription(printChildren, level);
119 _UiPrintTree(int level)
121 _ControlManager* pControlManager = _ControlManager::GetInstance();
122 SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
124 if (pControlManager->GetWindowCount() == 0)
129 int count = pControlManager->GetWindowCount();
130 for (int i = 0; i < count; i++)
132 _Window* pWindow = pControlManager->GetWindow((count-1) - i);
133 _UiPrintControl(*pWindow, true, level);
138 namespace Tizen { namespace Ui
140 _ControlManager* _ControlManager::__pInstance = null;
143 _ControlManager::Initialize(void)
145 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
149 pthread_once(&once_block, InitInstance);
152 result r = _SettingInfoImpl::AddSettingEventListenerForInternal(*__pInstance);
153 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
155 // [ToDo] Is it OK to directly get the device orientation?
156 int degree = app_get_device_orientation();
157 SysLog(NID_UI, "The initial value of device orientation is %d.", degree);
159 __pInstance->__screenRotation = ::Convert(degree);
165 _ControlManager::Release(void)
167 result r = _SettingInfoImpl::RemoveSettingEventListenerForInternal(*__pInstance);
168 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
177 _ControlManager::GetInstance(void)
183 _ControlManager::InitInstance(void)
190 __pInstance = new (std::nothrow) _ControlManager;
191 SysAssert(__pInstance);
195 _ControlManager::Register(_Control* pObject)
199 SysLog(NID_UI, "A _Control Registered()");
204 return _ControlHandle();
207 return __objectManager.Register(*pObject);
211 _ControlManager::Release(const _ControlHandle& handle)
213 _Control* pObject = GetObject(handle);
216 SysLog(NID_UI, "A _Control Released()");
219 return __objectManager.Unregister(handle);
223 _ControlManager::GetObject(const _ControlHandle& handle)
225 return __objectManager.GetObject(handle);
229 _ControlManager::GetObject(const _ControlHandle& handle) const
231 return __objectManager.GetObject(handle);
235 _ControlManager::GetUsedHandleCount(void) const
237 return __objectManager.GetObjectCount();
241 _ControlManager::GetAppCoordinateSystem(bool& isCoordinateSystemLogical, int& logicalCoordinateSystemInt, _BaseScreenSize& logicalBaseScreenSize)
243 _PackageInfoImpl infoImpl;
245 String subAppId(_AppInfo::GetPackageId());
247 result r = infoImpl.Construct(subAppId);
248 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
251 String baseScreenSize(null);
252 String coordinateSystem(null);
253 String logicalCoordinate(null);
255 result r = infoImpl.GetUiScalabilityInfo(baseScreenSize, coordinateSystem, logicalCoordinate);
256 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
258 if (coordinateSystem.Equals(L"Physical", false))
260 isCoordinateSystemLogical = false;
261 logicalCoordinateSystemInt = 0;
262 logicalBaseScreenSize = BASE_SCREEN_SIZE_DEFAULT;
268 r = Integer::Parse(logicalCoordinate, logicalCoordinateSystemInt);
269 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
272 if (baseScreenSize.Equals(L"Large", false))
274 logicalBaseScreenSize = BASE_SCREEN_SIZE_LARGE;
278 logicalBaseScreenSize = BASE_SCREEN_SIZE_NORMAL;
285 _ControlManager::IsCoordinateSystemLogical(void) const
287 return __isCoordinateSystemLogical;
291 _ControlManager::GetCoordinateSystem(void) const
293 return __logicalCoordinateSystem;
297 _ControlManager::GetLogicalBaseScreenSize(void) const
299 return __logicalBaseScreenSize;
302 _ControlManager::_ControlManager(void) // [ToDo] exception check.
303 : __pWindowList(null)
304 , __isCoordinateSystemLogical(true)
305 , __logicalCoordinateSystem(0)
306 , __logicalBaseScreenSize(BASE_SCREEN_SIZE_NONE)
307 , __pSystemWindowList(null)
308 , __pFocusedControl(null)
309 , __screenRotation(_CONTROL_ROTATION_0)
310 , __orientationStatus(_CONTROL_ROTATION_0)
311 , __orientation(_CONTROL_ORIENTATION_PORTRAIT)
312 , __pCurrentFrame(null)
313 , __pGestureList(null)
314 , __gestureMaxDuration(0)
316 , __isDefaultFontChanged(false)
317 , __defaultFontName(L"")
320 result r = GetAppCoordinateSystem(__isCoordinateSystemLogical, __logicalCoordinateSystem, __logicalBaseScreenSize);
321 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] System error occurred.");
323 Dimension deviceResolution = CoordinateSystem::GetPhysicalResolution();
324 _BaseScreenSize deviceBaseScreenSize = _CoordinateSystem::GetInstance()->GetPhysicalBaseScreenSize();
326 r = _CoordinateSystem::Initialize(__logicalCoordinateSystem, __logicalBaseScreenSize, deviceResolution, deviceBaseScreenSize);
327 SysAssert(r == E_SUCCESS);
329 r = _AnimationManager::CreateInstance();
330 SysAssertf(r == E_SUCCESS, "Failed to create animation manager!");
332 r = _DisplayManager::CreateInstance();
333 SysAssertf(r == E_SUCCESS, "Failed to create display manager!");
335 _EcoreEvas::CreateInstanceN();
337 __pWindowList = new (std::nothrow)LinkedListT<_Window*>;
338 SysTryCatch(NID_UI, __pWindowList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
340 __pGestureList = new (std::nothrow)LinkedListT<_TouchGestureDetector*>;
341 SysTryCatch(NID_UI, __pGestureList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
343 _UiEventManager::Initialize();
344 _TouchManager::Initialize();
345 _KeyEventManager::Initialize();
346 _IndicatorManager::InitializeInstance();
347 _AccessibilityManager::CreateInstance();
348 InitializeScreenDpi();
350 SetLastResult(E_SUCCESS);
355 _AnimationManager::ReleaseInstance();
359 delete __pWindowList;
360 __pWindowList = null;
365 delete __pGestureList;
366 __pGestureList = null;
370 _ControlManager::~_ControlManager(void)
372 _Clipboard::ReleaseInstance();
376 delete __pWindowList;
377 __pWindowList = null;
382 delete __pGestureList;
383 __pGestureList = null;
386 DestroyEcoreEvasMgr();
388 if (GetUsedHandleCount() != 0)
390 SysLog(NID_UI, "[Control Manager] The number of unreleased controls: %d", GetUsedHandleCount());
394 _IndicatorManager::ReleaseInstance();
396 _DisplayManager::ReleaseInstance();
398 _AnimationManager::ReleaseInstance();
400 _AccessibilityManager::ReleaseInstance();
402 _KeyEventManager::ReleaseInstance();
403 _TouchManager::ReleaseInstance();
404 _UiEventManager::Release();
408 _ControlManager::GetTopWindow(void) const
412 if (GetWindowCount() == 0)
417 return GetWindow(GetWindowCount() - 1);
421 _ControlManager::GetTopVisibleWindow(void) const
425 if (GetWindowCount() == 0)
430 int count = GetWindowCount();
431 for (int i = 0; i < count; i++)
433 _Window* pWindow = GetWindow((count-1) - i);
435 if (pWindow->GetVisibleState() == true)
445 _ControlManager::GetTopVisibleWindowAt(const Point& point) const
449 if (GetWindowCount() == 0)
454 int count = GetWindowCount();
455 for (int i = 0; i < count; i++)
457 _Window* pWindow = GetWindow((count-1) - i);
459 if (pWindow->GetVisibleState() == false)
464 Rectangle winBounds = pWindow->GetBounds();
465 if (winBounds.Contains(point))
475 _ControlManager::IsWindowOnTop(const _Window& window) const
477 return GetTopWindow() == &window;
481 _ControlManager::IsWindowAttached(const _Window& window) const
483 return __pWindowList->Contains(const_cast<_Window*>(&window));
486 // Open a window and bring it to top.
488 _ControlManager::OpenWindow(_Window& window, bool invalidate)
490 if (dynamic_cast <_Frame*>(&window) != null)
492 __pCurrentFrame = &window;
495 result r = ActivateWindow(window);
496 SysTryReturn(NID_UI, r != E_INVALID_OPERATION, r, r, "[%s] Propagating.", GetErrorMessage(r));
497 SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System Error.");
501 window.Invalidate(true);
508 _ControlManager::ActivateWindow(_Window& window)
511 result r = E_SUCCESS;
513 if (IsWindowOnTop(window))
518 if (window.IsActivationEnabled())
520 _Window* pTopWindow = GetTopWindow();
523 pTopWindow->Deactivate();
527 if (IsWindowAttached(window))
529 r = MoveWindowToTop(window); // [ToDo] excpetion
530 SysAssert(r == E_SUCCESS);
535 r = window.GetControlDelegate().OnAttaching(null);
536 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
538 r = CallOnAttachingToMainTree(window);
539 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
541 r = AttachWindow(window);
542 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
544 if (window.IsActivationEnabled())
549 if (window.IsOrientationRoot() == false)
551 #if !defined(WINDOW_BASE_ROTATE)
552 window.ChangeLayout(GetOrientation());
554 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
557 pEcoreEvas->RotateWindow(window, ::Convert(__orientationStatus));
560 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
563 pEcoreEvas->SetWindowPreferredRotation(window, ::Convert(__orientationStatus));
568 r = window.GetControlDelegate().OnAttached();
569 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
571 r = CallOnAttachedToMainTree(window);
572 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
578 _ControlManager::CallOnAttachingToMainTree(_Control& control)
580 result r = E_SUCCESS;
582 r = control.GetControlDelegate().OnAttachingToMainTree(null);
583 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
585 _Control::ControlList& children = control.GetChildList();
586 _Control* pChild = null;
588 for (int index = 0; index < children.GetCount(); index++)
590 r = children.GetAt(index, pChild);
593 SysAssert(r == E_OUT_OF_RANGE);
595 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
596 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
598 r = CallOnAttachingToMainTree(*pChild);
599 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
606 _ControlManager::CallOnAttachedToMainTree(_Control& control)
608 result r = E_SUCCESS;
610 _Control* pChild = null;
611 _Control::ControlList* pControlList = new (std::nothrow) _Control::ControlList;
612 pControlList->Construct(control.GetChildList());
614 r = control.GetControlDelegate().OnAttachedToMainTree();
615 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
617 for (int index = 0; index < pControlList->GetCount(); index++)
619 r = pControlList->GetAt(index, pChild);
622 SysAssert(r == E_OUT_OF_RANGE);
624 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
625 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
627 r = control.CallOnAttachedToMainTree(*pChild);
628 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
637 _ControlManager::CallOnDetachingFromMainTree(_Control& control)
639 result r = E_SUCCESS;
641 _Control* pChild = null;
642 _Control::ControlList& children = control.GetChildList();
644 r = control.GetControlDelegate().OnDetachingFromMainTree();
645 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
647 for (int index = 0; index < children.GetCount(); index++)
649 r = children.GetAt(index, pChild);
652 SysAssert(r == E_OUT_OF_RANGE);
654 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
655 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
657 r = CallOnDetachingFromMainTree(*pChild);
658 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
665 _ControlManager::CloseWindow(_Window& window) // [ToDo] exception check.
668 result r = E_SUCCESS;
670 if (IsWindowAttached(window) == false)
675 bool wasWindowOnTop = IsWindowOnTop(window);
677 r = CallOnDetachingFromMainTree(window);
678 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
680 window.GetControlDelegate().OnDetaching();
684 r = DetachWindow(window);
685 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
689 _Window* pNewTopWindow = GetTopWindow();
690 if (pNewTopWindow && pNewTopWindow->IsActivationEnabled())
692 pNewTopWindow->Activate();
695 if (dynamic_cast <_Frame*>(pNewTopWindow) != null)
697 __pCurrentFrame = pNewTopWindow;
705 _ControlManager::GetWindow(int index) const
708 __pWindowList->GetAt(index, pWindow);
714 _ControlManager::GetWindowCount(void) const
716 return __pWindowList->GetCount();
720 _ControlManager::AttachWindow(_Window& window)
722 _IndicatorManager::GetInstance()->AddWindow(&window);
724 return __pWindowList->Add(&window);
728 _ControlManager::InsertWindowToBottom(_Window& window)
730 return __pWindowList->InsertAt(&window, 0);
734 _ControlManager::InsertWindowAfter(const _Window& targetWindow, _Window& window)
738 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
739 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
741 return __pWindowList->InsertAt(&window, index+1);
745 _ControlManager::InsertWindowBefore(const _Window& targetWindow, _Window& window)
749 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
750 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
752 return __pWindowList->InsertAt(&window, index);
756 _ControlManager::DetachWindow(_Window& window)
758 _IndicatorManager::GetInstance()->DeleteWindow(&window);
760 return __pWindowList->Remove(&window);
764 _ControlManager::DetachAllWindows(void)
766 __pWindowList->RemoveAll();
770 _ControlManager::MoveWindowToTop(const _Window& window)
772 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
773 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
775 return __pWindowList->Add(const_cast<_Window*>(&window));
779 _ControlManager::MoveWindowToBottom(const _Window& window)
781 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
782 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
784 return __pWindowList->InsertAt(const_cast<_Window*>(&window), 0);
788 _ControlManager::MoveWindowAfter(const _Window& targetWindow, const _Window& window)
790 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
791 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
795 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
796 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
798 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index+1);
802 _ControlManager::MoveWindowBefore(const _Window& targetWindow, const _Window& window)
804 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
805 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
809 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
810 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
812 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index);
816 _ControlManager::GetOrientation(void) const
818 return __orientation;
822 _ControlManager::SetOrientation(_ControlOrientation orientation)
824 __orientation = orientation;
828 _ControlManager::GetScreenRotation(void) const
830 bool autoRotate = true;
831 int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, &autoRotate);
833 if (ret == RUNTIME_INFO_ERROR_NONE)
835 SysLog(NID_UI, "The flag of auto-rotate is %d.", autoRotate);
839 SysLog(NID_UI, "It's failed to get the flag of auto-rotate.");
842 if (autoRotate == false)
844 return _CONTROL_ROTATION_0;
848 #if defined(WINDOW_BASE_ROTATE)
849 int degree = app_get_device_orientation();
851 return ::Convert(degree);
853 return __screenRotation;
859 _ControlManager::OnScreenRotated(int rotation)
861 SysLog(NID_UI, "The angle of Emul or Target is %d.", rotation);
862 __screenRotation = ::Convert(rotation);
864 int count = GetWindowCount();
865 for (int i = 0; i < count; i++)
867 _Window* pWindow = GetWindow((count-1) - i);
869 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
873 Controls::_FrameImpl* pFrameImpl = static_cast<Controls::_FrameImpl*>(pFrame->GetUserData());
874 if (pFrameImpl == null)
879 Controls::_FormImpl* pCurrentFormImpl = pFrameImpl->GetCurrentForm();
880 if (pCurrentFormImpl)
882 pCurrentFormImpl->UpdateOrientationStatus(true);
886 pFrameImpl->UpdateOrientationStatus();
893 _ControlManager::SetTouchedWindow(unsigned int window)
895 __touchedWindow = window;
899 _ControlManager::GetTouchedWindow(void) const
903 if (GetWindowCount() == 0)
908 int count = GetWindowCount();
909 for (int i = 0; i < count; i++)
911 _Window* pWindow = GetWindow((count-1) - i);
913 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
914 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
916 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
917 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
919 if (win == __touchedWindow)
929 _ControlManager::SetOrientationStatus(_ControlRotation orientationStatus)
931 __orientationStatus = orientationStatus;
935 _ControlManager::GetOrientationStatus(void) const
937 return __orientationStatus;
941 _ControlManager::RotateScreen(const _Control& control, _ControlRotation screenRotation)
945 // Set window preferred rotation
947 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
948 SysAssert(pEcoreEvas);
949 if (pEcoreEvas == null)
954 // Rotate root window.
955 _Window* pRootWindow = control.GetRootWindow();
958 pEcoreEvas->RotateWindow(*pRootWindow, ::Convert(screenRotation));
959 //pRootWindow->SetRotation(::Convert(screenRotation));
962 #if !defined(WINDOW_BASE_ROTATE)
964 int owneeCount = control.GetOwneeCount();
965 for (int i = 0; i < owneeCount; i++)
967 _Window* pOwnee = control.GetOwnee(i);
970 pEcoreEvas->RotateWindow(*pOwnee, ::Convert(screenRotation));
975 if (__orientationStatus != screenRotation)
977 _TouchManager* pTouchManager = _TouchManager::GetInstance();
980 pTouchManager->SetTouchCanceled(true);
986 _ControlManager::OnWindowRotated(int rotation)
989 IEnumeratorT<_Window*>* pEnumerator = __pWindowList->GetEnumeratorN();
990 SysTryReturnVoidResult(NID_UI, pEnumerator, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
992 while (pEnumerator->MoveNext() == E_SUCCESS)
994 _Window* pWindow = null;
995 pEnumerator->GetCurrent(pWindow);
997 if (pWindow->GetOwner() == null)
999 void* pUserData = pWindow->GetUserData();
1002 _WindowImpl* pWindowImpl = static_cast<_WindowImpl*>(pUserData);
1003 pWindowImpl->OnRotated(Convert(rotation));
1012 _ControlManager::SetFocusedControl(const _Control& control, bool on)
1016 if (__pFocusedControl == &control)
1021 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1022 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1024 _Control *pPreviousFocusedControl = __pFocusedControl;
1025 if (pPreviousFocusedControl)
1027 // [review] make SetFocus() return result and use the returned result here.
1028 pEcoreEvas->SetFocus(*pPreviousFocusedControl, false);
1029 if (GetLastResult() == E_SUCCESS)
1031 if (pPreviousFocusedControl)
1033 pPreviousFocusedControl->SetFocusState(false);
1035 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1036 _UiEventManager::GetInstance()->SendEvent(event);
1040 // [review] make SetFocus() return result and use the returned result here.
1042 if (control.IsNativeObjectFocusable())
1044 pEcoreEvas->SetFocus(control, true);
1047 if (GetLastResult() == E_SUCCESS)
1049 __pFocusedControl = const_cast<_Control*>(&control);
1050 _UiFocusEvent event(control.GetHandle(), FOCUS_GAINED);
1051 _UiEventManager::GetInstance()->SendEvent(event);
1056 if (__pFocusedControl != &control)
1061 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1062 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1064 if (__pFocusedControl)
1066 // [review] make SetFocus() return result and use the returned result here.
1067 pEcoreEvas->SetFocus(*__pFocusedControl, false);
1068 if (GetLastResult() == E_SUCCESS)
1070 _UiFocusEvent event(__pFocusedControl->GetHandle(), FOCUS_LOST);
1071 _UiEventManager::GetInstance()->SendEvent(event);
1075 _Window* pTopWindow = GetTopWindow();
1078 // [review] make SetFocus() return result and use the returned result here.
1079 pEcoreEvas->SetFocus(*pTopWindow, true);
1080 if (GetLastResult() == E_SUCCESS)
1082 pTopWindow->SetFocusState(true);
1083 _UiFocusEvent event(pTopWindow->GetHandle(), FOCUS_GAINED);
1084 _UiEventManager::GetInstance()->SendEvent(event);
1087 __pFocusedControl = static_cast<_Control*>(pTopWindow);
1092 // [review] called in ~_Control and virtual OnFocusLost is called.
1093 // _Control::Release() instead of ~_Control.
1095 _ControlManager::TakeFocusFromControl(const _Control& control)
1097 if (__pFocusedControl == &control)
1099 _Control *pPreviousFocusedControl = __pFocusedControl;
1100 __pFocusedControl = null;
1101 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1102 _UiEventManager::GetInstance()->SendEvent(event);
1111 _ControlManager::GetFocusedControl(void) const
1113 return __pFocusedControl;
1117 _ControlManager::GetTopmostTouchedControl(const Point& point)
1119 _Control* pControl = null;
1120 _Window* pTopWindow = null;
1122 int count = GetWindowCount();
1125 for (int i = 0; i < count; i++)
1127 _Window* pWindow = GetWindow((count-1) - i);
1129 if (pWindow->GetVisibleState() == false)
1134 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
1135 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
1137 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1138 Ecore_X_Window win = (Ecore_X_Window)ecore_evas_window_get(pEcoreEvas);
1140 Rectangle winDeviceBounds(0, 0, 0, 0);
1141 ecore_x_window_geometry_get(win, &winDeviceBounds.x, &winDeviceBounds.y, &winDeviceBounds.width, &winDeviceBounds.height);
1143 Point winDevicePoint = _CoordinateSystemUtils::Transform(pWindow->GetPosition());
1145 Point devicePoint = _CoordinateSystemUtils::Transform(point);
1146 int x = devicePoint.x;
1147 int y = devicePoint.y;
1151 ecore_x_window_size_get(ecore_x_window_root_get(win), &rootW, &rootH);
1153 int rotation = ecore_evas_rotation_get(pEcoreEvas);
1157 devicePoint.x = rootW - y;
1159 winDeviceBounds.x = rootW - winDevicePoint.y - winDeviceBounds.width;
1160 winDeviceBounds.y = winDevicePoint.x;
1163 devicePoint.x = rootW - x;
1164 devicePoint.y = rootH - y;
1165 winDeviceBounds.x = rootW - winDevicePoint.x - winDeviceBounds.width;
1166 winDeviceBounds.y = rootH - winDevicePoint.y - winDeviceBounds.height;
1170 devicePoint.y = rootH - x;
1171 winDeviceBounds.x = winDevicePoint.y;
1172 winDeviceBounds.y = rootH - winDevicePoint.x - winDeviceBounds.height;
1177 winDeviceBounds.x = winDevicePoint.x;
1178 winDeviceBounds.y = winDevicePoint.y;
1182 if (winDeviceBounds.Contains(devicePoint))
1184 pTopWindow = pWindow;
1190 if (pTopWindow != null)
1193 winPos = pTopWindow->GetPosition();
1195 Point relPos(point.x - winPos.x, point.y - winPos.y);
1196 pControl = pTopWindow->GetTopmostChildAt(relPos);
1197 if (pControl != null)
1199 if (pControl->GetRootWindow() == pTopWindow)
1209 // [review] rename __InvXformer
1211 _ControlManager::GetScreenSize(void) const
1213 return _CoordinateSystemUtils::InverseTransform(Dimension(_Screen::GetWidth(), _Screen::GetHeight()));
1217 _ControlManager::GetScreenSizeF(void) const
1219 return _CoordinateSystemUtils::InverseTransform(FloatDimension(_Screen::GetWidth(), _Screen::GetHeight()));
1223 _ControlManager::InitializeScreenDpi()
1225 Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/screen.dpi", __screenDpi);
1229 _ControlManager::GetScreenDpi() const
1235 _ControlManager::GetCurrentFrame(void) const
1237 return __pCurrentFrame;
1241 _ControlManager::SetDefaultFont(const String& appFontName)
1244 if(appFontName.Equals(__defaultFontName))
1249 __isDefaultFontChanged = true;
1250 __defaultFontName = appFontName;
1251 __defaultFontFileName.Clear();
1254 : public _Control::Visitor
1256 virtual _Control::VisitType Visit(_Control& control)
1258 if (control.__fontName.IsEmpty() && control.__fontFileName.IsEmpty())
1260 control.GetFallbackFont();
1261 _IControlDelegate& delegate = control.GetControlDelegate();
1262 delegate.OnFontChanged(control.__pFont);
1264 return _Control::VISIT_DOWNWARD;
1270 int count = GetWindowCount();
1271 for (int j = 0; j < count; j++)
1273 _Window* pWindow = GetWindow((count-1) - j);
1274 pWindow->Accept(visitor);
1277 SetDefaultFontChangeState(false);
1283 _ControlManager::GetDefaultFont(void)
1285 return __defaultFontName;
1289 _ControlManager::SetDefaultFontFromFile(const Tizen::Base::String& fileName)
1291 if(fileName.Equals(__defaultFontFileName))
1296 __isDefaultFontChanged = true;
1297 __defaultFontFileName = fileName;
1298 __defaultFontName.Clear();
1300 : public _Control::Visitor
1302 virtual _Control::VisitType Visit(_Control& control)
1304 if (control.__fontName.IsEmpty() && control.__fontFileName.IsEmpty())
1306 control.GetFallbackFont();
1307 _IControlDelegate& delegate = control.GetControlDelegate();
1308 delegate.OnFontChanged(control.__pFont);
1310 return _Control::VISIT_DOWNWARD;
1316 int count = GetWindowCount();
1317 for (int j = 0; j < count; j++)
1319 _Window* pWindow = GetWindow((count-1) - j);
1320 pWindow->Accept(visitor);
1323 SetDefaultFontChangeState(false);
1328 _ControlManager::GetDefaultFontFile(void) const
1330 return __defaultFontFileName;
1333 _ControlManager::IsDefaultFontChanged(void)
1335 return __isDefaultFontChanged;
1339 _ControlManager::SetDefaultFontChangeState(bool isDefaultFontChanged)
1341 __isDefaultFontChanged = isDefaultFontChanged;
1345 _ControlManager::IsFrameActivated(void) const
1347 _Frame* pFrame = dynamic_cast<_Frame*>(__pCurrentFrame);
1348 SysTryReturn(NID_UI, pFrame, false, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1350 return pFrame->IsActivated();
1353 // [review] refactoring
1355 _ControlManager::AddGestureDetector(const _TouchGestureDetector& gesture)
1359 SysTryReturn(NID_UI, __pGestureList != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1361 bool exist = __pGestureList->Contains(const_cast<_TouchGestureDetector*>(&gesture));
1362 SysTryReturnResult(NID_UI, exist == false, E_OBJ_ALREADY_EXIST, "[E_OBJ_ALREADY_EXIST]__pGestureList has gesture already");
1364 result r = __pGestureList->Add(const_cast<_TouchGestureDetector*>(&gesture));
1365 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1367 switch (gesture.GetDetectorType())
1369 case _TOUCH_GESTURE_DETECTOR_TYPE_TAP:
1371 _TouchTapGestureDetector* pGestureTap = dynamic_cast<_TouchTapGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1372 SysTryReturnResult(NID_UI, pGestureTap, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1374 if (pGestureTap->GetTapInterval() > __gestureMaxDuration)
1376 __gestureMaxDuration = pGestureTap->GetTapInterval();
1380 case _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS:
1382 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1383 SysTryReturnResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1385 if (pGestureLongPress->GetDuration() > __gestureMaxDuration)
1387 __gestureMaxDuration = pGestureLongPress->GetDuration();
1399 _ControlManager::RemoveGestureDetector(const _TouchGestureDetector& gesture)
1403 result r = __pGestureList->Remove(&(const_cast<_TouchGestureDetector&>(gesture)));
1404 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1409 IListT <_TouchGestureDetector*>*
1410 _ControlManager::GetGestureDetectorList(void) const
1412 return __pGestureList;
1416 _ControlManager::GetGestureMaxTimeDuration(void) const
1418 return __gestureMaxDuration;
1422 _ControlManager::OnSettingChanged(Tizen::Base::String& key)
1424 const wchar_t* FONT_TYPE = L"http://tizen.org/setting/font.type";
1425 const wchar_t* LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country";
1426 const wchar_t* LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
1428 if (key == FONT_TYPE || key == LOCALE_COUNTRY || key == LOCALE_LANGUAGE)
1430 _FontImpl::UpdateDefaultFont(key);
1432 int count = GetWindowCount();
1434 for(int index = 0; index < count ; index++)
1436 _Window* pWindow = GetWindow(index);
1437 pWindow->Invalidate(true);
1441 //fixme : check longpress duration key
1444 if (!__pGestureList || (__pGestureList && (__pGestureList->GetCount() <= 0)))
1449 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = __pGestureList->GetEnumeratorN();
1450 SysTryReturnVoidResult(NID_UI, pEnumerator, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1452 int duration = static_cast<int>(elm_config_longpress_timeout_get());
1458 while (pEnumerator->MoveNext() == E_SUCCESS)
1460 _TouchGestureDetector* pGestureDetector = null;
1461 pEnumerator->GetCurrent(pGestureDetector);
1463 if (!pGestureDetector)
1468 if(pGestureDetector->GetDetectorType() == _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS)
1470 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(pGestureDetector));
1471 SysTryReturnVoidResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1472 pGestureLongPress->SetDuration(duration);