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

📄 mygridcontainer.cpp

📁 个人手机助理套件:包含1、记事本(备忘录)、名片夹、名片夹的上传下载(异地备份)、短消息模块
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CMyGridContainer from CCoeControl, MCoeControlObserver
*  Part of  : MyGrid
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES
#include <HelperGenius.rsg>
#include "HelperGenius.hrh"
#include "MyGridContainer.h"
#include "HelperGeniusAppui.h"

#include <akngrid.h>
#include <AknIconArray.h>	//for CAknIconArray
#include <aknlists.h>
#include <fbs.h>
#include <Helpergenius.mbg>
#include <e32base.h>		//for CArrayPtr
#include <AknUtils.h>
// ================= MEMBER MyGridS =======================

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

// EPOC default constructor can leave.
void CMyGridContainer::ConstructL(const TRect& aRect)
    {

    CreateWindowL();
	m_pBitmap = new (ELeave) CFbsBitmap;
	TBuf<KMaxPath> pathMbm;
#ifdef __WINS__
	pathMbm.Copy(_L("z:\\system\\apps\\HelperGenius\\HelperGenius.mbm"));
#else
	CHelperGeniusAppUi* pApp = (CHelperGeniusAppUi*)CEikonEnv::Static()->AppUi();
	pApp->GetAppPath(pathMbm);
	
	pathMbm.Append(_L("HelperGenius.mbm"));
#endif
    User::LeaveIfError(CompleteWithAppPath(pathMbm));
    User::LeaveIfError(m_pBitmap->Load(pathMbm,EMbmHelpergeniusHelpergenius_icon_17));

	//---begin-for-Grid----------------------
	m_pGrid = new( ELeave ) CAknGrid;	//创建一个Grid控制器实例/对象
	m_pGrid->SetContainerWindowL( *this );	//设置Grid所在的容器:把这个Grid放到容器中
	m_pGrid->ConstructL( this, EAknListBoxSelectionGrid );	//第二阶段构造
	m_pGrid->SetEmptyGridTextL(_L("empty"));	//设置Grid默认文本:当Grid的Text未设置时,显示默认字符串
	
	// set layout.
	m_pGrid->SetRect(aRect.Size());	//设置Grid的矩形显示区域
	
	// set initial params for the grid.
	
	m_pGridType = EAknExGridSelectionGrid;	//设置Grid的类型
	
	//Sets the orientation of the grid,either vertical or horizontal.
	iVerticalOrientation	= EFalse;	//排列方向:垂直方向为假,则是水平方向
	iTopToBottom			= ETrue;	//排列方式:从上倒下为真
	iLeftToRight			= ETrue;	//排列顺序:从左到有为真
	//the size of the primary dimension of the grid. 
	iNumOfColumns			= 3;	//列数
	iNumOfRows				= 3;	//行数
	iNumOfItems				= 9;	//项的总个数
	//the ordering of the data.
	iContentType			= EContainGraphic;	//内容类型:包含图片
	
	iVerticalScrollingType = CAknGridView::EScrollIncrementLineAndLoops;
	iHorizontalScrollingType = CAknGridView::EScrollIncrementLineAndLoops;
	iSizeOfItems.iWidth = ( aRect.iBr.iX - aRect.iTl.iX ) / iNumOfColumns;
	iSizeOfItems.iHeight = ( aRect.iBr.iY - aRect.iTl.iY ) / iNumOfRows;
	
	//Sets the orientation of the grid, either vertical or horizontal, the ordering of the data and the size of the primary dimension of the grid.
	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();	//激活Grid
	m_pGrid->DrawNow();	//画Grid

    SetRect(aRect);
    ActivateL();
    }

// Destructor
CMyGridContainer::~CMyGridContainer()
    {
	MEM_FREE(m_pGrid);
	  MEM_FREE(m_pBitmap);
    }

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

void CMyGridContainer::FocusTo(TInt aCommand)
    {
    }

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

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

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

// ---------------------------------------------------------
// CMyGridContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CMyGridContainer::Draw(const TRect& aRect) const
    {
	CWindowGc& gc = SystemGc();
	/******添加背景图片*******************************************/
    gc.Clear(aRect);
    TPoint topLeft(0,0);
	//    gc.DrawBitmap(TRect(topLeft,TSize(176,208)),m_pBitmap);
    gc.BitBlt(topLeft,m_pBitmap,TRect(topLeft,TSize(176,208)));
    }

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


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

