Nokia N97 SDK
Example Applications Guide

localizationappui.cpp

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

© Nokia 2009

Back to top