Using area registry based feedback

To use area registry based feedback, you must usually first call MTouchFeedback::Instance (unless you get a reference to it via another class).

It is recommended that you store the returned pointer as a member variable in those places where it is needed frequently. This is because the pointer is fetched from thread local storage, which can be somewhat time-consuming.

To add feedback areas to the area registry, use the SetFeedbackArea function. Usually the best place to do this is SizeChanged function, because that is also the place to update feedback areas in case of a layout change.

Note:

You can also use the same SetFeedbackArea function for updating the feedback area (the API implementation adds the area to the registry on the first time, and then just does updates on subsequent calls to this function).

If you want to change the feedback area or type without giving all the parameters again, use the functions ChangeFeedbackArea and ChangeFeedbackType for the updates.

Also notice that you have to be prepared in case your control is moved with CCoeControl::SetPosition function. For this you need to override CCoeControl::PositionChanged , and update the feedback area there the same way as in the SizeChanged function. Moreover, notice that this is necessary only for those non-window-owning controls, which produce area registry based feedback.

Feedback areas of a specific control will be automatically disabled in case the control becomes dimmed by CCoeControl::SetDimmed( ETrue ) or invisible by CCoeControl::MakeVisible( EFalse ) . Feedback will be re-enabled again when control becomes both undimmed and visible. This functionality is based on using the object provider hierarchy, and thus it does not work in case the object provider parent has not been set for the control.

If you need to disable a control’s feedback area temporarily (for other reasons than dimming or visibility), call EnableFeedbackForControl with second parameter EFalse to disable the feedback. You can then re-enable feedback by calling EnableFeedbackForControl with second parameter ETrue . Disabling of control’s feedback also affects direct feedback if it is generated with the overloaded version, which takes the control’s pointer as the second parameter.

In some special cases it may be necessary to only disable audio- or vibra feedback for some controls. For this purpose there is a specific overload of EnableFeedbackForControl function.

You must remove your control's feedback areas at the latest when you destroy the control. To do this, call the function RemoveFeedbackForControl . This also resets the feedback disabling information for the deleted control. If needed, you can remove individual feedback areas with the RemoveFeedbackArea function any time, but you must still call RemoveFeedbackForControl you destroy the control.

The example below illustrates using tactile feedback based on the area registry.

  1. Add the library touchfeedback.lib into your .mmp file, and then add the following include to your .cpp file:

            #include <touchfeedback.h>
           
  2. Update the area registry in the SizeChanged function.

    Note:

    You don’t need to check if you have already the area added to the registry or not, because you can use the SetFeedbackArea function anyway. (On the first time this function adds area to the registry, and on the second it updates the area.)

            MTouchFeedback* feedback = MTouchFeedback::Instance();
    
    if ( feedback )
        {
        feedback->SetFeedbackArea( 
            this,
            0, 
            Rect(), 
            ETouchFeedbackBasic,
            ETouchEventStylusDown );
        }
           

    The second parameter given to the SetFeedbackArea function is an index number, which is used to distinguish the feedback areas of same control from each other (in case the control has many feedback areas). You can choose the index numbers freely. It is recommended that you always use zero as the index if your control only has one feedback area.