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