From a9deca0bc9399319d750158c1b50d3bf8bfb35d4 Mon Sep 17 00:00:00 2001 From: rkotten Date: Tue, 21 Mar 2023 19:04:10 +0100 Subject: [PATCH] +chg: Default Print Colour Mode depending on Dark/Light Mode --- src/Config/Config.cpp | 13 ++++++------ src/Print.cpp | 46 ++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index 4cb3e7d7a..3e2250c94 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -1650,6 +1650,11 @@ void LoadSettings() Settings.DefaultEncoding = ((Settings.DefaultEncoding == CPI_NONE) ? CPI_PREFERRED_ENCODING : (cpi_enc_t)Encoding_MapIniSetting(true, (int)Settings.DefaultEncoding)); Globals.fvCurFile.iEncoding = Settings.DefaultEncoding; +#ifdef D_NP3_WIN10_DARK_MODE + Defaults.WinThemeDarkMode = ShouldAppsUseDarkModeEx(); + Settings.WinThemeDarkMode = IniSectionGetBool(IniSecSettings, L"WinThemeDarkMode", Defaults.WinThemeDarkMode) && IsDarkModeSupported(); +#endif + GET_BOOL_VALUE_FROM_INISECTION(UseDefaultForFileEncoding, false); GET_BOOL_VALUE_FROM_INISECTION(LoadASCIIasUTF8, true); GET_BOOL_VALUE_FROM_INISECTION(UseReliableCEDonly, true); @@ -1663,7 +1668,8 @@ void LoadSettings() GET_BOOL_VALUE_FROM_INISECTION(FixTrailingBlanks, false); GET_INT_VALUE_FROM_INISECTION(PrintHeader, 1, 0, 3); GET_INT_VALUE_FROM_INISECTION(PrintFooter, 0, 0, 1); - GET_INT_VALUE_FROM_INISECTION(PrintColorMode, 3, 0, 4); + int const defPrtColMod = Settings.WinThemeDarkMode ? SC_PRINT_INVERTLIGHT : SC_PRINT_COLOURONWHITE; + GET_INT_VALUE_FROM_INISECTION(PrintColorMode, defPrtColMod, SC_PRINT_NORMAL, SC_PRINT_SCREENCOLOURS); //int const zoomScale = 100; int const baseZoom = 100; @@ -1721,11 +1727,6 @@ void LoadSettings() GET_BOOL_VALUE_FROM_INISECTION(SearchByClipboardIfEmpty, true); GET_BOOL_VALUE_FROM_INISECTION(ReplaceByClipboardTag, true); -#ifdef D_NP3_WIN10_DARK_MODE - Defaults.WinThemeDarkMode = ShouldAppsUseDarkModeEx(); - Settings.WinThemeDarkMode = IniSectionGetBool(IniSecSettings, L"WinThemeDarkMode", Defaults.WinThemeDarkMode) && IsDarkModeSupported(); -#endif - ///~Settings2.IMEInteraction = clampi(IniSectionGetInt(IniSecSettings, L"IMEInteraction", Settings2.IMEInteraction), SC_IME_WINDOWED, SC_IME_INLINE); // see TBBUTTON s_tbbMainWnd[] for initial/reset set of buttons diff --git a/src/Print.cpp b/src/Print.cpp index 7c644b74b..d1e914943 100644 --- a/src/Print.cpp +++ b/src/Print.cpp @@ -88,8 +88,8 @@ static UINT_PTR CALLBACK _LPPrintHookProc(HWND hwnd, UINT uiMsg, WPARAM wParam, SetExplorerTheme(GetDlgItem(hwnd, IDCANCEL)); SetExplorerTheme(GetDlgItem(hwnd, 0x401)); int const ctl[] = { chx1, rad1, rad2, rad3, grp1, grp2, grp4, cmb4 }; - for (int i = 0; i < COUNTOF(ctl); ++i) { - SetWindowTheme(GetDlgItem(hwnd, ctl[i]), L"", L""); // remove theme for BS_AUTORADIOBUTTON + for (int i : ctl) { + SetWindowTheme(GetDlgItem(hwnd, i), L"", L""); // remove theme for BS_AUTORADIOBUTTON } } #endif @@ -104,7 +104,7 @@ static UINT_PTR CALLBACK _LPPrintHookProc(HWND hwnd, UINT uiMsg, WPARAM wParam, #ifdef D_NP3_WIN10_DARK_MODE -CASE_WM_CTLCOLOR_SET: + CASE_WM_CTLCOLOR_SET: return SetDarkModeCtlColors((HDC)wParam, UseDarkMode()); break; @@ -121,8 +121,8 @@ CASE_WM_CTLCOLOR_SET: RefreshTitleBarThemeColor(hwnd); int const buttons[] = { IDOK, IDCANCEL, 0x401 }; - for (int id = 0; id < COUNTOF(buttons); ++id) { - HWND const hBtn = GetDlgItem(hwnd, buttons[id]); + for (int button : buttons) { + HWND const hBtn = GetDlgItem(hwnd, button); AllowDarkModeForWindowEx(hBtn, darkModeEnabled); SendMessage(hBtn, WM_THEMECHANGED, 0, 0); } @@ -155,6 +155,8 @@ extern "C" bool EditPrint(HWND hwnd,LPCWSTR pszDocTitle,LPCWSTR pszPageFormat) InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_PRINT_EMPTY); return true; } + constexpr COLORREF const colorBlack = RGB(0x00, 0x00, 0x00); + constexpr COLORREF const colorWhite = RGB(0xFF, 0xFF, 0xFF); PRINTDLG pdlg = { sizeof(PRINTDLG), nullptr, nullptr, nullptr, nullptr, 0, 0, 0, 0, 0, 0, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr @@ -342,7 +344,7 @@ extern "C" bool EditPrint(HWND hwnd,LPCWSTR pszDocTitle,LPCWSTR pszPageFormat) } // Set print color mode - int printColorModes[6] = { + constexpr int const printColorModes[6] = { SC_PRINT_NORMAL, SC_PRINT_INVERTLIGHT, SC_PRINT_BLACKONWHITE, @@ -380,7 +382,7 @@ extern "C" bool EditPrint(HWND hwnd,LPCWSTR pszDocTitle,LPCWSTR pszPageFormat) } // We must substract the physical margins from the printable area - struct Sci_RangeToFormat frPrint; + struct Sci_RangeToFormat frPrint = { nullptr }; frPrint.hdc = hdc; frPrint.hdcTarget = hdc; frPrint.rc.left = rectMargins.left - rectPhysMargins.left; @@ -414,8 +416,8 @@ extern "C" bool EditPrint(HWND hwnd,LPCWSTR pszDocTitle,LPCWSTR pszPageFormat) StartPage(hdc); - SetTextColor(hdc, RGB(0,0,0)); - SetBkColor(hdc, RGB(0xFF, 0xFF, 0xFF)); + SetTextColor(hdc, colorBlack); + SetBkColor(hdc, colorWhite); SelectObject(hdc, fontHeader); UINT ta = SetTextAlign(hdc, TA_BOTTOM); RECT rcw = {frPrint.rc.left, frPrint.rc.top - headerLineHeight - headerLineHeight / 2, @@ -442,7 +444,7 @@ extern "C" bool EditPrint(HWND hwnd,LPCWSTR pszDocTitle,LPCWSTR pszPageFormat) if (Settings.PrintHeader < 3) { SetTextAlign(hdc, ta); HPEN pen = CreatePen(0, 1, RGB(0,0,0)); - HPEN const penOld = (HPEN)SelectObject(hdc, pen); + auto const penOld = (HPEN)SelectObject(hdc, pen); MoveToEx(hdc, frPrint.rc.left, frPrint.rc.top - headerLineHeight / 4, nullptr); LineTo(hdc, frPrint.rc.right, frPrint.rc.top - headerLineHeight / 4); SelectObject(hdc, penOld); @@ -456,8 +458,8 @@ extern "C" bool EditPrint(HWND hwnd,LPCWSTR pszDocTitle,LPCWSTR pszPageFormat) lengthPrinted = (int)SendMessage(hwnd, SCI_FORMATRANGE, printPage, (LPARAM)&frPrint); if (printPage) { - SetTextColor(hdc, RGB(0,0,0)); - SetBkColor(hdc, RGB(0xFF, 0xFF, 0xFF)); + SetTextColor(hdc, colorBlack); + SetBkColor(hdc, colorWhite); SelectObject(hdc, fontFooter); UINT ta = SetTextAlign(hdc, TA_TOP); RECT rcw = {frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 2, @@ -473,8 +475,8 @@ extern "C" bool EditPrint(HWND hwnd,LPCWSTR pszDocTitle,LPCWSTR pszPageFormat) SetTextAlign(hdc, ta); HPEN pen = ::CreatePen(0, 1, RGB(0,0,0)); - HPEN const penOld = (HPEN)SelectObject(hdc, pen); - SetBkColor(hdc, RGB(0,0,0)); + auto const penOld = (HPEN)SelectObject(hdc, pen); + SetBkColor(hdc, colorWhite); MoveToEx(hdc, frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 4, nullptr); LineTo(hdc, frPrint.rc.right, frPrint.rc.bottom + footerLineHeight / 4); SelectObject(hdc, penOld); @@ -543,8 +545,8 @@ static UINT_PTR CALLBACK _LPSetupHookProc(HWND hwnd, UINT uiMsg, WPARAM wParam, int const ctl[] = { 30, 31, 32, 33, 34, cmb2, cmb3, 1037, 1038, 1056, 1057, 1072, 1073, 1074, 1075, 1076, 1089, 1090, IDC_STATIC, IDC_STATIC2, IDC_STATIC3, IDC_STATIC4, IDC_STATIC5, IDC_STATIC6 }; - for (int i = 0; i < COUNTOF(ctl); ++i) { - SetWindowTheme(GetDlgItem(hwnd, ctl[i]), L"", L""); // remove theme for BS_AUTORADIOBUTTON + for (int i : ctl) { + SetWindowTheme(GetDlgItem(hwnd, i), L"", L""); // remove theme for BS_AUTORADIOBUTTON } } #endif @@ -634,8 +636,8 @@ CASE_WM_CTLCOLOR_SET: RefreshTitleBarThemeColor(hwnd); int const buttons[] = { IDOK, IDCANCEL, IDC_PRINTER }; - for (int id = 0; id < COUNTOF(buttons); ++id) { - HWND const hBtn = GetDlgItem(hwnd, buttons[id]); + for (int button : buttons) { + HWND const hBtn = GetDlgItem(hwnd, button); AllowDarkModeForWindowEx(hBtn, darkModeEnabled); SendMessage(hBtn, WM_THEMECHANGED, 0, 0); } @@ -647,12 +649,12 @@ CASE_WM_CTLCOLOR_SET: case WM_COMMAND: if (IsYesOkay(wParam)) { BOOL bError = FALSE; - int const iZoom = (int)SendDlgItemMessage(hwnd, 31, UDM_GETPOS32, 0, (LPARAM)&bError); + auto const iZoom = static_cast(SendDlgItemMessage(hwnd, 31, UDM_GETPOS32, 0, (LPARAM)&bError)); Settings.PrintZoom = bError ? Defaults.PrintZoom : iZoom; /*int const iFontSize = (int)*/ SendDlgItemMessage(hwnd, 41, UDM_GETPOS32, 0, (LPARAM)&bError); - Settings.PrintHeader = (int)SendDlgItemMessage(hwnd, 32, CB_GETCURSEL, 0, 0); - Settings.PrintFooter = (int)SendDlgItemMessage(hwnd, 33, CB_GETCURSEL, 0, 0); - Settings.PrintColorMode = (int)SendDlgItemMessage(hwnd, 34, CB_GETCURSEL, 0, 0); + Settings.PrintHeader = static_cast(SendDlgItemMessage(hwnd, 32, CB_GETCURSEL, 0, 0)); + Settings.PrintFooter = static_cast(SendDlgItemMessage(hwnd, 33, CB_GETCURSEL, 0, 0)); + Settings.PrintColorMode = static_cast(SendDlgItemMessage(hwnd, 34, CB_GETCURSEL, 0, 0)); } else if (LOWORD(wParam) == IDC_PRINTER) { PostWMCommand(hwnd, 1026); }