⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controlexamappui.cpp

📁 国内著名嵌入式培训机构内部资料,内含一些实例代码,包括技术专题书籍
💻 CPP
字号:
/*
============================================================================
 Name        : CControlExamAppUi from ControlExamAppui.cpp
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CControlExamAppUi implementation
============================================================================
*/

// INCLUDE FILES
#include "ControlExamApplication.h"
#include "ControlExamAppui.h"
#include "ControlExamView.h"
#include "ControlExamView2.h"
#include <ControlExam.rsg>
#include "ControlExam.hrh"

#include <stringloader.h>
#include <f32file.h>
#include <bautils.h>
#include <charconv.h>
#include <hlplch.h>
#include <avkon.hrh>
#include <aknmessagequerydialog.h>

#include "ControlExam_0xea0ae19a.hlp.hrh"

// ================= MEMBER FUNCTIONS =======================
//
// ----------------------------------------------------------
// CControlExamAppUi::ConstructL()
// 
// ----------------------------------------------------------
//
void CControlExamAppUi::ConstructL()
	{
	BaseConstructL();


	// Show tabs for main views from resources
	CEikStatusPane* sp = StatusPane();

	// Fetch pointer to the default navi pane control
	iNaviPane = (CAknNavigationControlContainer*)sp->ControlL( 
		TUid::Uid(EEikStatusPaneUidNavi));

	// Tabgroup has been read from resource and it were pushed to the navi pane. 
	// Get pointer to the navigation decorator with the ResourceDecorator() function. 
	// Application owns the decorator and it has responsibility to delete the object.
	iDecoratedTabGroup = iNaviPane->ResourceDecorator();
	if (iDecoratedTabGroup)
		{
		iTabGroup = (CAknTabGroup*) iDecoratedTabGroup->DecoratedControl();
		iTabGroup->SetObserver( this );
		}

	CControlExamView* view1 = new (ELeave) CControlExamView;

	CleanupStack::PushL( view1 );
	view1->ConstructL();
	AddViewL( view1 ); // transfer ownership to CAknViewAppUi
	CleanupStack::Pop(); // view1

	CControlExamView2* view2 = new (ELeave) CControlExamView2;

	CleanupStack::PushL( view2 );
	view2->ConstructL();
	AddViewL( view2 ); // transfer ownership to CAknViewAppUi
	CleanupStack::Pop(); // view2

	SetDefaultViewL(*view1);

	PrivacyStatementL();
	}

// ----------------------------------------------------
// CControlExamAppUi::~CControlExamAppUi()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CControlExamAppUi::~CControlExamAppUi()
	{
	delete iDecoratedTabGroup;
   }

// ------------------------------------------------------------------------------
// CControlExamAppUi::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
//  This function is called by the EIKON framework just before it displays
//  a menu pane. Its default implementation is empty, and by overriding it,
//  the application can set the state of menu items dynamically according
//  to the state of application data.
// ------------------------------------------------------------------------------
//
void CControlExamAppUi::DynInitMenuPaneL(
	TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/)
	{
	}

// ----------------------------------------------------
// CControlExamAppUi::HandleKeyEventL(
//	 const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
// takes care of key event handling
// ----------------------------------------------------
//
TKeyResponse CControlExamAppUi::HandleKeyEventL(
	const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	if ( iTabGroup == NULL )
		{
		return EKeyWasNotConsumed;
		}

	if ( aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow )
		{
		return iTabGroup->OfferKeyEventL( aKeyEvent, aType );
		}
	else
		{
		return EKeyWasNotConsumed;
		}
	}

