1 #ifndef __DALI_IMF_MANAGER_H__
2 #define __DALI_IMF_MANAGER_H__
5 * Copyright (c) 2015 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.
22 #include <dali/public-api/object/base-handle.h>
23 #include <dali/public-api/signals/dali-signal.h>
24 #include <dali/devel-api/adaptor-framework/input-method-options.h>
29 namespace Internal DALI_INTERNAL
38 * @brief The ImfManager class
40 * Specifically manages the ecore input method framework which enables the virtual or hardware keyboards.
42 class DALI_IMPORT_API ImfManager : public BaseHandle
47 * @brief The direction of text.
56 * @brief Events that are generated by the IMF.
61 PREEDIT, ///< Pre-Edit changed
62 COMMIT, ///< Commit recieved
63 DELETESURROUNDING, ///< Event to delete a range of characters from the string
64 GETSURROUNDING, ///< Event to query string and cursor position
65 PRIVATECOMMAND ///< Private command sent from the input panel
69 * @brief Enumeration for state of the input panel.
73 DEFAULT = 0, ///< Unknown state
74 SHOW, ///< Input panel is shown
75 HIDE, ///< Input panel is hidden
76 WILL_SHOW ///< Input panel in process of being shown
80 * @brief Enumeration for the type of Keyboard.
84 SOFTWARE_KEYBOARD, ///< Software keyboard (Virtual keyboard) is default
85 HARDWARE_KEYBOARD ///< Hardware keyboard
89 * @brief This structure is used to pass on data from the IMF regarding predictive text.
94 * @brief Default Constructor.
107 * @param[in] aEventName The name of the event from the IMF.
108 * @param[in] aPredictiveString The pre-edit or commit string.
109 * @param[in] aCursorOffset Start position from the current cursor position to start deleting characters.
110 * @param[in] aNumberOfChars The number of characters to delete from the cursorOffset.
112 ImfEventData( ImfEvent aEventName, const std::string& aPredictiveString, int aCursorOffset, int aNumberOfChars )
113 : predictiveString( aPredictiveString ),
114 eventName( aEventName ),
115 cursorOffset( aCursorOffset ),
116 numberOfChars( aNumberOfChars )
121 std::string predictiveString; ///< The pre-edit or commit string.
122 ImfEvent eventName; ///< The name of the event from the IMF.
123 int cursorOffset; ///< Start position from the current cursor position to start deleting characters.
124 int numberOfChars; ///< number of characters to delete from the cursorOffset.
128 * @brief Data required by IMF from the callback
130 struct ImfCallbackData
139 preeditResetRequired( false )
145 * @param[in] aUpdate True if cursor position needs to be updated
146 * @param[in] aCursorPosition new position of cursor
147 * @param[in] aCurrentText current text string
148 * @param[in] aPreeditResetRequired flag if preedit reset is required.
150 ImfCallbackData( bool aUpdate, int aCursorPosition, const std::string& aCurrentText, bool aPreeditResetRequired )
151 : currentText( aCurrentText ),
152 cursorPosition( aCursorPosition ),
154 preeditResetRequired( aPreeditResetRequired )
158 std::string currentText; ///< current text string
159 int cursorPosition; ///< new position of cursor
160 bool update :1; ///< if cursor position needs to be updated
161 bool preeditResetRequired :1; ///< flag if preedit reset is required.
164 typedef Signal< void (ImfManager&) > ImfManagerSignalType; ///< Keyboard actived signal
165 typedef Signal< ImfCallbackData ( ImfManager&, const ImfEventData& ) > ImfEventSignalType; ///< keyboard events
166 typedef Signal< void () > VoidSignalType;
167 typedef Signal< void ( bool ) > StatusSignalType;
168 typedef Signal< void ( KeyboardType ) > KeyboardTypeSignalType; ///< keyboard type
169 typedef Signal< void ( int ) > KeyboardResizedSignalType; ///< Keyboard resized signal
170 typedef Signal< void ( int ) > LanguageChangedSignalType; ///< Language changed signal
175 * @brief Retrieve a handle to the instance of ImfManager.
176 * @return A handle to the ImfManager.
178 static ImfManager Get();
181 * @brief Activate the IMF.
183 * It means that the text editing is started at somewhere.
184 * If the H/W keyboard isn't connected then it will show the virtual keyboard.
189 * @brief Deactivate the IMF.
191 * It means that the text editing is finished at somewhere.
196 * @brief Get the restoration status, which controls if the keyboard is restored after the focus lost then regained.
198 * If true then keyboard will be restored (activated) after focus is regained.
199 * @return restoration status.
201 bool RestoreAfterFocusLost() const;
204 * @brief Set status whether the IMF has to restore the keyboard after losing focus.
206 * @param[in] toggle True means that keyboard should be restored after focus lost and regained.
208 void SetRestoreAfterFocusLost( bool toggle );
211 * @brief Send message reset the pred-edit state / imf module.
213 * Used to interupt pre-edit state maybe due to a touch input.
218 * @brief Notifies IMF context that the cursor position has changed, required for features like auto-capitalisation.
220 void NotifyCursorPosition();
223 * @brief Sets cursor position stored in VirtualKeyboard, this is required by the IMF context.
225 * @param[in] cursorPosition position of cursor
227 void SetCursorPosition( unsigned int cursorPosition );
230 * @brief Gets cursor position stored in VirtualKeyboard, this is required by the IMF context.
232 * @return current position of cursor
234 unsigned int GetCursorPosition() const;
237 * @brief Method to store the string required by the IMF, this is used to provide predictive word suggestions.
239 * @param[in] text The text string surrounding the current cursor point.
241 void SetSurroundingText( const std::string& text );
244 * @brief Gets current text string set within the IMF manager, this is used to offer predictive suggestions.
246 * @return current position of cursor
248 const std::string& GetSurroundingText() const;
251 * @brief Notifies IMF context that text input is set to multi line or not
253 * @param[in] multiLine True if multiline text input is used
255 void NotifyTextInputMultiLine( bool multiLine );
258 * @brief Returns text direction of the keyboard's current input language.
259 * @return The direction of the text.
261 TextDirection GetTextDirection();
264 * @brief Provides size and position of keyboard.
266 * Position is relative to whether keyboard is visible or not.
267 * If keyboard is not visible then position will be off the screen.
268 * If keyboard is not being shown when this method is called the keyboard is partially setup (IMFContext) to get
269 * the values then taken down. So ideally GetInputMethodArea() should be called after Show().
270 * @return rect which is keyboard panel x, y, width, height
272 Dali::Rect<int> GetInputMethodArea();
275 * @brief Set one or more of the Input Method options
276 * @param[in] options The options to be applied
278 void ApplyOptions( const InputMethodOptions& options );
281 * @brief Sets up the input-panel specific data.
282 * @param[in] data The specific data to be set to the input panel
284 void SetInputPanelData( const std::string& data );
287 * @brief Gets the specific data of the current active input panel.
289 * Input Panel Data is not always the data which is set by SetInputPanelData().
290 * Data can be changed internally in the input panel.
291 * It is just used to get a specific data from the input panel to an application.
292 * @param[in] data The specific data to be got from the input panel
294 void GetInputPanelData( std::string& data );
297 * @brief Gets the state of the current active input panel.
298 * @return The state of the input panel.
300 State GetInputPanelState();
303 * @brief Sets the return key on the input panel to be visible or invisible.
305 * The default is true.
306 * @param[in] visible True if the return key is visible(enabled), false otherwise.
308 void SetReturnKeyState( bool visible );
311 * @brief Enable to show the input panel automatically when focused.
312 * @param[in] enabled If true, the input panel will be shown when focused
314 void AutoEnableInputPanel( bool enabled );
317 * @brief Shows the input panel.
319 void ShowInputPanel();
322 * @brief Hides the input panel.
324 void HideInputPanel();
327 * @brief Gets the keyboard type.
329 * The default keyboard type is SOFTWARE_KEYBOARD.
330 * @return The keyboard type
332 KeyboardType GetKeyboardType();
335 * @brief Gets the current language locale of the input panel.
337 * ex) en_US, en_GB, en_PH, fr_FR, ...
338 * @return The current language locale of the input panel
340 std::string GetInputPanelLocale();
347 * @brief This is emitted when the virtual keyboard is connected to or the hardware keyboard is activated.
349 * @return The IMF Activated signal.
351 ImfManagerSignalType& ActivatedSignal();
354 * @brief This is emitted when the IMF manager receives an event from the IMF.
356 * @return The Event signal containing the event data.
358 ImfEventSignalType& EventReceivedSignal();
361 * @brief Connect to this signal to be notified when the virtual keyboard is shown or hidden.
363 * A callback of the following type may be connected:
365 * void YourCallbackName(bool keyboardShown);
367 * If the parameter keyboardShown is true, then the keyboard has just shown, if it is false, then it
368 * has just been hidden.
369 * @return The signal to connect to.
371 StatusSignalType& StatusChangedSignal();
374 * @brief Connect to this signal to be notified when the virtual keyboard is resized.
376 * A callback of the following type may be connected:
378 * void YourCallbackName( int resolvedResize );
380 * The parameter sends the resolved resize defined by the IMF.
382 * User can get changed size by using GetInputMethodArea() in the callback
383 * @return The signal to connect to.
385 KeyboardResizedSignalType& ResizedSignal();
388 * @brief Connect to this signal to be notified when the virtual keyboard's language is changed.
390 * A callback of the following type may be connected:
392 * void YourCallbackName( int resolvedLanguage );
394 * The parameter sends the resolved language defined by the IMF.
396 * User can get the text direction of the language by calling GetTextDirection() in the callback.
397 * @return The signal to connect to.
399 LanguageChangedSignalType& LanguageChangedSignal();
402 * @brief Connect to this signal to be notified when the keyboard type is changed.
404 * A callback of the following type may be connected:
406 * void YourCallbackName( KeyboardType keyboard );
409 * @return The signal to connect to.
411 KeyboardTypeSignalType& KeyboardTypeChangedSignal();
413 // Construction & Destruction
416 * @brief Constructor.
423 * This is non-virtual since derived Handle types must not contain data or virtual methods.
428 * @brief This constructor is used by ImfManager::Get().
430 * @param[in] imfManager A pointer to the imf Manager.
432 explicit DALI_INTERNAL ImfManager( Internal::Adaptor::ImfManager* imfManager );
437 #endif // __DALI_IMF_MANAGER_H__