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;
67 * @brief Check whether the ImfManager is available.
68 * @return true if available, false otherwise
70 static bool IsAvailable();
73 * @brief Get the IMF manager instance
74 * It creates the instance if it has not already been created.
75 * Internally, a check should be made using IsAvailable() before this is called as we do not want
76 * to create an instance if not needed by applications.
78 * @return handle to ImfManager
80 static Dali::ImfManager Get();
88 * Connect Callbacks required for IMF.
89 * If you don't connect imf callbacks, you can't get the key events.
90 * The events are PreeditChanged, Commit and DeleteSurrounding.
92 void ConnectCallbacks();
95 * @brief Disconnect Callbacks attached to imf context.
97 void DisconnectCallbacks();
100 * @copydoc Dali::ImfManager::Activate()
105 * @copydoc Dali::ImfManager::Deactivate()
110 * @copydoc Dali::ImfManager::Reset()
115 * @copydoc Dali::ImfManager::GetContext()
120 * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
122 bool RestoreAfterFocusLost() const;
125 * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
127 void SetRestoreAfterFocusLost( bool toggle );
132 * @copydoc Dali::ImfManager::NotifyCursorPosition()
134 void NotifyCursorPosition();
137 * @copydoc Dali::ImfManager::SetCursorPosition()
139 void SetCursorPosition( unsigned int cursorPosition );
142 * @copydoc Dali::ImfManager::GetCursorPosition()
144 unsigned int GetCursorPosition() const;
147 * @copydoc Dali::ImfManager::SetSurroundingText()
149 void SetSurroundingText( const std::string& text );
152 * @copydoc Dali::ImfManager::GetSurroundingText()
154 const std::string& GetSurroundingText() const;
157 * @copydoc Dali::ImfManager::NotifyTextInputMultiLine()
159 void NotifyTextInputMultiLine( bool multiLine );
162 * @copydoc Dali::ImfManager::GetTextDirection()
164 Dali::ImfManager::TextDirection GetTextDirection();
167 * @copydoc Dali::ImfManager::GetInputMethodArea()
169 Dali::Rect<int> GetInputMethodArea();
172 * @copydoc Dali::ImfManager::ApplyOptions()
174 void ApplyOptions( const InputMethodOptions& options );
177 * @copydoc Dali::ImfManager::SetInputPanelData()
179 void SetInputPanelData( const std::string& data );
182 * @copydoc Dali::ImfManager::GetInputPanelData()
184 void GetInputPanelData( std::string& data );
187 * @copydoc Dali::ImfManager::GetInputPanelState()
189 Dali::ImfManager::State GetInputPanelState();
192 * @copydoc Dali::ImfManager::SetReturnKeyState()
194 void SetReturnKeyState( bool visible );
197 * @copydoc Dali::ImfManager::AutoEnableInputPanel()
199 void AutoEnableInputPanel( bool enabled );
202 * @copydoc Dali::ImfManager::ShowInputPanel()
204 void ShowInputPanel();
207 * @copydoc Dali::ImfManager::HideInputPanel()
209 void HideInputPanel();
212 * @copydoc Dali::ImfManager::GetKeyboardType()
214 Dali::ImfManager::KeyboardType GetKeyboardType();
217 * @copydoc Dali::ImfManager::GetInputPanelLocale()
219 std::string GetInputPanelLocale();
224 * @copydoc Dali::ImfManager::ActivatedSignal()
226 ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
229 * @copydoc Dali::ImfManager::EventReceivedSignal()
231 ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
234 * @copydoc Dali::ImfManager::StatusChangedSignal()
236 ImfStatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
239 * @copydoc Dali::ImfManager::ResizedSignal()
241 KeyboardResizedSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
244 * @copydoc Dali::ImfManager::LanguageChangedSignal()
246 LanguageChangedSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
249 * @copydoc Dali::ImfManager::KeyboardTypeChangedSignal()
251 ImfKeyboardTypeSignalType& KeyboardTypeChangedSignal() { return mKeyboardTypeChangedSignal; }
254 * @brief Called when an IMF Pre-Edit change event is received.
255 * We are still predicting what the user is typing. The latest string is what the IMF module thinks
256 * the user wants to type.
258 * @param[in] serial event serial
259 * @param[in] text pre-edit string
260 * @param[in] commit commit string
262 void PreEditStringChange( unsigned int serial, const std::string text, const std::string commit );
265 * @brief Called when an IMF Pre-Edit cursor event is received.
266 * @param[in] cursor cursor position
268 void PreEditCursorChange( int cursor );
271 * @brief called when IMF tell us to commit the text
272 * @param[in] serial event serial
273 * @param[in] commit text to commit
275 void CommitString( unsigned int serial, const std::string commit );
278 * @brief called when deleting surround text
279 * @param[in] index character index to start deleting from
280 * @param[in] length number of characters to delete
282 void DeleteSurroundingText( int index, unsigned int length );
289 virtual ~ImfManager();
294 ImfManagerSignalType mActivatedSignal;
295 ImfEventSignalType mEventSignal;
296 ImfStatusSignalType mKeyboardStatusSignal;
297 KeyboardResizedSignalType mKeyboardResizeSignal;
298 LanguageChangedSignalType mKeyboardLanguageChangedSignal;
299 ImfKeyboardTypeSignalType mKeyboardTypeChangedSignal;
302 ImfManager( const ImfManager& );
303 ImfManager& operator=( ImfManager& );
307 TextInputManager& mTextInputManager;
308 std::string mSurroundingText;
309 int mPreEditCursorPosition;
310 int mEditCursorPosition;
311 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
315 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
317 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
319 BaseObject& handle = imfManager.GetBaseObject();
321 return static_cast<Internal::Adaptor::ImfManager&>(handle);
324 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
326 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
328 const BaseObject& handle = imfManager.GetBaseObject();
330 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
336 } // namespace Adaptor
338 } // namespace Internal
342 #endif // __DALI_INTERNAL_IMF_MANAGER_WL_H