[4.0] Add ImfManager KeyboardResizedSignalType and LanguageChangedSignalType
[platform/core/uifw/dali-adaptor.git] / adaptors / integration-api / x11 / 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_X.h>
24
25 #include <dali/public-api/object/base-object.h>
26
27 // INTERNAL INCLUDES
28 #include <imf-manager.h>
29
30 namespace Dali
31 {
32
33 class RenderSurface;
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40
41 class DALI_IMPORT_API ImfManager : public Dali::BaseObject
42 {
43 public:
44   typedef Dali::ImfManager::ImfManagerSignalType ImfManagerSignalType;
45   typedef Dali::ImfManager::ImfEventSignalType ImfEventSignalType;
46   typedef Dali::ImfManager::StatusSignalType ImfStatusSignalType;
47   typedef Dali::ImfManager::VoidSignalType ImfVoidSignalType;
48   typedef Dali::ImfManager::KeyboardTypeSignalType ImfKeyboardTypeSignalType;
49   typedef Dali::ImfManager::KeyboardResizedSignalType KeyboardResizedSignalType;
50   typedef Dali::ImfManager::LanguageChangedSignalType LanguageChangedSignalType;
51
52 public:
53
54   /**
55    * @copydoc Dali::ImfManager::Finalize()
56    */
57   void Finalize();
58
59   /**
60    * Check whether the ImfManager is available.
61    * @return true if available, false otherwise
62    */
63   static bool IsAvailable();
64
65   /**
66    * Get the IMF manager instance, it creates the instance if it has not already been created.
67    * Internally, a check should be made using IsAvailable() before this is called as we do not want
68    * to create an instance if not needed by applications.
69    * @see IsAvailable()
70    */
71   static Dali::ImfManager Get();
72
73   /**
74    * Constructor
75    * @param[in] ecoreXwin, The window is created by application.
76    */
77   ImfManager( Ecore_X_Window ecoreXwin );
78
79   /**
80    * Connect Callbacks required for IMF.
81    * If you don't connect imf callbacks, you can't get the key events.
82    * The events are PreeditChanged, Commit and DeleteSurrounding.
83    */
84   void ConnectCallbacks();
85
86   /**
87    * Disconnect Callbacks attached to imf context.
88    */
89   void DisconnectCallbacks();
90
91   /**
92    * @copydoc Dali::ImfManager::Activate()
93    */
94   void Activate();
95
96   /**
97    * @copydoc Dali::ImfManager::Deactivate()
98    */
99   void Deactivate();
100
101   /**
102    * @copydoc Dali::ImfManager::Reset()
103    */
104   void Reset();
105
106   /**
107    * @copydoc Dali::ImfManager::GetContext()
108    */
109   Ecore_IMF_Context* GetContext();
110
111   /**
112    * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
113    */
114   bool RestoreAfterFocusLost() const;
115
116   /**
117    * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
118    */
119   void SetRestoreAfterFocusLost( bool toggle );
120
121   /**
122    * @copydoc Dali::ImfManager::PreEditChanged()
123    */
124   void PreEditChanged( void* data, Ecore_IMF_Context* imfContext, void* event_info );
125
126   /**
127    * @copydoc Dali::ImfManager::NotifyCursorPosition()
128    */
129   void CommitReceived( void* data, Ecore_IMF_Context* imfContext, void* event_info );
130
131   /**
132    * @copydoc Dali::ImfManager::NotifyCursorPosition()
133    */
134   Eina_Bool RetrieveSurrounding( void* data, Ecore_IMF_Context* imfContext, char** text, int* cursorPosition );
135
136   /**
137    * @copydoc Dali::ImfManager::DeleteSurrounding()
138    */
139   void DeleteSurrounding( 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   KeyboardResizedSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
253
254   /**
255    * @copydoc Dali::ImfManager::LanguageChangedSignal()
256    */
257   LanguageChangedSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
258
259   /**
260    * @copydoc Dali::ImfManager::KeyboardTypeChangedSignal()
261    */
262   ImfKeyboardTypeSignalType& KeyboardTypeChangedSignal() { return mKeyboardTypeChangedSignal; }
263 protected:
264
265   /**
266    * Destructor.
267    */
268   virtual ~ImfManager();
269
270 private:
271   /**
272    * Context created the first time and kept until deleted.
273    * @param[in] ecoreXwin, The window is created by application.
274    */
275   void CreateContext( Ecore_X_Window ecoreXwin );
276
277   /**
278    * @copydoc Dali::ImfManager::DeleteContext()
279    */
280   void DeleteContext();
281
282 private:
283   // Undefined
284   ImfManager( const ImfManager& );
285   ImfManager& operator=( ImfManager& );
286
287 private:
288   Ecore_IMF_Context* mIMFContext;
289   Ecore_X_Window mEcoreXWin;
290   int mIMFCursorPosition;
291   std::string mSurroundingText;
292
293   bool mInited:1;                            ///< Whether the imf is already inited.
294   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
295   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
296   InputMethodOptions        mOptions;
297
298   ImfManagerSignalType       mActivatedSignal;
299   ImfEventSignalType         mEventSignal;
300   ImfStatusSignalType        mKeyboardStatusSignal;
301   KeyboardResizedSignalType  mKeyboardResizeSignal;
302   LanguageChangedSignalType  mKeyboardLanguageChangedSignal;
303   ImfKeyboardTypeSignalType  mKeyboardTypeChangedSignal;
304
305 public:
306
307 DALI_IMPORT_API inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
308 {
309   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
310
311   BaseObject& handle = imfManager.GetBaseObject();
312
313   return static_cast<Internal::Adaptor::ImfManager&>(handle);
314 }
315
316 DALI_IMPORT_API inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
317 {
318   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
319
320   const BaseObject& handle = imfManager.GetBaseObject();
321
322   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
323 }
324
325 };
326
327
328 } // namespace Adaptor
329
330 } // namespace Internal
331
332 } // namespace Dali
333
334 #endif // __DALI_INTERNAL_IMF_MANAGER_H