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