Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / FUi_ControlImplManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
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.
16 //
17
18 /**
19  * @file                FUi_ControlImplManager.cpp
20  * @brief               This is the implementation file for the _ControlImplManager class.
21  */
22
23 #include <cstdio>
24 #include <cstring>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <new>
28 #include <dlfcn.h>
29
30 #include <FIoFile.h>
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"
42
43 #include "FUiCtrl_FrameImpl.h"
44 #include "FUiCtrl_FormImpl.h"
45 #include "FUiCtrl_PopupImpl.h"
46
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;
54
55 namespace // unnamed
56 {
57
58 OrientationStatus
59 Convert(_ControlRotation rotate, bool allowReverse)
60 {
61         OrientationStatus status = ORIENTATION_STATUS_NONE;
62
63         if (allowReverse == true)
64         {
65                 switch (rotate)
66                 {
67                 case _CONTROL_ROTATION_0:
68                         status = ORIENTATION_STATUS_PORTRAIT;
69                         break;
70                 case _CONTROL_ROTATION_270:
71                         status = ORIENTATION_STATUS_LANDSCAPE;
72                         break;
73                 case _CONTROL_ROTATION_180:
74                         status = ORIENTATION_STATUS_PORTRAIT_REVERSE;
75                         break;
76                 case _CONTROL_ROTATION_90:
77                         status = ORIENTATION_STATUS_LANDSCAPE_REVERSE;
78                         break;
79                 }
80         }
81         else
82         {
83                 switch (rotate)
84                 {
85                 case _CONTROL_ROTATION_0:
86                         // fall through
87                 case _CONTROL_ROTATION_180:
88                         status = ORIENTATION_STATUS_PORTRAIT;
89                         break;
90                 case _CONTROL_ROTATION_90:
91                         status = ORIENTATION_STATUS_LANDSCAPE_REVERSE;
92                         break;
93                 case _CONTROL_ROTATION_270:
94                         status = ORIENTATION_STATUS_LANDSCAPE;
95                         break;
96                 }
97         }
98
99         return status;
100 }
101
102 _ControlRotation
103 Convert(OrientationStatus orientationStatus)
104 {
105         switch (orientationStatus)
106         {
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;
115         default:
116                 return _CONTROL_ROTATION_0;
117         }
118 }
119
120 } // unnamed namespace
121
122 result
123 InitializeTestbuddyManager(void)
124 {
125         result r = E_FAILURE;
126         void* pHandle = null;
127
128         SysLog(NID_UI,"TestbuddyManager is starting.");
129
130         result (*pfnInitialize_TestBuddyManager)(void) = null;
131
132         pHandle = dlopen ("libtestbuddy.so", RTLD_LAZY);
133         if (!pHandle)
134         {
135                 SysLog(NID_UI, "[%s] Failed to dlopen libtestbuddy.so", dlerror());
136                 return E_LIBRARY_NOT_FOUND;
137         }
138
139         pfnInitialize_TestBuddyManager = reinterpret_cast<result (*)(void)>(dlsym(pHandle, "_Initialize_TestBuddyManager"));
140         if (pfnInitialize_TestBuddyManager == null)
141         {
142                 SysLog(NID_UI, "[%s] Failed to dlsym _Initialize_TestBuddyManager", dlerror());
143                 dlclose(pHandle);
144                 return E_SYMBOL_NOT_FOUND;
145         }
146
147         r = pfnInitialize_TestBuddyManager();
148         SysTryReturn(NID_UI, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] pfnInitialize_TestBuddyManager() is invaild.");
149
150         return r;
151 }
152
153 result
154 InitializeUiFramework(void)
155 {
156         _ControlImplManager::Initialize();
157
158         // TODO : After completing InitializeTestbuddyManager( )
159         //return GetLastResult();
160         return E_SUCCESS;
161 }
162
163 void
164 FinalizeUiFramework(void)
165 {
166         _ControlImplManager::Release();
167 }
168
169
170 namespace Tizen { namespace Ui {
171
172 _ControlImplManager* _ControlImplManager::__pInstance(null);
173
174 // Explicitly initialize just before the Form is created.
175 void
176 _ControlImplManager::Initialize(void)
177 {
178         static pthread_once_t once_block = PTHREAD_ONCE_INIT;
179
180         if (!__pInstance)
181         {
182                 pthread_once(&once_block, InitInstance);
183         }
184
185         _ControlManager::Initialize();
186
187         _KeyEventManagerImpl::Initialize();
188         _FocusManagerImpl::Initialize();
189         result r = InitializeTestbuddyManager();
190         SetLastResult(r);
191 }
192
193 void
194 _ControlImplManager::Release(void)
195 {
196         _ControlManager::Release();
197
198         _FocusManagerImpl::ReleaseInstance();
199         _KeyEventManagerImpl::ReleaseInstance();
200
201         delete __pInstance;
202         __pInstance = null;
203 }
204
205 _ControlImplManager*
206 _ControlImplManager::GetInstance(void)
207 {
208         return __pInstance;
209 }
210
211 void
212 _ControlImplManager::InitInstance(void)
213 {
214         if (__pInstance != null)
215         {
216                 return;
217         }
218
219         __pInstance = new (std::nothrow) _ControlImplManager;
220         SysAssert(__pInstance);
221 }
222
223 _ControlImplManager::_ControlImplManager(void)
224         : __pFrameImpl(null)
225 {
226 }
227
228 _ControlImplManager::~_ControlImplManager(void)
229 {
230 }
231
232 _WindowImpl*
233 _ControlImplManager::GetCurrentFrame(void) const
234 {
235         _Window* pFrame = _ControlManager::GetInstance()->GetCurrentFrame();
236         if (pFrame == null)
237         {
238                 return null;
239         }
240
241         _WindowImpl* pImpl = static_cast <_WindowImpl*>(pFrame->GetUserData());
242         return pImpl;
243 }
244
245 void
246 _ControlImplManager::OnScreenRotated(int rotation)
247 {
248         // Do not use the device orientation callback.
249         return;
250 }
251
252 void
253 _ControlImplManager::SetOrientationStatus(OrientationStatus orientationStatus)
254 {
255         _ControlManager* pCore = _ControlManager::GetInstance();
256         SysAssert(pCore);
257
258         pCore->SetOrientationStatus(::Convert(orientationStatus));
259 }
260
261 void
262 _ControlImplManager::RotateScreen(_ControlImpl* pControlImpl, OrientationStatus orientationStatus)
263 {
264         _ControlManager* pCore = _ControlManager::GetInstance();
265         SysAssert(pCore);
266
267         pCore->RotateScreen(pControlImpl->GetCore(), ::Convert(orientationStatus));
268 }
269
270 OrientationStatus
271 _ControlImplManager::GetOrientationStatus(Orientation mode) const
272 {
273         _ControlManager* pCore = _ControlManager::GetInstance();
274         SysAssert(pCore);
275
276         const _ControlRotation screenRotation = pCore->GetScreenRotation();
277
278 #if 1
279 // RSA : Support 4-Direction Rotation
280         if (mode == ORIENTATION_AUTOMATIC_FOUR_DIRECTION)
281         {
282                 return ::Convert(screenRotation, true);
283         }
284
285         if (mode == ORIENTATION_AUTOMATIC)
286 #else
287 // Private : Unsupport 4-Direction Rotation
288         if ((mode == ORIENTATION_AUTOMATIC) || (mode == ORIENTATION_AUTOMATIC_FOUR_DIRECTION))
289 #endif
290         {
291                 // device : 180 degree
292                 // return the previous orientation status
293
294                 _ControlManager* pCore = _ControlManager::GetInstance();
295                 if (pCore)
296                 {
297                         _ControlRotation controlRotation = pCore->GetScreenRotation();
298                         if (controlRotation == _CONTROL_ROTATION_180)
299                         {
300                                 OrientationStatus prevOrientationStatus = ORIENTATION_STATUS_NONE;
301
302                                 _ControlRotation prevRotation = pCore->GetOrientationStatus();
303                                 switch (prevRotation)
304                                 {
305                                 case _CONTROL_ROTATION_0:
306                                         // fall through
307                                 case _CONTROL_ROTATION_180:
308                                         prevOrientationStatus = ORIENTATION_STATUS_PORTRAIT;
309                                         break;
310                                 case _CONTROL_ROTATION_90:
311                                         prevOrientationStatus = ORIENTATION_STATUS_LANDSCAPE_REVERSE;
312                                         break;
313                                 case _CONTROL_ROTATION_270:
314                                         prevOrientationStatus = ORIENTATION_STATUS_LANDSCAPE;
315                                         break;
316                                 default:
317                                         break;
318                                 }
319
320                                 return prevOrientationStatus;
321                         }
322                 }
323
324                 return ::Convert(screenRotation, false);
325         }
326
327         OrientationStatus status = ORIENTATION_STATUS_NONE;
328         switch (mode)
329         {
330         case ORIENTATION_PORTRAIT:
331                 status = ORIENTATION_STATUS_PORTRAIT;
332                 break;
333         case ORIENTATION_LANDSCAPE:
334                 status = ORIENTATION_STATUS_LANDSCAPE;
335                 break;
336         case ORIENTATION_PORTRAIT_REVERSE:
337                 status = ORIENTATION_STATUS_PORTRAIT_REVERSE;
338                 break;
339         case ORIENTATION_LANDSCAPE_REVERSE:
340                 status = ORIENTATION_STATUS_LANDSCAPE_REVERSE;
341                 break;
342         default:
343                 SysAssert(false);
344         }
345
346         return status;
347 }
348
349 OrientationStatus
350 _ControlImplManager::GetFormOrientationStatus(const _ControlImpl* pControlImpl) const
351 {
352         const _FormImpl* pFormImpl = null;
353         const _ControlImpl* pOriControlImpl = pControlImpl;
354         OrientationStatus orientation = ORIENTATION_STATUS_NONE;
355
356         while(pControlImpl)
357         {
358                 pFormImpl = dynamic_cast<const _FormImpl*>(pControlImpl);
359
360                 if (pFormImpl)
361                 {
362                         break;
363                 }
364                 else
365                 {
366                         pControlImpl = pControlImpl->GetParent();
367                 }
368         }
369
370         if (pFormImpl)
371         {
372                 orientation = pFormImpl->GetOrientationStatus();
373         }
374
375         if (orientation == ORIENTATION_STATUS_NONE)
376         {
377                 _Form* pForm = null;
378                 _Control* pControl = const_cast<_Control*>(&(pOriControlImpl->GetCore()));
379                 while(pControl)
380                 {
381                         pForm = dynamic_cast<_Form*>(pControl);
382
383                         if (pForm != null)
384                         {
385                                 break;
386                         }
387                         else
388                         {
389                                 pControl = pControl->GetParent();
390                         }
391                 }
392
393                 if (pForm)
394                 {
395                         _FormImpl* pFormImpl = static_cast<_FormImpl*>(pForm->GetUserData());
396                         orientation = pFormImpl->GetOrientationStatus();
397                 }
398
399         }
400
401         return orientation;
402 }
403
404 }} // Tizen::Ui