From 89d835a56f14a45a923e647d144ede0dc606c32f Mon Sep 17 00:00:00 2001 From: ozone10 Date: Sat, 24 Jul 2021 14:17:40 +0200 Subject: [PATCH] Apply dark mode on all find dialogs 1. Apply dark mode on find in finder dialog. 2. Apply dark mode on progress window (searching in files). 3. Make color more consistent for incremental search. 4. Use different border style for incremental search. 5. Set border for finder for docking panel consistency. Fix #10233, close #10234 --- PowerEditor/src/Notepad_plus.cpp | 3 + PowerEditor/src/NppDarkMode.cpp | 26 ++++- PowerEditor/src/NppDarkMode.h | 1 + .../src/ScintillaComponent/FindReplaceDlg.cpp | 104 +++++++++++++++++- .../src/ScintillaComponent/FindReplaceDlg.rc | 2 +- 5 files changed, 132 insertions(+), 4 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 6dd2a622b..b74298da9 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -7575,6 +7575,9 @@ void Notepad_plus::refreshDarkMode() RedrawWindow(_pPublicInterface->getHSelf(), nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN); SendMessage(_pPublicInterface->getHSelf(), NPPM_INTERNAL_CHANGETABBAEICONS, 0, NppDarkMode::isEnabled() ? 2 : 0); + ::SendMessage(_findInFinderDlg.getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, 0); + ::RedrawWindow(_findInFinderDlg.getHSelf(), nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN); + toolBarStatusType state = _toolBar.getState(); switch (state) { diff --git a/PowerEditor/src/NppDarkMode.cpp b/PowerEditor/src/NppDarkMode.cpp index 79435c2e6..23f687b24 100644 --- a/PowerEditor/src/NppDarkMode.cpp +++ b/PowerEditor/src/NppDarkMode.cpp @@ -1563,7 +1563,7 @@ namespace NppDarkMode HWND hHeader = ListView_GetHeader(hwnd); NppDarkMode::allowDarkModeForWindow(hHeader, useDark); - SetWindowTheme(hHeader, L"ItemsView", nullptr); + SetWindowTheme(hHeader, useDark ? L"ItemsView" : nullptr, nullptr); NppDarkMode::allowDarkModeForWindow(hwnd, useDark); SetWindowTheme(hwnd, L"Explorer", nullptr); @@ -1587,6 +1587,30 @@ namespace NppDarkMode SetWindowTheme(hwnd, nullptr, nullptr); } + void setBorder(HWND hwnd, bool border) + { + auto style = static_cast(::GetWindowLongPtr(hwnd, GWL_STYLE)); + bool hasBorder = (style & WS_BORDER) == WS_BORDER; + bool change = false; + + if (!hasBorder && border) + { + style |= WS_BORDER; + change = true; + } + else if (hasBorder && !border) + { + style &= ~WS_BORDER; + change = true; + } + + if (change) + { + ::SetWindowLongPtr(hwnd, GWL_STYLE, style); + ::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); + } + } + LRESULT onCtlColor(HDC hdc) { ::SetTextColor(hdc, NppDarkMode::getTextColor()); diff --git a/PowerEditor/src/NppDarkMode.h b/PowerEditor/src/NppDarkMode.h index b944955b2..eaf235f6f 100644 --- a/PowerEditor/src/NppDarkMode.h +++ b/PowerEditor/src/NppDarkMode.h @@ -153,6 +153,7 @@ namespace NppDarkMode void disableVisualStyle(HWND hwnd, bool doDisable); void setTreeViewStyle(HWND hwnd); + void setBorder(HWND hwnd, bool border = true); LRESULT onCtlColor(HDC hdc); LRESULT onCtlColorSofter(HDC hdc); diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index 9ab7b179c..338ba7439 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -712,10 +712,61 @@ INT_PTR CALLBACK FindInFinderDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA { NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); pNativeSpeaker->changeDlgLang(_hSelf, "FindInFinder"); + + EnableThemeDialogTexture(_hSelf, ETDT_ENABLETAB); + NppDarkMode::autoSubclassAndThemeChildControls(_hSelf); + initFromOptions(); } return TRUE; + case WM_CTLCOLOREDIT: + { + if (NppDarkMode::isEnabled()) + { + return NppDarkMode::onCtlColorSofter(reinterpret_cast(wParam)); + } + break; + } + + case WM_CTLCOLORLISTBOX: + case WM_CTLCOLORDLG: + case WM_CTLCOLORSTATIC: + { + if (NppDarkMode::isEnabled()) + { + return NppDarkMode::onCtlColorDarker(reinterpret_cast(wParam)); + } + break; + } + + case WM_PRINTCLIENT: + { + if (NppDarkMode::isEnabled()) + { + return TRUE; + } + break; + } + + case WM_ERASEBKGND: + { + if (NppDarkMode::isEnabled()) + { + RECT rc = { 0 }; + getClientRect(rc); + ::FillRect(reinterpret_cast(wParam), &rc, NppDarkMode::getDarkerBackgroundBrush()); + return TRUE; + } + break; + } + + case NPPM_INTERNAL_REFRESHDARKMODE: + { + NppDarkMode::autoThemeChildControls(_hSelf); + return TRUE; + } + case WM_COMMAND: { switch (LOWORD(wParam)) @@ -767,6 +818,7 @@ INT_PTR CALLBACK FindInFinderDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA default: return FALSE; } + return FALSE; } @@ -896,6 +948,11 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM NppDarkMode::setDarkTooltips(_2ButtonsTip, NppDarkMode::ToolTipsType::tooltip); NppDarkMode::setDarkTooltips(_filterTip, NppDarkMode::ToolTipsType::tooltip); + if (_statusbarTooltipWnd) + { + NppDarkMode::setDarkTooltips(_statusbarTooltipWnd, NppDarkMode::ToolTipsType::tooltip); + } + HWND finder = getHFindResults(); if (finder) { @@ -3769,6 +3826,8 @@ void FindReplaceDlg::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) rect.right = rect.left + s; rect.bottom = rect.top + s; _statusbarTooltipWnd = CreateToolTipRect(1, _statusBar.getHSelf(), _hInst, const_cast(_statusbarTooltipMsg.c_str()), rect); + + NppDarkMode::setDarkTooltips(_statusbarTooltipWnd, NppDarkMode::ToolTipsType::tooltip); } } else @@ -4188,6 +4247,8 @@ void Finder::setFinderStyle() // Set global styles for the finder _scintView.performGlobalStyles(); + NppDarkMode::setBorder(_scintView.getHSelf()); + // Set current line background color for the finder const TCHAR * lexerName = ScintillaEditView::langNames[L_SEARCHRESULT].lexerName; LexerStyler *pStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(lexerName); @@ -4490,7 +4551,7 @@ INT_PTR CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR return DefWindowProc(getHSelf(), message, wParam, lParam); } - return NppDarkMode::onCtlColor(reinterpret_cast(wParam)); + return NppDarkMode::onCtlColorDarker(reinterpret_cast(wParam)); } case NPPM_INTERNAL_REFRESHDARKMODE: @@ -4503,6 +4564,7 @@ INT_PTR CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR { LRESULT lr = DefWindowProc(getHSelf(), message, wParam, lParam); + NppDarkMode::setBorder(::GetDlgItem(getHSelf(), IDC_INCFINDTEXT)); NppDarkMode::autoSubclassAndThemeChildControls(getHSelf()); return lr; } @@ -4608,7 +4670,7 @@ INT_PTR CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR { RECT rcClient = { 0 }; GetClientRect(_hSelf, &rcClient); - FillRect((HDC)wParam, &rcClient, NppDarkMode::getBackgroundBrush()); + ::FillRect(reinterpret_cast(wParam), &rcClient, NppDarkMode::getDarkerBackgroundBrush()); return TRUE; } else @@ -4875,6 +4937,17 @@ int Progress::createProgressWindow() _hwnd, NULL, _hInst, NULL); SendMessage(_hPBar, PBM_SETRANGE, 0, MAKELPARAM(0, 100)); + // Set border so user can distinguish easier progress bar, + // especially, when getBackgroundColor is very similar or same + // as getDarkerBackgroundColor + NppDarkMode::setBorder(_hPBar, NppDarkMode::isEnabled()); + NppDarkMode::disableVisualStyle(_hPBar, NppDarkMode::isEnabled()); + if (NppDarkMode::isEnabled()) + { + ::SendMessage(_hPBar, PBM_SETBKCOLOR, 0, static_cast(NppDarkMode::getBackgroundColor())); + ::SendMessage(_hPBar, PBM_SETBARCOLOR, 0, static_cast(NppDarkMode::getDarkerTextColor())); + } + _hBtn = ::CreateWindowEx(0, TEXT("BUTTON"), TEXT("Cancel"), WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_TEXT, (width - cBTNwidth) / 2, height - cBTNheight - 5, @@ -4883,6 +4956,9 @@ int Progress::createProgressWindow() if (hf) ::SendMessage(_hBtn, WM_SETFONT, reinterpret_cast(hf), MAKELPARAM(TRUE, 0)); + NppDarkMode::autoSubclassAndThemeChildControls(_hwnd); + NppDarkMode::setDarkTitleBar(_hwnd); + ::ShowWindow(_hwnd, SW_SHOWNORMAL); ::UpdateWindow(_hwnd); @@ -4974,6 +5050,30 @@ LRESULT APIENTRY Progress::wndProc(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM l return 0; } + case WM_CTLCOLORDLG: + case WM_CTLCOLORSTATIC: + { + if (NppDarkMode::isEnabled()) + { + return NppDarkMode::onCtlColorDarker(reinterpret_cast(wparam)); + } + + break; + } + + case WM_ERASEBKGND: + { + if (NppDarkMode::isEnabled()) + { + RECT rc = { 0 }; + GetClientRect(hwnd, &rc); + ::FillRect(reinterpret_cast(wparam), &rc, NppDarkMode::getDarkerBackgroundBrush()); + return TRUE; + } + + break; + } + case WM_SETFOCUS: { Progress* pw = reinterpret_cast(static_cast diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.rc b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.rc index a506f7d36..da17047fd 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.rc +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.rc @@ -93,7 +93,7 @@ FONT 8, TEXT("MS Shell Dlg") BEGIN PUSHBUTTON "X",IDCANCEL,2,3,16,14 RTEXT "Find :",IDC_INCSTATIC,20,6,25,12 - EDITTEXT IDC_INCFINDTEXT,45,6,175,10,ES_AUTOHSCROLL | ES_WANTRETURN | NOT WS_BORDER | WS_TABSTOP, WS_EX_STATICEDGE + EDITTEXT IDC_INCFINDTEXT,45,6,175,10,ES_AUTOHSCROLL | ES_WANTRETURN | NOT WS_BORDER | WS_TABSTOP PUSHBUTTON "<",IDC_INCFINDPREVOK,223,3,16,14, WS_TABSTOP PUSHBUTTON ">",IDC_INCFINDNXTOK,243,3,16,14, WS_TABSTOP CONTROL "&Highlight all", IDC_INCFINDHILITEALL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,270,5,65,12