|
Nokia N97 SDK Example Applications Guide |
00001 00002 /* 00003 * ============================================================================== 00004 * Name : MyViewView2.cpp 00005 * Part of : MyView 00006 * Interface : 00007 * Description : Defines second view,Implentation also demonstrates external 00008 * application's view activation and message commands. 00009 * DoActivateL recieves Messages and MessageUids from first view. 00010 * Version : 00011 * 00012 * Copyright (c) 2002 - 2007 Nokia Corporation. 00013 * This material, including documentation and any related 00014 * computer programs, is protected by copyright controlled by 00015 * Nokia Corporation. 00016 * ============================================================================== 00017 */ 00018 00019 00020 // INCLUDE FILES 00021 #include <viewcli.h> 00022 #include <aknviewappui.h> 00023 #include <avkon.hrh> 00024 #include <aknquerydialog.h> 00025 #include <MyView.rsg> 00026 #include "MyViewView2.h" 00027 #include "MyViewContainer2.h" 00028 #include "myview.hrh" 00029 #include <CPbkViewState.h> // For focused phonebook view. 00030 // You need to have PbkView.lib in .mmp 00031 00032 // ================= MEMBER FUNCTIONS ======================= 00033 00034 // --------------------------------------------------------- 00035 // CMyViewView2::ConstructL(const TRect& aRect) 00036 // EPOC two-phased constructor 00037 // --------------------------------------------------------- 00038 // 00039 void CMyViewView2::ConstructL() 00040 { 00041 BaseConstructL( R_MYVIEW_VIEW2 ); 00042 } 00043 00044 // --------------------------------------------------------- 00045 // CMyViewView2::~CMyViewView2() 00046 // Default destructor 00047 // --------------------------------------------------------- 00048 // 00049 CMyViewView2::~CMyViewView2() 00050 { 00051 if ( iContainer ) 00052 { 00053 AppUi()->RemoveFromViewStack( *this, iContainer ); 00054 } 00055 00056 delete iContainer; 00057 } 00058 00059 // --------------------------------------------------------- 00060 // TUid CMyViewView2::Id() 00061 // This returns the view ID 00062 // --------------------------------------------------------- 00063 // 00064 TUid CMyViewView2::Id() const 00065 { 00066 return KView2Id; 00067 } 00068 00069 // --------------------------------------------------------- 00070 // CMyViewView2::HandleCommandL(TInt aCommand) 00071 // Here we handle commands for this view. 00072 // Each view has their own HandleCommandL() 00073 // --------------------------------------------------------- 00074 // 00075 void CMyViewView2::HandleCommandL(TInt aCommand) 00076 { 00077 switch ( aCommand ) 00078 { 00079 case EAknSoftkeyOk: 00080 { 00081 break; 00082 } 00083 case EAknSoftkeyExit: 00084 { 00085 AppUi()->HandleCommandL(EEikCmdExit); 00086 break; 00087 } 00088 case EMyViewCmdView2Cmd1: 00089 { 00090 // Open calendar application in month view. 00091 // If other than month view is defined as default view, 00092 // month view will open only if calendar application is running on background. 00093 // If calendar is not running, user defined default view will open instead. 00094 // This is done by framework, when calendar gets focus, the default view will open. 00095 const TUid KCalendarUid = { 0x10005901 }; // Application Uid 00096 const TUid KCalendarViewUid = { 1 }; // View Uid of the external application 00097 AppUi()->ActivateViewL(TVwsViewId(KCalendarUid, KCalendarViewUid)); 00098 00099 break; 00100 } 00101 case EMyViewCmdView2Cmd2: 00102 { 00103 00104 //Open Messagin to main view 00105 const TUid KMessagingUid = { 0x100058C5 }; // Application Uid 00106 const TUid KInboxViewUid = { 1 }; // View Uid of the external application 00107 AppUi()->ActivateViewL(TVwsViewId(KMessagingUid, KInboxViewUid)); 00108 00109 break; 00110 } 00111 case EMyViewCmdView2Cmd3: 00112 { 00113 00114 const TUid KRecorderUid = { 0x100058CA }; // Application Uid 00115 00116 // Start recorder in recorder view and have it start immeditately 00117 const TUid KRecorderViewUid = { 1 }; // View Uid of the external application 00118 const TUid KRecorderMessageUid = { 2 }; // MessageUid of the external application 00119 AppUi()->ActivateViewL(TVwsViewId(KRecorderUid, KRecorderViewUid), KRecorderMessageUid, 00120 KNullDesC8); 00121 00122 break; 00123 } 00124 case EMyViewCmdView2Cmd4: 00125 { 00126 // Open phonebook application with focused view 00127 const TUid appUid = { 0x101f4cce }; // Application Uid 00128 const TUid KExtViewUid= { 4 }; // Contact Info View Uid of Phonebook Application 00129 00130 TInt contact = 1; 00131 CAknNumberQueryDialog *dlg = CAknNumberQueryDialog::NewL(contact); 00132 if (dlg->ExecuteLD(R_CONTACT_NUMBER_QUERY)) 00133 { 00134 // ok pressed 00135 00136 // Costruct a message for Phonebook application 00137 CPbkViewState* pbkViewParam = CPbkViewState::NewLC(); 00138 00139 // Focus on contact with specified id-number. You have to have 00140 // the specified contact for this to work. 00141 pbkViewParam->SetFocusedContactId(contact); 00142 // Package and return object in a buffer. 00143 HBufC8* paramBuf = pbkViewParam->PackLC(); 00144 00145 // Activate the view 00146 AppUi()->ActivateViewL(TVwsViewId(appUid, KExtViewUid), CPbkViewState::Uid(), 00147 *paramBuf); 00148 00149 // Cleanup 00150 CleanupStack::PopAndDestroy(paramBuf); 00151 CleanupStack::PopAndDestroy(pbkViewParam); 00152 } 00153 break; 00154 } 00155 00156 default: 00157 { 00158 AppUi()->HandleCommandL( aCommand ); 00159 break; 00160 } 00161 } 00162 } 00163 00164 // --------------------------------------------------------- 00165 // CMyViewView2::HandleClientRectChange() 00166 // --------------------------------------------------------- 00167 // 00168 void CMyViewView2::HandleClientRectChange() 00169 { 00170 if ( iContainer ) 00171 { 00172 iContainer->SetRect( ClientRect() ); 00173 } 00174 } 00175 00176 // --------------------------------------------------------- 00177 // CMyViewView2::DoActivateL(...) 00178 // This is called when a view needs to be activated. 00179 // This creates container with its controls. 00180 // --------------------------------------------------------- 00181 // 00182 void CMyViewView2::DoActivateL( 00183 const TVwsViewId& /*aPrevViewId*/,TUid aCustomMessageId, 00184 const TDesC8& aCustomMessage) 00185 { 00186 00187 // Create Container 00188 if (!iContainer) 00189 { 00190 iContainer = new (ELeave) CMyViewContainer2; 00191 iContainer->SetMopParent(this); 00192 iContainer->ConstructL( ClientRect() ); 00193 AppUi()->AddToStackL( *this, iContainer ); 00194 } 00195 00196 00197 // Check aCustomMessageId to handle aCustomMessage 00198 // You could check aPrevViewId if you were curious to know 00199 // from where this view was called from. 00200 const TUid KLocalComparisionUid= {2}; 00201 if (aCustomMessageId==KLocalComparisionUid) 00202 { 00203 TBuf8<255> customMessage; 00204 customMessage.Copy(aCustomMessage); 00205 00206 // do something with aCustomMessage 00207 if (customMessage==KNullDesC8) 00208 iEikonEnv->InfoMsg(_L("MessageUid passed")); 00209 else 00210 iEikonEnv->InfoMsg(_L("Message and Uid passed")); 00211 00212 } 00213 } 00214 00215 // --------------------------------------------------------- 00216 // CMyViewView2::HandleCommandL(TInt aCommand) 00217 // This is called when a view needs to be deactivated. 00218 // This destroys container with its controls. 00219 // --------------------------------------------------------- 00220 // 00221 void CMyViewView2::DoDeactivate() 00222 { 00223 if ( iContainer ) 00224 { 00225 AppUi()->RemoveFromViewStack( *this, iContainer ); 00226 } 00227 00228 delete iContainer; 00229 iContainer = NULL; 00230 } 00231 00232 00233 // End of File 00234
|
© Nokia 2009 |