Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / ubuntu-x11 / input-method-context-impl-x.h
1 #ifndef DALI_INTERNAL_INPUT_METHOD_CONTEXT_IMPL_X_H
2 #define DALI_INTERNAL_INPUT_METHOD_CONTEXT_IMPL_X_H
3
4 /*
5  * Copyright (c) 2019 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 <dali/internal/input/linux/dali-ecore-imf.h>
23 #include <dali/internal/system/linux/dali-ecore-x.h>
24
25 #include <dali/public-api/object/base-object.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/devel-api/adaptor-framework/input-method-context.h>
29 #include <dali/internal/input/common/input-method-context-impl.h>
30
31 namespace Dali
32 {
33
34 class RenderSurface;
35
36 namespace Internal
37 {
38
39 namespace Adaptor
40 {
41
42 class InputMethodContextX : public Dali::Internal::Adaptor::InputMethodContext
43 {
44 public:
45   /**
46    * @brief Creates a new InputMethodContext handle
47    *
48    * @return InputMethodContext pointer
49    */
50   static InputMethodContextPtr New();
51
52   /**
53    * Constructor
54    * @param[in] ecoreXwin, The window is created by application.
55    */
56   explicit InputMethodContextX( Ecore_X_Window ecoreXwin );
57
58 public:
59
60   /**
61    * @brief Initializes member data.
62    */
63   void Initialize() override;
64
65   /**
66    * Connect Callbacks required for InputMethodContext.
67    * If you don't connect InputMethodContext callbacks, you can't get the key events.
68    * The events are PreeditChanged, Commit and DeleteSurrounding.
69    */
70   void ConnectCallbacks() override;
71
72   /**
73    * Disconnect Callbacks attached to input method context.
74    */
75   void DisconnectCallbacks() override;
76
77   /**
78    * @copydoc Dali::InputMethodContext::Finalize()
79    */
80   void Finalize() override;
81
82   /**
83    * @copydoc Dali::InputMethodContext::Activate()
84    */
85   void Activate() override;
86
87   /**
88    * @copydoc Dali::InputMethodContext::Deactivate()
89    */
90   void Deactivate() override;
91
92   /**
93    * @copydoc Dali::InputMethodContext::Reset()
94    */
95   void Reset() override;
96
97   /**
98    * @copydoc Dali::InputMethodContext::GetContext()
99    */
100   ImfContext* GetContext() override;
101
102   /**
103    * @copydoc Dali::InputMethodContext::RestoreAfterFocusLost()
104    */
105   bool RestoreAfterFocusLost() const override;
106
107   /**
108    * @copydoc Dali::InputMethodContext::SetRestoreAfterFocusLost()
109    */
110   void SetRestoreAfterFocusLost( bool toggle ) override;
111
112   /**
113    * @copydoc Dali::InputMethodContext::PreEditChanged()
114    */
115   void PreEditChanged( void* data, ImfContext* imfContext, void* eventInfo ) override;
116
117   /**
118    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
119    */
120   void CommitReceived( void* data, ImfContext* imfContext, void* eventInfo ) override;
121
122   /**
123    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
124    */
125   bool RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition ) override;
126
127   /**
128    * @copydoc Dali::InputMethodContext::DeleteSurrounding()
129    */
130   void DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo ) override;
131
132   /**
133    * @copydoc Dali::InputMethodContext::SendPrivateCommand()
134    */
135   void SendPrivateCommand( void* data, ImfContext* imfContext, void* eventInfo ) override
136   {}
137
138   /**
139    * @copydoc Dali::InputMethodContext::SendCommitContent()
140    */
141   void SendCommitContent( void* data, ImfContext* imfContext, void* eventInfo ) override
142   {}
143
144   // Cursor related
145   /**
146    * @copydoc Dali::InputMethodContext::NotifyCursorPosition()
147    */
148   void NotifyCursorPosition() override;
149
150   /**
151    * @copydoc Dali::InputMethodContext::SetCursorPosition()
152    */
153   void SetCursorPosition( unsigned int cursorPosition ) override;
154
155   /**
156    * @copydoc Dali::InputMethodContext::GetCursorPosition()
157    */
158   unsigned int GetCursorPosition() const override;
159
160   /**
161    * @copydoc Dali::InputMethodContext::SetSurroundingText()
162    */
163   void SetSurroundingText( const std::string& text ) override;
164
165   /**
166    * @copydoc Dali::InputMethodContext::GetSurroundingText()
167    */
168   const std::string& GetSurroundingText() const override;
169
170   /**
171   * @copydoc Dali::InputMethodContext::NotifyTextInputMultiLine()
172   */
173   void NotifyTextInputMultiLine( bool multiLine ) override;
174
175   /**
176   * @copydoc Dali::InputMethodContext::GetTextDirection()
177   */
178   Dali::InputMethodContext::TextDirection GetTextDirection() override;
179
180   /**
181   * @copydoc Dali::InputMethodContext::GetInputMethodArea()
182   */
183   Dali::Rect<int> GetInputMethodArea() override;
184
185   /**
186   * @copydoc Dali::InputMethodContext::ApplyOptions()
187   */
188   void ApplyOptions( const InputMethodOptions& options ) override;
189
190   /**
191    * @copydoc Dali::InputMethodContext::SetInputPanelData()
192    */
193   void SetInputPanelData( const std::string& data ) override;
194
195   /**
196    * @copydoc Dali::InputMethodContext::GetInputPanelData()
197    */
198   void GetInputPanelData( std::string& data ) override;
199
200   /**
201    * @copydoc Dali::InputMethodContext::GetInputPanelState()
202    */
203   Dali::InputMethodContext::State GetInputPanelState() override;
204
205   /**
206    * @copydoc Dali::InputMethodContext::SetReturnKeyState()
207    */
208   void SetReturnKeyState( bool visible ) override;
209
210   /**
211    * @copydoc Dali::InputMethodContext::AutoEnableInputPanel()
212    */
213   void AutoEnableInputPanel( bool enabled ) override;
214
215   /**
216    * @copydoc Dali::InputMethodContext::ShowInputPanel()
217    */
218   void ShowInputPanel() override;
219
220   /**
221    * @copydoc Dali::InputMethodContext::HideInputPanel()
222    */
223   void HideInputPanel() override;
224
225   /**
226    * @copydoc Dali::InputMethodContext::GetKeyboardType()
227    */
228   Dali::InputMethodContext::KeyboardType GetKeyboardType() override;
229
230   /**
231    * @copydoc Dali::InputMethodContext::GetInputPanelLocale()
232    */
233   std::string GetInputPanelLocale() override;
234
235   /**
236    * @copydoc Dali::InputMethodContext::SetContentMIMETypes()
237    */
238   void SetContentMIMETypes( const std::string& mimeTypes ) override;
239
240   /**
241    * @copydoc Dali::InputMethodContext::FilterEventKey()
242    */
243   bool FilterEventKey( const Dali::KeyEvent& keyEvent ) override;
244
245   /**
246    * @copydoc Dali::InputMethodContext::AllowTextPrediction()
247    */
248   void AllowTextPrediction( bool prediction ) override;
249
250   /**
251    * @copydoc Dali::InputMethodContext::IsTextPredictionAllowed()
252    */
253   bool IsTextPredictionAllowed() const override;
254
255   /**
256    * @copydoc Dali::InputMethodContext::SetInputPanelLanguage()
257    */
258   void SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language ) override;
259
260   /**
261    * @copydoc Dali::InputMethodContext::GetInputPanelLanguage()
262    */
263   Dali::InputMethodContext::InputPanelLanguage GetInputPanelLanguage() const override;
264
265 private:
266   /**
267    * Context created the first time and kept until deleted.
268    * @param[in] ecoreXwin, The window is created by application.
269    */
270   void CreateContext( Ecore_X_Window ecoreXwin );
271
272   /**
273    * @copydoc Dali::InputMethodContext::DeleteContext()
274    */
275   void DeleteContext();
276
277 private:
278
279   /**
280    * @brief Process event key down, whether filter a key to isf.
281    *
282    * @param[in] keyEvent The event key to be handled.
283    * @return Whether the event key is handled.
284    */
285   bool ProcessEventKeyDown( const KeyEvent& keyEvent );
286
287   /**
288    * @brief Process event key up, whether filter a key to isf.
289    *
290    * @param[in] keyEvent The event key to be handled.
291    * @return Whether the event key is handled.
292    */
293   bool ProcessEventKeyUp( const KeyEvent& keyEvent );
294
295   /**
296   * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
297   * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
298   * @param[in] ecoreModifier the Ecore_Event_Modifier input.
299   * @return the Ecore_IMF_Keyboard_Modifiers output.
300   */
301   Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier( unsigned int ecoreModifier );
302
303   /**
304    * EcoreInputModifierToEcoreIMFLock function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Locks enums.
305    * @param[in] modifier the Ecore_Event_Modifier input.
306    * @return the Ecore_IMF_Keyboard_Locks output.
307    */
308   Ecore_IMF_Keyboard_Locks EcoreInputModifierToEcoreIMFLock( unsigned int modifier );
309
310 public:
311
312   /**
313    * Destructor.
314    */
315   virtual ~InputMethodContextX();
316
317 private:
318
319   // Undefined copy constructor
320   InputMethodContextX( const InputMethodContextX& inputMethodContext) = delete;
321
322   // Undefined assignment operator
323   InputMethodContextX& operator=( const InputMethodContextX& inputMethodContext ) = delete;
324
325 private:
326   Ecore_IMF_Context* mIMFContext;
327   Ecore_X_Window mEcoreXwin;
328   int mIMFCursorPosition;
329   std::string mSurroundingText;
330
331   bool mRestoreAfterFocusLost:1;             ///< Whether the keyboard needs to be restored (activated ) after focus regained.
332   bool mIdleCallbackConnected:1;             ///< Whether the idle callback is already connected.
333   InputMethodOptions        mOptions;
334 };
335
336 } // namespace Adaptor
337
338 } // namespace Internal
339
340 } // namespace Dali
341
342 #endif // DALI_INTERNAL_INPUT_METHOD_CONTEXT_IMPL_X_H