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

📄 keydrawitem.c

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

	$Id: keydrawitem.c,v 1.1 2002/10/07 17:15:21 wjb Exp $
____________________________________________________________________________*/

#include "windows.h"
#include "commctrl.h"

#include "pgpUnicode.h"

HFONT SetUTF8Font(HWND hwndControl)
{
	LOGFONT lf;
	HFONT hFont;

	SystemParametersInfo(SPI_GETICONTITLELOGFONT,
		sizeof(LOGFONT), &lf, 0);
	
	hFont = CreateFontIndirect (&lf);

	SendMessage (hwndControl, WM_SETFONT,
		(WPARAM)hFont, (LPARAM)FALSE);

	return hFont;
}

//	_______________________________________________
//
//  Truncate text string

static BOOL sTruncateText (
		HDC		hdc, 
		WCHAR*	wsz, 
		int		xmax) 
{
	BOOL bShowToolTip	= FALSE;
	SIZE s;
	int l, w;

	// truncate at <newline>, if present
	l = 0;
	while (wsz[l])
	{
		if (wsz[l] == '\n')
		{
			wsz[l] = 0;
			bShowToolTip = TRUE;
			break;
		}
		l++;
	}

	GetTextExtentPoint32W (hdc, wsz, lstrlenW (wsz), &s);
	w = s.cx + 4;

	l = lstrlenW (wsz);
	if (l < 3) 
	{
		if (w > xmax) 
		{
			bShowToolTip = TRUE;
			wsz[0] = 0;
		}
	}
	else 
	{
		l = lstrlenW (wsz) - 3;

		while ((w > xmax) && (l >= 0))
		{
			bShowToolTip = TRUE;
			lstrcpyW (&wsz[l], L"...");
			GetTextExtentPoint32W (hdc, wsz, lstrlenW (wsz), &s);
			w = s.cx + 4;
			l--;
		}

		if (l < 0) 
			wsz[0] = 0;
	}

	return bShowToolTip;
}

#define MAXUSERIDSTRING				300

#define OFFSET_FIRST 2
#define OFFSET_OTHER 2

