Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / FUi_FocusManagerImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
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 * @file             FUi_FocusManagerImpl.cpp
19 * @brief                This is the implementation file for _FocusManagerImpl class.
20 * @version              2.0
21 *
22 */
23
24 #include "FUi_FocusManagerImpl.h"
25 #include "FUi_ControlImpl.h"
26 #include "FUi_WindowImpl.h"
27 #include "FUi_ControlManager.h"
28
29
30 namespace Tizen { namespace Ui
31 {
32 ////////////////////////////////////////////////////////////////////////////////
33 /// _FocusManagerImpl class Lifecycle
34 _FocusManagerImpl* _FocusManagerImpl::__pInstance = null;
35
36 _FocusManagerImpl::_FocusManagerImpl(void)
37 {
38         //NOHING
39 }
40
41
42 _FocusManagerImpl::~_FocusManagerImpl(void)
43 {
44         // NOTHING
45 }
46
47 void
48 _FocusManagerImpl::Initialize(void)
49 {
50         static pthread_once_t once_block = PTHREAD_ONCE_INIT;
51
52         if (__pInstance == null)
53         {
54                 pthread_once(&once_block, InitializeInstance);
55         }
56 }
57
58 _FocusManagerImpl*
59 _FocusManagerImpl::GetInstance(void)
60 {
61         return __pInstance;
62 }
63
64 void
65 _FocusManagerImpl::InitializeInstance(void)
66 {
67         ClearLastResult();
68
69         if (__pInstance == null)
70         {
71                 __pInstance = new (std::nothrow) _FocusManagerImpl;
72                 SysTryReturnVoidResult(NID_UI, __pInstance != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
73         }
74 }
75
76 void
77 _FocusManagerImpl::ReleaseInstance(void)
78 {
79         if (__pInstance)
80         {
81                 delete __pInstance;
82                 __pInstance = null;
83         }
84 }
85
86 ////////////////////////////////////////////////////////////////////////////////
87 /// _FocusManagerImpl class Operation
88
89 _ControlImpl*
90 _FocusManagerImpl::GetCurrentFocusOwner(void) const
91 {
92         _Control* pFocus = _ControlManager::GetInstance()->GetFocusedControl();
93         if(pFocus == null)
94         {
95                 return null;
96         }
97
98         _ControlImpl* pFocusImpl = static_cast <_ControlImpl*>(pFocus->GetUserData());
99         SysAssert(pFocusImpl);
100
101         return pFocusImpl;
102 }
103
104
105 _WindowImpl*
106 _FocusManagerImpl::GetCurrentFocusedWindow(void) const
107 {
108         _Control* pFocus = _ControlManager::GetInstance()->GetFocusedControl();
109         if(pFocus == null)
110         {
111                 return null;
112         }
113         _Window* pWindow = pFocus->GetRootWindow();
114         SysAssert(pWindow);
115
116         _WindowImpl* pWindowImpl = static_cast <_WindowImpl*>(static_cast <_ControlImpl*>(pWindow->GetUserData()));
117         SysAssert(pWindowImpl);
118
119         return pWindowImpl;
120 }
121
122 } } //Tizen::Ui