2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Interface for using area registry and direct feedback from
15 * applications and UI controls.
21 #ifndef M_TOUCHFEEDBACK_H
22 #define M_TOUCHFEEDBACK_H
28 #include <touchlogicalfeedback.h>
34 * This is the Tactile Feedback interface for UI Controls.
36 * Provides an interface to add, modify and remove feedback areas
37 * in the registry. There is also an option to trigger direct feedback,
38 * hence bypassing the registry.
40 * Feedback areas must always be related to some UI Control (derived
41 * from CCoeControl). Areas are distinguished from each other based on
42 * control's address and an index number (so that it is possible
43 * to register and maintain multiple areas for same control).
45 * Clients must add, maintain and remove their feedback areas using this
46 * API according to the state changes of the application / control, and
47 * according to for e.g. device wide layout changes.
49 * There are two cases when tactile framework automatically updates the
50 * feedback areas for control: Feedback is always disabled when control
51 * becomes dimmed and re-enabled when control becomes undimmed again.
52 * If control becomes invisible, then feedback areas are (temporarily)
53 * removed, and they will be automatically added again when control
54 * becomes visible again.
56 * This class is not intended for derivation outside the library.
58 * @lib touchfeedback.lib
66 * Used for acquiring a pointer to touch feedback instance.
68 * Pointer is retrieved from thread local storage, and thus it is best
69 * to store the returned pointer as member variable in case it will
70 * be needed frequently.
72 * NULL is returned in case there is no instance. In that case
73 * CreateInstanceL -function can be used for creating a new instance.
76 * @return Pointer to touch feedback instance created for this
77 * application process.
79 IMPORT_C static MTouchFeedback* Instance();
82 * Creates a new touch feedback instance. The usage of
83 * this function should only be necessary from processes which
84 * are not GUI applications, but which still have user interface
85 * (or want to play direct feedback).
87 * DestroyInstance -function must be called for deleting the instance
88 * when it is no longer needed.
91 * @return Pointer to new touch feedback instance.
93 IMPORT_C static MTouchFeedback* CreateInstanceL();
96 * Destroys the touch feedback instance and clears pointer in
97 * thread local storage.
99 * This function must only be used in case touch feedback has been
100 * created with CreateInstanceL -function. I.e. normal GUI applications
101 * should never call this function.
105 IMPORT_C static void DestroyInstance();
108 * This function can be used to check, whether touch feedback is
109 * supported at all in the device.
111 * All the API functions can be called safely even if touch feedback
112 * is not enabled (for e.g. in devices without touch screen). But in
113 * some situations registry updates can require complex calculations,
114 * which can be skipped if touch feedback is not enabled at all.
116 * Notice that the settings related to touch feedback have no effect
117 * on the behavior of this function. I.e. even if user turns touch
118 * feedback OFF from settings, this function still returns
119 * ETrue. The reason for this is that registry updates must be done
120 * anyway even if the feedback is not on for the moment, because
121 * user can turn it on at anytime, and it is not possible to force
122 * an update for all applications in that case.
125 * @return ETrue if touch feedback is supported in this device.
127 virtual TBool TouchFeedbackSupported() = 0;
130 * Used for disabling or enabling feedback in the application.
132 * Tactile feedback is enabled by default, and thus standard
133 * S60 components (such as CBA, lists and options menu) automatically
134 * give feedback even if the application itself would make no effort
135 * for producing feedback.
137 * For some applications (such as games) feedback might not be
138 * wanted at all. In addition some applications may need to disable
139 * feedback in some specific situations. For example: A camera
140 * application may need to disable feedback during video recording,
141 * because otherwise feedbacks may cause disturbing sounds that
142 * will be recorded into the video clip.
144 * Notice that this function only affects direct feedback and
145 * area registry based feedback for this application. I.e. if this
146 * application is taken to background, other applications can still
149 * Also notice that enabling feedback doesn't still mean that feedback
150 * would necessarily be generated, because user may have disabled the
151 * feedback for whole device from the settings.
154 * @param aEnabled - Give ETrue as parameter for enabling feedback, and
155 * EFalse for disabling feedback.
157 virtual void SetFeedbackEnabledForThisApp( TBool aEnabled ) = 0;
160 * Used to check whether feedback is enabled for this application.
162 * Notice that this function only returns what was given as parameter
163 * to SetFeedbackEnabledForThisApp -function. I.e. this function
164 * can return ETrue even if feedback would be currently disabled
167 * If only vibra or audio feedback is enabled, this function still
171 * @return ETrue if feedback is enabled for this application.
173 virtual TBool FeedbackEnabledForThisApp() = 0;
176 * Sets or updates rectangular feedback area to registry.
178 * If this is new area (i.e. there is not yet area with given control
179 * address and area index in the registry), then this area will be
180 * added as the top priority area for its window, i.e. this
181 * area will be hit test first when pointer event arrives.
183 * Notice however, that this area will remain as top priority area only
184 * until the next new area is added to the registry, or until
185 * MoveFeedbackAreaToFirstPriority -function is called. I.e. new areas
186 * are always put on top priority, but they will only remain on top
187 * until they will be overridden by next area.
189 * The control that is given as parameter should usually be the one
190 * that is responsible of handling the pointer events on the
191 * corresponding feedback area.
193 * The area can later be identified by passing control pointer and
194 * index as parameters to the other functions (for modifying or
195 * removing the feedback area). In case control only
196 * registers one area, then index 0 can always be used. Usually most
197 * sensible approach is to use indexes 1, 2, 3 etc. for additional
198 * feedback areas, but in practice any desired index values can be
201 * Notice that if given control is dimmed, then feedback type will
202 * be set to "None". If given control is not visible, then feedback
203 * area will not be added to registry at all (for now). However,
204 * registry is automatically updated when control's dimming or
205 * visibility changes, so one can call this function also for
206 * dimmed and invisible control.
208 * When the control given as parameter to this function is destroyed,
209 * then the RemoveFeedbackForControl -function must be called while
210 * giving the same control as parameter again. This is necessary
211 * for removing all the feedback areas, and also for resetting the
212 * state information stored by the API implementation.
215 * @param aControl - The control handling pointer events on this
217 * @param aIndex - The index number of the area to be added.
218 * @param aRect - The feedback area rectangle.
219 * @param aFeedbackType - The logical feedback type given
220 * @param aEventType - The pointer event type that triggers the
221 * feedback (currently only ETouchEventStylusDown
223 * @return KErrNone, or one of standard Symbian OS error codes
224 * if setting of area to registry failed.
225 * Some specific error codes:
226 * KErrArgument - A NULL pointer was given as first parameter, or
227 * the given control does not have any window
229 * KErrNotSupported - Unsupported logical feedback type or
230 * event type was given as parameter.
232 virtual TInt SetFeedbackArea( const CCoeControl* aControl,
235 TTouchLogicalFeedback aFeedbackType,
236 TTouchEventType aEventType ) = 0;
239 * Removes feedback area from the registry.
241 * This function is designed to be used in case feedback areas
242 * need to be removed elsewhere than in control's destructor. In
243 * control's destructor RemoveFeedbackForControl -function must be
247 * @param aControl - The control, who has registered the area.
248 * @param aIndex - The index of the area to be removed.
250 virtual void RemoveFeedbackArea( const CCoeControl* aControl,
251 TUint32 aIndex ) = 0;
254 * Removes all feedback areas of specified control from registry.
256 * This function also clears all related data that has been cached
257 * by the API implementation, and thus it must always be called from
258 * control's destructor in case control has used any of the following
261 * - EnableFeedbackForControl
263 * Especially notice that it is not enough to remove all feedback areas
264 * individually by using RemoveFeedbackArea -function.
266 * The difference between this function and EnableFeedbackForControl
267 * -function is that this function really removes all areas related
268 * to this control from registry, whereas EnableFeedbackForControl
269 * (when EFalse if given as parameter) only temporarily disables
273 * @param aControl - Pointer to the control, whose area registry
274 * entries and cached information will be removed.
276 virtual void RemoveFeedbackForControl( const CCoeControl* aControl ) = 0;
279 * Changes feedback area in the registry.
281 * The area must have been originally added to the registry with
282 * SetFeedbackArea -function, or otherwise this function will
285 * This function is intended to be used especially in
286 * portrait / landscape changes.
288 * If given CCoeControl pointer is NULL, then this function call
292 * @param aControl - The control, who has registered the area.
293 * @param aIndex - The index number of the area, that will be changed.
294 * @param aNewRect - New area rectangle for given feedback area.
296 virtual void ChangeFeedbackArea( const CCoeControl* aControl,
298 TRect aNewRect ) = 0;
301 * Changes feedback type in the registry.
303 * Feedback can be temporarily disabled by giving ETouchFeedbackNone
304 * as parameter (although using EnableFeedbackForControl function with
305 * parameter EFalse is usually better for this functionality).
307 * The area must have been originally added to the registry with
308 * SetFeedbackArea -function, or otherwise this function will
311 * If given control pointer is NULL, then this function call
315 * @param aControl - The control, who has registered the area.
316 * @param aIndex - The index number of the area, that will be changed.
317 * @param aNewType - New feedback type for the area.
319 virtual void ChangeFeedbackType( const CCoeControl* aControl,
321 TTouchLogicalFeedback aNewType ) = 0;
325 * Makes the given feedback area the first priority area in the window
326 * where it is located.
328 * In practice this means that this will be the first area that is
329 * hit tested when a pointer event arrives.
331 * Notice however, that this area will only keep its top priority status
332 * until the next area is added to the registry, or until
333 * this function is called again for some other area. I.e. there is no
334 * way for giving any area a permanent status as top priority area
335 * (Registry works as a stack, and new items are added on top).
337 * If given control pointer is NULL, this function call does nothing.
340 * @param aControl - The control, who has registered the area.
341 * @param aIndex - The index number of the area, which
342 * will be prioritized.
344 virtual void MoveFeedbackAreaToFirstPriority( const CCoeControl* aControl,
345 TUint32 aIndex ) = 0;
348 * This function forces all registry changes made on client side to be
349 * sent to server side immediately.
351 * This operation causes always immediate and synchronous client-server
352 * transaction, and can possibly also cause flushing of window server
353 * client side buffer. Hence this function should only be used in case
354 * there is a synchronization problem so that feedback triggered from
355 * area registry does not correspond to the areas defined by application.
357 * This function is only likely to help in such situation, where this
358 * application's active objects are running all the time for several seconds,
359 * because in that case updates won't be transferred to server immediately.
361 * Calling this function has no effect in case there are no pending
362 * area registry updates.
366 virtual void FlushRegistryUpdates( ) = 0;
369 * Gives direct feedback.
371 * Notice that the feedback might not be actually played, if
372 * for example user has disabled the feedback from the settings.
374 * This function always causes a synchronous client-server transaction,
375 * and potentially flushing of window server client-side buffer.
378 * @param aType - The logical feedback type to play.
380 virtual void InstantFeedback( TTouchLogicalFeedback aType ) = 0;
383 * Gives direct feedback if given control has not disabled it.
385 * This function only gives feedback, if EnableFeedbackForControl
386 * function has NOT been called on given control with second
389 * This overload is recommended when
390 * feedback is triggered from UI controls, because then the owner
391 * of the control can decide whether both area registry based and
392 * direct feedback should be enabled or not.
394 * If feedback is enabled for the given control, then this function
395 * causes a synchronous client-server transaction,
396 * and potentially flushing of window server client-side buffer.
399 * @param aControl - The control, who fishes to play feedback.
400 * @param aType - The logical feedback type to play.
402 virtual void InstantFeedback( const CCoeControl* aControl,
403 TTouchLogicalFeedback aType ) = 0;
407 * Can be used for querying, whether given control has any feedback
410 * It does not matter whether the areas are disabled or enabled for
413 * Notice that one should not usually call this function, as it
414 * is always allowed to call for example RemoveFeedbackArea
415 * -function without checking if the area really exists (this
416 * is done internally in the API implementation anyway).
419 * @param aControl - Pointer to the control, whose feedback is
421 * @return ETrue if the given control has at least one feedback
422 * area defined. EFalse otherwise.
424 virtual TBool ControlHasFeedback( const CCoeControl* aControl ) = 0;
427 * Can be used for querying, whether given control has a feedback
428 * area defined with given index number.
430 * It does not matter whether the areas are disabled or enabled for
433 * Notice that one should not usually call this function, as it
434 * is always allowed to call for example RemoveFeedbackArea
435 * -function without checking if the area really exists (this
436 * is done internally in the API implementation anyway).
439 * @param aControl - Pointer to the control, whose feedback is
441 * @param aIndex - The index number of the area which is queried.
442 * @return ETrue if the given control has a feedback area defined
443 * with given index number. EFalse otherwise.
445 virtual TBool ControlHasFeedback( const CCoeControl* aControl,
446 TUint32 aIndex ) = 0;
449 * This function enables or disables all feedback areas registered for
450 * the given control. Disabling also affects to the overloaded version
451 * of InstantFeedback -function, so that feedback is not played if
452 * the control given as parameter has its feedback disabled.
454 * This function can be used for temporarily disabling
455 * the feedback for some given control. Calling with second parameter
456 * ETrue re-enables feedback areas, but it still does not
457 * guarantee any feedback (control can be dimmed, invisible, of may not
458 * even have any feedback areas registered).
460 * This function affects both vibra- and audio feedback.
462 * Any control that uses this function must call RemoveFeedbackForControl
463 * -function in its destructor.
466 * @param aControl - Pointer to control, whose feedback will be
467 * enabled or disabled according to second parameter.
468 * @param aEnable - Use EFalse for temporary disabling the feedback for
469 * this control, and ETrue for restoring the situation
472 virtual void EnableFeedbackForControl( const CCoeControl* aControl,
476 * This function can be used for separately enabling or disabling audio-
477 * and vibra feedback for the given control.
479 * Otherwise the function behaves in the same way as the overload with
480 * only one TBool parameter.
482 * Any control that uses this function must call RemoveFeedbackForControl
483 * -function in its destructor.
486 * @param aControl - Pointer to control, whose audio- and vibra
487 * feedback will be enabled or disabled according
488 * to given parameters.
489 * @param aEnableVibra - Use EFalse for temporary disabling the vibra
490 * feedback for this control, and ETrue for
491 * restoring the situation to normal.
492 * @param aEnableAudio - Use EFalse for temporary disabling the audio
493 * feedback for this control, and ETrue for
494 * restoring the situation to normal.
496 virtual void EnableFeedbackForControl( const CCoeControl* aControl,
498 TBool aEnableAudio ) = 0;
501 * Used for disabling or enabling feedback in the application.
503 * This is identical with the overload which has only one parameter,
504 * with the exception that one can disable audio and vibra feedback
505 * separately with this version.
508 * @param aVibraEnabled - Give ETrue as parameter for enabling vibra
509 * feedback, and EFalse for disabling vibra
510 * feedback for this application.
511 * @param aAudioEnabled - Give ETrue as parameter for enabling audio
512 * feedback, and EFalse for disabling audio
513 * feedback for this application.
515 virtual void SetFeedbackEnabledForThisApp( TBool aVibraEnabled,
516 TBool aAudioEnabled ) = 0;
521 #endif // M_TOUCHFEEDBACK_H