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