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