📄 viewmanagerdialog.cpp
字号:
/**
*
* @brief Definition of CViewManagerDialog
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class include
#include "ViewManagerDialog.h"
// System includes
#include <aknappui.h> // iAvkonAppUi
#include <avkon.hrh> // EAknSoftkeyBack, EEikCmdExit
#include <AknPopupFieldText.h> // CAknPopupFieldText
#include <barsread.h> // TResourceReader
#include <ViewManager.rsg> // R_VIEWMANAGER_VIEWLIST_ARRAY
// User includes
#include "ViewManager.hrh"
#include "ViewManagerAppUi.h" // CViewManagerAppUi
// Constants
const TInt KDefaultView = 0;
const TInt KDefaultArrayGranularity = 3;
// ================= MEMBER FUNCTIONS =======================
/**
* Symbian OS 2 phase constructor.
* Constructs the CViewManagerDialog 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 CViewManagerDialog
*/
CViewManagerDialog* CViewManagerDialog::NewL()
{
CViewManagerDialog* self = CViewManagerDialog::NewLC();
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CViewManagerDialog 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 CViewManagerDialog
*/
CViewManagerDialog* CViewManagerDialog::NewLC()
{
CViewManagerDialog* self = new (ELeave) CViewManagerDialog();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* Symbian OS 2nd phase constructor. Creates a Window for the controls, which it contains.
* Constructs a label and adds it to the window, which it then activates.
* @param aRect The rectangle for this window
*/
void CViewManagerDialog::ConstructL()
{
iAppNames = new (ELeave) CDesCArrayFlat(KDefaultArrayGranularity);
iViewText = new (ELeave) CDesCArrayFlat(KDefaultArrayGranularity);
iAppUi = static_cast<CViewManagerAppUi*>(iAvkonAppUi);
}
/**
* C++ constructor
*/
CViewManagerDialog::CViewManagerDialog()
{
}
/**
* Destructor
*/
CViewManagerDialog::~CViewManagerDialog()
{
delete iAppNames;
delete iViewText;
delete iNamesValueTextArray;
delete iNamesValueText;
delete iViewValueTextArray;
delete iViewValueText;
iViewListId.Close();
}
/**
* Called by the framework when a button is pressed.
* @param aButtonId The index of the button which was pressed
*/
TBool CViewManagerDialog::OkToExitL(TInt aButtonId)
{
if (aButtonId == EAknSoftkeySelect)
{
// Set the id of the view to switched
// in the appUI and then calls the relevent command
iViewId = iViewValueText->CurrentValueIndex();
iAppUi->SetViewIndex(iViewId);
iAppUi->HandleCommandL(iCommand);
}
else if (aButtonId == EAknSoftkeyExit)
{
iAppUi->ProcessCommandL(EEikCmdExit);
}
return EFalse;
}
/**
* From CEikdialog, this function is called by the EIKON dialog framework
* just before the dialog is activated. Initializes the dialog dynamically
*/
void CViewManagerDialog::PreLayoutDynInitL()
{
LoadApplicationListArrayL();
LoadApplicationViewArrayL(KDefaultView);
}
/**
* Called by the framework whenever a key event occurs.
* Passes the key event to base class of the dialog 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 CViewManagerDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
if (aKeyEvent.iScanCode == EStdKeyDevice3 && aType == EEventKeyDown)
{
CAknForm::ProcessCommandL(EAknFormCmdEdit);
}
return CAknForm::OfferKeyEventL(aKeyEvent, aType);
}
/**
* Called by the framework, when the state of a control
* changes. Calls LoadApplicationViewArrayL to fill the
* pop-up views listbox for the relevent app.
* @param aControlId id of relevent control
*/
void CViewManagerDialog::HandleControlStateChangeL(TInt aControlId)
{
switch (aControlId)
{
case EViewManagerDlgCtrlIdApplications:
{
// A different application has been selected,
// so display the list of available views
TInt applicationIndex = iNamesValueText->CurrentValueIndex();
LoadApplicationViewArrayL(applicationIndex);
break;
}
default:
// do nothing
break;
}
CAknForm::HandleControlStateChangeL(aControlId);
}
/**
* Reads the list of applications from a resource file
* and fills the arrays used to populate the dialogs
* query list box. It also stores the resource id of
* the list of views for an application. Is only called the
* once by PreLayoutDynInitL()
*/
void CViewManagerDialog::LoadApplicationListArrayL()
{
// Open the resource file
TResourceReader reader;
// CreateResourceReaderLC sets a TResourceReader's buffer to a HBufC which
// the required resource has been read into.
iEikonEnv->CreateResourceReaderLC(reader, R_VIEWMANAGER_VIEWLIST_ARRAY);
// read the number of applications
const TInt count = reader.ReadInt16();
for (TInt ii = 0; ii < count; ++ii)
{
// read the applications name
iAppNames->AppendL(reader.ReadTPtrC());
// read the id of the resoucre file contains the list of views
iViewListId.Append(reader.ReadInt32());
}
CleanupStack::PopAndDestroy(); // reader's HBufC buffer, allocated using CreateResourceReaderLC
// Set-up the text array, and set the dialog listbox
iNamesValueTextArray = CAknQueryValueTextArray::NewL();
iNamesValueTextArray->SetArray(*iAppNames);
iNamesValueText = CAknQueryValueText::NewL();
iNamesValueText->SetArrayL(iNamesValueTextArray);
iNamesValueText->SetCurrentValueIndex(NULL);
// Control returns the dialogs pop-up name selection control, or it panics
CAknPopupField* popupNames = STATIC_CAST(CAknPopupField*, Control(EViewManagerDlgCtrlIdApplications));
popupNames->SetQueryValueL(iNamesValueText);
}
/**
* Reads the list of views for an application from a resource file
* and fills the arrays used to populate the dialogs
* query list box
*/
void CViewManagerDialog::LoadApplicationViewArrayL(TInt aIndex)
{
iViewText->Reset();
TResourceReader reader;
// open the resource containing the list of views
TInt resourceId = iViewListId[aIndex];
// CreateResourceReaderLC sets a TResourceReader's buffer to a HBufC which
// the required resource has been read into.
iEikonEnv->CreateResourceReaderLC(reader, resourceId);
// read the command to switch to the relevent application
iCommand = reader.ReadInt16();
const TInt count = reader.ReadInt16();
for (TInt ii = 0; ii < count; ++ii)
{
// read the text describing the view
iViewText->AppendL(reader.ReadTPtrC());
}
CleanupStack::PopAndDestroy(); // reader's HBufC buffer, allocated using CreateResourceReaderLC
// Set-up the text array, and set the dialog listbox
delete iViewValueTextArray;
iViewValueTextArray = 0;
delete iViewValueText;
iViewValueText = 0;
iViewValueTextArray = CAknQueryValueTextArray::NewL();
iViewValueText = CAknQueryValueText::NewL();
iViewValueTextArray->SetArray(*iViewText);
iViewValueText->SetArrayL(iViewValueTextArray);
iViewValueText->SetCurrentValueIndex(NULL);
// Control returns the dialogs pop-up view selection control, or it panics
CAknPopupField* popupViews = STATIC_CAST(CAknPopupField*, Control(EViewManagerDlgCtrlIdViews));
popupViews->SetQueryValueL(iViewValueText);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -