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