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

📄 myviews.cpp

📁 &#8226 Symbian OS basics, Memory Management, Descriptors, Application Structure, Client-Server, Act
💻 CPP
字号:


#include "MyViews.h"
#include <eiklabel.h>
#include <coeaui.h>
#include <eikenv.h>
#include <aknviewappui.h>
#include <aknglobalnote.h>
#include "MyEngine.h"
#include "MyAppUi.h"
#include "MyApp.hrh"
#include <MyApp.rsg>

CMyViewOne::~CMyViewOne()
	{
	delete iContainer;
	}

CMyViewOne* CMyViewOne::NewL()
	{
	CMyViewOne* self = CMyViewOne::NewLC();
	CleanupStack::Pop(self);
	return self;
	}

CMyViewOne* CMyViewOne::NewLC()
	{
	CMyViewOne* self = new (ELeave) CMyViewOne();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}


void CMyViewOne::ConstructL()
    {
	BaseConstructL(R_MYAPP_VIEW_ONE);
    }


TUid CMyViewOne::Id() const
	{
	return KUidMyAppViewOne;
	}

void CMyViewOne::DoActivateL (const TVwsViewId &/*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8 &/*aCustomMessage*/)
	{
	if (!iContainer)
		{
		iContainer = CContainerOne::NewL(ClientRect());
		iContainer->SetMopParent(this);
		AppUi()->AddToStackL(*this, iContainer);
		}
	}

void CMyViewOne::DoDeactivate()
	{
	if (iContainer)
		{
		AppUi()->RemoveFromStack(iContainer);
		delete iContainer;
		iContainer = NULL;
		}

	}

void CMyViewOne::HandleCommandL(TInt aCommand)
	{
	// We could choose to handle events in this class but 
	// for consistency with UIQ they can be passed to appui
	AppUi()->HandleCommandL(aCommand);
	}
//////////////////////////////////////////////////////////

CMyViewTwo::~CMyViewTwo()
	{
	delete iContainer;
	}

CMyViewTwo* CMyViewTwo::NewL()
	{
	CMyViewTwo* self = CMyViewTwo::NewLC();
	CleanupStack::Pop(self);
	return self;
	}

CMyViewTwo* CMyViewTwo::NewLC()
	{
	CMyViewTwo* self = new (ELeave) CMyViewTwo();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}


void CMyViewTwo::ConstructL()
    {
	BaseConstructL(R_MYAPP_VIEW_TWO);

    }
void CMyViewTwo::HandleCommandL(TInt aCommand)
	{
	    switch ( aCommand )
        {
		case EMyAppCmdMessageType2:
			{
			CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
			globalNote->ShowNoteL(EAknGlobalWarningNote, _L("Warning Note"));
			CleanupStack::PopAndDestroy();
			break;
			}
		case EMyAppCmdMessageType3:
			{
			CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
			globalNote->ShowNoteL(EAknGlobalConfirmationNote, _L("Confirmation Note"));
			CleanupStack::PopAndDestroy();
			break;
			}

		// we let the AppUi deal with the rest
		// including the view switching
		default:
			AppUi()->HandleCommandL(aCommand);
		}

	}



TUid CMyViewTwo::Id() const
	{
	return KUidMyAppViewTwo;
	}

void CMyViewTwo::DoActivateL (const TVwsViewId &/*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8 &/*aCustomMessage*/)
	{
	if (!iContainer)
		{
		iContainer = CContainerTwo::NewL(ClientRect());
		iContainer->SetMopParent(this);
		AppUi()->AddToStackL(*this, iContainer);
		}	  
	}

void CMyViewTwo::DoDeactivate()
	{
	if (iContainer)
		{
		AppUi()->RemoveFromStack(iContainer);
		delete iContainer;
		iContainer = NULL;
		}

	}





/// Containers
CContainerOne* CContainerOne::NewL(const TRect& aRect)
	{
	CContainerOne* self = CContainerOne::NewLC(aRect);
	CleanupStack::Pop(self);
	return self;
	}

CContainerOne* CContainerOne::NewLC(const TRect& aRect)
	{
	CContainerOne* self = new (ELeave) CContainerOne;
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	return self;
	}

CContainerOne::~CContainerOne()
	{
	delete iLabel;
	}


void CContainerOne::ConstructL(const TRect& aRect)
	{
	CreateWindowL();
	iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL( *this );
	CMyEngine* engine = static_cast<CMyAppUi*>(CEikonEnv::Static()->AppUi())->GetEngine();
	iLabel->SetTextL(engine->GetViewOneData());

    SetRect(aRect);
    ActivateL();
	}


void CContainerOne::SizeChanged()
    {
    // TODO: Add here control resize code etc.
    iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
    }

TInt CContainerOne::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }

CCoeControl* CContainerOne::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
            return iLabel;
        default:
            return NULL;
        }
    }

void CContainerOne::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
    }



///////////// end of container one. //////////////////////////
CContainerTwo* CContainerTwo::NewL(const TRect& aRect)
	{
	CContainerTwo* self = CContainerTwo::NewLC(aRect);
	CleanupStack::Pop(self);
	return self;
	}

CContainerTwo* CContainerTwo::NewLC(const TRect& aRect)
	{
	CContainerTwo* self = new (ELeave) CContainerTwo;
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	return self;
	}

   
void CContainerTwo::ConstructL(const TRect& aRect)
	{
	CreateWindowL();
	iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL( *this );
	CMyEngine* engine = static_cast<CMyAppUi*>(CEikonEnv::Static()->AppUi())->GetEngine();
	iLabel->SetTextL(engine->GetViewTwoData());
    SetRect(aRect);
    ActivateL();
	}


⌨️ 快捷键说明

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