📄 activeobjappview.cpp
字号:
/*
============================================================================
Name : ActiveObjView.cpp
Author :
Version :
Copyright : Forum Nokia, 2006
Description : Application view
============================================================================
*/
#include <coemain.h>
#include <eiklabel.h>
#include "ActiveObjAppView.h"
#include "ActiveBubbleSorter.h"
_LIT( KStartActionText, "Select menu item\nto begin sorting..." );
_LIT( KCancelActionText, "Select menu item\nto cancel sorting..." );
_LIT( KSyncInfo, "Selecting menu item during sorting\n no effect at all" );
_LIT( KSortingText, "Sorting..." );
_LIT( KSortingComplete, "Sorting Complete." );
_LIT( KSortingError, "Sorting Error: %d");
_LIT( KSortingCancelled, "Sorting cancelled." );
// -----------------------------------------------------------------------------
// CActiveObjAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CActiveObjAppView* CActiveObjAppView::NewL( const TRect& aRect )
{
CActiveObjAppView* self = CActiveObjAppView::NewLC( aRect );
CleanupStack::Pop( self );
return self;
}
// -----------------------------------------------------------------------------
// CActiveObjAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CActiveObjAppView* CActiveObjAppView::NewLC( const TRect& aRect )
{
CActiveObjAppView* self = new ( ELeave ) CActiveObjAppView;
CleanupStack::PushL( self );
self->ConstructL( aRect );
return self;
}
// -----------------------------------------------------------------------------
// CActiveObjAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CActiveObjAppView::ConstructL( const TRect& aRect )
{
// Create a window for this application view
CreateWindowL();
iTopLabel = new (ELeave) CEikLabel;
iTopLabel->SetContainerWindowL( *this );
iTopLabel->SetTextL(KStartActionText);
iBottomLabel = new (ELeave) CEikLabel;
iBottomLabel->SetContainerWindowL( *this );
iBottomLabel->SetTextL(KNullDesC);
iActiveBubbleSorter = CActiveBubbleSorter::NewL(*this);
// Set the windows size
SetRect( aRect );
// Activate the window, which makes it ready to be drawn
ActivateL();
}
// -----------------------------------------------------------------------------
// CActiveObjAppView::CActiveObjAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CActiveObjAppView::CActiveObjAppView()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CActiveObjAppView::~CActiveObjAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CActiveObjAppView::~CActiveObjAppView()
{
delete iActiveBubbleSorter;
delete iBottomLabel;
delete iTopLabel;
}
// -----------------------------------------------------------------------------
// CActiveObjAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CActiveObjAppView::SizeChanged()
{
iTopLabel->SetExtent( TPoint(0,0), TSize(Rect().Width(), Rect().Height()/2));
iBottomLabel->SetExtent( TPoint(0,Rect().Height()/2), TSize(Rect().Width(),Rect().Height()/2));
}
TInt CActiveObjAppView::CountComponentControls() const
{
return 2; // return nbr of controls inside this container
}
// Gets an indexed component of this compound control
CCoeControl* CActiveObjAppView::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iTopLabel;
case 1:
return iBottomLabel;
default:
return NULL;
}
}
// Draw a grey rectangle that fills the client area of the screen
void CActiveObjAppView::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbGray);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// Starts sorting
void CActiveObjAppView::SortL()
{
iIsSorting = ETrue;
iTopLabel->SetTextL(KCancelActionText);
iBottomLabel->SetTextL(KSortingText);
DrawNow();
iActiveBubbleSorter->StartL();
}
void CActiveObjAppView::SyncSortL()
{
iIsSorting = ETrue;
iTopLabel->SetTextL( KSyncInfo );
iBottomLabel->SetTextL( KSortingText );
DrawNow();
iActiveBubbleSorter->SyncSortL();
}
// Callback function called when sorting has been completed
void CActiveObjAppView::SortComplete(TInt aError)
{
iIsSorting = EFalse;
TBuf<20> buf;
if (aError == KErrNone)
{
buf.Format(KSortingComplete);
}
else
{
buf.Format(KSortingError, aError);
}
iTopLabel->SetTextL(KStartActionText);
iBottomLabel->SetTextL(buf);
DrawNow();
}
// Cancels the sort
void CActiveObjAppView::CancelSortL()
{
iActiveBubbleSorter->Cancel();
iIsSorting = EFalse;
iTopLabel->SetTextL(KStartActionText);
iBottomLabel->SetTextL(KSortingCancelled);
DrawNow();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -