|
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-CDBBD44F-C5F6-4D51-B4BA-23DA9BB58D69" xml:lang="en"><title>Creating |
|
13 generic button</title><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <p>Create the <xref href="jar:GUID-759FBC7F-5384-4487-8457-A8D4B76F6AA6.jar!/html/classCAknButton.html" format="application/java-archive"><codeph>CAknButton</codeph></xref> object |
|
15 either dynamically from program code or from a resource structure. The constructed |
|
16 button can then be used as a component control of a compound control.</p> |
|
17 <p>Use the resource structures <codeph>AVKON_BUTTON</codeph>, <codeph>AVKON_BUTTON_STATE</codeph>, |
|
18 and <codeph>AVKON_BUTTON_STATE_EXTENSION</codeph> for the button object (defined |
|
19 in the file <codeph>eikon.rh</codeph>). The following example shows how to |
|
20 construct a button with the help of a button resource. The button is placed |
|
21 in a compound control (container) and it occupies the whole rectangle of the |
|
22 container. The container is set as the observer of the button.</p> |
|
23 <p><b>Example: Button resource</b></p> |
|
24 <codeblock xml:space="preserve">RESOURCE AVKON_BUTTON r_myapp_button |
|
25 { |
|
26 flags = KAknButtonTextLeft; |
|
27 states = |
|
28 { |
|
29 AVKON_BUTTON_STATE |
|
30 { |
|
31 txt = “Text”; |
|
32 helptxt = “Help text”; |
|
33 } |
|
34 }; |
|
35 } |
|
36 </codeblock> |
|
37 <p><b>Example: Constructing button from resource</b></p> |
|
38 <codeblock xml:space="preserve">void CMyButtonContainer::CreateButtonL() |
|
39 { |
|
40 CAknButton* iAknButton = CAknButton::NewL(); |
|
41 iAknButton->ConstructFromResourceL(R_MYAPP_BUTTON); |
|
42 iAknButton->SetContainerWindowL(*this); |
|
43 iAknButton->SetRect(Rect()); |
|
44 iAknButton->SetObserver(this); |
|
45 iAknButton->MakeVisible(ETrue); |
|
46 iAknButton->ActivateL(); |
|
47 } |
|
48 </codeblock> |
|
49 <p><b>Example: Constructing button from program code</b></p> |
|
50 <codeblock xml:space="preserve">void CMyButtonContainer::CreateButtonL() |
|
51 { |
|
52 HBufC* buttonText = StringLoader::LoadLC( R_MYAPP_TEXT ); |
|
53 HBufC* helpText = |
|
54 StringLoader::LoadLC( R_MYAPP_HELPTEXT ); |
|
55 CAknButton* iAknButton = CAknButton::NewL( |
|
56 0, 0, 0, 0, |
|
57 *buttonText, *helpText, KAknButtonTextLeft, 0); |
|
58 CleanupStack::PopAndDestroy( 2 ); // helpText, buttonText |
|
59 iAknButton->SetContainerWindowL(*this); |
|
60 iAknButton->SetRect(Rect()); |
|
61 iAknButton->SetObserver(this); |
|
62 iAknButton->MakeVisible(ETrue); |
|
63 iAknButton->ActivateL(); |
|
64 } |
|
65 </codeblock> |
|
66 </conbody></concept> |