Nokia N97 SDK Example Applications Guide |
00001 /* 00002 ============================================================================ 00003 Name : HsWidgetAppUi.cpp 00004 Author : 00005 Copyright : Your copyright notice 00006 Description : CHsWidgetAppUi implementation 00007 ============================================================================ 00008 */ 00009 00010 // INCLUDE FILES 00011 #include <eikmenup.h> 00012 #include <avkon.hrh> 00013 #include <aknmessagequerydialog.h> 00014 #include <aknnotewrappers.h> 00015 #include <stringloader.h> 00016 #include <f32file.h> 00017 #include <s32file.h> 00018 #include <hlplch.h> 00019 00020 #include <HsWidget.rsg> 00021 00022 #include "HsWidget.hlp.hrh" 00023 #include "HsWidget.hrh" 00024 #include "HsWidget.pan" 00025 #include "HsWidgetApplication.h" 00026 #include "HsWidgetAppUi.h" 00027 #include "HsWidgetAppView.h" 00028 #include "HsWidgetExample.h" 00029 00030 _LIT(KFileName, "C:\\private\\E965D1BA\\HsWidget.txt"); 00031 _LIT(KText, "Hello World!"); 00032 00033 // ============================ MEMBER FUNCTIONS =============================== 00034 00035 00036 // ----------------------------------------------------------------------------- 00037 // CHsWidgetAppUi::ConstructL() 00038 // Symbian 2nd phase constructor can leave. 00039 // ----------------------------------------------------------------------------- 00040 // 00041 void CHsWidgetAppUi::ConstructL() 00042 { 00043 // Initialise app UI with standard value. 00044 BaseConstructL(CAknAppUi::EAknEnableSkin); 00045 00046 // Create view object 00047 iAppView = CHsWidgetAppView::NewL(ClientRect() ); 00048 00049 // Create a file to write the text to 00050 TInt err = CCoeEnv::Static()->FsSession().MkDirAll(KFileName); 00051 if ( (KErrNone != err) && (KErrAlreadyExists != err)) 00052 { 00053 return; 00054 } 00055 00056 RFile file; 00057 err = file.Replace(CCoeEnv::Static()->FsSession(), KFileName, EFileWrite); 00058 CleanupClosePushL(file); 00059 if (KErrNone != err) 00060 { 00061 CleanupStack::PopAndDestroy(1); // file 00062 return; 00063 } 00064 00065 RFileWriteStream outputFileStream(file); 00066 CleanupClosePushL(outputFileStream); 00067 outputFileStream << KText; 00068 00069 CleanupStack::PopAndDestroy(2); // outputFileStream, file 00070 00071 } 00072 // ----------------------------------------------------------------------------- 00073 // CHsWidgetAppUi::CHsWidgetAppUi() 00074 // C++ default constructor can NOT contain any code, that might leave. 00075 // ----------------------------------------------------------------------------- 00076 // 00077 CHsWidgetAppUi::CHsWidgetAppUi() 00078 { 00079 // No implementation required 00080 } 00081 00082 // ----------------------------------------------------------------------------- 00083 // CHsWidgetAppUi::~CHsWidgetAppUi() 00084 // Destructor. 00085 // ----------------------------------------------------------------------------- 00086 // 00087 CHsWidgetAppUi::~CHsWidgetAppUi() 00088 { 00089 if (iAppView) 00090 { 00091 delete iAppView; 00092 iAppView = NULL; 00093 } 00094 delete iWidgetExample; 00095 } 00096 00097 // ----------------------------------------------------------------------------- 00098 // CHsWidgetAppUi::HandleCommandL() 00099 // Takes care of command handling. 00100 // ----------------------------------------------------------------------------- 00101 // 00102 void CHsWidgetAppUi::HandleCommandL(TInt aCommand) 00103 { 00104 switch (aCommand) 00105 { 00106 case EEikCmdExit: 00107 case EAknSoftkeyExit: 00108 Exit(); 00109 break; 00110 00111 case ERegisterWidget: 00112 { 00113 if( !iWidgetExample) 00114 { 00115 iWidgetExample = CHsWidgetExample::NewL(); 00116 } 00117 iWidgetExample->RegisterWidget(); 00118 } 00119 break; 00120 case EChangeWidgetValues: 00121 { 00122 iWidgetExample->ChangeWidgetValuesL(); 00123 } 00124 break; 00125 case ERemoveWidget: 00126 { 00127 iWidgetExample->RemoveWidget(); 00128 delete iWidgetExample; 00129 iWidgetExample = NULL; 00130 } 00131 break; 00132 case EHelp: 00133 { 00134 00135 CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL(); 00136 HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf); 00137 } 00138 break; 00139 case EAbout: 00140 { 00141 00142 CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog(); 00143 dlg->PrepareLC(R_ABOUT_QUERY_DIALOG); 00144 HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE); 00145 dlg->QueryHeading()->SetTextL(*title); 00146 CleanupStack::PopAndDestroy(); //title 00147 HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT); 00148 dlg->SetMessageTextL(*msg); 00149 CleanupStack::PopAndDestroy(); //msg 00150 dlg->RunLD(); 00151 } 00152 break; 00153 default: 00154 Panic(EHsWidgetUi); 00155 break; 00156 } 00157 } 00158 // ----------------------------------------------------------------------------- 00159 // Called by the framework when the application status pane 00160 // size is changed. Passes the new client rectangle to the 00161 // AppView 00162 // ----------------------------------------------------------------------------- 00163 // 00164 void CHsWidgetAppUi::HandleStatusPaneSizeChange() 00165 { 00166 iAppView->SetRect(ClientRect() ); 00167 } 00168 00169 CArrayFix<TCoeHelpContext>* CHsWidgetAppUi::HelpContextL() const 00170 { 00171 //#warning "Please see comment about help and UID3..." 00172 // Note: Help will not work if the application uid3 is not in the 00173 // protected range. The default uid3 range for projects created 00174 // from this template (0xE0000000 - 0xEFFFFFFF) are not in the protected range so that they 00175 // can be self signed and installed on the device during testing. 00176 // Once you get your official uid3 from Symbian Ltd. and find/replace 00177 // all occurrences of uid3 in your project, the context help will 00178 // work. 00179 CArrayFixFlat<TCoeHelpContext>* array = new(ELeave)CArrayFixFlat<TCoeHelpContext>(1); 00180 CleanupStack::PushL(array); 00181 array->AppendL(TCoeHelpContext(KUidHsWidgetApp, KGeneral_Information)); 00182 CleanupStack::Pop(array); 00183 return array; 00184 } 00185 00186 00187 // ----------------------------------------------------------------------------- 00188 // CHsWidgetAppUi::DynInitMenuPaneL 00189 // Dimm items depend on widget existing. 00190 // ----------------------------------------------------------------------------- 00191 // 00192 void CHsWidgetAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane ) 00193 { 00194 if( aResourceId != R_MENU ) 00195 { 00196 return; 00197 } 00198 if( !iWidgetExample ) 00199 { 00200 aMenuPane->SetItemDimmed( ERegisterWidget, EFalse ); 00201 aMenuPane->SetItemDimmed( EChangeWidgetValues, ETrue ); 00202 aMenuPane->SetItemDimmed( ERemoveWidget, ETrue ); 00203 } 00204 else 00205 { 00206 aMenuPane->SetItemDimmed( ERegisterWidget, ETrue ); 00207 aMenuPane->SetItemDimmed( EChangeWidgetValues, EFalse ); 00208 aMenuPane->SetItemDimmed( ERemoveWidget, EFalse ); 00209 } 00210 } 00211 00212 // End of File
© Nokia 2009 |