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

📄 shoppinglistdocument.cpp

📁 Symbian 的购物程序 shoppinglist-vc
💻 CPP
字号:
/*  Copyright (c) 2004, Nokia. All rights reserved */

// INCLUDE FILES
#include "ShoppingListDocument.h"
#include "ShoppingListAppUi.h"
#include "ShoppingItem.h"

// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CShoppingListDocument::NewL()
// ---------------------------------------------------------
//
CShoppingListDocument* CShoppingListDocument::NewL( CEikApplication& aApp )
    {
    CShoppingListDocument* self = NewLC( aApp );
    CleanupStack::Pop( self );
    return self;
    }

// ---------------------------------------------------------
// CShoppingListDocument::NewLC()
// ---------------------------------------------------------
//
CShoppingListDocument* CShoppingListDocument::NewLC( CEikApplication& aApp )
    {
    CShoppingListDocument* self = new ( ELeave ) CShoppingListDocument( aApp );
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
    }

// ---------------------------------------------------------
// CShoppingListDocument::ConstructL()
// 2nd phase constructor.
// ---------------------------------------------------------
//
void CShoppingListDocument::ConstructL()
    {
    // No implementation required
    }    

// ---------------------------------------------------------
// CShoppingListDocument::CShoppingListDocument()
// Constructor
// ---------------------------------------------------------
//
CShoppingListDocument::CShoppingListDocument( CEikApplication& aApp ) 
: CAknDocument( aApp ) 
    {
    // No implementation required
    }

// ---------------------------------------------------------
// CShoppingListDocument::~CShoppingListDocument()
// Destructor
// ---------------------------------------------------------
//
CShoppingListDocument::~CShoppingListDocument()
    {
    iItemList.ResetAndDestroy();
    }

// ---------------------------------------------------------
// CShoppingListDocument::CreateAppUiL()
// ---------------------------------------------------------
//
CEikAppUi* CShoppingListDocument::CreateAppUiL()
    {
    return ( static_cast <CEikAppUi*>( new ( ELeave ) CShoppingListAppUi ) ); 
    }

// ---------------------------------------------------------
// CShoppingListDocument::StoreL()
// ---------------------------------------------------------
//
void CShoppingListDocument::StoreL( CStreamStore& aStore, 
                                    CStreamDictionary& aStreamDic ) const
    {
    RStoreWriteStream stream;

    TStreamId id = stream.CreateLC( aStore );

    TInt count = iItemList.Count();

    stream.WriteInt16L( static_cast<TInt16>( count ) );

    for ( TInt index = 0; index < count; ++index )
        {
        ( static_cast<CShoppingItem*>( iItemList[index] ) )->
                                                    ExternalizeL( stream );
        }
        stream.CommitL();

        aStreamDic.AssignL( Application()->AppDllUid(), id );
        CleanupStack::PopAndDestroy(); // stream
    }

// ---------------------------------------------------------
// CShoppingListDocument::RestoreL()
// ---------------------------------------------------------
//
void CShoppingListDocument::RestoreL( const CStreamStore& aStore, 
                                      const CStreamDictionary& aStreamDic )
    {
    TStreamId id = aStreamDic.At( Application()->AppDllUid() );
    RStoreReadStream stream;
    stream.OpenLC( aStore, id );

    TInt count = stream.ReadInt16L();
    for ( TInt index = 0; index < count; ++index )
        {
        CShoppingItem* item = CShoppingItem::NewL();
        CleanupStack::PushL( item );
        item->InternalizeL( stream );
        User::LeaveIfError( iItemList.Append( item ) );
        CleanupStack::Pop( item );
        }

    CleanupStack::PopAndDestroy();  // stream
    }

// ---------------------------------------------------------
// CShoppingListDocument::OpenFileL()
// ---------------------------------------------------------
//
CFileStore* CShoppingListDocument::OpenFileL( TBool aDoOpen, 
                                              const TDesC& aFilename, RFs& aFs )
    {
    return CEikDocument::OpenFileL( aDoOpen, aFilename, aFs );
    }

// ---------------------------------------------------------
// CShoppingListDocument::Item()
// ---------------------------------------------------------
//
CShoppingItem* CShoppingListDocument::Item( TInt aIndex )
    {
    CShoppingItem* item = static_cast<CShoppingItem*>( iItemList[aIndex] );
    return item;
    }

// ---------------------------------------------------------
// CShoppingListDocument::InsertItemL()
// ---------------------------------------------------------
//
void CShoppingListDocument::InsertItemL( CShoppingItem* aItem, TInt aIndex )
    {
    User::LeaveIfError( iItemList.Insert( aItem, aIndex )  );
    }

// ---------------------------------------------------------
// CShoppingListDocument::RemoveItem()
// ---------------------------------------------------------
//
void CShoppingListDocument::RemoveItem( TInt aIndex )
    {
    CShoppingItem* item = static_cast<CShoppingItem*>( iItemList[aIndex] );
    iItemList.Remove( aIndex );
    delete item;
    }

// ---------------------------------------------------------
// CShoppingListDocument::ItemCount()
// ---------------------------------------------------------
//
TInt CShoppingListDocument::ItemCount()
    {
    return iItemList.Count();
    }

// End of File

⌨️ 快捷键说明

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