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

📄 shoppinglistappview.cpp

📁 为symbian7.0c操作系统series60系列开发的购物软件
💻 CPP
字号:
/* Copyright (c) 2003, Nokia. All rights reserved */

#include <coemain.h>

#include "ShoppingListAppView.h"
#include "ShoppingListDocument.h"
#include "ShoppingItem.h"
#include "ShoppingList.pan"

const TInt KGranularityOfArray = 10;

CShoppingListAppView* CShoppingListAppView::NewL(const TRect& aRect, CShoppingListDocument* aDocument)
    {
    CShoppingListAppView* self = CShoppingListAppView::NewLC(aRect, aDocument);
    CleanupStack::Pop(self);
    return self;
    }

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

CShoppingListAppView::CShoppingListAppView( CShoppingListDocument* aDocument ) : iDocument( aDocument )
    {
	// No implementation needed
    }

CShoppingListAppView::~CShoppingListAppView()
    {
	delete iListBox;
	iListBox = NULL;

	if( iListBoxRows )
		{
		iListBoxRows->Reset();
		}
	delete iListBoxRows;
	iListBoxRows= NULL;
    }

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);
    }

void CShoppingListAppView::UpdateL()
    {
	_LIT(KTab,"\t");
	_LIT(KMark,"|\t");

	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();
		}
	}


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;
	}


TInt CShoppingListAppView::CurrentItemIndex() const
	{
	return iListBox->CurrentItemIndex();
	}


void CShoppingListAppView::SetCurrentItemIndex( TInt aIndex )
	{
	iListBox->SetCurrentItemIndex( aIndex );
	}


void CShoppingListAppView::Draw(const TRect& /*aRect*/) const
    {
    CWindowGc& gc = SystemGc();
    TRect rect = Rect();
    gc.Clear(rect);
    }


TInt CShoppingListAppView::CountComponentControls() const
    {
    return 1; // Only have one Component
    }


CCoeControl* CShoppingListAppView::ComponentControl(TInt aIndex) const
    {
	if( aIndex > 0 )
		{
		Panic(EShoppingListView);
		}
    return iListBox;
    }

TKeyResponse CShoppingListAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
    {
    return iListBox->OfferKeyEventL(aKeyEvent, aType);
    }

⌨️ 快捷键说明

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