📄 gridcontainer.cpp
字号:
/*
* ============================================================================
* Name : CGridContainer from CCoeControl, MCoeControlObserver
* Part of : MyHello
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <MyHello.rsg>
#include "MyHello.hrh"
#include "GridContainer.h"
#include <akngrid.h> //for Grid
#include "common.h"
#include "MyHelloAppUi.h"
#include <e32base.h> //for CArrayPtr
#include <AknIconArray.h> //for CAknIconArray
#include <AknLists.h> //for AknListBoxLayouts
// ================= MEMBER FUNCTIONS =======================
// C++ default constructor can NOT contain any code, that
// might leave.
//
CGridContainer::CGridContainer()
{
m_pGrid = NULL;
}
// EPOC default constructor can leave.
void CGridContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
//---begin-for-Grid----------------------
m_pGrid = new( ELeave ) CAknGrid;
m_pGrid->SetContainerWindowL( *this );
m_pGrid->ConstructL( this, EAknListBoxSelectionGrid );
m_pGrid->SetEmptyGridTextL(_L("empty"));
// set layout
m_pGrid->SetRect(aRect.Size());
// set initial params for the grid
m_pGridType = EAknExGridSelectionGrid;
iVerticalOrientation = EFalse;
iTopToBottom = ETrue;
iLeftToRight = ETrue;
iNumOfColumns = 3;
iNumOfRows = 3;
iContentType = EContainGraphic;
iNumOfItems = 9;
iVerticalScrollingType = CAknGridView::EScrollIncrementLineAndLoops;
iHorizontalScrollingType = CAknGridView::EScrollIncrementLineAndLoops;
iSizeOfItems.iWidth = ( aRect.iBr.iX - aRect.iTl.iX ) / iNumOfColumns;
iSizeOfItems.iHeight = ( aRect.iBr.iY - aRect.iTl.iY ) / iNumOfRows;
m_pGrid->SetLayoutL( iVerticalOrientation, iLeftToRight, iTopToBottom,
iNumOfColumns, iNumOfRows, iSizeOfItems );
m_pGrid->SetPrimaryScrollingType( iHorizontalScrollingType );
m_pGrid->SetSecondaryScrollingType( iVerticalScrollingType );
//load data
LoadGraphicsL();
AddDataL();
iInstantsCreated = ETrue;
// activate the grid
m_pGrid->SetCurrentDataIndex(0);
m_pGrid->MakeVisible( ETrue );
m_pGrid->SetFocus( ETrue );
m_pGrid->ActivateL();
m_pGrid->DrawNow();
//---end-for-Grid-------------------------
SetRect(aRect);
ActivateL();
}
// Destructor
CGridContainer::~CGridContainer()
{
MEM_FREE(m_pGrid);
}
// ---------------------------------------------------------
// CGridContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CGridContainer::FocusTo(TInt aCommand)
{
}
// ---------------------------------------------------------
// CGridContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CGridContainer::SizeChanged()
{
}
// ---------------------------------------------------------
// CGridContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CGridContainer::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CGridContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CGridContainer::ComponentControl(TInt aIndex) const
{
//return NULL;
return m_pGrid;
}
// ---------------------------------------------------------
// CGridContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CGridContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbGray);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CGridContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CGridContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent, TEventCode aType)
{
//return EKeyWasNotConsumed;
if (NULL != m_pGrid)
{
return m_pGrid->OfferKeyEventL(aKeyEvent, aType);
}
else
{
return EKeyWasNotConsumed;
}
}
// ---------------------------------------------------------
// CGridContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CGridContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
//for Grid
void CGridContainer::LoadGraphicsL()
{
CMyHelloAppUi* pApp = (CMyHelloAppUi*)CEikonEnv::Static()->AppUi();
CArrayPtr< CGulIcon >* icons = new(ELeave) CAknIconArray(iNumOfItems);
CleanupStack::PushL( icons );
// Create icon bitmap and mask.
if ( m_pGridType == EAknExGridSelectionGrid )
{
icons->AppendL(pApp->LoadGraphicsL(1));
icons->AppendL(pApp->LoadGraphicsL(1));
icons->AppendL(pApp->LoadGraphicsL(1));
icons->AppendL(pApp->LoadGraphicsL(0));
icons->AppendL(pApp->LoadGraphicsL(0));
icons->AppendL(pApp->LoadGraphicsL(0));
icons->AppendL(pApp->LoadGraphicsL(1));
icons->AppendL(pApp->LoadGraphicsL(1));
icons->AppendL(pApp->LoadGraphicsL(1));
}
// Set icon array.
m_pGrid->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
CleanupStack::Pop(); // icons array
}
void CGridContainer::AddDataL()
{
MDesCArray* array = m_pGrid->Model()->ItemTextArray();
CDesCArray* cArray = ( CDesCArray* )array;
TBuf<32> sBuf;
//SMS
sBuf.Copy(_L("0\t"));
sBuf.Append(_L("abc"));
cArray->AppendL(sBuf);
//PHB
sBuf.Copy(_L("1\t"));
sBuf.Append(_L("abc"));
cArray->AppendL(sBuf);
//Account
sBuf.Copy(_L("2\t"));
sBuf.Append(_L("abc"));
cArray->AppendL(sBuf);
//SMS
sBuf.Copy(_L("3\t"));
sBuf.Append(_L("abc"));
cArray->AppendL(sBuf);
//PHB
sBuf.Copy(_L("4\t"));
sBuf.Append(_L("abc"));
cArray->AppendL(sBuf);
//Account
sBuf.Copy(_L("5\t"));
sBuf.Append(_L("abc"));
cArray->AppendL(sBuf);
//SMS
sBuf.Copy(_L("6\t"));
sBuf.Append(_L("abc"));
cArray->AppendL(sBuf);
//PHB
sBuf.Copy(_L("7\t"));
sBuf.Append(_L("abc"));
cArray->AppendL(sBuf);
//Account
sBuf.Copy(_L("8\t"));
sBuf.Append(_L("abc"));
cArray->AppendL(sBuf);
//const CFont* fontText = ApacPlain12();
m_pGrid->HandleItemAdditionL();
ApplySelGridGraphicStyleL();
}
void CGridContainer::ApplySelGridGraphicStyleL()
{
if (!m_pGrid)
{
return;
}
AknListBoxLayouts::SetupStandardGrid( *m_pGrid );
const CFont* fontText = ApacPlain12();
TInt nX = (m_pGrid->ColumnWidth() - 24) / 2;
TInt nY = (m_pGrid->ItemHeight() - 24 - fontText->HeightInPixels()) / 2;
AknListBoxLayouts::SetupFormGfxCell(
*m_pGrid,
m_pGrid->ItemDrawer(),
0,
nX,
nY,
0,
0,
24,
24,
TPoint( nX, nY ),
TPoint( 24+nX, 24+nY) );
// layout of text
AknListBoxLayouts::SetupFormAntiFlickerTextCell(
*m_pGrid,
m_pGrid->ItemDrawer(),
1,
fontText,
215,
0,
0,
24+nY+fontText->HeightInPixels(),
m_pGrid->ColumnWidth(),
CGraphicsContext::ECenter,
TPoint( 0, 24+nY),
TPoint( m_pGrid->ColumnWidth(), m_pGrid->ItemHeight()) );
DrawNow();
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -