⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fungridcontainer.cpp

📁 symbian系统上的记事本程序
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CFunGridContainer from CCoeControl, MCoeControlObserver
*  Part of  : Hello
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES


#include <EveryDay.rsg>
#include "EveryDay.hrh"
#include "FunGridContainer.h"

#include "common.h"
#include "EveryDayappui.h"

#include <akngrid.h>	//for CAknGrid

#include <e32base.h>		//for CArrayPtr
#include <AknIconArray.h>	//for CAknIconArray
#include <AknLists.h>		//for AknListBoxLayouts

#include <eiklabel.h>	//for CEikLabel
#include <eikedwin.h>	//for CEikEdit

#include <aknnotewrappers.h>
// ================= MEMBER FUNCTIONS =======================

// C++ default constructor can NOT contain any code, that
// might leave.
//
CFunGridContainer::CFunGridContainer()
{
	m_pGrid = NULL;
}

// EPOC default constructor can leave.
void CFunGridContainer::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
CFunGridContainer::~CFunGridContainer()
{
	MEM_FREE(m_pGrid);
}

// ---------------------------------------------------------
// CFunGridContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//

void CFunGridContainer::FocusTo(TInt aCommand)
{
}

// ---------------------------------------------------------
// CFunGridContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CFunGridContainer::SizeChanged()
{
}

// ---------------------------------------------------------
// CFunGridContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CFunGridContainer::CountComponentControls() const
{
	return 1; // return nbr of controls inside this container
}

// ---------------------------------------------------------
// CFunGridContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CFunGridContainer::ComponentControl(TInt aIndex) const
{
	return m_pGrid;
}

// ---------------------------------------------------------
// CFunGridContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CFunGridContainer::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbGreen);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
}

// ---------------------------------------------------------
// CFunGridContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CFunGridContainer::OfferKeyEventL(
											   const TKeyEvent& aKeyEvent, TEventCode aType)
{
	if (NULL != m_pGrid)
	{
		m_nIndex = m_pGrid->CurrentItemIndex();
		return m_pGrid->OfferKeyEventL(aKeyEvent, aType);
	}
	else
	{
		return EKeyWasNotConsumed;
	}
}


// ---------------------------------------------------------
// CFunGridContainer::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CFunGridContainer::HandleControlEventL(
											CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}


void CFunGridContainer::LoadGraphicsL()
{
	CEveryDayAppUi* pApp = (CEveryDayAppUi*)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 CFunGridContainer::AddDataL()
{
    MDesCArray* array = m_pGrid->Model()->ItemTextArray();
    CDesCArray* cArray = ( CDesCArray* )array;
	
	TBuf<32> sBuf;
	TBuf<32> sTxt;
	//SMS
	sBuf.Copy(_L("0\t"));
	CEikonEnv::Static()->ReadResource(sTxt,R_EVERYDAY_GRIDVIEW_001);
	sBuf.Append(sTxt);
	cArray->AppendL(sBuf);
	
	//PHB
	sBuf.Copy(_L("1\t"));
	CEikonEnv::Static()->ReadResource(sTxt,R_EVERYDAY_GRIDVIEW_002);
	sBuf.Append(sTxt);
	cArray->AppendL(sBuf);
	//Account
	sBuf.Copy(_L("2\t"));
	CEikonEnv::Static()->ReadResource(sTxt,R_EVERYDAY_GRIDVIEW_003);
	sBuf.Append(sTxt);
	cArray->AppendL(sBuf);
	//SMS
	sBuf.Copy(_L("3\t"));
	CEikonEnv::Static()->ReadResource(sTxt,R_EVERYDAY_GRIDVIEW_004);
	sBuf.Append(sTxt);
	cArray->AppendL(sBuf);
	//PHB
	sBuf.Copy(_L("4\t"));
	CEikonEnv::Static()->ReadResource(sTxt,R_EVERYDAY_GRIDVIEW_005);
	sBuf.Append(sTxt);
	cArray->AppendL(sBuf);
	//Account
	sBuf.Copy(_L("5\t"));
	CEikonEnv::Static()->ReadResource(sTxt,R_EVERYDAY_GRIDVIEW_006);
	sBuf.Append(sTxt);
	cArray->AppendL(sBuf);
	//SMS
	sBuf.Copy(_L("6\t"));
	CEikonEnv::Static()->ReadResource(sTxt,R_EVERYDAY_GRIDVIEW_007);
	sBuf.Append(sTxt);
	cArray->AppendL(sBuf);
	//PHB
	sBuf.Copy(_L("7\t"));
	CEikonEnv::Static()->ReadResource(sTxt,R_EVERYDAY_GRIDVIEW_008);
	sBuf.Append(sTxt);
	cArray->AppendL(sBuf);
	//Account
	sBuf.Copy(_L("8\t"));
	CEikonEnv::Static()->ReadResource(sTxt,R_EVERYDAY_GRIDVIEW_009);
	sBuf.Append(sTxt);
	cArray->AppendL(sBuf);
	
	//const CFont* fontText = ApacPlain12();
    m_pGrid->HandleItemAdditionL();
    ApplySelGridGraphicStyleL();
}

void CFunGridContainer::ApplySelGridGraphicStyleL()
{
    if (!m_pGrid) 
	{
        return;
	}
	
    AknListBoxLayouts::SetupStandardGrid( *m_pGrid );
	
	const CFont* fontText = ApacPlain12();
	TInt nX = (m_pGrid->ColumnWidth() - 30) / 2;
	TInt nY = (m_pGrid->ItemHeight() - 30 - fontText->HeightInPixels()) / 2;
    AknListBoxLayouts::SetupFormGfxCell( 
		*m_pGrid, 
		m_pGrid->ItemDrawer(),
		0, 
		nX, 
		nY, 
		0, 
		0,  
		30, 
		30, 
		TPoint( nX, nY ), 
		TPoint( 30+nX, 30+nY) );
	
	// layout of text
	AknListBoxLayouts::SetupFormAntiFlickerTextCell( 
		*m_pGrid, 
		m_pGrid->ItemDrawer(),
		1, 
		fontText, 
		215, 
		0, 
		0, 
		30+nY+fontText->HeightInPixels(),
		m_pGrid->ColumnWidth(), 
		CGraphicsContext::ECenter,
		TPoint( 0, 30+nY), 
		TPoint( m_pGrid->ColumnWidth(), m_pGrid->ItemHeight()) );
	
    DrawNow();
}
// End of File  
TInt CFunGridContainer::GetIndex()
{
	return m_nIndex;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -