examples/ForumNokia/Localisation/src/localizationappui.cpp

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 
00006 // INCLUDE FILES
00007 #include <avkon.hrh>
00008 #include <eikapp.h>
00009 #include <aknnotewrappers.h>
00010 #include <stringloader.h>
00011 #include <Localization.rsg>
00012 #include <f32file.h>
00013 #include <s32file.h>
00014 
00015 #include "Localization.pan"
00016 #include "LocalizationAppUi.h"
00017 #include "LocalizationAppView.h"
00018 #include "Localization.hrh"
00019 
00020 // ============================ MEMBER FUNCTIONS ===============================
00021 
00022 
00023 // -----------------------------------------------------------------------------
00024 // CLocalizationAppUi::ConstructL()
00025 // Symbian 2nd phase constructor can leave.
00026 // -----------------------------------------------------------------------------
00027 //
00028 void CLocalizationAppUi::ConstructL()
00029     {
00030     // Initialise app UI with standard value.
00031     BaseConstructL(EAknEnableSkin);
00032     // Create view object
00033     iAppView = CLocalizationAppView::NewL( ClientRect() );
00034     }
00035 // -----------------------------------------------------------------------------
00036 // CLocalizationAppUi::CLocalizationAppUi()
00037 // C++ default constructor can NOT contain any code, that might leave.
00038 // -----------------------------------------------------------------------------
00039 //
00040 CLocalizationAppUi::CLocalizationAppUi()
00041     {
00042     // No implementation required
00043     }
00044 
00045 // -----------------------------------------------------------------------------
00046 // CLocalizationAppUi::~CLocalizationAppUi()
00047 // Destructor.
00048 // -----------------------------------------------------------------------------
00049 //
00050 CLocalizationAppUi::~CLocalizationAppUi()
00051     {
00052     if ( iAppView )
00053         {
00054         delete iAppView;
00055         iAppView = NULL;
00056         }
00057 
00058     }
00059 
00060 // -----------------------------------------------------------------------------
00061 // CLocalizationAppUi::HandleCommandL()
00062 // Takes care of command handling.
00063 // -----------------------------------------------------------------------------
00064 //
00065 void CLocalizationAppUi::HandleCommandL( TInt aCommand )
00066     {
00067     switch( aCommand )
00068         {
00069         case EEikCmdExit:
00070         case EAknSoftkeyExit:
00071             Exit();
00072             break;
00073 
00074         // Number
00075         case ELocalizationCommandNumber:
00076             {
00077                 // buffer for localized text
00078                 TBuf<50> myBuf;
00079                 
00080                 // Amount to show
00081                 TReal myAmount = 1234.567;
00082                 
00083                 // Real number formatter, initialized with system's current locale settings
00084                 TRealFormat myFormat;
00085 
00086                 // Format real with current locales decimal separator setting
00087                 myBuf.AppendNum(myAmount, myFormat);
00088                 
00089                 // Show formatted text
00090                 CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
00091                 informationNote->ExecuteLD( myBuf );
00092             }
00093             break;
00094         
00095         // Currency
00096         case ELocalizationCommandCurrency:
00097             {
00098                 // locale is initialized with system's current locale settings
00099                 TLocale myLocale;
00100                 
00101                 // buffer for localized text
00102                 TBuf<50> myBuf;
00103 
00104                 // amount is integer, but it is treated as last two digits
00105                 // were decimal digits e.g. 1249 = 12.49, 2 = 0.02 ...
00106                 TInt myAmount = 123456789;
00107                 
00108                 // Format currency according to current locale settings
00109                 myLocale.FormatCurrency(myBuf, myAmount);
00110 
00111                 // Show formatted text              
00112                 CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
00113                 informationNote->ExecuteLD( myBuf );
00114             }
00115             break;
00116             
00117         // Date
00118         case ELocalizationCommandDate:
00119             {
00120                 // buffer for localized text
00121                 TBuf<50> myBuf;
00122                 
00123                 // Object for datetime data
00124                 TTime myDate;
00125                 
00126                 // Set current datetime to object
00127                 myDate.HomeTime();
00128                 
00129                 // Format date according to current locale settings
00130                 // Format string is universal, so that whatever the locale is,
00131                 // date is always formatted correctly
00132                 myDate.FormatL(myBuf, _L("%/0%1%/1%2%/2%3%/3%X"));
00133                 
00134                 // Show formatted text              
00135                 CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
00136                 informationNote->ExecuteLD( myBuf );
00137             }
00138             break;
00139             
00140         // Time
00141         case ELocalizationCommandTime:
00142             {
00143                 // buffer for localized text
00144                 TBuf<50> myBuf;
00145                 
00146                 // Object for datetime data
00147                 TTime myTime;
00148                 
00149                 // Set current datetime to object
00150                 myTime.HomeTime();
00151 
00152                 // Format time to current locale
00153                 // Format string is universal, so that whatever the locale is,
00154                 // time is always formatted correctly
00155                 myTime.FormatL(myBuf, _L("%-B%:0%J%:1%T%:2%S%:3%+B"));
00156                 
00157                 // Show formatted text          
00158                 CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
00159                 informationNote->ExecuteLD( myBuf );
00160             }
00161             break;
00162             
00163         // Text
00164         case ELocalizationCommandText:
00165             {
00166                 // buffer for string parameters that may change order
00167                 CDesCArrayFlat* strings = new CDesCArrayFlat( 2 );
00168                 CleanupStack::PushL( strings );
00169 
00170                 // Initialize parameter buffer
00171                 
00172                 // First parameter
00173                 strings->AppendL( _L("Heidi") );
00174                 
00175                 // Second parameter
00176                 strings->AppendL( _L("2") );
00177                 
00178                 // Load a string from the resource file, and append parameters into it
00179                 HBufC* textResource = StringLoader::LoadL( R_LOC_COMMANDTEXT_TEXT, *strings );
00180                 CleanupStack::PushL( textResource );
00181                 
00182                 // Show formatted text          
00183                 CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
00184                 informationNote->ExecuteLD( *textResource );
00185                 
00186                 // Cleanupstack
00187                 CleanupStack::PopAndDestroy( textResource );
00188                 CleanupStack::PopAndDestroy( strings );
00189             }
00190             break;
00191             
00192         // Image
00193         case ELocalizationCommandImage:
00194             {
00195                 // find the drive where the app has been installed
00196                 TParse parse;
00197                 parse.Set(Application()->AppFullName(),0,0);
00198                                 
00199                 // Load bitmap name from the resource file
00200                 HBufC* bmpFile = StringLoader::LoadLC(R_LOC_COMMANDIMAGE_BMPFILE);
00201                 
00202                 // bitmap pointer
00203                 CFbsBitmap* bitmap;
00204                 
00205                 // Create and Load the Bitmap
00206                 bitmap = new( ELeave )CFbsBitmap;
00207                 CleanupStack::PushL( bitmap );
00208                 
00209                 // Load the first bitmap (index 0) from multi-bitmap file
00210                 User::LeaveIfError(bitmap->Load( *bmpFile, 0 ));
00211                 
00212                 CleanupStack::Pop( bitmap );                
00213                 // Draw bitmap to screen 
00214                 // ownership of bitmap is transferred to view
00215                 iAppView->DrawImage( bitmap );
00216 
00217                 // Cleanupstack
00218                 CleanupStack::PopAndDestroy( bmpFile );
00219             }
00220             break;
00221         
00222         // Default case
00223         default:
00224 //            Panic( ELocalizationUi );
00225             break;
00226         }
00227     }
00228 /*
00229 void CLocalizationAppUi::HandleResourceChangeL(TInt aType)
00230     {
00231     CAknAppUi::HandleResourceChangeL( aType );
00232        
00233     if ( aType==KEikDynamicLayoutVariantSwitch )
00234         {
00235         if (iAppView)
00236             {
00237             TRect rect;
00238             AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,rect);
00239             iAppView->SetRect(rect);
00240             }
00241         }           
00242     }
00243 */
00244 // End of File
00245 

Generated by  doxygen 1.6.2