Revert "[3.0] temporary fix for build error"
[platform/core/uifw/dali-adaptor.git] / adaptors / wayland / input / text / text-input-manager.h
1 #ifndef __DALI_WAYLAND_TEXT_INPUT_MANAGER_H__
2 #define __DALI_WAYLAND_TEXT_INPUT_MANAGER_H__
3
4 /*
5  * Copyright (c) 2016 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 <vector>
23
24 // INTERNAL INCLUDES
25 #include <input/text/text-input-interface.h>
26 #include <input/seat.h>
27 #include <virtual-keyboard.h>
28 #include <wl-types.h>
29 #include <base/interfaces/window-event-interface.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace Adaptor
38 {
39
40
41 /**
42  * Handles wayland text input interface which deals with the input panel (virtual keyboard ).
43  *
44  */
45 class TextInputManager : private TextInputInterface
46 {
47
48 public:
49
50   /**
51    * @brief Constructor
52    */
53   TextInputManager();
54
55   /**
56    * @brief Destructor
57    */
58   ~TextInputManager();
59
60   /**
61    * @brief Assign the window event interface
62    * Used to send key events to DALi
63    * @param[in]  eventInterface event interface
64    */
65   void AssignWindowEventInterface( WindowEventInterface* eventInterface );
66
67   /**
68    * @brief Assign the Wayland connection
69    * @param[in] display Wayland display
70    */
71   void AssignDisplay( WlDisplay* display );
72
73   /**
74    * @brief Add a seat
75    * @param seat seat pointer
76    */
77   void AddSeat( Seat* seat );
78
79   /**
80    * Get the global TextInputManager
81    */
82   static TextInputManager& Get();
83
84 private:  // TextInputInterface
85
86   /**
87    * @copydoc TextInputInterface::Enter
88    */
89   virtual void Enter( Seat* seat, WlSurface* surface );
90
91   /**
92    * @copydoc TextInputInterface::Leave
93    */
94   virtual void Leave( Seat* seat );
95
96   /**
97    * @copydoc TextInputInterface::ModifiersMap
98    */
99   virtual void ModifiersMap( Seat* seat, WlArray *map );
100
101   /**
102    * @copydoc TextInputInterface::InputPanelState
103    */
104   virtual void InputPanelState( Seat* seat, uint32_t state );
105
106   /**
107    * @copydoc TextInputInterface::PreeditString
108    */
109   virtual void PreeditString( Seat* seat, uint32_t serial, const char *text, const char *commit );
110
111   /**
112    * @copydoc TextInputInterface::PreeditStyling
113    */
114   virtual void PreeditStyling( Seat* seat, uint32_t index, uint32_t length, uint32_t style );
115
116   /**
117    * @copydoc TextInputInterface::PreeditCursor
118    */
119   virtual void PreeditCursor( Seat* seat, int32_t index );
120
121   /**
122    * @copydoc TextInputInterface::CommitString
123    */
124   virtual void CommitString( Seat* seat, uint32_t serial, const char *text );
125
126   /**
127    * @copydoc TextInputInterface::CursorPosition
128    */
129   virtual void CursorPosition( Seat* seat, int32_t index, int32_t anchor );
130
131   /**
132    * @copydoc TextInputInterface::DeleteSurroundingText
133    */
134   virtual void DeleteSurroundingText( Seat* seat, int32_t index, uint32_t length );
135
136
137   /**
138    * @copydoc TextInputInterface::Keysym
139    */
140   virtual void Keysym( Seat* seat,
141                        uint32_t serial,
142                        uint32_t time,
143                        uint32_t sym,
144                        uint32_t state,
145                        uint32_t modifiers);
146
147   /**
148    * @copydoc TextInputInterface::Language
149    */
150   virtual void Language( Seat* seat, uint32_t serial, const char *language );
151
152   /**
153    * @copydoc TextInputInterface::TextDirection
154    */
155   virtual void TextDirection( Seat* seat, uint32_t serial, uint32_t direction );
156
157   /**
158    * @copydoc TextInputInterface::SelectionRegion
159    */
160   virtual void SelectionRegion( Seat* seat, uint32_t serial, int32_t start, int32_t end );
161
162   /**
163    * @copydoc TextInputInterface::PrivateCommand
164    */
165   virtual void PrivateCommand( Seat* seat, uint32_t serial, const char *command );
166
167   /**
168    * @copydoc TextInputInterface::InputPanelGeometry
169    */
170   virtual void InputPanelGeometry( Seat* seat, uint32_t x, uint32_t y, uint32_t width, uint32_t height );
171
172   /**
173    * @copydoc TextInputInterface::InputPanelData
174    */
175   virtual void InputPanelData( Seat* seat,
176                                 uint32_t serial,
177                                 const char* data,
178                                 uint32_t dataLength );
179
180   /**
181    * @copydoc TextInputInterface::GetSeat
182    */
183   virtual Seat* GetSeat( const WlTextInput* textInput );
184
185 public:
186
187   /**
188    * @brief show the input panel (virtual keyboard)
189    */
190   void ShowInputPanel();
191
192   /**
193    * @brief hide the input panel
194    */
195   void HideInputPanel();
196
197   /**
198    * @brief see if the input panel is visible
199    * @return true if panel is visible
200    */
201   bool IsInputPanelVisible();
202
203   /**
204    * @brief set the return key type
205    * @param[in] type return key type
206    */
207   void SetReturnKeyType( const InputMethod::ActionButton type );
208
209   /**
210    * @brief reset inputs state
211    * Should be called by an editor widget when the input state should be
212    * reset, for example after the text was changed outside of the normal
213    * input method flow.
214    */
215   void Reset();
216
217   /**
218    * @brief
219    * Set the plain surrounding text around the input position. Text is
220    * UTF-8 encoded. Cursor is the byte offset within the
221    * surrounding text. Anchor is the byte offset of the
222    * selection anchor within the surrounding text. If there is no selected
223    * @param[in] serial the serial
224    * @param[in] text the text
225    * @param[in] cursor cursor position
226    */
227   void SetSurroundingText( uint32_t serial, std::string text, unsigned int cursor);
228
229
230 public: // virtual keyboard signals
231
232   /**
233    * @copydoc Dali::VirtualKeyboard::StatusChangedSignal
234    */
235   Dali::VirtualKeyboard::StatusSignalType& StatusChangedSignal();
236
237   /**
238    * @copydoc Dali::VirtualKeyboard::ResizedSignal
239    */
240   Dali::VirtualKeyboard::VoidSignalType& ResizedSignal();
241
242   /**
243    * @copydoc Dali::VirtualKeyboard::LanguageChangedSignal
244    */
245   Dali::VirtualKeyboard::VoidSignalType& LanguageChangedSignal();
246
247 public:   ///< Input Panel Signals ( DALi currently doesn't use these, it only uses signals from IMF interface).
248
249    typedef Signal< void ( unsigned int, const std::string, const std::string ) > PreEditStringSignalType;
250    typedef Signal< void ( unsigned int, unsigned int length, unsigned int ) > PreEditStylingSignalType;
251    typedef Signal< void ( int ) > PreEditCursorSignalType;
252    typedef Signal< void ( unsigned int, const std::string ) > CommitStringSignalType;
253    typedef Signal< void ( int , int ) > CursorPositionSignalType;
254    typedef Signal< void ( int , unsigned int ) > DeleteSurroundingTextSignalType;
255    typedef Signal< void ( unsigned int ,int, int ) > SelectionRegionSignalType;
256
257    /**
258     * @brief Notify when composing new text
259     * Description from wayland-extension/protocol/text.xml:
260     * Notify when a new composing text (pre-edit) should be set around the
261     * current cursor position. Any previously set composing text should
262     * be removed.
263     *
264     * The commit text can be used to replace the preedit text on reset (for example on unfocus).
265     * The text input should also handle all preedit_style and preedit_cursor
266     * events occurring directly before preedit_string.
267     *
268     * @code
269     *   void YourCallbackName( unsigned int serial, std::string text, std::string commit );
270     * @endcode
271     */
272    PreEditStringSignalType& PreEditStringSignal();
273
274    /**
275     * @brief Pre-edit styling
276     *
277     * Description from wayland-extension/protocol/text.xml:
278     * Set styling information on composing text. The style is applied for
279     * length bytes from index relative to the beginning of the composing
280     * text (as byte offset). Multiple styles can be applied to a composing
281     * text by sending multiple preedit_styling events.
282     *
283     *
284     * @code
285     *   void YourCallbackName( unsigned int index, unsigned int length, unsigned int style );
286     * @endcode
287     */
288    PreEditStylingSignalType& PreEditStylingSignal();
289
290    /**
291     * @brief Notify pre-edit cursor position
292     * Description from wayland-extension/protocol/text.xml:
293     * Set the cursor position inside the composing text (as byte
294     * offset) relative to the start of the composing text. When index is a
295     * negative number no cursor is shown.
296     *
297     * @code
298     *   void YourCallbackName( int index );
299     * @endcode
300     */
301    PreEditCursorSignalType& PreEditCursorSignal();
302
303    /**
304     * @brief Commit string text
305     * From wayland-extension/protocol/text.xml:
306     * Notify when text should be inserted into the editor widget. The text to
307     * commit could be either just a single character after a key press or the
308     * result of some composing (pre-edit). It could be also an empty text
309     * when some text should be removed (see delete_surrounding_text) or when
310     * the input cursor should be moved (see cursor_position).
311     *
312     * Any previously set composing text should be removed.
313     *
314     * @code
315     *   void YourCallbackName(  const std::string text );
316     * @endcode
317     */
318    CommitStringSignalType& CommitStringSignal();
319
320    /**
321     * @brief Cursor position signal
322     * From wayland-extension/protocol/text.xml:
323     * Notify when the cursor or anchor position should be modified.
324     * This event should be handled as part of a following commit_string  event.
325     *  @code
326     *   void YourCallbackName( int index, int anchor );
327     * @endcode
328     */
329    CursorPositionSignalType& CursorPositionSignal();
330
331    /**
332     * @brief delete surrounding text
333     * From wayland-extension/protocol/text.xml:
334     * Notify when the text around the current cursor position should be deleted.
335     * @code
336     * Index is relative to the current cursor (in bytes).
337     * Length is the length of deleted text (in bytes).
338     *
339     *  void YourCallbackName( int index, unsigned int length );
340     * @endcode
341     * This event should be handled as part of a following commit_string event.
342     */
343    DeleteSurroundingTextSignalType& DeleteSurroundingTextSignal();
344
345    /**
346     * @brief text selection region
347     * Notify when the input panels ask to select the characters
348     * from the start cursor position to the end cursor position.
349     * * @code
350     * Index is relative to the current cursor (in bytes).
351     * Length is the length of deleted text (in bytes).
352     *
353     * void YourCallbackName( unsigned int serial, int start, int end );
354     * @endcode
355     */
356    SelectionRegionSignalType& SelectionRegionSignal();
357
358 public:
359
360   /**
361    * POD to store text input data for each seat.
362    */
363   struct SeatInfo
364   {
365     SeatInfo()
366     : mTextDirection( Dali::VirtualKeyboard::LeftToRight ),
367       mSeat( NULL ),
368       mInputPanelDimensions( 0,0,0,0 ),
369       mReturnKeyType( InputMethod::ACTION_UNSPECIFIED ),
370       mInputPanelVisible( false ),
371       mFocused( false )
372     {
373
374     }
375     Dali::VirtualKeyboard::TextDirection mTextDirection;
376     Seat* mSeat;
377     Dali::Rect<int> mInputPanelDimensions;    ///< size of the input panel
378     std::string mLanguage;                    ///< input panel language
379     InputMethod::ActionButton mReturnKeyType; ///< return key
380     bool mInputPanelVisible:1;                ///< panel status
381     bool mFocused:1;
382   };
383
384   /**
385    * @brief get the last active seat
386    * @return the last active seat
387    */
388   SeatInfo& GetLastActiveSeat();
389
390 private:
391
392   WlDisplay* mDisplay;        ///< Wayland display, handles all the data sent from and to the compositor
393   Seat* mLastActiveSeat;      ///< Seat that was last used
394   WindowEventInterface* mWindowEventInterface;
395
396   std::vector< SeatInfo > mSeats;         ///< keeps track of text input information for each seat
397   Dali::VirtualKeyboard::StatusSignalType mKeyboardStatusSignal;
398   Dali::VirtualKeyboard::VoidSignalType   mKeyboardResizeSignal;
399   Dali::VirtualKeyboard::VoidSignalType   mKeyboardLanguageChangedSignal;
400
401   // Input Panel (Virtual Keyboard) signals
402   PreEditStringSignalType                 mPreEditStringSignal;
403   PreEditStylingSignalType                mPreEditStylingSignal;
404   PreEditCursorSignalType                 mPreEditCursorSignal;
405   CommitStringSignalType                  mCommitStringSignal;
406   CursorPositionSignalType                mCursorPositionSignal;
407   DeleteSurroundingTextSignalType         mDeleteSurroundingTextSignal;
408   SelectionRegionSignalType               mSelectionRegionSignal;
409
410 };
411
412
413 } // Internal
414 } // Adaptor
415 } // Dali
416
417 #endif