Fix InputMethodContext to work well in multi-window env
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-input-method-context.cpp
1 /*
2  * Copyright (c) 2018 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-input-method-context.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/integration-api/debug.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29 namespace Adaptor
30 {
31 class RenderSurface;
32
33
34 class InputMethodContext : public Dali::BaseObject
35 {
36 public:
37   typedef Dali::InputMethodContext::ActivatedSignalType ActivatedSignalType;
38   typedef Dali::InputMethodContext::KeyboardEventSignalType KeyboardEventSignalType;
39   typedef Dali::InputMethodContext::StatusSignalType StatusSignalType;
40   typedef Dali::InputMethodContext::VoidSignalType VoidSignalType;
41
42 public:
43   static Dali::InputMethodContext New();
44
45   InputMethodContext( /* Ecore_X_Window ecoreXwin */ );
46   void Finalize();
47   void ConnectCallbacks();
48   void DisconnectCallbacks();
49   void Activate();
50   void Deactivate();
51   void Reset();
52
53   bool RestoreAfterFocusLost() const;
54   void SetRestoreAfterFocusLost( bool toggle );
55   void NotifyCursorPosition();
56   void SetCursorPosition( unsigned int cursorPosition );
57   unsigned int GetCursorPosition() const;
58   void SetSurroundingText( const std::string& text );
59   const std::string& GetSurroundingText() const;
60   void ApplyOptions( const InputMethodOptions& options );
61   bool FilterEventKey( const Dali::KeyEvent& keyEvent );
62
63 public:  // Signals
64   ActivatedSignalType& ActivatedSignal() { return mActivatedSignal; }
65   KeyboardEventSignalType& EventReceivedSignal() { return mEventSignal; }
66   StatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
67   VoidSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
68   VoidSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
69
70 protected:
71   virtual ~InputMethodContext();
72
73 private:
74   void CreateContext( /*Ecore_X_Window ecoreXwin*/ );
75   void DeleteContext();
76
77 private:
78   // Undefined
79   InputMethodContext( const InputMethodContext& );
80   InputMethodContext& operator=( InputMethodContext& );
81
82 private:
83   int mIMFCursorPosition;
84   std::string mSurroundingText;
85   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
86   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
87   InputMethodOptions        mOptions;
88
89   ActivatedSignalType      mActivatedSignal;
90   KeyboardEventSignalType  mEventSignal;
91   StatusSignalType         mKeyboardStatusSignal;
92   VoidSignalType           mKeyboardResizeSignal;
93   VoidSignalType           mKeyboardLanguageChangedSignal;
94
95   static Dali::InputMethodContext mToolkitInputMethodContext;
96
97 public:
98
99 inline static Internal::Adaptor::InputMethodContext& GetImplementation(Dali::InputMethodContext& inputMethodContext)
100 {
101   BaseObject& handle = inputMethodContext.GetBaseObject();
102   return static_cast<Internal::Adaptor::InputMethodContext&>(handle);
103 }
104
105 inline static const  Internal::Adaptor::InputMethodContext& GetImplementation(const Dali::InputMethodContext& inputMethodContext)
106 {
107   const BaseObject& handle = inputMethodContext.GetBaseObject();
108   return static_cast<const Internal::Adaptor::InputMethodContext&>(handle);
109 }
110
111 };
112
113 Dali::InputMethodContext Dali::Internal::Adaptor::InputMethodContext::mToolkitInputMethodContext;
114
115 Dali::InputMethodContext InputMethodContext::New()
116 {
117   if( ! mToolkitInputMethodContext )
118   {
119     mToolkitInputMethodContext = Dali::InputMethodContext( new Dali::Internal::Adaptor::InputMethodContext() );
120   }
121   return mToolkitInputMethodContext;
122 }
123
124 InputMethodContext::InputMethodContext( /*Ecore_X_Window ecoreXwin*/ )
125 : mIMFCursorPosition( 0 ),
126   mSurroundingText(),
127   mRestoreAfterFocusLost( false ),
128   mIdleCallbackConnected( false )
129 {
130   CreateContext( /*ecoreXwin*/ );
131   ConnectCallbacks();
132 }
133
134 InputMethodContext::~InputMethodContext()
135 {
136   DisconnectCallbacks();
137   DeleteContext();
138 }
139
140 void InputMethodContext::Finalize()
141 {
142 }
143
144 void InputMethodContext::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
145 {
146 }
147
148 void InputMethodContext::DeleteContext()
149 {
150 }
151
152 // Callbacks for predicitive text support.
153 void InputMethodContext::ConnectCallbacks()
154 {
155 }
156
157 void InputMethodContext::DisconnectCallbacks()
158 {
159 }
160
161 void InputMethodContext::Activate()
162 {
163 }
164
165 void InputMethodContext::Deactivate()
166 {
167 }
168
169 void InputMethodContext::Reset()
170 {
171 }
172
173 bool InputMethodContext::RestoreAfterFocusLost() const
174 {
175   return mRestoreAfterFocusLost;
176 }
177
178 void InputMethodContext::SetRestoreAfterFocusLost( bool toggle )
179 {
180   mRestoreAfterFocusLost = toggle;
181 }
182
183 void InputMethodContext::NotifyCursorPosition()
184 {
185 }
186
187 void InputMethodContext::SetCursorPosition( unsigned int cursorPosition )
188 {
189   mIMFCursorPosition = static_cast< int >( cursorPosition );
190 }
191
192 unsigned int InputMethodContext::GetCursorPosition() const
193 {
194   return static_cast<unsigned int>( mIMFCursorPosition );
195 }
196
197 void InputMethodContext::SetSurroundingText( const std::string& text )
198 {
199   mSurroundingText = text;
200 }
201
202 const std::string& InputMethodContext::GetSurroundingText() const
203 {
204   return mSurroundingText;
205 }
206
207 void InputMethodContext::ApplyOptions( const InputMethodOptions& options )
208 {
209 }
210
211 bool InputMethodContext::FilterEventKey( const Dali::KeyEvent& keyEvent )
212 {
213   return false;
214 }
215 } // Adaptor
216
217 } // Internal
218
219
220 /********************************************************************************/
221 /*********************************  PUBLIC CLASS  *******************************/
222 /********************************************************************************/
223
224 InputMethodContext::InputMethodContext()
225 {
226 }
227
228 InputMethodContext::~InputMethodContext()
229 {
230 }
231
232 InputMethodContext InputMethodContext::New()
233 {
234   return InputMethodContext::New( Actor() );
235 }
236
237 InputMethodContext InputMethodContext::New( Actor actor )
238 {
239   return Internal::Adaptor::InputMethodContext::New();
240 }
241
242 void InputMethodContext::Finalize()
243 {
244   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Finalize();
245 }
246
247 void InputMethodContext::Activate()
248 {
249   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Activate();
250 }
251
252 void InputMethodContext::Deactivate()
253 {
254   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Deactivate();
255 }
256
257 bool InputMethodContext::RestoreAfterFocusLost() const
258 {
259   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).RestoreAfterFocusLost();
260 }
261
262 void InputMethodContext::SetRestoreAfterFocusLost( bool toggle )
263 {
264   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetRestoreAfterFocusLost( toggle );
265 }
266
267 void InputMethodContext::Reset()
268 {
269   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Reset();
270 }
271
272 void InputMethodContext::NotifyCursorPosition()
273 {
274   Internal::Adaptor::InputMethodContext::GetImplementation(*this).NotifyCursorPosition();
275 }
276
277 void InputMethodContext::SetCursorPosition( unsigned int SetCursorPosition )
278 {
279   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
280 }
281
282 unsigned int InputMethodContext::GetCursorPosition() const
283 {
284   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetCursorPosition();
285 }
286
287 void InputMethodContext::SetSurroundingText( const std::string& text )
288 {
289   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetSurroundingText( text );
290 }
291
292 const std::string& InputMethodContext::GetSurroundingText() const
293 {
294   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetSurroundingText();
295 }
296
297 void InputMethodContext::NotifyTextInputMultiLine( bool multiLine )
298 {
299 }
300
301 void InputMethodContext::ApplyOptions( const InputMethodOptions& options )
302 {
303   Internal::Adaptor::InputMethodContext::GetImplementation(*this).ApplyOptions( options );
304 }
305
306 bool InputMethodContext::FilterEventKey( const Dali::KeyEvent& keyEvent )
307 {
308   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).FilterEventKey( keyEvent );
309 }
310
311 InputMethodContext::ActivatedSignalType& InputMethodContext::ActivatedSignal()
312 {
313   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).ActivatedSignal();
314 }
315
316 InputMethodContext::KeyboardEventSignalType& InputMethodContext::EventReceivedSignal()
317 {
318   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).EventReceivedSignal();
319 }
320
321 InputMethodContext::StatusSignalType& InputMethodContext::StatusChangedSignal()
322 {
323   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).StatusChangedSignal();
324 }
325
326 InputMethodContext::VoidSignalType& InputMethodContext::ResizedSignal()
327 {
328   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).ResizedSignal();
329 }
330
331 InputMethodContext::VoidSignalType& InputMethodContext::LanguageChangedSignal()
332 {
333   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).LanguageChangedSignal();
334 }
335
336 InputMethodContext::InputMethodContext(Internal::Adaptor::InputMethodContext *impl)
337   : BaseHandle(impl)
338 {
339 }
340
341 } // namespace Dali