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

📄 tlpaint.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 4 页
字号:
}


//	_______________________________________________
//
//  Compute minimum necessary width of column for auto-sizing

static int 
sComputeWidth (
		HDC			hdc,
		TLWndData*	pWD,
		int			icol,
		int			indent,
		TLTreeItem* p)
{
	int				iwidth		= 0;
	int				i, ilen;
	SIZE			size;
	WCHAR			wsz[TRUNCBUFSIZE];

	TLColumnItem*	pci;
	TLListItem*		pli;

	while (p) 
	{    
		if (icol == 0)
		{
			sGetWideText (p->pszText, wsz, sizeof(wsz));  
			ilen = sTextLength (wsz);
			GetTextExtentPoint32W (hdc, wsz, ilen, &size);
			i = size.cx + 12 + indent;
		}
		else
		{
			pli = p->listItem;
			pci = pWD->columnItem;

			for (i=1; i<icol; i++)
			{
				pci = pci->nextItem;
				pli = pli->nextItem;
			}
			                         
			sGetWideText (pli->pszText, wsz, sizeof(wsz));
			ilen = sTextLength (wsz);

			switch (pci->iDataType) {
			case TLC_DATASTRING :
				GetTextExtentPoint32W (hdc, wsz, ilen, &size);
				i = size.cx + 12;
				break;

			case TLC_DATALONG :
				switch (pci->iDataFmt) {
				case TLCFMT_IMAGE :
					if (pli->pszText) 
					{
						GetTextExtentPoint32W (hdc, wsz, ilen, &size);
						i = size.cx + 12;
					}
					else
					{
						i = BITMAPWIDTH + 12;
					}
					break;

				case TLCFMT_HIMAGELIST :
				case TLCFMT_HICON :
					i = 0;
					if (pli->lDataValue)
					{
						i += BITMAPWIDTH + 12;
					}
					if (pli->pszText)
					{
						GetTextExtentPoint32W (hdc, wsz, ilen, &size);
						i += size.cx + 12;
					}
					break;

				case TLCFMT_IMAGELIST :
				{
					ULONG uImageMask = 1;

					i = 12;
					while (!(uImageMask & 0x80000000)) 
					{
						if (pli->lDataValue & uImageMask)
							i += (BITMAPWIDTH + BITMAPSPACE);

						uImageMask <<= 1;
					}

					if (pli->pszText)
					{
						GetTextExtentPoint32W (hdc, wsz, ilen, &size);
						i += size.cx;
					}
					break;
				}

				default :
					i = pci->cx;
					break;
				}
				break;
			}
		}

		if (i > iwidth)
			iwidth = i;

		if (p->cChildren) 
		{
			if (p->state & TLIS_EXPANDED)
			{
				i = sComputeWidth (hdc, pWD, 
						icol, indent+INCREMENTINDENT, p->childItem);

				if (i > iwidth)
					iwidth = i;
			}
		}

		p = p->nextItem;
	}

	return iwidth;
}


//	_______________________________________________
//
//  compute the appropriate width of a column

int 
TLAutoComputeColumnWidth (
		TLWndData*	pWD, 
		int			icol) 
{
	HDC			hdc;
	TLTreeItem*	p;
	HFONT		hOldFont;

	int			iwidth			= -1;
	int			indent			= BUTTONWIDTH+BITMAPWIDTH+HTEXTSHIFT;

	hdc = GetDC (pWD->hWnd);
	if (hdc)
	{
		hOldFont = SelectObject (hdc, pWD->hFont);

		p = pWD->rootItem;

		if (pWD->style & TLS_DRAGSELECTION)
			indent += DRAGSELECTINDENT;

		iwidth = sComputeWidth (hdc, pWD, icol, indent, p);

		SelectObject (hdc, hOldFont);
		ReleaseDC (pWD->hWnd, hdc);
	}

	return iwidth;
}


//	_______________________________________________
//
//  Calculations before painting -- called in response to WM_PAINT

