2 * Copyright (c) 2018 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 );
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; }
71 virtual ~InputMethodContext();
74 void CreateContext( /*Ecore_X_Window ecoreXwin*/ );
79 InputMethodContext( const InputMethodContext& );
80 InputMethodContext& operator=( InputMethodContext& );
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;
89 ActivatedSignalType mActivatedSignal;
90 KeyboardEventSignalType mEventSignal;
91 StatusSignalType mKeyboardStatusSignal;
92 VoidSignalType mKeyboardResizeSignal;
93 VoidSignalType mKeyboardLanguageChangedSignal;
95 static Dali::InputMethodContext mToolkitInputMethodContext;
99 inline static Internal::Adaptor::InputMethodContext& GetImplementation(Dali::InputMethodContext& inputMethodContext)
101 BaseObject& handle = inputMethodContext.GetBaseObject();
102 return static_cast<Internal::Adaptor::InputMethodContext&>(handle);
105 inline static const Internal::Adaptor::InputMethodContext& GetImplementation(const Dali::InputMethodContext& inputMethodContext)
107 const BaseObject& handle = inputMethodContext.GetBaseObject();
108 return static_cast<const Internal::Adaptor::InputMethodContext&>(handle);
113 Dali::InputMethodContext Dali::Internal::Adaptor::InputMethodContext::mToolkitInputMethodContext;
115 Dali::InputMethodContext InputMethodContext::New()
117 if( ! mToolkitInputMethodContext )
119 mToolkitInputMethodContext = Dali::InputMethodContext( new Dali::Internal::Adaptor::InputMethodContext() );
121 return mToolkitInputMethodContext;
124 InputMethodContext::InputMethodContext( /*Ecore_X_Window ecoreXwin*/ )
125 : mIMFCursorPosition( 0 ),
127 mRestoreAfterFocusLost( false ),
128 mIdleCallbackConnected( false )
130 CreateContext( /*ecoreXwin*/ );
134 InputMethodContext::~InputMethodContext()
136 DisconnectCallbacks();
140 void InputMethodContext::Finalize()
144 void InputMethodContext::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
148 void InputMethodContext::DeleteContext()
152 // Callbacks for predicitive text support.
153 void InputMethodContext::ConnectCallbacks()
157 void InputMethodContext::DisconnectCallbacks()
161 void InputMethodContext::Activate()
165 void InputMethodContext::Deactivate()
169 void InputMethodContext::Reset()
173 bool InputMethodContext::RestoreAfterFocusLost() const
175 return mRestoreAfterFocusLost;
178 void InputMethodContext::SetRestoreAfterFocusLost( bool toggle )
180 mRestoreAfterFocusLost = toggle;
183 void InputMethodContext::NotifyCursorPosition()
187 void InputMethodContext::SetCursorPosition( unsigned int cursorPosition )
189 mIMFCursorPosition = static_cast< int >( cursorPosition );
192 unsigned int InputMethodContext::GetCursorPosition() const
194 return static_cast<unsigned int>( mIMFCursorPosition );
197 void InputMethodContext::SetSurroundingText( const std::string& text )
199 mSurroundingText = text;
202 const std::string& InputMethodContext::GetSurroundingText() const
204 return mSurroundingText;
207 void InputMethodContext::ApplyOptions( const InputMethodOptions& options )
211 bool InputMethodContext::FilterEventKey( const Dali::KeyEvent& keyEvent )
220 /********************************************************************************/
221 /********************************* PUBLIC CLASS *******************************/
222 /********************************************************************************/
224 InputMethodContext::InputMethodContext()
228 InputMethodContext::~InputMethodContext()
232 InputMethodContext InputMethodContext::New()
234 return Internal::Adaptor::InputMethodContext::New();
237 void InputMethodContext::Finalize()
239 Internal::Adaptor::InputMethodContext::GetImplementation(*this).Finalize();
242 void InputMethodContext::Activate()
244 Internal::Adaptor::InputMethodContext::GetImplementation(*this).Activate();
247 void InputMethodContext::Deactivate()
249 Internal::Adaptor::InputMethodContext::GetImplementation(*this).Deactivate();
252 bool InputMethodContext::RestoreAfterFocusLost() const
254 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).RestoreAfterFocusLost();
257 void InputMethodContext::SetRestoreAfterFocusLost( bool toggle )
259 Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetRestoreAfterFocusLost( toggle );
262 void InputMethodContext::Reset()
264 Internal::Adaptor::InputMethodContext::GetImplementation(*this).Reset();
267 void InputMethodContext::NotifyCursorPosition()
269 Internal::Adaptor::InputMethodContext::GetImplementation(*this).NotifyCursorPosition();
272 void InputMethodContext::SetCursorPosition( unsigned int SetCursorPosition )
274 Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
277 unsigned int InputMethodContext::GetCursorPosition() const
279 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetCursorPosition();
282 void InputMethodContext::SetSurroundingText( const std::string& text )
284 Internal::Adaptor::InputMethodContext::GetImplementation(*this).SetSurroundingText( text );
287 const std::string& InputMethodContext::GetSurroundingText() const
289 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).GetSurroundingText();
292 void InputMethodContext::NotifyTextInputMultiLine( bool multiLine )
296 void InputMethodContext::ApplyOptions( const InputMethodOptions& options )
298 Internal::Adaptor::InputMethodContext::GetImplementation(*this).ApplyOptions( options );
301 bool InputMethodContext::FilterEventKey( const Dali::KeyEvent& keyEvent )
303 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).FilterEventKey( keyEvent );
306 InputMethodContext::ActivatedSignalType& InputMethodContext::ActivatedSignal()
308 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).ActivatedSignal();
311 InputMethodContext::KeyboardEventSignalType& InputMethodContext::EventReceivedSignal()
313 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).EventReceivedSignal();
316 InputMethodContext::StatusSignalType& InputMethodContext::StatusChangedSignal()
318 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).StatusChangedSignal();
321 InputMethodContext::VoidSignalType& InputMethodContext::ResizedSignal()
323 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).ResizedSignal();
326 InputMethodContext::VoidSignalType& InputMethodContext::LanguageChangedSignal()
328 return Internal::Adaptor::InputMethodContext::GetImplementation(*this).LanguageChangedSignal();
331 InputMethodContext::InputMethodContext(Internal::Adaptor::InputMethodContext *impl)