📄 mementomaincontainer.cpp
字号:
/*
* ============================================================================
* Name : CMementoMainContainer from CCoeControl, MCoeControlObserver
* Part of : MementoMain
* Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/
// INCLUDE FILES
#include <Memento.rsg>
#include "Memento.hrh"
#include "MementoMainContainer.h"
#include <aknnotewrappers.h>
#include <akngrid.h>
#include "MementoAppUi.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.
//
CMementoMainContainer::CMementoMainContainer()
{
m_pGrid = NULL;
}
// EPOC default constructor can leave.
void CMementoMainContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
TBuf<32> nTitle1;
CEikonEnv::Static()->ReadResource(nTitle1, R_ONE_VIEW);
//---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-------------------------
//LabelHelp
TBuf<32> chinese;
CEikonEnv::Static()->ReadResource(chinese, R_QTN_MH_GRID_HEPL);
ipLabelHelp = new(ELeave) CEikLabel;
ipLabelHelp->SetContainerWindowL(*this);
ipLabelHelp->SetTextL(chinese);
ipLabelHelp->SetExtent(TPoint(0,0),TSize(176,20));
ipLabelHelp->MakeVisible(EFalse);
//EditName
CEikonEnv::Static()->ReadResource(chinese, R_QTN_MH_GRID_HEPL_TXT1);
ipEditHelp = new(ELeave) CEikEdwin;
ipEditHelp->SetContainerWindowL(*this);
ipEditHelp->ConstructL(EAknEditorFlagDefault, 10, 10, 1);
ipEditHelp->SetExtent(TPoint(0,20), TSize(176,124));
ipEditHelp->SetTextL(&chinese);
ipEditHelp->SetReadOnly(ETrue);
ipEditHelp->SetBackgroundColorL(KRgbDarkBlue);
ipEditHelp->MakeVisible(EFalse);
SetRect(aRect);
ActivateL();
}
// Destructor
CMementoMainContainer::~CMementoMainContainer()
{
MEM_FREE(m_pGrid);
MEM_FREE(ipEditHelp);
MEM_FREE(ipLabelHelp);
}
// ---------------------------------------------------------
// CMementoMainContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CMementoMainContainer::FocusTo(TInt aCommand)
{
}
// ---------------------------------------------------------
// CMementoMainContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CMementoMainContainer::SizeChanged()
{
}
// ---------------------------------------------------------
// CMementoMainContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CMementoMainContainer::CountComponentControls() const
{
return 3; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CMementoMainContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CMementoMainContainer::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0:
{
return ipEditHelp;
break;
}
case 1:
{
return ipLabelHelp;
break;
}
case 2:
{
return m_pGrid;
break;
}
default:
{
return NULL;
break;
}
};
}
// ---------------------------------------------------------
// CMementoMainContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CMementoMainContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbDarkMagenta);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CMementoMainContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CMementoMainContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent, TEventCode aType)
{
if (aType == EEventKey && aKeyEvent.iCode == EKeyDevice3)
{
if (0 == GetItem())
{
// ((CMementoAppUi*)CEikonEnv::Static()->AppUi())->GetDirPtr()->changeMenu();
((CMementoAppUi*)CEikonEnv::Static()->AppUi())->ActivateLocalViewL(KViewId2);
}
else
{
// _LIT(message,"building..");
// CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
// informationNote->ExecuteLD(message);
TBuf<32> chinese;
CEikonEnv::Static()->ReadResource(chinese, R_QTN_MH_GRID_TITLE2);
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(chinese);
}
}
if (NULL != m_pGrid)
{
return m_pGrid->OfferKeyEventL(aKeyEvent, aType);
}
else
{
return EKeyWasNotConsumed;
}
}
// ---------------------------------------------------------
// CMementoMainContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CMementoMainContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}
// End of File
void CMementoMainContainer::LoadGraphicsL()
{
CMementoAppUi* pApp = (CMementoAppUi*)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(0));
icons->AppendL(pApp->LoadGraphicsL(1));
icons->AppendL(pApp->LoadGraphicsL(2));
icons->AppendL(pApp->LoadGraphicsL(3));
icons->AppendL(pApp->LoadGraphicsL(4));
icons->AppendL(pApp->LoadGraphicsL(5));
icons->AppendL(pApp->LoadGraphicsL(6));
icons->AppendL(pApp->LoadGraphicsL(7));
icons->AppendL(pApp->LoadGraphicsL(8));
}
// Set icon array.
m_pGrid->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
CleanupStack::Pop(); // icons array
}
void CMementoMainContainer::AddDataL()
{
TBuf<32> title;
CEikonEnv::Static()->ReadResource(title, R_QTN_MH_GRID_TITLE1);
MDesCArray* array = m_pGrid->Model()->ItemTextArray();
CDesCArray* cArray = ( CDesCArray* )array;
TBuf<32> sBuf;
//SMS
sBuf.Copy(_L("0\t"));
sBuf.Append(title);
cArray->AppendL(sBuf);
//PHB
CEikonEnv::Static()->ReadResource(title, R_QTN_MH_GRID_TITLE2);
sBuf.Copy(_L("1\t"));
sBuf.Append(title);
cArray->AppendL(sBuf);
//Account
sBuf.Copy(_L("2\t"));
sBuf.Append(title);
cArray->AppendL(sBuf);
//SMS
sBuf.Copy(_L("3\t"));
sBuf.Append(title);
cArray->AppendL(sBuf);
//PHB
sBuf.Copy(_L("4\t"));
sBuf.Append(title);
cArray->AppendL(sBuf);
//Account
sBuf.Copy(_L("5\t"));
sBuf.Append(title);
cArray->AppendL(sBuf);
//SMS
sBuf.Copy(_L("6\t"));
sBuf.Append(title);
cArray->AppendL(sBuf);
//PHB
sBuf.Copy(_L("7\t"));
sBuf.Append(title);
cArray->AppendL(sBuf);
//Account
sBuf.Copy(_L("8\t"));
sBuf.Append(title);
cArray->AppendL(sBuf);
//const CFont* fontText = ApacPlain12();
m_pGrid->HandleItemAdditionL();
ApplySelGridGraphicStyleL();
}
void CMementoMainContainer::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();
}
TInt CMementoMainContainer::GetItem()
{
TInt currentIndex = m_pGrid->CurrentDataIndex();
// TPoint currentPos = m_pGrid->PositionAtIndex( currentIndex );
// TInt index = m_pGrid->IndexOfPosition( currentPos );
return currentIndex;
}
void CMementoMainContainer::setHelp(TBool aFlag)
{
ipEditHelp->MakeVisible(aFlag);
ipLabelHelp->MakeVisible(aFlag);
m_pGrid->MakeVisible(!aFlag);
}
CEikEdwin* CMementoMainContainer::GetEditHelpPtr()
{
return ipEditHelp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -