diff --git a/Build/Notepad3.ini b/Build/Notepad3.ini index 715bca556..266fe26c1 100644 --- a/Build/Notepad3.ini +++ b/Build/Notepad3.ini @@ -98,6 +98,7 @@ SettingsVersion=4 ;27=Monitoring Log ;28=History ;29=Always On Top +;30=Search in Files [Custom Colors] [Styles] [Common Base] diff --git a/grepWinNP3/src/AboutDlg.cpp b/grepWinNP3/src/AboutDlg.cpp index e752d371e..24f8cb354 100644 --- a/grepWinNP3/src/AboutDlg.cpp +++ b/grepWinNP3/src/AboutDlg.cpp @@ -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); diff --git a/src/Dialogs.c b/src/Dialogs.c index 9e2c35001..dbc9ac50d 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -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 diff --git a/src/Dialogs.h b/src/Dialogs.h index 1163ac68d..c9e1c9604 100644 --- a/src/Dialogs.h +++ b/src/Dialogs.h @@ -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); // ---------------------------------------------------------------------------- diff --git a/src/Edit.c b/src/Edit.c index 1e9922cf9..d044f8a93 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -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); } } diff --git a/src/Styles.c b/src/Styles.c index e7ae86413..9a1d9d86b 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -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;