1 #ifndef __DALI_INTERNAL_IMF_MANAGER_WL_H
2 #define __DALI_INTERNAL_IMF_MANAGER_WL_H
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/integration-api/events/key-event-integ.h>
27 #include <imf-manager.h>
28 #include "../text-input-manager.h"
44 * Handles text input editing with the virtual keyboard.
45 * The Tizen 3 Wayland text interface is still in development so some
46 * features are not available to test like text prediction.
47 * When this available we may need to add / test wl_text_input_commit_state
49 * To debug low level communication to the Wayland Compositor (Enlightenment) use environment variable
50 * export WAYLAND_DEBUG=1
53 class ImfManager : public Dali::BaseObject, public ConnectionTracker
56 typedef Dali::ImfManager::ImfManagerSignalType ImfManagerSignalType;
57 typedef Dali::ImfManager::ImfEventSignalType ImfEventSignalType;
58 typedef Dali::ImfManager::StatusSignalType ImfStatusSignalType;
59 typedef Dali::ImfManager::VoidSignalType ImfVoidSignalType;
60 typedef Dali::ImfManager::KeyboardTypeSignalType ImfKeyboardTypeSignalType;
65 * @brief Check whether the ImfManager is available.
66 * @return true if available, false otherwise
68 static bool IsAvailable();
71 * @brief Get the IMF manager instance
72 * It creates the instance if it has not already been created.
73 * Internally, a check should be made using IsAvailable() before this is called as we do not want
74 * to create an instance if not needed by applications.
76 * @return handle to ImfManager
78 static Dali::ImfManager Get();
86 * Connect Callbacks required for IMF.
87 * If you don't connect imf callbacks, you can't get the key events.
88 * The events are PreeditChanged, Commit and DeleteSurrounding.
90 void ConnectCallbacks();
93 * @brief Disconnect Callbacks attached to imf context.
95 void DisconnectCallbacks();
98 * @copydoc Dali::ImfManager::Activate()
103 * @copydoc Dali::ImfManager::Deactivate()
108 * @copydoc Dali::ImfManager::Reset()
113 * @copydoc Dali::ImfManager::GetContext()
118 * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
120 bool RestoreAfterFocusLost() const;
123 * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
125 void SetRestoreAfterFocusLost( bool toggle );
130 * @copydoc Dali::ImfManager::NotifyCursorPosition()
132 void NotifyCursorPosition();
135 * @copydoc Dali::ImfManager::SetCursorPosition()
137 void SetCursorPosition( unsigned int cursorPosition );
140 * @copydoc Dali::ImfManager::GetCursorPosition()
142 unsigned int GetCursorPosition() const;
145 * @copydoc Dali::ImfManager::SetSurroundingText()
147 void SetSurroundingText( const std::string& text );
150 * @copydoc Dali::ImfManager::GetSurroundingText()
152 const std::string& GetSurroundingText() const;
155 * @copydoc Dali::ImfManager::NotifyTextInputMultiLine()
157 void NotifyTextInputMultiLine( bool multiLine );
160 * @copydoc Dali::ImfManager::GetTextDirection()
162 Dali::ImfManager::TextDirection GetTextDirection();
165 * @copydoc Dali::ImfManager::GetInputMethodArea()
167 Dali::Rect<int> GetInputMethodArea();
170 * @copydoc Dali::ImfManager::ApplyOptions()
172 void ApplyOptions( const InputMethodOptions& options );
175 * @copydoc Dali::ImfManager::SetInputPanelUserData()
177 void SetInputPanelUserData( const std::string& data );
180 * @copydoc Dali::ImfManager::GetInputPanelUserData()
182 void GetInputPanelUserData( std::string& data );
185 * @copydoc Dali::ImfManager::GetInputPanelState()
187 Dali::ImfManager::State GetInputPanelState();
190 * @copydoc Dali::ImfManager::SetReturnKeyState()
192 void SetReturnKeyState( bool visible );
195 * @copydoc Dali::ImfManager::AutoEnableInputPanel()
197 void AutoEnableInputPanel( bool enabled );
200 * @copydoc Dali::ImfManager::ShowInputPanel()
202 void ShowInputPanel();
205 * @copydoc Dali::ImfManager::HideInputPanel()
207 void HideInputPanel();
210 * @copydoc Dali::ImfManager::GetKeyboardType()
212 Dali::ImfManager::KeyboardType GetKeyboardType();
215 * @copydoc Dali::ImfManager::GetInputPanelLocale()
217 std::string GetInputPanelLocale();
222 * @copydoc Dali::ImfManager::ActivatedSignal()
224 ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
227 * @copydoc Dali::ImfManager::EventReceivedSignal()
229 ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
232 * @copydoc Dali::ImfManager::StatusChangedSignal()
234 ImfStatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
237 * @copydoc Dali::ImfManager::ResizedSignal()
239 ImfVoidSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
242 * @copydoc Dali::ImfManager::LanguageChangedSignal()
244 ImfVoidSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
247 * @copydoc Dali::ImfManager::KeyboardTypeChangedSignal()
249 ImfKeyboardTypeSignalType& KeyboardTypeChangedSignal() { return mKeyboardTypeChangedSignal; }
252 * @brief Called when an IMF Pre-Edit change event is received.
253 * We are still predicting what the user is typing. The latest string is what the IMF module thinks
254 * the user wants to type.
256 * @param[in] serial event serial
257 * @param[in] text pre-edit string
258 * @param[in] commit commit string
260 void PreEditStringChange( unsigned int serial, const std::string text, const std::string commit );
263 * @brief Called when an IMF Pre-Edit cursor event is received.
264 * @param[in] cursor cursor position
266 void PreEditCursorChange( int cursor );
269 * @brief called when IMF tell us to commit the text
270 * @param[in] serial event serial
271 * @param[in] commit text to commit
273 void CommitString( unsigned int serial, const std::string commit );
276 * @brief called when deleting surround text
277 * @param[in] index character index to start deleting from
278 * @param[in] length number of characters to delete
280 void DeleteSurroundingText( int index, unsigned int length );
287 virtual ~ImfManager();
292 ImfManagerSignalType mActivatedSignal;
293 ImfEventSignalType mEventSignal;
294 ImfStatusSignalType mKeyboardStatusSignal;
295 ImfVoidSignalType mKeyboardResizeSignal;
296 ImfVoidSignalType mKeyboardLanguageChangedSignal;
297 ImfKeyboardTypeSignalType mKeyboardTypeChangedSignal;
300 ImfManager( const ImfManager& );
301 ImfManager& operator=( ImfManager& );
305 TextInputManager& mTextInputManager;
306 std::string mSurroundingText;
307 int mPreEditCursorPosition;
308 int mEditCursorPosition;
309 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
313 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
315 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
317 BaseObject& handle = imfManager.GetBaseObject();
319 return static_cast<Internal::Adaptor::ImfManager&>(handle);
322 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
324 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
326 const BaseObject& handle = imfManager.GetBaseObject();
328 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
334 } // namespace Adaptor
336 } // namespace Internal
340 #endif // __DALI_INTERNAL_IMF_MANAGER_WL_H