|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : aknexpopfieldtextvaluedialog.cpp 00004 * Part of : Popup-field example 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2004 - 2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 // INCLUDE FILES 00017 #include <eikenv.h> 00018 #include <avkon.hrh> 00019 #include <aknpopupfield.h> 00020 #include <aknpopupfieldtext.h> 00021 #include <aknqueryvaluetext.h> 00022 #include <AknExPopField.rsg> 00023 00024 #include "AknExPopField.hrh" 00025 #include "AknExPopFieldTextValueDialog.h" 00026 00027 00028 // ================= MEMBER FUNCTIONS ========================================= 00029 00030 00031 // ---------------------------------------------------------------------------- 00032 // CAknExPopFieldTextValueDialog::CAknExPopFieldTextValueDialog() 00033 // C++ default constructor can NOT contain any code, that might leave. 00034 // ---------------------------------------------------------------------------- 00035 // 00036 CAknExPopFieldTextValueDialog::CAknExPopFieldTextValueDialog(): 00037 iTextArray( NULL ), 00038 iValueTextArray( NULL ) 00039 { 00040 00041 TInt index( KAknExPopFieldIndexInitialize ); 00042 for ( index = KAknExPopFieldIndexInitialize; 00043 index < KAknExPopFieldMaxTextValueField; index++ ) 00044 { 00045 iTextValues[ index ] = NULL; 00046 } 00047 } 00048 00049 00050 // ---------------------------------------------------------------------------- 00051 // CAknExPopFieldTextValueDialog* CAknExPopFieldTextValueDialog::NewLC() 00052 // Two-phased constructor. 00053 // ---------------------------------------------------------------------------- 00054 // 00055 CAknExPopFieldTextValueDialog* CAknExPopFieldTextValueDialog::NewLC() 00056 { 00057 CAknExPopFieldTextValueDialog* self = 00058 new ( ELeave ) CAknExPopFieldTextValueDialog; 00059 CleanupStack::PushL( self ); 00060 self->ConstructL(); 00061 return self; 00062 } 00063 00064 // ---------------------------------------------------------------------------- 00065 // CAknExPopFieldTextValueDialog::~CAknExPopFieldTextValueDialog() 00066 // Destructor. 00067 // ---------------------------------------------------------------------------- 00068 // 00069 CAknExPopFieldTextValueDialog::~CAknExPopFieldTextValueDialog() 00070 { 00071 DiscardTextArray(); 00072 } 00073 00074 00075 // ---------------------------------------------------------------------------- 00076 // CAknExPopFieldTextValueDialog::DiscardTextArray() 00077 // Discard text array in popup field object. 00078 // ---------------------------------------------------------------------------- 00079 // 00080 void CAknExPopFieldTextValueDialog::DiscardTextArray() 00081 { 00082 TInt index( KAknExPopFieldIndexInitialize ); 00083 for ( index = KAknExPopFieldIndexInitialize; 00084 index < KAknExPopFieldMaxTextValueField; index++ ) 00085 { 00086 if ( iTextValues[ index ] ) 00087 { 00088 delete iTextValues[ index ]; 00089 iTextValues[ index ] = NULL; 00090 } 00091 } 00092 00093 if ( iValueTextArray ) 00094 { 00095 delete iValueTextArray; 00096 iValueTextArray = NULL; 00097 } 00098 00099 if ( iTextArray ) 00100 { 00101 delete iTextArray; 00102 iTextArray = NULL; 00103 } 00104 } 00105 00106 // ---------------------------------------------------------------------------- 00107 // CAknExPopFieldTextValueDialog::OkToExitL() 00108 // Implemented to test PopupFieldText API's. 00109 // ---------------------------------------------------------------------------- 00110 // 00111 TBool CAknExPopFieldTextValueDialog::OkToExitL( TInt aButtonId ) 00112 { 00113 switch ( aButtonId ) 00114 { 00115 case EAknSoftkeyBack: 00116 { 00117 CAknPopupFieldText* popupFieldText[KAknExPopupFieldTextMaxValues]; 00118 TBuf<256> textbuf; 00119 for ( TInt i = 0; i < KAknExPopupFieldTextMaxValues; i++ ) 00120 { 00121 // Get the proper control 00122 popupFieldText[i] = ( CAknPopupFieldText* ) 00123 ControlOrNull( EAknExPopFieldDlgCtrlIdText01+i ); 00124 00125 if ( popupFieldText[ i ] ) 00126 { 00127 // Perform the calls on the API 00128 // provided by CAknPopupFieldText 00129 HBufC* text = popupFieldText[ i ]->CurrentValueTextLC(); 00130 TInt value = popupFieldText[ i ]->CurrentValueIndex(); 00131 popupFieldText[ i ]->SetCurrentValueIndex( i ); 00132 popupFieldText[ i ]->SetAutoAppend( ETrue ); 00133 popupFieldText[ i ]->SetAllowsUserDefinedEntry( ETrue ); 00134 const MDesCArray* array = popupFieldText[ i ]->MdcArray(); 00135 TInt mdcaCount = array->MdcaCount(); 00136 00137 // Print results to Debug 00138 _LIT( KPopupFieldText,"PopupFieldText Control Vals -> Number %d, Value %d, Text : " ); 00139 textbuf.Format( KPopupFieldText,i,value ); 00140 textbuf.Append( *text ); 00141 RDebug::Print( textbuf ); 00142 00143 _LIT( KMdcaCountText,"... MdcaCount = %d." ); 00144 textbuf.Format( KMdcaCountText, mdcaCount ); 00145 RDebug::Print( textbuf ); 00146 00147 // Clean up text 00148 CleanupStack::PopAndDestroy(); // text 00149 } 00150 } 00151 break; 00152 } 00153 default: 00154 break; 00155 } 00156 return CAknExPopFieldBaseDialog::OkToExitL( aButtonId ); 00157 } 00158 00159 // ---------------------------------------------------------------------------- 00160 // CAknExPopFieldTextValueDialog::ConfigurePopfieldValueL() 00161 // Configuration values (text) into Popup Fields. 00162 // ---------------------------------------------------------------------------- 00163 // 00164 void CAknExPopFieldTextValueDialog::ConfigurePopfieldValueL() 00165 { 00166 // Discard textarray. 00167 DiscardTextArray(); 00168 00169 // Calculate number of pop-up field. 00170 TInt index( KAknExPopFieldIndexInitialize ); 00171 TInt count( KAknExPopFieldCountInitialize ); 00172 TInt controlId( KAknExPopFieldControlIdInitialize ); 00173 CAknPopupField* popup[ KAknExPopFieldMaxTextValueField ]; 00174 for ( index = KAknExPopFieldIndexInitialize; 00175 index < KAknExPopFieldMaxTextValueField; index++ ) 00176 { 00177 popup[ index ] = NULL; 00178 controlId = EAknExPopFieldDlgCtrlIdPop01 + index; 00179 CCoeControl* control = ControlOrNull( controlId ); 00180 if ( control ) 00181 { 00182 popup[ count ] = static_cast<CAknPopupField*> ( control ); 00183 count++; 00184 } 00185 } 00186 00187 // Create textarray. 00188 iTextArray = iCoeEnv->ReadDesCArrayResourceL( 00189 R_AKNEXPOPFIELD_FIVE_TEXT_ARRAY ); 00190 iValueTextArray = CAknQueryValueTextArray::NewL(); 00191 iValueTextArray->SetArray( *iTextArray ); 00192 00193 // Set the same textarray into all the values, and initial value index. 00194 for ( index = KAknExPopFieldIndexInitialize; index < count; index++ ) 00195 { 00196 iTextValues[ index ] = CAknQueryValueText::NewL(); 00197 iTextValues[ index ]->SetArrayL( iValueTextArray ); 00198 iTextValues[ index ]->SetCurrentValueIndex( 0 ); 00199 iTextValues[ index ]->SetQueryCaption( R_AKNEXPOPFIELD_QUERY_PROMPT ); 00200 // Set values into popup fields. 00201 popup[ index ]->SetQueryValueL( iTextValues[ index ] ); // Moved up 00202 // from below. 00203 } 00204 } 00205 00206 // ---------------------------------------------------------------------------- 00207 // CAknExPopFieldTextValueDialog::SaveFormDataL() 00208 // Save form data. 00209 // ---------------------------------------------------------------------------- 00210 // 00211 TBool CAknExPopFieldTextValueDialog::SaveFormDataL() 00212 { 00213 for ( TInt i = KAknExPopFieldIndexInitialize; 00214 i < KAknExPopFieldMaxTextValueField; i++ ) 00215 { 00216 if ( ControlOrNull( EAknExPopFieldDlgCtrlIdPop01+i ) ) 00217 { 00218 iIndexValue[ i ] = iTextValues[ i ]->CurrentValueIndex(); 00219 } 00220 } 00221 00222 return ETrue; 00223 } 00224 00225 // ---------------------------------------------------------------------------- 00226 // CAknExPopFieldTextValueDialog::DoNotSaveFormDataL() 00227 // Does not save form data. 00228 // ---------------------------------------------------------------------------- 00229 // 00230 void CAknExPopFieldTextValueDialog::DoNotSaveFormDataL() 00231 { 00232 for ( TInt i = KAknExPopFieldIndexInitialize; 00233 i < KAknExPopFieldMaxTextValueField; i++ ) 00234 { 00235 if( ControlOrNull( EAknExPopFieldDlgCtrlIdPop01+i ) ) 00236 { 00237 iTextValues[ i ]->SetCurrentValueIndex( iIndexValue[ i ] ); 00238 } 00239 } 00240 } 00241 00242 // End of File
|
© Nokia 2009 |