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