Lifecycle controller
[platform/core/uifw/dali-adaptor.git] / adaptors / 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 #include <imf-manager.h>
27 #include <dali/integration-api/events/key-event-integ.h>
28
29 // INTERNAL INCLUDES
30
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40
41 class RenderSurface;
42
43 class ImfManager : public Dali::BaseObject
44 {
45 public:
46   typedef Dali::ImfManager::ImfManagerSignalV2 ImfManagerSignalV2;
47   typedef Dali::ImfManager::ImfEventSignalV2 ImfEventSignalV2;
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::SetRestoreAferFocusLost()
110    */
111   void SetRestoreAferFocusLost( 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::GetCursorPosition()
141    */
142   int GetCursorPosition();
143
144   /**
145    * @copydoc Dali::ImfManager::SetCursorPosition()
146    */
147   void SetCursorPosition( unsigned int cursorPosition );
148
149   /**
150    * @copydoc Dali::ImfManager::SetSurroundingText()
151    */
152   void SetSurroundingText( std::string text );
153
154   /**
155    * @copydoc Dali::ImfManager::GetSurroundingText()
156    */
157   std::string GetSurroundingText();
158
159 public:  // Signals
160
161   /**
162    * @copydoc Dali::ImfManager::ActivatedSignal()
163    */
164   ImfManagerSignalV2& ActivatedSignal() { return mActivatedSignalV2; }
165
166   /**
167    * @copydoc Dali::ImfManager::EventReceivedSignal()
168    */
169   ImfEventSignalV2& EventReceivedSignal() { return mEventSignalV2; }
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] ecoreXwin, The window is created by application.
182    */
183   void CreateContext( Ecore_X_Window ecoreXwin );
184
185   /**
186    * @copydoc Dali::ImfManager::DeleteContext()
187    */
188   void DeleteContext();
189
190 private:
191   // Undefined
192   ImfManager( const ImfManager& );
193   ImfManager& operator=( ImfManager& );
194
195 private:
196   Ecore_IMF_Context* mIMFContext;
197   int mIMFCursorPosition;
198   std::string mSurroundingText;
199
200   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
201   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
202
203   std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
204
205   ImfManagerSignalV2      mActivatedSignalV2;
206   ImfEventSignalV2        mEventSignalV2;
207
208 public:
209
210 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
211 {
212   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
213
214   BaseObject& handle = imfManager.GetBaseObject();
215
216   return static_cast<Internal::Adaptor::ImfManager&>(handle);
217 }
218
219 inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
220 {
221   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
222
223   const BaseObject& handle = imfManager.GetBaseObject();
224
225   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
226 }
227
228 };
229
230
231 } // namespace Adaptor
232
233 } // namespace Internal
234
235 } // namespace Dali
236
237 #endif // __DALI_INTERNAL_IMF_MANAGER_H