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 Events that are generated by the input method context.
55 PRE_EDIT, ///< Pre-Edit changed
56 COMMIT, ///< Commit recieved
57 DELETE_SURROUNDING, ///< Event to delete a range of characters from the string
58 GET_SURROUNDING, ///< Event to query string and cursor position
59 PRIVATE_COMMAND ///< Private command sent from the input panel
63 * @brief This structure is used to pass on data from the input method cotext regarding predictive text.
68 * @brief Default Constructor.
81 * @param[in] aEventName The name of the event from the input method context.
82 * @param[in] aPredictiveString The pre-edit or commit string.
83 * @param[in] aCursorOffset Start position from the current cursor position to start deleting characters.
84 * @param[in] aNumberOfChars The number of characters to delete from the cursorOffset.
86 EventData( EventType aEventName, const std::string& aPredictiveString, int aCursorOffset, int aNumberOfChars )
87 : predictiveString( aPredictiveString ),
88 eventName( aEventName ),
89 cursorOffset( aCursorOffset ),
90 numberOfChars( aNumberOfChars )
95 std::string predictiveString; ///< The pre-edit or commit string.
96 EventType eventName; ///< The name of the event from the input method context.
97 int cursorOffset; ///< Start position from the current cursor position to start deleting characters.
98 int numberOfChars; ///< number of characters to delete from the cursorOffset.
102 * @brief Data required by input method context from the callback
113 preeditResetRequired( false )
119 * @param[in] aUpdate True if cursor position needs to be updated
120 * @param[in] aCursorPosition new position of cursor
121 * @param[in] aCurrentText current text string
122 * @param[in] aPreeditResetRequired flag if preedit reset is required.
124 CallbackData( bool aUpdate, int aCursorPosition, const std::string& aCurrentText, bool aPreeditResetRequired )
125 : currentText( aCurrentText ),
126 cursorPosition( aCursorPosition ),
128 preeditResetRequired( aPreeditResetRequired )
132 std::string currentText; ///< current text string
133 int cursorPosition; ///< new position of cursor
134 bool update :1; ///< if cursor position needs to be updated
135 bool preeditResetRequired :1; ///< flag if preedit reset is required.
138 typedef Signal< void (InputMethodContext&) > ActivatedSignalType; ///< Keyboard actived signal
139 typedef Signal< CallbackData ( InputMethodContext&, const EventData& ) > KeyboardEventSignalType; ///< keyboard events
140 typedef Signal< void () > VoidSignalType;
141 typedef Signal< void (bool) > StatusSignalType;
146 * @brief Create a handle to the instance of InputMethodContext.
147 * @return A handle to the InputMethodContext.
149 static InputMethodContext New();
152 * @brief Create a handle to the instance of InputMethodContext.
154 * @param[in] actor The actor that uses the new InputMethodContext instance.
155 * @return A handle to the InputMethodContext.
157 static InputMethodContext New( Actor actor );
160 * @brief Finalize the InputMethodContext.
162 * It means that the context will be deleted.
167 * @brief Activate the input method context.
169 * It means that the text editing is started at somewhere.
170 * If the H/W keyboard isn't connected then it will show the virtual keyboard.
175 * @brief Deactivate the input method context.
177 * It means that the text editing is finished at somewhere.
182 * @brief Get the restoration status, which controls if the keyboard is restored after the focus lost then regained.
184 * If true then keyboard will be restored (activated) after focus is regained.
185 * @return restoration status.
187 bool RestoreAfterFocusLost() const;
190 * @brief Set status whether the input method context has to restore the keyboard after losing focus.
192 * @param[in] toggle True means that keyboard should be restored after focus lost and regained.
194 void SetRestoreAfterFocusLost( bool toggle );
197 * @brief Send message reset the pred-edit state / input method context module.
199 * Used to interupt pre-edit state maybe due to a touch input.
204 * @brief Notifies ImfContext that the cursor position has changed, required for features like auto-capitalisation.
206 void NotifyCursorPosition();
209 * @brief Sets cursor position stored in VirtualKeyboard, this is required by the ImfContext.
211 * @param[in] cursorPosition position of cursor
213 void SetCursorPosition( unsigned int cursorPosition );
216 * @brief Gets cursor position stored in VirtualKeyboard, this is required by the ImfContext.
218 * @return current position of cursor
220 unsigned int GetCursorPosition() const;
223 * @brief Method to store the string required by the input method context, this is used to provide predictive word suggestions.
225 * @param[in] text The text string surrounding the current cursor point.
227 void SetSurroundingText( const std::string& text );
230 * @brief Gets current text string set within the input method context, this is used to offer predictive suggestions.
232 * @return current position of cursor
234 const std::string& GetSurroundingText() const;
237 * @brief Notifies ImfContext that text input is set to multi line or not
239 void NotifyTextInputMultiLine( bool multiLine );
242 * @brief Set one or more of the Input Method options
243 * @param[in] options The options to be applied
245 void ApplyOptions( const InputMethodOptions& options );
248 * @brief Process event key down or up, whether filter a key to isf.
250 * @param[in] keyEvent The event key to be handled.
251 * @return Whether the event key is handled.
253 bool FilterEventKey( const Dali::KeyEvent& keyEvent );
260 * @brief This is emitted when the virtual keyboard is connected to or the hardware keyboard is activated.
262 * @return The input method context Activated signal.
264 ActivatedSignalType& ActivatedSignal();
267 * @brief This is emitted when the input method context receives an event.
269 * @return The Event signal containing the event data.
271 KeyboardEventSignalType& EventReceivedSignal();
274 * @brief Connect to this signal to be notified when the virtual keyboard is shown or hidden.
276 * @return The signal connect to status changed event.
278 StatusSignalType& StatusChangedSignal();
281 * @brief Connect to this signal to be notified when the virtual keyboard is resized.
283 * @return The signal to connect to resized event.
285 VoidSignalType& ResizedSignal();
288 * @brief Connect to this signal to be notified when the virtual keyboard's language is changed.
290 * @return The signal to connect to language changed event.
292 VoidSignalType& LanguageChangedSignal();
294 // Construction & Destruction
297 * @brief Constructor.
299 InputMethodContext();
304 * This is non-virtual since derived Handle types must not contain data or virtual methods.
306 ~InputMethodContext();
309 * @brief This constructor is used by InputMethodContext::Get().
311 * @param[in] inputMethodContext A pointer to the input method context.
313 explicit InputMethodContext( Internal::Adaptor::InputMethodContext* inputMethodContext );
318 #endif // DALI_TOOLKIT_TOOLKIT_INPUT_METHOD_CONTEXT_H