• Symbian OS basics, Memory Management, Descriptors, Application Structure, Client-Server, Act
源代码在线查看: myviews.cpp
#include "MyViews.h"
#include
#include
#include
#include
#include
#include "MyEngine.h"
#include "MyAppUi.h"
#include "MyApp.hrh"
#include
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(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(CEikonEnv::Static()->AppUi())->GetEngine();
iLabel->SetTextL(engine->GetViewTwoData());
SetRect(aRect);
ActivateL();
}