f93cfe55f5b1c52c3e9fae2dd77615485acde7f6
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / input / text / imf / imf-manager-impl.h
1 #ifndef __DALI_INTERNAL_IMF_MANAGER_WL_H
2 #define __DALI_INTERNAL_IMF_MANAGER_WL_H
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25
26 // INTERNAL INCLUDES
27 #include <imf-manager.h>
28 #include "../text-input-manager.h"
29
30 namespace Dali
31 {
32
33 class RenderSurface;
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40
41 /**
42  * @brief ImfManager
43  *
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
48  *
49  * To debug low level communication to the Wayland Compositor (Enlightenment)  use environment variable
50  * export WAYLAND_DEBUG=1
51  *
52  */
53 class ImfManager : public Dali::BaseObject, public ConnectionTracker
54 {
55 public:
56   typedef Dali::ImfManager::ImfManagerSignalType ImfManagerSignalType;
57   typedef Dali::ImfManager::ImfEventSignalType ImfEventSignalType;
58   typedef Dali::ImfManager::StatusSignalType ImfStatusSignalType;
59   typedef Dali::ImfManager::VoidSignalType ImfVoidSignalType;
60   typedef Dali::ImfManager::KeyboardTypeSignalType ImfKeyboardTypeSignalType;
61
62 public:
63
64   /**
65    * @brief Check whether the ImfManager is available.
66    * @return true if available, false otherwise
67    */
68   static bool IsAvailable();
69
70   /**
71    * @brief Get the IMF manager instance
72    * It creates the instance if it has not already been created.
73    * Internally, a check should be made using IsAvailable() before this is called as we do not want
74    * to create an instance if not needed by applications.
75    * @see IsAvailable()
76    * @return handle to ImfManager
77    */
78   static Dali::ImfManager Get();
79
80   /**
81    * @brief Constructor
82    */
83   ImfManager();
84
85   /**
86    * Connect Callbacks required for IMF.
87    * If you don't connect imf callbacks, you can't get the key events.
88    * The events are PreeditChanged, Commit and DeleteSurrounding.
89    */
90   void ConnectCallbacks();
91
92   /**
93    * @brief Disconnect Callbacks attached to imf context.
94    */
95   void DisconnectCallbacks();
96
97   /**
98    * @copydoc Dali::ImfManager::Activate()
99    */
100   void Activate();
101
102   /**
103    * @copydoc Dali::ImfManager::Deactivate()
104    */
105   void Deactivate();
106
107   /**
108    * @copydoc Dali::ImfManager::Reset()
109    */
110   void Reset();
111
112   /**
113    * @copydoc Dali::ImfManager::GetContext()
114    */
115   void* GetContext();
116
117   /**
118    * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
119    */
120   bool RestoreAfterFocusLost() const;
121
122   /**
123    * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
124    */
125   void SetRestoreAfterFocusLost( bool toggle );
126
127
128   // Cursor related
129   /**
130    * @copydoc Dali::ImfManager::NotifyCursorPosition()
131    */
132   void NotifyCursorPosition();
133
134   /**
135    * @copydoc Dali::ImfManager::SetCursorPosition()
136    */
137   void SetCursorPosition( unsigned int cursorPosition );
138
139   /**
140    * @copydoc Dali::ImfManager::GetCursorPosition()
141    */
142   unsigned int GetCursorPosition() const;
143
144   /**
145    * @copydoc Dali::ImfManager::SetSurroundingText()
146    */
147   void SetSurroundingText( const std::string& text );
148
149   /**
150    * @copydoc Dali::ImfManager::GetSurroundingText()
151    */
152   const std::string& GetSurroundingText() const;
153
154   /**
155   * @copydoc Dali::ImfManager::NotifyTextInputMultiLine()
156   */
157   void NotifyTextInputMultiLine( bool multiLine );
158
159   /**
160   * @copydoc Dali::ImfManager::GetTextDirection()
161   */
162   Dali::ImfManager::TextDirection GetTextDirection();
163
164   /**
165   * @copydoc Dali::ImfManager::GetInputMethodArea()
166   */
167   Dali::Rect<int> GetInputMethodArea();
168
169   /**
170   * @copydoc Dali::ImfManager::ApplyOptions()
171   */
172   void ApplyOptions( const InputMethodOptions& options );
173
174   /**
175    * @copydoc Dali::ImfManager::SetInputPanelUserData()
176    */
177   void SetInputPanelUserData( const std::string& data );
178
179   /**
180    * @copydoc Dali::ImfManager::GetInputPanelUserData()
181    */
182   void GetInputPanelUserData( std::string& data );
183
184   /**
185    * @copydoc Dali::ImfManager::GetInputPanelState()
186    */
187   Dali::ImfManager::State GetInputPanelState();
188
189   /**
190    * @copydoc Dali::ImfManager::SetReturnKeyState()
191    */
192   void SetReturnKeyState( bool visible );
193
194   /**
195    * @copydoc Dali::ImfManager::AutoEnableInputPanel()
196    */
197   void AutoEnableInputPanel( bool enabled );
198
199   /**
200    * @copydoc Dali::ImfManager::ShowInputPanel()
201    */
202   void ShowInputPanel();
203
204   /**
205    * @copydoc Dali::ImfManager::HideInputPanel()
206    */
207   void HideInputPanel();
208
209   /**
210    * @copydoc Dali::ImfManager::GetKeyboardType()
211    */
212   Dali::ImfManager::KeyboardType GetKeyboardType();
213
214   /**
215    * @copydoc Dali::ImfManager::GetInputPanelLocale()
216    */
217   std::string GetInputPanelLocale();
218
219 public:  // Signals
220
221   /**
222    * @copydoc Dali::ImfManager::ActivatedSignal()
223    */
224   ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
225
226   /**
227    * @copydoc Dali::ImfManager::EventReceivedSignal()
228    */
229   ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
230
231   /**
232    * @copydoc Dali::ImfManager::StatusChangedSignal()
233    */
234   ImfStatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
235
236   /**
237    * @copydoc Dali::ImfManager::ResizedSignal()
238    */
239   ImfVoidSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
240
241   /**
242    * @copydoc Dali::ImfManager::LanguageChangedSignal()
243    */
244   ImfVoidSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
245
246   /**
247    * @copydoc Dali::ImfManager::KeyboardTypeChangedSignal()
248    */
249   ImfKeyboardTypeSignalType& KeyboardTypeChangedSignal() { return mKeyboardTypeChangedSignal; }
250
251   /**
252    * @brief Called when an IMF Pre-Edit change event is received.
253    * We are still predicting what the user is typing.  The latest string is what the IMF module thinks
254    * the user wants to type.
255    *
256    * @param[in] serial event serial
257    * @param[in] text pre-edit string
258    * @param[in] commit commit string
259    */
260   void PreEditStringChange( unsigned int serial, const std::string text, const std::string commit );
261
262   /**
263    * @brief Called when an IMF Pre-Edit cursor event is received.
264    * @param[in] cursor cursor position
265    */
266   void PreEditCursorChange( int cursor );
267
268   /**
269    * @brief called when IMF tell us to commit the text
270    * @param[in] serial event serial
271    * @param[in] commit text to commit
272    */
273   void CommitString( unsigned int serial, const std::string commit );
274
275   /**
276    * @brief called when deleting surround text
277    * @param[in] index character index to start deleting from
278    * @param[in] length number of characters to delete
279    */
280   void DeleteSurroundingText( int index, unsigned int length );
281
282 protected:
283
284   /**
285    * @brief Destructor.
286    */
287   virtual ~ImfManager();
288
289
290 private:
291
292   ImfManagerSignalType       mActivatedSignal;
293   ImfEventSignalType         mEventSignal;
294   ImfStatusSignalType        mKeyboardStatusSignal;
295   ImfVoidSignalType          mKeyboardResizeSignal;
296   ImfVoidSignalType          mKeyboardLanguageChangedSignal;
297   ImfKeyboardTypeSignalType  mKeyboardTypeChangedSignal;
298
299   // Undefined
300   ImfManager( const ImfManager& );
301   ImfManager& operator=( ImfManager& );
302
303 private:
304
305   TextInputManager& mTextInputManager;
306   std::string mSurroundingText;
307   int mPreEditCursorPosition;
308   int mEditCursorPosition;
309   bool mRestoreAfterFocusLost:1;  ///< Whether the keyboard needs to be restored (activated ) after focus regained.
310
311 public:
312
313 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
314 {
315   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
316
317   BaseObject& handle = imfManager.GetBaseObject();
318
319   return static_cast<Internal::Adaptor::ImfManager&>(handle);
320 }
321
322 inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
323 {
324   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
325
326   const BaseObject& handle = imfManager.GetBaseObject();
327
328   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
329 }
330
331 };
332
333
334 } // namespace Adaptor
335
336 } // namespace Internal
337
338 } // namespace Dali
339
340 #endif // __DALI_INTERNAL_IMF_MANAGER_WL_H