// End of File  
void CMyGridContainer::LoadGraphicsL()
{
	CHelperGeniusAppUi* pApp = (CHelperGeniusAppUi*)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); // icons array
} 


void CMyGridContainer::AddDataL()
 {
    MDesCArray* array = m_pGrid->Model()->ItemTextArray();
    CDesCArray* cArray = ( CDesCArray* )array;
	TBuf<32> sBuf;
	TBuf<32> sTmpTitle1;
	CEikonEnv::Static()->ReadResource(sTmpTitle1, R_QTN_MH_MYGRID_NOTE);
	TBuf<32> sTmpTitle2;
	CEikonEnv::Static()->ReadResource(sTmpTitle2, R_QTN_MH_MYGRID_USERPASS);
	TBuf<32> sTmpTitle3;
	CEikonEnv::Static()->ReadResource(sTmpTitle3, R_QTN_MH_MYGRID_FOOTBALL);
	TBuf<32> sTmpTitle4;
	CEikonEnv::Static()->ReadResource(sTmpTitle4, R_QTN_MH_MYGRID_ERROR);
	TBuf<32> sTmpTitle5;
	CEikonEnv::Static()->ReadResource(sTmpTitle5, R_QTN_MH_MYGRID_NETBANK);
	TBuf<32> sTmpTitle7;
	CEikonEnv::Static()->ReadResource(sTmpTitle7, R_QTN_MH_MYGRID_BASKETBALL);
	
	//SMS
	sBuf.Copy(_L("0\t"));
	sBuf.Append(sTmpTitle1);
	cArray->AppendL(sBuf);
	//PHB
	sBuf.Copy(_L("1\t"));
	sBuf.Append(sTmpTitle4);
	cArray->AppendL(sBuf);
	//Account
	sBuf.Copy(_L("2\t"));
	sBuf.Append(sTmpTitle2);
	cArray->AppendL(sBuf);
	//SMS
	sBuf.Copy(_L("3\t"));
	sBuf.Append(sTmpTitle3);
	cArray->AppendL(sBuf);
	//PHB
	sBuf.Copy(_L("4\t"));
	sBuf.Append(_L("VC6"));
	cArray->AppendL(sBuf);
	//Account
	sBuf.Copy(_L("5\t"));
	sBuf.Append(sTmpTitle5);
	cArray->AppendL(sBuf);
	//SMS
	sBuf.Copy(_L("6\t"));
	sBuf.Append(sTmpTitle7);
	cArray->AppendL(sBuf);
	//PHB
	sBuf.Copy(_L("7\t"));
	sBuf.Append(_L("RealPlayer"));
	cArray->AppendL(sBuf);
	//Account
	sBuf.Copy(_L("8\t"));
	sBuf.Append(_L("Windows"));
	cArray->AppendL(sBuf);	

    m_pGrid->HandleItemAdditionL();
    ApplySelGridGraphicStyleL();
	
}


void CMyGridContainer::ApplySelGridGraphicStyleL()
{
    if (!m_pGrid) 
	{
        return;
	}
	
	//Setup text foreground and background colours to default
    AknListBoxLayouts::SetupStandardGrid( *m_pGrid );
	
	//获取中文字体
	const CFont* fontText = ApacPlain12();
	//
	TInt nX = (m_pGrid->ColumnWidth() - 24) / 2;
	TInt nY = (m_pGrid->ItemHeight() - 24 - fontText->HeightInPixels()) / 2;
	
	//Setup a single graphics cell of list item.
    AknListBoxLayouts::SetupFormGfxCell( 
		*m_pGrid, 
		m_pGrid->ItemDrawer(),
		0, 
		nX, 
		nY, 
		0, 
		0,  
		24, 
		24, 
		TPoint( nX, nY ), 
		TPoint( 24+nX, 24+nY) );
	
	//Setup a single text cell of list item.
	// layout of text.
	//This has flicker for settings.
	// 	AknListBoxLayouts::SetupFormTextCell( 
	// 		*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()) );
	
	//This is for removing flicker for settings.
	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();
}

CAknGrid* CMyGridContainer::GetGrid()
{
	return m_pGrid;
}

⌨️ 快捷键说明

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