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