Nokia N97 SDK
Example Applications Guide

MyViewView.cpp

00001 
00002 /*
00003 * ==============================================================================
00004 *  Name        : MyViewView.cpp
00005 *  Part of     : MyView
00006 *  Interface   :
00007 *  Description : Defines first view, Local activation and message commands are 
00008 *                given in HandleCommandL
00009 *  Version     :
00010 *
00011 *  Copyright (c) 2002 - 2007 Nokia Corporation.
00012 *  This material, including documentation and any related
00013 *  computer programs, is protected by copyright controlled by
00014 *  Nokia Corporation.
00015 * ==============================================================================
00016 */
00017 
00018 // INCLUDE FILES
00019 #include  <aknviewappui.h>
00020 #include  <avkon.hrh>
00021 #include  <MyView.rsg>
00022 #include  "MyViewView.h"
00023 #include  "MyViewView2.h" //For view2 id
00024 #include  "MyViewContainer.h" 
00025 #include  "myview.hrh"
00026 
00027 
00028 // ================= MEMBER FUNCTIONS =======================
00029 
00030 // ---------------------------------------------------------
00031 // CMyViewView::ConstructL(const TRect& aRect)
00032 // EPOC two-phased constructor
00033 // ---------------------------------------------------------
00034 //
00035 void CMyViewView::ConstructL(CAknTabGroup* aTabGroup)
00036     {
00037     // construct R_MYVIEW_VIEW1 resources
00038     BaseConstructL( R_MYVIEW_VIEW1 );
00039     iTabGroup=aTabGroup;
00040     }
00041 
00042 // ---------------------------------------------------------
00043 // CMyViewView::~CMyViewView()
00044 // Default destructor
00045 // ---------------------------------------------------------
00046 //
00047 CMyViewView::~CMyViewView()
00048     {
00049     if ( iContainer )
00050         {
00051         AppUi()->RemoveFromViewStack( *this, iContainer );
00052         }
00053 
00054     delete iContainer;
00055     }
00056 
00057 // ---------------------------------------------------------
00058 // TUid CMyViewView::Id()
00059 // This returns the view ID
00060 // ---------------------------------------------------------
00061 //
00062 TUid CMyViewView::Id() const
00063     {
00064     return KViewId;
00065     }
00066 
00067 // ---------------------------------------------------------
00068 // CMyViewView::HandleCommandL(TInt aCommand)
00069 // Here we handle commands for this view. 
00070 // Each view has their own HandleCommandL()
00071 // ---------------------------------------------------------
00072 //
00073 void CMyViewView::HandleCommandL(TInt aCommand)
00074     {   
00075     switch ( aCommand )
00076         {
00077         case EAknSoftkeyOk:
00078             {
00079             iEikonEnv->InfoMsg( _L("view1 ok") );
00080             break;
00081             }
00082         case EAknSoftkeyExit:
00083             {
00084             AppUi()->HandleCommandL(EEikCmdExit);
00085             break;
00086             }
00087 
00088         case EMyViewCmdView1Cmd1:
00089             {
00090             // Update the correct tab in the navipane.
00091             // View Management System does not adjust the navi pane tabs.
00092             iTabGroup->SetActiveTabByIndex(1);
00093 
00094             // Switch to view 2            
00095             AppUi()->ActivateLocalViewL(KView2Id);
00096             break;
00097             }
00098         case EMyViewCmdView1Cmd2:
00099             {
00100             // Update the correct tab in the navipane.
00101             // View Management System does not adjust the navi pane tabs.
00102             iTabGroup->SetActiveTabByIndex(1);
00103 
00104             // Switch to view 2 and send a message Uid. Message is set to null.
00105             const TUid KCustomMessageUid= { 2 };    // MessageUid to send
00106             AppUi()->ActivateLocalViewL(KView2Id, KCustomMessageUid, KNullDesC8);
00107             break;
00108             }
00109         case EMyViewCmdView1Cmd3:
00110             {
00111             // Update the correct tab in the navipane.
00112             // View Management System does not adjust the navi pane tabs.
00113             iTabGroup->SetActiveTabByIndex(1);
00114 
00115             // Switch to view 2 and send a message Uid and a message
00116             const TUid KCustomMessageUid= { 2 };    // MessageUid to send
00117             // Construct a message to send
00118             TBuf8<255> customMessage;
00119             customMessage.Copy(_L8("Some data here"));
00120             AppUi()->ActivateLocalViewL(KView2Id, KCustomMessageUid, customMessage);
00121             break;
00122             }
00123 
00124         default:
00125             {
00126             AppUi()->HandleCommandL( aCommand );
00127             break;
00128             }
00129         }
00130     }
00131 
00132 // ---------------------------------------------------------
00133 // CMyViewView::HandleClientRectChange()
00134 // ---------------------------------------------------------
00135 //
00136 void CMyViewView::HandleClientRectChange()
00137     {
00138     if ( iContainer )
00139         {
00140         iContainer->SetRect( ClientRect() );
00141         }
00142     }
00143 
00144 // ---------------------------------------------------------
00145 // CMyViewView::DoActivateL(...)
00146 // This is called when a view needs to be activated. 
00147 // This creates container with its controls.
00148 // It also receives messages sent to the view.
00149 // aPrevViewId is passed s.t. we can return to the previous view.
00150 // aCustomMessageId is an ID for the message.
00151 // aCustomMessage is the actual message.
00152 // ---------------------------------------------------------
00153 //
00154 void CMyViewView::DoActivateL(
00155    const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
00156    const TDesC8& /*aCustomMessage*/)
00157     {
00158     if (!iContainer)
00159         {
00160         iContainer = new (ELeave) CMyViewContainer;
00161         iContainer->SetMopParent(this);
00162         iContainer->ConstructL( ClientRect() );
00163         AppUi()->AddToStackL( *this, iContainer );
00164         } 
00165 
00166     // Message handling would take place here.
00167    }
00168 
00169 // ---------------------------------------------------------
00170 // CMyViewView::HandleCommandL(TInt aCommand)
00171 // This is called when a view needs to be deactivated. 
00172 // This destroys container with its controls.
00173 // ---------------------------------------------------------
00174 //
00175 void CMyViewView::DoDeactivate()
00176     {
00177     if ( iContainer )
00178         {
00179         AppUi()->RemoveFromViewStack( *this, iContainer );
00180         }
00181     
00182     delete iContainer;
00183     iContainer = NULL;
00184     }
00185 
00186 
00187 // End of File
00188 

© Nokia 2009

Back to top