Don't reset style & icons, when changing dark tone

Improve title bar dynamic redraw when changing mode.

Fix #10049, fix #10196, close #10272
This commit is contained in:
ozone10 2021-07-28 14:12:24 +02:00 committed by Don Ho
parent 5edc7500e9
commit 1214319839
4 changed files with 91 additions and 89 deletions

View File

@ -7576,26 +7576,40 @@ void Notepad_plus::restoreMinimizeDialogs()
} }
} }
void Notepad_plus::refreshDarkMode() void Notepad_plus::refreshDarkMode(bool resetStyle)
{ {
NppParameters& nppParams = NppParameters::getInstance(); NppParameters& nppParams = NppParameters::getInstance();
SendMessage(_pPublicInterface->getHSelf(), NPPM_SETEDITORBORDEREDGE, 0, nppParams.getSVP()._showBorderEdge); SendMessage(_pPublicInterface->getHSelf(), NPPM_SETEDITORBORDEREDGE, 0, nppParams.getSVP()._showBorderEdge);
if (NppDarkMode::isExperimentalSupported())
if (resetStyle && NppDarkMode::isExperimentalSupported())
{ {
NppDarkMode::allowDarkModeForApp(NppDarkMode::isEnabled()); NppDarkMode::allowDarkModeForApp(NppDarkMode::isEnabled());
}
NppDarkMode::setDarkTitleBar(_pPublicInterface->getHSelf()); 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) for (auto& hwndDlg : _hModelessDlgs)
{ {
NppDarkMode::setDarkTitleBar(hwndDlg); NppDarkMode::setDarkTitleBar(hwndDlg);
::SendMessage(hwndDlg, NPPM_INTERNAL_REFRESHDARKMODE, 0, 0); ::SendMessage(hwndDlg, NPPM_INTERNAL_REFRESHDARKMODE, 0, 0);
::RedrawWindow(hwndDlg, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN); ::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) if (_pProjectPanel_1)
@ -7645,7 +7659,14 @@ void Notepad_plus::refreshDarkMode()
::SendMessage(_findInFinderDlg.getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, 0); ::SendMessage(_findInFinderDlg.getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, 0);
::RedrawWindow(_findInFinderDlg.getHSelf(), nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN); ::RedrawWindow(_findInFinderDlg.getHSelf(), nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN);
if (resetStyle && NppDarkMode::isExperimentalSupported())
{
NppDarkMode::setDarkTitleBar(_findInFinderDlg.getHSelf());
::SetWindowPos(_findInFinderDlg.getHSelf(), nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
if (resetStyle)
{
toolBarStatusType state = _toolBar.getState(); toolBarStatusType state = _toolBar.getState();
switch (state) switch (state)
{ {
@ -7706,28 +7727,6 @@ void Notepad_plus::refreshDarkMode()
::SendMessage(_pPublicInterface->getHSelf(), WM_UPDATESCINTILLAS, 0, 0); ::SendMessage(_pPublicInterface->getHSelf(), WM_UPDATESCINTILLAS, 0, 0);
} }
} }
if (NppDarkMode::isExperimentalSupported())
{
RECT rcClient;
GetWindowRect(_pPublicInterface->getHSelf(), &rcClient);
// 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);
} }
} }

View File

@ -264,7 +264,7 @@ public:
void minimizeDialogs(); void minimizeDialogs();
void restoreMinimizeDialogs(); void restoreMinimizeDialogs();
void refreshDarkMode(); void refreshDarkMode(bool resetStyle = false);
private: private:
Notepad_plus_Window *_pPublicInterface = nullptr; Notepad_plus_Window *_pPublicInterface = nullptr;
@ -642,5 +642,3 @@ private:
void monitoringStartOrStopAndUpdateUI(Buffer* pBuf, bool isStarting); void monitoringStartOrStopAndUpdateUI(Buffer* pBuf, bool isStarting);
void updateCommandShortcuts(); void updateCommandShortcuts();
}; };

View File

@ -199,7 +199,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_INTERNAL_REFRESHDARKMODE: case NPPM_INTERNAL_REFRESHDARKMODE:
{ {
refreshDarkMode(); refreshDarkMode(static_cast<bool>(wParam));
return TRUE; return TRUE;
} }

View File

@ -332,7 +332,9 @@ namespace NppDarkMode
} }
HWND hwndRoot = GetAncestor(hwnd, GA_ROOTOWNER); 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<WPARAM>(!forceRefresh), 0);
} }
bool isEnabled() bool isEnabled()
@ -1402,7 +1404,10 @@ namespace NppDarkMode
, theme , theme
}; };
if (subclass)
{
::EnableThemeDialogTexture(hwndParent, theme ? ETDT_ENABLETAB : ETDT_DISABLE); ::EnableThemeDialogTexture(hwndParent, theme ? ETDT_ENABLETAB : ETDT_DISABLE);
}
EnumChildWindows(hwndParent, [](HWND hwnd, LPARAM lParam) { EnumChildWindows(hwndParent, [](HWND hwnd, LPARAM lParam) {
auto& p = *reinterpret_cast<Params*>(lParam); auto& p = *reinterpret_cast<Params*>(lParam);