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