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

📄 numericeditorcontainer.cpp

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

// INCLUDE FILES

// Class include
#include "NumericEditorContainer.h"

// System includes
#include <akniconarray.h> 
#include <stringloader.h> 
#include <aknlists.h> // CAknSingleHeadingStyleListBox
#include <barsread.h> // TResourceReader
#include <NumericEditor.rsg> //R_NUMERICEDITOR_FORM, R_NUMERICEDITOR_EMPLOYEES_LISTBOX
#include <NumericEditor.mbg>
#include <e32def.h> // STATIC_CAST
#include <eikclbd.h> // CColumnListBoxData
#include <eikmenub.h> // CEikMenuBar
#include <stringloader.h> // StringLoader
#include <uikon.hrh> // 
#include <aknnotewrappers.h>
#include <eikslb.h> 
#include <eikrted.h>        // CEikRichTextEditor
#include <stringloader.h> 

// User includes
#include "NumericEditorForm.h"



// CONSTANTS

// N.B. #define'd as DLL cannot contain writeable static data
#define KListPosition TPoint(0,0) 
#define KLabelPosition TPoint(5,5)
const TInt KNumberOfIcons(4);


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

/**
* Symbian OS 2nd phase constructor.  Creates a Window for the controls, which it contains.
* Constructs a list and adds it to the window, which it then activates.
* @param aRect The rectangle for this window
*/		
void CNumericEditorContainer::ConstructL(const TRect& aRect)//itododb 没有用到,所以在ui的newlc中没有传进去,所以要用构造函数来初始化
	{
	CreateWindowL();
	
	iToDoList = new (ELeave) CAknSingleGraphicStyleListBox;
	iToDoList->SetContainerWindowL(*this);
	
	// Second Phase Construction
	TResourceReader reader;
	CEikonEnv::Static()->CreateResourceReaderLC(reader, R_NUMERICEDITOR_EMPLOYEES_LISTBOX);
	iToDoList->ConstructFromResourceL(reader);
	CleanupStack::PopAndDestroy(); // reader             
	
	iToDoList->CreateScrollBarFrameL(ETrue);
	iToDoList->ScrollBarFrame()->SetScrollBarVisibilityL(
		CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	
	iToDoDb.RestoreL();
	UpdateListBox();
	SetupListIconsL();
	//CreateLabel();
	//SetLabelText();
	//SetupScrollBarsL();
	SetRect(aRect);
	ActivateL();
	}

void CNumericEditorContainer::UpdateListBox()//没有显示列表数据,是因为没有写这个函数
	{
		CToDo* todo;
		//二部构造中被调用,simplelist中没有这个函数
		//把数据添加到model中,在把model中的数据放到array中
		CTextListBoxModel* model = iToDoList->Model();  // not taking ownership
		model->SetOwnershipType (ELbmOwnsItemArray); 
		CDesCArray* savedGamesArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
	//	LoadFormValuesFromDataL(*savedGamesArray);//调用下面的函数
		savedGamesArray->Reset();
		TInt count = iToDoDb.Count();
		for(TInt i = 0; i < iToDoDb.Count(); i++)//做了一个for循环把所建的todo一个加进去
			{
			 todo = iToDoDb.At(i);
			 savedGamesArray->AppendL (ListStringFromEmployeeL(*todo));
			iToDoList->HandleItemAdditionL();
			}

	}																																																																																																																																																																																																																																				

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

/**
* Symbian OS 2 phase constructor.
* Constructs the CNumericEditorContainer 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 CNumericEditorContainer
*/
CNumericEditorContainer* CNumericEditorContainer::NewLC(const TRect& aRect, CSynchToDoDb& aToDoDb)
	{
	CNumericEditorContainer* self = new (ELeave) CNumericEditorContainer( aToDoDb );
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	return self;
	}

/**
* Destructor. Frees up memory for the list and the array of employees.
*/
CNumericEditorContainer::~CNumericEditorContainer()
	{
	delete iToDoList;
//	delete iLabel;
	//iEmployees.Close();
	}


/**
*	
* Called by framework when the view size is changed.  Resizes the
* iEmployeesList accordingly.
*
*/
void CNumericEditorContainer::SizeChanged()
	{
	iToDoList->SetExtent (KListPosition, iToDoList->MinimumSize());
//	iLabel->SetExtent(KLabelPosition, iLabel->MinimumSize());
	}
/*
void CNumericEditorContainer::CreateLabel()
	{
	iLabel = new (ELeave) CEikLabel;
	iLabel->SetContainerWindowL(*this); 
	}
*/
/**
* Called by the framework in compound controls	
* @return The number of controls in this CNumericEditorContainer
*/
TInt CNumericEditorContainer::CountComponentControls() const
	{
	return 1; // return number of controls inside this container
	}

/**
* Called by the framework in compound controls	
* @param The index of the control to return
* @return The control for aIndex
*/
CCoeControl* CNumericEditorContainer::ComponentControl(TInt aIndex) const
	{
	switch (aIndex)
		{
		case 0:
			return iToDoList;
	//	case 1:
	//		return iLabel;
		default:
			return NULL;
		}
	}

/**
* Called by the framework to draw this control.  Clears the area in 
* aRect.
* @param aRect in which to draw
*/
void CNumericEditorContainer::Draw(const TRect& aRect) const
	{
	CWindowGc& gc = SystemGc();
	gc.Clear(aRect);
	}


void CNumericEditorContainer::SetupListIconsL()
	{
	// Get the name of the file containing the icons	
	HBufC* iconFileName;
	iconFileName = StringLoader::LoadLC(R_ICON_FILE_NAME);	// Pushes iconFileName onto the Cleanup Stack.
	
	// Create an array of icons, reading them from the file
	CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(KNumberOfIcons);
	CleanupStack::PushL(icons);
	//icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmNumericeditor1player,/*(mbg中自动生成的枚举值 )*/EMbmNumericeditor1player_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmNumericeditor2player, EMbmNumericeditor2player_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmNumericeditor3player, EMbmNumericeditor3player_mask));
	icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmNumericeditor4player, EMbmNumericeditor4player_mask));
	CleanupStack::Pop(icons);
	CleanupStack::PopAndDestroy(iconFileName);
	
	iToDoList->ItemDrawer()->ColumnData()->SetIconArray(icons); // passing ownership of icons
	}
