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