391c56d505d8fb8c879f85926519d12086583a2f
[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 ImfManager : public Dali::BaseObject
45 {
46 public:
47   typedef Dali::ImfManager::ImfManagerSignalType ImfManagerSignalType;
48   typedef Dali::ImfManager::ImfEventSignalType ImfEventSignalType;
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    * Connect Callbacks required for IMF.
68    * If you don't connect imf callbacks, you can't get the key events.
69    * The events are PreeditChanged, Commit and DeleteSurrounding.
70    */
71   void ConnectCallbacks();
72
73   /**
74    * Disconnect Callbacks attached to imf context.
75    */
76   void DisconnectCallbacks();
77
78   /**
79    * @copydoc Dali::ImfManager::Activate()
80    */
81   void Activate();
82
83   /**
84    * @copydoc Dali::ImfManager::Deactivate()
85    */
86   void Deactivate();
87
88   /**
89    * @copydoc Dali::ImfManager::Reset()
90    */
91   void Reset();
92
93   /**
94    * @copydoc Dali::ImfManager::GetContext()
95    */
96   Ecore_IMF_Context* GetContext();
97
98   /**
99    * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
100    */
101   bool RestoreAfterFocusLost() const;
102
103   /**
104    * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
105    */
106   void SetRestoreAfterFocusLost( bool toggle );
107
108   /**
109    * @copydoc Dali::ImfManager::PreEditChanged()
110    */
111   void PreEditChanged( void *data, Ecore_IMF_Context *imfContext, void *event_info );
112
113   /**
114    * @copydoc Dali::ImfManager::NotifyCursorPosition()
115    */
116   void CommitReceived( void *data, Ecore_IMF_Context *imfContext, void *event_info );
117
118   /**
119    * @copydoc Dali::ImfManager::NotifyCursorPosition()
120    */
121   Eina_Bool RetrieveSurrounding( void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition );
122
123   /**
124    * @copydoc Dali::ImfManager::DeleteSurrounding()
125    */
126   void DeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *event_info );
127
128   // Cursor related
129   /**
130    * @copydoc Dali::ImfManager::NotifyCursorPosition()
131    */
132   void NotifyCursorPosition();
133
134   /**
135    * @copydoc Dali::ImfManager::SetCursorPosition()
136    */
137   void SetCursorPosition( unsigned int cursorPosition );
138
139   /**
140    * @copydoc Dali::ImfManager::GetCursorPosition()
141    */
142   unsigned int GetCursorPosition() const;
143
144   /**
145    * @copydoc Dali::ImfManager::SetSurroundingText()
146    */
147   void SetSurroundingText( const std::string& text );
148
149   /**
150    * @copydoc Dali::ImfManager::GetSurroundingText()
151    */
152   const std::string& GetSurroundingText() const;
153
154   /**
155   * @copydoc Dali::ImfManager::NotifyTextInputMultiLine()
156   */
157   void NotifyTextInputMultiLine( bool multiLine );
158
159 public:  // Signals
160
161   /**
162    * @copydoc Dali::ImfManager::ActivatedSignal()
163    */
164   ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
165
166   /**
167    * @copydoc Dali::ImfManager::EventReceivedSignal()
168    */
169   ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
170
171 protected:
172
173   /**
174    * Destructor.
175    */
176   virtual ~ImfManager();
177
178 private:
179   /**
180    * Context created the first time and kept until deleted.
181    * @param[in] ecoreWlwin, The window is created by application.
182    */
183   void CreateContext( Ecore_Wl_Window *ecoreWlwin );
184
185   /**
186    * @copydoc Dali::ImfManager::DeleteContext()
187    */
188   void DeleteContext();
189
190 private:
191   // Undefined
192   ImfManager( Ecore_Wl_Window *ecoreWlwin );
193   ImfManager( const ImfManager& );
194   ImfManager& operator=( ImfManager& );
195
196 private:
197   Ecore_IMF_Context* mIMFContext;
198   int mIMFCursorPosition;
199   std::string mSurroundingText;
200
201   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
202   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
203
204   std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
205
206   ImfManagerSignalType      mActivatedSignal;
207   ImfEventSignalType        mEventSignal;
208
209 public:
210
211 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
212 {
213   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
214
215   BaseObject& handle = imfManager.GetBaseObject();
216
217   return static_cast<Internal::Adaptor::ImfManager&>(handle);
218 }
219
220 inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
221 {
222   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
223
224   const BaseObject& handle = imfManager.GetBaseObject();
225
226   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
227 }
228
229 };
230
231
232 } // namespace Adaptor
233
234 } // namespace Internal
235
236 } // namespace Dali
237
238 #endif // __DALI_INTERNAL_IMF_MANAGER_H