/*
void CNumericEditorContainer::SetLabelText()
	{
		HBufC* labelText = StringLoader::LoadLC( R_LABEL_ALL_TEXT );
		//HBufC* labelText = iEikonEnv->AllocReadResourceLC( R_HEWB_LABEL_STRING );
		iLabel->SetTextL( *labelText );
		//DrawNow();
		//iLabel->Set
		CleanupStack::PopAndDestroy(labelText);
	}
*/	
/*
void CNumericEditorContainer::SetupScrollBarsL()
	{
	iToDoList->CreateScrollBarFrameL(ETrue);
	iToDoList->ScrollBarFrame()->SetScrollBarVisibilityL(
	CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	}
*/

/**
* Called by the framework whenever a key event occurs.	
* Passes the key event to the employees list if it is not null, otherwise returns
* EKeyWasNotConsumed
* @param aKeyEvent the Key event which occured, e.g. select key pressed
* @param aType the type of Key event which occurred, e.g. key up, key down
* @return TKeyResponse EKeyWasNotConsumed if the key was not processed, EKeyWasConsumed if it was
*/
TKeyResponse CNumericEditorContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	if (iToDoList)
		return iToDoList->OfferKeyEventL (aKeyEvent, aType);
	else
		return EKeyWasNotConsumed;
	}


/**
* Invokes the form in editable state, with a new opponenet, so that the details can be entered.
* Adds the Employee to the array of iEmployees and the list
*/
void CNumericEditorContainer::NewEmployeeL()
	{
	CToDo* todo = CToDo::NewLC(); //创建一个新的
	TBool saveState = EFalse;
	CNumericEditorForm* form = CNumericEditorForm::NewL(*todo, saveState);//创建form , 要加*原因是,创建的是CToDo的指针,newl传的是引用,所以加*进行转换
	form->ExecuteLD(R_NUMERICEDITOR_FORM_DIALOG);
	if (saveState)
		{
		AddEmployeeToListL(*todo);
		CleanupStack::Pop(todo);
		}
	else
		{
		iToDoList->DrawNow();
		CleanupStack::PopAndDestroy(todo);
		}
	}

/**
* Invokes the form in the view state, with the currently selected Employee so that the details 
* can be viewed and edited.
* Updates the Employee in the array of iEmployees and the list
*/
void CNumericEditorContainer::OpenEmployeeL()
	{
	TInt index=iToDoList->CurrentItemIndex();
	CToDo& todo = *iToDoDb[index];//??????为什么加*
	TBool saveState = EFalse;
	CNumericEditorForm* form = CNumericEditorForm::NewL(todo, saveState);
	form->ExecuteLD(R_NUMERICEDITOR_FORM_DIALOG);
	if (saveState)
		{
		UpdateEmployeeInListL (todo);
		iToDoDb.SaveL();
		}
	else
		{
		iToDoList->DrawNow();
		
		//CleanupStack::PopAndDestroy(todo);
		}
	}



