Refactor and add Wayland support.
[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    * Create the IMF manager.
54    */
55   static Dali::ImfManager Get();
56
57   /**
58    * Connect Callbacks required for IMF.
59    * If you don't connect imf callbacks, you can't get the key events.
60    * The events are PreeditChanged, Commit and DeleteSurrounding.
61    */
62   void ConnectCallbacks();
63
64   /**
65    * Disconnect Callbacks attached to imf context.
66    */
67   void DisconnectCallbacks();
68
69   /**
70    * @copydoc Dali::ImfManager::Activate()
71    */
72   void Activate();
73
74   /**
75    * @copydoc Dali::ImfManager::Deactivate()
76    */
77   void Deactivate();
78
79   /**
80    * @copydoc Dali::ImfManager::Reset()
81    */
82   void Reset();
83
84   /**
85    * @copydoc Dali::ImfManager::GetContext()
86    */
87   Ecore_IMF_Context* GetContext();
88
89   /**
90    * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
91    */
92   bool RestoreAfterFocusLost() const;
93
94   /**
95    * @copydoc Dali::ImfManager::SetRestoreAferFocusLost()
96    */
97   void SetRestoreAferFocusLost( bool toggle );
98
99   /**
100    * @copydoc Dali::ImfManager::PreEditChanged()
101    */
102   void PreEditChanged( void *data, Ecore_IMF_Context *imfContext, void *event_info );
103
104   /**
105    * @copydoc Dali::ImfManager::NotifyCursorPosition()
106    */
107   void CommitReceived( void *data, Ecore_IMF_Context *imfContext, void *event_info );
108
109   /**
110    * @copydoc Dali::ImfManager::NotifyCursorPosition()
111    */
112   Eina_Bool RetrieveSurrounding( void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition );
113
114   /**
115    * @copydoc Dali::ImfManager::DeleteSurrounding()
116    */
117   void DeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *event_info );
118
119   // Cursor related
120   /**
121    * @copydoc Dali::ImfManager::NotifyCursorPosition()
122    */
123   void NotifyCursorPosition();
124
125   /**
126    * @copydoc Dali::ImfManager::GetCursorPosition()
127    */
128   int GetCursorPosition();
129
130   /**
131    * @copydoc Dali::ImfManager::SetCursorPosition()
132    */
133   void SetCursorPosition( unsigned int cursorPosition );
134
135   /**
136    * @copydoc Dali::ImfManager::SetSurroundingText()
137    */
138   void SetSurroundingText( std::string text );
139
140   /**
141    * @copydoc Dali::ImfManager::GetSurroundingText()
142    */
143   std::string GetSurroundingText();
144
145 public:  // Signals
146
147   /**
148    * @copydoc Dali::ImfManager::ActivatedSignal()
149    */
150   ImfManagerSignalV2& ActivatedSignal() { return mActivatedSignalV2; }
151
152   /**
153    * @copydoc Dali::ImfManager::EventReceivedSignal()
154    */
155   ImfEventSignalV2& EventReceivedSignal() { return mEventSignalV2; }
156
157 protected:
158
159   /**
160    * Destructor.
161    */
162   virtual ~ImfManager();
163
164 private:
165   /**
166    * @copydoc Dali::ImfManager::DeleteContext()
167    */
168   void DeleteContext();
169
170 private:
171   // Undefined
172   ImfManager( const ImfManager& );
173   ImfManager& operator=( ImfManager& );
174
175 private:
176   Ecore_IMF_Context* mIMFContext;
177   int mIMFCursorPosition;
178   std::string mSurroundingText;
179
180   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
181   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
182
183   std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
184
185   ImfManagerSignalV2      mActivatedSignalV2;
186   ImfEventSignalV2        mEventSignalV2;
187
188 public:
189
190 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
191 {
192   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
193
194   BaseObject& handle = imfManager.GetBaseObject();
195
196   return static_cast<Internal::Adaptor::ImfManager&>(handle);
197 }
198
199 inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
200 {
201   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
202
203   const BaseObject& handle = imfManager.GetBaseObject();
204
205   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
206 }
207
208 };
209
210
211 } // namespace Adaptor
212
213 } // namespace Internal
214
215 } // namespace Dali
216
217 #endif // __DALI_INTERNAL_IMF_MANAGER_H