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.
26 #include <sensor_accel.h>
27 #include <runtime_info.h>
29 #include <Elementary.h>
30 #include <FBaseInt8.h>
31 #include <FBaseSysLog.h>
32 #include <FGrpRectangle.h>
33 #include <FApp_AppInfo.h>
34 #include <FAppPkg_PackageInfoImpl.h>
35 #include <FGrp_Screen.h>
36 #include <FGrp_FontImpl.h>
37 #include <FSys_SettingInfoImpl.h>
38 #include <FSys_SystemInfoImpl.h>
39 #include "FUi_ControlManager.h"
40 #include "FUi_Control.h"
41 #include "FUi_Window.h"
42 #include "FUi_WindowImpl.h"
43 #include "FUi_EcoreEvas.h"
44 #include "FUi_EcoreEvasMgr.h"
45 #include "FUi_EflWindow.h"
46 #include "FUi_ResourceManager.h"
47 #include "FUi_Clipboard.h"
48 #include "FUi_UiFocusEvent.h"
49 #include "FUi_UiEventManager.h"
50 #include "FUi_TouchManager.h"
51 #include "FUi_TouchLongPressGestureDetector.h"
52 #include "FUi_TouchTapGestureDetector.h"
53 #include "FUi_KeyEventManager.h"
54 #include "FUi_CoordinateSystemUtils.h"
55 #include "FUiAnim_RootVisualElement.h"
56 #include "FUiAnim_AnimationManager.h"
57 #include "FUiAnim_DisplayManager.h"
58 #include "FUi_AccessibilityManager.h"
59 #include "FUiAnim_VisualElement.h"
60 #include "FUiAnim_EflLayer.h"
61 #include "FUiCtrl_FrameImpl.h"
62 #include "FUiCtrl_FormImpl.h"
63 #include "FUiCtrl_Frame.h"
64 #include "FUiCtrl_IndicatorManager.h"
66 using namespace Tizen::App;
67 using namespace Tizen::App::Package;
68 using namespace Tizen::Base;
69 using namespace Tizen::Base::Collection;
70 using namespace Tizen::Graphics;
71 using namespace Tizen::Ui;
72 using namespace Tizen::Ui::Animations;
73 using namespace Tizen::Ui::Controls;
74 using namespace Tizen::System;
78 _ControlRotation Convert(int rotationDegree)
80 switch (rotationDegree)
83 return _CONTROL_ROTATION_0;
85 return _CONTROL_ROTATION_90;
87 return _CONTROL_ROTATION_180;
89 return _CONTROL_ROTATION_270;
91 return _CONTROL_ROTATION_0;
95 int Convert(_ControlRotation rotation)
99 case _CONTROL_ROTATION_0:
101 case _CONTROL_ROTATION_90:
103 case _CONTROL_ROTATION_180:
105 case _CONTROL_ROTATION_270:
115 _UiPrintControl(const _Control& control, bool printChildren, int level)
117 const_cast<_Control&>(control).PrintDescription(printChildren, level);
121 _UiPrintTree(int level)
123 _ControlManager* pControlManager = _ControlManager::GetInstance();
124 SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
126 if (pControlManager->GetWindowCount() == 0)
131 int count = pControlManager->GetWindowCount();
132 for (int i = 0; i < count; i++)
134 _Window* pWindow = pControlManager->GetWindow((count-1) - i);
135 _UiPrintControl(*pWindow, true, level);
140 namespace Tizen { namespace Ui
142 _ControlManager* _ControlManager::__pInstance = null;
145 _ControlManager::Initialize(void)
147 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
151 pthread_once(&once_block, InitInstance);
154 result r = _SettingInfoImpl::AddSettingEventListenerForInternal(*__pInstance);
155 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
157 // [ToDo] Is it OK to directly get the device orientation?
158 int degree = app_get_device_orientation();
159 SysLog(NID_UI, "The initial value of device orientation is %d.", degree);
161 __pInstance->__screenRotation = ::Convert(degree);
167 _ControlManager::Release(void)
169 result r = _SettingInfoImpl::RemoveSettingEventListenerForInternal(*__pInstance);
170 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
179 _ControlManager::GetInstance(void)
185 _ControlManager::InitInstance(void)
192 __pInstance = new (std::nothrow) _ControlManager;
193 SysAssert(__pInstance);
197 _ControlManager::Register(_Control* pObject)
201 SysLog(NID_UI, "A _Control Registered()");
206 return _ControlHandle();
209 return __objectManager.Register(*pObject);
213 _ControlManager::Release(const _ControlHandle& handle)
215 _Control* pObject = GetObject(handle);
218 SysLog(NID_UI, "A _Control Released()");
221 return __objectManager.Unregister(handle);
225 _ControlManager::GetObject(const _ControlHandle& handle)
227 return __objectManager.GetObject(handle);
231 _ControlManager::GetObject(const _ControlHandle& handle) const
233 return __objectManager.GetObject(handle);
237 _ControlManager::GetUsedHandleCount(void) const
239 return __objectManager.GetObjectCount();
243 _ControlManager::GetAppCoordinateSystem(bool& isCoordinateSystemLogical, int& logicalCoordinateSystemInt, _BaseScreenSize& logicalBaseScreenSize)
245 _PackageInfoImpl infoImpl;
247 String subAppId(_AppInfo::GetPackageId());
249 result r = infoImpl.Construct(subAppId);
250 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
253 String baseScreenSize(null);
254 String coordinateSystem(null);
255 String logicalCoordinate(null);
257 result r = infoImpl.GetUiScalabilityInfo(baseScreenSize, coordinateSystem, logicalCoordinate);
258 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
260 if (coordinateSystem.Equals(L"Physical", false))
262 isCoordinateSystemLogical = false;
263 logicalCoordinateSystemInt = 0;
264 logicalBaseScreenSize = BASE_SCREEN_SIZE_DEFAULT;
270 r = Integer::Parse(logicalCoordinate, logicalCoordinateSystemInt);
271 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
274 if (baseScreenSize.Equals(L"Large", false))
276 logicalBaseScreenSize = BASE_SCREEN_SIZE_LARGE;
280 logicalBaseScreenSize = BASE_SCREEN_SIZE_NORMAL;
287 _ControlManager::IsCoordinateSystemLogical(void) const
289 return __isCoordinateSystemLogical;
293 _ControlManager::GetCoordinateSystem(void) const
295 return __logicalCoordinateSystem;
299 _ControlManager::GetLogicalBaseScreenSize(void) const
301 return __logicalBaseScreenSize;
304 _ControlManager::_ControlManager(void) // [ToDo] exception check.
305 : __pWindowList(null)
306 , __isCoordinateSystemLogical(true)
307 , __logicalCoordinateSystem(0)
308 , __logicalBaseScreenSize(BASE_SCREEN_SIZE_NONE)
309 , __pSystemWindowList(null)
310 , __pFocusedControl(null)
311 , __screenRotation(_CONTROL_ROTATION_0)
312 , __orientationStatus(_CONTROL_ROTATION_0)
313 , __orientation(_CONTROL_ORIENTATION_PORTRAIT)
314 , __pCurrentFrame(null)
315 , __pGestureList(null)
316 , __gestureMaxDuration(0)
318 , __isDefaultFontChanged(false)
319 , __defaultFontName(L"")
322 result r = GetAppCoordinateSystem(__isCoordinateSystemLogical, __logicalCoordinateSystem, __logicalBaseScreenSize);
323 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] System error occurred.");
325 Dimension deviceResolution = CoordinateSystem::GetPhysicalResolution();
326 _BaseScreenSize deviceBaseScreenSize = _CoordinateSystem::GetInstance()->GetPhysicalBaseScreenSize();
328 r = _CoordinateSystem::Initialize(__logicalCoordinateSystem, __logicalBaseScreenSize, deviceResolution, deviceBaseScreenSize);
329 SysAssert(r == E_SUCCESS);
331 r = _AnimationManager::CreateInstance();
332 SysAssertf(r == E_SUCCESS, "Failed to create animation manager!");
334 r = _DisplayManager::CreateInstance();
335 SysAssertf(r == E_SUCCESS, "Failed to create display manager!");
337 _EcoreEvas::CreateInstanceN();
339 __pWindowList = new (std::nothrow)LinkedListT<_Window*>;
340 SysTryCatch(NID_UI, __pWindowList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
342 __pGestureList = new (std::nothrow)LinkedListT<_TouchGestureDetector*>;
343 SysTryCatch(NID_UI, __pGestureList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
345 _UiEventManager::Initialize();
346 _TouchManager::Initialize();
347 _KeyEventManager::Initialize();
348 _IndicatorManager::InitializeInstance();
349 _AccessibilityManager::CreateInstance();
350 InitializeScreenDpi();
352 SetLastResult(E_SUCCESS);
357 _AnimationManager::ReleaseInstance();
361 delete __pWindowList;
362 __pWindowList = null;
367 delete __pGestureList;
368 __pGestureList = null;
372 _ControlManager::~_ControlManager(void)
374 _Clipboard::ReleaseInstance();
378 delete __pWindowList;
379 __pWindowList = null;
384 delete __pGestureList;
385 __pGestureList = null;
388 DestroyEcoreEvasMgr();
390 if (GetUsedHandleCount() != 0)
392 SysLog(NID_UI, "[Control Manager] The number of unreleased controls: %d", GetUsedHandleCount());
396 _IndicatorManager::ReleaseInstance();
398 _DisplayManager::ReleaseInstance();
400 _AnimationManager::ReleaseInstance();
402 _AccessibilityManager::ReleaseInstance();
404 _KeyEventManager::ReleaseInstance();
405 _TouchManager::ReleaseInstance();
406 _UiEventManager::Release();
410 _ControlManager::GetTopWindow(void) const
414 if (GetWindowCount() == 0)
419 return GetWindow(GetWindowCount() - 1);
423 _ControlManager::GetTopVisibleWindow(void) const
427 if (GetWindowCount() == 0)
432 int count = GetWindowCount();
433 for (int i = 0; i < count; i++)
435 _Window* pWindow = GetWindow((count-1) - i);
437 if (pWindow->GetVisibleState() == true)
447 _ControlManager::GetTopVisibleWindowAt(const Point& point) const
451 if (GetWindowCount() == 0)
456 int count = GetWindowCount();
457 for (int i = 0; i < count; i++)
459 _Window* pWindow = GetWindow((count-1) - i);
461 if (pWindow->GetVisibleState() == false)
466 Rectangle winBounds = pWindow->GetBounds();
467 if (winBounds.Contains(point))
477 _ControlManager::IsWindowOnTop(const _Window& window) const
479 return GetTopWindow() == &window;
483 _ControlManager::IsWindowAttached(const _Window& window) const
485 return __pWindowList->Contains(const_cast<_Window*>(&window));
488 // Open a window and bring it to top.
490 _ControlManager::OpenWindow(_Window& window, bool invalidate)
492 if (dynamic_cast <_Frame*>(&window) != null)
494 __pCurrentFrame = &window;
497 result r = ActivateWindow(window);
498 SysTryReturn(NID_UI, r != E_INVALID_OPERATION, r, r, "[%s] Propagating.", GetErrorMessage(r));
499 SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System Error.");
503 window.Invalidate(true);
510 _ControlManager::ActivateWindow(_Window& window)
513 result r = E_SUCCESS;
515 if (IsWindowOnTop(window))
520 if (window.IsActivationEnabled())
522 _Window* pTopWindow = GetTopWindow();
525 pTopWindow->Deactivate();
529 if (IsWindowAttached(window))
531 r = MoveWindowToTop(window); // [ToDo] excpetion
532 SysAssert(r == E_SUCCESS);
537 r = window.GetControlDelegate().OnAttaching(null);
538 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
540 r = CallOnAttachingToMainTree(window);
541 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
543 r = AttachWindow(window);
544 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
546 if (window.IsActivationEnabled())
551 if (window.IsOrientationRoot() == false)
553 #if !defined(WINDOW_BASE_ROTATE)
554 window.ChangeLayout(GetOrientation());
556 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
559 pEcoreEvas->RotateWindow(window, ::Convert(__orientationStatus));
562 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
565 pEcoreEvas->SetWindowPreferredRotation(window, ::Convert(__orientationStatus));
570 r = window.GetControlDelegate().OnAttached();
571 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
573 r = CallOnAttachedToMainTree(window);
574 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
580 _ControlManager::CallOnAttachingToMainTree(_Control& control)
582 result r = E_SUCCESS;
584 r = control.GetControlDelegate().OnAttachingToMainTree(null);
585 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
587 _Control::ControlList& children = control.GetChildList();
588 _Control* pChild = null;
590 for (int index = 0; index < children.GetCount(); index++)
592 r = children.GetAt(index, pChild);
595 SysAssert(r == E_OUT_OF_RANGE);
597 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
598 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
600 r = CallOnAttachingToMainTree(*pChild);
601 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
608 _ControlManager::CallOnAttachedToMainTree(_Control& control)
610 result r = E_SUCCESS;
612 _Control* pChild = null;
613 _Control::ControlList* pControlList = new (std::nothrow) _Control::ControlList;
614 pControlList->Construct(control.GetChildList());
616 r = control.GetControlDelegate().OnAttachedToMainTree();
617 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
619 for (int index = 0; index < pControlList->GetCount(); index++)
621 r = pControlList->GetAt(index, pChild);
624 SysAssert(r == E_OUT_OF_RANGE);
626 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
627 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
629 r = control.CallOnAttachedToMainTree(*pChild);
630 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
639 _ControlManager::CallOnDetachingFromMainTree(_Control& control)
641 result r = E_SUCCESS;
643 _Control* pChild = null;
644 _Control::ControlList& children = control.GetChildList();
646 r = control.GetControlDelegate().OnDetachingFromMainTree();
647 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
649 for (int index = 0; index < children.GetCount(); index++)
651 r = children.GetAt(index, pChild);
654 SysAssert(r == E_OUT_OF_RANGE);
656 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
657 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
659 r = CallOnDetachingFromMainTree(*pChild);
660 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
667 _ControlManager::CloseWindow(_Window& window) // [ToDo] exception check.
670 result r = E_SUCCESS;
672 if (IsWindowAttached(window) == false)
677 bool wasWindowOnTop = IsWindowOnTop(window);
679 r = CallOnDetachingFromMainTree(window);
680 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
682 window.GetControlDelegate().OnDetaching();
686 r = DetachWindow(window);
687 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
691 _Window* pNewTopWindow = GetTopWindow();
692 if (pNewTopWindow && pNewTopWindow->IsActivationEnabled())
694 pNewTopWindow->Activate();
697 if (dynamic_cast <_Frame*>(pNewTopWindow) != null)
699 __pCurrentFrame = pNewTopWindow;
707 _ControlManager::GetWindow(int index) const
710 __pWindowList->GetAt(index, pWindow);
716 _ControlManager::GetWindowCount(void) const
718 return __pWindowList->GetCount();
722 _ControlManager::AttachWindow(_Window& window)
724 _IndicatorManager::GetInstance()->AddWindow(&window);
726 return __pWindowList->Add(&window);
730 _ControlManager::InsertWindowToBottom(_Window& window)
732 return __pWindowList->InsertAt(&window, 0);
736 _ControlManager::InsertWindowAfter(const _Window& targetWindow, _Window& window)
740 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
741 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
743 return __pWindowList->InsertAt(&window, index+1);
747 _ControlManager::InsertWindowBefore(const _Window& targetWindow, _Window& window)
751 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
752 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
754 return __pWindowList->InsertAt(&window, index);
758 _ControlManager::DetachWindow(_Window& window)
760 _IndicatorManager::GetInstance()->DeleteWindow(&window);
762 return __pWindowList->Remove(&window);
766 _ControlManager::DetachAllWindows(void)
768 __pWindowList->RemoveAll();
772 _ControlManager::MoveWindowToTop(const _Window& window)
774 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
775 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
777 return __pWindowList->Add(const_cast<_Window*>(&window));
781 _ControlManager::MoveWindowToBottom(const _Window& window)
783 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
784 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
786 return __pWindowList->InsertAt(const_cast<_Window*>(&window), 0);
790 _ControlManager::MoveWindowAfter(const _Window& targetWindow, const _Window& window)
792 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
793 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
797 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
798 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
800 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index+1);
804 _ControlManager::MoveWindowBefore(const _Window& targetWindow, const _Window& window)
806 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
807 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
811 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
812 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
814 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index);
818 _ControlManager::GetOrientation(void) const
820 return __orientation;
824 _ControlManager::SetOrientation(_ControlOrientation orientation)
826 __orientation = orientation;
830 _ControlManager::GetScreenRotation(void) const
832 bool autoRotate = true;
833 int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, &autoRotate);
835 if (ret == RUNTIME_INFO_ERROR_NONE)
837 SysLog(NID_UI, "The flag of auto-rotate is %d.", autoRotate);
841 SysLog(NID_UI, "It's failed to get the flag of auto-rotate.");
844 SysLog(NID_UI, "[Window Manager Rotation] AUTO_ROTATION = %d", autoRotate);
846 if (autoRotate == false)
848 return _CONTROL_ROTATION_0;
852 #if defined(WINDOW_BASE_ROTATE)
853 // int degree = app_get_device_orientation();
855 unsigned long rotationState = 0;
856 int ret = sf_check_rotation(&rotationState);
857 int device_rotation = 0;
861 switch (rotationState)
863 case ROTATION_EVENT_0:
866 case ROTATION_EVENT_90:
867 device_rotation = 270;
869 case ROTATION_EVENT_180:
870 device_rotation = 180;
872 case ROTATION_EVENT_270:
873 device_rotation = 90;
879 SysLog(NID_UI, "[Window Manager Rotation] device_rotation = %d", device_rotation);
883 SysLog(NID_UI, "[Window Manager Rotation] device_rotation = error");
886 return ::Convert(device_rotation);
888 return __screenRotation;
894 _ControlManager::OnScreenRotated(int rotation)
896 SysLog(NID_UI, "The angle of Emul or Target is %d.", rotation);
897 __screenRotation = ::Convert(rotation);
899 int count = GetWindowCount();
900 for (int i = 0; i < count; i++)
902 _Window* pWindow = GetWindow((count-1) - i);
904 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
908 Controls::_FrameImpl* pFrameImpl = static_cast<Controls::_FrameImpl*>(pFrame->GetUserData());
909 if (pFrameImpl == null)
914 Controls::_FormImpl* pCurrentFormImpl = pFrameImpl->GetCurrentForm();
915 if (pCurrentFormImpl)
917 pCurrentFormImpl->UpdateOrientationStatus(true);
921 pFrameImpl->UpdateOrientationStatus();
928 _ControlManager::SetTouchedWindow(unsigned int window)
930 __touchedWindow = window;
934 _ControlManager::GetTouchedWindow(void) const
938 if (GetWindowCount() == 0)
943 int count = GetWindowCount();
944 for (int i = 0; i < count; i++)
946 _Window* pWindow = GetWindow((count-1) - i);
948 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
949 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
951 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
952 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
954 if (win == __touchedWindow)
964 _ControlManager::SetOrientationStatus(_ControlRotation orientationStatus)
966 __orientationStatus = orientationStatus;
970 _ControlManager::GetOrientationStatus(void) const
972 return __orientationStatus;
976 _ControlManager::RotateScreen(const _Control& control, _ControlRotation screenRotation)
980 // Set window preferred rotation
982 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
983 SysAssert(pEcoreEvas);
984 if (pEcoreEvas == null)
989 // Rotate root window.
990 _Window* pRootWindow = control.GetRootWindow();
993 pEcoreEvas->RotateWindow(*pRootWindow, ::Convert(screenRotation));
994 pRootWindow->SetRotation(::Convert(screenRotation));
997 #if !defined(WINDOW_BASE_ROTATE)
999 int owneeCount = control.GetOwneeCount();
1000 for (int i = 0; i < owneeCount; i++)
1002 _Window* pOwnee = control.GetOwnee(i);
1005 pEcoreEvas->RotateWindow(*pOwnee, ::Convert(screenRotation));
1010 if (__orientationStatus != screenRotation)
1012 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1015 pTouchManager->SetTouchCanceled(true);
1021 _ControlManager::OnWindowRotated(int rotation)
1024 IEnumeratorT<_Window*>* pEnumerator = __pWindowList->GetEnumeratorN();
1025 SysTryReturnVoidResult(NID_UI, pEnumerator, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1027 while (pEnumerator->MoveNext() == E_SUCCESS)
1029 _Window* pWindow = null;
1030 pEnumerator->GetCurrent(pWindow);
1032 if (pWindow->GetOwner() == null)
1034 void* pUserData = pWindow->GetUserData();
1037 _WindowImpl* pWindowImpl = static_cast<_WindowImpl*>(pUserData);
1038 pWindowImpl->OnRotated(Convert(rotation));
1047 _ControlManager::SetFocusedControl(const _Control& control, bool on)
1051 if (__pFocusedControl == &control)
1056 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1057 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1059 _Control *pPreviousFocusedControl = __pFocusedControl;
1060 if (pPreviousFocusedControl)
1062 // [review] make SetFocus() return result and use the returned result here.
1063 pEcoreEvas->SetFocus(*pPreviousFocusedControl, false);
1064 if (GetLastResult() == E_SUCCESS)
1066 if (pPreviousFocusedControl)
1068 pPreviousFocusedControl->SetFocusState(false);
1070 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1071 _UiEventManager::GetInstance()->SendEvent(event);
1075 // [review] make SetFocus() return result and use the returned result here.
1077 if (control.IsNativeObjectFocusable())
1079 pEcoreEvas->SetFocus(control, true);
1082 if (GetLastResult() == E_SUCCESS)
1084 __pFocusedControl = const_cast<_Control*>(&control);
1085 _UiFocusEvent event(control.GetHandle(), FOCUS_GAINED);
1086 _UiEventManager::GetInstance()->SendEvent(event);
1091 if (__pFocusedControl != &control)
1096 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1097 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1099 if (__pFocusedControl)
1101 // [review] make SetFocus() return result and use the returned result here.
1102 pEcoreEvas->SetFocus(*__pFocusedControl, false);
1103 if (GetLastResult() == E_SUCCESS)
1105 _UiFocusEvent event(__pFocusedControl->GetHandle(), FOCUS_LOST);
1106 _UiEventManager::GetInstance()->SendEvent(event);
1110 _Window* pTopWindow = GetTopWindow();
1113 // [review] make SetFocus() return result and use the returned result here.
1114 pEcoreEvas->SetFocus(*pTopWindow, true);
1115 if (GetLastResult() == E_SUCCESS)
1117 pTopWindow->SetFocusState(true);
1118 _UiFocusEvent event(pTopWindow->GetHandle(), FOCUS_GAINED);
1119 _UiEventManager::GetInstance()->SendEvent(event);
1122 __pFocusedControl = static_cast<_Control*>(pTopWindow);
1127 // [review] called in ~_Control and virtual OnFocusLost is called.
1128 // _Control::Release() instead of ~_Control.
1130 _ControlManager::TakeFocusFromControl(const _Control& control)
1132 if (__pFocusedControl == &control)
1134 _Control *pPreviousFocusedControl = __pFocusedControl;
1135 __pFocusedControl = null;
1136 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1137 _UiEventManager::GetInstance()->SendEvent(event);
1146 _ControlManager::GetFocusedControl(void) const
1148 return __pFocusedControl;
1152 _ControlManager::GetTopmostTouchedControl(const Point& point)
1154 _Control* pControl = null;
1155 _Window* pTopWindow = null;
1157 int count = GetWindowCount();
1160 for (int i = 0; i < count; i++)
1162 _Window* pWindow = GetWindow((count-1) - i);
1164 if (pWindow->GetVisibleState() == false)
1169 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
1170 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
1172 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1173 Ecore_X_Window win = (Ecore_X_Window)ecore_evas_window_get(pEcoreEvas);
1175 Rectangle winDeviceBounds(0, 0, 0, 0);
1176 ecore_x_window_geometry_get(win, &winDeviceBounds.x, &winDeviceBounds.y, &winDeviceBounds.width, &winDeviceBounds.height);
1178 Point winDevicePoint = _CoordinateSystemUtils::Transform(pWindow->GetPosition());
1180 Point devicePoint = _CoordinateSystemUtils::Transform(point);
1181 int x = devicePoint.x;
1182 int y = devicePoint.y;
1186 ecore_x_window_size_get(ecore_x_window_root_get(win), &rootW, &rootH);
1188 int rotation = ecore_evas_rotation_get(pEcoreEvas);
1192 devicePoint.x = rootW - y;
1194 winDeviceBounds.x = rootW - winDevicePoint.y - winDeviceBounds.width;
1195 winDeviceBounds.y = winDevicePoint.x;
1198 devicePoint.x = rootW - x;
1199 devicePoint.y = rootH - y;
1200 winDeviceBounds.x = rootW - winDevicePoint.x - winDeviceBounds.width;
1201 winDeviceBounds.y = rootH - winDevicePoint.y - winDeviceBounds.height;
1205 devicePoint.y = rootH - x;
1206 winDeviceBounds.x = winDevicePoint.y;
1207 winDeviceBounds.y = rootH - winDevicePoint.x - winDeviceBounds.height;
1212 winDeviceBounds.x = winDevicePoint.x;
1213 winDeviceBounds.y = winDevicePoint.y;
1217 if (winDeviceBounds.Contains(devicePoint))
1219 pTopWindow = pWindow;
1225 if (pTopWindow != null)
1228 winPos = pTopWindow->GetPosition();
1230 Point relPos(point.x - winPos.x, point.y - winPos.y);
1231 pControl = pTopWindow->GetTopmostChildAt(relPos);
1232 if (pControl != null)
1234 if (pControl->GetRootWindow() == pTopWindow)
1244 // [review] rename __InvXformer
1246 _ControlManager::GetScreenSize(void) const
1248 return _CoordinateSystemUtils::InverseTransform(Dimension(_Screen::GetWidth(), _Screen::GetHeight()));
1252 _ControlManager::GetScreenSizeF(void) const
1254 return _CoordinateSystemUtils::InverseTransform(FloatDimension(_Screen::GetWidth(), _Screen::GetHeight()));
1258 _ControlManager::InitializeScreenDpi()
1260 Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/screen.dpi", __screenDpi);
1264 _ControlManager::GetScreenDpi() const
1270 _ControlManager::GetCurrentFrame(void) const
1272 return __pCurrentFrame;
1276 _ControlManager::SetDefaultFont(const String& appFontName)
1279 if(appFontName.Equals(__defaultFontName))
1284 __isDefaultFontChanged = true;
1285 __defaultFontName = appFontName;
1286 __defaultFontFileName.Clear();
1289 : public _Control::Visitor
1291 virtual _Control::VisitType Visit(_Control& control)
1293 if (control.__fontName.IsEmpty() && control.__fontFileName.IsEmpty())
1295 control.GetFallbackFont();
1296 _IControlDelegate& delegate = control.GetControlDelegate();
1297 delegate.OnFontChanged(control.__pFont);
1299 return _Control::VISIT_DOWNWARD;
1305 int count = GetWindowCount();
1306 for (int j = 0; j < count; j++)
1308 _Window* pWindow = GetWindow((count-1) - j);
1309 pWindow->Accept(visitor);
1312 SetDefaultFontChangeState(false);
1318 _ControlManager::GetDefaultFont(void)
1320 return __defaultFontName;
1324 _ControlManager::SetDefaultFontFromFile(const Tizen::Base::String& fileName)
1326 if(fileName.Equals(__defaultFontFileName))
1331 __isDefaultFontChanged = true;
1332 __defaultFontFileName = fileName;
1333 __defaultFontName.Clear();
1335 : public _Control::Visitor
1337 virtual _Control::VisitType Visit(_Control& control)
1339 if (control.__fontName.IsEmpty() && control.__fontFileName.IsEmpty())
1341 control.GetFallbackFont();
1342 _IControlDelegate& delegate = control.GetControlDelegate();
1343 delegate.OnFontChanged(control.__pFont);
1345 return _Control::VISIT_DOWNWARD;
1351 int count = GetWindowCount();
1352 for (int j = 0; j < count; j++)
1354 _Window* pWindow = GetWindow((count-1) - j);
1355 pWindow->Accept(visitor);
1358 SetDefaultFontChangeState(false);
1363 _ControlManager::GetDefaultFontFile(void) const
1365 return __defaultFontFileName;
1368 _ControlManager::IsDefaultFontChanged(void)
1370 return __isDefaultFontChanged;
1374 _ControlManager::SetDefaultFontChangeState(bool isDefaultFontChanged)
1376 __isDefaultFontChanged = isDefaultFontChanged;
1380 _ControlManager::IsFrameActivated(void) const
1382 _Frame* pFrame = dynamic_cast<_Frame*>(__pCurrentFrame);
1383 SysTryReturn(NID_UI, pFrame, false, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1385 return pFrame->IsActivated();
1388 // [review] refactoring
1390 _ControlManager::AddGestureDetector(const _TouchGestureDetector& gesture)
1394 SysTryReturn(NID_UI, __pGestureList != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1396 bool exist = __pGestureList->Contains(const_cast<_TouchGestureDetector*>(&gesture));
1397 SysTryReturnResult(NID_UI, exist == false, E_OBJ_ALREADY_EXIST, "[E_OBJ_ALREADY_EXIST]__pGestureList has gesture already");
1399 result r = __pGestureList->Add(const_cast<_TouchGestureDetector*>(&gesture));
1400 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1402 switch (gesture.GetDetectorType())
1404 case _TOUCH_GESTURE_DETECTOR_TYPE_TAP:
1406 _TouchTapGestureDetector* pGestureTap = dynamic_cast<_TouchTapGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1407 SysTryReturnResult(NID_UI, pGestureTap, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1409 if (pGestureTap->GetTapInterval() > __gestureMaxDuration)
1411 __gestureMaxDuration = pGestureTap->GetTapInterval();
1415 case _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS:
1417 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1418 SysTryReturnResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1420 if (pGestureLongPress->GetDuration() > __gestureMaxDuration)
1422 __gestureMaxDuration = pGestureLongPress->GetDuration();
1434 _ControlManager::RemoveGestureDetector(const _TouchGestureDetector& gesture)
1438 result r = __pGestureList->Remove(&(const_cast<_TouchGestureDetector&>(gesture)));
1439 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1444 IListT <_TouchGestureDetector*>*
1445 _ControlManager::GetGestureDetectorList(void) const
1447 return __pGestureList;
1451 _ControlManager::GetGestureMaxTimeDuration(void) const
1453 return __gestureMaxDuration;
1457 _ControlManager::OnSettingChanged(Tizen::Base::String& key)
1459 const wchar_t* FONT_TYPE = L"http://tizen.org/setting/font.type";
1460 const wchar_t* LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country";
1461 const wchar_t* LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
1463 if (key == FONT_TYPE || key == LOCALE_COUNTRY || key == LOCALE_LANGUAGE)
1465 _FontImpl::UpdateDefaultFont(key);
1467 int count = GetWindowCount();
1469 for(int index = 0; index < count ; index++)
1471 _Window* pWindow = GetWindow(index);
1472 pWindow->Invalidate(true);
1476 //fixme : check longpress duration key
1479 if (!__pGestureList || (__pGestureList && (__pGestureList->GetCount() <= 0)))
1484 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = __pGestureList->GetEnumeratorN();
1485 SysTryReturnVoidResult(NID_UI, pEnumerator, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1487 int duration = static_cast<int>(elm_config_longpress_timeout_get() * 1000);
1493 while (pEnumerator->MoveNext() == E_SUCCESS)
1495 _TouchGestureDetector* pGestureDetector = null;
1496 pEnumerator->GetCurrent(pGestureDetector);
1498 if (!pGestureDetector)
1503 if(pGestureDetector->GetDetectorType() == _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS)
1505 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(pGestureDetector));
1506 SysTryReturnVoidResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1507 pGestureLongPress->SetDuration(duration);