Symbian3/SDK/Source/GUID-58318BAB-2EC4-4C9E-A7CA-580E701EE54F.dita
author Graeme Price <GRAEME.PRICE@NOKIA.COM>
Fri, 15 Oct 2010 14:32:18 +0100
changeset 15 307f4279f433
parent 0 89d6a7a84779
permissions -rw-r--r--
Initial contribution of the Adaptation Documentation.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-58318BAB-2EC4-4C9E-A7CA-580E701EE54F" xml:lang="en"><title>Adding
and removing toolbar items</title><prolog><metadata><keywords/></metadata></prolog><conbody>
<p> Toolbar items are controls that derive from the <codeph>CCoeControl</codeph> base
class. The floating toolbar can have only buttons (<xref href="jar:GUID-759FBC7F-5384-4487-8457-A8D4B76F6AA6.jar!/html/classCAknButton.html" format="application/java-archive"><codeph>CAknButton</codeph></xref>) 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. </p>
<p>You can define toolbar items either in the resource file or create them
dynamically at runtime. </p>
<p>If you define the items in resources, use the <codeph>TBAR_CTRL</codeph> structure.
Define at least the type, ID, and the control itself in this structure. For
the resource definitions, see <xref href="GUID-402C3EE7-8852-49B6-BE62-8588753FAC8F.dita">Constructing
the toolbar</xref>.</p>
<p>To add the items dynamically, use the toolbar functions as illustrated
in the examples below.</p>
<p>You can add items to a specific position in toolbar or as the last item
in the toolbar. </p>
<p>You can also remove toolbar items at runtime.</p>
<p>The example below shows how to add a button dynamically as the last toolbar
item.</p>
<codeblock xml:space="preserve">
void CMyAppView::AddItemAsLastToToolbarL()
    {
    CAknToolbar* toolbar = Toolbar();
    if ( toolbar )
        {
        CAknButton* newButton = CAknButton::NewL( R_MYAPP_BUTTON );
        toolbar-&gt;AddItemL( newButton, EAknCtButton, KButtonId, 0 );
        }
    }
</codeblock>
<p>The example below shows how to add a button dynamically as the first toolbar
item.</p>
<codeblock xml:space="preserve">
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-&gt;AddItemL( newButton, EAknCtButton, KButtonId, 0, 0 );
        }
    }
</codeblock>
<p>The example below shows how to remove a button from the toolbar based on
the button ID.</p>
<codeblock xml:space="preserve">
void CMyAppView::RemoveItemFromToolbar()
    {
    CAknToolbar* toolbar = Toolbar();
    if ( toolbar )
        {
        toolbar-&gt;RemoveItem( KButtonId );
        }
    }
</codeblock>
</conbody></concept>