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 );
176 * @copydoc Dali::ImfManager::ActivatedSignal()
178 ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
181 * @copydoc Dali::ImfManager::EventReceivedSignal()
183 ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
186 * @copydoc Dali::ImfManager::StatusChangedSignal()
188 ImfStatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
191 * @copydoc Dali::ImfManager::ResizedSignal()
193 ImfVoidSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
196 * @copydoc Dali::ImfManager::LanguageChangedSignal()
198 ImfVoidSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
202 * @brief Called when an IMF Pre-Edit change event is received.
203 * We are still predicting what the user is typing. The latest string is what the IMF module thinks
204 * the user wants to type.
206 * @param[in] serial event serial
207 * @param[in] text pre-edit string
208 * @param[in] commit commit string
210 void PreEditStringChange( unsigned int serial, const std::string text, const std::string commit );
213 * @brief Called when an IMF Pre-Edit cursor event is received.
214 * @param[in] cursor cursor position
216 void PreEditCursorChange( int cursor );
219 * @brief called when IMF tell us to commit the text
220 * @param[in] serial event serial
221 * @param[in] commit text to commit
223 void CommitString( unsigned int serial, const std::string commit );
226 * @brief called when deleting surround text
227 * @param[in] index character index to start deleting from
228 * @param[in] length number of characters to delete
230 void DeleteSurroundingText( int index, unsigned int length );
237 virtual ~ImfManager();
242 ImfManagerSignalType mActivatedSignal;
243 ImfEventSignalType mEventSignal;
244 ImfStatusSignalType mKeyboardStatusSignal;
245 ImfVoidSignalType mKeyboardResizeSignal;
246 ImfVoidSignalType mKeyboardLanguageChangedSignal;
249 ImfManager( const ImfManager& );
250 ImfManager& operator=( ImfManager& );
254 TextInputManager& mTextInputManager;
255 std::string mSurroundingText;
256 int mPreEditCursorPosition;
257 int mEditCursorPosition;
258 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
262 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
264 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
266 BaseObject& handle = imfManager.GetBaseObject();
268 return static_cast<Internal::Adaptor::ImfManager&>(handle);
271 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
273 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
275 const BaseObject& handle = imfManager.GetBaseObject();
277 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
283 } // namespace Adaptor
285 } // namespace Internal
289 #endif // __DALI_INTERNAL_IMF_MANAGER_WL_H