appui.cpp

来自「也是一个基于S60的源代码」· C++ 代码 · 共 155 行

CPP
155
字号
// appui.cpp
//
// Copyright (c) 2000 Symbian Ltd.  All rights reserved.
//

#include "appui.h"
#include "controller.h"
#include "view.h"

#include <eikenv.h>

/*
	CGameAppUi
*/

void CGameAppUi::ConstructL()
    {
    BaseConstructL();
	// construct app view
	iController=static_cast<CGameDocument*>(Document())->iController;
    iAppView=new(ELeave) CFleetView;
    iAppView->ConstructL(ClientRect());
	iController->SetAppView(iAppView);
	AddToStackL(iAppView);
    }

CGameAppUi::~CGameAppUi()
	{
	RemoveFromStack(iAppView);
	delete iAppView;
	}

void CGameAppUi::HandleCommandL(TInt aCommand)
	{
	switch (aCommand)
		{
	case EEikCmdExit:
		SaveL();
		Exit();
		break;
	case EEikCmdZoomIn:
		CmdZoomInL();
		break;
	case EEikCmdZoomOut:
		CmdZoomOutL();
		break;
	case EGameCmdStart:
		CmdStartL();
		break;
		}
	}

void CGameAppUi::CmdStartL()
	{
	// user-friendly check
	if (iController->IsMyTurn())
		{
		if (!iEikonEnv->QueryWinL(R_GAME_QUERY_ABANDON))
			return;
		}
	iController->Reset();
	iAppView->DrawTilesNow();
	}

void CGameAppUi::CmdZoomInL()
	{
	iController->ZoomInL();
	}

void CGameAppUi::CmdZoomOutL()
	{
	iController->ZoomOutL();
	}

void CGameAppUi::HandleModelChangeL()
	{
	// change pointers to new objects
	iController=static_cast<CGameDocument*>(Document())->iController;
	iController->SetAppView(iAppView);
	}
	
/*
	CGameDocument
*/

CGameDocument::CGameDocument(CEikApplication& aApp)
		: CEikDocument(aApp)
	{
	}

void CGameDocument::ConstructL()
	{
	iController=CGameController::NewL();
	}

CGameDocument::~CGameDocument()
	{
	delete iController;
	}

CEikAppUi* CGameDocument::CreateAppUiL()
	{
    return new(ELeave) CGameAppUi;
	}

void CGameDocument::NewDocumentL()
	{
	iController->Reset();
	}

void CGameDocument::RestoreL(const CStreamStore& aStore,const CStreamDictionary& aStreamDict)
	{
	// new controller initialized from store
	TStreamId id=aStreamDict.At(KUidExample);
	CGameController* controller=CGameController::NewL(aStore, id);
	delete iController;
	iController=controller;
	}

void CGameDocument::StoreL(CStreamStore& aStore,CStreamDictionary& aStreamDict) const
	{
	TStreamId id=iController->StoreL(aStore);
	aStreamDict.AssignL(KUidExample,id);
	}

/*
	CGameApplication
*/

TUid CGameApplication::AppDllUid() const
	{
	return KUidExample;
	}

CApaDocument* CGameApplication::CreateDocumentL()
	{
	CGameDocument* doc=new(ELeave) CGameDocument(*this);
	CleanupStack::PushL(doc);
	doc->ConstructL();
	CleanupStack::Pop();
	return doc;
	}

// DLL interface stuff

EXPORT_C CApaApplication* NewApplication()
	{
	return new CGameApplication;
	}

GLDEF_C TInt E32Dll(TDllReason)
	{
	return KErrNone;
	}

⌨️ 快捷键说明

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