Fixed SVACE errors in Test Graphics
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-input-method-context.cpp
1 /*
2  * Copyright (c) 2019 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   void GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) 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::PreEditAttributeDataContainer mPreeditAttrs; ///< Stores preedit attribute data
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 {
133   CreateContext( /*ecoreXwin*/ );
134   ConnectCallbacks();
135 }
136
137 InputMethodContext::~InputMethodContext()
138 {
139   DisconnectCallbacks();
140   DeleteContext();
141 }
142
143 void InputMethodContext::Finalize()
144 {
145 }
146
147 void InputMethodContext::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
148 {
149 }
150
151 void InputMethodContext::DeleteContext()
152 {
153 }
154
155 // Callbacks for predicitive text support.
156 void InputMethodContext::ConnectCallbacks()
157 {
158 }
159
160 void InputMethodContext::DisconnectCallbacks()
161 {
162 }
163
164 void InputMethodContext::Activate()
165 {
166 }
167
168 void InputMethodContext::Deactivate()
169 {
170 }
171
172 void InputMethodContext::Reset()
173 {
174 }
175
176 bool InputMethodContext::RestoreAfterFocusLost() const
177 {
178   return mRestoreAfterFocusLost;
179 }
180
181 void InputMethodContext::SetRestoreAfterFocusLost( bool toggle )
182 {
183   mRestoreAfterFocusLost = toggle;
184 }
185
186 void InputMethodContext::NotifyCursorPosition()
187 {
188 }
189
190 void InputMethodContext::SetCursorPosition( unsigned int cursorPosition )
191 {
192   mIMFCursorPosition = static_cast< int >( cursorPosition );
193 }
194
195 unsigned int InputMethodContext::GetCursorPosition() const
196 {
197   return static_cast<unsigned int>( mIMFCursorPosition );
198 }
199
200 void InputMethodContext::SetSurroundingText( const std::string& text )
201 {
202   mSurroundingText = text;
203 }
204
205 const std::string& InputMethodContext::GetSurroundingText() const
206 {
207   return mSurroundingText;
208 }
209
210 void InputMethodContext::ApplyOptions( const InputMethodOptions& options )
211 {
212 }
213
214 bool InputMethodContext::FilterEventKey( const Dali::KeyEvent& keyEvent )
215 {
216   return false;
217 }
218
219 void InputMethodContext::SetPreeditStyle( Dali::InputMethodContext::PreeditStyle type )
220 {
221   Dali::InputMethodContext::PreeditAttributeData data;
222   data.preeditType = type;
223   mPreeditAttrs.PushBack( data );
224 }
225
226 void InputMethodContext::GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const
227 {
228   attrs = mPreeditAttrs;
229 }
230 } // Adaptor
231
232 } // Internal
233
234
235 /********************************************************************************/
236 /*********************************  PUBLIC CLASS  *******************************/
237 /********************************************************************************/
238
239 InputMethodContext::InputMethodContext()
240 {
241 }
242
243 InputMethodContext::~InputMethodContext()
244 {
245 }
246
247 InputMethodContext InputMethodContext::New()
248 {
249   return InputMethodContext::New( Actor() );
250 }
251
252 InputMethodContext InputMethodContext::New( Actor actor )
253 {
254   return Internal::Adaptor::InputMethodContext::New();
255 }
256
257 void InputMethodContext::Finalize()
258 {
259   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Finalize();
260 }
261
262 void InputMethodContext::Activate()
263 {
264   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Activate();
265 }
266
267 void InputMethodContext::Deactivate()
268 {
269   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Deactivate();
270 }
271
272 bool InputMethodContext::RestoreAfterFocusLost() const
273 {
274   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).RestoreAfterFocusLost();
275 }
276
277 void InputMethodContext::SetRestoreAfterFocusLost( bool toggle )
278 {
279   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetRestoreAfterFocusLost( toggle );
280 }
281
282 void InputMethodContext::Reset()
283 {
284   Internal::Adaptor::InputMethodContext::GetImplementation(*this).Reset();
285 }
286
287 void InputMethodContext::NotifyCursorPosition()
288 {
289   Internal::Adaptor::InputMethodContext::GetImplementation(*this).NotifyCursorPosition();
290 }
291
292 void InputMethodContext::SetCursorPosition( unsigned int SetCursorPosition )
293 {
294   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
295 }
296
297 unsigned int InputMethodContext::GetCursorPosition() const
298 {
299   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetCursorPosition();
300 }
301
302 void InputMethodContext::SetSurroundingText( const std::string& text )
303 {
304   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetSurroundingText( text );
305 }
306
307 const std::string& InputMethodContext::GetSurroundingText() const
308 {
309   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetSurroundingText();
310 }
311
312 void InputMethodContext::NotifyTextInputMultiLine( bool multiLine )
313 {
314 }
315
316 void InputMethodContext::ApplyOptions( const InputMethodOptions& options )
317 {
318   Internal::Adaptor::InputMethodContext::GetImplementation(*this).ApplyOptions( options );
319 }
320
321 bool InputMethodContext::FilterEventKey( const Dali::KeyEvent& keyEvent )
322 {
323   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).FilterEventKey( keyEvent );
324 }
325
326 void InputMethodContext::SetPreeditStyle( Dali::InputMethodContext::PreeditStyle type )
327 {
328   Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetPreeditStyle( type );
329 }
330
331 void InputMethodContext::GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const
332 {
333   Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetPreeditStyle( attrs );
334 }
335
336 // Signals
337 InputMethodContext::ActivatedSignalType& InputMethodContext::ActivatedSignal()
338 {
339   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).ActivatedSignal();
340 }
341
342 InputMethodContext::KeyboardEventSignalType& InputMethodContext::EventReceivedSignal()
343 {
344   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).EventReceivedSignal();
345 }
346
347 InputMethodContext::StatusSignalType& InputMethodContext::StatusChangedSignal()
348 {
349   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).StatusChangedSignal();
350 }
351
352 InputMethodContext::VoidSignalType& InputMethodContext::ResizedSignal()
353 {
354   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).ResizedSignal();
355 }
356
357 InputMethodContext::VoidSignalType& InputMethodContext::LanguageChangedSignal()
358 {
359   return Internal::Adaptor::InputMethodContext::GetImplementation(*this).LanguageChangedSignal();
360 }
361
362 InputMethodContext::InputMethodContext(Internal::Adaptor::InputMethodContext *impl)
363   : BaseHandle(impl)
364 {
365 }
366
367 } // namespace Dali