5 * Copyright (c) 2014 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 * @addtogroup CAPI_DALI_ADAPTOR_MODULE
27 #include <dali/public-api/object/base-handle.h>
28 #include <dali/public-api/signals/dali-signal-v2.h>
30 namespace Dali DALI_IMPORT_API
33 namespace Internal DALI_INTERNAL
41 // TODO: Temporary patch to hidden ecore dependency. Must fix it.
42 typedef void* ImfContext;
45 * @brief The ImfManager class
47 * Specifically manages the ecore input method framework which enables the virtual or hardware keyboards.
49 class ImfManager : public BaseHandle
54 * @brief Events that are generated by the IMF.
59 PREEDIT, ///< Pre-Edit changed
60 COMMIT, ///< Commit recieved
61 DELETESURROUNDING, ///< Event to delete a range of characters from the string
62 GETSURROUNDING ///< Event to query string and cursor position
66 * @brief This structure is used to pass on data from the IMF regarding predictive text.
71 * @brief Default Constructor.
84 * @param[in] aEventName The name of the event from the IMF.
85 * @param[in] aPredictiveString The pre-edit or commit string.
86 * @param[in] aCursorOffset Start position from the current cursor position to start deleting characters.
87 * @param[in] aNumberOfChars The number of characters to delete from the cursorOffset.
89 ImfEventData(ImfEvent aEventName, const std::string& aPredictiveString, int aCursorOffset,int aNumberOfChars )
90 : eventName(aEventName), predictiveString(aPredictiveString), cursorOffset( aCursorOffset ), numberOfChars( aNumberOfChars )
95 ImfEvent eventName; ///< The name of the event from the IMF.
96 std::string predictiveString; ///< The pre-edit or commit string.
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 IMF from the callback
104 struct ImfCallbackData
110 : update( false ), cursorPosition( 0 ), preeditResetRequired ( false )
116 * @param[in] aUpdate True if cursor position needs to be updated
117 * @param[in] aCursorPosition new position of cursor
118 * @param[in] aCurrentText current text string
119 * @param[in] aPreeditResetRequired flag if preedit reset is required.
121 ImfCallbackData(bool aUpdate, int aCursorPosition, std::string aCurrentText, bool aPreeditResetRequired )
122 : update(aUpdate), cursorPosition(aCursorPosition), currentText( aCurrentText ), preeditResetRequired( aPreeditResetRequired )
126 bool update; ///< if cursor position needs to be updated
127 int cursorPosition; ///< new position of cursor
128 std::string currentText; ///< current text string
129 bool preeditResetRequired; ///< flag if preedit reset is required.
132 typedef SignalV2< void (ImfManager&) > ImfManagerSignalV2; ///< Keyboard actived signal
134 typedef SignalV2< ImfCallbackData ( ImfManager&, const ImfEventData& ) > ImfEventSignalV2; ///< keyboard events
139 * @brief Retrieve a handle to the instance of ImfManager.
140 * @return A handle to the ImfManager.
142 static ImfManager Get();
145 * @brief Get the current imf context.
146 * @return current imf context.
148 ImfContext GetContext();
151 * @brief Activate the IMF.
153 * It means that the text editing is started at somewhere.
154 * If the H/W keyboard isn't connected then it will show the virtual keyboard.
159 * @brief Deactivate the IMF.
161 * It means that the text editing is finished at somewhere.
166 * @brief Get the restoration status, which controls if the keyboard is restored after the focus lost then regained.
168 * If true then keyboard will be restored (activated) after focus is regained.
169 * @return restoration status.
171 bool RestoreAfterFocusLost() const;
174 * @brief Set status whether the IMF has to restore the keyboard after losing focus.
176 * @param[in] toggle True means that keyboard should be restored after focus lost and regained.
178 void SetRestoreAferFocusLost( bool toggle );
181 * @brief Send message reset the pred-edit state / imf module.
183 * Used to interupt pre-edit state maybe due to a touch input.
188 * @brief Notifies IMF context that the cursor position has changed, required for features like auto-capitalisation.
190 void NotifyCursorPosition();
193 * @brief Sets cursor position stored in VirtualKeyboard, this is required by the IMF context.
195 * @param[in] cursorPosition position of cursor
197 void SetCursorPosition( unsigned int cursorPosition );
200 * @brief Gets cursor position stored in VirtualKeyboard, this is required by the IMF context.
202 * @return current position of cursor
204 int GetCursorPosition();
207 * @brief Method to store the string required by the IMF, this is used to provide predictive word suggestions.
209 * @param[in] text The text string surrounding the current cursor point.
211 void SetSurroundingText( std::string text );
214 * @brief Gets current text string set within the IMF manager, this is used to offer predictive suggestions.
216 * @return current position of cursor
218 std::string GetSurroundingText();
225 * @brief This is emitted when the virtual keyboard is connected to or the hardware keyboard is activated.
227 * @return The IMF Activated signal.
229 ImfManagerSignalV2& ActivatedSignal();
232 * @brief This is emitted when the IMF manager receives an event from the IMF.
234 * @return The Event signal containing the event data.
236 ImfEventSignalV2& EventReceivedSignal();
238 // Construction & Destruction
241 * @brief Constructor.
248 * This is non-virtual since derived Handle types must not contain data or virtual methods.
253 * @brief This constructor is used by ImfManager::Get().
255 * @param[in] imfManager A pointer to the imf Manager.
257 ImfManager( Internal::Adaptor::ImfManager* imfManager );
265 #endif // IMFMANAGER_H