Merge pull request #2620 from RaiKoHoff/Dev_NewFeatures

Relative calculation of title font size for AboutBox and CS dialog
This commit is contained in:
Rainer Kottenhoff 2020-08-08 00:04:46 +02:00 committed by GitHub
commit 63d0653414
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 144 additions and 107 deletions

View File

@ -98,6 +98,7 @@ SettingsVersion=4
;27=Monitoring Log
;28=History
;29=Always On Top
;30=Search in Files
[Custom Colors]
[Styles]
[Common Base]

View File

@ -42,7 +42,7 @@ static LRESULT DrawGrepWinIcon(HWND hWnd)
if (g_hDlgIcon128)
{
PAINTSTRUCT ps;
HDC const hDC = GetWindowDC(hWnd);
HDC const hDC = GetDC(hWnd);
if (hDC)
{
BeginPaint(hWnd, &ps);

View File

@ -92,28 +92,16 @@ static LRESULT CALLBACK SetPosRelatedToParent_Hook(INT nCode, WPARAM wParam, LPA
GetWindowRect(hParentWnd, &rcParent);
// set new coordinates
DPI_T const dpi = Scintilla_GetWindowDPI(hParentWnd);
RECT rcDlg;
rcDlg.left = pCreateStructure->x;
rcDlg.top = pCreateStructure->y;
rcDlg.right = pCreateStructure->x + pCreateStructure->cx;
rcDlg.bottom = pCreateStructure->y + pCreateStructure->cy;
if (dpi.y == USER_DEFAULT_SCREEN_DPI) {
RECT rcDlg;
rcDlg.left = pCreateStructure->x;
rcDlg.top = pCreateStructure->y;
rcDlg.right = pCreateStructure->x + pCreateStructure->cx;
rcDlg.bottom = pCreateStructure->y + pCreateStructure->cy;
POINT const ptTL = GetCenterOfDlgInParent(&rcDlg, &rcParent);
POINT const ptTL = GetCenterOfDlgInParent(&rcDlg, &rcParent);
pCreateStructure->x = ptTL.x;
pCreateStructure->y = ptTL.y;
}
else {
// don't know how to handle DPI Awareness
//pCreateStructure->x = rcParent.left + 20;
//pCreateStructure->y = rcParent.top + 20;
//pCreateStructure->x = MulDiv(rcParent.left + (rcParent.right - rcParent.left)/8, USER_DEFAULT_SCREEN_DPI, dpi.x);
//pCreateStructure->y = MulDiv(rcParent.top + (rcParent.bottom - rcParent.top)/2, USER_DEFAULT_SCREEN_DPI, dpi.y);
}
pCreateStructure->x = ptTL.x;
pCreateStructure->y = ptTL.y;
}
// we are done
@ -755,6 +743,21 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam
CenterDlgInParent(hwnd, NULL);
HFONT const hFont = (HFONT)SendDlgItemMessage(hwnd, IDC_SCI_VERSION, WM_GETFONT, 0, 0);
if (hFont) {
LOGFONT lf;
GetObject(hFont, sizeof(LOGFONT), &lf);
lf.lfHeight = MulDiv(lf.lfHeight, 3, 2);
lf.lfWeight = FW_BOLD;
//lf.lfUnderline = true;
if (hVersionFont) {
DeleteObject(hVersionFont);
}
hVersionFont = CreateFontIndirectW(&lf);
SendDlgItemMessageW(hwnd, IDC_VERSION, WM_SETFONT, (WPARAM)hVersionFont, true);
}
// render rich-edit control text again
if (!StrIsEmptyA(pAboutResource)) {
pAboutInfo = pAboutResource;
@ -800,44 +803,49 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam
SetBitmapControlResample(hwnd, IDC_RIZONEBMP, hBmp, width, height);
DeleteObject(hBmp);
HFONT const hFont = (HFONT)SendDlgItemMessage(hwnd, IDC_SCI_VERSION, WM_GETFONT, 0, 0);
if (hFont) {
LOGFONT lf;
GetObject(hFont, sizeof(LOGFONT), &lf);
lf.lfHeight = MulDiv(lf.lfHeight, 3, 2);
lf.lfWeight = FW_BOLD;
//lf.lfUnderline = true;
if (hVersionFont) {
DeleteObject(hVersionFont);
}
hVersionFont = CreateFontIndirectW(&lf);
SendDlgItemMessageW(hwnd, IDC_VERSION, WM_SETFONT, (WPARAM)hVersionFont, true);
}
UpdateWindowLayoutForDPI(hwnd, (RECT*)lParam, NULL);
}
break;
case WM_PAINT:
{
HDC const hdc = GetWindowDC(hwnd);
SetMapMode(hdc, MM_TEXT);
PAINTSTRUCT ps;
HDC const hdc = GetDC(hwnd); // ClientArea
if (hdc) {
BeginPaint(hwnd, &ps);
SetMapMode(hdc, MM_TEXT);
int const iconSize = 128;
int const dpiWidth = ScaleIntByDPI(iconSize, dpi.x);
int const dpiHeight = ScaleIntByDPI(iconSize, dpi.y);
HICON const hicon = (dpiHeight > 128) ? Globals.hDlgIcon256 : Globals.hDlgIcon128;
if (hicon) {
//RECT rc = {0};
//MapWindowPoints(GetDlgItem(hwnd, IDC_INFO_GROUPBOX), hwnd, (LPPOINT)&rc, 2);
DrawIconEx(hdc, ScaleIntByDPI(22, dpi.x), ScaleIntByDPI(44, dpi.x), hicon, dpiWidth, dpiHeight, 0, NULL, DI_NORMAL);
}
// --- larger bold condensed version string
NONCLIENTMETRICSW ncMetrics = {0};
ncMetrics.cbSize = sizeof(NONCLIENTMETRICSW);
if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncMetrics, 0))
{
if (hVersionFont) {
DeleteObject(hVersionFont);
int const iconSize = 128;
int const dpiWidth = ScaleIntByDPI(iconSize, dpi.x);
int const dpiHeight = ScaleIntByDPI(iconSize, dpi.y);
HICON const hicon = (dpiHeight > 128) ? Globals.hDlgIcon256 : Globals.hDlgIcon128;
if (hicon) {
//RECT rc = {0};
//MapWindowPoints(GetDlgItem(hwnd, IDC_INFO_GROUPBOX), hwnd, (LPPOINT)&rc, 2);
DrawIconEx(hdc, ScaleIntByDPI(10, dpi.x), ScaleIntByDPI(10, dpi.x), hicon, dpiWidth, dpiHeight, 0, NULL, DI_NORMAL);
}
int const verFontSize = ScaleIntByDPI(14, dpi.y);
ncMetrics.lfMessageFont.lfWeight = FW_BOLD;
ncMetrics.lfMessageFont.lfHeight = -MulDiv(verFontSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
hVersionFont = CreateFontIndirectW(&ncMetrics.lfMessageFont);
SendDlgItemMessage(hwnd, IDC_VERSION, WM_SETFONT, (WPARAM)hVersionFont, true);
}
ReleaseDC(hwnd, hdc);
ReleaseDC(hwnd, hdc);
EndPaint(hwnd, &ps);
}
}
return 0;
case WM_NOTIFY:
{
LPNMHDR pnmhdr = (LPNMHDR)lParam;
@ -4471,18 +4479,6 @@ DPI_T GetCurrentPPI(HWND hwnd) {
return ppi;
}
/*
if (!bSucceed) {
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(NONCLIENTMETRICS),&ncm,0);
if (ncm.lfMessageFont.lfHeight < 0)
ncm.lfMessageFont.lfHeight = -ncm.lfMessageFont.lfHeight;
*wSize = (WORD)MulDiv(ncm.lfMessageFont.lfHeight,72,iLogPixelsY);
if (*wSize == 0)
*wSize = 8;
}*/
/*
@ -4802,6 +4798,7 @@ HBITMAP ResampleImageBitmap(HWND hwnd, HBITMAP hbmp, int width, int height)
return hbmp;
}
//=============================================================================
//
// SendWMSize()
@ -4817,6 +4814,42 @@ LRESULT SendWMSize(HWND hwnd, RECT* rc)
}
#if FALSE
//=============================================================================
//
// CreateAndSetFontDlgItemDPI()
//
HFONT CreateAndSetFontDlgItemDPI(HWND hdlg, const int idDlgItem, int fontSize, bool bold)
{
NONCLIENTMETRICSW ncm = {0};
ncm.cbSize = sizeof(NONCLIENTMETRICSW);
if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncm, 0)) {
HDC const hdcSys = GetDC(NULL);
DPI_T const dpiSys = Scintilla_GetWindowDPI(NULL);
DPI_T const dpiDlg = Scintilla_GetWindowDPI(hdlg);
if (fontSize <= 0) {
fontSize = (ncm.lfMessageFont.lfHeight < 0) ? -ncm.lfMessageFont.lfHeight : ncm.lfMessageFont.lfHeight;
if (fontSize == 0) {
fontSize = 8;
}
}
fontSize <<= 10; // precision
fontSize = MulDiv(fontSize, USER_DEFAULT_SCREEN_DPI, dpiSys.y); // correction
fontSize = ScaleIntByDPI(fontSize, dpiDlg.y);
ncm.lfMessageFont.lfHeight = -(MulDiv(fontSize, GetDeviceCaps(hdcSys, LOGPIXELSY), 72) >> 10);
ncm.lfMessageFont.lfWeight = bold ? FW_BOLD : FW_NORMAL;
HFONT const hFont = CreateFontIndirectW(&ncm.lfMessageFont);
if (idDlgItem > 0) {
SendDlgItemMessageW(hdlg, idDlgItem, WM_SETFONT, (WPARAM)hFont, true);
}
ReleaseDC(hdlg, hdcSys);
return hFont;
}
return NULL;
}
#endif
//=============================================================================
#if FALSE

View File

@ -163,6 +163,7 @@ void UpdateWindowLayoutForDPI(HWND hwnd, const RECT* pRC, const DPI_T* pDPI);
//#define BMP_RESAMPLE_FILTER STOCK_FILTER_QUADRATICBSPLINE
HBITMAP ResampleImageBitmap(HWND hwnd, HBITMAP hbmp, int width, int height);
LRESULT SendWMSize(HWND hwnd, RECT* rc);
//HFONT CreateAndSetFontDlgItemDPI(HWND hdlg, const int idDlgItem, int fontSize, bool bold);
// ----------------------------------------------------------------------------

View File

@ -7913,9 +7913,8 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam
static unsigned id_hover = 0;
static unsigned id_capture = 0;
static HFONT hFontNormal = NULL;
//static HFONT hFontNormal = NULL;
static HFONT hFontHover = NULL;
static HCURSOR hCursorNormal;
static HCURSOR hCursorHover;
@ -7927,35 +7926,20 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam
id_capture = 0;
SetDialogIconNP3(hwnd);
HDC const hdc = GetWindowDC(hwnd);
hFontNormal = (HFONT)SendDlgItemMessage(hwnd, 200, WM_GETFONT, 0, 0);
if (hFontNormal) {
HFONT const hFont = (HFONT)SendDlgItemMessage(hwnd, 200, WM_GETFONT, 0, 0);
if (hFont) {
LOGFONT lf;
GetObject(hFontNormal, sizeof(LOGFONT), &lf);
GetObject(hFont, sizeof(LOGFONT), &lf);
lf.lfUnderline = true;
//lf.lfWeight = FW_BOLD;
//lf.lfWeight = FW_BOLD;
if (hFontHover) {
DeleteObject(hFontHover);
}
hFontHover = CreateFontIndirectW(&lf);
}
else {
NONCLIENTMETRICSW ncMetrics = {0};
ncMetrics.cbSize = sizeof(NONCLIENTMETRICSW);
if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncMetrics, 0)) {
int const hoverFontSize = ScaleIntToDPI_Y(hwnd, 10);
//ncMetrics.lfMessageFont.lfWeight = FW_BOLD;
ncMetrics.lfMessageFont.lfUnderline = true;
ncMetrics.lfMessageFont.lfHeight = -MulDiv(hoverFontSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
if (hFontHover) {
DeleteObject(hFontHover);
}
hFontHover = CreateFontIndirectW(&ncMetrics.lfMessageFont);
}
}
hCursorNormal = LoadCursor(NULL,IDC_ARROW);
hCursorNormal = LoadCursor(NULL, IDC_ARROW);
hCursorHover = LoadCursor(NULL,IDC_HAND);
if (!hCursorHover) {
hCursorHover = LoadCursor(Globals.hInstance, IDC_ARROW);
@ -7975,10 +7959,10 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam
dpi.x = LOWORD(wParam);
dpi.y = HIWORD(wParam);
hFontNormal = (HFONT)SendDlgItemMessage(hwnd, 200, WM_GETFONT, 0, 0);
if (hFontNormal) {
HFONT const hFont = (HFONT)SendDlgItemMessage(hwnd, 200, WM_GETFONT, 0, 0);
if (hFont) {
LOGFONT lf;
GetObject(hFontNormal, sizeof(LOGFONT), &lf);
GetObject(hFont, sizeof(LOGFONT), &lf);
lf.lfUnderline = true;
//lf.lfWeight = FW_BOLD;
if (hFontHover) {
@ -7986,13 +7970,15 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam
}
hFontHover = CreateFontIndirectW(&lf);
}
UpdateWindowLayoutForDPI(hwnd, (RECT*)lParam, &dpi);
}
return !0;
case WM_DESTROY:
//DeleteObject(hFontNormal);
DeleteObject(hFontHover);
return false;
return 0;
case WM_NCACTIVATE:
if (!(bool)wParam) {
@ -8017,8 +8003,8 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam
else {
SetTextColor(hdc, RGB(0, 0, 0xFF));
}
SelectObject(hdc,hFontHover);
//SelectObject(hdc, (dwId == id_hover) ? hFontHover : hFontNormal);
SelectObject(hdc, hFontHover);
return (INT_PTR)GetSysColorBrush(COLOR_BTNFACE);
}
}

View File

@ -4099,8 +4099,20 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
bWarnedNoIniFile = false;
//~UpdateWindowLayoutForDPI(hwnd, NULL, NULL);
PostMessage(hwnd, WM_DPICHANGED, (WPARAM)NULL, (LPARAM)NULL);
// Set title font
HFONT const hFont = (HFONT)SendDlgItemMessage(hwnd, IDC_STYLELABEL, WM_GETFONT, 0, 0);
if (hFont) {
LOGFONT lf;
GetObject(hFont, sizeof(LOGFONT), &lf);
lf.lfHeight = MulDiv(lf.lfHeight, 3, 2);
lf.lfWeight = FW_BOLD;
//lf.lfUnderline = true;
if (hFontTitle) {
DeleteObject(hFontTitle);
}
hFontTitle = CreateFontIndirectW(&lf);
SendDlgItemMessageW(hwnd, IDC_TITLE, WM_SETFONT, (WPARAM)hFontTitle, true);
}
}
return !0;
@ -4118,6 +4130,21 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
flagIconSize | SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES),
TVSIL_NORMAL);
// Set title font
HFONT const hFont = (HFONT)SendDlgItemMessage(hwnd, IDC_STYLELABEL, WM_GETFONT, 0, 0);
if (hFont) {
LOGFONT lf;
GetObject(hFont, sizeof(LOGFONT), &lf);
lf.lfHeight = MulDiv(lf.lfHeight, 3, 2);
lf.lfWeight = FW_BOLD;
//lf.lfUnderline = true;
if (hFontTitle) {
DeleteObject(hFontTitle);
}
hFontTitle = CreateFontIndirectW(&lf);
SendDlgItemMessageW(hwnd, IDC_TITLE, WM_SETFONT, (WPARAM)hFontTitle, true);
}
MakeBitmapButton(hwnd, IDC_PREVSTYLE, IDB_PREV, -1, -1);
MakeBitmapButton(hwnd, IDC_NEXTSTYLE, IDB_NEXT, -1, -1);
@ -4127,8 +4154,10 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
case WM_PAINT:
{
HDC const hdc = GetWindowDC(hwnd);
SetMapMode(hdc, MM_TEXT);
PAINTSTRUCT ps;
HDC const hdc = GetDC(hwnd); // ClientArea
if (hdc) {
BeginPaint(hwnd, &ps);
DPI_T const dpi = Scintilla_GetWindowDPI(hwnd);
@ -4140,25 +4169,12 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
{
RECT rc = {0};
MapWindowPoints(GetDlgItem(hwnd, IDC_INFO_GROUPBOX), hwnd, (LPPOINT)&rc, 2);
DrawIconEx(hdc, rc.left + ScaleIntByDPI(20, dpi.x), rc.top + ScaleIntByDPI(50, dpi.y), hicon, dpiWidth, dpiHeight, 0, NULL, DI_NORMAL);
}
// Set title font
NONCLIENTMETRICSW ncMetrics = {0};
ncMetrics.cbSize = sizeof(NONCLIENTMETRICSW);
if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncMetrics, 0))
{
if (hFontTitle) {
DeleteObject(hFontTitle);
}
int const verFontSize = ScaleIntByDPI(16, dpi.y);
ncMetrics.lfMessageFont.lfWeight = FW_BOLD;
ncMetrics.lfMessageFont.lfHeight = -MulDiv(verFontSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
hFontTitle = CreateFontIndirectW(&ncMetrics.lfMessageFont);
SendDlgItemMessage(hwnd, IDC_TITLE, WM_SETFONT, (WPARAM)hFontTitle, true);
DrawIconEx(hdc, rc.left + ScaleIntByDPI(10, dpi.x), rc.top + ScaleIntByDPI(20, dpi.y), hicon, dpiWidth, dpiHeight, 0, NULL, DI_NORMAL);
}
ReleaseDC(hwnd, hdc);
EndPaint(hwnd, &ps);
}
}
return 0;