/**
* If the Employee is valid, adds it to the array of iEmployees and updates the list
* of employees
* @param aEmployee reference to the Employee which should be added
*/
void CNumericEditorContainer::AddEmployeeToListL (CToDo& aToDo)
	{
		iToDoDb.AddToDoL(&aToDo);
		//iToDoDb.SaveL();
		
		CTextListBoxModel* model = iToDoList->Model();  // not taking ownership
		model->SetOwnershipType (ELbmOwnsItemArray);
		CDesCArray* itemArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
		itemArray->AppendL (ListStringFromEmployeeL(aToDo));
		iToDoList->HandleItemAdditionL();
	
	}

void CNumericEditorContainer::SearchToDoL()
	{
	
		TBuf<30> aSubject;
		TDateTime dateTime(2008,EJanuary,1,0,0,0,0);
		TTime time(dateTime);//刚开始不弹出对话框,是因为资源文件的问题,设置的是多行,下面的形式用的是单行
	    
		CAknMultiLineDataQueryDialog* dlg = CAknMultiLineDataQueryDialog::NewL(aSubject, time);//创建form , 要加*原因是,创建的是CToDo的指针,newl传的是引用,所以加*进行转换
		dlg->ExecuteLD(R_AKNEXQUERY_MULTI_LINE_DATA_AND_DATE_LAYOUT);
		if (iToDoDb.Find(aSubject) != KErrNone)
			{
			iToDoDb.Find(aSubject);
			iToDoList->CurrentItemIndex();
			}
			iToDoList->DrawNow();
		
	}

/**
* Extracts the information from aEmployee, for display in the list.
* @param aEmployee the Employee to get the information from
*/
TBuf<50> CNumericEditorContainer::ListStringFromEmployeeL (const CToDo& aToDo) const
	{
	TBuf<50> string; 
	TBuf<3> icons;
	_LIT (KStringHeader, "%d\t%S");
	switch ( aToDo.Priority() )
				{
			case 0:
				icons = _L("1");
			case 1:
				icons = _L("2");
				break;
		 	case 2:
		 		icons = _L("0");
				break;
			default:
				break;
				}
	
	HBufC* subject = aToDo.GetSubject().AllocLC();		
	string.Format(KStringHeader(), aToDo.Priority(),subject);	
	CleanupStack::PopAndDestroy(subject);
	return string;

	}


/**
* Updates the Employee in the array of iEmployees and updates the list
* of employees
* @param aEmployee reference to the employee which should be updated
*/
void CNumericEditorContainer::UpdateEmployeeInListL (CToDo& aToDo)
	{
	CTextListBoxModel* model = iToDoList->Model();  // not taking ownership
	model->SetOwnershipType (ELbmOwnsItemArray);
	CDesCArray* itemArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
	
	TInt index = iToDoList->CurrentItemIndex();
	
	itemArray->Delete(index);
	itemArray->InsertL(index, ListStringFromEmployeeL(aToDo));
	iToDoList->DrawNow();
	}

/**
* Deletes the currently selected Employee in the array of iEmployees and updates the list of employees
*/
void CNumericEditorContainer::DeleteEmployeeL()
	{
	
	CTextListBoxModel* model = iToDoList->Model();  // not taking ownership
	model->SetOwnershipType (ELbmOwnsItemArray);
	CDesCArray* itemArray = STATIC_CAST(CDesCArray*, model->ItemTextArray());
	
	TInt index = iToDoList->CurrentItemIndex();
	
	iToDoDb.RemoveToDo(index);
	itemArray->Delete(index);
	iToDoList->SetCurrentItemIndex(iToDoList->TopItemIndex());
	iToDoList->DrawNow();
	}

/**
* Returns the number of employees currently in the list
*/
TInt CNumericEditorContainer::NumberOfEmployees()
	{
	TInt numberOfEmployees = 0;
	
	if (iToDoList)
		numberOfEmployees = iToDoDb.Count();
	
	return numberOfEmployees;
	}

void CNumericEditorContainer::HandleListBoxEventL(CEikListBox*/* aListBox*/, TListBoxEvent aListBoxEvent)
	{
	//处理listbox的控件事件
	// if the Select Key has been pressed
	if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
		(aListBoxEvent == MEikListBoxObserver::EEventItemClicked))
		{
		//	PlaySelectedGame();
		}
	}

// End of File	

⌨️ 快捷键说明

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