Adding and removing toolbar extension items

The toolbar extension can basically hold the same items as the toolbar itself. However, the floating toolbar extension can only have focusable buttons. A fixed toolbar extension does not naturally have focus since its parent toolbar is not focusing.

The toolbar extension can have a variable number of items. They are located from the upper left (right in mirrored layout) corner. If all items cannot fit into the extension, items from the end will be dropped.

You can add items to the toolbar extension in the similar way as to a toolbar, either by defining TBAR_CTRL resource structures in the resource file or adding the items dynamically by using toolbar extension functions.

You can also remove items from the extension.

The example below shows how to add an item to the toolbar extension as the first item.

void CMyAppView::AddItemAsFirstToToolbarExtensionL()
    {
    CAknToolbar* toolbar = Toolbar();
    if ( toolbar )
        {
        CAknToolbarExtension* toolbarExtension = toolbar->ToolbarExtension();
        if ( toolbarExtension )
            {
            CAknButton* newButton = CAknButton::NewL( R_MYAPP_EXTENSION_BUTTON );
            // Last parameter tells the index at where to add new item
            toolbarExtension->AddItemL( 
                newButton, EAknCtButton, KExtensionButtonId, 0, 0 );
            }
        }
    }

The example below shows how to remove an item from the toolbar extension.

void CMyAppView::RemoveItemFromToolbarExtensionL()
    {
    CAknToolbar* toolbar = Toolbar();
    if ( toolbar )
        {
        CAknToolbarExtension* toolbarExtension = toolbar->ToolbarExtension();
        if ( toolbarExtension )
            {
            toolbarExtension->RemoveItemL( KExtensionButtonId );
            }
        }
    }