[dali_1.4.54] Merge branch 'devel/master'
[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   void SetPreeditStyle( Dali::InputMethodContext::PreeditStyle type );
63   Dali::InputMethodContext::PreeditStyle GetPreeditStyle() const;
64
65 public:  // Signals
66   ActivatedSignalType& ActivatedSignal() { return mActivatedSignal; }
67   KeyboardEventSignalType& EventReceivedSignal() { return mEventSignal; }
68   StatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
69   VoidSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
70   VoidSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
71
72 protected:
73   virtual ~InputMethodContext();
74
75 private:
76   void CreateContext( /*Ecore_X_Window ecoreXwin*/ );
77   void DeleteContext();
78
79 private:
80   // Undefined
81   InputMethodContext( const InputMethodContext& );
82   InputMethodContext& operator=( InputMethodContext& );
83
84 private:
85   int mIMFCursorPosition;
86   std::string mSurroundingText;
87   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
88   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
89   InputMethodOptions        mOptions;
90   Dali::InputMethodContext::PreeditStyle mPreeditStyle;
91
92   ActivatedSignalType      mActivatedSignal;
93   KeyboardEventSignalType  mEventSignal;
94   StatusSignalType         mKeyboardStatusSignal;
95   VoidSignalType           mKeyboardResizeSignal;
96   VoidSignalType           mKeyboardLanguageChangedSignal;
97
98   static Dali::InputMethodContext mToolkitInputMethodContext;
99
100 public:
101
102 inline static Internal::Adaptor::InputMethodContext& GetImplementation(Dali::InputMethodContext& inputMethodContext)
103 {
104   BaseObject& handle = inputMethodContext.GetBaseObject();
105   return static_cast<Internal::Adaptor::InputMethodContext&>(handle);
106 }
107
108 inline static const  Internal::Adaptor::InputMethodContext& GetImplementation(const Dali::InputMethodContext& inputMethodContext)
109 {
110   const BaseObject& handle = inputMethodContext.GetBaseObject();
111   return static_cast<const Internal::Adaptor::InputMethodContext&>(handle);
112 }
113
114 };
115
116 Dali::InputMethodContext Dali::Internal::Adaptor::InputMethodContext::mToolkitInputMethodContext;
117
118 Dali::InputMethodContext InputMethodContext::New()
119 {
120   if( ! mToolkitInputMethodContext )
121   {
122     mToolkitInputMethodContext = Dali::InputMethodContext( new Dali::Internal::Adaptor::InputMethodContext() );
123   }
124   return mToolkitInputMethodContext;
125 }
126
127 InputMethodContext::InputMethodContext( /*Ecore_X_Window ecoreXwin*/ )
128 : mIMFCursorPosition( 0 ),
129   mSurroundingText(),
130   mRestoreAfterFocusLost( false ),
131   mIdleCallbackConnected( false ),
132   mPreeditStyle( Dali::InputMethodContext::PreeditStyle::NONE )
133 {
134   CreateContext( /*ecoreXwin*/ );
135   ConnectCallbacks();
136 }
137
138 InputMethodContext::~InputMethodContext()
139 {
140   DisconnectCallbacks();
141   DeleteContext();
142 }
143
144 void InputMethodContext::Finalize()
145 {
146 }
147
148 void InputMethodContext::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
149 {
150 }
151
152 void InputMethodContext::DeleteContext()
153 {
154 }
155
156 // Callbacks for predicitive text support.
157 void InputMethodContext::ConnectCallbacks()
158 {
159 }
160
161 void InputMethodContext::DisconnectCallbacks()
162 {
163 }
164
165 void InputMethodContext::Activate()
166 {
167 }
168
169 void InputMethodContext::Deactivate()
170 {
171 }
172
173 void InputMethodContext::Reset()
174 {
175 }
176
177 bool InputMethodContext::RestoreAfterFocusLost() const
178 {
179   return mRestoreAfterFocusLost;
180 }
181
182 void InputMethodContext::SetRestoreAfterFocusLost( bool toggle )
183 {
184   mRestoreAfterFocusLost = toggle;
185 }
186
187 void InputMethodContext::NotifyCursorPosition()
188 {
189 }
190
191 void InputMethodContext::SetCursorPosition( unsigned int cursorPosition )
192 {
193   mIMFCursorPosition = static_cast< int >( cursorPosition );
194 }
195
196 unsigned int InputMethodContext::GetCursorPosition() const
197 {
198   return static_cast<unsigned int>( mIMFCursorPosition );
199 }
200
201 void InputMethodContext::SetSurroundingText( const std::string& text )
202 {
203   mSurroundingText = text;
204 }
205
206 const std::string& InputMethodContext::GetSurroundingText() const
207 {
208   return mSurroundingText;
209 }
210
211 void InputMethodContext::ApplyOptions( const InputMethodOptions& options )
212 {
213 }
214
215 bool InputMethodContext::FilterEventKey( const Dali::KeyEvent& keyEvent )
216 {
217   return false;
218 }
219
220 void InputMethodContext::SetPreeditStyle( Dali::InputMethodContext::PreeditStyle type )
221 {
222   mPreeditStyle = type;
223 }
224
225 Dali::InputMethodContext::PreeditStyle InputMethodContext::GetPreeditStyle() const
226 {
227   return mPreeditStyle;
228 }
229 } // Adaptor
230
231 } // Internal
232
233
234 /********************************************************************************/
235 /*********************************  PUBLIC CLASS  *******************************/
236 /********************************************************************************/
237
238 InputMethodContext::InputMethodContext()
239 {
240 }
241
242 InputMethodContext::~InputMethodContext()
243 {
244 }
245
246 InputMethodContext InputMethodContext::New()
247 {
248   return InputMethodContext::New( Actor() );
249 }
250
251 InputMethodContext InputMethodContext::New( Actor actor )
252 {
253   return Internal::Adaptor::InputMethodContext::New();
254 }
255
256 void InputMethodContext::Finalize()
257 {
258   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Finalize();
259 }
260
261 void InputMethodContext::Activate()
262 {
263   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Activate();
264 }
265
266 void InputMethodContext::Deactivate()
267 {
268   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Deactivate();
269 }
270
271 bool InputMethodContext::RestoreAfterFocusLost() const
272 {
273   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).RestoreAfterFocusLost();
274 }
275
276 void InputMethodContext::SetRestoreAfterFocusLost( bool toggle )
277 {
278   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetRestoreAfterFocusLost( toggle );
279 }
280
281 void InputMethodContext::Reset()
282 {
283   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Reset();
284 }
285
286 void InputMethodContext::NotifyCursorPosition()
287 {
288   Internal::Adaptor::InputMethodContext::GetImplementation(*this).NotifyCursorPosition();
289 }
290
291 void InputMethodContext::SetCursorPosition( unsigned int SetCursorPosition )
292 {
293   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
294 }
295
296 unsigned int InputMethodContext::GetCursorPosition() const
297 {
298   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetCursorPosition();
299 }
300
301 void InputMethodContext::SetSurroundingText( const std::string& text )
302 {
303   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetSurroundingText( text );
304 }
305
306 const std::string& InputMethodContext::GetSurroundingText() const
307 {
308   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetSurroundingText();
309 }
310
311 void InputMethodContext::NotifyTextInputMultiLine( bool multiLine )
312 {
313 }
314
315 void InputMethodContext::ApplyOptions( const InputMethodOptions& options )
316 {
317   Internal::Adaptor::InputMethodContext::GetImplementation(*this).ApplyOptions( options );
318 }
319
320 bool InputMethodContext::FilterEventKey( const Dali::KeyEvent& keyEvent )
321 {
322   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).FilterEventKey( keyEvent );
323 }
324
325 void InputMethodContext::SetPreeditStyle( Dali::InputMethodContext::PreeditStyle type )
326 {
327   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetPreeditStyle( type );
328 }
329
330 Dali::InputMethodContext::PreeditStyle InputMethodContext::GetPreeditStyle() const
331 {
332   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetPreeditStyle();
333 }
334
335 // Signals
336 InputMethodContext::ActivatedSignalType& InputMethodContext::ActivatedSignal()
337 {
338   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).ActivatedSignal();
339 }
340
341 InputMethodContext::KeyboardEventSignalType& InputMethodContext::EventReceivedSignal()
342 {
343   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).EventReceivedSignal();
344 }
345
346 InputMethodContext::StatusSignalType& InputMethodContext::StatusChangedSignal()
347 {
348   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).StatusChangedSignal();
349 }
350
351 InputMethodContext::VoidSignalType& InputMethodContext::ResizedSignal()
352 {
353   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).ResizedSignal();
354 }
355
356 InputMethodContext::VoidSignalType& InputMethodContext::LanguageChangedSignal()
357 {
358   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).LanguageChangedSignal();
359 }
360
361 InputMethodContext::InputMethodContext(Internal::Adaptor::InputMethodContext *impl)
362   : BaseHandle(impl)
363 {
364 }
365
366 } // namespace Dali