73e92c15dcec3bb1f72e0ea81da1a8e6175289a1
[platform/core/uifw/dali-adaptor.git] / adaptors / ecore / wayland / imf-manager-impl.h
1 #ifndef __DALI_INTERNAL_IMF_MANAGER_H
2 #define __DALI_INTERNAL_IMF_MANAGER_H
3
4 /*
5  * Copyright (c) 2014 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 #include <Ecore_IMF.h>
23 #include <Ecore.h>
24 #include <Ecore_Wayland.h>
25
26 #include <dali/public-api/common/vector-wrapper.h>
27 #include <dali/public-api/object/base-object.h>
28 #include <dali/integration-api/events/key-event-integ.h>
29
30 // INTERNAL INCLUDES
31 #include <imf-manager.h>
32
33 namespace Dali
34 {
35
36 class RenderSurface;
37
38 namespace Internal
39 {
40
41 namespace Adaptor
42 {
43
44 class DALI_IMPORT_API ImfManager : public Dali::BaseObject
45 {
46 public:
47   typedef Dali::ImfManager::ImfManagerSignalType ImfManagerSignalType;
48   typedef Dali::ImfManager::ImfEventSignalType ImfEventSignalType;
49   typedef Dali::ImfManager::StatusSignalType ImfStatusSignalType;
50   typedef Dali::ImfManager::VoidSignalType ImfVoidSignalType;
51
52 public:
53
54   /**
55    * Check whether the ImfManager is available.
56    * @return true if available, false otherwise
57    */
58   static bool IsAvailable();
59
60   /**
61    * Get the IMF manager instance, it creates the instance if it has not already been created.
62    * Internally, a check should be made using IsAvailable() before this is called as we do not want
63    * to create an instance if not needed by applications.
64    * @see IsAvailable()
65    */
66   static Dali::ImfManager Get();
67
68   /**
69    * Connect Callbacks required for IMF.
70    * If you don't connect imf callbacks, you can't get the key events.
71    * The events are PreeditChanged, Commit, DeleteSurrounding and PrivateCommand.
72    */
73   void ConnectCallbacks();
74
75   /**
76    * Disconnect Callbacks attached to imf context.
77    */
78   void DisconnectCallbacks();
79
80   /**
81    * @copydoc Dali::ImfManager::Activate()
82    */
83   void Activate();
84
85   /**
86    * @copydoc Dali::ImfManager::Deactivate()
87    */
88   void Deactivate();
89
90   /**
91    * @copydoc Dali::ImfManager::Reset()
92    */
93   void Reset();
94
95   /**
96    * @copydoc Dali::ImfManager::GetContext()
97    */
98   Ecore_IMF_Context* GetContext();
99
100   /**
101    * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
102    */
103   bool RestoreAfterFocusLost() const;
104
105   /**
106    * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
107    */
108   void SetRestoreAfterFocusLost( bool toggle );
109
110   /**
111    * @copydoc Dali::ImfManager::PreEditChanged()
112    */
113   void PreEditChanged( void *data, Ecore_IMF_Context *imfContext, void *event_info );
114
115   /**
116    * @copydoc Dali::ImfManager::NotifyCursorPosition()
117    */
118   void CommitReceived( void *data, Ecore_IMF_Context *imfContext, void *event_info );
119
120   /**
121    * @copydoc Dali::ImfManager::NotifyCursorPosition()
122    */
123   Eina_Bool RetrieveSurrounding( void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition );
124
125   /**
126    * @copydoc Dali::ImfManager::DeleteSurrounding()
127    */
128   void DeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *event_info );
129
130  /**
131   * @copydoc Dali::ImfManager::SendPrivateCommand()
132   */
133   void SendPrivateCommand( void* data, Ecore_IMF_Context* imfContext, void* event_info );
134
135   // Cursor related
136   /**
137    * @copydoc Dali::ImfManager::NotifyCursorPosition()
138    */
139   void NotifyCursorPosition();
140
141   /**
142    * @copydoc Dali::ImfManager::SetCursorPosition()
143    */
144   void SetCursorPosition( unsigned int cursorPosition );
145
146   /**
147    * @copydoc Dali::ImfManager::GetCursorPosition()
148    */
149   unsigned int GetCursorPosition() const;
150
151   /**
152    * @copydoc Dali::ImfManager::SetSurroundingText()
153    */
154   void SetSurroundingText( const std::string& text );
155
156   /**
157    * @copydoc Dali::ImfManager::GetSurroundingText()
158    */
159   const std::string& GetSurroundingText() const;
160
161   /**
162   * @copydoc Dali::ImfManager::NotifyTextInputMultiLine()
163   */
164   void NotifyTextInputMultiLine( bool multiLine );
165
166   /**
167   * @copydoc Dali::ImfManager::GetTextDirection()
168   */
169   Dali::ImfManager::TextDirection GetTextDirection();
170
171   /**
172   * @copydoc Dali::ImfManager::GetInputMethodArea()
173   */
174   Dali::Rect<int> GetInputMethodArea();
175
176   /**
177   * @copydoc Dali::ImfManager::ApplyOptions()
178   */
179   void ApplyOptions( const InputMethodOptions& options );
180
181   /**
182    * @copydoc Dali::ImfManager::SetInputPanelUserData()
183    */
184   void SetInputPanelUserData( const std::string& data );
185
186   /**
187    * @copydoc Dali::ImfManager::GetInputPanelUserData()
188    */
189   void GetInputPanelUserData( std::string& data );
190
191   /**
192    * @copydoc Dali::ImfManager::GetInputPanelState()
193    */
194   Dali::ImfManager::State GetInputPanelState();
195
196   /**
197    * @copydoc Dali::ImfManager::SetReturnKeyState()
198    */
199   void SetReturnKeyState( bool visible );
200
201   /**
202    * @copydoc Dali::ImfManager::AutoEnableInputPanel()
203    */
204   void AutoEnableInputPanel( bool enabled );
205
206   /**
207    * @copydoc Dali::ImfManager::ShowInputPanel()
208    */
209   void ShowInputPanel();
210
211   /**
212    * @copydoc Dali::ImfManager::HideInputPanel()
213    */
214   void HideInputPanel();
215
216 public:  // Signals
217
218   /**
219    * @copydoc Dali::ImfManager::ActivatedSignal()
220    */
221   ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
222
223   /**
224    * @copydoc Dali::ImfManager::EventReceivedSignal()
225    */
226   ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
227
228   /**
229    * @copydoc Dali::ImfManager::StatusChangedSignal()
230    */
231   ImfStatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
232
233   /**
234    * @copydoc Dali::ImfManager::ResizedSignal()
235    */
236   ImfVoidSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
237
238   /**
239    * @copydoc Dali::ImfManager::LanguageChangedSignal()
240    */
241   ImfVoidSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
242
243
244 protected:
245
246   /**
247    * Destructor.
248    */
249   virtual ~ImfManager();
250
251 private:
252   /**
253    * Context created the first time and kept until deleted.
254    * @param[in] ecoreWlwin, The window is created by application.
255    */
256   void CreateContext( Ecore_Wl_Window *ecoreWlwin );
257
258   /**
259    * @copydoc Dali::ImfManager::DeleteContext()
260    */
261   void DeleteContext();
262
263 private:
264   // Undefined
265   ImfManager( Ecore_Wl_Window *ecoreWlwin );
266   ImfManager( const ImfManager& );
267   ImfManager& operator=( ImfManager& );
268
269 private:
270   Ecore_IMF_Context* mIMFContext;
271   int mIMFCursorPosition;
272   std::string mSurroundingText;
273
274   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
275   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
276
277   std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
278   InputMethodOptions        mOptions;
279
280   ImfManagerSignalType      mActivatedSignal;
281   ImfEventSignalType        mEventSignal;
282   ImfStatusSignalType       mKeyboardStatusSignal;
283   ImfVoidSignalType         mKeyboardResizeSignal;
284   ImfVoidSignalType         mKeyboardLanguageChangedSignal;
285
286 public:
287
288 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
289 {
290   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
291
292   BaseObject& handle = imfManager.GetBaseObject();
293
294   return static_cast<Internal::Adaptor::ImfManager&>(handle);
295 }
296
297 inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
298 {
299   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
300
301   const BaseObject& handle = imfManager.GetBaseObject();
302
303   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
304 }
305
306 };
307
308
309 } // namespace Adaptor
310
311 } // namespace Internal
312
313 } // namespace Dali
314
315 #endif // __DALI_INTERNAL_IMF_MANAGER_H