Nokia N97 SDK
Example Applications Guide

focuseventappui.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : focuseventappui.cpp
00004 *  Part of     : Focus event 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 <avkon.hrh>
00018 #include <aknnotewrappers.h>
00019 #include <stringloader.h>
00020 #include <FocusEvent.rsg>
00021 
00022 #include "FocusEvent.pan"
00023 #include "FocusEventAppUi.h"
00024 #include "FocusEventAppView.h"
00025 
00026 // ============================ MEMBER FUNCTIONS ===============================
00027 
00028 // -----------------------------------------------------------------------------
00029 // CFocusEventAppUi::CFocusEventAppUi()
00030 // C++ default constructor can NOT contain any code, that might leave.
00031 // -----------------------------------------------------------------------------
00032 //
00033 CFocusEventAppUi::CFocusEventAppUi()
00034     {
00035     // No implementation required
00036     }
00037 
00038 // -----------------------------------------------------------------------------
00039 // CFocusEventAppUi::ConstructL()
00040 // Symbian 2nd phase constructor can leave.
00041 // -----------------------------------------------------------------------------
00042 //
00043 void CFocusEventAppUi::ConstructL()
00044     {
00045     BaseConstructL( EAknEnableSkin );
00046 
00047     iAppView = CFocusEventAppView::NewL( ClientRect() );
00048     AddToStackL( iAppView );
00049     }
00050 
00051 
00052 // -----------------------------------------------------------------------------
00053 // CFocusEventAppUi::~CFocusEventAppUi()
00054 // Destructor.
00055 // -----------------------------------------------------------------------------
00056 //
00057 CFocusEventAppUi::~CFocusEventAppUi()
00058     {
00059     if ( iAppView )
00060         {
00061         iEikonEnv->RemoveFromStack( iAppView );
00062         delete iAppView;
00063         iAppView = NULL;
00064         }
00065     }
00066 
00067 // -----------------------------------------------------------------------------
00068 // CFocusEventAppUi::HandleCommandL()
00069 // Takes care of key event handling.
00070 // -----------------------------------------------------------------------------
00071 //
00072 void CFocusEventAppUi::HandleCommandL( TInt aCommand )
00073     {
00074     switch ( aCommand )
00075         {
00076     case EEikCmdExit:
00077     case EAknSoftkeyExit:
00078         Exit();
00079         break;
00080 
00081     default:
00082         break;
00083         }
00084     }
00085 
00086 // -----------------------------------------------------------------------------
00087 // CFocusEventAppUi::HandleForegroundEventL()
00088 // Displays message every time focus is gained or lost.
00089 // -----------------------------------------------------------------------------
00090 //
00091 void CFocusEventAppUi::HandleForegroundEventL( TBool aForeground )
00092     {
00093     if ( !aForeground ) // Focus lost
00094         {
00095         // Load a string from the resource file.
00096         HBufC* lostFocusMessage = StringLoader::LoadLC
00097                                                  ( R_FOCU_LOST_FOCUS_TEXT );
00098 #ifdef __WINS__
00099         User::InfoPrint( *lostFocusMessage );
00100 #endif /* __WINS__ */
00101         iAppView->Print( *lostFocusMessage );
00102         iAppView->PrintNewLineL();
00103         // Pop HBuf from CleanupStack and destroy it.
00104         CleanupStack::PopAndDestroy( lostFocusMessage );
00105         }
00106     else // Focus gained
00107         {
00108         // Load a string from the resource file.
00109         HBufC* gainedFocusMessage = StringLoader::LoadLC
00110                                                    ( R_FOCU_GAINED_FOCUS_TEXT );
00111 #ifdef __WINS__
00112         User::InfoPrint( *gainedFocusMessage );
00113 #endif /* __WINS__ */
00114         iAppView->Print( *gainedFocusMessage );
00115         iAppView->PrintNewLineL();
00116         // Pop HBuf from CleanupStack and Destroy it.
00117         CleanupStack::PopAndDestroy( gainedFocusMessage );
00118         }
00119 
00120     CAknAppUi::HandleForegroundEventL( aForeground );
00121     }
00122 
00123 // End of File

© Nokia 2009

Back to top