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