Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-imf-manager.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "toolkit-imf-manager.h"
20
21 // EXTERNAL INCLUDES
22 #include <boost/bind.hpp>
23
24 #include <dali/dali.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/integration-api/events/key-event-integ.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 namespace Adaptor
33 {
34 class RenderSurface;
35
36
37 class ImfManager : public Dali::BaseObject
38 {
39 public:
40   typedef Dali::ImfManager::ImfManagerSignalV2 ImfManagerSignalV2;
41   typedef Dali::ImfManager::ImfEventSignalV2 ImfEventSignalV2;
42
43 public:
44   static Dali::ImfManager Get();
45
46   ImfManager( /* Ecore_X_Window ecoreXwin */ );
47   void ConnectCallbacks();
48   void DisconnectCallbacks();
49   void Activate();
50   void Deactivate();
51   void Reset();
52
53   bool RestoreAfterFocusLost() const;
54   void SetRestoreAferFocusLost( bool toggle );
55   void NotifyCursorPosition();
56   int GetCursorPosition();
57   void SetCursorPosition( unsigned int cursorPosition );
58   void SetSurroundingText( std::string text );
59   std::string GetSurroundingText();
60
61 public:  // Signals
62   ImfManagerSignalV2& ActivatedSignal() { return mActivatedSignalV2; }
63   ImfEventSignalV2& EventReceivedSignal() { return mEventSignalV2; }
64
65 protected:
66   virtual ~ImfManager();
67
68 private:
69   void CreateContext( /*Ecore_X_Window ecoreXwin*/ );
70   void DeleteContext();
71
72 private:
73   // Undefined
74   ImfManager( const ImfManager& );
75   ImfManager& operator=( ImfManager& );
76
77 private:
78   int mIMFCursorPosition;
79   std::string mSurroundingText;
80   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
81   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
82
83   std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
84   ImfManagerSignalV2      mActivatedSignalV2;
85   ImfEventSignalV2        mEventSignalV2;
86
87
88   static Dali::ImfManager mToolkitImfManager;
89
90 public:
91
92 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
93 {
94   Dali::ImfManager actualImfManager = ImfManager::Get();
95
96   BaseObject& handle = actualImfManager.GetBaseObject();
97   return static_cast<Internal::Adaptor::ImfManager&>(handle);
98 }
99
100 inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
101 {
102   Dali::ImfManager actualImfManager = ImfManager::Get();
103
104   const BaseObject& handle = imfManager.GetBaseObject();
105   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
106 }
107
108 };
109
110 Dali::ImfManager Dali::Internal::Adaptor::ImfManager::mToolkitImfManager;
111
112 Dali::ImfManager ImfManager::Get()
113 {
114   Dali::ImfManager manager;
115
116   if( ! mToolkitImfManager )
117   {
118     mToolkitImfManager = Dali::ImfManager( new Dali::Internal::Adaptor::ImfManager() );
119   }
120   return mToolkitImfManager;
121 }
122
123 ImfManager::ImfManager( /*Ecore_X_Window ecoreXwin*/ )
124 : mIMFCursorPosition( 0 ),
125   mSurroundingText(""),
126   mRestoreAfterFocusLost( false ),
127   mIdleCallbackConnected( false ),
128   mKeyEvents()
129 {
130   CreateContext( /*ecoreXwin*/ );
131   ConnectCallbacks();
132 }
133
134 ImfManager::~ImfManager()
135 {
136   DisconnectCallbacks();
137   DeleteContext();
138 }
139
140 void ImfManager::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
141 {
142 }
143
144 void ImfManager::DeleteContext()
145 {
146 }
147
148 // Callbacks for predicitive text support.
149 void ImfManager::ConnectCallbacks()
150 {
151 }
152
153 void ImfManager::DisconnectCallbacks()
154 {
155 }
156
157 void ImfManager::Activate()
158 {
159 }
160
161 void ImfManager::Deactivate()
162 {
163 }
164
165 void ImfManager::Reset()
166 {
167 }
168
169 bool ImfManager::RestoreAfterFocusLost() const
170 {
171   return mRestoreAfterFocusLost;
172 }
173
174 void ImfManager::SetRestoreAferFocusLost( bool toggle )
175 {
176   mRestoreAfterFocusLost = toggle;
177 }
178
179 void ImfManager::NotifyCursorPosition()
180 {
181 }
182
183 int ImfManager::GetCursorPosition()
184 {
185   return mIMFCursorPosition;
186 }
187
188 void ImfManager::SetCursorPosition( unsigned int cursorPosition )
189 {
190   mIMFCursorPosition = ( int )cursorPosition;
191 }
192
193 void ImfManager::SetSurroundingText( std::string text )
194 {
195   mSurroundingText = text;
196 }
197
198 std::string ImfManager::GetSurroundingText()
199 {
200   return mSurroundingText;
201 }
202
203 } // Adaptor
204
205 } // Internal
206
207
208 /********************************************************************************/
209 /*********************************  PUBLIC CLASS  *******************************/
210 /********************************************************************************/
211
212 ImfManager::ImfManager()
213 {
214 }
215
216 ImfManager::~ImfManager()
217 {
218 }
219
220 ImfManager ImfManager::Get()
221 {
222   return Internal::Adaptor::ImfManager::Get();
223 }
224
225 ImfContext ImfManager::GetContext()
226 {
227   return NULL;
228 }
229
230 void ImfManager::Activate()
231 {
232   Internal::Adaptor::ImfManager::GetImplementation(*this).Activate();
233 }
234
235 void ImfManager::Deactivate()
236 {
237   Internal::Adaptor::ImfManager::GetImplementation(*this).Deactivate();
238 }
239
240 bool ImfManager::RestoreAfterFocusLost() const
241 {
242   return Internal::Adaptor::ImfManager::GetImplementation(*this).RestoreAfterFocusLost();
243 }
244
245 void ImfManager::SetRestoreAferFocusLost( bool toggle )
246 {
247   Internal::Adaptor::ImfManager::GetImplementation(*this).SetRestoreAferFocusLost( toggle );
248 }
249
250 void ImfManager::Reset()
251 {
252   Internal::Adaptor::ImfManager::GetImplementation(*this).Reset();
253 }
254
255 void ImfManager::NotifyCursorPosition()
256 {
257   Internal::Adaptor::ImfManager::GetImplementation(*this).NotifyCursorPosition();
258 }
259
260 void ImfManager::SetCursorPosition( unsigned int SetCursorPosition )
261 {
262   Internal::Adaptor::ImfManager::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
263 }
264
265 int ImfManager::GetCursorPosition()
266 {
267   return Internal::Adaptor::ImfManager::GetImplementation(*this).GetCursorPosition();
268 }
269
270 void ImfManager::SetSurroundingText( std::string text )
271 {
272   Internal::Adaptor::ImfManager::GetImplementation(*this).SetSurroundingText( text );
273 }
274
275 std::string ImfManager::GetSurroundingText()
276 {
277   return Internal::Adaptor::ImfManager::GetImplementation(*this).GetSurroundingText();
278 }
279
280 ImfManager::ImfManagerSignalV2& ImfManager::ActivatedSignal()
281 {
282   return Internal::Adaptor::ImfManager::GetImplementation(*this).ActivatedSignal();
283 }
284
285 ImfManager::ImfEventSignalV2& ImfManager::EventReceivedSignal()
286 {
287   return Internal::Adaptor::ImfManager::GetImplementation(*this).EventReceivedSignal();
288 }
289
290 ImfManager::ImfManager(Internal::Adaptor::ImfManager *impl)
291   : BaseHandle(impl)
292 {
293 }
294
295 } // namespace Dali