1 #ifndef __DALI_TOOLKIT_TOOLKIT_INPUT_METHOD_CONTEXT_H__
2 #define __DALI_TOOLKIT_TOOLKIT_INPUT_METHOD_CONTEXT_H__
5 * Copyright (c) 2018 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/object/base-handle.h>
24 #include <dali/public-api/signals/dali-signal.h>
25 #include <dali/devel-api/adaptor-framework/input-method-options.h>
26 #include <dali/public-api/events/key-event.h>
28 namespace Dali DALI_IMPORT_API
31 namespace Internal DALI_INTERNAL
35 class InputMethodContext;
40 * @brief The InputMethodContext class
42 * Specifically manages the ecore input method framework which enables the virtual or hardware keyboards.
44 class InputMethodContext : public BaseHandle
49 * @brief Events that are generated by the input method context.
54 PRE_EDIT, ///< Pre-Edit changed
55 COMMIT, ///< Commit recieved
56 DELETE_SURROUNDING, ///< Event to delete a range of characters from the string
57 GET_SURROUNDING, ///< Event to query string and cursor position
58 PRIVATE_COMMAND ///< Private command sent from the input panel
62 * @brief This structure is used to pass on data from the input method cotext regarding predictive text.
67 * @brief Default Constructor.
80 * @param[in] aEventName The name of the event from the input method context.
81 * @param[in] aPredictiveString The pre-edit or commit string.
82 * @param[in] aCursorOffset Start position from the current cursor position to start deleting characters.
83 * @param[in] aNumberOfChars The number of characters to delete from the cursorOffset.
85 EventData( EventType aEventName, const std::string& aPredictiveString, int aCursorOffset, int aNumberOfChars )
86 : predictiveString( aPredictiveString ),
87 eventName( aEventName ),
88 cursorOffset( aCursorOffset ),
89 numberOfChars( aNumberOfChars )
94 std::string predictiveString; ///< The pre-edit or commit string.
95 EventType eventName; ///< The name of the event from the input method context.
96 int cursorOffset; ///< Start position from the current cursor position to start deleting characters.
97 int numberOfChars; ///< number of characters to delete from the cursorOffset.
101 * @brief Data required by input method context from the callback
112 preeditResetRequired( false )
118 * @param[in] aUpdate True if cursor position needs to be updated
119 * @param[in] aCursorPosition new position of cursor
120 * @param[in] aCurrentText current text string
121 * @param[in] aPreeditResetRequired flag if preedit reset is required.
123 CallbackData( bool aUpdate, int aCursorPosition, const std::string& aCurrentText, bool aPreeditResetRequired )
124 : currentText( aCurrentText ),
125 cursorPosition( aCursorPosition ),
127 preeditResetRequired( aPreeditResetRequired )
131 std::string currentText; ///< current text string
132 int cursorPosition; ///< new position of cursor
133 bool update :1; ///< if cursor position needs to be updated
134 bool preeditResetRequired :1; ///< flag if preedit reset is required.
137 typedef Signal< void (InputMethodContext&) > ActivatedSignalType; ///< Keyboard actived signal
138 typedef Signal< CallbackData ( InputMethodContext&, const EventData& ) > KeyboardEventSignalType; ///< keyboard events
139 typedef Signal< void () > VoidSignalType;
140 typedef Signal< void (bool) > StatusSignalType;
145 * @brief Create a handle to the instance of InputMethodContext.
146 * @return A handle to the InputMethodContext.
148 static InputMethodContext New();
151 * @brief Finalize the InputMethodContext.
153 * It means that the context will be deleted.
158 * @brief Activate the input method context.
160 * It means that the text editing is started at somewhere.
161 * If the H/W keyboard isn't connected then it will show the virtual keyboard.
166 * @brief Deactivate the input method context.
168 * It means that the text editing is finished at somewhere.
173 * @brief Get the restoration status, which controls if the keyboard is restored after the focus lost then regained.
175 * If true then keyboard will be restored (activated) after focus is regained.
176 * @return restoration status.
178 bool RestoreAfterFocusLost() const;
181 * @brief Set status whether the input method context has to restore the keyboard after losing focus.
183 * @param[in] toggle True means that keyboard should be restored after focus lost and regained.
185 void SetRestoreAfterFocusLost( bool toggle );
188 * @brief Send message reset the pred-edit state / input method context module.
190 * Used to interupt pre-edit state maybe due to a touch input.
195 * @brief Notifies ImfContext that the cursor position has changed, required for features like auto-capitalisation.
197 void NotifyCursorPosition();
200 * @brief Sets cursor position stored in VirtualKeyboard, this is required by the ImfContext.
202 * @param[in] cursorPosition position of cursor
204 void SetCursorPosition( unsigned int cursorPosition );
207 * @brief Gets cursor position stored in VirtualKeyboard, this is required by the ImfContext.
209 * @return current position of cursor
211 unsigned int GetCursorPosition() const;
214 * @brief Method to store the string required by the input method context, this is used to provide predictive word suggestions.
216 * @param[in] text The text string surrounding the current cursor point.
218 void SetSurroundingText( const std::string& text );
221 * @brief Gets current text string set within the input method context, this is used to offer predictive suggestions.
223 * @return current position of cursor
225 const std::string& GetSurroundingText() const;
228 * @brief Notifies ImfContext that text input is set to multi line or not
230 void NotifyTextInputMultiLine( bool multiLine );
233 * @brief Set one or more of the Input Method options
234 * @param[in] options The options to be applied
236 void ApplyOptions( const InputMethodOptions& options );
239 * @brief Process event key down or up, whether filter a key to isf.
241 * @param[in] keyEvent The event key to be handled.
242 * @return Whether the event key is handled.
244 bool FilterEventKey( const Dali::KeyEvent& keyEvent );
251 * @brief This is emitted when the virtual keyboard is connected to or the hardware keyboard is activated.
253 * @return The input method context Activated signal.
255 ActivatedSignalType& ActivatedSignal();
258 * @brief This is emitted when the input method context receives an event.
260 * @return The Event signal containing the event data.
262 KeyboardEventSignalType& EventReceivedSignal();
265 * @brief Connect to this signal to be notified when the virtual keyboard is shown or hidden.
267 * @return The signal connect to status changed event.
269 StatusSignalType& StatusChangedSignal();
272 * @brief Connect to this signal to be notified when the virtual keyboard is resized.
274 * @return The signal to connect to resized event.
276 VoidSignalType& ResizedSignal();
279 * @brief Connect to this signal to be notified when the virtual keyboard's language is changed.
281 * @return The signal to connect to language changed event.
283 VoidSignalType& LanguageChangedSignal();
285 // Construction & Destruction
288 * @brief Constructor.
290 InputMethodContext();
295 * This is non-virtual since derived Handle types must not contain data or virtual methods.
297 ~InputMethodContext();
300 * @brief This constructor is used by InputMethodContext::Get().
302 * @param[in] inputMethodContext A pointer to the input method context.
304 explicit InputMethodContext( Internal::Adaptor::InputMethodContext* inputMethodContext );
309 #endif // __DALI_TOOLKIT_TOOLKIT_INPUT_METHOD_CONTEXT_H__