0aee8ec07e298d90f67aa43e886776cc84390cfe
[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 <dali/public-api/object/base-object.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 namespace Adaptor
31 {
32 class RenderSurface;
33
34
35 class ImfManager : public Dali::BaseObject
36 {
37 public:
38   typedef Dali::ImfManager::ImfManagerSignalType ImfManagerSignalType;
39   typedef Dali::ImfManager::ImfEventSignalType ImfEventSignalType;
40
41 public:
42   static Dali::ImfManager Get();
43
44   ImfManager( /* Ecore_X_Window ecoreXwin */ );
45   void ConnectCallbacks();
46   void DisconnectCallbacks();
47   void Activate();
48   void Deactivate();
49   void Reset();
50
51   bool RestoreAfterFocusLost() const;
52   void SetRestoreAfterFocusLost( bool toggle );
53   void NotifyCursorPosition();
54   int GetCursorPosition();
55   void SetCursorPosition( unsigned int cursorPosition );
56   void SetSurroundingText( std::string text );
57   std::string GetSurroundingText();
58
59 public:  // Signals
60   ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
61   ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
62
63 protected:
64   virtual ~ImfManager();
65
66 private:
67   void CreateContext( /*Ecore_X_Window ecoreXwin*/ );
68   void DeleteContext();
69
70 private:
71   // Undefined
72   ImfManager( const ImfManager& );
73   ImfManager& operator=( ImfManager& );
74
75 private:
76   int mIMFCursorPosition;
77   std::string mSurroundingText;
78   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
79   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
80
81   std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
82   ImfManagerSignalType      mActivatedSignal;
83   ImfEventSignalType        mEventSignal;
84
85
86   static Dali::ImfManager mToolkitImfManager;
87
88 public:
89
90 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
91 {
92   Dali::ImfManager actualImfManager = ImfManager::Get();
93
94   BaseObject& handle = actualImfManager.GetBaseObject();
95   return static_cast<Internal::Adaptor::ImfManager&>(handle);
96 }
97
98 inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
99 {
100   Dali::ImfManager actualImfManager = ImfManager::Get();
101
102   const BaseObject& handle = imfManager.GetBaseObject();
103   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
104 }
105
106 };
107
108 Dali::ImfManager Dali::Internal::Adaptor::ImfManager::mToolkitImfManager;
109
110 Dali::ImfManager ImfManager::Get()
111 {
112   Dali::ImfManager manager;
113
114   if( ! mToolkitImfManager )
115   {
116     mToolkitImfManager = Dali::ImfManager( new Dali::Internal::Adaptor::ImfManager() );
117   }
118   return mToolkitImfManager;
119 }
120
121 ImfManager::ImfManager( /*Ecore_X_Window ecoreXwin*/ )
122 : mIMFCursorPosition( 0 ),
123   mSurroundingText(""),
124   mRestoreAfterFocusLost( false ),
125   mIdleCallbackConnected( false ),
126   mKeyEvents()
127 {
128   CreateContext( /*ecoreXwin*/ );
129   ConnectCallbacks();
130 }
131
132 ImfManager::~ImfManager()
133 {
134   DisconnectCallbacks();
135   DeleteContext();
136 }
137
138 void ImfManager::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
139 {
140 }
141
142 void ImfManager::DeleteContext()
143 {
144 }
145
146 // Callbacks for predicitive text support.
147 void ImfManager::ConnectCallbacks()
148 {
149 }
150
151 void ImfManager::DisconnectCallbacks()
152 {
153 }
154
155 void ImfManager::Activate()
156 {
157 }
158
159 void ImfManager::Deactivate()
160 {
161 }
162
163 void ImfManager::Reset()
164 {
165 }
166
167 bool ImfManager::RestoreAfterFocusLost() const
168 {
169   return mRestoreAfterFocusLost;
170 }
171
172 void ImfManager::SetRestoreAfterFocusLost( bool toggle )
173 {
174   mRestoreAfterFocusLost = toggle;
175 }
176
177 void ImfManager::NotifyCursorPosition()
178 {
179 }
180
181 int ImfManager::GetCursorPosition()
182 {
183   return mIMFCursorPosition;
184 }
185
186 void ImfManager::SetCursorPosition( unsigned int cursorPosition )
187 {
188   mIMFCursorPosition = ( int )cursorPosition;
189 }
190
191 void ImfManager::SetSurroundingText( std::string text )
192 {
193   mSurroundingText = text;
194 }
195
196 std::string ImfManager::GetSurroundingText()
197 {
198   return mSurroundingText;
199 }
200
201 } // Adaptor
202
203 } // Internal
204
205
206 /********************************************************************************/
207 /*********************************  PUBLIC CLASS  *******************************/
208 /********************************************************************************/
209
210 ImfManager::ImfManager()
211 {
212 }
213
214 ImfManager::~ImfManager()
215 {
216 }
217
218 ImfManager ImfManager::Get()
219 {
220   return Internal::Adaptor::ImfManager::Get();
221 }
222
223 ImfContext ImfManager::GetContext()
224 {
225   return NULL;
226 }
227
228 void ImfManager::Activate()
229 {
230   Internal::Adaptor::ImfManager::GetImplementation(*this).Activate();
231 }
232
233 void ImfManager::Deactivate()
234 {
235   Internal::Adaptor::ImfManager::GetImplementation(*this).Deactivate();
236 }
237
238 bool ImfManager::RestoreAfterFocusLost() const
239 {
240   return Internal::Adaptor::ImfManager::GetImplementation(*this).RestoreAfterFocusLost();
241 }
242
243 void ImfManager::SetRestoreAfterFocusLost( bool toggle )
244 {
245   Internal::Adaptor::ImfManager::GetImplementation(*this).SetRestoreAfterFocusLost( toggle );
246 }
247
248 void ImfManager::Reset()
249 {
250   Internal::Adaptor::ImfManager::GetImplementation(*this).Reset();
251 }
252
253 void ImfManager::NotifyCursorPosition()
254 {
255   Internal::Adaptor::ImfManager::GetImplementation(*this).NotifyCursorPosition();
256 }
257
258 void ImfManager::SetCursorPosition( unsigned int SetCursorPosition )
259 {
260   Internal::Adaptor::ImfManager::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
261 }
262
263 int ImfManager::GetCursorPosition()
264 {
265   return Internal::Adaptor::ImfManager::GetImplementation(*this).GetCursorPosition();
266 }
267
268 void ImfManager::SetSurroundingText( std::string text )
269 {
270   Internal::Adaptor::ImfManager::GetImplementation(*this).SetSurroundingText( text );
271 }
272
273 std::string ImfManager::GetSurroundingText()
274 {
275   return Internal::Adaptor::ImfManager::GetImplementation(*this).GetSurroundingText();
276 }
277
278 ImfManager::ImfManagerSignalType& ImfManager::ActivatedSignal()
279 {
280   return Internal::Adaptor::ImfManager::GetImplementation(*this).ActivatedSignal();
281 }
282
283 ImfManager::ImfEventSignalType& ImfManager::EventReceivedSignal()
284 {
285   return Internal::Adaptor::ImfManager::GetImplementation(*this).EventReceivedSignal();
286 }
287
288 ImfManager::ImfManager(Internal::Adaptor::ImfManager *impl)
289   : BaseHandle(impl)
290 {
291 }
292
293 } // namespace Dali