// ----------------------------------------------------
// CControlExamAppUi::HandleCommandL(TInt aCommand)
// takes care of command handling
// ----------------------------------------------------
//
void CControlExamAppUi::HandleCommandL(TInt aCommand)
	{
	switch ( aCommand )
		{
		case EEikCmdExit:
			{
			Exit();
			break;
			}
		case EControlExamCmdAppTest:
			{
			iEikonEnv->InfoMsg(_L("test"));
			break;
			}
	case EHelp:
		{
		CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
		HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
		}
		break;
	case EAbout:
		{
		CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog(); 
		dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
		HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
		dlg->QueryHeading()->SetTextL(*title);
		CleanupStack::PopAndDestroy(); //title
		HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
		dlg->SetMessageTextL(*msg);
		CleanupStack::PopAndDestroy(); //msg
		dlg->RunLD(); 
		}
		break;

		// TODO: Add Your command handling code here

		default:
			break;
		}
	}

 // ----------------------------------------------------
 // CControlExamAppUi::TabChangedL(TInt aIndex)
 // This method gets called when CAknTabGroup active 
 // tab has changed.
 // ----------------------------------------------------
 //
 void CControlExamAppUi::TabChangedL(TInt aIndex)
	 {
	 ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(aIndex)));
	 }

	CArrayFix<TCoeHelpContext>* CControlExamAppUi::HelpContextL() const
	{	 
	// Note: help will not work if the application uid3 is not in the
	// protected range.  The default uid3 range for projects created
	// from this template (0xE0000000 - 0xEFFFFFFF) are not in the protected range so they
	// can be self signed and installed on the device during testing.
	// Once you get your official uid3 from Symbian Ltd. and find/replace
	// all occurrences of uid3 in your project, the context help will
	// work.
	CArrayFixFlat<TCoeHelpContext>* ctxs = new(ELeave)CArrayFixFlat<TCoeHelpContext>(1);
	CleanupStack::PushL(ctxs);
	ctxs->AppendL(TCoeHelpContext(KUidControlExamApp, KGeneral_Information));
	CleanupStack::Pop(ctxs);
	return ctxs;
	}
	
void CControlExamAppUi::PrivacyStatementL() 
	{
	// Note: to see privacy statement in emulator, copy
	// PrivacyStatement.txt from group/ directory to 
	// %EPOCROOT%\Epoc32\release\winscw\udeb\z\private\ea0ae19a\
	// Also note that on emulator you can't modify files on Z: drive,
	// so even if you answer Yes to privacy statement, it will popup
	// dialog every time you launch application. But on device it will work
	// as expected.
	HBufC * fileName = StringLoader::LoadLC(R_PRIVACY_STATEMENT_FILENAME);
	RFs &fs= iCoeEnv->FsSession();
	
	// Make full path to privacy statement
	TFileName fullFileName;
	TFileName privatePath;
	fs.PrivatePath(privatePath);
	TParse parser;
	TFileName processFileName(RProcess().FileName());
	User::LeaveIfError(parser.Set(*fileName, &privatePath, &processFileName));
	fullFileName = parser.FullName();
	CleanupStack::PopAndDestroy(fileName);
	
	if(BaflUtils::FileExists(fs, fullFileName)) 
		{
		RBuf text(CControlExamAppUi::ReadUnicodeFileL(fs, fullFileName));
		CleanupClosePushL(text);
		CAknMessageQueryDialog *dialog = CAknMessageQueryDialog::NewL(text);
		if(dialog->ExecuteLD(R_PRIVSTMT_DIALOG) == EAknSoftkeyYes) 
			{
			BaflUtils::DeleteFile(fs, fullFileName);
			}
		CleanupStack::PopAndDestroy(&text);
		}
	}

HBufC * CControlExamAppUi::ReadUnicodeFileL(RFs& aFs, const TDesC& aFileName)
	{
	RFile file;
	User::LeaveIfError(file.Open(aFs, aFileName, EFileShareReadersOnly | EFileStreamText | EFileRead));
	CleanupClosePushL(file);

	TInt size;
	User::LeaveIfError(file.Size(size));

	RBuf8 tmp;
	tmp.CreateL(size);
	CleanupClosePushL(tmp);
	User::LeaveIfError(file.Read(tmp));

	CCnvCharacterSetConverter * converter = CCnvCharacterSetConverter::NewLC();
	converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierUtf8, aFs);

	HBufC *text = HBufC::NewL(size);

	TInt state = CCnvCharacterSetConverter::KStateDefault;
	TPtrC8 remainderOfForeignText(tmp);
	for(;;)
		{
		TPtr textPtr(text->Des());
		TInt retValue = converter->ConvertToUnicode(textPtr, remainderOfForeignText, state);
		if(retValue == CCnvCharacterSetConverter::EErrorIllFormedInput)
			User::Leave(KErrCorrupt);
		else if(retValue < 0)
			User::Leave(KErrGeneral);
		
		if(retValue == 0)
			break;
			
		remainderOfForeignText.Set(remainderOfForeignText.Right(retValue));
		}	
	
	CleanupStack::PopAndDestroy(converter);
	CleanupStack::PopAndDestroy(2);
	return text;
	}
	
// End of file
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -