fa2b0231ef85747c95e3733155481530e28931d0
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / ubuntu-x11 / imf-manager-impl-x.h
1 #ifndef DALI_INTERNAL_INPUT_COMMON_IMF_MANAGER_IMPL_X_H
2 #define DALI_INTERNAL_INPUT_COMMON_IMF_MANAGER_IMPL_X_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 <dali/devel-api/adaptor-framework/imf-manager.h>
29 #include <dali/internal/input/common/imf-manager-impl.h>
30
31 namespace Dali
32 {
33
34 class RenderSurface;
35
36 namespace Internal
37 {
38
39 namespace Adaptor
40 {
41
42 class DALI_IMPORT_API ImfManagerX : public Dali::Internal::Adaptor::ImfManager
43 {
44 public:
45
46   /**
47    * Check whether the ImfManager is available.
48    * @return true if available, false otherwise
49    */
50   static bool IsAvailable();
51
52   /**
53    * Get the IMF manager instance, it creates the instance if it has not already been created.
54    * Internally, a check should be made using IsAvailable() before this is called as we do not want
55    * to create an instance if not needed by applications.
56    * @see IsAvailable()
57    */
58   static Dali::ImfManager Get();
59
60   /**
61    * Constructor
62    * @param[in] ecoreXwin, The window is created by application.
63    */
64   explicit ImfManagerX( Ecore_X_Window ecoreXwin );
65
66   /**
67    * Connect Callbacks required for IMF.
68    * If you don't connect imf callbacks, you can't get the key events.
69    * The events are PreeditChanged, Commit and DeleteSurrounding.
70    */
71   void ConnectCallbacks() override;
72
73   /**
74    * Disconnect Callbacks attached to imf context.
75    */
76   void DisconnectCallbacks() override;
77
78   /**
79    * @copydoc Dali::ImfManager::Activate()
80    */
81   void Activate() override;
82
83   /**
84    * @copydoc Dali::ImfManager::Deactivate()
85    */
86   void Deactivate() override;
87
88   /**
89    * @copydoc Dali::ImfManager::Reset()
90    */
91   void Reset() override;
92
93   /**
94    * @copydoc Dali::ImfManager::GetContext()
95    */
96   ImfContext* GetContext() override;
97
98   /**
99    * @copydoc Dali::ImfManager::RestoreAfterFocusLost()
100    */
101   bool RestoreAfterFocusLost() const override;
102
103   /**
104    * @copydoc Dali::ImfManager::SetRestoreAfterFocusLost()
105    */
106   void SetRestoreAfterFocusLost( bool toggle ) override;
107
108   /**
109    * @copydoc Dali::ImfManager::PreEditChanged()
110    */
111   void PreEditChanged( void* data, ImfContext* imfContext, void* event_info ) override;
112
113   /**
114    * @copydoc Dali::ImfManager::NotifyCursorPosition()
115    */
116   void CommitReceived( void* data, ImfContext* imfContext, void* event_info ) override;
117
118   /**
119    * @copydoc Dali::ImfManager::NotifyCursorPosition()
120    */
121   bool RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition ) override;
122
123   /**
124    * @copydoc Dali::ImfManager::DeleteSurrounding()
125    */
126   void DeleteSurrounding( void* data, ImfContext* imfContext, void* event_info );
127
128
129   void SendPrivateCommand( void* data, ImfContext* imfContext, void* event_info )  override
130   {
131
132   }
133
134
135   // Cursor related
136   /**
137    * @copydoc Dali::ImfManager::NotifyCursorPosition()
138    */
139   void NotifyCursorPosition() override;
140
141   /**
142    * @copydoc Dali::ImfManager::SetCursorPosition()
143    */
144   void SetCursorPosition( unsigned int cursorPosition ) override;
145
146   /**
147    * @copydoc Dali::ImfManager::GetCursorPosition()
148    */
149   unsigned int GetCursorPosition() const override;
150
151   /**
152    * @copydoc Dali::ImfManager::SetSurroundingText()
153    */
154   void SetSurroundingText( const std::string& text ) override;
155
156   /**
157    * @copydoc Dali::ImfManager::GetSurroundingText()
158    */
159   const std::string& GetSurroundingText() const override;
160
161   /**
162   * @copydoc Dali::ImfManager::NotifyTextInputMultiLine()
163   */
164   void NotifyTextInputMultiLine( bool multiLine ) override;
165
166   /**
167   * @copydoc Dali::ImfManager::GetTextDirection()
168   */
169   Dali::ImfManager::TextDirection GetTextDirection() override;
170
171   /**
172   * @copydoc Dali::ImfManager::GetInputMethodArea()
173   */
174   Dali::Rect<int> GetInputMethodArea() override;
175
176   /**
177   * @copydoc Dali::ImfManager::ApplyOptions()
178   */
179   void ApplyOptions( const InputMethodOptions& options ) override;
180
181   /**
182    * @copydoc Dali::ImfManager::SetInputPanelData()
183    */
184   void SetInputPanelData( const std::string& data ) override;
185
186   /**
187    * @copydoc Dali::ImfManager::GetInputPanelData()
188    */
189   void GetInputPanelData( std::string& data ) override;
190
191   /**
192    * @copydoc Dali::ImfManager::GetInputPanelState()
193    */
194   Dali::ImfManager::State GetInputPanelState() override;
195
196   /**
197    * @copydoc Dali::ImfManager::SetReturnKeyState()
198    */
199   void SetReturnKeyState( bool visible ) override;
200
201   /**
202    * @copydoc Dali::ImfManager::AutoEnableInputPanel()
203    */
204   void AutoEnableInputPanel( bool enabled ) override;
205
206   /**
207    * @copydoc Dali::ImfManager::ShowInputPanel()
208    */
209   void ShowInputPanel() override;
210
211   /**
212    * @copydoc Dali::ImfManager::HideInputPanel()
213    */
214   void HideInputPanel() override;
215
216   /**
217    * @copydoc Dali::ImfManager::GetKeyboardType()
218    */
219   Dali::ImfManager::KeyboardType GetKeyboardType() override;
220
221   /**
222    * @copydoc Dali::ImfManager::GetInputPanelLocale()
223    */
224   std::string GetInputPanelLocale() override;
225
226 protected:
227
228   /**
229    * Destructor.
230    */
231   ~ImfManagerX() override;
232
233 private:
234   /**
235    * Context created the first time and kept until deleted.
236    * @param[in] ecoreXwin, The window is created by application.
237    */
238   void CreateContext( Ecore_X_Window ecoreXwin );
239
240   /**
241    * @copydoc Dali::ImfManager::DeleteContext()
242    */
243   void DeleteContext();
244
245 private:
246   // Undefined
247   ImfManagerX( const ImfManagerX& );
248   ImfManagerX& operator=( ImfManagerX& ) = delete;
249
250 private:
251   Ecore_IMF_Context* mIMFContext;
252   int mIMFCursorPosition;
253   std::string mSurroundingText;
254
255   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
256   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
257   InputMethodOptions        mOptions;
258 };
259
260
261 } // namespace Adaptor
262
263 } // namespace Internal
264
265 } // namespace Dali
266
267 #endif // DALI_INTERNAL_INPUT_COMMON_IMF_MANAGER_IMPL_X_H