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

📄 cinfobar.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
字号:
/*____________________________________________________________________________
		Copyright (C) 2002 PGP Corporation
        All rights reserved.

        $Id: CInfoBar.cpp,v 1.3 2002/08/06 20:09:23 dallen Exp $
____________________________________________________________________________*/

#include "pgpClassesConfig.h"

#include "UMath.h"

#include "CDC.h"
#include "CInfoBar.h"
#include "CRect.h"

#include "Resource.h"

_USING_PGP

_UNNAMED_BEGIN

const COLORREF	kBlackColor			= RGB(0, 0, 0);
const COLORREF	kPaleYellowColor	= RGB(255, 255, 204);

const char		*kInfoBarClassName	= "PGP Info Bar Class";

_UNNAMED_END


// Types

struct CInfoBar::LineInfo : public CListableObject<CInfoBar::LineInfo>
{
	CString		string;
	PGPUInt32	id;
};


// Class CInfoBar member functions

PGPUInt32 
CInfoBar::Height() const
{
	if (NumLines() == 0)
		return 0;
	else
		return (mTopMargin + NumLines() * mLineHeight + mBottomMargin + 2);
}

PGPUInt32 
CInfoBar::GetIdOfIndex(PGPInt32 index) const
{
	pgpAssert(WeCreated());
	return GetAtIndex(index)->id;
}

PGPInt32 
CInfoBar::GetIndexOfId(PGPUInt32 id) const
{
	pgpAssert(WeCreated());

	LineInfo	*pInfo	= mLines.Head();

	for (PGPInt32 i = 0; i < NumLines(); i++)
	{
		if (pInfo->id == id)
			return i;

		pInfo = mLines.Next(pInfo);
	}

	return -1;
}

const char * 
CInfoBar::GetStringAtIndex(PGPInt32 index) const
{
	pgpAssert(WeCreated());
	return GetAtIndex(index)->string;
}

void 
CInfoBar::SetIcon(InfoBarIcon icon)
{
	pgpAssert(mShowIcon);

	switch (icon)
	{
	case kInfoIcon:
		mInfoIcon.Load(mInstance, MAKEINTRESOURCE(IDI_SMALLINFO));
		break;

	case kStopIcon:
		mInfoIcon.Load(mInstance, MAKEINTRESOURCE(IDI_SMALLSTOP));
		break;
	}
}

void 
CInfoBar::AddString(PGPInt32 index, const char * string, PGPUInt32 id)
{
	pgpAssert(WeCreated());

	if ((index < 0) || (index > NumLines()))
		THROW_PGPERROR(kPGPError_BadParams);

	auto_ptr<LineInfo>	pNewLI(new LineInfo);

	pNewLI->string = string;
	pNewLI->id = id;

	if (NumLines() == 0)
	{
		mLines.AddHead(pNewLI.release());
	}
	else if (index == NumLines())
	{
		mLines.AddTail(pNewLI.release());
	}
	else
	{
		LineInfo	*pLI	= GetAtIndex(index);
		mLines.InsertBefore(pLI, pNewLI.release());
	}
}

void 
CInfoBar::RemoveString(PGPInt32 index)
{
	pgpAssert(WeCreated());
	pgpAssert(index <= NumLines());

	LineInfo	*pLI	= GetAtIndex(index);

	mLines.Remove(pLI);
	delete pLI;
}

void 
CInfoBar::Empty()
{
	mLines.Empty();
}

void 
CInfoBar::ResizeRedraw()
{
	pgpAssert(WeCreated());

	SetWindowPos(HWND_TOP, 0, 0, mWidth, Height(), SWP_NOMOVE | SWP_NOZORDER);
	InvalidateRect(NULL, TRUE);
}

