📄 tlpaint.c
字号:
{
HBRUSH oldbrush, bgbrush, fgbrush, barbrush;
INT iBCent, iBMPos;
HPEN oldpen, textpen;
SIZE s;
INT ix, iy, cx, xoffset;
TLColumnItem* pci;
TLListItem* pli;
RECT rc;
DOTTEDSTRUCT DottedStruct;
double f;
WCHAR wsz[TRUNCBUFSIZE];
BOOL bEnabled;
bEnabled = IsWindowEnabled (pWD->hWnd);
iBCent = pWD->iBCent;
iBMPos = pWD->iBMPos;
DottedStruct.hDC = hdc;
xoffset = indent - pWD->iHorizontalPos;
while (p)
{
// increment item count
(*item)++;
// check if items are visible in window
if ((*item) > (pWD->iFirstRow + pWD->iMaxRows + 2))
break;
if ((*item) > pWD->iFirstRow)
{
// first paint the tree items ...
// select colors based on state of tree item
if (!bEnabled)
{
bgbrush = pWD->unfocusbgbrush;
fgbrush = pWD->unselfgbrush;
textpen = pWD->unseltextpen;
DottedStruct.dwDottedColor = pWD->unselfocuscolor;
pWD->textbgcolor = GetSysColor (COLOR_BTNFACE);
SetTextColor (hdc, GetSysColor (COLOR_WINDOWTEXT));
}
else if (pWD->bTreeFocused)
{
if (p->state & TLIS_SELECTED)
{
bgbrush = pWD->selbgbrush;
fgbrush = pWD->selfgbrush;
textpen = pWD->seltextpen;
DottedStruct.dwDottedColor = pWD->selfocuscolor;
pWD->textbgcolor = GetSysColor (COLOR_HIGHLIGHT);
SetTextColor (hdc, GetSysColor (COLOR_HIGHLIGHTTEXT));
}
else
{
bgbrush = pWD->unselbgbrush;
fgbrush = pWD->unselfgbrush;
textpen = pWD->unseltextpen;
DottedStruct.dwDottedColor = pWD->unselfocuscolor;
pWD->textbgcolor = GetSysColor (COLOR_WINDOW);
SetTextColor (hdc, GetSysColor (COLOR_WINDOWTEXT));
}
}
else
{
if ((p->state & (TLIS_SELECTED|TLIS_DRAGGEDOVER)) &&
(pWD->style & TLS_SHOWSELECTIONALWAYS))
{
bgbrush = pWD->unfocusbgbrush;
fgbrush = pWD->unselfgbrush;
textpen = pWD->unseltextpen;
DottedStruct.dwDottedColor = pWD->unselfocuscolor;
pWD->textbgcolor = GetSysColor (COLOR_BTNFACE);
SetTextColor (hdc, GetSysColor (COLOR_WINDOWTEXT));
}
else
{
bgbrush = pWD->unselbgbrush;
fgbrush = pWD->unselfgbrush;
textpen = pWD->unseltextpen;
DottedStruct.dwDottedColor = pWD->unselfocuscolor;
pWD->textbgcolor = GetSysColor (COLOR_WINDOW);
SetTextColor (hdc, GetSysColor (COLOR_WINDOWTEXT));
}
}
SetBkColor (hdc, pWD->textbgcolor);
// set rectangle coordinates
// rectangle sensitive to "selection" mouse clicks
p->selectRect.left = xoffset + BUTTONWIDTH;
p->selectRect.right = pWD->tlInval.right;
p->selectRect.top = *y+1;
p->selectRect.bottom = p->selectRect.top + pWD->iRowHeight;
// rectangle sensitive to "button" mouse clicks
if (p->cChildren && (pWD->style & TLS_HASBUTTONS))
{
p->buttonRect.left = xoffset;
p->buttonRect.right = p->buttonRect.left + BUTTONWIDTH;
p->buttonRect.top = *y;
p->buttonRect.bottom = p->buttonRect.top + pWD->iRowHeight;
}
else
{
p->buttonRect.left = xoffset + BUTTONWIDTH;
p->buttonRect.right = xoffset + BUTTONWIDTH;
p->buttonRect.top = *y;
p->buttonRect.bottom = 0;
}
// rectangle which is highlighted when item is selected
p->hiliteRect.left =
min (xoffset + BUTTONWIDTH+BITMAPWIDTH+HTEXTSHIFT,
pWD->iFirstColumnWidth);
p->hiliteRect.top = *y+1;
p->hiliteRect.bottom = p->selectRect.top + pWD->iRowHeight;
if (p->state & TLIS_BOLD)
SelectObject (hdc, pWD->hFontBold);
else if (p->state & TLIS_ITALICS)
SelectObject (hdc, pWD->hFontItalic);
else
SelectObject (hdc, pWD->hFont);
sGetWideText (p->pszText, wsz, sizeof(wsz));
if (sTruncateText (hdc, wsz,
pWD->iFirstColumnWidth-
(indent + BUTTONWIDTH+BITMAPWIDTH+HTEXTSHIFT)))
{
p->state |= TLIS_TRUNCATED;
}
else
p->state &= ~TLIS_TRUNCATED;
GetTextExtentPoint32W (hdc, wsz, lstrlenW (wsz), &s);
p->hiliteRect.right = p->hiliteRect.left + s.cx + HTEXTSHIFT;
pli = p->listItem;
pci = pWD->columnItem;
ix = pWD->iFirstColumnWidth;
while (pci && pli)
{
ix += pci->cx;
if (pli->state & TLIS_VISIBLE) p->hiliteRect.right = ix;
pci = pci->nextItem;
pli = pli->nextItem;
}
// if focused, draw box
if (bgbrush != pWD->unselbgbrush)
FillRect (hdc, &p->hiliteRect, bgbrush);
if (pWD->bTreeFocused)
{
if ((p->state & TLIS_FOCUSED) ||
(p->state & TLIS_DRAGGEDOVER))
{
LineDDA (p->hiliteRect.left, p->hiliteRect.top,
p->hiliteRect.right-1, p->hiliteRect.top,
(LINEDDAPROC)sDottedLineProc,
(LPARAM)&DottedStruct);
LineDDA (p->hiliteRect.right-1, p->hiliteRect.top,
p->hiliteRect.right-1, p->hiliteRect.bottom-1,
(LINEDDAPROC)sDottedLineProc,
(LPARAM)&DottedStruct);
LineDDA (p->hiliteRect.right-1, p->hiliteRect.bottom-1,
p->hiliteRect.left, p->hiliteRect.bottom-1,
(LINEDDAPROC)sDottedLineProc,
(LPARAM)&DottedStruct);
LineDDA (p->hiliteRect.left, p->hiliteRect.bottom-1,
p->hiliteRect.left, p->hiliteRect.top,
(LINEDDAPROC)sDottedLineProc,
(LPARAM)&DottedStruct);
}
else if (p->state & TLIS_DRAGGEDBEFORE)
{
oldpen = SelectObject (hdc, pWD->unseltextpen);
MoveToEx (hdc, p->selectRect.left,
p->selectRect.top, NULL);
LineTo (hdc, p->selectRect.right-BUTTONWIDTH,
p->selectRect.top);
SelectObject (hdc, oldpen);
}
else if (p->state & TLIS_DRAGGEDAFTER)
{
oldpen = SelectObject (hdc, pWD->unseltextpen);
MoveToEx (hdc, p->selectRect.left,
p->selectRect.bottom-1, NULL);
LineTo (hdc, p->selectRect.right-BUTTONWIDTH,
p->selectRect.bottom-1);
SelectObject (hdc, oldpen);
}
}
// draw tree item text
iy = p->hiliteRect.top + TEXTVERTOFF;
SetTextAlign (hdc, TA_LEFT);
TextOutW (hdc, p->hiliteRect.left+2, iy, wsz, lstrlenW(wsz));
// draw tree item bitmap, if there is space
if (pWD->iFirstColumnWidth >= (p->buttonRect.right+BITMAPWIDTH))
{
ImageList_Draw (pWD->hImageList, p->iImage, hdc,
p->buttonRect.right, p->hiliteRect.top+iBMPos,
ILD_TRANSPARENT);
}
// paint list items based on their data type
SelectObject (hdc, pWD->hFont);
pli = p->listItem;
pci = pWD->columnItem;
ix = pWD->iFirstColumnWidth - pWD->iHorizontalPos;
while (pci && pli)
{
if (pli->state & TLIS_VISIBLE)
{
switch (pci->iDataType) {
case TLC_DATANONE :
break;
case TLC_DATASTRING :
sGetWideText (pli->pszText, wsz, sizeof(wsz));
if (sTruncateText (hdc, wsz, pci->cx))
pli->state |= TLIS_TRUNCATED;
else
pli->state &= ~TLIS_TRUNCATED;
SetBkColor (hdc, pWD->textbgcolor);
switch (pci->iDataFmt) {
case TLCFMT_LEFT :
SetTextAlign (hdc, TA_LEFT);
TextOutW (hdc, ix+6, iy,
wsz, lstrlenW(wsz));
break;
case TLCFMT_CENTER :
SetTextAlign (hdc, TA_CENTER);
TextOutW (hdc, ix + (pci->cx>>1), iy,
wsz, lstrlenW(wsz));
break;
case TLCFMT_RIGHT :
SetTextAlign (hdc, TA_RIGHT);
TextOutW (hdc, ix + pci->cx - 6, iy,
wsz, lstrlenW(wsz));
break;
}
break;
case TLC_DATALONG :
switch (pci->iDataFmt) {
case TLCFMT_LINBAR :
cx = pci->cx - BARCOLUMNDIFF;
if (cx <= 0)
break;
rc.left = ix + HBARSHIFT;
rc.top = iy + VBARSHIFT +1;
rc.right = ix + pci->cx - HBARSHIFT -1;
rc.bottom = iy+pWD->iRowHeight-(VBARSHIFT+2) -1;
oldbrush = SelectObject (hdc, pWD->barbgbrush);
oldpen = SelectObject (hdc, pWD->buttonpen);
Rectangle (hdc, rc.left - 1, rc.top - 1,
rc.right + 2, rc.bottom + 2);
SelectObject (hdc, pWD->shadowpen);
MoveToEx (hdc, rc.left, rc.bottom, NULL);
LineTo (hdc, rc.left, rc.top);
LineTo (hdc, rc.right, rc.top);
SelectObject (hdc, pWD->hilightpen);
LineTo (hdc, rc.right, rc.bottom);
LineTo (hdc, rc.left, rc.bottom);
if (pci->lMaxValue != 0)
{
if (pli->lDataValue > pci->lMaxValue)
{
barbrush = pWD->spcbarbrush;
rc.right = rc.left + cx;
}
else
{
barbrush = pWD->stdbarbrush;
rc.right = rc.left +
(int)(((float)pli->lDataValue /
(float)pci->lMaxValue)
* (float)cx);
}
}
else
rc.right = rc.left;
rc.top++;
rc.left++;
if (rc.right > rc.left)
{
SetBkColor (hdc, pWD->barcolor);
FillRect (hdc, &rc, barbrush);
rc.top--;
rc.left--;
// hilight pen already selected
MoveToEx (hdc, rc.right, rc.top, NULL);
LineTo (hdc, rc.left, rc.top);
LineTo (hdc, rc.left,rc.bottom);
SelectObject (hdc, pWD->shadowpen);
LineTo (hdc, rc.right, rc.bottom);
LineTo (hdc, rc.right, rc.top);
}
SelectObject (hdc, oldbrush);
SelectObject (hdc, oldpen);
break;
case TLCFMT_LOGBAR :
rc.left = ix + HBARSHIFT;
rc.top = iy + VBARSHIFT +1;
rc.right = ix + pci->cx - HBARSHIFT -1;
rc.bottom = iy+pWD->iRowHeight-(VBARSHIFT+2) -1;
oldbrush = SelectObject (hdc, pWD->barbgbrush);
oldpen = SelectObject (hdc, pWD->buttonpen);
Rectangle (hdc, rc.left - 1, rc.top - 1,
rc.right + 2, rc.bottom + 2);
SelectObject (hdc, pWD->shadowpen);
MoveToEx (hdc, rc.left, rc.bottom, NULL);
LineTo (hdc, rc.left, rc.top);
LineTo (hdc, rc.right, rc.top);
SelectObject (hdc, pWD->hilightpen);
LineTo (hdc, rc.right, rc.bottom);
LineTo (hdc, rc.left, rc.bottom);
if (pci->lMaxValue != 0)
{
if (pli->lDataValue > pci->lMaxValue)
{
barbrush = pWD->spcbarbrush;
rc.right = rc.left + cx;
}
else
{
barbrush = pWD->stdbarbrush;
f = (float)pli->lDataValue /
(float)pci->lMaxValue;
f += 1.0;
f = log (f) / log (2.0);
rc.right = rc.left + (int)(f * (float)cx);
}
}
else
rc.right = rc.left;
rc.top++;
rc.left++;
if (rc.right > rc.left)
{
SetBkColor (hdc, pWD->barcolor);
FillRect (hdc, &rc, barbrush);
rc.top--;
rc.left--;
// hilight pen already selected
MoveToEx (hdc, rc.right, rc.top, NULL);
LineTo (hdc, rc.left, rc.top);
LineTo (hdc, rc.left,rc.bottom);
SelectObject (hdc, pWD->shadowpen);
LineTo (hdc, rc.right, rc.bottom);
LineTo (hdc, rc.right, rc.top);
}
SelectObject (hdc, oldbrush);
SelectObject (hdc, oldpen);
break;
case TLCFMT_IMAGE :
// use text if available
if (pli->pszText)
{
sGetWideText (pli->pszText, wsz, sizeof(wsz));
if (sTruncateText (hdc, wsz, pci->cx))
pli->state |= TLIS_TRUNCATED;
else
pli->state &= ~TLIS_TRUNCATED;
SetBkColor (hdc, pWD->textbgcolor);
SetTextAlign (hdc, TA_CENTER);
TextOutW (hdc, ix + (pci->cx>>1), iy,
wsz, lstrlenW(wsz));
}
// otherwise paint image
else
{
if (pci->cx >= (BITMAPWIDTH))
{
int i = 0;
WORD wCur = LOWORD (pli->lDataValue);
if ((pWD->bStepAnimation) &&
(pli->state & TLIS_ANIMATED))
{
int iLim;
pWD->bContAnimation = TRUE;
iLim = HIBYTE(HIWORD(pli->lDataValue));
wCur = LOWORD(++(pli->lDataValue));
if (wCur > iLim) {
wCur =
LOBYTE(HIWORD(pli->lDataValue));
pli->lDataValue =
MAKELONG (wCur,
HIWORD(pli->lDataValue));
}
}
else
{
if (pli->state & TLIS_CLICKED)
i = 1;
}
ImageList_Draw (pWD->hImageList,
(wCur + i), hdc,
ix + pci->cxImageOffset,
p->hiliteRect.top+iBMPos,
ILD_TRANSPARENT);
}
}
break;
case TLCFMT_IMAGELIST :
{
int iImage = 0;
int iXpos = 0;
ULONG uImageMask = 1;
// first paint images
while (!(uImageMask & 0x80000000))
{
if (pli->lDataValue & uImageMask)
{
if ((iXpos+BITMAPWIDTH) <= pci->cx)
{
ImageList_Draw (pWD->hImageList,
iImage, hdc,
ix + iXpos,
p->hiliteRect.top+iBMPos,
ILD_TRANSPARENT);
iXpos +=
(BITMAPWIDTH + BITMAPSPACE);
}
else
{
lstrcpyW (wsz, L"...");
sTruncateText (hdc, wsz, pci->cx);
SetBkColor (hdc,
pWD->textbgcolor);
SetTextAlign (hdc, TA_LEFT);
TextOutW (hdc, ix + iXpos,
iy, wsz, lstrlenW(wsz));
}
}
uImageMask <<= 1;
iImage++;
}
// then draw text if available
if (pli->pszText)
{
sGetWideText (pli->pszText, wsz, sizeof(wsz));
if (sTruncateText (hdc,
wsz, (pci->cx - iXpos)))
{
pli->state |= TLIS_TRUNCATED;
}
else
pli->state &= ~TLIS_TRUNCATED;
SetBkColor (hdc, pWD->textbgcolor);
SetTextAlign (hdc, TA_LEFT);
TextOutW (hdc, ix + iXpos, iy,
wsz, lstrlenW(wsz));
}
break;
}
case TLCFMT_HIMAGELIST :
{
int iXpos = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -