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

📄 settingslistsample.cpp

📁 Symbian系统
💻 CPP
字号:
#include "SettingsListSample.h"
#include "SLIDlg.hrh"
#include <SLIDlg.rsg>

#include <EikEdwin.h>
#include <AknDialog.h>
#include <aknsettingitemlist.h> 

_LIT(KModule, "SettingListSample.cpp");

// This is the derived CAknSettingItemList that
// provides the functionality to create the 
// items for the settings list, see the CreateSettingItemL
// implementation for what this does and now it binds the
// instance variables (iText1 and iText2) to the
// settings item.
class CSettingItemList : public CAknSettingItemList
{
public:
	CSettingItemList();
	
	virtual CAknSettingItem* CreateSettingItemL(TInt aIdentifier);
		
	TBuf<32>			iText1;
	TBuf<32>			iText2;
	
	CSettingItemList*	iSettingsList;
};

// This is the constuctor for the settings item list.
// This just initializes the data for the settings item list.
// In practise you will not store data in the list, but link it
// to your document or model.
// This is just an example and its designed to be simple and
// encapsulted in one file!
CSettingItemList::CSettingItemList()
{
	_LIT(KItem1, "Item 1");
	
	iText1 = KItem1;
	
	// we leave the second item blank so it will display "none"	
}

// This is the main function to create editors for each item
// in the settings item list.
// You need to look at the identifier and then create an appropriate
// setting item editor for the item
CAknSettingItem* CSettingItemList::CreateSettingItemL(TInt aIdentifier)
{
	CAknSettingItem* settingitem = NULL;
	
	switch (aIdentifier)
	{
		case ESLIText1:
		{
			settingitem = new (ELeave) CAknTextSettingItem(aIdentifier, iText1);
		}
		break;
		case ESLIText2:
		{
			settingitem = new (ELeave) CAknTextSettingItem(aIdentifier, iText2);
		}
		break;
	}
	
	return settingitem;
}

// This is the dialog that implements the functionality to provide
// the integration of the settings into the dialog.
//
// When the dialog is created, the control type is passed to CreateCustomControlL
// which is then used to create an instance of the CSettingItemListDlg, 
// it will be at this point you would bind any data in the dialog to the settings
// dialog class.
//
// Next ConvertCustomControlTypeToBaseControlType allows the dialog to pass events
// and perform correct processing and handling of command and events to the
// settings item list.

// Finally the OkToExitL is called when the user presses one of the soft key, in
// which case we check to see which key was pressed and perform the approporiate 
// action. Here if the select key was pressed we edit the item, otherwise
// if the cancel button was pressed we cancel the dialog, otherwise if the
// Ok button in the middle of the 5 way nav was pressed we close the dialog
// and save the changes
class CSettingItemListDlg : public CAknDialog
{
	public:
	
		virtual SEikControlInfo CreateCustomControlL(TInt aControlType);
		virtual CSettingItemListDlg::TFormControlTypes ConvertCustomControlTypeToBaseControlType(TInt aControlType) const;

		virtual void PostLayoutDynInitL();
		
		virtual TBool OkToExitL(TInt aButtonId);
		
	protected:
		CSettingItemList*	iSettingsList;
};

// This function is cheating a little bit. We automatically assume if we are
// getting called then we are the only custom control on the form so
// we create a new instance without checking.
// In practise you will need to look at the control type and construct the
// correct control.
// If you have a dialog/form with additional
// lines in it or multiple custom controls then you will need to examine the
// control type and create the appropriate control based on the control type.
SEikControlInfo CSettingItemListDlg::CreateCustomControlL(TInt aControlType)
{
	__ASSERT_ALWAYS(aControlType == EAknCtLastControlId, User::Panic(KModule, KErrArgument));
	
	iSettingsList = new (ELeave) CSettingItemList;
	
	SEikControlInfo controlInfo;
	controlInfo.iFlags = EEikControlHasEars;
	controlInfo.iTrailerTextId = 0;
	controlInfo.iControl = iSettingsList;
	STATIC_CAST(CSettingItemList*, controlInfo.iControl)->SetContainerWindowL(*this);
	
	return controlInfo;
}

// This function also cheats in that it automatically assumes that the only dialog control that
// needs to return how it works is the list item control. If your dialog has other custom controls
// you will need to alter this accordingly to return the correct class based on the type of control.
// This function tells the dialog manager that the custom control behaves like a popup field.
// It is essential that this function is defined as it is used extensivly when laying out and
// interacting with controls via the dialog manager.
CSettingItemListDlg::TFormControlTypes CSettingItemListDlg::ConvertCustomControlTypeToBaseControlType(TInt aControlType) const
{
	__ASSERT_ALWAYS(aControlType == EAknCtLastControlId, User::Panic(KModule, KErrArgument));

	return EPopfieldDerived;
}

// This safely loads the dialog with the data
void CSettingItemListDlg::PostLayoutDynInitL()
{
	_LIT(KItem2, "Item 2 data");
	iSettingsList->iText2 = KItem2;
	iSettingsList->LoadSettingsL();
}

// This function will handle what is happened when a menu button is pressed. This will be either
// the left or right soft key buttons or it will be the ok button in the middle of the 5 way nave
// buttons.
// Here we check the type of button that was pressed and perform the appropriate action:
// Select button: We just get the current item and start editing it.
// Cancel button: We cancel editing of the data.
// Ok button    : We save the changes and then close the dialog box. 
TBool CSettingItemListDlg::OkToExitL(TInt aButtonId)
{
	if (aButtonId == EAknSoftkeySelect)
	{
		// we could use iSettingsList but this shows another way of doing it
		CSettingItemList* settingslist = (CSettingItemList*)Control(ESLIList);
		const TInt current = settingslist->ListBox()->CurrentItemIndex();
		iSettingsList->EditItemL(current, ETrue);
	}

	if (aButtonId == EAknSoftkeyCancel)
		return ETrue;
		
	if (aButtonId == EAknSoftkeyOk)
	{
		iSettingsList->StoreSettingsL();
		return ETrue;
	}

	return EFalse;
}

// This is the entry point function. This is where the dialog is created which in turn creates
// the setting items list and allows editing of the items in the list.
void EditSettings()
{
	CSettingItemListDlg* dlg = new (ELeave)CSettingItemListDlg();
	
	dlg->ExecuteLD(R_SETTINGITEMLIST_DIALOG);
}

⌨️ 快捷键说明

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