726060bf0da38a40b5cdd61e9812e8f114593b1d
[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 public:  // Signals
174
175   /**
176    * @copydoc Dali::ImfManager::ActivatedSignal()
177    */
178   ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
179
180   /**
181    * @copydoc Dali::ImfManager::EventReceivedSignal()
182    */
183   ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
184
185   /**
186    * @copydoc Dali::ImfManager::StatusChangedSignal()
187    */
188   ImfStatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
189
190   /**
191    * @copydoc Dali::ImfManager::ResizedSignal()
192    */
193   ImfVoidSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
194
195   /**
196    * @copydoc Dali::ImfManager::LanguageChangedSignal()
197    */
198   ImfVoidSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
199
200
201   /**
202    * @brief Called when an IMF Pre-Edit change event is received.
203    * We are still predicting what the user is typing.  The latest string is what the IMF module thinks
204    * the user wants to type.
205    *
206    * @param[in] serial event serial
207    * @param[in] text pre-edit string
208    * @param[in] commit commit string
209    */
210   void PreEditStringChange( unsigned int serial, const std::string text, const std::string commit );
211
212   /**
213    * @brief Called when an IMF Pre-Edit cursor event is received.
214    * @param[in] cursor cursor position
215    */
216   void PreEditCursorChange( int cursor );
217
218   /**
219    * @brief called when IMF tell us to commit the text
220    * @param[in] serial event serial
221    * @param[in] commit text to commit
222    */
223   void CommitString( unsigned int serial, const std::string commit );
224
225   /**
226    * @brief called when deleting surround text
227    * @param[in] index character index to start deleting from
228    * @param[in] length number of characters to delete
229    */
230   void DeleteSurroundingText( int index, unsigned int length );
231
232 protected:
233
234   /**
235    * @brief Destructor.
236    */
237   virtual ~ImfManager();
238
239
240 private:
241
242   ImfManagerSignalType      mActivatedSignal;
243   ImfEventSignalType        mEventSignal;
244   ImfStatusSignalType       mKeyboardStatusSignal;
245   ImfVoidSignalType         mKeyboardResizeSignal;
246   ImfVoidSignalType         mKeyboardLanguageChangedSignal;
247
248   // Undefined
249   ImfManager( const ImfManager& );
250   ImfManager& operator=( ImfManager& );
251
252 private:
253
254   TextInputManager& mTextInputManager;
255   std::string mSurroundingText;
256   int mPreEditCursorPosition;
257   int mEditCursorPosition;
258   bool mRestoreAfterFocusLost:1;  ///< Whether the keyboard needs to be restored (activated ) after focus regained.
259
260 public:
261
262 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
263 {
264   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
265
266   BaseObject& handle = imfManager.GetBaseObject();
267
268   return static_cast<Internal::Adaptor::ImfManager&>(handle);
269 }
270
271 inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
272 {
273   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
274
275   const BaseObject& handle = imfManager.GetBaseObject();
276
277   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
278 }
279
280 };
281
282
283 } // namespace Adaptor
284
285 } // namespace Internal
286
287 } // namespace Dali
288
289 #endif // __DALI_INTERNAL_IMF_MANAGER_WL_H