Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3472711
  • 博文数量: 1450
  • 博客积分: 11163
  • 博客等级: 上将
  • 技术积分: 11101
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-25 14:40
文章分类

全部博文(1450)

文章存档

2017年(5)

2014年(2)

2013年(3)

2012年(35)

2011年(39)

2010年(88)

2009年(395)

2008年(382)

2007年(241)

2006年(246)

2005年(14)

分类: C/C++

2009-07-09 17:34:50

//首先先创建一个 GRID 对象
iGrid = new( ELeave ) CAknGrid;
iGrid->SetContainerWindowL( *this );
TInt gridFlags = EAknListBoxSelectionGrid;
iGrid->ConstructL( this, gridFlags);

//第二,创建 GRID MODE 对象
iGridM = new( ELeave ) CAknGridM;
iGrid->SetModel( iGridM );

//第三, 设置GRID层
TBool iVerticalOrientation = EFalse;
TBool iTopToBottom = ETrue;
TBool iLeftToRight = ETrue;
iNumOfColumns = KNumOfSelectionColumns;
iNumOfRows = KNumOfSelectionRows;
iGraphHeight=KGraphHeight;
iCellSize.iWidth = ( aRect.iBr.iX - aRect.iTl.iX ) / iNumOfColumns;
iCellSize.iHeight = ( aRect.iBr.iY - aRect.iTl.iY ) / iNumOfRows;
iGrid->SetLayoutL( iVerticalOrientation,iLeftToRight, iTopToBottom,
iNumOfRows, iNumOfColumns,iCellSize );

//第四,设置滚动条
CAknGridView::TScrollingType 
    iVerticalScrollingType = CAknGridView::EScrollIncrementLineAndLoops;

CAknGridView::TScrollingType 
  iHorizontalScrollingType = CAknGridView::EScrollIncrementLineAndLoops;

iGrid->SetPrimaryScrollingType( iVerticalScrollingType );
iGrid->SetSecondaryScrollingType( iHorizontalScrollingType );
iGrid->CreateScrollBarFrameL(ETrue);
iGrid->ScrollBarFrame()
->SetScrollBarVisibilityL(
   CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto);

AknListBoxLayouts::SetupStandardGrid( *iGrid );

//设置GRID元素的图像信息和文本信息
TInt grWidth = 0;
TInt txWidth = 0;
grWidth = iGrid->ColumnWidth();
txWidth = iGrid->ColumnWidth();
const CFont* fontText = CCoeEnv::Static()->NormalFont();
AknListBoxLayouts::SetupFormGfxCell( *iGrid, iGrid->ItemDrawer(),
0, 0, 0, 0, 0,  grWidth, iGraphHeight,
TPoint( 0, 0 ), TPoint( grWidth, iGraphHeight) );
AknListBoxLayouts::SetupFormTextCell( *iGrid, iGrid->ItemDrawer(),
1, fontText,
215,
0, 0,
iGrid->ItemHeight()-3,
txWidth,
CGraphicsContext::ECenter,
TPoint( 0, iGrid->ItemHeight()-iGraphHeight),
TPoint( iGrid->ColumnWidth(), iGrid->ItemHeight() )
);

//创建图片数组,并将它放到数据层中
CArrayPtr* icons =new ( ELeave ) CAknIconArray(7);
CleanupStack::PushL( icons );
icons->AppendL( 
iEikonEnv->CreateIconL(
KMbmPath,EMbmGirdtestContact,EMbmGirdtestContact) );
icons->AppendL( 
iEikonEnv->CreateIconL(
KMbmPath,EMbmGirdtestCalllog,EMbmGirdtestCalllog) );
icons->AppendL( 
iEikonEnv->CreateIconL(
KMbmPath,EMbmGirdtestConfig,EMbmGirdtestConfig) );
icons->AppendL( 
iEikonEnv->CreateIconL(
KMbmPath,EMbmGirdtestCallwall,EMbmGirdtestCallwall) );
icons->AppendL( 
iEikonEnv->CreateIconL(
KMbmPath,EMbmGirdtestFind,EMbmGirdtestFind) );
icons->AppendL( 
iEikonEnv->CreateIconL(
KMbmPath,EMbmGirdtestBlackcode,EMbmGirdtestBlackcode) );
icons->AppendL( 
iEikonEnv->CreateIconL(
KMbmPath,EMbmGirdtestTodo,EMbmGirdtestTodo) );

// Sets graphics as ListBox icon.
iGrid->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
CleanupStack::Pop();

//从视图层得到数据层对象
CDesCArray* array = static_cast
(iGrid->Model()->ItemTextArray());
array->Reset();

//从资源文件中得到字符串,添加到数据层中
TBuf<255> item;
HBufC* textResource = StringLoader::LoadLC(QTN_CONTACT);       
item.Format(KItemFormat,0,textResource);
array->AppendL(item); 
CleanupStack::PopAndDestroy();

textResource = StringLoader::LoadLC(QTN_CALLLOG);
item.Format(KItemFormat,1,textResource);
array->AppendL(item); 
CleanupStack::PopAndDestroy();

textResource = StringLoader::LoadLC(QTN_CONFIG);
item.Format(KItemFormat,2,textResource);
array->AppendL(item); 
CleanupStack::PopAndDestroy();

textResource = StringLoader::LoadLC(QTN_CALLWALL);
item.Format(KItemFormat,3,textResource);
array->AppendL(item); 
CleanupStack::PopAndDestroy();

textResource = StringLoader::LoadLC(QTN_FIND);
item.Format(KItemFormat,4,textResource);
array->AppendL(item); 
CleanupStack::PopAndDestroy();

textResource = StringLoader::LoadLC(QTN_BLACKCODE);
item.Format(KItemFormat,5,textResource);
array->AppendL(item); 
CleanupStack::PopAndDestroy();

textResource = StringLoader::LoadLC(QTN_TODO);
item.Format(KItemFormat,6,textResource);
array->AppendL(item); 
CleanupStack::PopAndDestroy();

//将数据变化显示到视图上
iGrid->HandleItemAdditionL();




阅读(414) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~