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

📄 cellitem.cpp

📁 手机编程
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CGridDemoAppUi from GridDemoAppUi.cpp
*  Part of  : GridDemo
*  Created  : 2006-11-28 by tomken
*  Implementation notes:
*     Initial content was generated by Series 60 AppWizard.
*  Version  :
*  Copyright: Copyright (c) 2006-2008
* ============================================================================
*/

#include "CellItem.h"
#include <gulutil.h>
#include "GridDemoAppUi.h"

#define BORDER_COLOR   0xaaaaaa
#define HEADER_BACK_COLOR 0xeeeeee
#define CONTENT_BACK_COLOR 0xffffff

#define HEADER_FONT_COLOR 0x000000
#define CONTENT_FONT_COLOR 0x000000

#define FOCUS_BODER_COLOR  0x000000

CRowItem::CRowItem(TInt aRowType)
{
	iRowType = aRowType;
	iFristCellItem = NULL;
	iLastCellItem = NULL;
}

CRowItem::~CRowItem()
{
	iCells.ResetAndDestroy();
}

void CRowItem::AppendCellItem(CCellItem* aCellItem)
{
	if(iLastCellItem)
	{
		iLastCellItem->iNextCellItem = aCellItem;
		aCellItem->iPrevCellItem = iLastCellItem;
	}
	else
	{
		iFristCellItem = aCellItem;
	}

	iLastCellItem = aCellItem;
	iCells.Append(aCellItem);
}

CCellItem::CCellItem()
{
	iText = NULL;
	iIsFocus = EFalse;
	iNextCellItem = 0;
	iPrevCellItem = 0;
}

CCellItem::~CCellItem()
{
	if(iText)
		delete iText;
	iText = NULL;
}

void CCellItem::Redraw(CWindowGc &gc, TRect& aRect, TBool iIsLock) const
{
	gc.Reset();
	TRect rect = aRect;
	gc.SetClippingRect(aRect);
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	if(iIsFocus && !iIsLock)
		gc.SetBrushColor(FOCUS_BODER_COLOR);
	else
		gc.SetBrushColor(BORDER_COLOR);

	gc.SetPenStyle(CGraphicsContext::ESolidPen);

	if(iIsFocus && !iIsLock)
		gc.SetPenColor(FOCUS_BODER_COLOR);
	else
		gc.SetPenColor(BORDER_COLOR);
	
	gc.DrawRect(aRect);
	
	if(iIsFocus && !iIsLock)
		rect.Shrink(TSize(2,2));
	else
		rect.Shrink(TSize(1,1));

	if(iCellItemType == CRowItem::ERowTypeHeader || iIsLock)
	{
		gc.SetBrushColor(HEADER_BACK_COLOR);
		gc.SetPenColor(HEADER_BACK_COLOR);
	}
	else
	{
		gc.SetBrushColor(CONTENT_BACK_COLOR);
		gc.SetPenColor(CONTENT_BACK_COLOR);
	}
	gc.DrawRect(rect);

	gc.SetBrushStyle(CGraphicsContext::ENullBrush);
	if(iCellItemType == CRowItem::ERowTypeHeader || iIsLock)
		gc.SetPenColor(HEADER_FONT_COLOR);
	else
		gc.SetPenColor(CONTENT_FONT_COLOR);

	if(iText)
	{
		gc.UseFont(iFont);

		TInt baseline = rect.Height() /2 + iFont->AscentInPixels()/2;

		TBuf<256> buf;

		if(iText->Length() > buf.MaxLength())
			buf.Copy(iText->Left(buf.MaxLength()));
		else
			buf.Copy(*iText);

		TextUtils::ClipToFit(buf, *iFont, rect.Width());
		DrawUtils::DrawText(gc, buf, rect, baseline, iCellItemAlign, 0, iFont);
		gc.DiscardFont();
	}

	gc.CancelClippingRect();
}

TInt CCellItem::GetHight(TInt /*aWidth*/)
{
	return ITEM_DEFAULT_HEIGHT;
}

void CCellItem::SetText(const TDesC& aText)
{
	if(iText)
		delete iText;

	iText = aText.AllocL();

	if(iCellItemType == CRowItem::ERowTypeHeader)
	{
		if(iFont)
		{
			iWidth = iFont->TextWidthInPixels(*iText) + 4;

			if(iWidth > ITEM_DEFAULT_WIDTH)
				iWidth = ITEM_DEFAULT_WIDTH;
		}
		else
		{
			iWidth = ITEM_DEFAULT_WIDTH;
		}
	}
}

TPtrC CCellItem::GetText()
{
	if(iText)
		return iText->Des();
	else
		return TPtrC(0,0);
}

⌨️ 快捷键说明

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