00001
00002
00003
00004
00005 #include "DescriptorExAppUi.h"
00006 #include "DescriptorExContainer.h"
00007 #include <DescriptorEx.rsg>
00008 #include "descriptorex.hrh"
00009 #include <aknutils.h>
00010
00011 #include <avkon.hrh>
00012 #include "DescriptorExamples.h"
00013
00014
00015
00016
00017 typedef void (CDescriptorExamples::*TExampleMethodPtr)();
00018
00019
00020
00021
00022 static const TExampleMethodPtr ExampleMethods[] =
00023 {
00024 &CDescriptorExamples::ToStack,
00025 &CDescriptorExamples::ToHeapL,
00026 &CDescriptorExamples::Literals,
00027
00028 &CDescriptorExamples::NonModifyingMethods,
00029 &CDescriptorExamples::ModifyingMethodsL,
00030 &CDescriptorExamples::CharacterConversionsL,
00031 &CDescriptorExamples::LexicalAnalysis,
00032
00033 &CDescriptorExamples::CircularBuffersL,
00034 &CDescriptorExamples::FlatDynamicBuffersL,
00035 &CDescriptorExamples::SegmentedDynamicBuffersL,
00036 &CDescriptorExamples::PackageBuffers,
00037 &CDescriptorExamples::RBufDemonstrations
00038 };
00039 static const TInt KNumberOfExampleMethods = sizeof(ExampleMethods) /
00040 sizeof(TExampleMethodPtr);
00041
00042
00043
00044
00045
00046 LOCAL_C void ExecuteExampleMethodL(TInt aNumber, CDescriptorExamples &aExample)
00047 {
00048 if( aNumber >= 0 && aNumber < KNumberOfExampleMethods )
00049 {
00050 TExampleMethodPtr mPtr = ExampleMethods[aNumber];
00051 (aExample.*mPtr)();
00052 }
00053 }
00054
00055
00056
00057
00058 void CDescriptorExAppUi::ConstructL()
00059 {
00060 BaseConstructL(EAknEnableSkin);
00061
00062 iAppContainer = new (ELeave) CDescriptorExContainer;
00063 iAppContainer->SetMopParent(this);
00064 iAppContainer->ConstructL( ClientRect() );
00065 AddToStackL( iAppContainer );
00066 iBuffer = HBufC::NewL(4096);
00067 iExamples = new (ELeave) CDescriptorExamples( this );
00068 }
00069
00070
00071
00072
00073 CDescriptorExAppUi::~CDescriptorExAppUi()
00074 {
00075 delete iExamples;
00076 iExamples = NULL;
00077 delete iBuffer;
00078 iBuffer = NULL;
00079 if (iAppContainer)
00080 {
00081 RemoveFromStack( iAppContainer );
00082 delete iAppContainer;
00083 iAppContainer = NULL;
00084 }
00085 }
00086
00087
00088
00089
00090 void CDescriptorExAppUi::RunAllL()
00091 {
00092 _LIT( KFileName, "c:\\Data\\DescriptorEx.log.txt" );
00093
00094 CFileForwarder *fileWriter = new (ELeave) CFileForwarder();
00095 CleanupStack::PushL( fileWriter );
00096 fileWriter->ConstructL(KFileName);
00097
00098 CDescriptorExamples *example = new (ELeave) CDescriptorExamples(fileWriter);
00099 CleanupStack::PushL( example );
00100
00101 for( TInt i=0; i < KNumberOfExampleMethods; i++ )
00102 {
00103 ExecuteExampleMethodL(i, *example);
00104 }
00105 GetViewBuffer().AppendFormat( _L(
00106 "Results of example methods written to file\n\"%S\"\n"), &KFileName );
00107 UpdateView();
00108
00109 CleanupStack::PopAndDestroy(2);
00110 }
00111
00112
00113
00114
00115
00116 void CDescriptorExAppUi::HandleCommandL(TInt aCommand)
00117 {
00118 if( aCommand - TDescriptorExCommandFirstID < KNumberOfExampleMethods )
00119 {
00120
00121 iBuffer->Des().SetLength(0);
00122
00123
00124
00125
00126
00127 ExecuteExampleMethodL( aCommand - TDescriptorExCommandFirstID,
00128 *iExamples );
00129 }
00130
00131 switch ( aCommand )
00132 {
00133 case EAknSoftkeyExit:
00134 case EEikCmdExit:
00135 {
00136 Exit();
00137 break;
00138 }
00139 case ECmd_RunAll:
00140 {
00141
00142
00143
00144
00145 RunAllL();
00146 break;
00147 }
00148 default:
00149 {
00150 break;
00151 }
00152 };
00153 }
00154
00155
00156
00157
00158 TKeyResponse CDescriptorExAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,
00159 TEventCode aType)
00160 {
00161
00162 return iAppContainer->OfferKeyEventL( aKeyEvent, aType );
00163 }
00164
00165
00166
00167
00168
00169 TPtr CDescriptorExAppUi::GetViewBuffer()
00170 {
00171 return iBuffer->Des();
00172 }
00173
00174
00175
00176
00177
00178
00179 void CDescriptorExAppUi::UpdateView()
00180 {
00181
00182
00183 #ifdef _UNICODE
00184 TText16* ptr=(TText16*)iBuffer->Ptr();
00185 TText16* endPtr=ptr + iBuffer->Length();
00186 for(;ptr < endPtr; ptr++ )
00187 {
00188 if( *ptr == '\n' )
00189 {
00190 *ptr = 0x2029;
00191 }
00192 }
00193 #endif
00194
00195
00196 TRAPD(ignored, iAppContainer->SetTextL(*iBuffer));
00197 }
00198
00199 void CDescriptorExAppUi::HandleResourceChangeL(TInt aType)
00200 {
00201 CAknAppUi::HandleResourceChangeL(aType);
00202
00203 if ( aType == KEikDynamicLayoutVariantSwitch )
00204 {
00205 TRect rect;
00206 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00207 iAppContainer->SetRect(rect);
00208 }
00209 }