1 #ifndef __DALI_INTERNAL_IMF_MANAGER_WL_H
2 #define __DALI_INTERNAL_IMF_MANAGER_WL_H
5 * Copyright (c) 2016 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.
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/integration-api/events/key-event-integ.h>
27 #include <imf-manager.h>
28 #include "../text-input-manager.h"
44 * Handles text input editing with the virtual keyboard.
45 * The Tizen 3 Wayland text interface is still in development so some
46 * features are not available to test like text prediction.
47 * When this available we may need to add / test wl_text_input_commit_state
49 * To debug low level communication to the Wayland Compositor (Enlightenment) use environment variable
50 * export WAYLAND_DEBUG=1
53 class ImfManager : public Dali::BaseObject, public ConnectionTracker
56 typedef Dali::ImfManager::ImfManagerSignalType ImfManagerSignalType;
57 typedef Dali::ImfManager::ImfEventSignalType ImfEventSignalType;
62 * @brief Check whether the ImfManager is available.
63 * @return true if available, false otherwise
65 static bool IsAvailable();
68 * @brief Get the IMF manager instance
69 * It creates the instance if it has not already been created.
70 * Internally, a check should be made using IsAvailable() before this is called as we do not want
71 * to create an instance if not needed by applications.
73 * @return handle to ImfManager
75 static Dali::ImfManager Get();
83 * Connect Callbacks required for IMF.
84 * If you don't connect imf callbacks, you can't get the key events.
85 * The events are PreeditChanged, Commit and DeleteSurrounding.
87 void ConnectCallbacks();
90 * @brief Disconnect Callbacks attached to imf context.
92 void DisconnectCallbacks();
95 * @copydoc Dali::ImfManager::Activate()
100 * @copydoc Dali::ImfManager::Deactivate()
105 * @copydoc Dali::ImfManager::Reset()
110 * @copydoc Dali::ImfManager::GetContext()
115 * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
117 bool RestoreAfterFocusLost() const;
120 * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
122 void SetRestoreAfterFocusLost( bool toggle );
127 * @copydoc Dali::ImfManager::NotifyCursorPosition()
129 void NotifyCursorPosition();
132 * @copydoc Dali::ImfManager::SetCursorPosition()
134 void SetCursorPosition( unsigned int cursorPosition );
137 * @copydoc Dali::ImfManager::GetCursorPosition()
139 unsigned int GetCursorPosition() const;
142 * @copydoc Dali::ImfManager::SetSurroundingText()
144 void SetSurroundingText( const std::string& text );
147 * @copydoc Dali::ImfManager::GetSurroundingText()
149 const std::string& GetSurroundingText() const;
154 * @copydoc Dali::ImfManager::ActivatedSignal()
156 ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
159 * @copydoc Dali::ImfManager::EventReceivedSignal()
161 ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
164 * @brief Called when an IMF Pre-Edit change event is received.
165 * We are still predicting what the user is typing. The latest string is what the IMF module thinks
166 * the user wants to type.
168 * @param[in] serial event serial
169 * @param[in] text pre-edit string
170 * @param[in] commit commit string
172 void PreEditStringChange( unsigned int serial, const std::string text, const std::string commit );
175 * @brief Called when an IMF Pre-Edit cursor event is received.
176 * @param[in] cursor cursor position
178 void PreEditCursorChange( int cursor );
181 * @brief called when IMF tell us to commit the text
182 * @param[in] serial event serial
183 * @param[in] commit text to commit
185 void CommitString( unsigned int serial, const std::string commit );
188 * @brief called when deleting surround text
189 * @param[in] index character index to start deleting from
190 * @param[in] length number of characters to delete
192 void DeleteSurroundingText( int index, unsigned int length );
199 virtual ~ImfManager();
204 ImfManagerSignalType mActivatedSignal;
205 ImfEventSignalType mEventSignal;
208 ImfManager( const ImfManager& );
209 ImfManager& operator=( ImfManager& );
213 TextInputManager& mTextInputManager;
214 std::string mSurroundingText;
215 int mPreEditCursorPosition;
216 int mEditCursorPosition;
217 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
221 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
223 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
225 BaseObject& handle = imfManager.GetBaseObject();
227 return static_cast<Internal::Adaptor::ImfManager&>(handle);
230 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
232 DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
234 const BaseObject& handle = imfManager.GetBaseObject();
236 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
242 } // namespace Adaptor
244 } // namespace Internal
248 #endif // __DALI_INTERNAL_IMF_MANAGER_WL_H