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

📄 mylistbox.cpp

📁 Symbian工程 九宫格界面
💻 CPP
字号:
#include <aknnotewrappers.h>

#include "MyListBox.h"

#define  LINE_COUNT	7;

CMyListBoxContainer::CMyListBoxContainer()
{
   // iSnowBrushBackgroundColor=TRgb(100,200,91);
	iSnowBrushBackgroundColor=KRgbWhite;
	iSnowPenColor=KRgbBlack;
	iSnowChose=0;
	iSnowFirstCurrent=0;
	iLineHeight = 0;
	iLineHeight=0;
	iTimeWidth=0;
	iStartTimeX=0;
	iStartTimeY=0;
    iStartTitleX=0;
	iStartY=0;
    iStartX=0;
	iLineHeight=0;
	
}

void CMyListBoxContainer::ConstructL(const TRect& aRect)
{
  //	SetExtentToWholeScreen();
    SetRect(aRect);

	SnowCalcPoint(aRect);

    ActivateL();
}

CMyListBoxContainer::~CMyListBoxContainer()
{
	iSnowTextArr.ResetAndDestroy();
	iSnowTimeArr.ResetAndDestroy();
}
void CMyListBoxContainer::SizeChanged()
{ 
	TRect rc(Rect());
	SnowCalcPoint(rc); 
}
void CMyListBoxContainer::Draw( const TRect& aRect) const
{
	
	CWindowGc& gc = SystemGc();		//获取窗口上下文
	const CFont* fontUsed = iEikonEnv->LegendFont();//获取中文字体
	gc.UseFont(fontUsed);
	gc.SetPenStyle(CGraphicsContext::ESolidPen);	
	gc.SetPenColor(iSnowPenColor);
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	gc.SetBrushColor(iSnowBrushBackgroundColor);
	if (iSnowTimeArr.Count()>0)
	{
		TRect aTRect(TPoint(iStartX,(iStartTimeY+iSnowChose*iLineHeight-fontUsed->HeightInPixels()-2)),TSize(iTimeWidth+iTitleWidth,fontUsed->HeightInPixels()+2));
		
		gc.DrawRect(aTRect);
	}
	for (int i=0;i<6;i++)
	{
		if(i+iSnowFirstCurrent>=  iSnowTimeArr.Count()) break;
		if (iSnowTimeArr[i+iSnowFirstCurrent]->Des().Length()<=10)
		{
			gc.DrawText(*(iSnowTimeArr[i+iSnowFirstCurrent]),TPoint(iStartTimeX, iStartTimeY + i*iLineHeight));
		}
		else
		{
			TBuf<32> sTime;
			sTime=iSnowTimeArr[i+iSnowFirstCurrent]->Des().Mid(0,10);
			sTime.Append(_L("..."));
			gc.DrawText(sTime,TPoint(iStartTimeX, iStartTimeY + i*iLineHeight));
		}
		if (iSnowTextArr[i+iSnowFirstCurrent]->Des().Length()<=6)
		{
				gc.DrawText(*(iSnowTextArr[i+iSnowFirstCurrent]),TPoint(iStartTitleX, iStartTimeY + i*iLineHeight));
		}
		else
		{
			TBuf<32> sTitle;
			sTitle=iSnowTextArr[i+iSnowFirstCurrent]->Des().Mid(0,6);
			sTitle.Append(_L("..."));
				gc.DrawText(sTitle,TPoint(iStartTitleX, iStartTimeY + i*iLineHeight));
		}
	}
	gc.DiscardFont();
	gc.SetPenStyle(CGraphicsContext::ENullPen);
	gc.SetBrushStyle(CGraphicsContext::ENullBrush);
}

