Listening for scrollbar touch events

If your custom control contains a scrollbar, you need to listen for touch events in the scrollbar.

For custom controls that override CCoeControl::HandleScrollEventL(), you must also call the base class implementation of the function.

Figure 1. Scrollbar

For an implementation example, see below.

void CMyContainerControl::HandleScrollEventL( CEikScrollBar* aScrollBar, TEikScrollEvent aEventType )
    {
    if( !aScrollBar )
        {
        return;
        }

    TInt newPosition = aScrollBar->ThumbPosition();
    
    switch( aEventType )
        {
        case EEikScrollUp: // Moving up one step
            {
            MoveFocusUpL();
            break;
            }
        case EEikScrollDown: // Moving down one step
            {
            MoveFocusDownL();
            break;
            }
        case EEikScrollThumbDragVert: // Drag started
        case EEikScrollThumbReleaseVert: // Drag released
            {
            if( newPosition < iFocusedIndex )
                {
                MoveFocusUpL();
                }
            else if( newPosition > iFocusedIndex )
                {
                MoveFocusDownL();
                }
            break;
            }
        case EEikScrollPageUp:
            {
            while( newPosition < iFocusedIndex )
                {
                MoveFocusUpL();
                }
            break;
            }
        case EEikScrollPageDown:
            {
            while( newPosition > iFocusedIndex )
                {
                MoveFocusDownL();
                }
            break;
            }
        default:
            {
            break;
            }
        }
    DrawNow();
    }