2ac731f165f0620236fa71edd166f932cf411109
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-imf-manager.h
1 #ifndef __DALI_TOOLKIT_TOOLKIT_IMF_MANAGER_H__
2 #define __DALI_TOOLKIT_TOOLKIT_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 #define __DALI_IMF_MANAGER_H__
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/signals/dali-signal-v2.h>
25
26 namespace Dali DALI_IMPORT_API
27 {
28
29 namespace Internal DALI_INTERNAL
30 {
31 namespace Adaptor
32 {
33 class ImfManager;
34 }
35 }
36
37 typedef void* ImfContext;
38
39 /**
40  * @brief The ImfManager class
41  * Specifically manages the ecore input method framework which enables the virtual or hardware keyboards.
42  */
43 class ImfManager : public BaseHandle
44 {
45 public:
46
47   enum ImfEvent
48   {
49     VOID,
50     PREEDIT,
51     COMMIT,
52     DELETESURROUNDING,
53     GETSURROUNDING
54   };
55
56   /**
57    * This structure is used to pass on data from the IMF regarding predictive text.
58    */
59   struct ImfEventData
60   {
61     /**
62      * Default Constructor.
63      */
64     ImfEventData()
65     : eventName( VOID ),
66       predictiveString(""),
67       cursorOffset( 0 ),
68       numberOfChars ( 0 )
69     {
70     };
71
72     /**
73      * Constructor
74      * @param[in] aEventName The name of the event from the IMF.
75      * @param[in] aPredictiveString The pre-edit or commit string.
76      * @param[in] aCursorOffset Start position from the current cursor position to start deleting characters.
77      * @param[in] aNumberOfChars The number of characters to delete from the cursorOffset.
78      */
79     ImfEventData(ImfEvent aEventName, const std::string& aPredictiveString, int aCursorOffset,int aNumberOfChars  )
80     : eventName(aEventName), predictiveString(aPredictiveString), cursorOffset( aCursorOffset ), numberOfChars( aNumberOfChars )
81     {
82     }
83
84     // Data
85     ImfEvent eventName; // The name of the event from the IMF.
86     std::string predictiveString; // The pre-edit or commit string.
87     int cursorOffset; // Start position from the current cursor position to start deleting characters.
88     int numberOfChars; //number of characters to delete from the cursorOffset.
89   };
90
91   /**
92    * Data required my IMF from the callback
93    */
94   struct ImfCallbackData
95   {
96     ImfCallbackData( )
97     : update( false ), cursorPosition( 0 ), preeditResetRequired ( false )
98     {
99     }
100
101     ImfCallbackData(bool aUpdate, int aCursorPosition, std::string aCurrentText, bool aPreeditResetRequired )
102     : update(aUpdate), cursorPosition(aCursorPosition), currentText( aCurrentText ), preeditResetRequired( aPreeditResetRequired )
103     {
104     }
105
106     bool update; // if cursor position needs to be updated
107     int cursorPosition; // new position of cursor
108     std::string currentText; // current text string
109     bool preeditResetRequired; // flag if preedit reset is required.
110   };
111
112   typedef SignalV2< void (ImfManager&) > ImfManagerSignalV2;
113
114   typedef SignalV2< ImfCallbackData ( ImfManager&, const ImfEventData& ) > ImfEventSignalV2;
115
116 public:
117
118   /**
119    * Retrieve a handle to the instance of ImfManager.
120    * @return A handle to the ImfManager.
121    */
122   static ImfManager Get();
123
124   /**
125    * Get the current imf context.
126    * @return current imf context.
127    */
128   ImfContext GetContext();
129
130   /**
131    * Activate the IMF.
132    * It means that the text editing is started at somewhere.
133    * If the H/W keyboard isn't connected then it will show the virtual keyboard.
134    */
135   void Activate();
136
137   /**
138    * Deactivate the IMF.
139    * It means that the text editing is finished at somewhere.
140    */
141   void Deactivate();
142
143   /**
144    * Get the restoration status, which controls if the keyboard is restored after the focus lost then regained.
145    * If true then keyboard will be restored (activated) after focus is regained.
146    * @return restoration status.
147    */
148   bool RestoreAfterFocusLost() const;
149
150   /**
151    * Set status whether the IMF has to restore the keyboard after losing focus.
152    * @param[in] toggle True means that keyboard should be restored after focus lost and regained.
153    */
154   void SetRestoreAferFocusLost( bool toggle );
155
156   /**
157    * Send message reset the pred-edit state / imf module.  Used to interupt pre-edit state maybe due to a touch input.
158    */
159   void Reset();
160
161   /**
162    * Notifies IMF context that the cursor position has changed, required for features like auto-capitalisation
163    */
164   void NotifyCursorPosition();
165
166   /**
167    * Sets cursor position stored in VirtualKeyboard, this is required by the IMF context
168    * @param[in] cursorPosition position of cursor
169    */
170   void SetCursorPosition( unsigned int cursorPosition );
171
172   /**
173    * Gets cursor position stored in VirtualKeyboard, this is required by the IMF context
174    * @return current position of cursor
175    */
176   int GetCursorPosition();
177
178   /**
179    * Method to store the string required by the IMF, this is used to provide predictive word suggestions.
180    * @param[in] text The text string surrounding the current cursor point.
181    */
182   void SetSurroundingText( std::string text );
183
184   /**
185    * Gets current text string set within the IMF manager, this is used to offer predictive suggestions
186    * @return current position of cursor
187    */
188   std::string GetSurroundingText();
189
190 public:
191
192   // Signals
193
194   /**
195    * This is emitted when the virtual keyboard is connected to or the hardware keyboard is activated.
196    * @return The IMF Activated signal.
197    */
198   ImfManagerSignalV2& ActivatedSignal();
199
200   /**
201    * This is emitted when the IMF manager receives an event from the IMF
202    * @return The Event signal containing the event data.
203    */
204   ImfEventSignalV2& EventReceivedSignal();
205
206   // Construction & Destruction
207
208   /**
209    * Constructor
210    */
211   ImfManager();
212
213   /**
214    * Non virtual destructor.
215    */
216   ~ImfManager();
217
218   /**
219    * This constructor is used by ImfManager::Get().
220    * @param[in] imfManager A pointer to the imf Manager.
221    */
222   ImfManager( Internal::Adaptor::ImfManager* imfManager );
223 };
224
225 } // namespace Dali
226
227 #endif // __DALI_TOOLKIT_TOOLKIT_IMF_MANAGER_H__