|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-58318BAB-2EC4-4C9E-A7CA-580E701EE54F" xml:lang="en"><title>Adding |
|
13 and removing toolbar items</title><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <p> Toolbar items are controls that derive from the <codeph>CCoeControl</codeph> base |
|
15 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 |
|
16 depends on the screen resolution in use. The fixed toolbar always has three |
|
17 buttons. </p> |
|
18 <p>You can define toolbar items either in the resource file or create them |
|
19 dynamically at runtime. </p> |
|
20 <p>If you define the items in resources, use the <codeph>TBAR_CTRL</codeph> structure. |
|
21 Define at least the type, ID, and the control itself in this structure. For |
|
22 the resource definitions, see <xref href="GUID-402C3EE7-8852-49B6-BE62-8588753FAC8F.dita">Constructing |
|
23 the toolbar</xref>.</p> |
|
24 <p>To add the items dynamically, use the toolbar functions as illustrated |
|
25 in the examples below.</p> |
|
26 <p>You can add items to a specific position in toolbar or as the last item |
|
27 in the toolbar. </p> |
|
28 <p>You can also remove toolbar items at runtime.</p> |
|
29 <p>The example below shows how to add a button dynamically as the last toolbar |
|
30 item.</p> |
|
31 <codeblock xml:space="preserve"> |
|
32 void CMyAppView::AddItemAsLastToToolbarL() |
|
33 { |
|
34 CAknToolbar* toolbar = Toolbar(); |
|
35 if ( toolbar ) |
|
36 { |
|
37 CAknButton* newButton = CAknButton::NewL( R_MYAPP_BUTTON ); |
|
38 toolbar->AddItemL( newButton, EAknCtButton, KButtonId, 0 ); |
|
39 } |
|
40 } |
|
41 </codeblock> |
|
42 <p>The example below shows how to add a button dynamically as the first toolbar |
|
43 item.</p> |
|
44 <codeblock xml:space="preserve"> |
|
45 void CMyAppView::AddItemAsFirstToToolbarL() |
|
46 { |
|
47 CAknToolbar* toolbar = Toolbar(); |
|
48 if ( toolbar ) |
|
49 { |
|
50 CAknButton* newButton = CAknButton::NewL( R_MYAPP_BUTTON ); |
|
51 // Last parameter the index at where to add the button |
|
52 toolbar->AddItemL( newButton, EAknCtButton, KButtonId, 0, 0 ); |
|
53 } |
|
54 } |
|
55 </codeblock> |
|
56 <p>The example below shows how to remove a button from the toolbar based on |
|
57 the button ID.</p> |
|
58 <codeblock xml:space="preserve"> |
|
59 void CMyAppView::RemoveItemFromToolbar() |
|
60 { |
|
61 CAknToolbar* toolbar = Toolbar(); |
|
62 if ( toolbar ) |
|
63 { |
|
64 toolbar->RemoveItem( KButtonId ); |
|
65 } |
|
66 } |
|
67 </codeblock> |
|
68 </conbody></concept> |