📄 contextmenucontainer.cpp
字号:
/**
*
* @brief Definition of CContextMenuContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class include
#include "ContextMenuContainer.h"
// System includes
#include <aknlists.h> // CAknSingleStyleListBox
#include <barsread.h> // TResource Reader
#include <eikmenub.h> // CEikMenuBar
#include <ContextMenu.rsg> // R_CONTEXTMENU_SAVED_GAMES_LISTBOX
#include <uikon.hrh> // TKeyCode #defines
// CONSTANTS
// 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 CContextMenuContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iSavedGamesListBox = new (ELeave) CAknSingleStyleListBox;
iSavedGamesListBox->SetContainerWindowL(*this);
TResourceReader reader;
CEikonEnv::Static()->CreateResourceReaderLC(reader, R_CONTEXTMENU_SAVED_GAMES_LISTBOX);
iSavedGamesListBox->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // reader
SetRect(aRect);
ActivateL();
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CContextMenuContainer 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 CContextMenuContainer
*/
CContextMenuContainer* CContextMenuContainer::NewL(const TRect& aRect)
{
CContextMenuContainer* self = CContextMenuContainer::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CContextMenuContainer 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 CContextMenuContainer
*/
CContextMenuContainer* CContextMenuContainer::NewLC(const TRect& aRect)
{
CContextMenuContainer* self = new (ELeave) CContextMenuContainer;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
/**
* Destructor. Frees up memory for the iLabel.
*/
CContextMenuContainer::~CContextMenuContainer()
{
delete iSavedGamesListBox;
}
/**
*
* Called by framework when the view size is changed. Resizes the
* iLabel accordingly.
*
*/
void CContextMenuContainer::SizeChanged()
{
iSavedGamesListBox->SetExtent (KListPosition, iSavedGamesListBox->MinimumSize());
}
/**
* Called by the framework in compound controls
* @return The number of controls in this CContextMenuContainer
*/
TInt CContextMenuContainer::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* CContextMenuContainer::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 CContextMenuContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear(aRect);
}
/**
* Called by the framework whenever a key event occurs.
* If the select key is pressed, displays a context-sensitive menu, otherwise passes the key event
* to the saved games list
* @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
*/
TKeyResponse CContextMenuContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
// If the Select Key (OK key in emulator) is pressed, show the context sensitive menu
TBool selectKeyPressed = (aType == EEventKey) && (aKeyEvent.iCode == EKeyOK);
TBool savedGameListNotEmpty = (iSavedGamesListBox) && (iSavedGamesListBox->Model()->NumberOfItems() > 0);
if (selectKeyPressed && savedGameListNotEmpty)
{
// get the menu bar from the parent of this control.
CEikMenuBar* parentMenuBar = iEikonEnv->AppUiFactory()->MenuBar();
// Set the menu bar to the context-sensitive menu bar
parentMenuBar->SetMenuTitleResourceId(R_CONTEXTMENU_SAVED_GAMES_MENU_BAR);
// try to display the context sensitive menu bar
if (parentMenuBar)
{
parentMenuBar->TryDisplayMenuBarL();
}
// change the menu bars resource to the normal menu bar so that the left softkey displays
// the correct menu
parentMenuBar->SetMenuTitleResourceId(R_CONTEXTMENU_MENU_BAR);
return EKeyWasConsumed;
}
// Otherwise, offer the key to the listbox to process.
else
return iSavedGamesListBox->OfferKeyEventL (aKeyEvent, aType);
}
/**
* Deletes the currently select game in the iSavedGamesListBox, if one exists.
*/
void CContextMenuContainer::DeleteSelectedGameL()
{
if (iSavedGamesListBox)
{
CTextListBoxModel* model = iSavedGamesListBox->Model();
if (model->NumberOfItems() > 0)
{
MDesCArray* itemList = model->ItemTextArray();
CDesCArray* itemArray = STATIC_CAST(CDesCArray*, itemList);
TInt currentItem = iSavedGamesListBox->CurrentItemIndex();
itemArray->Delete(currentItem);
AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(iSavedGamesListBox,
currentItem,
ETrue );
iSavedGamesListBox->DrawNow();
}
}
}
/**
* Plays the currently select game in the iSavedGamesListBox, if one exists.
* This is an empty implementation of this method
*/
void CContextMenuContainer::PlaySelectedGame()
{
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -