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;
64 * @copydoc Dali::ImfManager::Finalize()
69 * @brief Check whether the ImfManager is available.
70 * @return true if available, false otherwise
72 static bool IsAvailable();
75 * @brief Get the IMF manager instance
76 * It creates the instance if it has not already been created.
77 * Internally, a check should be made using IsAvailable() before this is called as we do not want
78 * to create an instance if not needed by applications.
80 * @return handle to ImfManager
82 static Dali::ImfManager Get();
90 * Connect Callbacks required for IMF.
91 * If you don't connect imf callbacks, you can't get the key events.
92 * The events are PreeditChanged, Commit and DeleteSurrounding.
94 void ConnectCallbacks();
97 * @brief Disconnect Callbacks attached to imf context.
99 void DisconnectCallbacks();
102 * @copydoc Dali::ImfManager::Activate()
107 * @copydoc Dali::ImfManager::Deactivate()
112 * @copydoc Dali::ImfManager::Reset()
117 * @copydoc Dali::ImfManager::GetContext()
122 * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
124 bool RestoreAfterFocusLost() const;
127 * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
129 void SetRestoreAfterFocusLost( bool toggle );
134 * @copydoc Dali::ImfManager::NotifyCursorPosition()
136 void NotifyCursorPosition();
139 * @copydoc Dali::ImfManager::SetCursorPosition()
141 void SetCursorPosition( unsigned int cursorPosition );
144 * @copydoc Dali::ImfManager::GetCursorPosition()
146 unsigned int GetCursorPosition() const;
149 * @copydoc Dali::ImfManager::SetSurroundingText()
151 void SetSurroundingText( const std::string& text );
154 * @copydoc Dali::ImfManager::GetSurroundingText()
156 const std::string& GetSurroundingText() const;
159 * @copydoc Dali::ImfManager::NotifyTextInputMultiLine()
161 void NotifyTextInputMultiLine( bool multiLine );
164 * @copydoc Dali::ImfManager::GetTextDirection()
166 Dali::ImfManager::TextDirection GetTextDirection();
169 * @copydoc Dali::ImfManager::GetInputMethodArea()
171 Dali::Rect<int> GetInputMethodArea();
174 * @copydoc Dali::ImfManager::ApplyOptions()
176 void ApplyOptions( const InputMethodOptions& options );
179 * @copydoc Dali::ImfManager::SetInputPanelUserData()
181 void SetInputPanelUserData( const std::string& data );
184 * @copydoc Dali::ImfManager::GetInputPanelUserData()
186 void GetInputPanelUserData( std::string& data );
189 * @copydoc Dali::ImfManager::GetInputPanelState()
191 Dali::ImfManager::State GetInputPanelState();
194 * @copydoc Dali::ImfManager::SetReturnKeyState()
196 void SetReturnKeyState( bool visible );
199 * @copydoc Dali::ImfManager::AutoEnableInputPanel()
201 void AutoEnableInputPanel( bool enabled );
204 * @copydoc Dali::ImfManager::ShowInputPanel()
206 void ShowInputPanel();
209 * @copydoc Dali::ImfManager::HideInputPanel()
211 void HideInputPanel();
214 * @copydoc Dali::ImfManager::GetKeyboardType()
216 Dali::ImfManager::KeyboardType GetKeyboardType();
219 * @copydoc Dali::ImfManager::GetInputPanelLocale()
221 std::string GetInputPanelLocale();
226 * @copydoc Dali::ImfManager::ActivatedSignal()
228 ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
231 * @copydoc Dali::ImfManager::EventReceivedSignal()
233 ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
236 * @copydoc Dali::ImfManager::StatusChangedSignal()
238 ImfStatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
241 * @copydoc Dali::ImfManager::ResizedSignal()
243 ImfVoidSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
246 * @copydoc Dali::ImfManager::LanguageChangedSignal()
248 ImfVoidSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
251 * @copydoc Dali::ImfManager::KeyboardTypeChangedSignal()
253 ImfKeyboardTypeSignalType& KeyboardTypeChangedSignal() { return mKeyboardTypeChangedSignal; }
256 * @brief Called when an IMF Pre-Edit change event is received.
257 * We are still predicting what the user is typing. The latest string is what the IMF module thinks
258 * the user wants to type.
260 * @param[in] serial event serial
261 * @param[in] text pre-edit string
262 * @param[in] commit commit string
264 void PreEditStringChange( unsigned int serial, const std::string text, const std::string commit );
267 * @brief Called when an IMF Pre-Edit cursor event is received.
268 * @param[in] cursor cursor position
270 void PreEditCursorChange( int cursor );
273 * @brief called when IMF tell us to commit the text
274 * @param[in] serial event serial
275 * @param[in] commit text to commit
277 void CommitString( unsigned int serial, const std::string commit );
280 * @brief called when deleting surround text
281 * @param[in] index character index to start deleting from
282 * @param[in] length number of characters to delete
284 void DeleteSurroundingText( int index, unsigned int length );
291 virtual ~ImfManager();
296 ImfManagerSignalType mActivatedSignal;
297 ImfEventSignalType mEventSignal;
298 ImfStatusSignalType mKeyboardStatusSignal;
299 ImfVoidSignalType mKeyboardResizeSignal;
300 ImfVoidSignalType mKeyboardLanguageChangedSignal;
301 ImfKeyboardTypeSignalType mKeyboardTypeChangedSignal;
304 ImfManager( const ImfManager& );
305 ImfManager& operator=( ImfManager& );
309 TextInputManager& mTextInputManager;
310 std::string mSurroundingText;
311 int mPreEditCursorPosition;
312 int mEditCursorPosition;
313 bool mInited:1; ///< Whether the imf is already inited.
314 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
318 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
320 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
322 BaseObject& handle = imfManager.GetBaseObject();
324 return static_cast<Internal::Adaptor::ImfManager&>(handle);
327 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
329 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
331 const BaseObject& handle = imfManager.GetBaseObject();
333 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
339 } // namespace Adaptor
341 } // namespace Internal
345 #endif // __DALI_INTERNAL_IMF_MANAGER_WL_H