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;
64 * @brief Check whether the ImfManager is available.
65 * @return true if available, false otherwise
67 static bool IsAvailable();
70 * @brief Get the IMF manager instance
71 * It creates the instance if it has not already been created.
72 * Internally, a check should be made using IsAvailable() before this is called as we do not want
73 * to create an instance if not needed by applications.
75 * @return handle to ImfManager
77 static Dali::ImfManager Get();
85 * Connect Callbacks required for IMF.
86 * If you don't connect imf callbacks, you can't get the key events.
87 * The events are PreeditChanged, Commit and DeleteSurrounding.
89 void ConnectCallbacks();
92 * @brief Disconnect Callbacks attached to imf context.
94 void DisconnectCallbacks();
97 * @copydoc Dali::ImfManager::Activate()
102 * @copydoc Dali::ImfManager::Deactivate()
107 * @copydoc Dali::ImfManager::Reset()
112 * @copydoc Dali::ImfManager::GetContext()
117 * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
119 bool RestoreAfterFocusLost() const;
122 * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
124 void SetRestoreAfterFocusLost( bool toggle );
129 * @copydoc Dali::ImfManager::NotifyCursorPosition()
131 void NotifyCursorPosition();
134 * @copydoc Dali::ImfManager::SetCursorPosition()
136 void SetCursorPosition( unsigned int cursorPosition );
139 * @copydoc Dali::ImfManager::GetCursorPosition()
141 unsigned int GetCursorPosition() const;
144 * @copydoc Dali::ImfManager::SetSurroundingText()
146 void SetSurroundingText( const std::string& text );
149 * @copydoc Dali::ImfManager::GetSurroundingText()
151 const std::string& GetSurroundingText() const;
154 * @copydoc Dali::ImfManager::NotifyTextInputMultiLine()
156 void NotifyTextInputMultiLine( bool multiLine );
159 * @copydoc Dali::ImfManager::GetTextDirection()
161 Dali::ImfManager::TextDirection GetTextDirection();
164 * @copydoc Dali::ImfManager::GetInputMethodArea()
166 Dali::Rect<int> GetInputMethodArea();
169 * @copydoc Dali::ImfManager::ApplyOptions()
171 void ApplyOptions( const InputMethodOptions& options );
174 * @copydoc Dali::ImfManager::SetInputPanelUserData()
176 void SetInputPanelUserData( const std::string& data );
179 * @copydoc Dali::ImfManager::GetInputPanelUserData()
181 void GetInputPanelUserData( std::string& data );
184 * @copydoc Dali::ImfManager::GetInputPanelState()
186 Dali::ImfManager::State GetInputPanelState();
189 * @copydoc Dali::ImfManager::SetReturnKeyState()
191 void SetReturnKeyState( bool visible );
194 * @copydoc Dali::ImfManager::AutoEnableInputPanel()
196 void AutoEnableInputPanel( bool enabled );
199 * @copydoc Dali::ImfManager::ShowInputPanel()
201 void ShowInputPanel();
204 * @copydoc Dali::ImfManager::HideInputPanel()
206 void HideInputPanel();
211 * @copydoc Dali::ImfManager::ActivatedSignal()
213 ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
216 * @copydoc Dali::ImfManager::EventReceivedSignal()
218 ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
221 * @copydoc Dali::ImfManager::StatusChangedSignal()
223 ImfStatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
226 * @copydoc Dali::ImfManager::ResizedSignal()
228 ImfVoidSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
231 * @copydoc Dali::ImfManager::LanguageChangedSignal()
233 ImfVoidSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
237 * @brief Called when an IMF Pre-Edit change event is received.
238 * We are still predicting what the user is typing. The latest string is what the IMF module thinks
239 * the user wants to type.
241 * @param[in] serial event serial
242 * @param[in] text pre-edit string
243 * @param[in] commit commit string
245 void PreEditStringChange( unsigned int serial, const std::string text, const std::string commit );
248 * @brief Called when an IMF Pre-Edit cursor event is received.
249 * @param[in] cursor cursor position
251 void PreEditCursorChange( int cursor );
254 * @brief called when IMF tell us to commit the text
255 * @param[in] serial event serial
256 * @param[in] commit text to commit
258 void CommitString( unsigned int serial, const std::string commit );
261 * @brief called when deleting surround text
262 * @param[in] index character index to start deleting from
263 * @param[in] length number of characters to delete
265 void DeleteSurroundingText( int index, unsigned int length );
272 virtual ~ImfManager();
277 ImfManagerSignalType mActivatedSignal;
278 ImfEventSignalType mEventSignal;
279 ImfStatusSignalType mKeyboardStatusSignal;
280 ImfVoidSignalType mKeyboardResizeSignal;
281 ImfVoidSignalType mKeyboardLanguageChangedSignal;
284 ImfManager( const ImfManager& );
285 ImfManager& operator=( ImfManager& );
289 TextInputManager& mTextInputManager;
290 std::string mSurroundingText;
291 int mPreEditCursorPosition;
292 int mEditCursorPosition;
293 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
297 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
299 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
301 BaseObject& handle = imfManager.GetBaseObject();
303 return static_cast<Internal::Adaptor::ImfManager&>(handle);
306 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
308 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
310 const BaseObject& handle = imfManager.GetBaseObject();
312 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
318 } // namespace Adaptor
320 } // namespace Internal
324 #endif // __DALI_INTERNAL_IMF_MANAGER_WL_H