#include "GraphicStyleListBox.h"
_LIT(KTab," ");
CGraphicStyleListBox* CGraphicStyleListBox::NewL(const TRect& aRect,
CEikonEnv* aEikon)
{
CGraphicStyleListBox* self = CGraphicStyleListBox::NewLC(aRect, aEikon);
CleanupStack::Pop(self);
return self;
}
CGraphicStyleListBox* CGraphicStyleListBox::NewLC(const TRect& aRect,
CEikonEnv* aEikon)
{
CGraphicStyleListBox* self = new (ELeave) CGraphicStyleListBox();
CleanupStack::PushL(self);
self->ConstructL(aRect, aEikon);
return self;
}
CGraphicStyleListBox::CGraphicStyleListBox()
{
iIndex = 0;
iStartIndex = 0;
iScreenCount = 6;
iIconDistance = 0;
iAlignmentType = 0;
iTextAndIconDistance = 0;
}
void CGraphicStyleListBox::ConstructL(const TRect& aRect, CEikonEnv* aEikon)
{
iClientRect.SetRect(aRect.iTl, aRect.Size());
iEikEnv = aEikon;
iFristInfoArray = new (ELeave) CDesCArrayFlat(4);
iSencondInfoArray = new (ELeave) CDesCArrayFlat(4);
}
CGraphicStyleListBox::~CGraphicStyleListBox()
{
if (iFristInfoArray)
{
iFristInfoArray->Reset();
delete iFristInfoArray;
}
if (iSencondInfoArray)
{
iSencondInfoArray->Reset();
delete iSencondInfoArray;
}
}
void CGraphicStyleListBox::Draw(CWindowGc& gc)
{
const CFont* Font = iEikEnv->NormalFont();
gc.UseFont(Font);
//绘制背景
if (iBackGround && iBackGroundMask)
{
gc.DrawBitmapMasked(iClientRect, iBackGround, TRect(0, 0,
iBackGroundSize.iWidth, iBackGroundSize.iHeight),
iBackGroundMask, EFalse);
}
else if (iBackGround && !iBackGroundMask)
{
gc.DrawBitmap(iClientRect, iBackGround);
}
else if (iIsDisPlayBackRgb)
{
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.SetBrushColor(iBackGroundRgb);
gc.DrawRect(iClientRect);
}
TInt FontHigh = Font->HeightInPixels();//字体高度
TInt OptaionHigh = iClientRect.Height() / iScreenCount;//一个选项的高度;
TInt TxtCount1 = iFristInfoArray->Count();
TInt TxtCount2 = iSencondInfoArray->Count();
TInt IconH(0);//绘制图片的高度
TInt IconCount(0);//位图个数
TInt IConMaskCount(0);//掩码图个数
TInt FristPointX(0);
TInt FristPointY(0);
TInt SencondPointX(0);
TInt SencondPointY(0);
TInt IconDistance(0);
if (iIconArray)
{
IconCount = iIconArray->Count();
if (IconCount)
{
IconH = OptaionHigh;
IconDistance = iIconDistance;
}
}
if (iIconMaskArray)
{
IConMaskCount = iIconMaskArray->Count();
}
TRect rct;
rct.SetRect(iClientRect.iTl, TSize(iClientRect.Width(), OptaionHigh));//第一个高亮区的区域
for (TInt i(0); i < iScreenCount; i++)
{
if ((iStartIndex + i) < TxtCount1)
{
//绘制前景
if ((i + iStartIndex) == iIndex)
{
if (iForeGround && iForeGroundMask)
{
gc.DrawBitmapMasked(TRect(TPoint(rct.iTl.iX, rct.iTl.iY + i
* OptaionHigh), rct.Size()), iForeGround,
TRect(0, 0, iForeGroundSize.iWidth,
iForeGroundSize.iHeight), iForeGroundMask,
EFalse);
}
else if (iForeGround && !iForeGroundMask)
{
gc.DrawBitmap(TRect(TPoint(rct.iTl.iX, rct.iTl.iY + i
* OptaionHigh), rct.Size()), iForeGround);
}
else if (iIsDisPlayForeRgb)
{
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.SetBrushColor(iForeGroundRgb);
gc.DrawRect(TRect(TPoint(rct.iTl.iX, rct.iTl.iY + i
* OptaionHigh), rct.Size()));
}
}
//绘制图像
if (IconCount && IConMaskCount)
{
gc.DrawBitmapMasked(TRect(TPoint(rct.iTl.iX + iIconDistance,
rct.iTl.iY + i * OptaionHigh), TSize(IconH, IconH)),
(*iIconArray)[i + iStartIndex], TRect(0, 0,
iIconSize.iWidth, iIconSize.iHeight),
(*iIconMaskArray)[i + iStartIndex], EFalse);
}
else if (IconCount && !IConMaskCount)
{
gc.DrawBitmap(TRect(TPoint(rct.iTl.iX + iIconDistance,
rct.iTl.iY + i * OptaionHigh), TSize(IconH, IconH)),
(*iIconArray)[i + iStartIndex]);
}
//设置文字颜色
gc.SetPenColor(TRgb(255, 255, 255));
if (TxtCount1 && TxtCount2)//有2个文本的
{
FristPointY = iClientRect.iTl.iY + OptaionHigh / 4 + FontHigh
/ 2 + i * OptaionHigh;
SencondPointY = rct.iTl.iY + (OptaionHigh * 3) / 4 + FontHigh
/ 2 + i * OptaionHigh;
if (iAlignmentType == 0)//左对齐
{
FristPointX = iClientRect.iTl.iX + iTextAndIconDistance
+ IconDistance + IconH;
SencondPointX = FristPointX;
}
else if (iAlignmentType == 1)//局中
{
FristPointX
= iClientRect.iTl.iX + IconDistance + IconH
+ (iClientRect.Width() - IconDistance
- IconH) / 2
- Font->TextWidthInPixels(
iFristInfoArray->MdcaPoint(i
+ iStartIndex)) / 2;
SencondPointX = iClientRect.iTl.iX + IconDistance + IconH
+ (iClientRect.Width() - IconDistance - IconH) / 2