📄 simplelistcontainer.cpp
字号:
/**
*
* @brief Definition of CSimpleListContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class include
#include "SimpleListContainer.h"
// System includes
#include <akniconarray.h> // CAknIcon
#include <aknlists.h> // CAknSingleStyleListBox
#include <barsread.h> // TResource Reader
#include <eikclbd.h> // CColumnListBoxData
#include <eikmenub.h> // CEikMenuBar
#include <SimpleList.mbg> // icons
#include <SimpleList.rsg> // R_SIMPLELIST_SAVED_GAMES_LISTBOX
#include <stringloader.h> // StringLoader
#include <uikon.hrh> // TKeyCode #defines
#include <aknnotewrappers.h>
// CONSTANTS
const TInt KNumberOfIcons(2);
// N.B. #define'd as DLL cannot contain writeable static data
#define KListPosition TPoint(0,0)
// ================= MEMBER FUNCTIONS =======================
/**
* 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 CSimpleListContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
// Create the list
CreateListL();
// Observe the list
iSavedGamesListBox->SetListBoxObserver(this);
// Set the icons in the list's drawer
SetupListIconsL();
// Set up scroll bars
SetupScrollBarsL();
SetRect(aRect);
ActivateL();
}
/**
* Constructs the iSavedGamesList, setting its window.
*/
void CSimpleListContainer::CreateListL()
{
// First phase construction
iSavedGamesListBox = new (ELeave) CAknSingleGraphicStyleListBox;
iSavedGamesListBox->SetContainerWindowL(*this);
// Second Phase Construction
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC(reader, R_SIMPLELIST_SAVED_GAMES_LISTBOX);
iSavedGamesListBox->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // reader
}
/**
* Creates vertical scrollbars for the list, which appear automatically when required.
*/
void CSimpleListContainer::SetupScrollBarsL()
{
iSavedGamesListBox->CreateScrollBarFrameL(ETrue);
iSavedGamesListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
}
/**
* Loads icons from a file and sets them in the drawer for iSavedGamesList
*/
void CSimpleListContainer::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, EMbmSimplelist1player, EMbmSimplelist1player_mask));
icons->AppendL(iEikonEnv->CreateIconL(*iconFileName, EMbmSimplelist2player, EMbmSimplelist1player_mask));
CleanupStack::Pop(icons);
CleanupStack::PopAndDestroy(iconFileName);
iSavedGamesListBox->ItemDrawer()->ColumnData()->SetIconArray(icons); // passing ownership of icons
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CSimpleListContainer 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 CSimpleListContainer
*/
CSimpleListContainer* CSimpleListContainer::NewL(const TRect& aRect)
{
CSimpleListContainer* self = CSimpleListContainer::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CSimpleListContainer 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 CSimpleListContainer
*/
CSimpleListContainer* CSimpleListContainer::NewLC(const TRect& aRect)
{
CSimpleListContainer* self = new (ELeave) CSimpleListContainer;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
/**
* Destructor. Frees up memory for the iLabel.
*/
CSimpleListContainer::~CSimpleListContainer()
{
delete iSavedGamesListBox;
}
/**
*
* Called by framework when the view size is changed. Resizes the
* iLabel accordingly.
*
*/
void CSimpleListContainer::SizeChanged()
{
iSavedGamesListBox->SetExtent (KListPosition, iSavedGamesListBox->MinimumSize());
}
/**
* Called by the framework in compound controls
* @return The number of controls in this CSimpleListContainer
*/
TInt CSimpleListContainer::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* CSimpleListContainer::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0:
return iSavedGamesListBox;
default:
return NULL;
}
}
/**
* Called by the framework to draw this control. Clears the area in
* aRect.
* @param aRect in which to draw
*/
void CSimpleListContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear(aRect);
}
/**
* Called by the framework whenever a key event occurs.
* Passes the key event to the saved games 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 CSimpleListContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
if (iSavedGamesListBox)
return iSavedGamesListBox->OfferKeyEventL (aKeyEvent, aType);
else
return EKeyWasNotConsumed;
}
/**
* Plays the currently select game in the iSavedGamesListBox, if one exists.
* This is an empty implementation of this method
*/
void CSimpleListContainer::PlaySelectedGame()
{
CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
informationNote->ExecuteLD( _L("TEST") );
}
/**
* Called by the framework whenever a list event occurs for which this container
* is an observer.
* @param aListBoxEvent The type of event which occured
*
*/
void CSimpleListContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aListBoxEvent)
{
// if the Select Key has been pressed
if (aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed)
{
PlaySelectedGame();
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -