2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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 , __isSystemFontChanged(false)
317 , __defaultFontName(L"")
319 , __pClipboardOwner(null)
321 result r = GetAppCoordinateSystem(__isCoordinateSystemLogical, __logicalCoordinateSystem, __logicalBaseScreenSize);
322 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] System error occurred.");
324 Dimension deviceResolution = CoordinateSystem::GetPhysicalResolution();
325 _BaseScreenSize deviceBaseScreenSize = _CoordinateSystem::GetInstance()->GetPhysicalBaseScreenSize();
327 r = _CoordinateSystem::Initialize(__logicalCoordinateSystem, __logicalBaseScreenSize, deviceResolution, deviceBaseScreenSize);
328 SysAssert(r == E_SUCCESS);
330 r = _AnimationManager::CreateInstance();
331 SysAssertf(r == E_SUCCESS, "Failed to create animation manager!");
333 r = _DisplayManager::CreateInstance();
334 SysAssertf(r == E_SUCCESS, "Failed to create display manager!");
336 _EcoreEvas::CreateInstanceN();
338 __pWindowList = new (std::nothrow)LinkedListT<_Window*>;
339 SysTryCatch(NID_UI, __pWindowList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
341 __pGestureList = new (std::nothrow)LinkedListT<_TouchGestureDetector*>;
342 SysTryCatch(NID_UI, __pGestureList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
344 _UiEventManager::Initialize();
345 _TouchManager::Initialize();
346 _KeyEventManager::Initialize();
347 _IndicatorManager::InitializeInstance();
348 _AccessibilityManager::CreateInstance();
350 SetLastResult(E_SUCCESS);
355 _AnimationManager::ReleaseInstance();
359 delete __pWindowList;
360 __pWindowList = null;
365 delete __pGestureList;
366 __pGestureList = null;
370 _ControlManager::~_ControlManager(void)
372 _Clipboard::ReleaseInstance();
376 delete __pWindowList;
377 __pWindowList = null;
382 delete __pGestureList;
383 __pGestureList = null;
386 DestroyEcoreEvasMgr();
388 if (GetUsedHandleCount() != 0)
390 SysLog(NID_UI, "[Control Manager] The number of unreleased controls: %d", GetUsedHandleCount());
394 _IndicatorManager::ReleaseInstance();
396 _DisplayManager::ReleaseInstance();
398 _AnimationManager::ReleaseInstance();
400 _AccessibilityManager::ReleaseInstance();
402 _KeyEventManager::ReleaseInstance();
403 _TouchManager::ReleaseInstance();
404 _DimmingManager::ReleaseInstance();
405 _UiEventManager::Release();
409 _ControlManager::GetTopWindow(void) const
413 if (GetWindowCount() == 0)
418 return GetWindow(GetWindowCount() - 1);
422 _ControlManager::GetTopVisibleWindow(void) const
426 if (GetWindowCount() == 0)
431 int count = GetWindowCount();
432 for (int i = 0; i < count; i++)
434 _Window* pWindow = GetWindow((count-1) - i);
436 if (pWindow->GetVisibleState() == true)
446 _ControlManager::GetTopVisibleWindowAt(const Point& point) const
450 if (GetWindowCount() == 0)
455 int count = GetWindowCount();
456 for (int i = 0; i < count; i++)
458 _Window* pWindow = GetWindow((count-1) - i);
460 if (pWindow->GetVisibleState() == false)
465 Rectangle winBounds = pWindow->GetBounds();
466 if (winBounds.Contains(point))
476 _ControlManager::IsWindowOnTop(const _Window& window) const
478 return GetTopWindow() == &window;
482 _ControlManager::IsWindowAttached(const _Window& window) const
484 return __pWindowList->Contains(const_cast<_Window*>(&window));
487 // Open a window and bring it to top.
489 _ControlManager::OpenWindow(_Window& window, bool invalidate)
491 if (dynamic_cast <_Frame*>(&window) != null)
493 __pCurrentFrame = &window;
496 result r = ActivateWindow(window);
497 SysTryReturn(NID_UI, r != E_INVALID_OPERATION, r, r, "[%s] Propagating.", GetErrorMessage(r));
498 SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System Error.");
502 window.Invalidate(true);
509 _ControlManager::ActivateWindow(_Window& window)
512 result r = E_SUCCESS;
514 if (IsWindowOnTop(window))
519 if (window.IsActivationEnabled())
521 _Window* pTopWindow = GetTopWindow();
524 pTopWindow->Deactivate();
528 if (IsWindowAttached(window))
530 r = MoveWindowToTop(window); // [ToDo] excpetion
531 SysAssert(r == E_SUCCESS);
536 r = window.GetControlDelegate().OnAttaching(null);
537 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
539 r = CallOnAttachingToMainTree(window);
540 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
542 r = AttachWindow(window);
543 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
545 if (window.IsActivationEnabled())
550 if (window.IsOrientationRoot() == false)
552 #if !defined(WINDOW_BASE_ROTATE)
553 window.ChangeLayout(GetOrientation());
555 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
558 pEcoreEvas->RotateWindow(window, ::Convert(__orientationStatus));
561 // Rotate partial window without Window State Changed Callback.
563 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
566 #if !defined(WINDOW_OWNEE_PREFERRED)
567 window.ChangeLayout(GetOrientation());
568 pEcoreEvas->RotateWindow(window, ::Convert(__orientationStatus));
569 // window.SetRotation(::Convert(__orientationStatus));
570 // window.Invalidate(true);
572 pEcoreEvas->SetWindowPreferredRotation(window, ::Convert(__orientationStatus));
574 pEcoreEvas->SetWindowPreferredRotation(window, ::Convert(__orientationStatus));
580 r = window.GetControlDelegate().OnAttached();
581 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
583 r = CallOnAttachedToMainTree(window);
584 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
586 if (window.IsDimmingEnabled())
588 r = _DimmingManager::GetInstance()->ShowDimmingLayer(&window);
589 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
596 _ControlManager::CallOnAttachingToMainTree(_Control& control)
598 result r = E_SUCCESS;
600 r = control.GetControlDelegate().OnAttachingToMainTree(null);
601 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
603 _Control::ControlList& children = control.GetChildList();
604 _Control* pChild = null;
606 for (int index = 0; index < children.GetCount(); index++)
608 r = children.GetAt(index, pChild);
611 SysAssert(r == E_OUT_OF_RANGE);
613 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
614 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
616 r = CallOnAttachingToMainTree(*pChild);
617 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
624 _ControlManager::CallOnAttachedToMainTree(_Control& control)
626 result r = E_SUCCESS;
628 _Control* pChild = null;
629 _Control::ControlList* pControlList = new (std::nothrow) _Control::ControlList;
630 pControlList->Construct(control.GetChildList());
632 r = control.GetControlDelegate().OnAttachedToMainTree();
633 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
635 for (int index = 0; index < pControlList->GetCount(); index++)
637 r = pControlList->GetAt(index, pChild);
640 SysAssert(r == E_OUT_OF_RANGE);
642 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
643 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
645 r = control.CallOnAttachedToMainTree(*pChild);
646 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
655 _ControlManager::CallOnDetachingFromMainTree(_Control& control)
657 result r = E_SUCCESS;
659 _Control* pChild = null;
660 _Control::ControlList& children = control.GetChildList();
662 r = control.GetControlDelegate().OnDetachingFromMainTree();
663 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
665 for (int index = 0; index < children.GetCount(); index++)
667 r = children.GetAt(index, pChild);
670 SysAssert(r == E_OUT_OF_RANGE);
672 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
673 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
675 r = CallOnDetachingFromMainTree(*pChild);
676 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
683 _ControlManager::CloseWindow(_Window& window) // [ToDo] exception check.
686 result r = E_SUCCESS;
688 if (IsWindowAttached(window) == false)
693 bool wasWindowOnTop = IsWindowOnTop(window);
695 r = CallOnDetachingFromMainTree(window);
696 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
698 window.GetControlDelegate().OnDetaching();
702 r = DetachWindow(window);
703 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
707 _Window* pNewTopWindow = GetTopWindow();
708 if (pNewTopWindow && pNewTopWindow->IsActivationEnabled())
710 pNewTopWindow->Activate();
713 if (dynamic_cast <_Frame*>(pNewTopWindow) != null)
715 __pCurrentFrame = pNewTopWindow;
723 _ControlManager::GetWindow(int index) const
726 __pWindowList->GetAt(index, pWindow);
732 _ControlManager::GetWindowCount(void) const
734 return __pWindowList->GetCount();
738 _ControlManager::AttachWindow(_Window& window)
740 _IndicatorManager::GetInstance()->AddWindow(&window);
742 if (window.IsDimmingEnabled())
744 _DimmingManager::GetInstance()->RegisterWindow(&window);
747 return __pWindowList->Add(&window);
751 _ControlManager::InsertWindowToBottom(_Window& window)
753 return __pWindowList->InsertAt(&window, 0);
757 _ControlManager::InsertWindowAfter(const _Window& targetWindow, _Window& window)
761 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
762 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
764 return __pWindowList->InsertAt(&window, index+1);
768 _ControlManager::InsertWindowBefore(const _Window& targetWindow, _Window& window)
772 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
773 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
775 return __pWindowList->InsertAt(&window, index);
779 _ControlManager::DetachWindow(_Window& window)
781 _IndicatorManager::GetInstance()->DeleteWindow(&window);
783 if (window.IsDimmingEnabled())
785 _DimmingManager::GetInstance()->UnRegisterWindow(&window);
788 return __pWindowList->Remove(&window);
792 _ControlManager::DetachAllWindows(void)
794 __pWindowList->RemoveAll();
798 _ControlManager::MoveWindowToTop(const _Window& window)
800 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
801 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
803 return __pWindowList->Add(const_cast<_Window*>(&window));
807 _ControlManager::MoveWindowToBottom(const _Window& window)
809 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
810 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
812 return __pWindowList->InsertAt(const_cast<_Window*>(&window), 0);
816 _ControlManager::MoveWindowAfter(const _Window& targetWindow, const _Window& window)
818 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
819 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
823 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
824 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
826 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index+1);
830 _ControlManager::MoveWindowBefore(const _Window& targetWindow, const _Window& window)
832 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
833 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
837 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
838 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
840 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index);
844 _ControlManager::GetOrientation(void) const
846 return __orientation;
850 _ControlManager::SetOrientation(_ControlOrientation orientation)
852 __orientation = orientation;
856 _ControlManager::GetScreenRotation(void) const
858 bool autoRotate = true;
859 int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, &autoRotate);
861 if (ret == RUNTIME_INFO_ERROR_NONE)
863 SysLog(NID_UI, "The flag of auto-rotate is %d.", autoRotate);
867 SysLog(NID_UI, "It's failed to get the flag of auto-rotate.");
870 SysLog(NID_UI, "[Window Manager Rotation] AUTO_ROTATION = %d", autoRotate);
872 if (autoRotate == false)
874 return _CONTROL_ROTATION_0;
878 #if defined(WINDOW_BASE_ROTATE)
879 // int degree = app_get_device_orientation();
881 unsigned long rotationState = 0;
882 int ret = sf_check_rotation(&rotationState);
883 int device_rotation = 0;
887 switch (rotationState)
889 case ROTATION_EVENT_0:
892 case ROTATION_EVENT_90:
893 device_rotation = 270;
895 case ROTATION_EVENT_180:
896 device_rotation = 180;
898 case ROTATION_EVENT_270:
899 device_rotation = 90;
905 SysLog(NID_UI, "[Window Manager Rotation] device_rotation = %d", device_rotation);
909 SysLog(NID_UI, "[Window Manager Rotation] device_rotation = error");
912 return ::Convert(device_rotation);
914 return __screenRotation;
920 _ControlManager::OnScreenRotated(int rotation)
922 SysLog(NID_UI, "The angle of Emul or Target is %d.", rotation);
923 __screenRotation = ::Convert(rotation);
925 int count = GetWindowCount();
926 for (int i = 0; i < count; i++)
928 _Window* pWindow = GetWindow((count-1) - i);
930 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
934 Controls::_FrameImpl* pFrameImpl = static_cast<Controls::_FrameImpl*>(pFrame->GetUserData());
935 if (pFrameImpl == null)
940 Controls::_FormImpl* pCurrentFormImpl = pFrameImpl->GetCurrentForm();
941 if (pCurrentFormImpl)
943 pCurrentFormImpl->UpdateOrientationStatus(true);
947 pFrameImpl->UpdateOrientationStatus();
954 _ControlManager::SetTouchedWindow(unsigned int window)
956 __touchedWindow = window;
960 _ControlManager::GetTouchedWindow(void) const
964 if (GetWindowCount() == 0)
969 int count = GetWindowCount();
970 for (int i = 0; i < count; i++)
972 _Window* pWindow = GetWindow((count-1) - i);
974 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
975 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
977 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
978 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
980 if (win == __touchedWindow)
990 _ControlManager::SetOrientationStatus(_ControlRotation orientationStatus)
992 __orientationStatus = orientationStatus;
996 _ControlManager::GetOrientationStatus(void) const
998 return __orientationStatus;
1002 _ControlManager::RotateScreen(const _Control& control, _ControlRotation screenRotation)
1006 // Set window preferred rotation
1008 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
1009 SysAssert(pEcoreEvas);
1010 if (pEcoreEvas == null)
1015 // Rotate root window.
1016 _Window* pRootWindow = control.GetRootWindow();
1019 pEcoreEvas->RotateWindow(*pRootWindow, ::Convert(screenRotation));
1020 pRootWindow->SetRotation(::Convert(screenRotation));
1023 #if !defined(WINDOW_BASE_ROTATE)
1025 int owneeCount = control.GetOwneeCount();
1026 for (int i = 0; i < owneeCount; i++)
1028 _Window* pOwnee = control.GetOwnee(i);
1031 pEcoreEvas->RotateWindow(*pOwnee, ::Convert(screenRotation));
1036 if (__orientationStatus != screenRotation)
1038 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1041 pTouchManager->SetTouchCanceled(null);
1047 _ControlManager::OnWindowRotated(int rotation)
1050 IEnumeratorT<_Window*>* pEnumerator = __pWindowList->GetEnumeratorN();
1051 SysTryReturnVoidResult(NID_UI, pEnumerator, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1053 while (pEnumerator->MoveNext() == E_SUCCESS)
1055 _Window* pWindow = null;
1056 pEnumerator->GetCurrent(pWindow);
1058 if (pWindow->GetOwner() == null)
1060 void* pUserData = pWindow->GetUserData();
1063 _WindowImpl* pWindowImpl = static_cast<_WindowImpl*>(pUserData);
1064 pWindowImpl->OnRotated(Convert(rotation));
1073 _ControlManager::SetFocusedControl(const _Control& control, bool on)
1077 if (__pFocusedControl == &control)
1082 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1083 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1085 _Control *pPreviousFocusedControl = __pFocusedControl;
1086 if (pPreviousFocusedControl)
1088 // [review] make SetFocus() return result and use the returned result here.
1089 pEcoreEvas->SetFocus(*pPreviousFocusedControl, false);
1090 if (GetLastResult() == E_SUCCESS)
1092 if (pPreviousFocusedControl)
1094 pPreviousFocusedControl->SetFocusState(false);
1096 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1097 _UiEventManager::GetInstance()->SendEvent(event);
1101 // [review] make SetFocus() return result and use the returned result here.
1103 if (control.IsNativeObjectFocusable())
1105 pEcoreEvas->SetFocus(control, true);
1108 if (GetLastResult() == E_SUCCESS)
1110 __pFocusedControl = const_cast<_Control*>(&control);
1111 _UiFocusEvent event(control.GetHandle(), FOCUS_GAINED);
1112 _UiEventManager::GetInstance()->SendEvent(event);
1117 if (__pFocusedControl != &control)
1122 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1123 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1125 if (__pFocusedControl)
1127 // [review] make SetFocus() return result and use the returned result here.
1128 pEcoreEvas->SetFocus(*__pFocusedControl, false);
1129 if (GetLastResult() == E_SUCCESS)
1131 _UiFocusEvent event(__pFocusedControl->GetHandle(), FOCUS_LOST);
1132 _UiEventManager::GetInstance()->SendEvent(event);
1136 _Window* pTopWindow = GetTopWindow();
1139 // [review] make SetFocus() return result and use the returned result here.
1140 pEcoreEvas->SetFocus(*pTopWindow, true);
1141 if (GetLastResult() == E_SUCCESS)
1143 pTopWindow->SetFocusState(true);
1144 _UiFocusEvent event(pTopWindow->GetHandle(), FOCUS_GAINED);
1145 _UiEventManager::GetInstance()->SendEvent(event);
1148 __pFocusedControl = static_cast<_Control*>(pTopWindow);
1153 // [review] called in ~_Control and virtual OnFocusLost is called.
1154 // _Control::Release() instead of ~_Control.
1156 _ControlManager::TakeFocusFromControl(const _Control& control)
1158 if (__pFocusedControl == &control)
1160 _Control *pPreviousFocusedControl = __pFocusedControl;
1161 __pFocusedControl = null;
1162 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1163 _UiEventManager::GetInstance()->SendEvent(event);
1172 _ControlManager::GetFocusedControl(void) const
1174 return __pFocusedControl;
1178 _ControlManager::SetClipboardOwner(_Window* pOwner)
1180 __pClipboardOwner = pOwner;
1184 _ControlManager::GetClipboardOwner(void) const
1186 if (__pClipboardOwner)
1188 return __pClipboardOwner;
1191 return GetCurrentFrame();
1195 _ControlManager::GetTopmostTouchedControl(const Point& point)
1197 _Control* pControl = null;
1198 _Window* pTopWindow = null;
1200 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1201 SysTryReturn(NID_UI, pTouchManager, null, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
1203 _Control* pCapturedControl = pTouchManager->GetCapturedControl();
1205 if (pCapturedControl)
1207 if (pTouchManager->IsCaptureAllowedOwnerBounds())
1209 if (pTouchManager->IsCaptureAllowedOutOfBounds())
1211 pControl = pCapturedControl;
1214 _Window * pWindow = dynamic_cast<_Window*>(pCapturedControl);
1217 _Control* pOwner = pWindow->GetOwner();
1220 Tizen::Graphics::Rectangle ownerRc(pOwner->GetAbsoluteBounds());
1221 if ((point.x >= ownerRc.x) && (point.x <= (ownerRc.x + ownerRc.width)) && (point.y >= ownerRc.y) && (point.y <= (ownerRc.y + ownerRc.height)))
1228 Tizen::Graphics::Rectangle rc(pCapturedControl->GetAbsoluteBounds());
1229 if ((point.x >= rc.x) && (point.x <= (rc.x + rc.width)) && (point.y >= rc.y) && (point.y <= (rc.y + rc.height)))
1231 pControl = pCapturedControl;
1236 if (pTouchManager->IsCaptureAllowedOutOfBounds())
1238 pControl = pCapturedControl;
1242 Tizen::Graphics::Rectangle rc(pCapturedControl->GetAbsoluteBounds());
1244 if ((point.x < rc.x) || (point.x > (rc.x + rc.width)) || (point.y < rc.y) || (point.y > (rc.y + rc.height)))
1246 pControl = pCapturedControl;
1251 if (pControl != null)
1257 int count = GetWindowCount();
1260 for (int i = 0; i < count; i++)
1262 _Window* pWindow = GetWindow((count-1) - i);
1264 if (pWindow->GetVisibleState() == false)
1269 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
1270 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
1272 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1273 Ecore_X_Window win = (Ecore_X_Window)ecore_evas_window_get(pEcoreEvas);
1275 Rectangle winDeviceBounds(0, 0, 0, 0);
1276 ecore_x_window_geometry_get(win, &winDeviceBounds.x, &winDeviceBounds.y, &winDeviceBounds.width, &winDeviceBounds.height);
1278 Point winDevicePoint = _CoordinateSystemUtils::Transform(pWindow->GetPosition());
1280 Point devicePoint = _CoordinateSystemUtils::Transform(point);
1281 int x = devicePoint.x;
1282 int y = devicePoint.y;
1286 ecore_x_window_size_get(ecore_x_window_root_get(win), &rootW, &rootH);
1288 int rotation = ecore_evas_rotation_get(pEcoreEvas);
1292 devicePoint.x = rootW - y;
1294 winDeviceBounds.x = rootW - winDevicePoint.y - winDeviceBounds.width;
1295 winDeviceBounds.y = winDevicePoint.x;
1298 devicePoint.x = rootW - x;
1299 devicePoint.y = rootH - y;
1300 winDeviceBounds.x = rootW - winDevicePoint.x - winDeviceBounds.width;
1301 winDeviceBounds.y = rootH - winDevicePoint.y - winDeviceBounds.height;
1305 devicePoint.y = rootH - x;
1306 winDeviceBounds.x = winDevicePoint.y;
1307 winDeviceBounds.y = rootH - winDevicePoint.x - winDeviceBounds.height;
1312 winDeviceBounds.x = winDevicePoint.x;
1313 winDeviceBounds.y = winDevicePoint.y;
1317 if (winDeviceBounds.Contains(devicePoint))
1319 pTopWindow = pWindow;
1325 if (pTopWindow != null)
1328 winPos = pTopWindow->GetPosition();
1330 Point relPos(point.x - winPos.x, point.y - winPos.y);
1331 pControl = pTopWindow->GetTopmostChildAt(relPos);
1332 if (pControl != null)
1334 if (pControl->GetRootWindow() == pTopWindow)
1344 // [review] rename __InvXformer
1346 _ControlManager::GetScreenSize(void) const
1348 return _CoordinateSystemUtils::InverseTransform(Dimension(_Screen::GetWidth(), _Screen::GetHeight()));
1352 _ControlManager::GetScreenSizeF(void) const
1354 return _CoordinateSystemUtils::InverseTransform(FloatDimension(_Screen::GetWidth(), _Screen::GetHeight()));
1358 _ControlManager::SetScreenDpi(int dpi)
1364 _ControlManager::GetScreenDpi() const
1370 _ControlManager::GetCurrentFrame(void) const
1372 return __pCurrentFrame;
1376 _ControlManager::SetDefaultFont(const String& appFontName)
1379 if(appFontName.Equals(__defaultFontName))
1384 __isDefaultFontChanged = true;
1385 __defaultFontName = appFontName;
1386 __defaultFontFileName.Clear();
1389 : public _Control::Visitor
1391 virtual _Control::VisitType Visit(_Control& control)
1393 if (control.__fontName.IsEmpty() && control.__fontFileName.IsEmpty())
1395 control.GetFallbackFont();
1396 _IControlDelegate& delegate = control.GetControlDelegate();
1397 delegate.OnFontChanged(control.__pFont);
1399 return _Control::VISIT_DOWNWARD;
1405 int count = GetWindowCount();
1406 for (int j = 0; j < count; j++)
1408 _Window* pWindow = GetWindow((count-1) - j);
1409 pWindow->Accept(visitor);
1412 SetDefaultFontChangeState(false);
1418 _ControlManager::GetDefaultFont(void)
1420 return __defaultFontName;
1424 _ControlManager::SetDefaultFontFromFile(const Tizen::Base::String& fileName)
1426 if(fileName.Equals(__defaultFontFileName))
1431 __isDefaultFontChanged = true;
1432 __defaultFontFileName = fileName;
1433 __defaultFontName.Clear();
1435 : public _Control::Visitor
1437 virtual _Control::VisitType Visit(_Control& control)
1439 if (control.__fontName.IsEmpty() && control.__fontFileName.IsEmpty())
1441 control.GetFallbackFont();
1442 _IControlDelegate& delegate = control.GetControlDelegate();
1443 delegate.OnFontChanged(control.__pFont);
1445 return _Control::VISIT_DOWNWARD;
1451 int count = GetWindowCount();
1452 for (int j = 0; j < count; j++)
1454 _Window* pWindow = GetWindow((count-1) - j);
1455 pWindow->Accept(visitor);
1458 SetDefaultFontChangeState(false);
1463 _ControlManager::GetDefaultFontFile(void) const
1465 return __defaultFontFileName;
1468 _ControlManager::IsDefaultFontChanged(void) const
1470 return __isDefaultFontChanged;
1474 _ControlManager::IsSystemFontChanged(void) const
1476 return __isSystemFontChanged;
1480 _ControlManager::SetDefaultFontChangeState(bool isDefaultFontChanged)
1482 __isDefaultFontChanged = isDefaultFontChanged;
1486 _ControlManager::IsFrameActivated(void) const
1488 _Frame* pFrame = dynamic_cast<_Frame*>(__pCurrentFrame);
1489 SysTryReturn(NID_UI, pFrame, false, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1491 return pFrame->IsActivated();
1494 // [review] refactoring
1496 _ControlManager::AddGestureDetector(const _TouchGestureDetector& gesture)
1500 SysTryReturn(NID_UI, __pGestureList != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1502 bool exist = __pGestureList->Contains(const_cast<_TouchGestureDetector*>(&gesture));
1503 SysTryReturnResult(NID_UI, exist == false, E_OBJ_ALREADY_EXIST, "[E_OBJ_ALREADY_EXIST]__pGestureList has gesture already");
1505 result r = __pGestureList->Add(const_cast<_TouchGestureDetector*>(&gesture));
1506 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1508 switch (gesture.GetDetectorType())
1510 case _TOUCH_GESTURE_DETECTOR_TYPE_TAP:
1512 _TouchTapGestureDetector* pGestureTap = dynamic_cast<_TouchTapGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1513 SysTryReturnResult(NID_UI, pGestureTap, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1515 if (pGestureTap->GetTapInterval() > __gestureMaxDuration)
1517 __gestureMaxDuration = pGestureTap->GetTapInterval();
1521 case _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS:
1523 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1524 SysTryReturnResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1526 if (pGestureLongPress->GetDuration() > __gestureMaxDuration)
1528 __gestureMaxDuration = pGestureLongPress->GetDuration();
1540 _ControlManager::RemoveGestureDetector(const _TouchGestureDetector& gesture)
1544 result r = __pGestureList->Remove(&(const_cast<_TouchGestureDetector&>(gesture)));
1545 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1550 IListT <_TouchGestureDetector*>*
1551 _ControlManager::GetGestureDetectorList(void) const
1553 return __pGestureList;
1557 _ControlManager::GetGestureMaxTimeDuration(void) const
1559 return __gestureMaxDuration;
1563 _ControlManager::OnSettingChanged(Tizen::Base::String& key)
1565 const wchar_t* FONT_TYPE = L"http://tizen.org/setting/font.type";
1566 const wchar_t* LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country";
1567 const wchar_t* LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
1569 if (key == FONT_TYPE || key == LOCALE_COUNTRY || key == LOCALE_LANGUAGE)
1571 _FontImpl::UpdateDefaultFont(key);
1572 __isSystemFontChanged = true;
1574 : public _Control::Visitor
1576 virtual _Control::VisitType Visit(_Control& control)
1578 control.GetFallbackFont();
1579 _IControlDelegate& delegate = control.GetControlDelegate();
1580 delegate.OnFontChanged(control.__pFont);
1581 return _Control::VISIT_DOWNWARD;
1587 int count = GetWindowCount();
1588 for (int j = 0; j < count; j++)
1590 _Window* pWindow = GetWindow((count-1) - j);
1591 pWindow->Accept(visitor);
1594 __isSystemFontChanged = false;
1595 for(int index = 0; index < count ; index++)
1597 _Window* pWindow = GetWindow(index);
1598 pWindow->Invalidate(true);
1602 //fixme : check longpress duration key
1605 if (!__pGestureList || (__pGestureList && (__pGestureList->GetCount() <= 0)))
1610 IEnumeratorT<_TouchGestureDetector*>* pEnumerator = __pGestureList->GetEnumeratorN();
1611 SysTryReturnVoidResult(NID_UI, pEnumerator, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1613 int duration = static_cast<int>(elm_config_longpress_timeout_get() * 1000);
1619 while (pEnumerator->MoveNext() == E_SUCCESS)
1621 _TouchGestureDetector* pGestureDetector = null;
1622 pEnumerator->GetCurrent(pGestureDetector);
1624 if (!pGestureDetector)
1629 if(pGestureDetector->GetDetectorType() == _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS)
1631 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(pGestureDetector));
1632 SysTryReturnVoidResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM] System error occurred.")
1633 pGestureLongPress->SetDuration(duration);