From 121431983967e9253bae3d5737a4164491c7434e Mon Sep 17 00:00:00 2001 From: ozone10 Date: Wed, 28 Jul 2021 14:12:24 +0200 Subject: [PATCH] Don't reset style & icons, when changing dark tone Improve title bar dynamic redraw when changing mode. Fix #10049, fix #10196, close #10272 --- PowerEditor/src/Notepad_plus.cpp | 165 +++++++++++++++---------------- PowerEditor/src/Notepad_plus.h | 4 +- PowerEditor/src/NppBigSwitch.cpp | 2 +- PowerEditor/src/NppDarkMode.cpp | 9 +- 4 files changed, 91 insertions(+), 89 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 75e3cb3f7..3c8daf8c6 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -7576,26 +7576,40 @@ void Notepad_plus::restoreMinimizeDialogs() } } -void Notepad_plus::refreshDarkMode() +void Notepad_plus::refreshDarkMode(bool resetStyle) { NppParameters& nppParams = NppParameters::getInstance(); SendMessage(_pPublicInterface->getHSelf(), NPPM_SETEDITORBORDEREDGE, 0, nppParams.getSVP()._showBorderEdge); - if (NppDarkMode::isExperimentalSupported()) + + if (resetStyle && NppDarkMode::isExperimentalSupported()) { NppDarkMode::allowDarkModeForApp(NppDarkMode::isEnabled()); - } - NppDarkMode::setDarkTitleBar(_pPublicInterface->getHSelf()); - for (auto &hwndDlg : _hModelessDlgs) - { - NppDarkMode::setDarkTitleBar(hwndDlg); - ::SendMessage(hwndDlg, NPPM_INTERNAL_REFRESHDARKMODE, 0, 0); - ::RedrawWindow(hwndDlg, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN); + NppDarkMode::setDarkTitleBar(_pPublicInterface->getHSelf()); + ::SetWindowPos(_pPublicInterface->getHSelf(), nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); + + for (auto& docCont : _dockingManager.getContainerInfo()) + { + NppDarkMode::setDarkTitleBar(docCont->getCaptionWnd()); + ::SetWindowPos(docCont->getCaptionWnd(), nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); + } + + for (auto& hwndDlg : _hModelessDlgs) + { + NppDarkMode::setDarkTitleBar(hwndDlg); + ::SendMessage(hwndDlg, NPPM_INTERNAL_REFRESHDARKMODE, 0, 0); + ::RedrawWindow(hwndDlg, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN); + ::SetWindowPos(hwndDlg, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); + } } - for (auto &docCont : _dockingManager.getContainerInfo()) + else { - NppDarkMode::setDarkTitleBar(docCont->getCaptionWnd()); + for (auto& hwndDlg : _hModelessDlgs) + { + ::SendMessage(hwndDlg, NPPM_INTERNAL_REFRESHDARKMODE, 0, 0); + ::RedrawWindow(hwndDlg, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN); + } } if (_pProjectPanel_1) @@ -7645,89 +7659,74 @@ void Notepad_plus::refreshDarkMode() ::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) + if (resetStyle && NppDarkMode::isExperimentalSupported()) { - case TB_SMALL: - _toolBar.reduce(); - break; - - case TB_LARGE: - _toolBar.enlarge(); - break; - - case TB_SMALL2: - _toolBar.reduceToSet2(); - break; - - case TB_LARGE2: - _toolBar.enlargeToSet2(); - break; - - case TB_STANDARD: - // Force standard colorful icon to Fluent UI small icon in dark mode - if (NppDarkMode::isEnabled()) - _toolBar.reduce(); - break; + NppDarkMode::setDarkTitleBar(_findInFinderDlg.getHSelf()); + ::SetWindowPos(_findInFinderDlg.getHSelf(), nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); } - ThemeSwitcher & themeSwitcher = nppParams.getThemeSwitcher(); - generic_string themePath; - generic_string themeName; - const TCHAR darkModeXmlFileName[] = TEXT("DarkModeDefault.xml"); - if (NppDarkMode::isEnabled()) + if (resetStyle) { - themePath = themeSwitcher.getThemeDirPath(); - PathAppend(themePath, darkModeXmlFileName); - - themeName = themeSwitcher.getThemeFromXmlFileName(themePath.c_str()); - } - else - { - //use _stylerPath; - - pair & themeInfo = themeSwitcher.getElementFromIndex(0); - themePath = themeInfo.second; - themeName = themeSwitcher.getDefaultThemeLabel(); - } - - if (::PathFileExists(themePath.c_str())) - { - nppParams.getNppGUI()._themeName = themePath; - - if (_configStyleDlg.isCreated()) + toolBarStatusType state = _toolBar.getState(); + switch (state) { - _configStyleDlg.selectThemeByName(themeName.c_str()); + case TB_SMALL: + _toolBar.reduce(); + break; + + case TB_LARGE: + _toolBar.enlarge(); + break; + + case TB_SMALL2: + _toolBar.reduceToSet2(); + break; + + case TB_LARGE2: + _toolBar.enlargeToSet2(); + break; + + case TB_STANDARD: + // Force standard colorful icon to Fluent UI small icon in dark mode + if (NppDarkMode::isEnabled()) + _toolBar.reduce(); + break; + } + + ThemeSwitcher& themeSwitcher = nppParams.getThemeSwitcher(); + generic_string themePath; + generic_string themeName; + const TCHAR darkModeXmlFileName[] = TEXT("DarkModeDefault.xml"); + if (NppDarkMode::isEnabled()) + { + themePath = themeSwitcher.getThemeDirPath(); + PathAppend(themePath, darkModeXmlFileName); + + themeName = themeSwitcher.getThemeFromXmlFileName(themePath.c_str()); } else { - nppParams.reloadStylers(themePath.c_str()); - ::SendMessage(_pPublicInterface->getHSelf(), WM_UPDATESCINTILLAS, 0, 0); + //use _stylerPath; + + pair& themeInfo = themeSwitcher.getElementFromIndex(0); + themePath = themeInfo.second; + themeName = themeSwitcher.getDefaultThemeLabel(); } - } - if (NppDarkMode::isExperimentalSupported()) - { - RECT rcClient; - - GetWindowRect(_pPublicInterface->getHSelf(), &rcClient); + if (::PathFileExists(themePath.c_str())) + { + nppParams.getNppGUI()._themeName = themePath; - // Inform application of the frame change. - SetWindowPos(_pPublicInterface->getHSelf(), - NULL, - rcClient.left, rcClient.top, - rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, - SWP_FRAMECHANGED); - - GetWindowRect(_findReplaceDlg.getHSelf(), &rcClient); - - // Inform application of the frame change. - SetWindowPos(_findReplaceDlg.getHSelf(), - NULL, - rcClient.left, rcClient.top, - rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, - SWP_FRAMECHANGED); + if (_configStyleDlg.isCreated()) + { + _configStyleDlg.selectThemeByName(themeName.c_str()); + } + else + { + nppParams.reloadStylers(themePath.c_str()); + ::SendMessage(_pPublicInterface->getHSelf(), WM_UPDATESCINTILLAS, 0, 0); + } + } } } diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index beef3e325..2266fec7f 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -264,7 +264,7 @@ public: void minimizeDialogs(); void restoreMinimizeDialogs(); - void refreshDarkMode(); + void refreshDarkMode(bool resetStyle = false); private: Notepad_plus_Window *_pPublicInterface = nullptr; @@ -642,5 +642,3 @@ private: void monitoringStartOrStopAndUpdateUI(Buffer* pBuf, bool isStarting); void updateCommandShortcuts(); }; - - diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 286558bed..a7981ad38 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -199,7 +199,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case NPPM_INTERNAL_REFRESHDARKMODE: { - refreshDarkMode(); + refreshDarkMode(static_cast(wParam)); return TRUE; } diff --git a/PowerEditor/src/NppDarkMode.cpp b/PowerEditor/src/NppDarkMode.cpp index 1a01edbf9..a839c6c78 100644 --- a/PowerEditor/src/NppDarkMode.cpp +++ b/PowerEditor/src/NppDarkMode.cpp @@ -332,7 +332,9 @@ namespace NppDarkMode } HWND hwndRoot = GetAncestor(hwnd, GA_ROOTOWNER); - ::SendMessage(hwndRoot, NPPM_INTERNAL_REFRESHDARKMODE, 0, 0); + + // wParam == true, will reset style and toolbar icon + ::SendMessage(hwndRoot, NPPM_INTERNAL_REFRESHDARKMODE, static_cast(!forceRefresh), 0); } bool isEnabled() @@ -1402,7 +1404,10 @@ namespace NppDarkMode , theme }; - ::EnableThemeDialogTexture(hwndParent, theme ? ETDT_ENABLETAB : ETDT_DISABLE); + if (subclass) + { + ::EnableThemeDialogTexture(hwndParent, theme ? ETDT_ENABLETAB : ETDT_DISABLE); + } EnumChildWindows(hwndParent, [](HWND hwnd, LPARAM lParam) { auto& p = *reinterpret_cast(lParam);