2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "toolkit-input-method-context.h"
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/integration-api/debug.h>
34 class InputMethodContext : public Dali::BaseObject
37 typedef Dali::InputMethodContext::ActivatedSignalType ActivatedSignalType;
38 typedef Dali::InputMethodContext::KeyboardEventSignalType KeyboardEventSignalType;
39 typedef Dali::InputMethodContext::StatusSignalType StatusSignalType;
40 typedef Dali::InputMethodContext::VoidSignalType VoidSignalType;
43 static Dali::InputMethodContext New();
45 InputMethodContext( /* Ecore_X_Window ecoreXwin */ );
47 void ConnectCallbacks();
48 void DisconnectCallbacks();
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;
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; }
73 virtual ~InputMethodContext();
76 void CreateContext( /*Ecore_X_Window ecoreXwin*/ );
81 InputMethodContext( const InputMethodContext& );
82 InputMethodContext& operator=( InputMethodContext& );
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
92 ActivatedSignalType mActivatedSignal;
93 KeyboardEventSignalType mEventSignal;
94 StatusSignalType mKeyboardStatusSignal;
95 VoidSignalType mKeyboardResizeSignal;
96 VoidSignalType mKeyboardLanguageChangedSignal;
98 static Dali::InputMethodContext mToolkitInputMethodContext;
102 inline static Internal::Adaptor::InputMethodContext& GetImplementation(Dali::InputMethodContext& inputMethodContext)
104 BaseObject& handle = inputMethodContext.GetBaseObject();
105 return static_cast<Internal::Adaptor::InputMethodContext&>(handle);
108 inline static const Internal::Adaptor::InputMethodContext& GetImplementation(const Dali::InputMethodContext& inputMethodContext)
110 const BaseObject& handle = inputMethodContext.GetBaseObject();
111 return static_cast<const Internal::Adaptor::InputMethodContext&>(handle);
116 Dali::InputMethodContext Dali::Internal::Adaptor::InputMethodContext::mToolkitInputMethodContext;
118 Dali::InputMethodContext InputMethodContext::New()
120 if( ! mToolkitInputMethodContext )
122 mToolkitInputMethodContext = Dali::InputMethodContext( new Dali::Internal::Adaptor::InputMethodContext() );
124 return mToolkitInputMethodContext;
127 InputMethodContext::InputMethodContext( /*Ecore_X_Window ecoreXwin*/ )
128 : mIMFCursorPosition( 0 ),
130 mRestoreAfterFocusLost( false ),
131 mIdleCallbackConnected( false )
133 CreateContext( /*ecoreXwin*/ );
137 InputMethodContext::~InputMethodContext()
139 DisconnectCallbacks();
143 void InputMethodContext::Finalize()
147 void InputMethodContext::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
151 void InputMethodContext::DeleteContext()
155 // Callbacks for predicitive text support.
156 void InputMethodContext::ConnectCallbacks()
160 void InputMethodContext::DisconnectCallbacks()
164 void InputMethodContext::Activate()
168 void InputMethodContext::Deactivate()
172 void InputMethodContext::Reset()
176 bool InputMethodContext::RestoreAfterFocusLost() const
178 return mRestoreAfterFocusLost;
181 void InputMethodContext::SetRestoreAfterFocusLost( bool toggle )
183 mRestoreAfterFocusLost = toggle;
186 void InputMethodContext::NotifyCursorPosition()
190 void InputMethodContext::SetCursorPosition( unsigned int cursorPosition )
192 mIMFCursorPosition = static_cast< int >( cursorPosition );
195 unsigned int InputMethodContext::GetCursorPosition() const
197 return static_cast<unsigned int>( mIMFCursorPosition );
200 void InputMethodContext::SetSurroundingText( const std::string& text )
202 mSurroundingText = text;
205 const std::string& InputMethodContext::GetSurroundingText() const
207 return mSurroundingText;
210 void InputMethodContext::ApplyOptions( const InputMethodOptions& options )
214 bool InputMethodContext::FilterEventKey( const Dali::KeyEvent& keyEvent )
219 void InputMethodContext::SetPreeditStyle( Dali::InputMethodContext::PreeditStyle type )
221 Dali::InputMethodContext::PreeditAttributeData data;
222 data.preeditType = type;
223 mPreeditAttrs.PushBack( data );
226 void InputMethodContext::GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const
228 attrs = mPreeditAttrs;
235 /********************************************************************************/
236 /********************************* PUBLIC CLASS *******************************/
237 /********************************************************************************/
239 InputMethodContext::InputMethodContext()
243 InputMethodContext::~InputMethodContext()
247 InputMethodContext InputMethodContext::New()
249 return InputMethodContext::New( Actor() );
252 InputMethodContext InputMethodContext::New( Actor actor )
254 return Internal::Adaptor::InputMethodContext::New();
257 void InputMethodContext::Finalize()
259 Internal::Adaptor::InputMethodContext::GetImplementation(*this).Finalize();
262 void InputMethodContext::Activate()
264 Internal::Adaptor::InputMethodContext::GetImplementation(*this).Activate();
267 void InputMethodContext::Deactivate()
269 Internal::Adaptor::InputMethodContext::GetImplementation(*this).Deactivate();
272 bool InputMethodContext::RestoreAfterFocusLost() const
274 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).RestoreAfterFocusLost();
277 void InputMethodContext::SetRestoreAfterFocusLost( bool toggle )
279 Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetRestoreAfterFocusLost( toggle );
282 void InputMethodContext::Reset()
284 Internal::Adaptor::InputMethodContext::GetImplementation(*this).Reset();
287 void InputMethodContext::NotifyCursorPosition()
289 Internal::Adaptor::InputMethodContext::GetImplementation(*this).NotifyCursorPosition();
292 void InputMethodContext::SetCursorPosition( unsigned int SetCursorPosition )
294 Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
297 unsigned int InputMethodContext::GetCursorPosition() const
299 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetCursorPosition();
302 void InputMethodContext::SetSurroundingText( const std::string& text )
304 Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetSurroundingText( text );
307 const std::string& InputMethodContext::GetSurroundingText() const
309 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetSurroundingText();
312 void InputMethodContext::NotifyTextInputMultiLine( bool multiLine )
316 void InputMethodContext::ApplyOptions( const InputMethodOptions& options )
318 Internal::Adaptor::InputMethodContext::GetImplementation(*this).ApplyOptions( options );
321 bool InputMethodContext::FilterEventKey( const Dali::KeyEvent& keyEvent )
323 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).FilterEventKey( keyEvent );
326 void InputMethodContext::SetPreeditStyle( Dali::InputMethodContext::PreeditStyle type )
328 Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetPreeditStyle( type );
331 void InputMethodContext::GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const
333 Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetPreeditStyle( attrs );
337 InputMethodContext::ActivatedSignalType& InputMethodContext::ActivatedSignal()
339 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).ActivatedSignal();
342 InputMethodContext::KeyboardEventSignalType& InputMethodContext::EventReceivedSignal()
344 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).EventReceivedSignal();
347 InputMethodContext::StatusSignalType& InputMethodContext::StatusChangedSignal()
349 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).StatusChangedSignal();
352 InputMethodContext::VoidSignalType& InputMethodContext::ResizedSignal()
354 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).ResizedSignal();
357 InputMethodContext::VoidSignalType& InputMethodContext::LanguageChangedSignal()
359 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).LanguageChangedSignal();
362 InputMethodContext::InputMethodContext(Internal::Adaptor::InputMethodContext *impl)