Merge "DALi Version 1.2.1" 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   /**
152   * @copydoc Dali::ImfManager::NotifyTextInputMultiLine()
153   */
154   void NotifyTextInputMultiLine( bool multiLine );
155
156 public:  // Signals
157
158   /**
159    * @copydoc Dali::ImfManager::ActivatedSignal()
160    */
161   ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
162
163   /**
164    * @copydoc Dali::ImfManager::EventReceivedSignal()
165    */
166   ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
167
168   /**
169    * @brief Called when an IMF Pre-Edit change event is received.
170    * We are still predicting what the user is typing.  The latest string is what the IMF module thinks
171    * the user wants to type.
172    *
173    * @param[in] serial event serial
174    * @param[in] text pre-edit string
175    * @param[in] commit commit string
176    */
177   void PreEditStringChange( unsigned int serial, const std::string text, const std::string commit );
178
179   /**
180    * @brief Called when an IMF Pre-Edit cursor event is received.
181    * @param[in] cursor cursor position
182    */
183   void PreEditCursorChange( int cursor );
184
185   /**
186    * @brief called when IMF tell us to commit the text
187    * @param[in] serial event serial
188    * @param[in] commit text to commit
189    */
190   void CommitString( unsigned int serial, const std::string commit );
191
192   /**
193    * @brief called when deleting surround text
194    * @param[in] index character index to start deleting from
195    * @param[in] length number of characters to delete
196    */
197   void DeleteSurroundingText( int index, unsigned int length );
198
199 protected:
200
201   /**
202    * @brief Destructor.
203    */
204   virtual ~ImfManager();
205
206
207 private:
208
209   ImfManagerSignalType      mActivatedSignal;
210   ImfEventSignalType        mEventSignal;
211
212   // Undefined
213   ImfManager( const ImfManager& );
214   ImfManager& operator=( ImfManager& );
215
216 private:
217
218   TextInputManager& mTextInputManager;
219   std::string mSurroundingText;
220   int mPreEditCursorPosition;
221   int mEditCursorPosition;
222   bool mRestoreAfterFocusLost:1;  ///< Whether the keyboard needs to be restored (activated ) after focus regained.
223
224 public:
225
226 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
227 {
228   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
229
230   BaseObject& handle = imfManager.GetBaseObject();
231
232   return static_cast<Internal::Adaptor::ImfManager&>(handle);
233 }
234
235 inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
236 {
237   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
238
239   const BaseObject& handle = imfManager.GetBaseObject();
240
241   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
242 }
243
244 };
245
246
247 } // namespace Adaptor
248
249 } // namespace Internal
250
251 } // namespace Dali
252
253 #endif // __DALI_INTERNAL_IMF_MANAGER_WL_H