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;
61 typedef Dali::ImfManager::KeyboardResizedSignalType KeyboardResizedSignalType;
62 typedef Dali::ImfManager::LanguageChangedSignalType LanguageChangedSignalType;
66 * @copydoc Dali::ImfManager::Finalize()
71 * @brief Check whether the ImfManager is available.
72 * @return true if available, false otherwise
74 static bool IsAvailable();
77 * @brief Get the IMF manager instance
78 * It creates the instance if it has not already been created.
79 * Internally, a check should be made using IsAvailable() before this is called as we do not want
80 * to create an instance if not needed by applications.
82 * @return handle to ImfManager
84 static Dali::ImfManager Get();
92 * Connect Callbacks required for IMF.
93 * If you don't connect imf callbacks, you can't get the key events.
94 * The events are PreeditChanged, Commit and DeleteSurrounding.
96 void ConnectCallbacks();
99 * @brief Disconnect Callbacks attached to imf context.
101 void DisconnectCallbacks();
104 * @copydoc Dali::ImfManager::Activate()
109 * @copydoc Dali::ImfManager::Deactivate()
114 * @copydoc Dali::ImfManager::Reset()
119 * @copydoc Dali::ImfManager::GetContext()
124 * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
126 bool RestoreAfterFocusLost() const;
129 * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
131 void SetRestoreAfterFocusLost( bool toggle );
136 * @copydoc Dali::ImfManager::NotifyCursorPosition()
138 void NotifyCursorPosition();
141 * @copydoc Dali::ImfManager::SetCursorPosition()
143 void SetCursorPosition( unsigned int cursorPosition );
146 * @copydoc Dali::ImfManager::GetCursorPosition()
148 unsigned int GetCursorPosition() const;
151 * @copydoc Dali::ImfManager::SetSurroundingText()
153 void SetSurroundingText( const std::string& text );
156 * @copydoc Dali::ImfManager::GetSurroundingText()
158 const std::string& GetSurroundingText() const;
161 * @copydoc Dali::ImfManager::NotifyTextInputMultiLine()
163 void NotifyTextInputMultiLine( bool multiLine );
166 * @copydoc Dali::ImfManager::GetTextDirection()
168 Dali::ImfManager::TextDirection GetTextDirection();
171 * @copydoc Dali::ImfManager::GetInputMethodArea()
173 Dali::Rect<int> GetInputMethodArea();
176 * @copydoc Dali::ImfManager::ApplyOptions()
178 void ApplyOptions( const InputMethodOptions& options );
181 * @copydoc Dali::ImfManager::SetInputPanelData()
183 void SetInputPanelData( const std::string& data );
186 * @copydoc Dali::ImfManager::GetInputPanelData()
188 void GetInputPanelData( std::string& data );
191 * @copydoc Dali::ImfManager::GetInputPanelState()
193 Dali::ImfManager::State GetInputPanelState();
196 * @copydoc Dali::ImfManager::SetReturnKeyState()
198 void SetReturnKeyState( bool visible );
201 * @copydoc Dali::ImfManager::AutoEnableInputPanel()
203 void AutoEnableInputPanel( bool enabled );
206 * @copydoc Dali::ImfManager::ShowInputPanel()
208 void ShowInputPanel();
211 * @copydoc Dali::ImfManager::HideInputPanel()
213 void HideInputPanel();
216 * @copydoc Dali::ImfManager::GetKeyboardType()
218 Dali::ImfManager::KeyboardType GetKeyboardType();
221 * @copydoc Dali::ImfManager::GetInputPanelLocale()
223 std::string GetInputPanelLocale();
228 * @copydoc Dali::ImfManager::ActivatedSignal()
230 ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
233 * @copydoc Dali::ImfManager::EventReceivedSignal()
235 ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
238 * @copydoc Dali::ImfManager::StatusChangedSignal()
240 ImfStatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
243 * @copydoc Dali::ImfManager::ResizedSignal()
245 KeyboardResizedSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
248 * @copydoc Dali::ImfManager::LanguageChangedSignal()
250 LanguageChangedSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
253 * @copydoc Dali::ImfManager::KeyboardTypeChangedSignal()
255 ImfKeyboardTypeSignalType& KeyboardTypeChangedSignal() { return mKeyboardTypeChangedSignal; }
258 * @brief Called when an IMF Pre-Edit change event is received.
259 * We are still predicting what the user is typing. The latest string is what the IMF module thinks
260 * the user wants to type.
262 * @param[in] serial event serial
263 * @param[in] text pre-edit string
264 * @param[in] commit commit string
266 void PreEditStringChange( unsigned int serial, const std::string text, const std::string commit );
269 * @brief Called when an IMF Pre-Edit cursor event is received.
270 * @param[in] cursor cursor position
272 void PreEditCursorChange( int cursor );
275 * @brief called when IMF tell us to commit the text
276 * @param[in] serial event serial
277 * @param[in] commit text to commit
279 void CommitString( unsigned int serial, const std::string commit );
282 * @brief called when deleting surround text
283 * @param[in] index character index to start deleting from
284 * @param[in] length number of characters to delete
286 void DeleteSurroundingText( int index, unsigned int length );
293 virtual ~ImfManager();
298 ImfManagerSignalType mActivatedSignal;
299 ImfEventSignalType mEventSignal;
300 ImfStatusSignalType mKeyboardStatusSignal;
301 KeyboardResizedSignalType mKeyboardResizeSignal;
302 LanguageChangedSignalType mKeyboardLanguageChangedSignal;
303 ImfKeyboardTypeSignalType mKeyboardTypeChangedSignal;
306 ImfManager( const ImfManager& );
307 ImfManager& operator=( ImfManager& );
311 TextInputManager& mTextInputManager;
312 std::string mSurroundingText;
313 int mPreEditCursorPosition;
314 int mEditCursorPosition;
315 bool mInited:1; ///< Whether the imf is already inited.
316 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
320 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
322 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
324 BaseObject& handle = imfManager.GetBaseObject();
326 return static_cast<Internal::Adaptor::ImfManager&>(handle);
329 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
331 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
333 const BaseObject& handle = imfManager.GetBaseObject();
335 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
341 } // namespace Adaptor
343 } // namespace Internal
347 #endif // __DALI_INTERNAL_IMF_MANAGER_WL_H