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