void 
TLPrePaint (
		TLWndData*	pWD) 
{
	SCROLLINFO si;
	INT iY;

	pWD->iBCent = (pWD->iRowHeight / 2) +2;
	pWD->iBMPos = pWD->iBCent - (BITMAPHEIGHT/2) -1;

	pWD->tlInval = pWD->tlRect;
	pWD->tlInval.top += pWD->iRowHeight+1;

	pWD->iExpandedRows = sCountRows (pWD->rootItem);
	pWD->iMaxRows = (pWD->tlInval.bottom-pWD->tlInval.top-
					(pWD->iRowHeight/2)) / pWD->iRowHeight;

	if (pWD->iMaxRows <= pWD->iExpandedRows) 
	{
		pWD->tlInval.right = 
				pWD->tlRect.right - GetSystemMetrics (SM_CXVSCROLL);
	}
	else 
	{
		pWD->iFirstRow = 0;
		pWD->tlInval.right = pWD->tlRect.right;
	}

	iY = pWD->tlInval.right - pWD->tlInval.left;

	if (pWD->iTotalWidth > iY) 
	{
		pWD->tlInval.bottom =
				pWD->tlRect.bottom - GetSystemMetrics (SM_CYHSCROLL);
	}
	else 
		pWD->tlInval.bottom = pWD->tlRect.bottom;

	pWD->iMaxRows = (pWD->tlInval.bottom-pWD->tlInval.top-
			(pWD->iRowHeight/2)) / pWD->iRowHeight;

	si.cbSize = sizeof (SCROLLINFO);
	si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
	si.nMin = 0;
	si.nMax = pWD->iExpandedRows;
	si.nPage = pWD->iMaxRows;
	si.nPos = pWD->iFirstRow;
	SetScrollInfo (pWD->hWnd, SB_VERT, &si, TRUE);

	si.nMax = pWD->iTotalWidth;
	si.nPage = pWD->tlRect.right - pWD->tlRect.left;
	if (pWD->iMaxRows <= pWD->iExpandedRows)
		si.nPage -= GetSystemMetrics (SM_CXVSCROLL);
	si.nPos = pWD->iHorizontalPos;
	SetScrollInfo (pWD->hWnd, SB_HORZ, &si, TRUE);
}


//	_______________________________________________
//
//  Paint a tree list -- called in response to WM_PAINT

void 
TLPaint (
		TLWndData*	pWD, 
		HDC			hdc) 
{
	TLTreeItem*	p;
	HFONT		hOldFont;
	HBRUSH		hOldBrush;
	int			y, item, indent;

	hOldFont = SelectObject (hdc, pWD->hFont);

	UnrealizeObject (pWD->spcbarbrush);
	SetBrushOrgEx (hdc, -1 * pWD->iHorizontalPos, 0, NULL);
	hOldBrush = SelectObject (hdc, pWD->spcbarbrush);

	p = pWD->rootItem;
	y = pWD->tlInval.top;
	item = 0;
	indent = 0;

	if (pWD->style & TLS_DRAGSELECTION)
		indent = DRAGSELECTINDENT;

	if (pWD->bStepAnimation)
		pWD->bContAnimation = FALSE;

	sPaintItems (hdc, pWD, &item, &y, indent, p);

	SelectObject (hdc, hOldBrush);
	SelectObject (hdc, hOldFont);
}


//	_______________________________________________
//
//  delete the memory DC

void 
TLDeleteMemDC (
		TLWndData*	pWD) 
{
	if (pWD->hdcMem) 
	{
		SelectObject (pWD->hdcMem, pWD->hbmOld);
		DeleteObject (pWD->hbmMem);
		DeleteDC (pWD->hdcMem);
		pWD->hdcMem = NULL;
	}
}


//	_______________________________________________
//
//  create mem dc and pass it to routine to render treelist

void 
TLMemPaint (
		TLWndData*		pWD, 
		HDC				hdc, 
		PAINTSTRUCT*	pps) 
{
	RECT rc;

	GetClientRect (pWD->hWnd, &rc);

	if (!pWD->hdcMem) 
	{
		pWD->hdcMem = CreateCompatibleDC (hdc);
		pWD->hbmMem = CreateCompatibleBitmap (hdc, 
				rc.right-rc.left, rc.bottom-rc.top);
		pWD->hbmOld = SelectObject (pWD->hdcMem, pWD->hbmMem);
		SetBkMode (pWD->hdcMem, TRANSPARENT);
	}

	if (IsWindowEnabled (pWD->hWnd))
	{
		if (pWD->watermark.ulFlags & TLWM_CONSTANTBKGRND)
		{
			HBRUSH	hb	= CreateSolidBrush (pWD->watermark.crBkgrnd);
			FillRect (pWD->hdcMem, &rc, hb);
			DeleteObject (hb);
		}
		else
			FillRect (pWD->hdcMem, &rc, pWD->unselbgbrush);

		if (pWD->watermark.hbm)
		{
			HDC				hdcMem;
			HBITMAP			hbmpOld;
			RECT			rc2;
			INT				iSize, iCenter, iHalf;

			hdcMem = CreateCompatibleDC (hdc);
			hbmpOld = SelectObject (hdcMem, pWD->watermark.hbm);

			rc2 = pWD->tlRect;
			rc2.top += pWD->iRowHeight+1;
			rc2.bottom -= pWD->iRowHeight+1;
			if (pWD->watermark.ulFlags & TLWM_KEEPASPECTRATIO)
			{
				if (rc2.right > (rc2.bottom - rc2.top))
				{
					iCenter = rc2.right / 2;
					iHalf = (rc2.bottom - rc2.top) / 2;
					if (pWD->watermark.ulFlags & TLWM_SHRINKONLY)
					{
						iSize = pWD->watermark.size.cy / 2;
						if (iHalf > iSize)
						{
							rc2.bottom = rc2.top + (iHalf + iSize);
							rc2.top += iHalf - iSize;
							iHalf = iSize;
						}
					}
					rc2.left = iCenter - iHalf;
					rc2.right = iCenter + iHalf;
				}
				else
				{
					iCenter = (rc2.bottom - rc2.top) / 2;
					iHalf = rc2.right / 2;
					if (pWD->watermark.ulFlags & TLWM_SHRINKONLY)
					{
						iSize = pWD->watermark.size.cx / 2;
						if (iHalf > iSize)
						{
							rc2.left = iHalf - iSize;
							rc2.right = iHalf + iSize;
							iHalf = iSize;
						}
					}
					rc2.bottom = rc2.top + (iCenter + iHalf);
					rc2.top += iCenter - iHalf;
				}
			}

			StretchBlt (pWD->hdcMem, 
					rc2.left, rc2.top, 
					rc2.right-rc2.left, rc2.bottom-rc2.top,
					hdcMem, 0, 0, 
					pWD->watermark.size.cx, pWD->watermark.size.cy, 
					SRCCOPY);

			SelectObject (hdcMem, hbmpOld);
			DeleteDC (hdcMem);
		}
	}
	else
		FillRect (pWD->hdcMem, &rc, pWD->unfocusbgbrush);

	TLPaint (pWD, pWD->hdcMem);

	BitBlt (hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
			pWD->hdcMem, 0, 0, SRCCOPY);
}


