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