Merge "Wayland IMF support" into devel/master
[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
59 public:
60
61   /**
62    * @brief Check whether the ImfManager is available.
63    * @return true if available, false otherwise
64    */
65   static bool IsAvailable();
66
67   /**
68    * @brief Get the IMF manager instance
69    * It creates the instance if it has not already been created.
70    * Internally, a check should be made using IsAvailable() before this is called as we do not want
71    * to create an instance if not needed by applications.
72    * @see IsAvailable()
73    * @return handle to ImfManager
74    */
75   static Dali::ImfManager Get();
76
77   /**
78    * @brief Constructor
79    */
80   ImfManager();
81
82   /**
83    * Connect Callbacks required for IMF.
84    * If you don't connect imf callbacks, you can't get the key events.
85    * The events are PreeditChanged, Commit and DeleteSurrounding.
86    */
87   void ConnectCallbacks();
88
89   /**
90    * @brief Disconnect Callbacks attached to imf context.
91    */
92   void DisconnectCallbacks();
93
94   /**
95    * @copydoc Dali::ImfManager::Activate()
96    */
97   void Activate();
98
99   /**
100    * @copydoc Dali::ImfManager::Deactivate()
101    */
102   void Deactivate();
103
104   /**
105    * @copydoc Dali::ImfManager::Reset()
106    */
107   void Reset();
108
109   /**
110    * @copydoc Dali::ImfManager::GetContext()
111    */
112   void* GetContext();
113
114   /**
115    * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
116    */
117   bool RestoreAfterFocusLost() const;
118
119   /**
120    * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
121    */
122   void SetRestoreAfterFocusLost( bool toggle );
123
124
125   // Cursor related
126   /**
127    * @copydoc Dali::ImfManager::NotifyCursorPosition()
128    */
129   void NotifyCursorPosition();
130
131   /**
132    * @copydoc Dali::ImfManager::SetCursorPosition()
133    */
134   void SetCursorPosition( unsigned int cursorPosition );
135
136   /**
137    * @copydoc Dali::ImfManager::GetCursorPosition()
138    */
139   unsigned int GetCursorPosition() const;
140
141   /**
142    * @copydoc Dali::ImfManager::SetSurroundingText()
143    */
144   void SetSurroundingText( const std::string& text );
145
146   /**
147    * @copydoc Dali::ImfManager::GetSurroundingText()
148    */
149   const std::string& GetSurroundingText() const;
150
151 public:  // Signals
152
153   /**
154    * @copydoc Dali::ImfManager::ActivatedSignal()
155    */
156   ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
157
158   /**
159    * @copydoc Dali::ImfManager::EventReceivedSignal()
160    */
161   ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
162
163   /**
164    * @brief Called when an IMF Pre-Edit change event is received.
165    * We are still predicting what the user is typing.  The latest string is what the IMF module thinks
166    * the user wants to type.
167    *
168    * @param[in] serial event serial
169    * @param[in] text pre-edit string
170    * @param[in] commit commit string
171    */
172   void PreEditStringChange( unsigned int serial, const std::string text, const std::string commit );
173
174   /**
175    * @brief Called when an IMF Pre-Edit cursor event is received.
176    * @param[in] cursor cursor position
177    */
178   void PreEditCursorChange( int cursor );
179
180   /**
181    * @brief called when IMF tell us to commit the text
182    * @param[in] serial event serial
183    * @param[in] commit text to commit
184    */
185   void CommitString( unsigned int serial, const std::string commit );
186
187   /**
188    * @brief called when deleting surround text
189    * @param[in] index character index to start deleting from
190    * @param[in] length number of characters to delete
191    */
192   void DeleteSurroundingText( int index, unsigned int length );
193
194 protected:
195
196   /**
197    * @brief Destructor.
198    */
199   virtual ~ImfManager();
200
201
202 private:
203
204   ImfManagerSignalType      mActivatedSignal;
205   ImfEventSignalType        mEventSignal;
206
207   // Undefined
208   ImfManager( const ImfManager& );
209   ImfManager& operator=( ImfManager& );
210
211 private:
212
213   TextInputManager& mTextInputManager;
214   std::string mSurroundingText;
215   int mPreEditCursorPosition;
216   int mEditCursorPosition;
217   bool mRestoreAfterFocusLost:1;  ///< Whether the keyboard needs to be restored (activated ) after focus regained.
218
219 public:
220
221 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
222 {
223   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
224
225   BaseObject& handle = imfManager.GetBaseObject();
226
227   return static_cast<Internal::Adaptor::ImfManager&>(handle);
228 }
229
230 inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
231 {
232   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
233
234   const BaseObject& handle = imfManager.GetBaseObject();
235
236   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
237 }
238
239 };
240
241
242 } // namespace Adaptor
243
244 } // namespace Internal
245
246 } // namespace Dali
247
248 #endif // __DALI_INTERNAL_IMF_MANAGER_WL_H