//	_______________________________________________
//
//  Paint a tree list -- called in response to WM_PAINT

void 
TLPaintDragBitmap (
		TLWndData*	pWD, 
		ULONG		ulFlags, 
		HDC			hdc) 
{
	TLTreeItem* p;
	HFONT hOldFont;
	int y, item;
	BOOL bStarted;

	hOldFont = SelectObject (hdc, pWD->hFont);

	p = pWD->rootItem;
	y = 0;
	item = 0;
	bStarted = FALSE;
	sPaintItemsDragBitmap (hdc, pWD, ulFlags, &item, &y, 0, p, &bStarted);

	SelectObject (hdc, hOldFont);
}


//	_______________________________________________
//
//  Paint a tree list -- called in response to WM_PAINT

void 
TLCalcDragBitmap (
		TLWndData*	pWD, 
		ULONG		ulFlags, 
		RECT*		prc) 
{
	TLTreeItem* p;
	int y, item;
	BOOL bStarted;

	prc->left = BUTTONWIDTH;
	prc->right = prc->left + pWD->iFirstColumnWidth;

	prc->top = 0;
	prc->bottom = 0;
	p = pWD->rootItem;
	y = 0;
	item = 0;
	bStarted = FALSE;
	sCalcItemsDragBitmap (pWD, ulFlags, &item, &y, 0, p, &bStarted, prc);
}


//	_______________________________________________
//
//  create bitmap and paint selected items to it

BOOL 
TLMemPaintDragBitmap (
		TLWndData*			pWD,
		LPTL_DRAGBITMAP		lpdb) 
{
	HBITMAP	hbmOld;
	HDC		hdcMem;
	HDC		hdcScreen;
	RECT	rc;

	if (!lpdb) 
		return FALSE;

	// calculate bitmap size and position
	TLCalcDragBitmap (pWD, lpdb->ulFlags, &rc);
	if (rc.right <= rc.left)
		return FALSE;

	lpdb->sizeDrag.cx = rc.right - rc.left;
	lpdb->sizeDrag.cy = rc.bottom - rc.top;

	lpdb->ptHotSpot.x = lpdb->ptCursorPos.x - rc.left;
	lpdb->ptHotSpot.y = lpdb->ptCursorPos.y - rc.top - pWD->tlInval.top;

	// contstruct bitmap
	hdcMem = CreateCompatibleDC (NULL);
	hdcScreen = GetDC (pWD->hWnd);
	lpdb->hbmDrag = CreateCompatibleBitmap (hdcScreen, 
			lpdb->sizeDrag.cx, lpdb->sizeDrag.cy);
	ReleaseDC (pWD->hWnd, hdcScreen);

	hbmOld = SelectObject (hdcMem, lpdb->hbmDrag);
	SetBkMode (hdcMem, TRANSPARENT);
	rc.left = 0;
	rc.top = 0;
	rc.right = lpdb->sizeDrag.cx;
	rc.bottom = lpdb->sizeDrag.cy;
	FillRect (hdcMem, &rc, pWD->unselbgbrush);

	TLPaintDragBitmap (pWD, lpdb->ulFlags, hdcMem);

	SelectObject (hdcMem, hbmOld);

	DeleteDC (hdcMem);

	return TRUE;
}


⌨️ 快捷键说明

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