|
Nokia N97 SDK Example Applications Guide |
00001 /** 00002 * Copyright (c) 2007 Nokia Corporation. 00003 * This material, including documentation and any related 00004 * computer programs, is protected by 00005 * copyright controlled by Nokia Corporation. 00006 */ 00007 00008 00009 00010 // INCLUDE FILES 00011 #include <eikmenup.h> 00012 #include <aknnotewrappers.h> 00013 #include <aknuniteditor.h> 00014 #include <e32math.h> 00015 #include <avkon.hrh> 00016 #include <avkon.rsg> 00017 #include <UEEx.rsg> 00018 00019 #include "ueex.hrh" 00020 #include "ueexform.h" 00021 00022 // CONSTANTS 00023 _LIT ( KCustomUnit, "XYZ" ); 00024 00025 const TInt KMaxFractionalDigits = 8; 00026 00027 // ============================ MEMBER FUNCTIONS =============================== 00028 00029 // ----------------------------------------------------------------------------- 00030 // CUEExForm::ProcessCommandL() 00031 // Handles commands from menu. 00032 // ----------------------------------------------------------------------------- 00033 // 00034 void CUEExForm::ProcessCommandL( TInt aCommandId ) 00035 { 00036 CAknUnitEditor* unitEditor = 00037 static_cast<CAknUnitEditor*>( ControlOrNull( EUEExUnitEditor ) ); 00038 00039 if ( unitEditor ) 00040 { 00041 switch ( aCommandId ) 00042 { 00043 case ECmdSetValue: 00044 DoSetValue( unitEditor ); 00045 break; 00046 case ECmdSetNan: 00047 DoSetNaN( unitEditor ); 00048 break; 00049 case ECmdSetMinMax: 00050 DoSetMinMax( unitEditor ); 00051 break; 00052 case ECmdSetUnit: 00053 DoSetUnit( unitEditor ); 00054 break; 00055 case ECmdSetCustomUnit: 00056 DoSetCustomUnit( unitEditor ); 00057 break; 00058 case ECmdSetMaxFractionalDigits: 00059 DoSetMaxFractionalDigits( unitEditor ); 00060 break; 00061 case ECmdGetValue: 00062 DoGetValue( unitEditor ); 00063 break; 00064 default: 00065 break; 00066 } 00067 } 00068 00069 // Exit form gracefully 00070 if ( aCommandId == EAknCmdExit ) 00071 { 00072 TryExitL( EAknSoftkeyBack ); 00073 } 00074 else 00075 { 00076 CAknForm::ProcessCommandL( aCommandId ); 00077 } 00078 } 00079 00080 // ----------------------------------------------------------------------------- 00081 // CUEExForm::DynInitMenuPaneL() 00082 // Initializes the menu pane when it is opened. 00083 // ----------------------------------------------------------------------------- 00084 // 00085 void CUEExForm::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane *aMenuPane ) 00086 { 00087 CAknForm::DynInitMenuPaneL( aResourceId, aMenuPane ); 00088 00089 if ( aResourceId == R_AVKON_FORM_MENUPANE ) 00090 { 00091 // Disable the Label, Add, Delete, and Save Field 00092 aMenuPane->SetItemDimmed( EAknFormCmdLabel, ETrue ); 00093 aMenuPane->SetItemDimmed( EAknFormCmdAdd, ETrue ); 00094 aMenuPane->SetItemDimmed( EAknFormCmdDelete, ETrue ); 00095 aMenuPane->SetItemDimmed( EAknFormCmdSave, ETrue ); 00096 } 00097 } 00098 00099 // ----------------------------------------------------------------------------- 00100 // CUEExForm::QuerySaveChangesL() 00101 // ----------------------------------------------------------------------------- 00102 // 00103 TBool CUEExForm::QuerySaveChangesL() 00104 { 00105 return EFalse; 00106 } 00107 00108 00109 // ----------------------------------------------------------------------------- 00110 // CUEExForm::DoSetValue() 00111 // ----------------------------------------------------------------------------- 00112 // 00113 void CUEExForm::DoSetValue( CAknUnitEditor* aUnitEditor ) 00114 { 00115 TInt number( 0 ); 00116 CAknNumberQueryDialog* dlg = CAknNumberQueryDialog::NewL( number ); 00117 dlg->PrepareLC( R_AVKON_DIALOG_QUERY_VALUE_NUMBER ); 00118 dlg->SetMinimumAndMaximum( KMinTInt, KMaxTInt ); 00119 if ( dlg->RunLD() ) 00120 { 00121 aUnitEditor->SetValue( number ); 00122 } 00123 } 00124 00125 // ----------------------------------------------------------------------------- 00126 // CUEExForm::DoSetNaN() 00127 // ----------------------------------------------------------------------------- 00128 // 00129 void CUEExForm::DoSetNaN( CAknUnitEditor* aUnitEditor ) 00130 { 00131 TRealX nan; 00132 nan.SetNaN(); 00133 aUnitEditor->SetValue( nan ); 00134 } 00135 00136 // ----------------------------------------------------------------------------- 00137 // CUEExForm::DoSetMinMax() 00138 // ----------------------------------------------------------------------------- 00139 // 00140 void CUEExForm::DoSetMinMax( CAknUnitEditor* aUnitEditor ) 00141 { 00142 TInt newMin( 0 ); 00143 TInt newMax( 0 ); 00144 TInt ret; 00145 00146 CAknNumberQueryDialog* dlg = CAknNumberQueryDialog::NewL( newMin ); 00147 dlg->PrepareLC( R_NEWMINQUERY ); 00148 dlg->SetMinimumAndMaximum( KMinTInt, KMaxTInt ); 00149 ret = dlg->RunLD(); 00150 00151 if ( ret == EAknSoftkeyOk ) 00152 { 00153 dlg = CAknNumberQueryDialog::NewL( newMax ); 00154 dlg->PrepareLC( R_NEWMAXQUERY ); 00155 dlg->SetMinimumAndMaximum( KMinTInt, KMaxTInt ); 00156 ret = dlg->RunLD(); 00157 00158 if ( ret == EAknSoftkeyOk ) 00159 { 00160 aUnitEditor->SetMinimumAndMaximum( newMin, newMax ); 00161 } 00162 } 00163 } 00164 00165 // ----------------------------------------------------------------------------- 00166 // CUEExForm::DoSetUnit() 00167 // ----------------------------------------------------------------------------- 00168 // 00169 void CUEExForm::DoSetUnit( CAknUnitEditor* aUnitEditor ) 00170 { 00171 TRAP_IGNORE( aUnitEditor->SetUnitL( EAknUnitEditorMetricSpeed ) ); 00172 } 00173 00174 // ----------------------------------------------------------------------------- 00175 // CUEExForm::DoSetCustomUnit() 00176 // ----------------------------------------------------------------------------- 00177 // 00178 void CUEExForm::DoSetCustomUnit( CAknUnitEditor* aUnitEditor ) 00179 { 00180 TRAP_IGNORE( aUnitEditor->SetUnitL( KCustomUnit ) ); 00181 } 00182 00183 // ----------------------------------------------------------------------------- 00184 // CUEExForm::DoSetMaxFractionalDigits() 00185 // ----------------------------------------------------------------------------- 00186 // 00187 void CUEExForm::DoSetMaxFractionalDigits( CAknUnitEditor* aUnitEditor ) 00188 { 00189 TInt number( 0 ); 00190 CAknNumberQueryDialog* dlg = CAknNumberQueryDialog::NewL( number ); 00191 dlg->PrepareLC( R_AVKON_DIALOG_QUERY_VALUE_NUMBER ); 00192 dlg->SetMinimumAndMaximum( 0, KMaxFractionalDigits ); 00193 if ( dlg->RunLD() ) 00194 { 00195 aUnitEditor->SetMaxFractionalDigits( number ); 00196 } 00197 } 00198 00199 // ----------------------------------------------------------------------------- 00200 // CUEExForm::DoGetValue() 00201 // ----------------------------------------------------------------------------- 00202 // 00203 void CUEExForm::DoGetValue( CAknUnitEditor* aUnitEditor ) 00204 { 00205 TReal realValue = aUnitEditor->Value(); 00206 TBuf<32> buf; 00207 TRealFormat format( 10, aUnitEditor->MaxFractionalDigits() ); 00208 buf.Num( realValue, format ); 00209 CAknInformationNote* note = new ( ELeave ) CAknInformationNote; 00210 note->ExecuteLD( buf ); 00211 }
|
© Nokia 2009 |