waitnotecontainer.cpp

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

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

// INCLUDE FILES

// Class include
#include "WaitNoteContainer.h"

// System includes
#include <aknnotedialog.h> // CAknWaitNoteWrapper
#include <waitnote.rsg>

// CONSTANTS
const TInt KNumberOfStepsToSaveGame(5);

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

/**
* Symbian OS 2nd phase constructor.  Creates a Window for the controls, which it contains.
* Constructs a label and adds it to the window, which it then activates.
* @param aRect The rectangle for this window
*/        
void CWaitNoteContainer::ConstructL(const TRect& aRect)
{
    iTimeWaster.CreateLocal();
    CreateWindowL();
    SetRect(aRect);
    ActivateL();
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CWaitNoteContainer 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 CWaitNoteContainer
*/
CWaitNoteContainer* CWaitNoteContainer::NewL(const TRect& aRect)
{
    CWaitNoteContainer* self = CWaitNoteContainer::NewLC(aRect);
    CleanupStack::Pop(self);
    return self;
}

/**
* Symbian OS 2 phase constructor.
* Constructs the CWaitNoteContainer 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 CWaitNoteContainer
*/
CWaitNoteContainer* CWaitNoteContainer::NewLC(const TRect& aRect)
{
    CWaitNoteContainer* self = new (ELeave) CWaitNoteContainer;
    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 CWaitNoteContainer::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.Clear(aRect);
}

/**
* Destructor. Frees up memory. 
*/
CWaitNoteContainer::~CWaitNoteContainer()
{
    iTimeWaster.Close();
}

/**
* Called by the AppUi when the Save Game command is invoked. 
* Constructs and executes the wait note wrapper. If the user cancels the note,
* it cancels the game save processing.
*/
void CWaitNoteContainer::SaveGameL()
{
    CAknWaitNoteWrapper* waitNoteWrapper = CAknWaitNoteWrapper::NewL();
    CleanupStack::PushL(reinterpret_cast<CBase*>(waitNoteWrapper)); // Required reinterpret_cast as CAknWaitNoteWrapper inherits privately from CActive
    if (! waitNoteWrapper->ExecuteL(R_WAITNOTE_SAVING_GAME_NOTE, *this)) // this is a blocking call, remember the wrapper isn't a dialog, so it doesn't need the EEikDialogFlagWait flag to make it blocking 
        CancelGameSave();
    CleanupStack::PopAndDestroy(waitNoteWrapper);
}
/**
* Called by the wait note wrapper when the note is dismissed. 
* This is as a result of either the user cancelling the note,
* or the process finishing.
*/
void CWaitNoteContainer::DialogDismissedL(TInt /*aButtonId*/)
{    
}

/**
* Called by the wait note wrapper following StepL. Unless the user has cancelled the note, 
* if this returns EFalse, it will call StepL again, otherwise, it will call ProcessFinished.
* @return ETrue if processing is complete, EFalse otherwise
*/
TBool CWaitNoteContainer::IsProcessDone() const
{
    return (iStepsCompleted == KNumberOfStepsToSaveGame);
}

/**
* Called by the wait note wrapper if the process is complete or if the user cancelled the note.
* Completes the game save and resets the steps completed counter.
*/
void CWaitNoteContainer::ProcessFinished()
{
        CompleteGameSave();
        iStepsCompleted = 0;
}

/**
* Called by the wait note wrapper if the processing is not yet complete. 
* Completes a step in the processing, by saving part of the game to a file, and incrementing the
* number of steps completed. This is a synchronous method.
*/
void CWaitNoteContainer::StepL()
{
    SaveGamePartToFile();

    // Note that we have completed a step
    iStepsCompleted++;
}

/**
* Dummy method which could be used to cancel a partially saved game, e.g.
* by resetting values and deleting the partially created file.
*/
void CWaitNoteContainer::CancelGameSave()
{
}

/**
* Dummy method which could be used to save part of a game to a file
* In this example, it runs a timer for an arbitrary period of time
* to simulate saving part of the game. This is a synchronous method.
*/
void CWaitNoteContainer::SaveGamePartToFile ()
{
    // Use an arbitrary delay to simulate saving part of the game
    TRequestStatus status;
    TInt delay = 1000000; // 1 second
    iTimeWaster.After(status, delay);
    User::WaitForRequest(status); 
}

/**
* Dummy method which could be used to complete the game saving process, e.g. by closing
* the saved game file.
* In this example it stops the timer used to simulate a game save.
*/
void CWaitNoteContainer::CompleteGameSave()
{
    iTimeWaster.Cancel();
}


//End of File    

⌨️ 快捷键说明

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