void 
KeyDrawItem (
		LPDRAWITEMSTRUCT	pdis)
{
	RECT			rc;
	RECT			rcAll;
	RECT			rcLabel;
	RECT			rcDraw;

	BOOL			bFocus = (GetFocus() == pdis->hwndItem);
	BOOL			bSelected;

	static CHAR		sz[128];

	COLORREF		clrTextSave, clrBkSave;

	LV_COLUMN		lvc;
	LVITEM			lvi;
	UINT			nJustify = DT_LEFT;
	INT				iCol;

	// get item data
	lvi.mask		= LVIF_IMAGE | LVIF_TEXT | LVIF_STATE;
	lvi.iItem		= pdis->itemID;
	lvi.iSubItem	= 0;
	lvi.pszText		= sz;
	lvi.cchTextMax	= sizeof(sz);
	lvi.stateMask	= 0xFFFF;     // get all state flags
	ListView_GetItem (pdis->hwndItem, &lvi);

	bSelected = lvi.state & LVIS_SELECTED;

	ListView_GetItemRect (pdis->hwndItem, pdis->itemID, &rcAll, LVIR_BOUNDS);
	ListView_GetItemRect (pdis->hwndItem, pdis->itemID, &rcLabel, LVIR_LABEL);
	rcAll.left = rcLabel.left;

	// set colors if item is selected
	if (!IsWindowEnabled(pdis->hwndItem))
	{
		clrTextSave = SetTextColor(pdis->hDC, GetSysColor(COLOR_BTNTEXT));
		clrBkSave = SetBkColor(pdis->hDC, GetSysColor(COLOR_3DFACE));

		FillRect (pdis->hDC, &rcAll, (HBRUSH)(COLOR_3DFACE+1));
	}
	else if (bSelected && bFocus)
	{
		clrTextSave = SetTextColor(pdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
		clrBkSave = SetBkColor(pdis->hDC, GetSysColor(COLOR_HIGHLIGHT));

		FillRect (pdis->hDC, &rcAll, (HBRUSH)(COLOR_HIGHLIGHT+1));
	}
	else if (bSelected && !bFocus)
	{
		clrTextSave = SetTextColor(pdis->hDC, GetSysColor(COLOR_BTNTEXT));
		clrBkSave = SetBkColor(pdis->hDC, GetSysColor(COLOR_BTNFACE));

		FillRect (pdis->hDC, &rcAll, (HBRUSH)(COLOR_BTNFACE+1));
	}
	else
		FillRect (pdis->hDC, &rcAll, (HBRUSH)(COLOR_WINDOW+1));

	if (lvi.iImage >= 0)
	{
		HIMAGELIST hil;

		hil = ListView_GetImageList (pdis->hwndItem, LVSIL_SMALL);
		if (hil)
		{
			ListView_GetItemRect (
					pdis->hwndItem, pdis->itemID, &rcDraw, LVIR_ICON);
			ImageList_Draw (hil, lvi.iImage, pdis->hDC, 
					rcDraw.left, rcDraw.top+OFFSET_FIRST, ILD_TRANSPARENT);
		}
	}

	// draw item label
	rcDraw = rcLabel;
	rcDraw.left += OFFSET_FIRST;
	rcDraw.right -= OFFSET_FIRST;
	rcDraw.top += OFFSET_FIRST; //

//	DrawText (pdis->hDC, sz, -1, &rcDraw,
//		DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER |
//		DT_END_ELLIPSIS);

	{
		WCHAR wsz[MAXUSERIDSTRING];
		DWORD ulen;

		pgpUTF8StringToUCS2 (sz, kPGPUnicodeNullTerminated, 
				wsz, MAXUSERIDSTRING, &ulen);

		sTruncateText (pdis->hDC, wsz, rcDraw.right - rcDraw.left);

		// print the text
		ExtTextOutW(pdis->hDC, rcDraw.left, rcDraw.top, 
				   ETO_CLIPPED | ETO_OPAQUE,
				   &rcDraw, 
				   wsz, 
				   lstrlenW(wsz), 
				   NULL);
	}

	// draw labels for extra columns
	rc = rcLabel;
	lvc.mask = LVCF_FMT | LVCF_WIDTH;
	for (iCol = 1; ListView_GetColumn (pdis->hwndItem, iCol, &lvc); iCol++)
	{
		rc.left = rc.right;
		rc.right += lvc.cx;

		sz[0] = '\0';
		ListView_GetItemText (pdis->hwndItem, pdis->itemID, iCol,
						sz, sizeof(sz));
		if (sz[0] == '\0')
			continue;

		switch (lvc.fmt & LVCFMT_JUSTIFYMASK)
		{
		case LVCFMT_RIGHT:
			nJustify = DT_RIGHT;
			break;
		case LVCFMT_CENTER:
			nJustify = DT_CENTER;
			break;
		default:
			break;
		}

		rcDraw = rc;
		rcDraw.left += OFFSET_OTHER;
		rcDraw.right -= OFFSET_OTHER;

		DrawText (pdis->hDC, sz, -1, &rcDraw,
			nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER |
			DT_END_ELLIPSIS);
	}

	// draw focus rectangle if item has focus
	if (lvi.state & LVIS_FOCUSED && bFocus && bSelected)
		DrawFocusRect (pdis->hDC, &rcAll);

	// set original colors if item was selected
	if (bSelected)
	{
		SetTextColor (pdis->hDC, clrTextSave);
		SetBkColor (pdis->hDC, clrBkSave);
	}
}

/*__Editor_settings____

	Local Variables:
	tab-width: 4
	End:
	vi: ts=4 sw=4
	vim: si
_____________________*/

⌨️ 快捷键说明

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