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

📄 numericeditorform.cpp

📁 symbian手机上记事本的程序
💻 CPP
字号:
/**
* 
* @brief Definition of CNumericEditorForm
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "NumericEditorForm.h"
#include "NumericEditor.hrh"

// 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(CToDo& aToDo,TBool &aSaveState)
	{
	CNumericEditorForm* self = new (ELeave) CNumericEditorForm(aToDo, 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* personEditor = static_cast<CEikEdwin*>(ControlOrNull(100));

	if (personEditor)
		{
		HBufC* person = personEditor->GetTextInHBufL();
		if (person)
			{
			iToDo.SetPerson(*person);
			delete person;
			}
		}

	CAknSlider* priority = static_cast<CAknSlider*>(ControlOrNull(EPriorityId));
	
	if(priority)
		{
		iToDo.SetPriority(priority->Value());
		}
	
	CAknPopupFieldText*  alarmFieldText = static_cast<CAknPopupFieldText*>(ControlOrNull(EAlarm));
	
	if(alarmFieldText)
		{
		TInt16  alarm = alarmFieldText->CurrentValueIndex();
		iToDo.SetAlarm(alarm);		
		}
	
	CEikEdwin* subjectEditor = static_cast<CEikEdwin*>(ControlOrNull(ESubject));
	if(subjectEditor)
		{
		HBufC* subject =  subjectEditor->GetTextInHBufL();
		if(subject)
			{
			iToDo.SetSubject(*subject);
			delete subject;
			}
		}
	
	CEikEdwin* locationEditor = static_cast<CEikEdwin*>(ControlOrNull(ELocation));
	if(locationEditor)
		{
		HBufC* location = locationEditor->GetTextInHBufL();
		if(location)
			{
			iToDo.SetLocation(*location);
			delete location;
			}
		}
	
	CEikEdwin* commentsEditor = static_cast<CEikEdwin*>(ControlOrNull(EComments));
	if(commentsEditor)
		{
		HBufC* comments = commentsEditor->GetTextInHBufL();
		if(comments)
			{
			iToDo.SetComments(*comments);
			delete comments;
			}
		}
	
	CEikDateEditor* dateEditor = static_cast<CEikDateEditor*>(ControlOrNull(EAknExEditorIDForFormDate));
	if (dateEditor)// 这里会自动提示最大还是最小,所以不用进行判断
		{
		TTime date = dateEditor->Date();
		iToDo.SetDate(date.DateTime());
		}

	CEikTimeEditor* timeEditor = static_cast<CEikTimeEditor*>(ControlOrNull(EAknExEditorIDForFormTime));
	if (timeEditor)
		{
		TTime time = timeEditor->Time();
		iToDo.SetTime(time.DateTime());
		}
	
	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* personEditor = static_cast<CEikEdwin*>(ControlOrNull(100));

	if (personEditor)
		{
		HBufC* person = iToDo.Person().AllocLC();
		personEditor->SetTextL(person);
		CleanupStack::PopAndDestroy(person);
		}
	
	CEikEdwin* subjectEditor = static_cast<CEikEdwin*>(ControlOrNull(ESubject));
	if(subjectEditor)
		{
		HBufC* subject = iToDo.GetSubject().AllocLC();//若get函数返回的是指针类型的话,那就用->,如果是引用的话才是.
		subjectEditor->SetTextL(subject);
		CleanupStack::PopAndDestroy(subject);
		}
	
	CEikEdwin* locationEditor = static_cast<CEikEdwin*>(ControlOrNull(ELocation));
	if(locationEditor)
		{
		HBufC* location = iToDo.Location().AllocLC();
		locationEditor->SetTextL(location);
		CleanupStack::PopAndDestroy(location);
		}
	
	CEikEdwin* commentsEditor = static_cast<CEikEdwin*>(ControlOrNull(EComments));
	if(commentsEditor)
		{
		HBufC* comments = iToDo.Comments().AllocLC();
		commentsEditor->SetTextL(comments);
		CleanupStack::PopAndDestroy(comments);
		}
	
	CAknSlider* priority = static_cast<CAknSlider*>(ControlOrNull(EPriorityId));
	if(priority)
		{
		priority->SetValueL(iToDo.Priority());
		}
	
	CAknPopupFieldText*  alarmEditor = static_cast<CAknPopupFieldText*>(ControlOrNull(EAlarm));
		if(alarmEditor)
			{
			alarmEditor->SetCurrentValueIndex(iToDo.Alarm());
			}
	CEikDateEditor* dateEditor = static_cast<CEikDateEditor*>(ControlOrNull(EAknExEditorIDForFormDate));
//	TDateTime date(2008, EJune, 0, 9, 29, 12, 0);
	if(dateEditor) 
		{
		TDateTime date = iToDo.Date();
		dateEditor->SetDate(TTime(date));
		}

	CEikTimeEditor* timeEditor = static_cast<CEikTimeEditor*>(ControlOrNull(EAknExEditorIDForFormTime));
//	TDateTime time(2008, EJune, 0, 9, 29, 12, 0);
	if(timeEditor) 
		{
		TDateTime time = iToDo.Time();
		timeEditor->SetTime(TTime(time));
		}
	}

/**
* 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 (CToDo& aToDo,TBool &aSaveState) :
	iToDo(aToDo), 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 + -