void 
CInfoBar::Create(
	HINSTANCE	instance, 
	HWND		parent, 
	CPoint		origin, 
	PGPUInt32	width, 
	PGPBoolean	showIcon)
{
	pgpAssert(!WeCreated());
	pgpAssert(CWindow::IsWindow(parent));

	mInstance = instance;

	mShowIcon = showIcon;
	mWidth = width;

	mBackBrush.CreateSolid(kPaleYellowColor);
	mBorderPen.Create(PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW));

	if (showIcon)
		SetIcon(kInfoIcon);

	CWindow::Create(kInfoBarClassName, NULL, "", WS_CHILD | WS_VISIBLE, 0, 
		origin.X(), origin.Y(), 0, 0, parent);
}

void 
CInfoBar::InitClass()
{
	RegisterClass(kInfoBarClassName, CS_HREDRAW | CS_VREDRAW);
}

void 
CInfoBar::CleanupClass()
{
	UnregisterClass(kInfoBarClassName);
}

CInfoBar::LineInfo * 
CInfoBar::GetAtIndex(PGPInt32 index) const
{
	pgpAssert(WeCreated());

	if ((index < 0) || (index >= NumLines()))
		THROW_PGPERROR(kPGPError_BadParams);

	LineInfo	*pInfo	= mLines.Head();

	for (PGPInt32 i = 0; i < NumLines(); i++)
	{
		if (i == index)
			return pInfo;

		pInfo = mLines.Next(pInfo);
	}

	return NULL;
}

PGPInt32 
CInfoBar::OnCreate(LPCREATESTRUCT pCS)
{
	CDC	dc(Handle());

	// Get height of one line of text.
	mInfoFont.Attach(CWindow(GetParent()).GetFont());
	HFONT	oldFont	= dc.SelectObject(mInfoFont.Get());

	TEXTMETRIC	textMetric;
	dc.GetTextMetrics(&textMetric);

	dc.SelectObject(oldFont);

	mLineHeight		= textMetric.tmHeight;
	mTopMargin		= textMetric.tmDescent;
	mBottomMargin	= textMetric.tmDescent*2;
	mRightMargin	= textMetric.tmDescent*2;

	if (mShowIcon)
	{
		mLeftMargin = CIcon::kSmallIconWidth + 
			(textMetric.tmAveCharWidth)/2;
	}
	else
	{
		mLeftMargin = textMetric.tmAveCharWidth;
	}

	return CWindow::OnCreate(pCS);
}

void
CInfoBar::OnNcDestroy()
{
	CWindow::OnNcDestroy();

	mBackBrush.Clear();
	mInfoIcon.Clear();
	mBorderPen.Clear();
}

void 
CInfoBar::OnPaint(HDC paintDC)
{
	if (NumLines() == 0)
		return;

	CDC	dc;

	if (IsNull(paintDC))
		dc.BeginPaint(Handle());
	else
		dc.Attach(paintDC);

	HBRUSH	oldBrush	= dc.SelectObject(mBackBrush.Get());
	HPEN	oldPen		= dc.SelectObject(mBorderPen.Get());

	dc.Rectangle(0, 0, mWidth, Height());

	if (mShowIcon)
		mInfoIcon.DrawIcon(dc, 1, 1);

	dc.SelectObject(oldBrush);
	dc.SelectObject(oldPen);

	COLORREF	oldBackColor	= dc.SetBkColor(kPaleYellowColor);
	COLORREF	oldTextColor	= dc.SetTextColor(kBlackColor);
	HFONT		oldFont			= dc.SelectObject(mInfoFont.Get());

	LineInfo	*pLI	= mLines.Head();
	PGPUInt32	curY	= mTopMargin + 1;

	while (IsntNull(pLI))
	{
		CRect	textRect(mLeftMargin + 1, curY, 
			mWidth - mRightMargin - 2, curY + mLineHeight);

		dc.ExtTextOut(textRect.Left(), textRect.Top(), ETO_CLIPPED, 
			textRect, pLI->string, strlen(pLI->string));

		curY += mLineHeight;
		pLI = mLines.Next(pLI);
	}

	dc.SetBkColor(oldBackColor);
	dc.SetTextColor(oldTextColor);
	dc.SelectObject(oldFont);

	dc.Clear();
}

⌨️ 快捷键说明

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