Symbian3/PDK/Source/GUID-07DD47FD-86B7-4AFD-BEDB-DF6EA12DFC6C.dita
changeset 1 25a17d01db0c
child 3 46218c8b8afa
equal deleted inserted replaced
0:89d6a7a84779 1:25a17d01db0c
       
     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-07DD47FD-86B7-4AFD-BEDB-DF6EA12DFC6C" xml:lang="en"><title>Using
       
    13 button states</title><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p>The states can also be added to button dynamically. To add button states
       
    15 as required, use the method <xref href="jar:GUID-759FBC7F-5384-4487-8457-A8D4B76F6AA6.jar!/html/classCAknButton.html#656fd550a246e6c2b77bf96939dad6d2" format="application/java-archive"><codeph>AddStateL()</codeph></xref> in the class <xref href="jar:GUID-759FBC7F-5384-4487-8457-A8D4B76F6AA6.jar!/html/classCAknButton.html" format="application/java-archive"><codeph>CAknButton</codeph></xref>. </p>
       
    16 <codeblock xml:space="preserve">// Add state with button text and help text 
       
    17 HBufC* stateText = StringLoader::LoadLC( R_MYAPP_BUTTON_TEXT );    
       
    18 HBufC* stateHelpText = StringLoader::LoadLC( R_MYAPP_BUTTON_TEXT ); 
       
    19 button-&gt;AddStateL( 0, 0, 0, 0, *stateText, *stateHelpText, 0 ); 
       
    20 CleanupStack::PopAndDestroy( 2 ); // stateText, stateHelpText 
       
    21 
       
    22 // Add state with icon 
       
    23
       
    24 #include &lt;avkon.mbg&gt; 
       
    25
       
    26 TPtrC8 pathPtr( ( TUint8* ) AVKON_BITMAP_FILE ); 
       
    27 HBufC *filePath = HBufC::NewLC( pathPtr.Length() ); 
       
    28 filePath-&gt;Des().Copy( pathPtr ); 
       
    29 button-&gt;AddStateL( *filePath, 
       
    30                    EMbmAvkonQgn_indi_volume_arrow_down, 
       
    31                    EMbmAvkonQgn_indi_volume_arrow_down_mask, 
       
    32                    0, 0, 
       
    33                    EMbmAvkonQgn_indi_volume_arrow_down, 
       
    34                    EMbmAvkonQgn_indi_volume_arrow_down_mask, 
       
    35                    0, 0, 
       
    36                    KNullDesC, KNullDesC, 0, 
       
    37                    KAknsIIDQgnIndiVolumeArrowDown, 
       
    38                    KAknsIIDQgnIndiVolumeArrowDownInactive, 
       
    39                    KAknsIIDQgnIndiVolumeArrowDownSelected, 
       
    40                    KAknsIIDDefault ); 
       
    41 CleanupStack::PopAndDestroy( filePath ); 
       
    42 </codeblock>
       
    43 <p>The following sample code defines three different kinds of buttons with
       
    44 button states in a resource file.</p>
       
    45 <codeblock xml:space="preserve">#include &lt;avkon.mbg&gt; 
       
    46 #include &lt;aknsconstants.hrh&gt; 
       
    47 
       
    48
       
    49 
       
    50 RESOURCE AVKON_BUTTON r_myapp_command_button 
       
    51     { 
       
    52     flags  = 0; 
       
    53     states = 
       
    54         { 
       
    55         AVKON_BUTTON_STATE 
       
    56             { 
       
    57             bmpfile = AVKON_BITMAP_FILE; 
       
    58             bmpid = EMbmAvkonQgn_indi_volume_arrow_down; 
       
    59             bmpmask = EMbmAvkonQgn_indi_volume_arrow_down_mask; 
       
    60             press_bmpid = EMbmAvkonQgn_indi_volume_arrow_down; 
       
    61             press_bmpmask = EMbmAvkonQgn_indi_volume_arrow_down_mask; 
       
    62             helptxt = "Volume down"; 
       
    63             // Skinning support for state icon 
       
    64             extension = r_myapp_command_button_extension; 
       
    65             } 
       
    66         }; 
       
    67     } 
       
    68 
       
    69 RESOURCE AVKON_BUTTON_STATE_EXTENSION r_myapp_command_button_extension 
       
    70     { 
       
    71     bmbSkinIdMajor = EAknsMajorGeneric; 
       
    72     bmbSkinIdMinor = EAknsMinorGenericQgnIndiVolumeArrowDown; 
       
    73     } 
       
    74 
       
    75 RESOURCE AVKON_BUTTON r_myapp_onoff_button 
       
    76     { 
       
    77     flags  = 0; 
       
    78     states = 
       
    79         { 
       
    80         AVKON_BUTTON_STATE 
       
    81             { 
       
    82             txt = "Off"; 
       
    83             helptxt = "Turn on"; 
       
    84             }, 
       
    85             AVKON_BUTTON_STATE 
       
    86             { 
       
    87             flags = KAknButtonStateHasLatchedFrame; 
       
    88             txt = "On"; 
       
    89             helptxt = "Turn off"; 
       
    90             } 
       
    91         }; 
       
    92     } 
       
    93 
       
    94 RESOURCE AVKON_BUTTON r_myapp_mode_button 
       
    95     { 
       
    96     flags  = 0; 
       
    97     states = 
       
    98         { 
       
    99         AVKON_BUTTON_STATE 
       
   100             { 
       
   101             txt = "Mode 1"; 
       
   102             helptxt = "Switch to 2"; 
       
   103             }, 
       
   104         AVKON_BUTTON_STATE 
       
   105             { 
       
   106             txt = "Mode 2"; 
       
   107             helptxt = "Switch to 3"; 
       
   108             }, 
       
   109         AVKON_BUTTON_STATE 
       
   110             { 
       
   111             txt = "Mode 3"; 
       
   112             helptxt = "Switch to 1"; 
       
   113             } 
       
   114         }; 
       
   115     } 
       
   116 
       
   117 </codeblock>
       
   118 <p>To set current state for the button, use the method <xref href="jar:GUID-759FBC7F-5384-4487-8457-A8D4B76F6AA6.jar!/html/classCAknButton.html#19d9e952ed9002fcb6fc3f15dfe5583a" format="application/java-archive"><codeph>SetCurrentState()</codeph></xref> in the class <codeph>CAknButton</codeph>.
       
   119 To get a pointer to the current state of the button, use <codeph>State()</codeph> method.
       
   120 The index of the current state can be acquired with the method <codeph>CAknButton::StateIndex()</codeph>.</p>
       
   121 <codeblock xml:space="preserve">if ( button-&gt;StateIndex() == 0 ) 
       
   122 { 
       
   123       button-&gt;SetCurrentState( 1, ETrue ); 
       
   124 }</codeblock>
       
   125 </conbody></concept>