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