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