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