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