TKeyResponse CMyListBoxContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
{
	if (iSnowTimeArr.Count() <= 0)
	{
		return EKeyWasNotConsumed;
	}
	if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
	{
		if(iSnowChose<5&&iSnowFirstCurrent==0)
		{	
			iSnowChose=(iSnowChose+1)%(iSnowTimeArr.Count());
			DrawDeferred();
		}
		else if (iSnowChose<5&&iSnowFirstCurrent>0)
		{
			iSnowChose++;
		}
 		else if (iSnowChose==5)
 		{
 			if ((iSnowChose+iSnowFirstCurrent)<iSnowTextArr.Count()-1)
 			{
 				iSnowFirstCurrent++;
 				DrawDeferred();
 			}
 			else if ((iSnowChose+iSnowFirstCurrent)==iSnowTextArr.Count()-1)
 			{
 				iSnowChose=0;
				iSnowFirstCurrent=0;
				DrawDeferred();
 			}
 		}
	}
	else if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
	{
		if(iSnowChose>0 )
		{	
			iSnowChose--;
			DrawDeferred();
		}
		else if (iSnowChose==0)
		{
			if (iSnowFirstCurrent>0)
			{
				iSnowFirstCurrent--;
				DrawDeferred();
			}
			else if (iSnowTextArr.Count()>6)
			{
				iSnowChose = 5;
				iSnowFirstCurrent = iSnowTextArr.Count()-6;
				DrawDeferred();
			}
			else 
			{
				iSnowChose = iSnowTextArr.Count()-1;
				DrawDeferred();
			}
		}

	}

	return EKeyWasNotConsumed;
}
void CMyListBoxContainer::SnowSetContent(const TDesC& aTitle)
{
	if(aTitle.Length() <= 0) return;
	HBufC* bufText = HBufC::NewLC(500);
	bufText->Des().Copy(aTitle);
	iSnowTextArr.Append(bufText);
	CleanupStack::Pop();
}
void CMyListBoxContainer::SnowSetTime(const TDesC& aTime)
{
	if(aTime.Length() <= 0) return;
	HBufC* bufText1 = HBufC::NewLC(100);
	bufText1->Des().Copy(aTime);
	iSnowTimeArr.Append(bufText1);
	CleanupStack::Pop();
}
void CMyListBoxContainer::SetCurrentIndex(TInt& aIndex)
{
	if(aIndex < 0) return;
	iSnowChose = aIndex;
	DrawDeferred();
}
void CMyListBoxContainer::SnowGetIndex(TInt& aIndex)
{
	aIndex=iSnowChose+iSnowFirstCurrent;
}

void CMyListBoxContainer::SnowCalcPoint(const TRect& aRect)
{
	iLineHeight			=aRect.Height()*4/42;
	iTimeWidth			=(3*aRect.Width()) / 7;
	iStartTimeX			=aRect.Width()/15;
 	iStartTimeY			=aRect.Height()/7+aRect.Width()/15;
	iStartTitleX		=iTimeWidth+aRect.Width()/20;
	iStartX				=0;
	iStartY             =aRect.Height()/7;
	iTitleWidth        =(4*aRect.Width()) / 7;
}
void CMyListBoxContainer::SnowSetBackgroundColor(TRgb aColor)
{
	iSnowBrushBackgroundColor = aColor;
}

void CMyListBoxContainer::SnowSetPenColor(TRgb aColor)
{
	iSnowPenColor = aColor;
}
void CMyListBoxContainer::DelList()
{
	if (iSnowTimeArr.Count()>0)
	{
		delete iSnowTextArr[iSnowChose+iSnowFirstCurrent];
		iSnowTextArr.Remove(iSnowChose+iSnowFirstCurrent);
		delete iSnowTimeArr[iSnowChose+iSnowFirstCurrent];
		iSnowTimeArr.Remove(iSnowChose+iSnowFirstCurrent);

		if (iSnowChose>0&&iSnowChose==iSnowTextArr.Count()&&iSnowFirstCurrent==0)
		{
			iSnowChose--;
		}
		else if (iSnowChose==5&&iSnowFirstCurrent>0)
		{
			iSnowFirstCurrent--;
		}
 		else if (iSnowChose<5&&iSnowFirstCurrent>0)
 		{
			iSnowChose++;
 			iSnowFirstCurrent--;
 		}
	}
}

⌨️ 快捷键说明

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