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.
18 * @file FUi_ControlManager.cpp
19 * @brief This is the implementation file for the _ControlManager class.
24 #include <runtime_info.h>
25 #if defined(MULTI_WINDOW)
27 #include <Elementary.h>
29 #include <FBaseInt8.h>
30 #include <FBaseSysLog.h>
31 #if defined(MULTI_WINDOW)
32 #include <FGrpRectangle.h>
34 #include <FApp_AppInfo.h>
35 #include <FAppPkg_PackageInfoImpl.h>
36 #include <FGrp_Screen.h>
37 #include <FGrp_FontImpl.h>
38 #include <FSys_SettingInfoImpl.h>
39 #include "FUi_ControlManager.h"
40 #include "FUi_Control.h"
41 #include "FUi_Window.h"
42 #include "FUi_WindowImpl.h"
43 #include "FUi_EcoreEvas.h"
44 #include "FUi_EcoreEvasMgr.h"
45 #include "FUi_EflWindow.h"
46 #include "FUi_ResourceManager.h"
47 #include "FUi_Clipboard.h"
48 #include "FUi_UiFocusEvent.h"
49 #include "FUi_UiEventManager.h"
50 #include "FUi_TouchManager.h"
51 #include "FUi_TouchLongPressGestureDetector.h"
52 #include "FUi_TouchTapGestureDetector.h"
53 #include "FUi_KeyEventManager.h"
54 #include "FUi_CoordinateSystemUtils.h"
55 #include "FUiAnim_RootVisualElement.h"
56 #include "FUiAnim_AnimationManager.h"
57 #include "FUiAnim_DisplayManager.h"
58 #include "FUi_AccessibilityManager.h"
59 #if defined(MULTI_WINDOW)
60 #include "FUiAnim_VisualElement.h"
61 #include "FUiAnim_EflLayer.h"
62 #include "FUiCtrl_FrameImpl.h"
63 #include "FUiCtrl_FormImpl.h"
65 #include "FUiCtrl_Frame.h"
66 // #include "FUiCtrl_NotificationFrame.h"
67 // #include "FUiCtrl_NotificationFrameImpl.h"
68 #include "FUiCtrl_IndicatorManager.h"
70 using namespace Tizen::App;
71 using namespace Tizen::App::Package;
72 using namespace Tizen::Base;
73 using namespace Tizen::Base::Collection;
74 using namespace Tizen::Graphics;
75 using namespace Tizen::Ui;
76 using namespace Tizen::Ui::Animations;
77 using namespace Tizen::Ui::Controls;
78 using namespace Tizen::System;
82 _ControlRotation Convert(int rotationDegree)
84 switch (rotationDegree)
87 return _CONTROL_ROTATION_0;
89 return _CONTROL_ROTATION_90;
91 return _CONTROL_ROTATION_180;
93 return _CONTROL_ROTATION_270;
95 return _CONTROL_ROTATION_0;
99 int Convert(_ControlRotation rotation)
103 case _CONTROL_ROTATION_0:
105 case _CONTROL_ROTATION_90:
107 case _CONTROL_ROTATION_180:
109 case _CONTROL_ROTATION_270:
116 namespace Tizen { namespace Ui
122 static void PrintControl(const _Control& control, bool printChildren = true);
123 static void PrintTree(void);
127 _UiDebug::PrintControl(const _Control& control, bool printChildren)
129 const_cast<_Control&>(control).PrintDescription(printChildren);
133 _UiDebug::PrintTree(void)
135 _ControlManager* pControlManager = _ControlManager::GetInstance();
136 SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
138 #if !defined(MULTI_WINDOW)
139 PrintControl(pControlManager->GetRoot(), true);
141 if (pControlManager->GetWindowCount() == 0)
143 SysLog(NID_UI, "There is no window.");
147 int count = pControlManager->GetWindowCount();
148 for (int i = 0; i < count; i++)
150 _Window* pWindow = pControlManager->GetWindow((count-1) - i);
151 PrintControl(*pWindow, true);
156 _ControlManager* _ControlManager::__pInstance = null;
159 _ControlManager::Initialize(void)
161 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
165 pthread_once(&once_block, InitInstance);
168 result r = _SettingInfoImpl::AddSettingEventListenerForInternal(*__pInstance);
169 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
171 // [ToDo] Is it OK to directly get the device orientation?
172 int degree = app_get_device_orientation();
173 SysLog(NID_UI, "The initial value of device orientation is %d.", degree);
175 __pInstance->__screenRotation = ::Convert(degree);
179 _ControlManager::Release(void)
181 result r = _SettingInfoImpl::RemoveSettingEventListenerForInternal(*__pInstance);
182 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
189 _ControlManager::GetInstance(void)
195 _ControlManager::InitInstance(void)
202 __pInstance = new (std::nothrow) _ControlManager;
203 SysAssert(__pInstance);
207 _ControlManager::Register(_Control* pObject)
211 SysLog(NID_UI, "A _Control Registered()");
216 return _ControlHandle();
219 return __objectManager.Register(*pObject);
223 _ControlManager::Release(const _ControlHandle& handle)
225 _Control* pObject = GetObject(handle);
228 SysLog(NID_UI, "A _Control Released()");
231 return __objectManager.Unregister(handle);
235 _ControlManager::GetObject(const _ControlHandle& handle)
237 return __objectManager.GetObject(handle);
241 _ControlManager::GetObject(const _ControlHandle& handle) const
243 return __objectManager.GetObject(handle);
247 _ControlManager::GetUsedHandleCount(void) const
249 return __objectManager.GetObjectCount();
253 _ControlManager::GetAppCoordinateSystem(bool& isCoordinateSystemLogical, int& logicalCoordinateSystemInt, _BaseScreenSize& logicalBaseScreenSize)
255 _PackageInfoImpl infoImpl;
257 String subAppId(_AppInfo::GetAppId());
259 result r = infoImpl.Construct(subAppId);
260 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
263 String baseScreenSize(null);
264 String coordinateSystem(null);
265 String logicalCoordinate(null);
267 result r = infoImpl.GetUiScalabilityInfo(baseScreenSize, coordinateSystem, logicalCoordinate);
268 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
270 if (coordinateSystem.Equals(L"Physical", false))
272 isCoordinateSystemLogical = false;
273 logicalCoordinateSystemInt = 0;
274 logicalBaseScreenSize = BASE_SCREEN_SIZE_DEFAULT;
280 r = Integer::Parse(logicalCoordinate, logicalCoordinateSystemInt);
281 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
284 if (baseScreenSize.Equals(L"Large", false))
286 logicalBaseScreenSize = BASE_SCREEN_SIZE_LARGE;
290 logicalBaseScreenSize = BASE_SCREEN_SIZE_NORMAL;
297 _ControlManager::IsCoordinateSystemLogical(void) const
299 return __isCoordinateSystemLogical;
303 _ControlManager::GetCoordinateSystem(void) const
305 return __logicalCoordinateSystem;
309 _ControlManager::GetLogicalBaseScreenSize(void) const
311 return __logicalBaseScreenSize;
314 _ControlManager::_ControlManager(void) // [ToDo] exception check.
315 #if !defined(MULTI_WINDOW)
318 : __pWindowList(null)
320 , __isCoordinateSystemLogical(true)
321 , __logicalCoordinateSystem(0)
322 , __logicalBaseScreenSize(BASE_SCREEN_SIZE_NONE)
323 , __pSystemWindowList(null)
324 , __pFocusedControl(null)
325 , __screenRotation(_CONTROL_ROTATION_0)
326 , __orientationStatus(_CONTROL_ROTATION_0)
327 , __orientation(_CONTROL_ORIENTATION_PORTRAIT)
328 #if !defined(MULTI_WINDOW)
331 , __pCurrentFrame(null)
332 , __pGestureList(null)
333 , __gestureMaxDuration(0)
334 #if defined(MULTI_WINDOW)
337 , __isDefaultFontChanged(false)
338 , __defaultFontName(L"")
340 result r = GetAppCoordinateSystem(__isCoordinateSystemLogical, __logicalCoordinateSystem, __logicalBaseScreenSize);
341 SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] System error occurred.");
343 Dimension deviceResolution = CoordinateSystem::GetPhysicalResolution();
344 _BaseScreenSize deviceBaseScreenSize = _CoordinateSystem::GetInstance()->GetPhysicalBaseScreenSize();
346 r = _CoordinateSystem::Initialize(__logicalCoordinateSystem, __logicalBaseScreenSize, deviceResolution, deviceBaseScreenSize);
347 SysAssert(r == E_SUCCESS);
349 #if !defined(MULTI_WINDOW)
350 _RootVisualElement* pVisualElementRoot = null;
351 _EflWindow* pWindowPi = null;
352 _Control* pRoot = null;
353 _ControlHandle rootHandle;
355 // Initialize _UiEventManager
356 _UiEventManager::Initialize();
358 // Initialize _TouchManager
359 _TouchManager::Initialize();
361 _KeyEventManager::Initialize();
363 _AccessibilityManager::CreateInstance();
365 r = _AnimationManager::CreateInstance();
366 SysAssertf(r == E_SUCCESS, "Failed to create animation manager!");
368 r = _DisplayManager::CreateInstance();
369 SysAssertf(r == E_SUCCESS, "Failed to create display manager!");
371 pWindowPi = _EflWindow::CreateInstanceN();
372 SysTryReturnVoidResult(NID_UI, pWindowPi, E_SYSTEM, "[E_SYSTEM] System error occurred.");
374 pRoot = new (std::nothrow) _Control; // The children of pRoot are set not to be clipped to the parent.
375 SysTryCatch(NID_UI, pRoot, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
378 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error occurred.");
380 pVisualElementRoot = pWindowPi->GetRootVisualElement();
381 SysTryCatch(NID_UI, pVisualElementRoot, , E_SYSTEM, "[E_SYSTEM] System error occurred.");
382 pVisualElementRoot->SetName(L"Root");
384 r = pVisualElementRoot->AttachChild(*pRoot->GetVisualElement());
385 SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] System error occurred.");
386 pRoot->GetVisualElement()->SetClipChildrenEnabled(false);
387 pRoot->GetVisualElement()->SetName(L"RootControl");
389 __pSystemWindowList = new (std::nothrow)LinkedListT<_Window*>;
390 SysTryCatch(NID_UI, __pSystemWindowList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
392 __pGestureList = new (std::nothrow)LinkedListT<_TouchGestureDetector*>;
393 SysTryCatch(NID_UI, __pGestureList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
395 rootHandle = Register(pRoot); // [review] exception
396 SysAssert(rootHandle.IsValid());
398 __pWindowPi = pWindowPi;
401 pWindowPi->SetFrame(*pRoot);
412 delete __pGestureList;
413 __pGestureList = null;
415 delete __pSystemWindowList;
416 __pSystemWindowList = null;
419 r = _AnimationManager::CreateInstance();
420 SysAssertf(r == E_SUCCESS, "Failed to create animation manager!");
422 r = _DisplayManager::CreateInstance();
423 SysAssertf(r == E_SUCCESS, "Failed to create display manager!");
425 _EcoreEvas::CreateInstanceN();
427 __pWindowList = new (std::nothrow)LinkedListT<_Window*>;
428 SysTryCatch(NID_UI, __pWindowList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
430 __pGestureList = new (std::nothrow)LinkedListT<_TouchGestureDetector*>;
431 SysTryCatch(NID_UI, __pGestureList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
433 _UiEventManager::Initialize();
434 _TouchManager::Initialize();
435 _KeyEventManager::Initialize();
436 _IndicatorManager::InitializeInstance();
437 _AccessibilityManager::CreateInstance();
439 SetLastResult(E_SUCCESS);
444 _AnimationManager::ReleaseInstance();
448 delete __pWindowList;
449 __pWindowList = null;
454 delete __pGestureList;
455 __pGestureList = null;
460 _ControlManager::~_ControlManager(void)
462 #if !defined(MULTI_WINDOW)
463 _EflWindow* pWindowPi = static_cast<_EflWindow*>(__pWindowPi);
465 // Release frame window
468 _RootVisualElement* pRootVE = pWindowPi->GetRootVisualElement();
469 _VisualElement* pControlRootVE = __pRoot->GetVisualElement();
470 if (pRootVE && pControlRootVE)
472 pRootVE->DetachChild(*pControlRootVE);
476 // Release clip board
477 _Clipboard::ReleaseInstance();
482 delete __pGestureList;
483 delete __pSystemWindowList;
485 _AnimationManager::ReleaseInstance();
487 // Release ecore evas manager
488 DestroyEcoreEvasMgr();
490 // Check control handle count
491 if (GetUsedHandleCount() != 0)
493 SysLog(NID_UI, "[Control Manager] The number of unreleased controls: %d", GetUsedHandleCount());
496 _DisplayManager::ReleaseInstance();
498 _Clipboard::ReleaseInstance();
502 delete __pWindowList;
503 __pWindowList = null;
508 delete __pGestureList;
509 __pGestureList = null;
512 DestroyEcoreEvasMgr();
514 if (GetUsedHandleCount() != 0)
516 SysLog(NID_UI, "[Control Manager] The number of unreleased controls: %d", GetUsedHandleCount());
519 _DisplayManager::ReleaseInstance();
521 _AnimationManager::ReleaseInstance();
523 _AccessibilityManager::ReleaseInstance();
525 _IndicatorManager::ReleaseInstance();
527 _KeyEventManager::ReleaseInstance();
528 _TouchManager::ReleaseInstance();
530 _UiEventManager::Release();
533 #if !defined(MULTI_WINDOW)
535 _ControlManager::GetRoot(void) const
542 _ControlManager::GetRoot(void)
550 _ControlManager::GetTopWindow(void) const
554 if (GetWindowCount() == 0)
559 return GetWindow(GetWindowCount() - 1);
562 #if defined(MULTI_WINDOW)
564 _ControlManager::GetTopVisibleWindow(void) const
568 if (GetWindowCount() == 0)
573 int count = GetWindowCount();
574 for (int i = 0; i < count; i++)
576 _Window* pWindow = GetWindow((count-1) - i);
578 if (pWindow->GetVisibleState() == true)
588 _ControlManager::GetTopVisibleWindowAt(const Point& point) const
592 if (GetWindowCount() == 0)
597 int count = GetWindowCount();
598 for (int i = 0; i < count; i++)
600 _Window* pWindow = GetWindow((count-1) - i);
602 if (pWindow->GetVisibleState() == false)
607 Rectangle winBounds = pWindow->GetBounds();
608 if (winBounds.Contains(point))
619 _ControlManager::IsWindowOnTop(const _Window& window) const
621 return GetTopWindow() == &window;
625 _ControlManager::IsWindowAttached(const _Window& window) const
627 #if !defined(MULTI_WINDOW)
628 if (window.IsSystemWindow())
630 return __pSystemWindowList->Contains(const_cast<_Window*>(&window));
633 return window.GetParent() == __pRoot;
635 return __pWindowList->Contains(const_cast<_Window*>(&window));
639 // Open a window and bring it to top.
641 _ControlManager::OpenWindow(_Window& window, bool invalidate)
643 #if !defined(MULTI_WINDOW)
645 if (dynamic_cast <_Frame*>(&window) != null)
647 __pWindowPi->SetFrame(window);
651 if (dynamic_cast <_Frame*>(&window) != null)
653 __pCurrentFrame = &window;
656 result r = ActivateWindow(window);
657 SysTryReturn(NID_UI, r != E_INVALID_OPERATION, r, r, "[%s] Propagating.", GetErrorMessage(r));
658 SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System Error.");
662 window.Invalidate(true);
669 _ControlManager::ActivateWindow(_Window& window)
672 result r = E_SUCCESS;
674 #if !defined(MULTI_WINDOW)
675 // if (dynamic_cast<_NotificationFrame*>(&window))
676 if (window.IsSystemWindow())
678 r = window.GetControlDelegate().OnAttaching(null);
679 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
681 r = CallOnAttachingToMainTree(window);
682 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
686 r = window.GetControlDelegate().OnAttached();
687 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
689 r = CallOnAttachedToMainTree(window);
690 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
694 if (IsWindowOnTop(window))
699 if (window.IsActivatedOnOpen())
701 _Window* pTopWindow = GetTopWindow();
704 pTopWindow->Deactivate();
708 if (IsWindowAttached(window))
710 r = MoveWindowToTop(window); // [ToDo] excpetion
711 SysAssert(r == E_SUCCESS);
716 r = AttachWindow(window);
717 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
719 if (window.IsActivatedOnOpen())
725 window.SetWindowState(WINDOW_STATE_DEACTIVATED);
729 if (IsWindowOnTop(window))
734 if (window.IsActivationEnabled())
736 _Window* pTopWindow = GetTopWindow();
739 pTopWindow->Deactivate();
743 if (IsWindowAttached(window))
745 r = MoveWindowToTop(window); // [ToDo] excpetion
746 SysAssert(r == E_SUCCESS);
751 r = window.GetControlDelegate().OnAttaching(null);
752 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
754 r = CallOnAttachingToMainTree(window);
755 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
757 r = AttachWindow(window);
758 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
760 if (window.IsActivationEnabled())
765 if (window.IsOrientationRoot() == false)
767 window.ChangeLayout(GetOrientation());
769 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
772 pEcoreEvas->RotateWindow(window, ::Convert(__orientationStatus));
776 r = window.GetControlDelegate().OnAttached();
777 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
779 r = CallOnAttachedToMainTree(window);
780 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
787 _ControlManager::CallOnAttachingToMainTree(_Control& control)
789 result r = E_SUCCESS;
791 r = control.GetControlDelegate().OnAttachingToMainTree(null);
792 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
794 _Control::ControlList& children = control.GetChildList();
795 _Control* pChild = null;
797 for (int index = 0; index < children.GetCount(); index++)
799 r = children.GetAt(index, pChild);
802 SysAssert(r == E_OUT_OF_RANGE);
804 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
805 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
807 r = CallOnAttachingToMainTree(*pChild);
808 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
815 _ControlManager::CallOnAttachedToMainTree(_Control& control)
817 result r = E_SUCCESS;
819 _Control* pChild = null;
820 _Control::ControlList* pControlList = new (std::nothrow) _Control::ControlList;
821 pControlList->Construct(control.GetChildList());
823 r = control.GetControlDelegate().OnAttachedToMainTree();
824 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
826 for (int index = 0; index < pControlList->GetCount(); index++)
828 r = pControlList->GetAt(index, pChild);
831 SysAssert(r == E_OUT_OF_RANGE);
833 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
834 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
836 r = control.CallOnAttachedToMainTree(*pChild);
837 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
846 _ControlManager::CallOnDetachingFromMainTree(_Control& control)
848 result r = E_SUCCESS;
850 _Control* pChild = null;
851 _Control::ControlList& children = control.GetChildList();
853 r = control.GetControlDelegate().OnDetachingFromMainTree();
854 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
856 for (int index = 0; index < children.GetCount(); index++)
858 r = children.GetAt(index, pChild);
861 SysAssert(r == E_OUT_OF_RANGE);
863 (r != E_OUT_OF_RANGE), E_OUT_OF_RANGE,
864 E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified index is out of range.");
866 r = CallOnDetachingFromMainTree(*pChild);
867 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
874 _ControlManager::CloseWindow(_Window& window) // [ToDo] exception check.
877 result r = E_SUCCESS;
879 #if !defined(MULTI_WINDOW)
880 // if (dynamic_cast<_NotificationFrame*>(&window))
881 if (window.IsSystemWindow())
883 r = CallOnDetachingFromMainTree(window);
884 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
886 window.GetControlDelegate().OnDetaching();
892 if (IsWindowAttached(window) == false)
897 bool wasWindowOnTop = IsWindowOnTop(window);
901 r = DetachWindow(window);
902 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
906 _Window* pNewTopWindow = GetTopWindow();
907 if (pNewTopWindow && pNewTopWindow->IsActivatedOnOpen())
909 pNewTopWindow->Activate();
913 if (dynamic_cast <_Frame*>(&window) != null)
915 // __pWindowPi->SetFrame(null); // ?
916 __pCurrentFrame = null;
920 if (IsWindowAttached(window) == false)
925 bool wasWindowOnTop = IsWindowOnTop(window);
927 r = CallOnDetachingFromMainTree(window);
928 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
930 window.GetControlDelegate().OnDetaching();
934 r = DetachWindow(window);
935 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
939 _Window* pNewTopWindow = GetTopWindow();
940 if (pNewTopWindow && pNewTopWindow->IsActivationEnabled())
942 pNewTopWindow->Activate();
945 if (dynamic_cast <_Frame*>(pNewTopWindow) != null)
947 __pCurrentFrame = pNewTopWindow;
956 _ControlManager::GetWindow(int index) const
958 #if !defined(MULTI_WINDOW)
959 return dynamic_cast <_Window*>(GetRoot().GetChild(index));
962 __pWindowList->GetAt(index, pWindow);
969 _ControlManager::GetWindowCount(void) const
971 #if !defined(MULTI_WINDOW)
972 return GetRoot().GetChildCount();
974 return __pWindowList->GetCount();
979 _ControlManager::AttachWindow(_Window& window)
981 _IndicatorManager::GetInstance()->AddWindow(&window);
983 #if !defined(MULTI_WINDOW)
984 return GetRoot().AttachChild(window);
986 return __pWindowList->Add(&window);
991 _ControlManager::InsertWindowToBottom(_Window& window)
993 #if !defined(MULTI_WINDOW)
994 return GetRoot().InsertChildToBottom(window);
996 return __pWindowList->InsertAt(&window, 0);
1001 _ControlManager::InsertWindowAfter(const _Window& targetWindow, _Window& window)
1003 #if !defined(MULTI_WINDOW)
1004 return GetRoot().InsertChildAfter(targetWindow, window);
1008 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
1009 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1011 return __pWindowList->InsertAt(&window, index+1);
1016 _ControlManager::InsertWindowBefore(const _Window& targetWindow, _Window& window)
1018 #if !defined(MULTI_WINDOW)
1019 return GetRoot().InsertChildBefore(targetWindow, window);
1023 result r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
1024 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1026 return __pWindowList->InsertAt(&window, index);
1031 _ControlManager::DetachWindow(_Window& window)
1033 _IndicatorManager::GetInstance()->DeleteWindow(&window);
1035 #if !defined(MULTI_WINDOW)
1036 return GetRoot().DetachChild(window);
1038 return __pWindowList->Remove(&window);
1043 _ControlManager::DetachAllWindows(void)
1045 #if !defined(MULTI_WINDOW)
1046 GetRoot().DetachAllChildren();
1048 __pWindowList->RemoveAll();
1053 _ControlManager::MoveWindowToTop(const _Window& window)
1055 #if !defined(MULTI_WINDOW)
1056 return GetRoot().MoveChildToTop(window);
1058 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
1059 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1061 return __pWindowList->Add(const_cast<_Window*>(&window));
1066 _ControlManager::MoveWindowToBottom(const _Window& window)
1068 #if !defined(MULTI_WINDOW)
1069 return GetRoot().MoveChildToBottom(window);
1071 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
1072 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1074 return __pWindowList->InsertAt(const_cast<_Window*>(&window), 0);
1079 _ControlManager::MoveWindowAfter(const _Window& targetWindow, const _Window& window)
1081 #if !defined(MULTI_WINDOW)
1082 return GetRoot().MoveChildAfter(targetWindow, window);
1084 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
1085 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1089 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
1090 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1092 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index+1);
1097 _ControlManager::MoveWindowBefore(const _Window& targetWindow, const _Window& window)
1099 #if !defined(MULTI_WINDOW)
1100 return GetRoot().MoveChildBefore(targetWindow, window);
1102 result r = __pWindowList->Remove(const_cast<_Window*>(&window));
1103 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1107 r = __pWindowList->IndexOf(const_cast<_Window*>(&targetWindow), index);
1108 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1110 return __pWindowList->InsertAt(const_cast<_Window*>(&window), index);
1115 _ControlManager::GetOrientation(void) const
1117 return __orientation;
1121 _ControlManager::SetOrientation(_ControlOrientation orientation)
1123 __orientation = orientation;
1127 _ControlManager::GetScreenRotation(void) const
1129 bool autoRotate = true;
1130 int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_AUTO_ROTATION_ENABLED, &autoRotate);
1132 if (ret == RUNTIME_INFO_ERROR_NONE)
1134 SysLog(NID_UI, "The flag of auto-rotate is %d.", autoRotate);
1138 SysLog(NID_UI, "It's failed to get the flag of auto-rotate.");
1141 if (autoRotate == false)
1143 return _CONTROL_ROTATION_0;
1147 return __screenRotation;
1152 _ControlManager::OnScreenRotated(int rotation)
1154 SysLog(NID_UI, "The angle of Emul or Target is %d.", rotation);
1155 __screenRotation = ::Convert(rotation);
1157 #if defined(MULTI_WINDOW)
1158 int count = GetWindowCount();
1160 for (int i = 0; i < count; i++)
1162 _Window* pWindow = GetWindow((count-1) - i);
1164 _Frame* pFrame = dynamic_cast<_Frame*>(pWindow);
1168 Controls::_FrameImpl* pFrameImpl = static_cast<Controls::_FrameImpl*>(pFrame->GetUserData());
1169 if (pFrameImpl == null)
1174 Controls::_FormImpl* pCurrentFormImpl = pFrameImpl->GetCurrentForm();
1175 if (pCurrentFormImpl)
1177 pCurrentFormImpl->UpdateOrientationStatus(true);
1181 pFrameImpl->UpdateOrientationStatus();
1188 #if defined(MULTI_WINDOW)
1190 _ControlManager::SetTouchedWindow(unsigned int window)
1192 __touchedWindow = window;
1196 _ControlManager::GetTouchedWindow(void) const
1200 if (GetWindowCount() == 0)
1205 int count = GetWindowCount();
1206 for (int i = 0; i < count; i++)
1208 _Window* pWindow = GetWindow((count-1) - i);
1210 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
1211 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
1213 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1214 Ecore_X_Window win = (Ecore_X_Window) ecore_evas_window_get(pEcoreEvas);
1216 if (win == __touchedWindow)
1227 _ControlManager::SetOrientationStatus(_ControlRotation orientationStatus)
1229 __orientationStatus = orientationStatus;
1233 _ControlManager::RotateScreen(_ControlRotation screenRotation)
1235 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
1236 SysAssert(pEcoreEvas);
1237 if (pEcoreEvas == null)
1242 pEcoreEvas->RotateWindow(::Convert(screenRotation));
1244 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1247 pTouchManager->SetTouchCanceled(true);
1252 _ControlManager::RotateScreen(const _Control& control, _ControlRotation screenRotation)
1254 _EcoreEvas* pEcoreEvas = ::GetEcoreEvasMgr()->GetEcoreEvas();
1255 SysAssert(pEcoreEvas);
1256 if (pEcoreEvas == null)
1261 // Rotate root window.
1262 _Window* pRootWindow = control.GetRootWindow();
1265 pEcoreEvas->RotateWindow(*pRootWindow, ::Convert(screenRotation));
1268 #if defined(MULTI_WINDOW)
1270 int owneeCount = control.GetOwneeCount();
1271 for (int i = 0; i < owneeCount; i++)
1273 _Window* pOwnee = control.GetOwnee(i);
1276 pEcoreEvas->RotateWindow(*pOwnee, ::Convert(screenRotation));
1281 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1284 pTouchManager->SetTouchCanceled(true);
1289 _ControlManager::OnWindowRotated(int rotation)
1291 #if !defined(MULTI_WINDOW)
1292 IEnumeratorT<_Window*>* pEnumerator = __pSystemWindowList->GetEnumeratorN();
1293 SysTryReturnVoidResult(NID_UI, pEnumerator, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1295 while (pEnumerator->MoveNext() == E_SUCCESS)
1297 _Window* pWindow = null;
1298 pEnumerator->GetCurrent(pWindow);
1301 _WindowImpl* pWindowImpl = static_cast<_WindowImpl*>(pWindow->GetUserData());
1304 pWindowImpl->Rotate(Convert(rotation));
1310 IEnumeratorT<_Window*>* pEnumerator = __pWindowList->GetEnumeratorN();
1311 SysTryReturnVoidResult(NID_UI, pEnumerator, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
1313 while (pEnumerator->MoveNext() == E_SUCCESS)
1315 _Window* pWindow = null;
1316 pEnumerator->GetCurrent(pWindow);
1318 if (pWindow->GetOwner() == null)
1320 void* pUserData = pWindow->GetUserData();
1323 _WindowImpl* pWindowImpl = static_cast<_WindowImpl*>(pUserData);
1324 pWindowImpl->OnRotated(Convert(rotation));
1334 _ControlManager::SetFocusedControl(const _Control& control)
1336 if (__pFocusedControl == &control)
1341 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
1342 SysTryReturnVoidResult(NID_UI, pEcoreEvas, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1344 _Control *pPreviousFocusedControl = __pFocusedControl;
1345 __pFocusedControl = const_cast<_Control*>(&control);
1347 if (pPreviousFocusedControl)
1349 // [review] make SetFocus() return result and use the returned result here.
1350 pEcoreEvas->SetFocus(*pPreviousFocusedControl, false);
1351 if (GetLastResult() == E_SUCCESS)
1353 if (pPreviousFocusedControl)
1355 pPreviousFocusedControl->SetFocusOff(pPreviousFocusedControl);
1357 _UiFocusEvent event(pPreviousFocusedControl->GetHandle(), FOCUS_LOST);
1358 _UiEventManager::GetInstance()->SendEvent(event);
1362 // [review] make SetFocus() return result and use the returned result here.
1363 if (control.IsNativeObjectFocusable())
1365 pEcoreEvas->SetFocus(control, true);
1368 if (GetLastResult() == E_SUCCESS)
1370 _UiFocusEvent event(control.GetHandle(), FOCUS_GAINED);
1371 _UiEventManager::GetInstance()->SendEvent(event);
1372 const_cast<_Control*>(&control)->SetFocusOn();
1376 // [review] called in ~_Control and virtual OnFocusLost is called.
1377 // _Control::Release() instead of ~_Control.
1379 _ControlManager::TakeFocusFromControl(const _Control& control)
1381 if (__pFocusedControl == &control)
1383 _UiFocusEvent event(__pFocusedControl->GetHandle(), FOCUS_LOST);
1384 _UiEventManager::GetInstance()->SendEvent(event);
1385 __pFocusedControl = null;
1393 _ControlManager::GetFocusedControl(void) const
1395 return __pFocusedControl;
1399 _ControlManager::GetTopmostTouchedControl(const Point& point)
1401 _Control* pControl = null;
1402 _Window* pTopWindow = null;
1404 #if !defined(MULTI_WINDOW)
1405 pTopWindow = GetTopWindow();
1407 int count = GetWindowCount();
1411 for (int i = 0; i < count; i++)
1413 _Window* pWindow = GetWindow((count-1) - i);
1415 if (pWindow->GetVisibleState() == false)
1420 _RootVisualElement* pRootVE = pWindow->GetRootVisualElement();
1421 _EflLayer* pLayer = static_cast<_EflLayer*>(pRootVE->GetNativeLayer());
1423 Ecore_Evas* pEcoreEvas = pLayer->GetEcoreEvas();
1424 Ecore_X_Window win = (Ecore_X_Window)ecore_evas_window_get(pEcoreEvas);
1426 Rectangle winDeviceBounds(0, 0, 0, 0);
1427 ecore_x_window_geometry_get(win, &winDeviceBounds.x, &winDeviceBounds.y, &winDeviceBounds.width, &winDeviceBounds.height);
1429 Point winDevicePoint = _CoordinateSystemUtils::Transform(pWindow->GetPosition());
1431 Point devicePoint = _CoordinateSystemUtils::Transform(point);
1432 int x = devicePoint.x;
1433 int y = devicePoint.y;
1437 ecore_x_window_size_get(ecore_x_window_root_get(win), &rootW, &rootH);
1439 int rotation = ecore_evas_rotation_get(pEcoreEvas);
1443 devicePoint.x = rootW - y;
1445 winDeviceBounds.x = rootW - winDevicePoint.y - winDeviceBounds.width;
1446 winDeviceBounds.y = winDevicePoint.x;
1449 devicePoint.x = rootW - x;
1450 devicePoint.y = rootH - y;
1451 winDeviceBounds.x = rootW - winDevicePoint.x - winDeviceBounds.width;
1452 winDeviceBounds.y = rootH - winDevicePoint.y - winDeviceBounds.height;
1456 devicePoint.y = rootH - x;
1457 winDeviceBounds.x = winDevicePoint.y;
1458 winDeviceBounds.y = rootH - winDevicePoint.x - winDeviceBounds.height;
1463 winDeviceBounds.x = winDevicePoint.x;
1464 winDeviceBounds.y = winDevicePoint.y;
1468 if (winDeviceBounds.Contains(devicePoint))
1470 pTopWindow = pWindow;
1477 if (pTopWindow != null)
1481 #if !defined(MULTI_WINDOW)
1482 _Frame* pFrame = dynamic_cast<_Frame*>(pTopWindow);
1485 winPos = pFrame->GetPosition();
1488 Point relPos(point.x - winPos.x, point.y - winPos.y);
1489 pControl = GetRoot().GetTopmostChildAt(relPos);
1491 winPos = pTopWindow->GetPosition();
1493 Point relPos(point.x - winPos.x, point.y - winPos.y);
1494 pControl = pTopWindow->GetTopmostChildAt(relPos);
1496 if (pControl != null)
1498 if (pControl->GetRootWindow() == pTopWindow)
1508 // [review] rename __InvXformer
1510 _ControlManager::GetScreenSize(void) const
1512 return _CoordinateSystemUtils::InverseTransform(Dimension(_Screen::GetWidth(), _Screen::GetHeight()));
1516 _ControlManager::GetCurrentFrame(void) const
1518 return __pCurrentFrame;
1522 _ControlManager::SetDefaultFont(const String& appFontName)
1525 if(appFontName.Equals(__defaultFontName))
1530 __isDefaultFontChanged = true;
1531 __defaultFontName = appFontName;
1534 : public _Control::Visitor
1536 virtual _Control::VisitType Visit(_Control& control)
1538 if (control.__fontName.IsEmpty())
1540 control.GetFallbackFont();
1541 _IControlDelegate& delegate = control.GetControlDelegate();
1542 delegate.OnFontChanged(control.__pFont);
1544 return _Control::VISIT_DOWNWARD;
1550 #if !defined(MULTI_WINDOW)
1551 _Control& control = GetRoot();
1552 control.Accept(visitor);
1554 int count = GetWindowCount();
1556 for (int j = 0; j < count; j++)
1558 _Window* pWindow = GetWindow((count-1) - j);
1559 pWindow->Accept(visitor);
1563 SetDefaultFontChangeState(false);
1569 _ControlManager::GetDefaultFont(void)
1571 return __defaultFontName;
1575 _ControlManager::IsDefaultFontChanged(void)
1577 return __isDefaultFontChanged;
1581 _ControlManager::SetDefaultFontChangeState(bool isDefaultFontChanged)
1583 __isDefaultFontChanged = isDefaultFontChanged;
1587 _ControlManager::IsFrameActivated(void) const
1589 _Frame* pFrame = dynamic_cast<_Frame*>(__pCurrentFrame);
1590 SysTryReturn(NID_UI, pFrame, false, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1592 return pFrame->IsActivated();
1595 // [review] refactoring
1597 _ControlManager::AddGestureDetector(const _TouchGestureDetector& gesture)
1601 SysTryReturn(NID_UI, __pGestureList != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred. ");
1603 bool exist = __pGestureList->Contains(const_cast<_TouchGestureDetector*>(&gesture));
1604 SysTryReturnResult(NID_UI, exist == false, E_OBJ_ALREADY_EXIST, "[E_OBJ_ALREADY_EXIST]__pGestureList has gesture already");
1606 result r = __pGestureList->Add(const_cast<_TouchGestureDetector*>(&gesture));
1607 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1609 switch (gesture.GetDetectorType())
1611 case _TOUCH_GESTURE_DETECTOR_TYPE_TAP:
1613 _TouchTapGestureDetector* pGestureTap = dynamic_cast<_TouchTapGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1614 SysTryReturnResult(NID_UI, pGestureTap, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1616 if (pGestureTap->GetTapInterval() > __gestureMaxDuration)
1618 __gestureMaxDuration = pGestureTap->GetTapInterval();
1622 case _TOUCH_GESTURE_DETECTOR_TYPE_LONG_PRESS:
1624 _TouchLongPressGestureDetector* pGestureLongPress= dynamic_cast<_TouchLongPressGestureDetector*>(const_cast<_TouchGestureDetector*>(&gesture));
1625 SysTryReturnResult(NID_UI, pGestureLongPress, E_SYSTEM, "[E_SYSTEM]system error occurred.");
1627 if (pGestureLongPress->GetDuration() > __gestureMaxDuration)
1629 __gestureMaxDuration = pGestureLongPress->GetDuration();
1641 _ControlManager::RemoveGestureDetector(const _TouchGestureDetector& gesture)
1645 result r = __pGestureList->Remove(&(const_cast<_TouchGestureDetector&>(gesture)));
1646 SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1651 IListT <_TouchGestureDetector*>*
1652 _ControlManager::GetGestureDetectorList(void) const
1654 return __pGestureList;
1658 _ControlManager::GetGestureMaxTimeDuration(void) const
1660 return __gestureMaxDuration;
1664 _ControlManager::OnSettingChanged(Tizen::Base::String& key)
1666 const wchar_t* FONT_TYPE = L"http://tizen.org/setting/font.type";
1667 const wchar_t* LOCALE_COUNTRY = L"http://tizen.org/setting/locale.country";
1668 const wchar_t* LOCALE_LANGUAGE = L"http://tizen.org/setting/locale.language";
1670 if (key == FONT_TYPE || key == LOCALE_COUNTRY || key == LOCALE_LANGUAGE)
1672 _FontImpl::UpdateDefaultFont(key);
1674 int count = GetWindowCount();
1676 for(int index = 0; index < count ; index++)
1678 _Window* pWindow = GetWindow(index);
1679 pWindow->Invalidate(true);