opponentformform.cpp

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

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

// INCLUDE FILES

// Class include
#include "OpponentFormForm.h"

// System includes
#include <AknPopupFieldText.h> // CAknPopupFieldText
#include <aknslider.h> // CAknSlider
#include <avkon.hrh> // Commands
#include <avkon.rsg> // R_AVKON_FORM_MENUPANE
#include <eikedwin.h> // CEikEdwin
#include <eikmenup.h> // CEikMenuPane

// CONSTANTS


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

/**
* Symbian OS 2 phase constructor.
* Constructs the COpponentFormForm using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
* 
* @return The newly constructed COpponentFormForm
*/
COpponentFormForm* COpponentFormForm::NewL(TOpponentFormOpponent& aOpponent)
{
    COpponentFormForm* self = new (ELeave) COpponentFormForm(aOpponent);
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(self);
    return self;
}

/**
* Called by the framework whenver the 'Save' menu item is selected, and by the QuerySaveChangesL 
* method when the user answers yes to the save query.
* Saves the data from the forms controls, into the iOpponent.
* @return TBool ETrue if the form data has been saved, EFalse otherwise
*/
TBool COpponentFormForm::SaveFormDataL()
{
    CAknSlider* slider = static_cast <CAknSlider*> (ControlOrNull(EOpponentFormDlgCIdSlider));
    if (slider)
    {
        iOpponent.SetStrength (slider->Value());
    }
    
    
    CEikEdwin* nameEditor = static_cast <CEikEdwin*> (ControlOrNull(EOpponentFormDlgCIdEdwin));
    if (nameEditor)
    {
        HBufC* name = nameEditor->GetTextInHBufL();
        if (name)
        {
            iOpponent.SetName (*name);
            delete name;
        }
    }
    
    CAknPopupFieldText* popupFieldText = static_cast <CAknPopupFieldText*> (ControlOrNull(EOpponentFormDlgCIdPopup));
    if (popupFieldText)
    {
        HBufC* popupFieldValue = popupFieldText->CurrentValueTextLC();
        iOpponent.SetPower(*popupFieldValue);
        CleanupStack::PopAndDestroy (popupFieldValue);
        iOpponent.SetPowerIndex(popupFieldText->CurrentValueIndex());        
    }
    
    return ETrue;
}



/**
* Sets the forms contols using the values contained in iOpponent. Called when the form is 
* executed and when the user chooses to discard changes in QuerySaveChangesL (via DoNotSaveFormDataL).
*/
void COpponentFormForm::LoadFormValuesFromDataL()
{
    CAknSlider* slider = static_cast <CAknSlider*> (ControlOrNull(EOpponentFormDlgCIdSlider));
    if (slider)
    {
        slider->SetValueL (iOpponent.Strength());
    }
    
    
    CEikEdwin* nameEditor = static_cast <CEikEdwin*> (ControlOrNull(EOpponentFormDlgCIdEdwin));
    if (nameEditor)
    {
        HBufC* name = iOpponent.Name().AllocLC();
        nameEditor->SetTextL(name);
        CleanupStack::PopAndDestroy(name);
    }
    
    CAknPopupFieldText* popupFieldText = static_cast <CAknPopupFieldText*> (ControlOrNull(EOpponentFormDlgCIdPopup));
    if (popupFieldText)
    {
        popupFieldText->SetCurrentValueIndex (iOpponent.PowerIndex());
    }
}

/**
* Called by QuerySaveChangeL when the user chooses to discard changes made to the form.
* Loads the form values from iOpponent
*/
void COpponentFormForm::DoNotSaveFormDataL()
{
    LoadFormValuesFromDataL();
}


/**
* Called by the framework before the form is initialised
* Loads the form values from iOpponent ready for execution of the form
*/
void COpponentFormForm::PreLayoutDynInitL()
{
    CAknForm::PreLayoutDynInitL();
    LoadFormValuesFromDataL();
}


/**
* Called by the framework when a menu is displayed.
* Removes the default items from the options menu of the form for editing a fields label,
* adding a field and deleting a field
*/
void COpponentFormForm::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
{
    CAknForm::DynInitMenuPaneL(aResourceId,aMenuPane);
    
    if (aResourceId == R_AVKON_FORM_MENUPANE)
    {
        aMenuPane->SetItemDimmed(EAknFormCmdLabel, ETrue);
        aMenuPane->SetItemDimmed(EAknFormCmdAdd, ETrue);
        aMenuPane->SetItemDimmed(EAknFormCmdDelete, ETrue);
    }
}


// End of File    

⌨️ 快捷键说明

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