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