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 "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.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.
16 * Part of: Tactile Feedback.
22 #ifndef M_TOUCHFEEDBACK_H
23 #define M_TOUCHFEEDBACK_H
29 #include <touchlogicalfeedback.h>
30 #include <touchfeedbackspec.h>
35 * This is the Tactile Feedback interface for UI Controls.
37 * Provides an interface to add, modify and remove feedback areas
38 * in the registry. There is also an option to trigger direct feedback,
39 * hence bypassing the registry.
41 * Feedback areas must always be related to some UI Control (derived
42 * from CCoeControl). Areas are distinguished from each other based on
43 * control's address and an index number (so that it is possible
44 * to register and maintain multiple areas for same control).
46 * Clients must add, maintain and remove their feedback areas using this
47 * API according to the state changes of the application / control, and
48 * according to for e.g. device wide layout changes.
50 * There are two cases when tactile framework automatically updates the
51 * feedback areas for control: Feedback is always disabled when control
52 * becomes dimmed and re-enabled when control becomes undimmed again.
53 * If control becomes invisible, then feedback areas are (temporarily)
54 * removed, and they will be automatically added again when control
55 * becomes visible again.
57 * This class is not intended for derivation outside the library.
59 * @lib touchfeedback.lib
67 * Used for acquiring a pointer to touch feedback instance.
69 * Pointer is retrieved from thread local storage, and thus it is best
70 * to store the returned pointer as member variable in case it will
71 * be needed frequently.
73 * NULL is returned in case there is no instance. In that case
74 * CreateInstanceL -function can be used for creating a new instance.
77 * @return Pointer to touch feedback instance created for this
78 * application process.
80 IMPORT_C static MTouchFeedback* Instance();
83 * Creates a new touch feedback instance. The usage of
84 * this function should only be necessary from processes which
85 * are not GUI applications, but which still have user interface
86 * (or want to play direct feedback).
88 * DestroyInstance -function must be called for deleting the instance
89 * when it is no longer needed.
92 * @return Pointer to new touch feedback instance.
94 IMPORT_C static MTouchFeedback* CreateInstanceL();
97 * Destroys the touch feedback instance and clears pointer in
98 * thread local storage.
100 * This function must only be used in case touch feedback has been
101 * created with CreateInstanceL -function. I.e. normal GUI applications
102 * should never call this function.
106 IMPORT_C static void DestroyInstance();
109 * This function can be used to check, whether touch feedback is
110 * supported at all in the device.
112 * All the API functions can be called safely even if touch feedback
113 * is not enabled (for e.g. in devices without touch screen). But in
114 * some situations registry updates can require complex calculations,
115 * which can be skipped if touch feedback is not enabled at all.
117 * Notice that the settings related to touch feedback have no effect
118 * on the behavior of this function. I.e. even if user turns touch
119 * feedback OFF from settings, this function still returns
120 * ETrue. The reason for this is that registry updates must be done
121 * anyway even if the feedback is not on for the moment, because
122 * user can turn it on at anytime, and it is not possible to force
123 * an update for all applications in that case.
126 * @return ETrue if touch feedback is supported in this device.
128 virtual TBool TouchFeedbackSupported() = 0;
131 * Used for disabling or enabling feedback in the application.
133 * Tactile feedback is enabled by default, and thus standard
134 * S60 components (such as CBA, lists and options menu) automatically
135 * give feedback even if the application itself would make no effort
136 * for producing feedback.
138 * For some applications (such as games) feedback might not be
139 * wanted at all. In addition some applications may need to disable
140 * feedback in some specific situations. For example: A camera
141 * application may need to disable feedback during video recording,
142 * because otherwise feedbacks may cause disturbing sounds that
143 * will be recorded into the video clip.
145 * Notice that this function only affects direct feedback and
146 * area registry based feedback for this application. I.e. if this
147 * application is taken to background, other applications can still
150 * Also notice that enabling feedback doesn't still mean that feedback
151 * would necessarily be generated, because user may have disabled the
152 * feedback for whole device from the settings.
155 * @param aEnabled - Give ETrue as parameter for enabling feedback, and
156 * EFalse for disabling feedback.
158 virtual void SetFeedbackEnabledForThisApp( TBool aEnabled ) = 0;
161 * Used to check whether feedback is enabled for this application.
163 * Notice that this function only returns what was given as parameter
164 * to SetFeedbackEnabledForThisApp -function. I.e. this function
165 * can return ETrue even if feedback would be currently disabled
168 * If only vibra or audio feedback is enabled, this function still
172 * @return ETrue if feedback is enabled for this application.
174 virtual TBool FeedbackEnabledForThisApp() = 0;
177 * Sets or updates rectangular feedback area to registry.
179 * If this is new area (i.e. there is not yet area with given control
180 * address and area index in the registry), then this area will be
181 * added as the top priority area for its window, i.e. this
182 * area will be hit test first when pointer event arrives.
184 * Notice however, that this area will remain as top priority area only
185 * until the next new area is added to the registry, or until
186 * MoveFeedbackAreaToFirstPriority -function is called. I.e. new areas
187 * are always put on top priority, but they will only remain on top
188 * until they will be overridden by next area.
190 * The control that is given as parameter should usually be the one
191 * that is responsible of handling the pointer events on the
192 * corresponding feedback area.
194 * The area can later be identified by passing control pointer and
195 * index as parameters to the other functions (for modifying or
196 * removing the feedback area). In case control only
197 * registers one area, then index 0 can always be used. Usually most
198 * sensible approach is to use indexes 1, 2, 3 etc. for additional
199 * feedback areas, but in practice any desired index values can be
202 * Notice that if given control is dimmed, then feedback type will
203 * be set to "None". If given control is not visible, then feedback
204 * area will not be added to registry at all (for now). However,
205 * registry is automatically updated when control's dimming or
206 * visibility changes, so one can call this function also for
207 * dimmed and invisible control.
209 * When the control given as parameter to this function is destroyed,
210 * then the RemoveFeedbackForControl -function must be called while
211 * giving the same control as parameter again. This is necessary
212 * for removing all the feedback areas, and also for resetting the
213 * state information stored by the API implementation.
216 * @param aControl - The control handling pointer events on this
218 * @param aIndex - The index number of the area to be added.
219 * @param aRect - The feedback area rectangle.
220 * @param aFeedbackType - The logical feedback type given
221 * @param aEventType - The pointer event type that triggers the
222 * feedback (currently only ETouchEventStylusDown
224 * @return KErrNone, or one of standard Symbian OS error codes
225 * if setting of area to registry failed.
226 * Some specific error codes:
227 * KErrArgument - A NULL pointer was given as first parameter, or
228 * the given control does not have any window
230 * KErrNotSupported - Unsupported logical feedback type or
231 * event type was given as parameter.
233 virtual TInt SetFeedbackArea( const CCoeControl* aControl,
236 TTouchLogicalFeedback aFeedbackType,
237 TTouchEventType aEventType ) = 0;
240 * Removes feedback area from the registry.
242 * This function is designed to be used in case feedback areas
243 * need to be removed elsewhere than in control's destructor. In
244 * control's destructor RemoveFeedbackForControl -function must be
248 * @param aControl - The control, who has registered the area.
249 * @param aIndex - The index of the area to be removed.
251 virtual void RemoveFeedbackArea( const CCoeControl* aControl,
252 TUint32 aIndex ) = 0;
255 * Removes all feedback areas of specified control from registry.
257 * This function also clears all related data that has been cached
258 * by the API implementation, and thus it must always be called from
259 * control's destructor in case control has used any of the following
262 * - EnableFeedbackForControl
264 * Especially notice that it is not enough to remove all feedback areas
265 * individually by using RemoveFeedbackArea -function.
267 * The difference between this function and EnableFeedbackForControl
268 * -function is that this function really removes all areas related
269 * to this control from registry, whereas EnableFeedbackForControl
270 * (when EFalse if given as parameter) only temporarily disables
274 * @param aControl - Pointer to the control, whose area registry
275 * entries and cached information will be removed.
277 virtual void RemoveFeedbackForControl( const CCoeControl* aControl ) = 0;
280 * Changes feedback area in the registry.
282 * The area must have been originally added to the registry with
283 * SetFeedbackArea -function, or otherwise this function will
286 * This function is intended to be used especially in
287 * portrait / landscape changes.
289 * If given CCoeControl pointer is NULL, then this function call
293 * @param aControl - The control, who has registered the area.
294 * @param aIndex - The index number of the area, that will be changed.
295 * @param aNewRect - New area rectangle for given feedback area.
297 virtual void ChangeFeedbackArea( const CCoeControl* aControl,
299 TRect aNewRect ) = 0;
302 * Changes feedback type in the registry.
304 * Feedback can be temporarily disabled by giving ETouchFeedbackNone
305 * as parameter (although using EnableFeedbackForControl function with
306 * parameter EFalse is usually better for this functionality).
308 * The area must have been originally added to the registry with
309 * SetFeedbackArea -function, or otherwise this function will
312 * If given control pointer is NULL, then this function call
315 * This function only changes feedback type for down event.
316 * To change feedback types for all the events in the feedback area use
317 * function SetFeedbackArea with CFeedbackSpec container class
321 * @param aControl - The control, who has registered the area.
322 * @param aIndex - The index number of the area, that will be changed.
323 * @param aNewType - New feedback type for the area.
325 virtual void ChangeFeedbackType( const CCoeControl* aControl,
327 TTouchLogicalFeedback aNewType ) = 0;
331 * Makes the given feedback area the first priority area in the window
332 * where it is located.
334 * In practice this means that this will be the first area that is
335 * hit tested when a pointer event arrives.
337 * Notice however, that this area will only keep its top priority status
338 * until the next area is added to the registry, or until
339 * this function is called again for some other area. I.e. there is no
340 * way for giving any area a permanent status as top priority area
341 * (Registry works as a stack, and new items are added on top).
343 * If given control pointer is NULL, this function call does nothing.
346 * @param aControl - The control, who has registered the area.
347 * @param aIndex - The index number of the area, which
348 * will be prioritized.
350 virtual void MoveFeedbackAreaToFirstPriority( const CCoeControl* aControl,
351 TUint32 aIndex ) = 0;
354 * This function forces all registry changes made on client side to be
355 * sent to server side immediately.
357 * This operation causes always immediate and synchronous client-server
358 * transaction, and can possibly also cause flushing of window server
359 * client side buffer. Hence this function should only be used in case
360 * there is a synchronization problem so that feedback triggered from
361 * area registry does not correspond to the areas defined by application.
363 * This function is only likely to help in such situation, where this
364 * application's active objects are running all the time for several seconds,
365 * because in that case updates won't be transferred to server immediately.
367 * Calling this function has no effect in case there are no pending
368 * area registry updates.
372 virtual void FlushRegistryUpdates( ) = 0;
375 * Gives direct feedback.
377 * Notice that the feedback might not be actually played, if
378 * for example user has disabled the feedback from the settings.
380 * This function always causes a synchronous client-server transaction,
381 * and potentially flushing of window server client-side buffer.
384 * @param aType - The logical feedback type to play.
386 virtual void InstantFeedback( TTouchLogicalFeedback aType ) = 0;
389 * Gives direct feedback if given control has not disabled it.
391 * This function only gives feedback, if EnableFeedbackForControl
392 * function has NOT been called on given control with second
395 * This overload is recommended when
396 * feedback is triggered from UI controls, because then the owner
397 * of the control can decide whether both area registry based and
398 * direct feedback should be enabled or not.
400 * If feedback is enabled for the given control, then this function
401 * causes a synchronous client-server transaction,
402 * and potentially flushing of window server client-side buffer.
405 * @param aControl - The control, who wishes to play feedback.
406 * @param aType - The logical feedback type to play.
408 virtual void InstantFeedback( const CCoeControl* aControl,
409 TTouchLogicalFeedback aType ) = 0;
413 * Can be used for querying, whether given control has any feedback
416 * It does not matter whether the areas are disabled or enabled for
419 * Notice that one should not usually call this function, as it
420 * is always allowed to call for example RemoveFeedbackArea
421 * -function without checking if the area really exists (this
422 * is done internally in the API implementation anyway).
425 * @param aControl - Pointer to the control, whose feedback is
427 * @return ETrue if the given control has at least one feedback
428 * area defined. EFalse otherwise.
430 virtual TBool ControlHasFeedback( const CCoeControl* aControl ) = 0;
433 * Can be used for querying, whether given control has a feedback
434 * area defined with given index number.
436 * It does not matter whether the areas are disabled or enabled for
439 * Notice that one should not usually call this function, as it
440 * is always allowed to call for example RemoveFeedbackArea
441 * -function without checking if the area really exists (this
442 * is done internally in the API implementation anyway).
445 * @param aControl - Pointer to the control, whose feedback is
447 * @param aIndex - The index number of the area which is queried.
448 * @return ETrue if the given control has a feedback area defined
449 * with given index number. EFalse otherwise.
451 virtual TBool ControlHasFeedback( const CCoeControl* aControl,
452 TUint32 aIndex ) = 0;
455 * This function enables or disables all feedback areas registered for
456 * the given control. Disabling also affects to the overloaded version
457 * of InstantFeedback -function, so that feedback is not played if
458 * the control given as parameter has its feedback disabled.
460 * This function can be used for temporarily disabling
461 * the feedback for some given control. Calling with second parameter
462 * ETrue re-enables feedback areas, but it still does not
463 * guarantee any feedback (control can be dimmed, invisible, of may not
464 * even have any feedback areas registered).
466 * This function affects both vibra- and audio feedback.
468 * Any control that uses this function must call RemoveFeedbackForControl
469 * -function in its destructor.
472 * @param aControl - Pointer to control, whose feedback will be
473 * enabled or disabled according to second parameter.
474 * @param aEnable - Use EFalse for temporary disabling the feedback for
475 * this control, and ETrue for restoring the situation
478 virtual void EnableFeedbackForControl( const CCoeControl* aControl,
482 * This function can be used for separately enabling or disabling audio-
483 * and vibra feedback for the given control.
485 * Otherwise the function behaves in the same way as the overload with
486 * only one TBool parameter.
488 * Any control that uses this function must call RemoveFeedbackForControl
489 * -function in its destructor.
492 * @param aControl - Pointer to control, whose audio- and vibra
493 * feedback will be enabled or disabled according
494 * to given parameters.
495 * @param aEnableVibra - Use EFalse for temporary disabling the vibra
496 * feedback for this control, and ETrue for
497 * restoring the situation to normal.
498 * @param aEnableAudio - Use EFalse for temporary disabling the audio
499 * feedback for this control, and ETrue for
500 * restoring the situation to normal.
502 virtual void EnableFeedbackForControl( const CCoeControl* aControl,
504 TBool aEnableAudio ) = 0;
507 * Used for disabling/enabling audio/vibra feedback in
510 * This is identical with the overload which has only one parameter,
511 * with the exception that one can disable audio and vibra feedback
512 * separately with this version.
515 * @param aVibraEnabled - Give ETrue as parameter for enabling vibra
516 * feedback, and EFalse for disabling vibra
517 * feedback for this application.
518 * @param aAudioEnabled - Give ETrue as parameter for enabling audio
519 * feedback, and EFalse for disabling audio
520 * feedback for this application.
522 virtual void SetFeedbackEnabledForThisApp( TBool aVibraEnabled,
523 TBool aAudioEnabled ) = 0;
527 * Used to check whether audio or vibra feedback is enabled for this application.
529 * Notice that this function only returns what was given as parameter
530 * to SetFeedbackEnabledForThisApp -function. I.e. this function
531 * can return ETrue even if feedback would be currently disabled
535 * @param aFeedbackType - Feedback type.
536 * @return ETrue if asked feedback type is enabled for this application.
538 virtual TBool FeedbackEnabledForThisApp( TTouchFeedbackType aFeedbackType ) = 0;
541 * Starts continuous feedback if given control has not disabled it.
543 * Only one continuous feedback per control can be played simultaneously.
544 * Started feedback will be stopped automatically if application loses
545 * key focus or application crashes or some other control starts
546 * continuous feedback.
548 * If StartFeedback is called again for the same control, then feedback
549 * type and intensity are modified accordingly. This may cause a break
550 * in the feedback effect in case feedback type changes.
552 * EnableFeedbackForControl also affects to this function so that
553 * feedback is not given if EnableFeedbackForControl
554 * function has been called with second and third parameter EFalse.
557 * @param aControl - The control, who wishes to play feedback.
558 * @param aType - The continuous feedback type to play.
559 * @param aPointerEvent - Pointer event which triggered this feedback
560 * (give NULL as parameter if no related pointer
562 * @param aIntensity - Feedback intensity to begin with. range 0-100%.
563 * Use 50% if no reason to use other value.
564 * @param aTimeout - Timeout value to automatically stop continuous
565 * feedback if there's no new Start call within the
566 * timeout. Use value 0 if timeout is not used.
568 virtual void StartFeedback( const CCoeControl* aControl,
569 TTouchContinuousFeedback aType,
570 const TPointerEvent* aPointerEvent,
572 TTimeIntervalMicroSeconds32 aTimeout ) = 0;
576 * This function modifies intensity of continuous feedback on the fly.
579 * @param aControl - The control which continuous feedback is modified.
580 * @param aIntensity - New intensity value. range 0-100%
582 virtual void ModifyFeedback( const CCoeControl* aControl,
583 TInt aIntensity ) = 0;
587 * This function stops continuous feedback.
590 * @param aControl - The control which continuous feedback is stopped.
592 virtual void StopFeedback( const CCoeControl* aControl ) = 0;
596 * This function enables or disables audio or/and vibra feedback in
599 * Tactile feedback is enabled by default, and thus standard
600 * S60 components (such as CBA, lists and options menu) automatically
601 * give feedback even if the application itself would make no effort
602 * for producing feedback.
604 * Requires WriteDeviceData capability
607 * @param aFeedbackType - Feedback types to be enabled/disabled defined as
608 * a bitmask combination of enumeration items from
610 * @return KErrNone, or one of standard Symbian OS error codes
611 * if user has not WriteDeviceData capability.
613 virtual TInt SetFeedbackEnabledForDevice( TTouchFeedbackType aFeedbackType ) = 0;
617 * Used to check enabled feedback types for the device.
619 * Notice that this function only returns what was given as parameter
620 * to SetFeedbackEnabledForDevice -function. I.e. this function
621 * can return ETrue even if feedback would be currently disabled
625 * @return Enabled/disabled feedback types as bitmask combination.
627 virtual TTouchFeedbackType FeedbackEnabledForDevice() = 0;
631 * Gives direct feedback if given control has not disabled it.
633 * This overload is recommended when triggered feedback is related
634 * to pointer event. System uses aPointerEvent to avoiding
635 * two (or more) direct feedbacks for the same pointer event.
638 * @param aControl - The control, who wishes to play feedback.
639 * @param aType - The logical feedback type to play.
640 * @param aPointerEvent - pointer event which triggered this feedback.
642 virtual void InstantFeedback( const CCoeControl* aControl,
643 TTouchLogicalFeedback aType,
644 const TPointerEvent& aPointerEvent ) = 0;
648 * Sets or updates rectangular feedback area to registry.
650 * This overload allows user to set more than one touch event types to
651 * one feedback area. Otherwise the function behaves in the same way
652 * as the overload with separated feedback type and event type parameters.
655 * @param aControl - The control handling pointer events on this
657 * @param aIndex - The index number of the area to be added.
658 * @param aRect - The feedback area rectangle.
659 * @param aFeedbackSpec - The specification how this feedback area
660 * triggers feedback for different touch events.
661 * @return KErrNone, or one of standard Symbian OS error codes
662 * if setting of area to registry failed.
663 * Some specific error codes:
664 * KErrArgument - A NULL pointer was given as first parameter, or
665 * the given control does not have any window
667 * KErrNotSupported - Unsupported predefined feedback profile
668 * was given as parameter.
670 virtual TInt SetFeedbackArea( const CCoeControl* aControl,
673 CFeedbackSpec* aFeedbackSpec ) = 0;
676 * Gives direct feedback if given control has not disabled it.
678 * This overload is recommended when triggered feedback is related
679 * to pointer event. System uses aPointerEvent to avoiding
680 * two (or more) direct feedbacks for the same pointer event. Using this
681 * overload it is also possible to disable unwanted feedback (vibra/audio)
682 * by giving only wanted feedback type as parameter.
685 * @param aControl - The control, who wishes to play feedback.
686 * @param aType - The logical feedback type to play.
687 * @param aFeedbackType - Feedback types to be played as a bitmask
688 * combination of enumeration items from
690 * @param aPointerEvent - Pointer event, which triggered this feedback.
692 virtual void InstantFeedback( const CCoeControl* aControl,
693 TTouchLogicalFeedback aType,
694 TTouchFeedbackType aFeedbackType,
695 const TPointerEvent& aPointerEvent ) = 0;
703 #endif // M_TOUCHFEEDBACK_H