📄 shoppinglistappview.cpp
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */
// INCLUDE FILES
#include <coemain.h>
#include "ShoppingListAppView.h"
#include "ShoppingListDocument.h"
#include "ShoppingItem.h"
#include "ShoppingList.pan"
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CShoppingListAppView::NewL()
// ---------------------------------------------------------
//
CShoppingListAppView* CShoppingListAppView::NewL( const TRect& aRect,
CShoppingListDocument* aDocument )
{
CShoppingListAppView* self = CShoppingListAppView::NewLC( aRect, aDocument );
CleanupStack::Pop( self );
return self;
}
// ---------------------------------------------------------
// CShoppingListAppView::NewLC()
// ---------------------------------------------------------
//
CShoppingListAppView* CShoppingListAppView::NewLC( const TRect& aRect,
CShoppingListDocument* aDocument )
{
CShoppingListAppView* self = new ( ELeave ) CShoppingListAppView( aDocument );
CleanupStack::PushL( self );
self->ConstructL( aRect );
return self;
}
// ---------------------------------------------------------
// CShoppingListAppView::CShoppingListAppView()
// Constructor
// ---------------------------------------------------------
//
CShoppingListAppView::CShoppingListAppView( CShoppingListDocument* aDocument )
: iDocument( aDocument )
{
// No implementation needed
}
// ---------------------------------------------------------
// CShoppingListAppView::~CShoppingListAppView()
// Destructor
// ---------------------------------------------------------
//
CShoppingListAppView::~CShoppingListAppView()
{
delete iListBox;
iListBox = NULL;
if( iListBoxRows )
{
iListBoxRows->Reset();
}
delete iListBoxRows;
iListBoxRows= NULL;
}
// ---------------------------------------------------------
// CShoppingListAppView::ConstructL()
// 2nd phase constructor.
// ---------------------------------------------------------
//
void CShoppingListAppView::ConstructL( const TRect& aRect )
{
CreateWindowL();
SetRect( aRect );
iListBox = new ( ELeave ) CAknSingleStyleListBox;
iListBox->ConstructL( this, 0 );
iListBox->SetContainerWindowL( *this );
iListBox->SetRect( aRect.Size() );
iListBoxRows = new ( ELeave ) CDesCArrayFlat( KGranularityOfArray );
iListBox->Model()->SetItemTextArray( iListBoxRows );
iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
iListBox->ActivateL();
iListBox->CreateScrollBarFrameL( ETrue );
iListBox->ScrollBarFrame()
->SetScrollBarVisibilityL( CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto );
ActivateL();
MakeVisible( ETrue );
}
// ---------------------------------------------------------
// CShoppingListAppView::UpdateL()
// ---------------------------------------------------------
//
void CShoppingListAppView::UpdateL()
{
iListBoxRows->Reset();
if( iDocument->ItemCount() > 0 )
{
for( TInt i = 0; i < iDocument->ItemCount(); ++i )
{
CShoppingItem* item = iDocument->Item( i );
HBufC* row;
if( item->Flags() & CShoppingItem::EMarked )
{
row = PrependLC( KMark(), *( item->Name() ) );
}
else
{
row = PrependLC( KTab(), *( item->Name() ) );
}
iListBoxRows->AppendL( row->Des() );
CleanupStack::PopAndDestroy( row );
}
iListBox->HandleItemAdditionL();
}
else
{
iListBox->HandleItemRemovalL();
}
}
// ---------------------------------------------------------
// CShoppingListAppView::PrependLC()
// ---------------------------------------------------------
//
HBufC* CShoppingListAppView::PrependLC( const TDesC& aString1, TDesC& aString2 )
{
HBufC* result = HBufC::NewMaxLC( aString1.Length() + aString2.Length() );
TPtr resultDes = result->Des();
resultDes = aString1;
resultDes.Append( aString2 );
return result;
}
// ---------------------------------------------------------
// CShoppingListAppView::CurrentItemIndex()
// ---------------------------------------------------------
//
TInt CShoppingListAppView::CurrentItemIndex() const
{
return iListBox->CurrentItemIndex();
}
// ---------------------------------------------------------
// CShoppingListAppView::SetCurrentItemIndex()
// ---------------------------------------------------------
//
void CShoppingListAppView::SetCurrentItemIndex( TInt aIndex )
{
iListBox->SetCurrentItemIndex( aIndex );
}
// ---------------------------------------------------------
// CShoppingListAppView::Draw()
// ---------------------------------------------------------
//
void CShoppingListAppView::Draw( const TRect& /*aRect*/ ) const
{
CWindowGc& gc = SystemGc();
TRect rect = Rect();
gc.Clear( rect );
}
// ---------------------------------------------------------
// CShoppingListAppView::CountComponentControls()
// ---------------------------------------------------------
//
TInt CShoppingListAppView::CountComponentControls() const
{
return 1; // Only have one Component
}
// ---------------------------------------------------------
// CShoppingListAppView::ComponentControl()
// ---------------------------------------------------------
//
CCoeControl* CShoppingListAppView::ComponentControl( TInt aIndex ) const
{
if( aIndex > 0 )
{
Panic( EShoppingListView );
}
return iListBox;
}
// ---------------------------------------------------------
// CShoppingListAppView::OfferKeyEventL()
// ---------------------------------------------------------
//
TKeyResponse CShoppingListAppView::OfferKeyEventL( const TKeyEvent& aKeyEvent,
TEventCode aType )
{
return iListBox->OfferKeyEventL( aKeyEvent, aType );
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -