diff -r 000000000000 -r 89d6a7a84779 Symbian3/SDK/Source/GUID-58318BAB-2EC4-4C9E-A7CA-580E701EE54F.dita --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/SDK/Source/GUID-58318BAB-2EC4-4C9E-A7CA-580E701EE54F.dita Thu Jan 21 18:18:20 2010 +0000 @@ -0,0 +1,68 @@ + + + + + +Adding +and removing toolbar items +

Toolbar items are controls that derive from the CCoeControl base +class. The floating toolbar can have only buttons (CAknButton) if it is focusing. The number of buttons displayed in floating toolbar +depends on the screen resolution in use. The fixed toolbar always has three +buttons.

+

You can define toolbar items either in the resource file or create them +dynamically at runtime.

+

If you define the items in resources, use the TBAR_CTRL structure. +Define at least the type, ID, and the control itself in this structure. For +the resource definitions, see Constructing +the toolbar.

+

To add the items dynamically, use the toolbar functions as illustrated +in the examples below.

+

You can add items to a specific position in toolbar or as the last item +in the toolbar.

+

You can also remove toolbar items at runtime.

+

The example below shows how to add a button dynamically as the last toolbar +item.

+ +void CMyAppView::AddItemAsLastToToolbarL() + { + CAknToolbar* toolbar = Toolbar(); + if ( toolbar ) + { + CAknButton* newButton = CAknButton::NewL( R_MYAPP_BUTTON ); + toolbar->AddItemL( newButton, EAknCtButton, KButtonId, 0 ); + } + } + +

The example below shows how to add a button dynamically as the first toolbar +item.

+ +void CMyAppView::AddItemAsFirstToToolbarL() + { + CAknToolbar* toolbar = Toolbar(); + if ( toolbar ) + { + CAknButton* newButton = CAknButton::NewL( R_MYAPP_BUTTON ); + // Last parameter the index at where to add the button + toolbar->AddItemL( newButton, EAknCtButton, KButtonId, 0, 0 ); + } + } + +

The example below shows how to remove a button from the toolbar based on +the button ID.

+ +void CMyAppView::RemoveItemFromToolbar() + { + CAknToolbar* toolbar = Toolbar(); + if ( toolbar ) + { + toolbar->RemoveItem( KButtonId ); + } + } + +
\ No newline at end of file