1 #ifndef DALI_TOOLKIT_TOOLKIT_INPUT_METHOD_CONTEXT_H
2 #define DALI_TOOLKIT_TOOLKIT_INPUT_METHOD_CONTEXT_H
5 * Copyright (c) 2019 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 #define DALI_INPUT_METHOD_CONTEXT_H
23 #include <dali/public-api/actors/actor.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/signals/dali-signal.h>
26 #include <dali/devel-api/adaptor-framework/input-method-options.h>
27 #include <dali/public-api/events/key-event.h>
29 namespace Dali DALI_IMPORT_API
32 namespace Internal DALI_INTERNAL
36 class InputMethodContext;
41 * @brief The InputMethodContext class
43 * Specifically manages the ecore input method framework which enables the virtual or hardware keyboards.
45 class InputMethodContext : public BaseHandle
50 * @brief The direction of text.
59 * @brief Events that are generated by the InputMethodContext.
64 PRE_EDIT, ///< Pre-Edit changed
65 COMMIT, ///< Commit recieved
66 DELETE_SURROUNDING, ///< Event to delete a range of characters from the string
67 GET_SURROUNDING, ///< Event to query string and cursor position
68 PRIVATE_COMMAND ///< Private command sent from the input panel
72 * @brief Enumeration for state of the input panel.
76 DEFAULT = 0, ///< Unknown state
77 SHOW, ///< Input panel is shown
78 HIDE, ///< Input panel is hidden
79 WILL_SHOW ///< Input panel in process of being shown
83 * @brief Enumeration for the type of Keyboard.
87 SOFTWARE_KEYBOARD, ///< Software keyboard (Virtual keyboard) is default
88 HARDWARE_KEYBOARD ///< Hardware keyboard
92 * @brief Enumeration for the language mode of the input panel.
94 enum class InputPanelLanguage
96 AUTOMATIC, ///< IME Language automatically set depending on the system display
97 ALPHABET ///< Latin alphabet at all times
101 * @brief Enumeration for the preedit style types.
103 enum class PreeditStyle
105 NONE, ///< None style
106 UNDERLINE, ///< Underline substring style
107 REVERSE, ///< Reverse substring style
108 HIGHLIGHT, ///< Highlight substring style
109 CUSTOM_PLATFORM_STYLE_1, ///< Custom style for platform
110 CUSTOM_PLATFORM_STYLE_2, ///< Custom style for platform
111 CUSTOM_PLATFORM_STYLE_3, ///< Custom style for platform
112 CUSTOM_PLATFORM_STYLE_4 ///< Custom style for platform
116 * @brief This structure is for the preedit style types and indices.
118 struct PreeditAttributeData
120 PreeditStyle preeditType; /// The preedit style type
121 unsigned int startIndex; /// The start index of preedit
122 unsigned int endIndex; /// The end index of preedit
126 * @brief This structure is used to pass on data from the InputMethodContext regarding predictive text.
131 * @brief Default Constructor.
134 : predictiveString(),
144 * @param[in] aEventName The name of the event from the input method context.
145 * @param[in] aPredictiveString The pre-edit or commit string.
146 * @param[in] aCursorOffset Start position from the current cursor position to start deleting characters.
147 * @param[in] aNumberOfChars The number of characters to delete from the cursorOffset.
149 EventData( EventType aEventName, const std::string& aPredictiveString, int aCursorOffset, int aNumberOfChars )
150 : predictiveString( aPredictiveString ),
151 eventName( aEventName ),
152 cursorOffset( aCursorOffset ),
153 numberOfChars( aNumberOfChars )
158 std::string predictiveString; ///< The pre-edit or commit string.
159 EventType eventName; ///< The name of the event from the input method context.
160 int cursorOffset; ///< Start position from the current cursor position to start deleting characters.
161 int numberOfChars; ///< number of characters to delete from the cursorOffset.
165 * @brief Data required by input method context from the callback
176 preeditResetRequired( false )
182 * @param[in] aUpdate True if cursor position needs to be updated
183 * @param[in] aCursorPosition new position of cursor
184 * @param[in] aCurrentText current text string
185 * @param[in] aPreeditResetRequired flag if preedit reset is required.
187 CallbackData( bool aUpdate, int aCursorPosition, const std::string& aCurrentText, bool aPreeditResetRequired )
188 : currentText( aCurrentText ),
189 cursorPosition( aCursorPosition ),
191 preeditResetRequired( aPreeditResetRequired )
195 std::string currentText; ///< current text string
196 int cursorPosition; ///< new position of cursor
197 bool update :1; ///< if cursor position needs to be updated
198 bool preeditResetRequired :1; ///< flag if preedit reset is required.
201 typedef Signal< void (InputMethodContext&) > ActivatedSignalType; ///< Keyboard actived signal
202 typedef Signal< CallbackData ( InputMethodContext&, const EventData& ) > KeyboardEventSignalType; ///< keyboard events
203 typedef Signal< void () > VoidSignalType;
204 typedef Signal< void (bool) > StatusSignalType;
209 * @brief Create a handle to the instance of InputMethodContext.
210 * @return A handle to the InputMethodContext.
212 static InputMethodContext New();
215 * @brief Create a handle to the instance of InputMethodContext.
217 * @param[in] actor The actor that uses the new InputMethodContext instance.
218 * @return A handle to the InputMethodContext.
220 static InputMethodContext New( Actor actor );
223 * @brief Finalize the InputMethodContext.
225 * It means that the context will be deleted.
230 * @brief Activate the input method context.
232 * It means that the text editing is started at somewhere.
233 * If the H/W keyboard isn't connected then it will show the virtual keyboard.
238 * @brief Deactivate the input method context.
240 * It means that the text editing is finished at somewhere.
245 * @brief Get the restoration status, which controls if the keyboard is restored after the focus lost then regained.
247 * If true then keyboard will be restored (activated) after focus is regained.
248 * @return restoration status.
250 bool RestoreAfterFocusLost() const;
253 * @brief Set status whether the input method context has to restore the keyboard after losing focus.
255 * @param[in] toggle True means that keyboard should be restored after focus lost and regained.
257 void SetRestoreAfterFocusLost( bool toggle );
260 * @brief Send message reset the pred-edit state / input method context module.
262 * Used to interupt pre-edit state maybe due to a touch input.
267 * @brief Notifies ImfContext that the cursor position has changed, required for features like auto-capitalisation.
269 void NotifyCursorPosition();
272 * @brief Sets cursor position stored in VirtualKeyboard, this is required by the ImfContext.
274 * @param[in] cursorPosition position of cursor
276 void SetCursorPosition( unsigned int cursorPosition );
279 * @brief Gets cursor position stored in VirtualKeyboard, this is required by the ImfContext.
281 * @return current position of cursor
283 unsigned int GetCursorPosition() const;
286 * @brief Method to store the string required by the input method context, this is used to provide predictive word suggestions.
288 * @param[in] text The text string surrounding the current cursor point.
290 void SetSurroundingText( const std::string& text );
293 * @brief Gets current text string set within the input method context, this is used to offer predictive suggestions.
295 * @return current position of cursor
297 const std::string& GetSurroundingText() const;
300 * @brief Notifies ImfContext that text input is set to multi line or not
302 void NotifyTextInputMultiLine( bool multiLine );
305 * @brief Set one or more of the Input Method options
306 * @param[in] options The options to be applied
308 void ApplyOptions( const InputMethodOptions& options );
311 * @brief Process event key down or up, whether filter a key to isf.
313 * @param[in] keyEvent The event key to be handled.
314 * @return Whether the event key is handled.
316 bool FilterEventKey( const Dali::KeyEvent& keyEvent );
319 * @brief Sets the preedit type.
321 * @param[in] type The preedit style type
323 void SetPreeditStyle( PreeditStyle type );
326 * @brief Gets the preedit attrs data.
328 * @param[out] attrs The preedit attrs data.
330 void GetPreeditStyle( Vector<PreeditAttributeData>& attrs ) const;
337 * @brief This is emitted when the virtual keyboard is connected to or the hardware keyboard is activated.
339 * @return The input method context Activated signal.
341 ActivatedSignalType& ActivatedSignal();
344 * @brief This is emitted when the input method context receives an event.
346 * @return The Event signal containing the event data.
348 KeyboardEventSignalType& EventReceivedSignal();
351 * @brief Connect to this signal to be notified when the virtual keyboard is shown or hidden.
353 * @return The signal connect to status changed event.
355 StatusSignalType& StatusChangedSignal();
358 * @brief Connect to this signal to be notified when the virtual keyboard is resized.
360 * @return The signal to connect to resized event.
362 VoidSignalType& ResizedSignal();
365 * @brief Connect to this signal to be notified when the virtual keyboard's language is changed.
367 * @return The signal to connect to language changed event.
369 VoidSignalType& LanguageChangedSignal();
371 // Construction & Destruction
374 * @brief Constructor.
376 InputMethodContext();
381 * This is non-virtual since derived Handle types must not contain data or virtual methods.
383 ~InputMethodContext();
386 * @brief This constructor is used by InputMethodContext::Get().
388 * @param[in] inputMethodContext A pointer to the input method context.
390 explicit InputMethodContext( Internal::Adaptor::InputMethodContext* inputMethodContext );
395 #endif // DALI_TOOLKIT_TOOLKIT_INPUT_METHOD_CONTEXT_H