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

📄 numericeditorform.cpp

📁 series60 应用程序开发的源代码 series60 应用程序开发的源代码
💻 CPP
字号:
/**
* 
* @brief Definition of CNumericEditorForm
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "NumericEditorForm.h"

// System includes
#include <aknnotewrappers.h>    // CAknWarningNote
#include <aknnumed.h>            // TValidationStatus
#include <aknnumedwin.h>        // CAknIntegerEdwin
#include <AknPopupFieldText.h>    // CAknPopupFieldText
#include <aknslider.h>            // CAknSlider
#include <avkon.hrh>            // Commands
#include <avkon.rsg>            // R_AVKON_FORM_MENUPANE
#include <eikedwin.h>            // CEikEdwin
#include <eikfpne.h>            // CEikFloatingPointEditor
#include <eikmenup.h>            // CEikMenuPane
#include <NumericEditor.rsg>    // Resources
#include <stringloader.h>        // StringLoader

// CONSTANTS

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

/**
* Symbian OS 2 phase constructor.
* Constructs the CNumericEditorForm using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
* 
* @return The newly constructed CNumericEditorForm
*/
CNumericEditorForm* CNumericEditorForm::NewL(TNumericEditorEmployee& aEmployee,
    TBool &aSaveState)
{
    CNumericEditorForm* self = new (ELeave) CNumericEditorForm(aEmployee, aSaveState);
    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 iEmployee.
* @return TBool ETrue if the form data has been saved, EFalse otherwise
*/
TBool CNumericEditorForm::SaveFormDataL()
{
    iSaveState = EFalse;
    CEikEdwin* nameEditor = static_cast<CEikEdwin*>(ControlOrNull(ENumericEditorDlgCIdEdwin));

    if (nameEditor)
    {
        HBufC* name = nameEditor->GetTextInHBufL();
        if (name)
        {
            iEmployee.SetName (*name);
            delete name;
        }
    }

    CAknIntegerEdwin* ageEditor = static_cast<CAknIntegerEdwin*>(ControlOrNull(ENumericEditorDlgCIdIntegerEdwin));

    if (ageEditor)
    {
        TInt age = 0;
        CAknNumericEdwin::TValidationStatus ageStatus = ageEditor->GetTextAsInteger(age);

        switch (ageStatus)
        {
            case CAknNumericEdwin::EValueValid:
            {
                iEmployee.SetAge(age);
                break;
            }
            case CAknNumericEdwin::EValueTooSmall:
            {
                CAknWarningNote* note = new (ELeave) CAknWarningNote();
                HBufC* text = StringLoader::LoadLC(R_NUMERICEDITOR_AGE_TOO_SMALL_TEXT, iCoeEnv);
                note->ExecuteLD(*text);
                CleanupStack::PopAndDestroy(text);
                return EFalse;
                break;
            }
            case CAknNumericEdwin::EValueTooLarge:
            {
                CAknWarningNote* note = new (ELeave) CAknWarningNote();
                HBufC* text = StringLoader::LoadLC(R_NUMERICEDITOR_AGE_TOO_LARGE_TEXT, iCoeEnv);
                note->ExecuteLD(*text);
                CleanupStack::PopAndDestroy(text);
                return EFalse;
                break;
            }
            case CAknNumericEdwin::EValueNotParsed:
            {
                CAknWarningNote* note = new (ELeave) CAknWarningNote();
                HBufC* text = StringLoader::LoadLC(R_NUMERICEDITOR_AGE_NOT_PARSED_TEXT, iCoeEnv);
                note->ExecuteLD(*text);
                CleanupStack::PopAndDestroy(text);
                return EFalse;
                break;
            }
            case CAknNumericEdwin::EEmpty:
            {
                CAknWarningNote* note = new (ELeave) CAknWarningNote();
                HBufC* text = StringLoader::LoadLC(R_NUMERICEDITOR_AGE_EMPTY_TEXT, iCoeEnv);
                note->ExecuteLD(*text);
                CleanupStack::PopAndDestroy(text);
                return EFalse;
                break;
            }
            default:
                return EFalse;
                break;
        }
    }
    
    CEikFixedPointEditor* salaryEditor = static_cast<CEikFixedPointEditor*>(ControlOrNull(ENumericEditorDlgCIdFxPtEd));

    if (salaryEditor)
    {
        TInt salary = 0;
        CAknNumericEdwin::TValidationStatus salaryStatus = salaryEditor->GetValueAsInteger(salary);

        switch (salaryStatus)
        {
            case CAknNumericEdwin::EValueValid:
            {
                iEmployee.SetSalary(salary);
                break;
            }
            case CAknNumericEdwin::EValueTooSmall:
            {
                CAknWarningNote* note = new (ELeave) CAknWarningNote();
                HBufC* text = StringLoader::LoadLC(R_NUMERICEDITOR_SALARY_TOO_SMALL_TEXT, iCoeEnv);
                note->ExecuteLD(*text);
                CleanupStack::PopAndDestroy(text);
                return EFalse;
                break;
            }
            case CAknNumericEdwin::EValueTooLarge:
            {
                CAknWarningNote* note = new (ELeave) CAknWarningNote();
                HBufC* text = StringLoader::LoadLC(R_NUMERICEDITOR_SALARY_TOO_LARGE_TEXT, iCoeEnv);
                note->ExecuteLD(*text);
                CleanupStack::PopAndDestroy(text);
                return EFalse;
                break;
            }
            case CAknNumericEdwin::EValueNotParsed:
            {
                CAknWarningNote* note = new (ELeave) CAknWarningNote();
                HBufC* text = StringLoader::LoadLC(R_NUMERICEDITOR_SALARY_NOT_PARSED_TEXT, iCoeEnv);
                note->ExecuteLD(*text);
                CleanupStack::PopAndDestroy(text);
                return EFalse;
                break;
            }
            case CAknNumericEdwin::EEmpty:
            {
                CAknWarningNote* note = new (ELeave) CAknWarningNote();
                HBufC* text = StringLoader::LoadLC(R_NUMERICEDITOR_SALARY_EMPTY_TEXT, iCoeEnv);
                note->ExecuteLD(*text);
                CleanupStack::PopAndDestroy(text);
                return EFalse;
                break;
            }
            default:
                return EFalse;
                break;
        }
    }
    iSaveState = ETrue;
    return ETrue;
}



/**
* Sets the forms contols using the values contained in iEmployee. Called when the form is 
* executed and when the user chooses to discard changes in QuerySaveChangesL (via DoNotSaveFormDataL).
*/
void CNumericEditorForm::LoadFormValuesFromDataL()
{
    CEikEdwin* nameEditor = static_cast<CEikEdwin*>(ControlOrNull(ENumericEditorDlgCIdEdwin));

    if (nameEditor)
    {
        HBufC* name = iEmployee.Name().AllocLC();
        nameEditor->SetTextL(name);
        CleanupStack::PopAndDestroy(name);
    }

    CAknIntegerEdwin* ageEditor = static_cast<CAknIntegerEdwin*>(ControlOrNull(ENumericEditorDlgCIdIntegerEdwin));

    if (ageEditor)
    {
        ageEditor->SetValueL(iEmployee.Age());
    }
    
    CEikFixedPointEditor* salaryEditor = static_cast<CEikFixedPointEditor*>(ControlOrNull(ENumericEditorDlgCIdFxPtEd));

    if (salaryEditor)
    {
        TInt salary = iEmployee.Salary();
        salaryEditor->SetValueL(&salary);
    }
}

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


/**
* Called by the framework after the form has been sized and laid out, but before it has been 
* activated. 
* Loads the form values from iEmployee ready for execution of the form
*/
void CNumericEditorForm::PostLayoutDynInitL()
{
    CAknForm::PostLayoutDynInitL();
    LoadFormValuesFromDataL();
}


/**
* Constructs the editor form
* @param aEmployee to be populated
* @param aSaveState state if there was a succesful save.
*/
CNumericEditorForm::CNumericEditorForm (TNumericEditorEmployee& aEmployee,TBool &aSaveState) :
    iEmployee(aEmployee), iSaveState (aSaveState)
{
    iSaveState = EFalse;
}


/**
* 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 CNumericEditorForm::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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -