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);
166 _ControlManager::Release(void)
168 result r = _SettingInfoImpl::RemoveSettingEventListenerForInternal(*__pInstance);
169 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
176 _ControlManager::GetInstance(void)
182 _ControlManager::InitInstance(void)
189 __pInstance = new (std::nothrow) _ControlManager;
190 SysAssert(__pInstance);
194 _ControlManager::Register(_Control* pObject)
198 SysLog(NID_UI, "A _Control Registered()");
203 return _ControlHandle();
206 return __objectManager.Register(*pObject);
210 _ControlManager::Release(const _ControlHandle& handle)
212 _Control* pObject = GetObject(handle);
215 SysLog(NID_UI, "A _Control Released()");
218 return __objectManager.Unregister(handle);
222 _ControlManager::GetObject(const _ControlHandle& handle)
224 return __objectManager.GetObject(handle);
228 _ControlManager::GetObject(const _ControlHandle& handle) const
230 return __objectManager.GetObject(handle);
234 _ControlManager::GetUsedHandleCount(void) const
236 return __objectManager.GetObjectCount();
240 _ControlManager::GetAppCoordinateSystem(bool& isCoordinateSystemLogical, int& logicalCoordinateSystemInt, _BaseScreenSize& logicalBaseScreenSize)
242 _PackageInfoImpl infoImpl;
244 String subAppId(_AppInfo::GetPackageId());
246 result r = infoImpl.Construct(subAppId);
247 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
250 String baseScreenSize(null);
251 String coordinateSystem(null);
252 String logicalCoordinate(null);
254 result r = infoImpl.GetUiScalabilityInfo(baseScreenSize, coordinateSystem, logicalCoordinate);
255 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
257 if (coordinateSystem.Equals(L"Physical", false))
259 isCoordinateSystemLogical = false;
260 logicalCoordinateSystemInt = 0;
261 logicalBaseScreenSize = BASE_SCREEN_SIZE_DEFAULT;
267 r = Integer::Parse(logicalCoordinate, logicalCoordinateSystemInt);
268 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
271 if (baseScreenSize.Equals(L"Large", false))
273 logicalBaseScreenSize = BASE_SCREEN_SIZE_LARGE;
277 logicalBaseScreenSize = BASE_SCREEN_SIZE_NORMAL;
284 _ControlManager::IsCoordinateSystemLogical(void) const
286 return __isCoordinateSystemLogical;
290 _ControlManager::GetCoordinateSystem(void) const
292 return __logicalCoordinateSystem;
296 _ControlManager::GetLogicalBaseScreenSize(void) const
298 return __logicalBaseScreenSize;
301 _ControlManager::_ControlManager(void) // [ToDo] exception check.
302 : __pWindowList(null)
303 , __isCoordinateSystemLogical(true)
304 , __logicalCoordinateSystem(0)
305 , __logicalBaseScreenSize(BASE_SCREEN_SIZE_NONE)
306 , __pSystemWindowList(null)
307 , __pFocusedControl(null)
308 , __screenRotation(_CONTROL_ROTATION_0)
309 , __orientationStatus(_CONTROL_ROTATION_0)
310 , __orientation(_CONTROL_ORIENTATION_PORTRAIT)
311 , __pCurrentFrame(null)
312 , __pGestureList(null)
313 , __gestureMaxDuration(0)
315 , __isDefaultFontChanged(false)
316 , __defaultFontName(L"")
318 , __pClipboardOwner(null)
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();
349 SetLastResult(E_SUCCESS);
354 _AnimationManager::ReleaseInstance();
358 delete __pWindowList;
359 __pWindowList = null;
364 delete __pGestureList;
365 __pGestureList = null;
369 _ControlManager::~_ControlManager(void)
371 _Clipboard::ReleaseInstance();
375 delete __pWindowList;
376 __pWindowList = null;
381 delete __pGestureList;
382 __pGestureList = null;
385 DestroyEcoreEvasMgr();
387 if (GetUsedHandleCount() != 0)
389 SysLog(NID_UI, "[Control Manager] The number of unreleased controls: %d", GetUsedHandleCount());
393 _IndicatorManager::ReleaseInstance();
395 _DisplayManager::ReleaseInstance();
397 _AnimationManager::ReleaseInstance();
399 _AccessibilityManager::ReleaseInstance();
401 _KeyEventManager::ReleaseInstance();
402 _TouchManager::ReleaseInstance();
403 _DimmingManager::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 // Rotate partial window without Window State Changed Callback.
562 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
565 #if !defined(WINDOW_OWNEE_PREFERRED)
566 window.ChangeLayout(GetOrientation());
567 pEcoreEvas->RotateWindow(window, ::Convert(__orientationStatus));
568 // window.SetRotation(::Convert(__orientationStatus));
569 // window.Invalidate(true);
571 pEcoreEvas->SetWindowPreferredRotation(window, ::Convert(__orientationStatus));
573 pEcoreEvas->SetWindowPreferredRotation(window, ::Convert(__orientationStatus));
579 r = window.GetControlDelegate().OnAttached();
580 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
582 r = CallOnAttachedToMainTree(window);
583 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
589 _ControlManager::CallOnAttachingToMainTree(_Control& control)
591 result r = E_SUCCESS;
593 r = control.GetControlDelegate().OnAttachingToMainTree(null);
594 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
596 _Control::ControlList& children = control.GetChildList();
597 _Control* pChild = null;
599 for (int index = 0; index < children.GetCount(); index++)
601 r = children.GetAt(index, pChild);
604 SysAssert(r == E_OUT_OF_RANGE);
606 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
607 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
609 r = CallOnAttachingToMainTree(*pChild);
610 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
617 _ControlManager::CallOnAttachedToMainTree(_Control& control)
619 result r = E_SUCCESS;
621 _Control* pChild = null;
622 _Control::ControlList* pControlList = new (std::nothrow) _Control::ControlList;
623 pControlList->Construct(control.GetChildList());
625 r = control.GetControlDelegate().OnAttachedToMainTree();
626 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
628 for (int index = 0; index < pControlList->GetCount(); index++)
630 r = pControlList->GetAt(index, pChild);
633 SysAssert(r == E_OUT_OF_RANGE);
635 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
636 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
638 r = control.CallOnAttachedToMainTree(*pChild);
639 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
648 _ControlManager::CallOnDetachingFromMainTree(_Control& control)
650 result r = E_SUCCESS;
652 _Control* pChild = null;
653 _Control::ControlList& children = control.GetChildList();
655 r = control.GetControlDelegate().OnDetachingFromMainTree();
656 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
658 for (int index = 0; index < children.GetCount(); index++)
660 r = children.GetAt(index, pChild);
663 SysAssert(r == E_OUT_OF_RANGE);
665 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
666 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
668 r = CallOnDetachingFromMainTree(*pChild);
669 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
676 _ControlManager::CloseWindow(_Window& window) // [ToDo] exception check.
679 result r = E_SUCCESS;
681 if (IsWindowAttached(window) == false)
686 bool wasWindowOnTop = IsWindowOnTop(window);
688 r = CallOnDetachingFromMainTree(window);
689 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
691 window.GetControlDelegate().OnDetaching();
695 r = DetachWindow(window);
696 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
700 _Window* pNewTopWindow = GetTopWindow();
701 if (pNewTopWindow && pNewTopWindow->IsActivationEnabled())
703 pNewTopWindow->Activate();
706 if (dynamic_cast <_Frame*>(pNewTopWindow) != null)
708 __pCurrentFrame = pNewTopWindow;
716 _ControlManager::GetWindow(int index) const
719 __pWindowList->GetAt(index, pWindow);
725 _ControlManager::GetWindowCount(void) const
727 return __pWindowList->GetCount();
731 _ControlManager::AttachWindow(_Window& window)
733 _IndicatorManager::GetInstance()->AddWindow(&window);
735 if (window.IsDimmingEnabled())
737 _DimmingManager::GetInstance()->RegisterWindow(&window);
740 return __pWindowList->Add(&window);
744 _ControlManager::InsertWindowToBottom(_Window& window)
746 return __pWindowList->InsertAt(&window, 0);
750 _ControlManager::InsertWindowAfter(const _Window& targetWindow, _Window& window)
754 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
755 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
757 return __pWindowList->InsertAt(&window, index+1);
761 _ControlManager::InsertWindowBefore(const _Window& targetWindow, _Window& window)
765 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
766 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
768 return __pWindowList->InsertAt(&window, index);
772 _ControlManager::DetachWindow(_Window& window)
774 _IndicatorManager::GetInstance()->DeleteWindow(&window);
776 if (window.IsDimmingEnabled())
778 _DimmingManager::GetInstance()->UnRegisterWindow(&window);
781 return __pWindowList->Remove(&window);
785 _ControlManager::DetachAllWindows(void)
787 __pWindowList->RemoveAll();
791 _ControlManager::MoveWindowToTop(const _Window& window)
793 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
794 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
796 return __pWindowList->Add(const_cast<_Window*>(&window));
800 _ControlManager::MoveWindowToBottom(const _Window& window)
802 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
803 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
805 return __pWindowList->InsertAt(const_cast<_Window*>(&window), 0);
809 _ControlManager::MoveWindowAfter(const _Window& targetWindow, const _Window& window)
811 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
812 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
816 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
817 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
819 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index+1);
823 _ControlManager::MoveWindowBefore(const _Window& targetWindow, const _Window& window)
825 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
826 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
830 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
831 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
833 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index);
837 _ControlManager::GetOrientation(void) const
839 return __orientation;
843 _ControlManager::SetOrientation(_ControlOrientation orientation)
845 __orientation = orientation;
849 _ControlManager::GetScreenRotation(void) const
851 bool autoRotate = true;
852 int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, &autoRotate);
854 if (ret == RUNTIME_INFO_ERROR_NONE)
856 SysLog(NID_UI, "The flag of auto-rotate is %d.", autoRotate);
860 SysLog(NID_UI, "It's failed to get the flag of auto-rotate.");
863 SysLog(NID_UI, "[Window Manager Rotation] AUTO_ROTATION = %d", autoRotate);
865 if (autoRotate == false)
867 return _CONTROL_ROTATION_0;
871 #if defined(WINDOW_BASE_ROTATE)
872 // int degree = app_get_device_orientation();
874 unsigned long rotationState = 0;
875 int ret = sf_check_rotation(&rotationState);
876 int device_rotation = 0;
880 switch (rotationState)
882 case ROTATION_EVENT_0:
885 case ROTATION_EVENT_90:
886 device_rotation = 270;
888 case ROTATION_EVENT_180:
889 device_rotation = 180;
891 case ROTATION_EVENT_270:
892 device_rotation = 90;
898 SysLog(NID_UI, "[Window Manager Rotation] device_rotation = %d", device_rotation);
902 SysLog(NID_UI, "[Window Manager Rotation] device_rotation = error");
905 return ::Convert(device_rotation);
907 return __screenRotation;
913 _ControlManager::OnScreenRotated(int rotation)
915 SysLog(NID_UI, "The angle of Emul or Target is %d.", rotation);
916 __screenRotation = ::Convert(rotation);
918 int count = GetWindowCount();
919 for (int i = 0; i < count; i++)
921 _Window* pWindow = GetWindow((count-1) - i);
923 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
927 Controls::_FrameImpl* pFrameImpl = static_cast<Controls::_FrameImpl*>(pFrame->GetUserData());
928 if (pFrameImpl == null)
933 Controls::_FormImpl* pCurrentFormImpl = pFrameImpl->GetCurrentForm();
934 if (pCurrentFormImpl)
936 pCurrentFormImpl->UpdateOrientationStatus(true);
940 pFrameImpl->UpdateOrientationStatus();
947 _ControlManager::SetTouchedWindow(unsigned int window)
949 __touchedWindow = window;
953 _ControlManager::GetTouchedWindow(void) const
957 if (GetWindowCount() == 0)
962 int count = GetWindowCount();
963 for (int i = 0; i < count; i++)
965 _Window* pWindow = GetWindow((count-1) - i);
967 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
968 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
970 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
971 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
973 if (win == __touchedWindow)
983 _ControlManager::SetOrientationStatus(_ControlRotation orientationStatus)
985 __orientationStatus = orientationStatus;
989 _ControlManager::GetOrientationStatus(void) const
991 return __orientationStatus;
995 _ControlManager::RotateScreen(const _Control& control, _ControlRotation screenRotation)
999 // Set window preferred rotation
1001 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
1002 SysAssert(pEcoreEvas);
1003 if (pEcoreEvas == null)
1008 // Rotate root window.
1009 _Window* pRootWindow = control.GetRootWindow();
1012 pEcoreEvas->RotateWindow(*pRootWindow, ::Convert(screenRotation));
1013 pRootWindow->SetRotation(::Convert(screenRotation));
1016 #if !defined(WINDOW_BASE_ROTATE)
1018 int owneeCount = control.GetOwneeCount();
1019 for (int i = 0; i < owneeCount; i++)
1021 _Window* pOwnee = control.GetOwnee(i);
1024 pEcoreEvas->RotateWindow(*pOwnee, ::Convert(screenRotation));
1029 if (__orientationStatus != screenRotation)
1031 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1034 pTouchManager->SetTouchCanceled(null);
1040 _ControlManager::OnWindowRotated(int rotation)
1043 IEnumeratorT<_Window*>* pEnumerator = __pWindowList->GetEnumeratorN();
1044 SysTryReturnVoidResult(NID_UI, pEnumerator, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1046 while (pEnumerator->MoveNext() == E_SUCCESS)
1048 _Window* pWindow = null;
1049 pEnumerator->GetCurrent(pWindow);
1051 if (pWindow->GetOwner() == null)
1053 void* pUserData = pWindow->GetUserData();
1056 _WindowImpl* pWindowImpl = static_cast<_WindowImpl*>(pUserData);
1057 pWindowImpl->OnRotated(Convert(rotation));
1066 _ControlManager::SetFocusedControl(const _Control& control, bool on)
1070 if (__pFocusedControl == &control)
1075 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1076 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1078 _Control *pPreviousFocusedControl = __pFocusedControl;
1079 if (pPreviousFocusedControl)
1081 // [review] make SetFocus() return result and use the returned result here.
1082 pEcoreEvas->SetFocus(*pPreviousFocusedControl, false);
1083 if (GetLastResult() == E_SUCCESS)
1085 if (pPreviousFocusedControl)
1087 pPreviousFocusedControl->SetFocusState(false);
1089 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1090 _UiEventManager::GetInstance()->SendEvent(event);
1094 // [review] make SetFocus() return result and use the returned result here.
1096 if (control.IsNativeObjectFocusable())
1098 pEcoreEvas->SetFocus(control, true);
1101 if (GetLastResult() == E_SUCCESS)
1103 __pFocusedControl = const_cast<_Control*>(&control);
1104 _UiFocusEvent event(control.GetHandle(), FOCUS_GAINED);
1105 _UiEventManager::GetInstance()->SendEvent(event);
1110 if (__pFocusedControl != &control)
1115 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1116 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1118 if (__pFocusedControl)
1120 // [review] make SetFocus() return result and use the returned result here.
1121 pEcoreEvas->SetFocus(*__pFocusedControl, false);
1122 if (GetLastResult() == E_SUCCESS)
1124 _UiFocusEvent event(__pFocusedControl->GetHandle(), FOCUS_LOST);
1125 _UiEventManager::GetInstance()->SendEvent(event);
1129 _Window* pTopWindow = GetTopWindow();
1132 // [review] make SetFocus() return result and use the returned result here.
1133 pEcoreEvas->SetFocus(*pTopWindow, true);
1134 if (GetLastResult() == E_SUCCESS)
1136 pTopWindow->SetFocusState(true);
1137 _UiFocusEvent event(pTopWindow->GetHandle(), FOCUS_GAINED);
1138 _UiEventManager::GetInstance()->SendEvent(event);
1141 __pFocusedControl = static_cast<_Control*>(pTopWindow);
1146 // [review] called in ~_Control and virtual OnFocusLost is called.
1147 // _Control::Release() instead of ~_Control.
1149 _ControlManager::TakeFocusFromControl(const _Control& control)
1151 if (__pFocusedControl == &control)
1153 _Control *pPreviousFocusedControl = __pFocusedControl;
1154 __pFocusedControl = null;
1155 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1156 _UiEventManager::GetInstance()->SendEvent(event);
1165 _ControlManager::GetFocusedControl(void) const
1167 return __pFocusedControl;
1171 _ControlManager::SetClipboardOwner(_Window* pOwner)
1173 __pClipboardOwner = pOwner;
1177 _ControlManager::GetClipboardOwner(void) const
1179 if (__pClipboardOwner)
1181 return __pClipboardOwner;
1184 return GetCurrentFrame();
1188 _ControlManager::GetTopmostTouchedControl(const Point& point)
1190 _Control* pControl = null;
1191 _Window* pTopWindow = null;
1193 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1194 SysTryReturn(NID_UI, pTouchManager, null, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1196 _Control* pCapturedControl = pTouchManager->GetCapturedControl();
1198 if (pCapturedControl)
1200 if (pTouchManager->IsCaptureAllowedOwnerBounds())
1202 if (pTouchManager->IsCaptureAllowedOutOfBounds())
1204 pControl = pCapturedControl;
1207 _Window * pWindow = dynamic_cast<_Window*>(pCapturedControl);
1210 _Control* pOwner = pWindow->GetOwner();
1213 Tizen::Graphics::Rectangle ownerRc(pOwner->GetAbsoluteBounds());
1214 if ((point.x >= ownerRc.x) && (point.x <= (ownerRc.x + ownerRc.width)) && (point.y >= ownerRc.y) && (point.y <= (ownerRc.y + ownerRc.height)))
1221 Tizen::Graphics::Rectangle rc(pCapturedControl->GetAbsoluteBounds());
1222 if ((point.x >= rc.x) && (point.x <= (rc.x + rc.width)) && (point.y >= rc.y) && (point.y <= (rc.y + rc.height)))
1224 pControl = pCapturedControl;
1229 if (pTouchManager->IsCaptureAllowedOutOfBounds())
1231 pControl = pCapturedControl;
1235 Tizen::Graphics::Rectangle rc(pCapturedControl->GetAbsoluteBounds());
1237 if ((point.x < rc.x) || (point.x > (rc.x + rc.width)) || (point.y < rc.y) || (point.y > (rc.y + rc.height)))
1239 pControl = pCapturedControl;
1244 if (pControl != null)
1250 int count = GetWindowCount();
1253 for (int i = 0; i < count; i++)
1255 _Window* pWindow = GetWindow((count-1) - i);
1257 if (pWindow->GetVisibleState() == false)
1262 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
1263 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
1265 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1266 Ecore_X_Window win = (Ecore_X_Window)ecore_evas_window_get(pEcoreEvas);
1268 Rectangle winDeviceBounds(0, 0, 0, 0);
1269 ecore_x_window_geometry_get(win, &winDeviceBounds.x, &winDeviceBounds.y, &winDeviceBounds.width, &winDeviceBounds.height);
1271 Point winDevicePoint = _CoordinateSystemUtils::Transform(pWindow->GetPosition());
1273 Point devicePoint = _CoordinateSystemUtils::Transform(point);
1274 int x = devicePoint.x;
1275 int y = devicePoint.y;
1279 ecore_x_window_size_get(ecore_x_window_root_get(win), &rootW, &rootH);
1281 int rotation = ecore_evas_rotation_get(pEcoreEvas);
1285 devicePoint.x = rootW - y;
1287 winDeviceBounds.x = rootW - winDevicePoint.y - winDeviceBounds.width;
1288 winDeviceBounds.y = winDevicePoint.x;
1291 devicePoint.x = rootW - x;
1292 devicePoint.y = rootH - y;
1293 winDeviceBounds.x = rootW - winDevicePoint.x - winDeviceBounds.width;
1294 winDeviceBounds.y = rootH - winDevicePoint.y - winDeviceBounds.height;
1298 devicePoint.y = rootH - x;
1299 winDeviceBounds.x = winDevicePoint.y;
1300 winDeviceBounds.y = rootH - winDevicePoint.x - winDeviceBounds.height;
1305 winDeviceBounds.x = winDevicePoint.x;
1306 winDeviceBounds.y = winDevicePoint.y;
1310 if (winDeviceBounds.Contains(devicePoint))
1312 pTopWindow = pWindow;
1318 if (pTopWindow != null)
1321 winPos = pTopWindow->GetPosition();
1323 Point relPos(point.x - winPos.x, point.y - winPos.y);
1324 pControl = pTopWindow->GetTopmostChildAt(relPos);
1325 if (pControl != null)
1327 if (pControl->GetRootWindow() == pTopWindow)
1337 // [review] rename __InvXformer
1339 _ControlManager::GetScreenSize(void) const
1341 return _CoordinateSystemUtils::InverseTransform(Dimension(_Screen::GetWidth(), _Screen::GetHeight()));
1345 _ControlManager::GetScreenSizeF(void) const
1347 return _CoordinateSystemUtils::InverseTransform(FloatDimension(_Screen::GetWidth(), _Screen::GetHeight()));
1351 _ControlManager::SetScreenDpi(int dpi)
1357 _ControlManager::GetScreenDpi() const
1363 _ControlManager::GetCurrentFrame(void) const
1365 return __pCurrentFrame;
1369 _ControlManager::SetDefaultFont(const String& appFontName)
1372 if(appFontName.Equals(__defaultFontName))
1377 __isDefaultFontChanged = true;
1378 __defaultFontName = appFontName;
1379 __defaultFontFileName.Clear();
1382 : public _Control::Visitor
1384 virtual _Control::VisitType Visit(_Control& control)
1386 if (control.__fontName.IsEmpty() && control.__fontFileName.IsEmpty())
1388 control.GetFallbackFont();
1389 _IControlDelegate& delegate = control.GetControlDelegate();
1390 delegate.OnFontChanged(control.__pFont);
1392 return _Control::VISIT_DOWNWARD;
1398 int count = GetWindowCount();
1399 for (int j = 0; j < count; j++)
1401 _Window* pWindow = GetWindow((count-1) - j);
1402 pWindow->Accept(visitor);
1405 SetDefaultFontChangeState(false);
1411 _ControlManager::GetDefaultFont(void)
1413 return __defaultFontName;
1417 _ControlManager::SetDefaultFontFromFile(const Tizen::Base::String& fileName)
1419 if(fileName.Equals(__defaultFontFileName))
1424 __isDefaultFontChanged = true;
1425 __defaultFontFileName = fileName;
1426 __defaultFontName.Clear();
1428 : public _Control::Visitor
1430 virtual _Control::VisitType Visit(_Control& control)
1432 if (control.__fontName.IsEmpty() && control.__fontFileName.IsEmpty())
1434 control.GetFallbackFont();
1435 _IControlDelegate& delegate = control.GetControlDelegate();
1436 delegate.OnFontChanged(control.__pFont);
1438 return _Control::VISIT_DOWNWARD;
1444 int count = GetWindowCount();
1445 for (int j = 0; j < count; j++)
1447 _Window* pWindow = GetWindow((count-1) - j);
1448 pWindow->Accept(visitor);
1451 SetDefaultFontChangeState(false);
1456 _ControlManager::GetDefaultFontFile(void) const
1458 return __defaultFontFileName;
1461 _ControlManager::IsDefaultFontChanged(void)
1463 return __isDefaultFontChanged;
1467 _ControlManager::SetDefaultFontChangeState(bool isDefaultFontChanged)
1469 __isDefaultFontChanged = isDefaultFontChanged;
1473 _ControlManager::IsFrameActivated(void) const
1475 _Frame* pFrame = dynamic_cast<_Frame*>(__pCurrentFrame);
1476 SysTryReturn(NID_UI, pFrame, false, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1478 return pFrame->IsActivated();
1481 // [review] refactoring
1483 _ControlManager::AddGestureDetector(const _TouchGestureDetector& gesture)
1487 SysTryReturn(NID_UI, __pGestureList != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1489 bool exist = __pGestureList->Contains(const_cast<_TouchGestureDetector*>(&gesture));
1490 SysTryReturnResult(NID_UI, exist == false, E_OBJ_ALREADY_EXIST, "[E_OBJ_ALREADY_EXIST]__pGestureList has gesture already");
1492 result r = __pGestureList->Add(const_cast<_TouchGestureDetector*>(&gesture));
1493 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1495 switch (gesture.GetDetectorType())
1497 case _TOUCH_GESTURE_DETECTOR_TYPE_TAP:
1499 _TouchTapGestureDetector* pGestureTap = dynamic_cast<_TouchTapGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1500 SysTryReturnResult(NID_UI, pGestureTap, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1502 if (pGestureTap->GetTapInterval() > __gestureMaxDuration)
1504 __gestureMaxDuration = pGestureTap->GetTapInterval();
1508 case _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS:
1510 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1511 SysTryReturnResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1513 if (pGestureLongPress->GetDuration() > __gestureMaxDuration)
1515 __gestureMaxDuration = pGestureLongPress->GetDuration();
1527 _ControlManager::RemoveGestureDetector(const _TouchGestureDetector& gesture)
1531 result r = __pGestureList->Remove(&(const_cast<_TouchGestureDetector&>(gesture)));
1532 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1537 IListT <_TouchGestureDetector*>*
1538 _ControlManager::GetGestureDetectorList(void) const
1540 return __pGestureList;
1544 _ControlManager::GetGestureMaxTimeDuration(void) const
1546 return __gestureMaxDuration;
1550 _ControlManager::OnSettingChanged(Tizen::Base::String& key)
1552 const wchar_t* FONT_TYPE = L"http://tizen.org/setting/font.type";
1553 const wchar_t* LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country";
1554 const wchar_t* LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
1556 if (key == FONT_TYPE || key == LOCALE_COUNTRY || key == LOCALE_LANGUAGE)
1558 _FontImpl::UpdateDefaultFont(key);
1560 int count = GetWindowCount();
1562 for(int index = 0; index < count ; index++)
1564 _Window* pWindow = GetWindow(index);
1565 pWindow->Invalidate(true);
1569 //fixme : check longpress duration key
1572 if (!__pGestureList || (__pGestureList && (__pGestureList->GetCount() <= 0)))
1577 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = __pGestureList->GetEnumeratorN();
1578 SysTryReturnVoidResult(NID_UI, pEnumerator, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1580 int duration = static_cast<int>(elm_config_longpress_timeout_get() * 1000);
1586 while (pEnumerator->MoveNext() == E_SUCCESS)
1588 _TouchGestureDetector* pGestureDetector = null;
1589 pEnumerator->GetCurrent(pGestureDetector);
1591 if (!pGestureDetector)
1596 if(pGestureDetector->GetDetectorType() == _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS)
1598 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(pGestureDetector));
1599 SysTryReturnVoidResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1600 pGestureLongPress->SetDuration(duration);