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_ControlImplManager.cpp
20 * @brief This is the implementation file for the _ControlImplManager class.
31 #include <FBaseSysLog.h>
32 #include <FUiCtrlForm.h>
33 #include <FApp_AppInfo.h>
34 #include <FGrp_CoordinateSystem.h>
35 #include <FSys_SystemInfoImpl.h>
36 #include "FUi_FocusManagerImpl.h"
37 #include "FUi_ControlImplManager.h"
38 #include "FUi_ControlManager.h"
39 #include "FUi_WindowImpl.h"
40 #include "FUi_KeyEventManagerImpl.h"
41 #include "FUi_FocusManagerImpl.h"
43 #include "FUiCtrl_FrameImpl.h"
44 #include "FUiCtrl_FormImpl.h"
45 #include "FUiCtrl_PopupImpl.h"
47 using namespace Tizen::App;
48 using namespace Tizen::Base;
49 using namespace Tizen::Graphics;
50 using namespace Tizen::Io;
51 using namespace Tizen::Ui;
52 using namespace Tizen::Ui::Controls;
53 using namespace Tizen::Ui::Animations;
59 Convert(_ControlRotation rotate, bool allowReverse)
61 OrientationStatus status = ORIENTATION_STATUS_NONE;
63 if (allowReverse == true)
67 case _CONTROL_ROTATION_0:
68 status = ORIENTATION_STATUS_PORTRAIT;
70 case _CONTROL_ROTATION_270:
71 status = ORIENTATION_STATUS_LANDSCAPE;
73 case _CONTROL_ROTATION_180:
74 status = ORIENTATION_STATUS_PORTRAIT_REVERSE;
76 case _CONTROL_ROTATION_90:
77 status = ORIENTATION_STATUS_LANDSCAPE_REVERSE;
85 case _CONTROL_ROTATION_0:
87 case _CONTROL_ROTATION_180:
88 status = ORIENTATION_STATUS_PORTRAIT;
90 case _CONTROL_ROTATION_90:
91 status = ORIENTATION_STATUS_LANDSCAPE_REVERSE;
93 case _CONTROL_ROTATION_270:
94 status = ORIENTATION_STATUS_LANDSCAPE;
103 Convert(OrientationStatus orientationStatus)
105 switch (orientationStatus)
107 case ORIENTATION_STATUS_PORTRAIT:
108 return _CONTROL_ROTATION_0;
109 case ORIENTATION_STATUS_LANDSCAPE:
110 return _CONTROL_ROTATION_270;
111 case ORIENTATION_STATUS_PORTRAIT_REVERSE:
112 return _CONTROL_ROTATION_180;
113 case ORIENTATION_STATUS_LANDSCAPE_REVERSE:
114 return _CONTROL_ROTATION_90;
116 return _CONTROL_ROTATION_0;
120 } // unnamed namespace
123 InitializeTestbuddyManager(void)
125 result r = E_FAILURE;
126 void* pHandle = null;
128 SysLog(NID_UI,"TestbuddyManager is starting.");
130 result (*pfnInitialize_TestBuddyManager)(void) = null;
132 pHandle = dlopen ("libtestbuddy.so", RTLD_LAZY);
135 SysLog(NID_UI, "[%s] Failed to dlopen libtestbuddy.so", dlerror());
136 return E_LIBRARY_NOT_FOUND;
139 pfnInitialize_TestBuddyManager = reinterpret_cast<result (*)(void)>(dlsym(pHandle, "_Initialize_TestBuddyManager"));
140 if (pfnInitialize_TestBuddyManager == null)
142 SysLog(NID_UI, "[%s] Failed to dlsym _Initialize_TestBuddyManager", dlerror());
144 return E_SYMBOL_NOT_FOUND;
147 r = pfnInitialize_TestBuddyManager();
148 SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] pfnInitialize_TestBuddyManager() is invaild.");
154 InitializeUiFramework(void)
156 _ControlImplManager::Initialize();
158 // TODO : After completing InitializeTestbuddyManager( )
159 //return GetLastResult();
164 FinalizeUiFramework(void)
166 _ControlImplManager::Release();
170 namespace Tizen { namespace Ui {
172 _ControlImplManager* _ControlImplManager::__pInstance(null);
174 // Explicitly initialize just before the Form is created.
176 _ControlImplManager::Initialize(void)
178 static pthread_once_t once_block = PTHREAD_ONCE_INIT;
182 pthread_once(&once_block, InitInstance);
185 _ControlManager::Initialize();
187 _KeyEventManagerImpl::Initialize();
188 _FocusManagerImpl::Initialize();
189 result r = InitializeTestbuddyManager();
194 _ControlImplManager::Release(void)
196 _ControlManager::Release();
198 _FocusManagerImpl::ReleaseInstance();
199 _KeyEventManagerImpl::ReleaseInstance();
206 _ControlImplManager::GetInstance(void)
212 _ControlImplManager::InitInstance(void)
214 if (__pInstance != null)
219 __pInstance = new (std::nothrow) _ControlImplManager;
220 SysAssert(__pInstance);
223 _ControlImplManager::_ControlImplManager(void)
228 _ControlImplManager::~_ControlImplManager(void)
233 _ControlImplManager::GetCurrentFrame(void) const
235 _Window* pFrame = _ControlManager::GetInstance()->GetCurrentFrame();
241 _WindowImpl* pImpl = static_cast <_WindowImpl*>(pFrame->GetUserData());
246 _ControlImplManager::OnScreenRotated(int rotation)
248 // Do not use the device orientation callback.
253 _ControlImplManager::SetOrientationStatus(OrientationStatus orientationStatus)
255 _ControlManager* pCore = _ControlManager::GetInstance();
258 pCore->SetOrientationStatus(::Convert(orientationStatus));
262 _ControlImplManager::RotateScreen(_ControlImpl* pControlImpl, OrientationStatus orientationStatus)
264 _ControlManager* pCore = _ControlManager::GetInstance();
267 pCore->RotateScreen(pControlImpl->GetCore(), ::Convert(orientationStatus));
271 _ControlImplManager::GetOrientationStatus(Orientation mode) const
273 _ControlManager* pCore = _ControlManager::GetInstance();
276 const _ControlRotation screenRotation = pCore->GetScreenRotation();
279 // RSA : Support 4-Direction Rotation
280 if (mode == ORIENTATION_AUTOMATIC_FOUR_DIRECTION)
282 return ::Convert(screenRotation, true);
285 if (mode == ORIENTATION_AUTOMATIC)
287 // Private : Unsupport 4-Direction Rotation
288 if ((mode == ORIENTATION_AUTOMATIC) || (mode == ORIENTATION_AUTOMATIC_FOUR_DIRECTION))
291 // device : 180 degree
292 // return the previous orientation status
294 _ControlManager* pCore = _ControlManager::GetInstance();
297 _ControlRotation controlRotation = pCore->GetScreenRotation();
298 if (controlRotation == _CONTROL_ROTATION_180)
300 OrientationStatus prevOrientationStatus = ORIENTATION_STATUS_NONE;
302 _ControlRotation prevRotation = pCore->GetOrientationStatus();
303 switch (prevRotation)
305 case _CONTROL_ROTATION_0:
307 case _CONTROL_ROTATION_180:
308 prevOrientationStatus = ORIENTATION_STATUS_PORTRAIT;
310 case _CONTROL_ROTATION_90:
311 prevOrientationStatus = ORIENTATION_STATUS_LANDSCAPE_REVERSE;
313 case _CONTROL_ROTATION_270:
314 prevOrientationStatus = ORIENTATION_STATUS_LANDSCAPE;
320 return prevOrientationStatus;
324 return ::Convert(screenRotation, false);
327 OrientationStatus status = ORIENTATION_STATUS_NONE;
330 case ORIENTATION_PORTRAIT:
331 status = ORIENTATION_STATUS_PORTRAIT;
333 case ORIENTATION_LANDSCAPE:
334 status = ORIENTATION_STATUS_LANDSCAPE;
336 case ORIENTATION_PORTRAIT_REVERSE:
337 status = ORIENTATION_STATUS_PORTRAIT_REVERSE;
339 case ORIENTATION_LANDSCAPE_REVERSE:
340 status = ORIENTATION_STATUS_LANDSCAPE_REVERSE;
350 _ControlImplManager::GetFormOrientationStatus(const _ControlImpl* pControlImpl) const
352 const _FormImpl* pFormImpl = null;
353 const _ControlImpl* pOriControlImpl = pControlImpl;
354 OrientationStatus orientation = ORIENTATION_STATUS_NONE;
358 pFormImpl = dynamic_cast<const _FormImpl*>(pControlImpl);
366 pControlImpl = pControlImpl->GetParent();
372 orientation = pFormImpl->GetOrientationStatus();
375 if (orientation == ORIENTATION_STATUS_NONE)
378 _Control* pControl = const_cast<_Control*>(&(pOriControlImpl->GetCore()));
381 pForm = dynamic_cast<_Form*>(pControl);
389 pControl = pControl->GetParent();
395 _FormImpl* pFormImpl = static_cast<_FormImpl*>(pForm->GetUserData());
396 orientation = pFormImpl->GetOrientationStatus();