listquerycontainer.cpp

来自「series60 应用程序开发的源代码 series60 应用程序开发的源代码」· C++ 代码 · 共 134 行

CPP
134
字号
/**
* 
* @brief Definition of CListQueryContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "ListQueryContainer.h"

// System includes
#include <aknquerydialog.h> // CAknQueryDialog
#include <listquery.rsg> // resources
#include <stringloader.h> // StringLoader

// User includes
#include "listquery.hrh" // constants

// CONSTANTS
const TInt KMaxSavedGames(4);

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

/**
* Symbian OS 2nd phase constructor.  Creates and activates it.
* Sets up the list query item array.
* @param aRect The rectangle for this window
*/        
void CListQueryContainer::ConstructL(const TRect& aRect)
{
    SetupListQueryItemArrayL();
    CreateWindowL();
    SetRect(aRect);
    ActivateL();
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CListQueryContainer using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
* 
* @param aRect The rectangle for this window
* @return The newly constructed CListQueryContainer
*/
CListQueryContainer* CListQueryContainer::NewL(const TRect& aRect)
{
    CListQueryContainer* self = CListQueryContainer::NewLC(aRect);
    CleanupStack::Pop(self);
    return self;
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CListQueryContainer using the constructor and ConstructL 
* method, leaving the constructed object on the CleanupStack before returning it.
* 
* @param aRect The rectangle for this window
* @return The newly constructed CListQueryContainer
*/
CListQueryContainer* CListQueryContainer::NewLC(const TRect& aRect)
{
    CListQueryContainer* self = new (ELeave) CListQueryContainer;
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
}
/**
* Called by the framework to draw this control.  Clears the area in 
* aRect.
* @param aRect in which to draw
*/
void CListQueryContainer::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.Clear(aRect);
}

/**
* Called by the AppUi when Exit is selected from the Options menu.
* Queries whether to save the game. If yes, then queries the name for the 
* saved game from a list of predefined names and saves the game to file.
*/
void CListQueryContainer::SaveGameL()
{
    CAknQueryDialog* saveGameQuery = CAknQueryDialog::NewL();    
    if (saveGameQuery->ExecuteLD(R_LISTQUERY_CONFIRMATION_QUERY))
    {
        TInt index(0); // the index of the selected item
        CAknListQueryDialog* query = new (ELeave) CAknListQueryDialog(&index);
        query->PrepareLC(R_LISTQUERY_LIST_QUERY);
        query->SetItemTextArray(iListQueryItemArray);    
        query->SetOwnershipType (ELbmDoesNotOwnItemArray); // keep ownership of the item array. Only call this after setting the item array!
        if (query->RunLD())
        {
            SaveGameToFileL((*iListQueryItemArray)[index]); // use the name of the currently selected item as the file name. 
        }
    }
}

/**
* Called on construction. Instantiates the list query item array and populates
* it with appropriate list items. This method merely creates some list items dynamically, and adds them
* to the array.  In a real-world application, it is likely that the 
* items would be read from a file   
*/
void CListQueryContainer::SetupListQueryItemArrayL()
{
    iListQueryItemArray =  new (ELeave) CDesCArrayFlat(KMaxSavedGames);
    _LIT (KStringHeader, "Saved Game %d");
    TBuf <16> aString;
    for (TInt i = 1; i<= KMaxSavedGames; i++)
    {
        aString.Format(KStringHeader(), i);
        iListQueryItemArray->AppendL (aString);
    }
}

/** 
* Destructor.  Frees up memory for the list query item array.
*/
CListQueryContainer::~CListQueryContainer()
{
    if (iListQueryItemArray)
    {
        iListQueryItemArray->Reset();
        delete iListQueryItemArray;
    }
}

//End of File    

⌨️ 快捷键说明

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