Make Task List dpi aware

Closes #2172
This commit is contained in:
A-R-C-A 2016-08-15 23:56:43 +00:00 committed by Don Ho
parent 40509ccb3d
commit 438926bbd9
2 changed files with 18 additions and 23 deletions

View File

@ -105,33 +105,32 @@ RECT TaskList::adjustSize()
RECT rc;
ListView_GetItemRect(_hSelf, 0, &rc, LVIR_ICON);
const int imgWidth = rc.right - rc.left;
const int leftMarge = 30;
const int xpBottomMarge = 5;
const int w7BottomMarge = 15;
const int aSpaceWidth = ListView_GetStringWidth(_hSelf, TEXT(" "));
const int leftMarge = ::GetSystemMetrics(SM_CXFRAME) * 2 + aSpaceWidth * 4;
// Temporary set "selected" font to get the worst case widths
::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFontSelected), 0);
int maxwidth = -1;
_rc.left = 0;
_rc.top = 0;
_rc.bottom = 0;
_rc = { 0, 0, 0, 0 };
TCHAR buf[MAX_PATH];
for (int i = 0 ; i < _nbItem ; ++i)
{
TCHAR buf[MAX_PATH];
ListView_GetItemText(_hSelf, i, 0, buf, MAX_PATH);
int width = ListView_GetStringWidth(_hSelf, buf);
if (width > maxwidth)
maxwidth = width;
_rc.bottom += rc.bottom - rc.top;
}
_rc.right = maxwidth + imgWidth + leftMarge;
ListView_SetColumnWidth(_hSelf, 0, _rc.right);
::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFont), 0);
reSizeTo(_rc);
winVer ver = (NppParameters::getInstance())->getWinVersion();
_rc.bottom += (ver <= WV_XP && ver != WV_UNKNOWN)?xpBottomMarge:w7BottomMarge;
// Task List's border is 1px smaller than ::GetSystemMetrics(SM_CYFRAME) returns
_rc.bottom += (::GetSystemMetrics(SM_CYFRAME) - 1) * 2;
return _rc;
}

View File

@ -72,7 +72,7 @@ INT_PTR CALLBACK TaskListDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lP
i2set = 0;
_taskList.init(_hInst, _hSelf, _hImalist, nbTotal, i2set);
_taskList.setFont(TEXT("Verdana"), 14);
_taskList.setFont(TEXT("Verdana"), NppParameters::getInstance()->_dpiManager.scaleY(14));
_rc = _taskList.adjustSize();
reSizeTo(_rc);
@ -172,7 +172,9 @@ void TaskListDlg::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
int nItem = lpDrawItemStruct->itemID;
const TCHAR *label = _taskListInfo._tlfsLst[nItem]._fn.c_str();
int iImage = _taskListInfo._tlfsLst[nItem]._status;
const int aSpaceWidth = ListView_GetStringWidth(_taskList.getHSelf(), TEXT(" "));
COLORREF textColor = darkGrey;
int imgStyle = ILD_SELECTED;
@ -189,25 +191,19 @@ void TaskListDlg::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
HIMAGELIST hImgLst = _taskList.getImgLst();
IMAGEINFO info;
ImageList_GetImageInfo(hImgLst, iImage, &info);
::ImageList_GetImageInfo(hImgLst, iImage, &info);
RECT & imageRect = info.rcImage;
//int yPos = (rect.top + (rect.bottom - rect.top)/2 + (isSelected?0:2)) - (imageRect.bottom - imageRect.top)/2;
SIZE charPixel;
::GetTextExtentPoint(hDC, TEXT(" "), 1, &charPixel);
int spaceUnit = charPixel.cx;
int marge = spaceUnit;
// center icon position, prefer bottom orientation
imageRect.top = ((rect.bottom - rect.top) - (imageRect.bottom - imageRect.top) + 1) / 2;
rect.left += marge;
ImageList_Draw(hImgLst, iImage, hDC, rect.left, rect.top, imgStyle);
rect.left += imageRect.right - imageRect.left + spaceUnit * 2;
rect.left += aSpaceWidth;
::ImageList_Draw(hImgLst, iImage, hDC, rect.left, rect.top + imageRect.top, imgStyle);
rect.left += imageRect.right - imageRect.left + aSpaceWidth * 2;
//
// DRAW TEXT
//
::SetTextColor(hDC, textColor);
rect.top -= ::GetSystemMetrics(SM_CYEDGE);
::DrawText(hDC, label, lstrlen(label), &rect, DT_SINGLELINE | DT_VCENTER | DT_LEFT);
}