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_DimmingManager.h"
52 #include "FUi_TouchLongPressGestureDetector.h"
53 #include "FUi_TouchTapGestureDetector.h"
54 #include "FUi_KeyEventManager.h"
55 #include "FUi_CoordinateSystemUtils.h"
56 #include "FUiAnim_RootVisualElement.h"
57 #include "FUiAnim_AnimationManager.h"
58 #include "FUiAnim_DisplayManager.h"
59 #include "FUi_AccessibilityManager.h"
60 #include "FUiAnim_VisualElement.h"
61 #include "FUiAnim_EflLayer.h"
62 #include "FUiCtrl_FrameImpl.h"
63 #include "FUiCtrl_FormImpl.h"
64 #include "FUiCtrl_Frame.h"
65 #include "FUiCtrl_IndicatorManager.h"
67 using namespace Tizen::App;
68 using namespace Tizen::App::Package;
69 using namespace Tizen::Base;
70 using namespace Tizen::Base::Collection;
71 using namespace Tizen::Graphics;
72 using namespace Tizen::Ui;
73 using namespace Tizen::Ui::Animations;
74 using namespace Tizen::Ui::Controls;
75 using namespace Tizen::System;
79 _ControlRotation Convert(int rotationDegree)
81 switch (rotationDegree)
84 return _CONTROL_ROTATION_0;
86 return _CONTROL_ROTATION_90;
88 return _CONTROL_ROTATION_180;
90 return _CONTROL_ROTATION_270;
92 return _CONTROL_ROTATION_0;
96 int Convert(_ControlRotation rotation)
100 case _CONTROL_ROTATION_0:
102 case _CONTROL_ROTATION_90:
104 case _CONTROL_ROTATION_180:
106 case _CONTROL_ROTATION_270:
116 _UiPrintControl(const _Control& control, bool printChildren, int level)
118 const_cast<_Control&>(control).PrintDescription(printChildren, level);
122 _UiPrintTree(int level)
124 _ControlManager* pControlManager = _ControlManager::GetInstance();
125 SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
127 if (pControlManager->GetWindowCount() == 0)
132 int count = pControlManager->GetWindowCount();
133 for (int i = 0; i < count; i++)
135 _Window* pWindow = pControlManager->GetWindow((count-1) - i);
136 _UiPrintControl(*pWindow, true, level);
141 namespace Tizen { namespace Ui
143 _ControlManager* _ControlManager::__pInstance = null;
146 _ControlManager::Initialize(void)
148 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
152 pthread_once(&once_block, InitInstance);
155 result r = _SettingInfoImpl::AddSettingEventListenerForInternal(*__pInstance);
156 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
158 // [ToDo] Is it OK to directly get the device orientation?
159 int degree = app_get_device_orientation();
160 SysLog(NID_UI, "The initial value of device orientation is %d.", degree);
162 __pInstance->__screenRotation = ::Convert(degree);
168 _ControlManager::Release(void)
170 result r = _SettingInfoImpl::RemoveSettingEventListenerForInternal(*__pInstance);
171 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
180 _ControlManager::GetInstance(void)
186 _ControlManager::InitInstance(void)
193 __pInstance = new (std::nothrow) _ControlManager;
194 SysAssert(__pInstance);
198 _ControlManager::Register(_Control* pObject)
202 SysLog(NID_UI, "A _Control Registered()");
207 return _ControlHandle();
210 return __objectManager.Register(*pObject);
214 _ControlManager::Release(const _ControlHandle& handle)
216 _Control* pObject = GetObject(handle);
219 SysLog(NID_UI, "A _Control Released()");
222 return __objectManager.Unregister(handle);
226 _ControlManager::GetObject(const _ControlHandle& handle)
228 return __objectManager.GetObject(handle);
232 _ControlManager::GetObject(const _ControlHandle& handle) const
234 return __objectManager.GetObject(handle);
238 _ControlManager::GetUsedHandleCount(void) const
240 return __objectManager.GetObjectCount();
244 _ControlManager::GetAppCoordinateSystem(bool& isCoordinateSystemLogical, int& logicalCoordinateSystemInt, _BaseScreenSize& logicalBaseScreenSize)
246 _PackageInfoImpl infoImpl;
248 String subAppId(_AppInfo::GetPackageId());
250 result r = infoImpl.Construct(subAppId);
251 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
254 String baseScreenSize(null);
255 String coordinateSystem(null);
256 String logicalCoordinate(null);
258 result r = infoImpl.GetUiScalabilityInfo(baseScreenSize, coordinateSystem, logicalCoordinate);
259 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
261 if (coordinateSystem.Equals(L"Physical", false))
263 isCoordinateSystemLogical = false;
264 logicalCoordinateSystemInt = 0;
265 logicalBaseScreenSize = BASE_SCREEN_SIZE_DEFAULT;
271 r = Integer::Parse(logicalCoordinate, logicalCoordinateSystemInt);
272 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
275 if (baseScreenSize.Equals(L"Large", false))
277 logicalBaseScreenSize = BASE_SCREEN_SIZE_LARGE;
281 logicalBaseScreenSize = BASE_SCREEN_SIZE_NORMAL;
288 _ControlManager::IsCoordinateSystemLogical(void) const
290 return __isCoordinateSystemLogical;
294 _ControlManager::GetCoordinateSystem(void) const
296 return __logicalCoordinateSystem;
300 _ControlManager::GetLogicalBaseScreenSize(void) const
302 return __logicalBaseScreenSize;
305 _ControlManager::_ControlManager(void) // [ToDo] exception check.
306 : __pWindowList(null)
307 , __isCoordinateSystemLogical(true)
308 , __logicalCoordinateSystem(0)
309 , __logicalBaseScreenSize(BASE_SCREEN_SIZE_NONE)
310 , __pSystemWindowList(null)
311 , __pFocusedControl(null)
312 , __screenRotation(_CONTROL_ROTATION_0)
313 , __orientationStatus(_CONTROL_ROTATION_0)
314 , __orientation(_CONTROL_ORIENTATION_PORTRAIT)
315 , __pCurrentFrame(null)
316 , __pGestureList(null)
317 , __gestureMaxDuration(0)
319 , __isDefaultFontChanged(false)
320 , __defaultFontName(L"")
323 result r = GetAppCoordinateSystem(__isCoordinateSystemLogical, __logicalCoordinateSystem, __logicalBaseScreenSize);
324 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] System error occurred.");
326 Dimension deviceResolution = CoordinateSystem::GetPhysicalResolution();
327 _BaseScreenSize deviceBaseScreenSize = _CoordinateSystem::GetInstance()->GetPhysicalBaseScreenSize();
329 r = _CoordinateSystem::Initialize(__logicalCoordinateSystem, __logicalBaseScreenSize, deviceResolution, deviceBaseScreenSize);
330 SysAssert(r == E_SUCCESS);
332 r = _AnimationManager::CreateInstance();
333 SysAssertf(r == E_SUCCESS, "Failed to create animation manager!");
335 r = _DisplayManager::CreateInstance();
336 SysAssertf(r == E_SUCCESS, "Failed to create display manager!");
338 _EcoreEvas::CreateInstanceN();
340 __pWindowList = new (std::nothrow)LinkedListT<_Window*>;
341 SysTryCatch(NID_UI, __pWindowList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
343 __pGestureList = new (std::nothrow)LinkedListT<_TouchGestureDetector*>;
344 SysTryCatch(NID_UI, __pGestureList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
346 _UiEventManager::Initialize();
347 _TouchManager::Initialize();
348 _KeyEventManager::Initialize();
349 _IndicatorManager::InitializeInstance();
350 _AccessibilityManager::CreateInstance();
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 _DimmingManager::ReleaseInstance();
407 _UiEventManager::Release();
411 _ControlManager::GetTopWindow(void) const
415 if (GetWindowCount() == 0)
420 return GetWindow(GetWindowCount() - 1);
424 _ControlManager::GetTopVisibleWindow(void) const
428 if (GetWindowCount() == 0)
433 int count = GetWindowCount();
434 for (int i = 0; i < count; i++)
436 _Window* pWindow = GetWindow((count-1) - i);
438 if (pWindow->GetVisibleState() == true)
448 _ControlManager::GetTopVisibleWindowAt(const Point& point) const
452 if (GetWindowCount() == 0)
457 int count = GetWindowCount();
458 for (int i = 0; i < count; i++)
460 _Window* pWindow = GetWindow((count-1) - i);
462 if (pWindow->GetVisibleState() == false)
467 Rectangle winBounds = pWindow->GetBounds();
468 if (winBounds.Contains(point))
478 _ControlManager::IsWindowOnTop(const _Window& window) const
480 return GetTopWindow() == &window;
484 _ControlManager::IsWindowAttached(const _Window& window) const
486 return __pWindowList->Contains(const_cast<_Window*>(&window));
489 // Open a window and bring it to top.
491 _ControlManager::OpenWindow(_Window& window, bool invalidate)
493 if (dynamic_cast <_Frame*>(&window) != null)
495 __pCurrentFrame = &window;
498 result r = ActivateWindow(window);
499 SysTryReturn(NID_UI, r != E_INVALID_OPERATION, r, r, "[%s] Propagating.", GetErrorMessage(r));
500 SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System Error.");
504 window.Invalidate(true);
511 _ControlManager::ActivateWindow(_Window& window)
514 result r = E_SUCCESS;
516 if (IsWindowOnTop(window))
521 if (window.IsActivationEnabled())
523 _Window* pTopWindow = GetTopWindow();
526 pTopWindow->Deactivate();
530 if (IsWindowAttached(window))
532 r = MoveWindowToTop(window); // [ToDo] excpetion
533 SysAssert(r == E_SUCCESS);
538 r = window.GetControlDelegate().OnAttaching(null);
539 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
541 r = CallOnAttachingToMainTree(window);
542 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
544 r = AttachWindow(window);
545 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
547 if (window.IsActivationEnabled())
552 if (window.IsOrientationRoot() == false)
554 #if !defined(WINDOW_BASE_ROTATE)
555 window.ChangeLayout(GetOrientation());
557 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
560 pEcoreEvas->RotateWindow(window, ::Convert(__orientationStatus));
563 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
566 pEcoreEvas->SetWindowPreferredRotation(window, ::Convert(__orientationStatus));
571 r = window.GetControlDelegate().OnAttached();
572 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
574 r = CallOnAttachedToMainTree(window);
575 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
581 _ControlManager::CallOnAttachingToMainTree(_Control& control)
583 result r = E_SUCCESS;
585 r = control.GetControlDelegate().OnAttachingToMainTree(null);
586 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
588 _Control::ControlList& children = control.GetChildList();
589 _Control* pChild = null;
591 for (int index = 0; index < children.GetCount(); index++)
593 r = children.GetAt(index, pChild);
596 SysAssert(r == E_OUT_OF_RANGE);
598 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
599 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
601 r = CallOnAttachingToMainTree(*pChild);
602 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
609 _ControlManager::CallOnAttachedToMainTree(_Control& control)
611 result r = E_SUCCESS;
613 _Control* pChild = null;
614 _Control::ControlList* pControlList = new (std::nothrow) _Control::ControlList;
615 pControlList->Construct(control.GetChildList());
617 r = control.GetControlDelegate().OnAttachedToMainTree();
618 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
620 for (int index = 0; index < pControlList->GetCount(); index++)
622 r = pControlList->GetAt(index, pChild);
625 SysAssert(r == E_OUT_OF_RANGE);
627 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
628 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
630 r = control.CallOnAttachedToMainTree(*pChild);
631 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
640 _ControlManager::CallOnDetachingFromMainTree(_Control& control)
642 result r = E_SUCCESS;
644 _Control* pChild = null;
645 _Control::ControlList& children = control.GetChildList();
647 r = control.GetControlDelegate().OnDetachingFromMainTree();
648 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
650 for (int index = 0; index < children.GetCount(); index++)
652 r = children.GetAt(index, pChild);
655 SysAssert(r == E_OUT_OF_RANGE);
657 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
658 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
660 r = CallOnDetachingFromMainTree(*pChild);
661 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
668 _ControlManager::CloseWindow(_Window& window) // [ToDo] exception check.
671 result r = E_SUCCESS;
673 if (IsWindowAttached(window) == false)
678 bool wasWindowOnTop = IsWindowOnTop(window);
680 r = CallOnDetachingFromMainTree(window);
681 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
683 window.GetControlDelegate().OnDetaching();
687 r = DetachWindow(window);
688 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
692 _Window* pNewTopWindow = GetTopWindow();
693 if (pNewTopWindow && pNewTopWindow->IsActivationEnabled())
695 pNewTopWindow->Activate();
698 if (dynamic_cast <_Frame*>(pNewTopWindow) != null)
700 __pCurrentFrame = pNewTopWindow;
708 _ControlManager::GetWindow(int index) const
711 __pWindowList->GetAt(index, pWindow);
717 _ControlManager::GetWindowCount(void) const
719 return __pWindowList->GetCount();
723 _ControlManager::AttachWindow(_Window& window)
725 _IndicatorManager::GetInstance()->AddWindow(&window);
727 if (window.IsDimmingEnabled())
729 _DimmingManager::GetInstance()->RegisterWindow(&window);
732 return __pWindowList->Add(&window);
736 _ControlManager::InsertWindowToBottom(_Window& window)
738 return __pWindowList->InsertAt(&window, 0);
742 _ControlManager::InsertWindowAfter(const _Window& targetWindow, _Window& window)
746 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
747 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
749 return __pWindowList->InsertAt(&window, index+1);
753 _ControlManager::InsertWindowBefore(const _Window& targetWindow, _Window& window)
757 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
758 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
760 return __pWindowList->InsertAt(&window, index);
764 _ControlManager::DetachWindow(_Window& window)
766 _IndicatorManager::GetInstance()->DeleteWindow(&window);
768 if (window.IsDimmingEnabled())
770 _DimmingManager::GetInstance()->UnRegisterWindow(&window);
773 return __pWindowList->Remove(&window);
777 _ControlManager::DetachAllWindows(void)
779 __pWindowList->RemoveAll();
783 _ControlManager::MoveWindowToTop(const _Window& window)
785 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
786 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
788 return __pWindowList->Add(const_cast<_Window*>(&window));
792 _ControlManager::MoveWindowToBottom(const _Window& window)
794 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
795 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
797 return __pWindowList->InsertAt(const_cast<_Window*>(&window), 0);
801 _ControlManager::MoveWindowAfter(const _Window& targetWindow, const _Window& window)
803 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
804 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
808 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
809 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
811 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index+1);
815 _ControlManager::MoveWindowBefore(const _Window& targetWindow, const _Window& window)
817 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
818 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
822 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
823 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
825 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index);
829 _ControlManager::GetOrientation(void) const
831 return __orientation;
835 _ControlManager::SetOrientation(_ControlOrientation orientation)
837 __orientation = orientation;
841 _ControlManager::GetScreenRotation(void) const
843 bool autoRotate = true;
844 int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, &autoRotate);
846 if (ret == RUNTIME_INFO_ERROR_NONE)
848 SysLog(NID_UI, "The flag of auto-rotate is %d.", autoRotate);
852 SysLog(NID_UI, "It's failed to get the flag of auto-rotate.");
855 SysLog(NID_UI, "[Window Manager Rotation] AUTO_ROTATION = %d", autoRotate);
857 if (autoRotate == false)
859 return _CONTROL_ROTATION_0;
863 #if defined(WINDOW_BASE_ROTATE)
864 // int degree = app_get_device_orientation();
866 unsigned long rotationState = 0;
867 int ret = sf_check_rotation(&rotationState);
868 int device_rotation = 0;
872 switch (rotationState)
874 case ROTATION_EVENT_0:
877 case ROTATION_EVENT_90:
878 device_rotation = 270;
880 case ROTATION_EVENT_180:
881 device_rotation = 180;
883 case ROTATION_EVENT_270:
884 device_rotation = 90;
890 SysLog(NID_UI, "[Window Manager Rotation] device_rotation = %d", device_rotation);
894 SysLog(NID_UI, "[Window Manager Rotation] device_rotation = error");
897 return ::Convert(device_rotation);
899 return __screenRotation;
905 _ControlManager::OnScreenRotated(int rotation)
907 SysLog(NID_UI, "The angle of Emul or Target is %d.", rotation);
908 __screenRotation = ::Convert(rotation);
910 int count = GetWindowCount();
911 for (int i = 0; i < count; i++)
913 _Window* pWindow = GetWindow((count-1) - i);
915 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
919 Controls::_FrameImpl* pFrameImpl = static_cast<Controls::_FrameImpl*>(pFrame->GetUserData());
920 if (pFrameImpl == null)
925 Controls::_FormImpl* pCurrentFormImpl = pFrameImpl->GetCurrentForm();
926 if (pCurrentFormImpl)
928 pCurrentFormImpl->UpdateOrientationStatus(true);
932 pFrameImpl->UpdateOrientationStatus();
939 _ControlManager::SetTouchedWindow(unsigned int window)
941 __touchedWindow = window;
945 _ControlManager::GetTouchedWindow(void) const
949 if (GetWindowCount() == 0)
954 int count = GetWindowCount();
955 for (int i = 0; i < count; i++)
957 _Window* pWindow = GetWindow((count-1) - i);
959 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
960 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
962 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
963 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
965 if (win == __touchedWindow)
975 _ControlManager::SetOrientationStatus(_ControlRotation orientationStatus)
977 __orientationStatus = orientationStatus;
981 _ControlManager::GetOrientationStatus(void) const
983 return __orientationStatus;
987 _ControlManager::RotateScreen(const _Control& control, _ControlRotation screenRotation)
991 // Set window preferred rotation
993 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
994 SysAssert(pEcoreEvas);
995 if (pEcoreEvas == null)
1000 // Rotate root window.
1001 _Window* pRootWindow = control.GetRootWindow();
1004 pEcoreEvas->RotateWindow(*pRootWindow, ::Convert(screenRotation));
1005 pRootWindow->SetRotation(::Convert(screenRotation));
1008 #if !defined(WINDOW_BASE_ROTATE)
1010 int owneeCount = control.GetOwneeCount();
1011 for (int i = 0; i < owneeCount; i++)
1013 _Window* pOwnee = control.GetOwnee(i);
1016 pEcoreEvas->RotateWindow(*pOwnee, ::Convert(screenRotation));
1021 if (__orientationStatus != screenRotation)
1023 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1026 pTouchManager->SetTouchCanceled(true);
1032 _ControlManager::OnWindowRotated(int rotation)
1035 IEnumeratorT<_Window*>* pEnumerator = __pWindowList->GetEnumeratorN();
1036 SysTryReturnVoidResult(NID_UI, pEnumerator, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1038 while (pEnumerator->MoveNext() == E_SUCCESS)
1040 _Window* pWindow = null;
1041 pEnumerator->GetCurrent(pWindow);
1043 if (pWindow->GetOwner() == null)
1045 void* pUserData = pWindow->GetUserData();
1048 _WindowImpl* pWindowImpl = static_cast<_WindowImpl*>(pUserData);
1049 pWindowImpl->OnRotated(Convert(rotation));
1058 _ControlManager::SetFocusedControl(const _Control& control, bool on)
1062 if (__pFocusedControl == &control)
1067 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1068 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1070 _Control *pPreviousFocusedControl = __pFocusedControl;
1071 if (pPreviousFocusedControl)
1073 // [review] make SetFocus() return result and use the returned result here.
1074 pEcoreEvas->SetFocus(*pPreviousFocusedControl, false);
1075 if (GetLastResult() == E_SUCCESS)
1077 if (pPreviousFocusedControl)
1079 pPreviousFocusedControl->SetFocusState(false);
1081 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1082 _UiEventManager::GetInstance()->SendEvent(event);
1086 // [review] make SetFocus() return result and use the returned result here.
1088 if (control.IsNativeObjectFocusable())
1090 pEcoreEvas->SetFocus(control, true);
1093 if (GetLastResult() == E_SUCCESS)
1095 __pFocusedControl = const_cast<_Control*>(&control);
1096 _UiFocusEvent event(control.GetHandle(), FOCUS_GAINED);
1097 _UiEventManager::GetInstance()->SendEvent(event);
1102 if (__pFocusedControl != &control)
1107 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1108 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1110 if (__pFocusedControl)
1112 // [review] make SetFocus() return result and use the returned result here.
1113 pEcoreEvas->SetFocus(*__pFocusedControl, false);
1114 if (GetLastResult() == E_SUCCESS)
1116 _UiFocusEvent event(__pFocusedControl->GetHandle(), FOCUS_LOST);
1117 _UiEventManager::GetInstance()->SendEvent(event);
1121 _Window* pTopWindow = GetTopWindow();
1124 // [review] make SetFocus() return result and use the returned result here.
1125 pEcoreEvas->SetFocus(*pTopWindow, true);
1126 if (GetLastResult() == E_SUCCESS)
1128 pTopWindow->SetFocusState(true);
1129 _UiFocusEvent event(pTopWindow->GetHandle(), FOCUS_GAINED);
1130 _UiEventManager::GetInstance()->SendEvent(event);
1133 __pFocusedControl = static_cast<_Control*>(pTopWindow);
1138 // [review] called in ~_Control and virtual OnFocusLost is called.
1139 // _Control::Release() instead of ~_Control.
1141 _ControlManager::TakeFocusFromControl(const _Control& control)
1143 if (__pFocusedControl == &control)
1145 _Control *pPreviousFocusedControl = __pFocusedControl;
1146 __pFocusedControl = null;
1147 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1148 _UiEventManager::GetInstance()->SendEvent(event);
1157 _ControlManager::GetFocusedControl(void) const
1159 return __pFocusedControl;
1163 _ControlManager::GetTopmostTouchedControl(const Point& point)
1165 _Control* pControl = null;
1166 _Window* pTopWindow = null;
1168 int count = GetWindowCount();
1171 for (int i = 0; i < count; i++)
1173 _Window* pWindow = GetWindow((count-1) - i);
1175 if (pWindow->GetVisibleState() == false)
1180 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
1181 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
1183 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1184 Ecore_X_Window win = (Ecore_X_Window)ecore_evas_window_get(pEcoreEvas);
1186 Rectangle winDeviceBounds(0, 0, 0, 0);
1187 ecore_x_window_geometry_get(win, &winDeviceBounds.x, &winDeviceBounds.y, &winDeviceBounds.width, &winDeviceBounds.height);
1189 Point winDevicePoint = _CoordinateSystemUtils::Transform(pWindow->GetPosition());
1191 Point devicePoint = _CoordinateSystemUtils::Transform(point);
1192 int x = devicePoint.x;
1193 int y = devicePoint.y;
1197 ecore_x_window_size_get(ecore_x_window_root_get(win), &rootW, &rootH);
1199 int rotation = ecore_evas_rotation_get(pEcoreEvas);
1203 devicePoint.x = rootW - y;
1205 winDeviceBounds.x = rootW - winDevicePoint.y - winDeviceBounds.width;
1206 winDeviceBounds.y = winDevicePoint.x;
1209 devicePoint.x = rootW - x;
1210 devicePoint.y = rootH - y;
1211 winDeviceBounds.x = rootW - winDevicePoint.x - winDeviceBounds.width;
1212 winDeviceBounds.y = rootH - winDevicePoint.y - winDeviceBounds.height;
1216 devicePoint.y = rootH - x;
1217 winDeviceBounds.x = winDevicePoint.y;
1218 winDeviceBounds.y = rootH - winDevicePoint.x - winDeviceBounds.height;
1223 winDeviceBounds.x = winDevicePoint.x;
1224 winDeviceBounds.y = winDevicePoint.y;
1228 if (winDeviceBounds.Contains(devicePoint))
1230 pTopWindow = pWindow;
1236 if (pTopWindow != null)
1239 winPos = pTopWindow->GetPosition();
1241 Point relPos(point.x - winPos.x, point.y - winPos.y);
1242 pControl = pTopWindow->GetTopmostChildAt(relPos);
1243 if (pControl != null)
1245 if (pControl->GetRootWindow() == pTopWindow)
1255 // [review] rename __InvXformer
1257 _ControlManager::GetScreenSize(void) const
1259 return _CoordinateSystemUtils::InverseTransform(Dimension(_Screen::GetWidth(), _Screen::GetHeight()));
1263 _ControlManager::GetScreenSizeF(void) const
1265 return _CoordinateSystemUtils::InverseTransform(FloatDimension(_Screen::GetWidth(), _Screen::GetHeight()));
1269 _ControlManager::SetScreenDpi(int dpi)
1275 _ControlManager::GetScreenDpi() const
1281 _ControlManager::GetCurrentFrame(void) const
1283 return __pCurrentFrame;
1287 _ControlManager::SetDefaultFont(const String& appFontName)
1290 if(appFontName.Equals(__defaultFontName))
1295 __isDefaultFontChanged = true;
1296 __defaultFontName = appFontName;
1297 __defaultFontFileName.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);
1329 _ControlManager::GetDefaultFont(void)
1331 return __defaultFontName;
1335 _ControlManager::SetDefaultFontFromFile(const Tizen::Base::String& fileName)
1337 if(fileName.Equals(__defaultFontFileName))
1342 __isDefaultFontChanged = true;
1343 __defaultFontFileName = fileName;
1344 __defaultFontName.Clear();
1346 : public _Control::Visitor
1348 virtual _Control::VisitType Visit(_Control& control)
1350 if (control.__fontName.IsEmpty() && control.__fontFileName.IsEmpty())
1352 control.GetFallbackFont();
1353 _IControlDelegate& delegate = control.GetControlDelegate();
1354 delegate.OnFontChanged(control.__pFont);
1356 return _Control::VISIT_DOWNWARD;
1362 int count = GetWindowCount();
1363 for (int j = 0; j < count; j++)
1365 _Window* pWindow = GetWindow((count-1) - j);
1366 pWindow->Accept(visitor);
1369 SetDefaultFontChangeState(false);
1374 _ControlManager::GetDefaultFontFile(void) const
1376 return __defaultFontFileName;
1379 _ControlManager::IsDefaultFontChanged(void)
1381 return __isDefaultFontChanged;
1385 _ControlManager::SetDefaultFontChangeState(bool isDefaultFontChanged)
1387 __isDefaultFontChanged = isDefaultFontChanged;
1391 _ControlManager::IsFrameActivated(void) const
1393 _Frame* pFrame = dynamic_cast<_Frame*>(__pCurrentFrame);
1394 SysTryReturn(NID_UI, pFrame, false, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1396 return pFrame->IsActivated();
1399 // [review] refactoring
1401 _ControlManager::AddGestureDetector(const _TouchGestureDetector& gesture)
1405 SysTryReturn(NID_UI, __pGestureList != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1407 bool exist = __pGestureList->Contains(const_cast<_TouchGestureDetector*>(&gesture));
1408 SysTryReturnResult(NID_UI, exist == false, E_OBJ_ALREADY_EXIST, "[E_OBJ_ALREADY_EXIST]__pGestureList has gesture already");
1410 result r = __pGestureList->Add(const_cast<_TouchGestureDetector*>(&gesture));
1411 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1413 switch (gesture.GetDetectorType())
1415 case _TOUCH_GESTURE_DETECTOR_TYPE_TAP:
1417 _TouchTapGestureDetector* pGestureTap = dynamic_cast<_TouchTapGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1418 SysTryReturnResult(NID_UI, pGestureTap, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1420 if (pGestureTap->GetTapInterval() > __gestureMaxDuration)
1422 __gestureMaxDuration = pGestureTap->GetTapInterval();
1426 case _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS:
1428 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1429 SysTryReturnResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1431 if (pGestureLongPress->GetDuration() > __gestureMaxDuration)
1433 __gestureMaxDuration = pGestureLongPress->GetDuration();
1445 _ControlManager::RemoveGestureDetector(const _TouchGestureDetector& gesture)
1449 result r = __pGestureList->Remove(&(const_cast<_TouchGestureDetector&>(gesture)));
1450 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1455 IListT <_TouchGestureDetector*>*
1456 _ControlManager::GetGestureDetectorList(void) const
1458 return __pGestureList;
1462 _ControlManager::GetGestureMaxTimeDuration(void) const
1464 return __gestureMaxDuration;
1468 _ControlManager::OnSettingChanged(Tizen::Base::String& key)
1470 const wchar_t* FONT_TYPE = L"http://tizen.org/setting/font.type";
1471 const wchar_t* LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country";
1472 const wchar_t* LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
1474 if (key == FONT_TYPE || key == LOCALE_COUNTRY || key == LOCALE_LANGUAGE)
1476 _FontImpl::UpdateDefaultFont(key);
1478 int count = GetWindowCount();
1480 for(int index = 0; index < count ; index++)
1482 _Window* pWindow = GetWindow(index);
1483 pWindow->Invalidate(true);
1487 //fixme : check longpress duration key
1490 if (!__pGestureList || (__pGestureList && (__pGestureList->GetCount() <= 0)))
1495 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = __pGestureList->GetEnumeratorN();
1496 SysTryReturnVoidResult(NID_UI, pEnumerator, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1498 int duration = static_cast<int>(elm_config_longpress_timeout_get() * 1000);
1504 while (pEnumerator->MoveNext() == E_SUCCESS)
1506 _TouchGestureDetector* pGestureDetector = null;
1507 pEnumerator->GetCurrent(pGestureDetector);
1509 if (!pGestureDetector)
1514 if(pGestureDetector->GetDetectorType() == _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS)
1516 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(pGestureDetector));
1517 SysTryReturnVoidResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1518 pGestureLongPress->SetDuration(duration);