📄 selegridcontainer.cpp
字号:
/*
* ============================================================================
* Name : CSeleGridContainer from SeleGridContainer.h
* Part of : SeleGrid
* Created : 16.03.2006 by ToBeReplacedByAuthor
* Implementation notes:
* Initial content was generated by Series 60 Application Wizard.
* Version :
* Copyright: ToBeReplacedByCopyright
* ============================================================================
*/
// INCLUDE FILES
#include <apgcli.h> // for RApaLsSession
#include <eikapp.h> // for CEikApplication
#include <akniconarray.h> // for CAknIconArray
#include <aknlists.h> // for CAknGrid
#include <SeleGrid.mbg> // for EMbmSelegridPinb1
#include <SeleGrid.rsg>
#include <aknsconstants.hrh> // for EAknsMajorCalendar
#include "SeleGridContainer.h"
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CSeleGridContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CSeleGridContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
// Create the grid
iGrid = new(ELeave) CAknPinbStyleGrid;
iGrid->SetContainerWindowL(*this);
iGrid->ConstructL(this, EAknListBoxSelectionGrid);
iGrid->SetListBoxObserver(this);
// Add items
CTextListBoxModel* model = iGrid->Model();
CDesCArray* array = static_cast<CDesCArray*>(model->ItemTextArray());
_LIT(KItemFormat, "%d\t\t");
TBuf<32> item;
TInt i=0;
for(i=0; i<3; i++)
{
item.Format(KItemFormat(), i);
array->AppendL(item);
}
// Create an array of icons, reading them from the file
CEikonEnv* eikonEnv = CEikonEnv::Static();
TFileName mbmFile = eikonEnv->EikAppUi()->Application()->BitmapStoreName();
CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(3);
CleanupStack::PushL(icons);
icons->AppendL(eikonEnv->CreateIconL(mbmFile, EMbmSelegridPinb1, EMbmSelegridPinbm1));
icons->AppendL(eikonEnv->CreateIconL(mbmFile, EMbmSelegridPinb2, EMbmSelegridPinbm2));
icons->AppendL(eikonEnv->CreateIconL(mbmFile, EMbmSelegridPinb3, EMbmSelegridPinbm3));
CleanupStack::Pop(icons);
// Transfer ownership
iGrid->ItemDrawer()->FormattedCellData()->SetIconArray(icons);
SetRect(aRect);
ActivateL();
}
// Destructor
CSeleGridContainer::~CSeleGridContainer()
{
delete iGrid;
}
// New methods
TInt CSeleGridContainer::RecordCount()
{
return iGrid->Model()->NumberOfItems();
}
void CSeleGridContainer::DeleteRecordL()
{
CTextListBoxModel* model = iGrid->Model();
CDesCArray* array = static_cast<CDesCArray*>(model->ItemTextArray());
TInt index = iGrid->CurrentItemIndex();
if(index>=0)
{
array->Delete(index);
AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(iGrid, index, ETrue);
}
}
// ---------------------------------------------------------
// CSeleGridContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CSeleGridContainer::SizeChanged()
{
iGrid->SetRect(Rect());
// Apply layout
TRAPD(err, iGrid->SetLayoutL(ETrue, ETrue, ETrue, 5, 5, TSize(33,28)));
}
// ---------------------------------------------------------
// CSeleGridContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CSeleGridContainer::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CSeleGridContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CSeleGridContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iGrid;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CSeleGridContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CSeleGridContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
// TODO: Add your drawing code here
// example code...
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGray );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}
// ---------------------------------------------------------
// CSeleGridContainer::OfferKeyEventL()
// @param aKeyEvent Event to handled.
// @param aType Type of the key event.
// @return Response code (EKeyWasConsumed, EKeyWasNotConsumed).
// ---------------------------------------------------------
//
TKeyResponse CSeleGridContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
return iGrid->OfferKeyEventL(aKeyEvent, aType);
}
// ---------------------------------------------------------
// CSeleGridContainer::HandleListBoxEventL(
// CEikListBox* aListBox, TListBoxEvent aListBoxEvent)
// ---------------------------------------------------------
//
void CSeleGridContainer::HandleListBoxEventL(CEikListBox*/*aListBox*/, TListBoxEvent aListBoxEvent)
{
if((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
(aListBoxEvent == MEikListBoxObserver::EEventItemClicked)) // for emulator
{
switch(iGrid->CurrentItemIndex())
{
case 0: // Calendar application
{
const TUid KAppUid = { 0x10005901 };
const TUid KViewUid = { 0x01 }; // Month view
CEikonEnv::Static()->EikAppUi()->ActivateViewL(TVwsViewId(KAppUid, KViewUid));
break;
}
case 1: // Message application
{
const TUid KAppUid = { 0x100058C5 };
const TUid KViewUid = { 0x02 }; // Show folder
const TUid KMsgUid = { 0x1002 }; // Inbox folder
CEikonEnv::Static()->EikAppUi()->ActivateViewL(TVwsViewId(KAppUid, KViewUid), KMsgUid, KNullDesC8);
break;
}
case 2:
{
RApaLsSession session;
User::LeaveIfError(session.Connect());
CleanupClosePushL(session);
_LIT(KNotepad, "z:\\system\\apps\\notepad\\notepad.app");
CApaCommandLine* cmd = CApaCommandLine::NewLC();
cmd->SetLibraryNameL(KNotepad());
cmd->SetCommandL(EApaCommandCreate);
User::LeaveIfError(session.StartApp(*cmd));
CleanupStack::PopAndDestroy(2); // cmd, session
break;
}
default:
{
break;
}
}
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -