Move imf-manager-impl.h to integration-api.
[platform/core/uifw/dali-adaptor.git] / adaptors / integration-api / 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
27 // INTERNAL INCLUDES
28 #include <imf-manager.h>
29
30 namespace Dali
31 {
32
33 class RenderSurface;
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40
41 class DALI_IMPORT_API ImfManager : public Dali::BaseObject
42 {
43 public:
44   typedef Dali::ImfManager::ImfManagerSignalType ImfManagerSignalType;
45   typedef Dali::ImfManager::ImfEventSignalType ImfEventSignalType;
46
47 public:
48
49   /**
50    * Check whether the ImfManager is available.
51    * @return true if available, false otherwise
52    */
53   static bool IsAvailable();
54
55   /**
56    * Get the IMF manager instance, it creates the instance if it has not already been created.
57    * Internally, a check should be made using IsAvailable() before this is called as we do not want
58    * to create an instance if not needed by applications.
59    * @see IsAvailable()
60    */
61   static Dali::ImfManager Get();
62
63   /**
64    * Constructor
65    * @param[in] ecoreXwin, The window is created by application.
66    */
67   ImfManager( Ecore_X_Window ecoreXwin );
68
69   /**
70    * Connect Callbacks required for IMF.
71    * If you don't connect imf callbacks, you can't get the key events.
72    * The events are PreeditChanged, Commit and DeleteSurrounding.
73    */
74   void ConnectCallbacks();
75
76   /**
77    * Disconnect Callbacks attached to imf context.
78    */
79   void DisconnectCallbacks();
80
81   /**
82    * @copydoc Dali::ImfManager::Activate()
83    */
84   void Activate();
85
86   /**
87    * @copydoc Dali::ImfManager::Deactivate()
88    */
89   void Deactivate();
90
91   /**
92    * @copydoc Dali::ImfManager::Reset()
93    */
94   void Reset();
95
96   /**
97    * @copydoc Dali::ImfManager::GetContext()
98    */
99   Ecore_IMF_Context* GetContext();
100
101   /**
102    * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
103    */
104   bool RestoreAfterFocusLost() const;
105
106   /**
107    * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
108    */
109   void SetRestoreAfterFocusLost( bool toggle );
110
111   /**
112    * @copydoc Dali::ImfManager::PreEditChanged()
113    */
114   void PreEditChanged( void* data, Ecore_IMF_Context* imfContext, void* event_info );
115
116   /**
117    * @copydoc Dali::ImfManager::NotifyCursorPosition()
118    */
119   void CommitReceived( void* data, Ecore_IMF_Context* imfContext, void* event_info );
120
121   /**
122    * @copydoc Dali::ImfManager::NotifyCursorPosition()
123    */
124   Eina_Bool RetrieveSurrounding( void* data, Ecore_IMF_Context* imfContext, char** text, int* cursorPosition );
125
126   /**
127    * @copydoc Dali::ImfManager::DeleteSurrounding()
128    */
129   void DeleteSurrounding( void* data, Ecore_IMF_Context* imfContext, void* event_info );
130
131   // Cursor related
132   /**
133    * @copydoc Dali::ImfManager::NotifyCursorPosition()
134    */
135   void NotifyCursorPosition();
136
137   /**
138    * @copydoc Dali::ImfManager::SetCursorPosition()
139    */
140   void SetCursorPosition( unsigned int cursorPosition );
141
142   /**
143    * @copydoc Dali::ImfManager::GetCursorPosition()
144    */
145   unsigned int GetCursorPosition() const;
146
147   /**
148    * @copydoc Dali::ImfManager::SetSurroundingText()
149    */
150   void SetSurroundingText( const std::string& text );
151
152   /**
153    * @copydoc Dali::ImfManager::GetSurroundingText()
154    */
155   const std::string& GetSurroundingText() const;
156
157 public:  // Signals
158
159   /**
160    * @copydoc Dali::ImfManager::ActivatedSignal()
161    */
162   ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
163
164   /**
165    * @copydoc Dali::ImfManager::EventReceivedSignal()
166    */
167   ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
168
169 protected:
170
171   /**
172    * Destructor.
173    */
174   virtual ~ImfManager();
175
176 private:
177   /**
178    * Context created the first time and kept until deleted.
179    * @param[in] ecoreXwin, The window is created by application.
180    */
181   void CreateContext( Ecore_X_Window ecoreXwin );
182
183   /**
184    * @copydoc Dali::ImfManager::DeleteContext()
185    */
186   void DeleteContext();
187
188 private:
189   // Undefined
190   ImfManager( const ImfManager& );
191   ImfManager& operator=( ImfManager& );
192
193 private:
194   Ecore_IMF_Context* mIMFContext;
195   int mIMFCursorPosition;
196   std::string mSurroundingText;
197
198   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
199   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
200
201   ImfManagerSignalType      mActivatedSignal;
202   ImfEventSignalType        mEventSignal;
203
204 public:
205
206 DALI_IMPORT_API inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
207 {
208   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
209
210   BaseObject& handle = imfManager.GetBaseObject();
211
212   return static_cast<Internal::Adaptor::ImfManager&>(handle);
213 }
214
215 DALI_IMPORT_API inline static const  Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
216 {
217   DALI_ASSERT_ALWAYS( imfManager && "ImfManager handle is empty" );
218
219   const BaseObject& handle = imfManager.GetBaseObject();
220
221   return static_cast<const Internal::Adaptor::ImfManager&>(handle);
222 }
223
224 };
225
226
227 } // namespace Adaptor
228
229 } // namespace Internal
230
231 } // namespace Dali
232
233 #endif // __DALI_INTERNAL_IMF_MANAGER_H