Skip to content

Commit

Permalink
Use ATTR_SYMBOLIC and ATTR_JUNCTION for link check; attempt to make f…
Browse files Browse the repository at this point in the history
…unction code style consistent
  • Loading branch information
malxau committed Mar 13, 2022
1 parent a4b2c7d commit d991b78
Show file tree
Hide file tree
Showing 3 changed files with 826 additions and 713 deletions.
338 changes: 189 additions & 149 deletions src/treectl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1555,188 +1555,228 @@ TCWP_DrawItem(
HWND hwndLB,
HWND hWnd)
{
INT x, y, dy;
INT nLevel;
HDC hdc;
UINT len;
RECT rc;
BOOL bHasFocus, bDrawSelected;
PDNODE pNode, pNTemp;
DWORD rgbText;
DWORD rgbBackground;
HBRUSH hBrush, hOld;
INT iBitmap;
DWORD view;


// +1 added since IsNetPath->GetTreePath->GetTreePathIndirect
// is recursive and adds extra '\' at end then strips it off
TCHAR szPath[MAXPATHLEN+1];

SIZE size;

if (lpLBItem->itemID == (DWORD)-1) {
return;
}

hdc = lpLBItem->hDC;
pNode = (PDNODE)lpLBItem->itemData;
INT x, y, dy;
INT nLevel;
HDC hdc;
UINT len;
RECT rc;
BOOL bHasFocus, bDrawSelected;
PDNODE pNode, pNTemp;
DWORD rgbText;
DWORD rgbBackground;
HBRUSH hBrush, hOld;
INT iBitmap;
DWORD view;


// +1 added since IsNetPath->GetTreePath->GetTreePathIndirect
// is recursive and adds extra '\' at end then strips it off
TCHAR szPath[MAXPATHLEN+1];

SIZE size;

if (lpLBItem->itemID == (DWORD)-1)
{
return;
}

PreserveBitmapInRTL(hdc);
hdc = lpLBItem->hDC;
pNode = (PDNODE)lpLBItem->itemData;

/*
* Save the real extent.
*/
size.cx = GetRealExtent(pNode, NULL, szPath, &len);
size.cx += dyBorder;
PreserveBitmapInRTL(hdc);

rc = lpLBItem->rcItem;
rc.left = pNode->nLevels * dxText * 2;
rc.right = rc.left + dxFolder + size.cx + 4 * dyBorderx2;
/*
* Save the real extent.
*/
size.cx = GetRealExtent(pNode, NULL, szPath, &len);
size.cx += dyBorder;

if (lpLBItem->itemAction & (ODA_DRAWENTIRE | ODA_SELECT))
{
// draw the branches of the tree first
rc = lpLBItem->rcItem;
rc.left = pNode->nLevels * dxText * 2;
rc.right = rc.left + dxFolder + size.cx + 4 * dyBorderx2;

nLevel = pNode->nLevels;
if (lpLBItem->itemAction & (ODA_DRAWENTIRE | ODA_SELECT))
{
// draw the branches of the tree first

x = (nLevel * dxText * 2) - dxText + dyBorderx2;
dy = lpLBItem->rcItem.bottom - lpLBItem->rcItem.top;
y = lpLBItem->rcItem.top + (dy/2);
nLevel = pNode->nLevels;

if (hBrush = CreateSolidBrush(GetSysColor(COLOR_GRAYTEXT)))
{
hOld = SelectObject(hdc, hBrush);
x = (nLevel * dxText * 2) - dxText + dyBorderx2;
dy = lpLBItem->rcItem.bottom - lpLBItem->rcItem.top;
y = lpLBItem->rcItem.top + (dy/2);

if (pNode->pParent)
if (hBrush = CreateSolidBrush(GetSysColor(COLOR_GRAYTEXT)))
{
/* Draw the horizontal line over to the (possible) folder. */
PatBlt(hdc, x, y, dyText, dyBorder, PATCOPY);
hOld = SelectObject(hdc, hBrush);

/* Draw the top part of the vertical line. */
PatBlt(hdc, x, lpLBItem->rcItem.top, dyBorder, dy/2, PATCOPY);
if (pNode->pParent)
{
/* Draw the horizontal line over to the (possible) folder. */
PatBlt(hdc, x, y, dyText, dyBorder, PATCOPY);

/* If not the end of a node, draw the bottom part... */
if (!(pNode->wFlags & TF_LASTLEVELENTRY))
PatBlt(hdc, x, y+dyBorder, dyBorder, dy/2, PATCOPY);
/* Draw the top part of the vertical line. */
PatBlt(hdc, x, lpLBItem->rcItem.top, dyBorder, dy/2, PATCOPY);

/* Draw the verticals on the left connecting other nodes. */
pNTemp = pNode->pParent;
while (pNTemp)
{
nLevel--;
if (!(pNTemp->wFlags & TF_LASTLEVELENTRY))
PatBlt(hdc, (nLevel * dxText * 2) - dxText + dyBorderx2,
lpLBItem->rcItem.top, dyBorder,dy, PATCOPY);
/* If not the end of a node, draw the bottom part... */
if (!(pNode->wFlags & TF_LASTLEVELENTRY))
{
PatBlt(hdc, x, y+dyBorder, dyBorder, dy/2, PATCOPY);
}

pNTemp = pNTemp->pParent;
}
/* Draw the verticals on the left connecting other nodes. */
pNTemp = pNode->pParent;
while (pNTemp)
{
nLevel--;
if (!(pNTemp->wFlags & TF_LASTLEVELENTRY))
PatBlt(hdc, (nLevel * dxText * 2) - dxText + dyBorderx2,
lpLBItem->rcItem.top, dyBorder,dy, PATCOPY);

pNTemp = pNTemp->pParent;
}
}
}

if (hOld)
SelectObject(hdc, hOld);
SelectObject(hdc, hOld);

DeleteObject(hBrush);
}
}

bDrawSelected = (lpLBItem->itemState & ODS_SELECTED);
bHasFocus = (GetFocus() == lpLBItem->hwndItem);
bDrawSelected = (lpLBItem->itemState & ODS_SELECTED);
bHasFocus = (GetFocus() == lpLBItem->hwndItem);

// draw text with the proper background or rect
// draw text with the proper background or rect

if (bHasFocus && bDrawSelected)
{
rgbText = SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
rgbBackground = SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
}
else
{
//
// Set Text color of Compressed items to BLUE and Encrypted items
// to GREEN.
//
if (pNode->dwAttribs & ATTR_COMPRESSED)
{
rgbText = SetTextColor(hdc, RGB(0, 0, 255));
}
else if (pNode->dwAttribs & ATTR_ENCRYPTED)
{
rgbText = SetTextColor(hdc, RGB(0, 192, 0));
}
else
{
rgbText = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
}
rgbBackground = SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
}
if (bHasFocus && bDrawSelected)
{
rgbText = SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
rgbBackground = SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
}
else
{
//
// Set Text color of Compressed items to BLUE and Encrypted items
// to GREEN.
//
if (pNode->dwAttribs & ATTR_COMPRESSED)
{
rgbText = SetTextColor(hdc, RGB(0, 0, 255));
}
else if (pNode->dwAttribs & ATTR_ENCRYPTED)
{
rgbText = SetTextColor(hdc, RGB(0, 192, 0));
}
else
{
rgbText = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
}
rgbBackground = SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
}

ExtTextOut(hdc, x + dxText + dxFolder + 2 * dyBorderx2,
y-(dyText/2), ETO_OPAQUE, &rc,
szPath, len, NULL);
ExtTextOut(hdc, x + dxText + dxFolder + 2 * dyBorderx2,
y-(dyText/2), ETO_OPAQUE, &rc,
szPath, len, NULL);

// draw the bitmaps as needed
// draw the bitmaps as needed

// HACK: Don't draw the bitmap when moving
// HACK: Don't draw the bitmap when moving

if (fShowSourceBitmaps || (hwndDragging != hwndLB) || !bDrawSelected)
{
// Blt the proper folder bitmap
if (fShowSourceBitmaps || (hwndDragging != hwndLB) || !bDrawSelected)
{
// Blt the proper folder bitmap

view = GetWindowLongPtr(GetParent(hWnd), GWL_VIEW);
view = GetWindowLongPtr(GetParent(hWnd), GWL_VIEW);

if (IsNetPath(pNode)) {
if (IsNetPath(pNode))
{
if (bDrawSelected)
{
iBitmap = BM_IND_OPENDFS;
}
else
{
iBitmap = BM_IND_CLOSEDFS;
}
}
else if (!(view & VIEW_PLUSES) || !(pNode->wFlags & TF_HASCHILDREN))
{
if (bDrawSelected)
{
if (pNode->dwAttribs & (ATTR_SYMBOLIC | ATTR_JUNCTION))
{
iBitmap = BM_IND_OPENREPARSE;
}
else
{
iBitmap = BM_IND_OPEN;
}
}
else
{
if (pNode->dwAttribs & (ATTR_SYMBOLIC | ATTR_JUNCTION))
{
iBitmap = BM_IND_CLOSEREPARSE;
}
else
{
iBitmap = BM_IND_CLOSE;
}
}
}
else
{
if (pNode->wFlags & TF_EXPANDED)
{
if (bDrawSelected)
iBitmap = BM_IND_OPENDFS;
{
iBitmap = BM_IND_OPENMINUS;
}
else
iBitmap = BM_IND_CLOSEDFS;

} else if (!(view & VIEW_PLUSES) || !(pNode->wFlags & TF_HASCHILDREN)) {
if (bDrawSelected) {
if (pNode->dwAttribs & ATTR_REPARSE_POINT)
iBitmap = BM_IND_OPENREPARSE;
else
iBitmap = BM_IND_OPEN;
} else {
if (pNode->dwAttribs & ATTR_REPARSE_POINT)
iBitmap = BM_IND_CLOSEREPARSE;
else
iBitmap = BM_IND_CLOSE;
}
} else {
if (pNode->wFlags & TF_EXPANDED) {
if (bDrawSelected)
iBitmap = BM_IND_OPENMINUS;
else
iBitmap = BM_IND_CLOSEMINUS;
} else {
if (bDrawSelected)
iBitmap = BM_IND_OPENPLUS;
else
iBitmap = BM_IND_CLOSEPLUS;
{
iBitmap = BM_IND_CLOSEMINUS;
}
}
BitBlt(hdc, x + dxText + dyBorder, y-(dyFolder/2), dxFolder, dyFolder,
hdcMem, iBitmap * dxFolder, (bHasFocus && bDrawSelected) ? dyFolder : 0, SRCCOPY);
}
else
{
if (bDrawSelected)
{
iBitmap = BM_IND_OPENPLUS;
}
else
{
iBitmap = BM_IND_CLOSEPLUS;
}
}
}
BitBlt(hdc, x + dxText + dyBorder, y-(dyFolder/2), dxFolder, dyFolder,
hdcMem, iBitmap * dxFolder, (bHasFocus && bDrawSelected) ? dyFolder : 0, SRCCOPY);
}

// restore text stuff and draw rect as required
// restore text stuff and draw rect as required

if (bDrawSelected) {
if (bHasFocus) {
SetTextColor(hdc, rgbText);
SetBkColor(hdc, rgbBackground);
} else {
HBRUSH hbr;
if (hbr = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT))) {
FrameRect(hdc, &rc, hbr);
DeleteObject(hbr);
}
}
}
}
if (bDrawSelected)
{
if (bHasFocus)
{
SetTextColor(hdc, rgbText);
SetBkColor(hdc, rgbBackground);
}
else
{
HBRUSH hbr;
if (hbr = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT)))
{
FrameRect(hdc, &rc, hbr);
DeleteObject(hbr);
}
}
}

if (lpLBItem->itemAction == ODA_FOCUS)
DrawFocusRect(hdc, &rc);
if (lpLBItem->itemAction == ODA_FOCUS)
{
DrawFocusRect(hdc, &rc);
}
}

#ifdef TBCUSTSHOWSHARE
Expand Down Expand Up @@ -2232,7 +2272,7 @@ TreeControlWndProc(
(LPARAM)szPath);
StripBackslash(szPath);
}

CharUpperBuff(szPath, 1); // make sure

SetWindowLongPtr(hwndParent, GWL_TYPE, szPath[0] - TEXT('A'));
Expand Down
Loading

0 comments on commit d991b78

Please sign in to comment.