Skip to content

Commit

Permalink
Don't reset style & icons, when changing dark tone
Browse files Browse the repository at this point in the history
Improve title bar dynamic redraw when changing mode.

Fix #10049, fix #10196, close #10272
  • Loading branch information
ozone10 authored and donho committed Jul 28, 2021
1 parent 5edc750 commit 1214319
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 87 deletions.
161 changes: 80 additions & 81 deletions PowerEditor/src/Notepad_plus.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
toolBarStatusType state = _toolBar.getState();
switch (state)
{
case TB_SMALL:
_toolBar.reduce();
break;

themeName = themeSwitcher.getThemeFromXmlFileName(themePath.c_str());
}
else
{
//use _stylerPath;

pair<generic_string, generic_string> & themeInfo = themeSwitcher.getElementFromIndex(0);
themePath = themeInfo.second;
themeName = themeSwitcher.getDefaultThemeLabel();
}
case TB_LARGE:
_toolBar.enlarge();
break;

if (::PathFileExists(themePath.c_str()))
{
nppParams.getNppGUI()._themeName = themePath;
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;
}

if (_configStyleDlg.isCreated())
ThemeSwitcher& themeSwitcher = nppParams.getThemeSwitcher();
generic_string themePath;
generic_string themeName;
const TCHAR darkModeXmlFileName[] = TEXT("DarkModeDefault.xml");
if (NppDarkMode::isEnabled())
{
_configStyleDlg.selectThemeByName(themeName.c_str());
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<generic_string, generic_string>& themeInfo = themeSwitcher.getElementFromIndex(0);
themePath = themeInfo.second;
themeName = themeSwitcher.getDefaultThemeLabel();
}
}

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);
if (::PathFileExists(themePath.c_str()))
{
nppParams.getNppGUI()._themeName = themePath;

if (_configStyleDlg.isCreated())
{
_configStyleDlg.selectThemeByName(themeName.c_str());
}
else
{
nppParams.reloadStylers(themePath.c_str());
::SendMessage(_pPublicInterface->getHSelf(), WM_UPDATESCINTILLAS, 0, 0);
}
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions PowerEditor/src/Notepad_plus.h
Expand Up @@ -264,7 +264,7 @@ friend class FileManager;
void minimizeDialogs();
void restoreMinimizeDialogs();

void refreshDarkMode();
void refreshDarkMode(bool resetStyle = false);

private:
Notepad_plus_Window *_pPublicInterface = nullptr;
Expand Down Expand Up @@ -642,5 +642,3 @@ friend class FileManager;
void monitoringStartOrStopAndUpdateUI(Buffer* pBuf, bool isStarting);
void updateCommandShortcuts();
};


2 changes: 1 addition & 1 deletion PowerEditor/src/NppBigSwitch.cpp
Expand Up @@ -199,7 +199,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa

case NPPM_INTERNAL_REFRESHDARKMODE:
{
refreshDarkMode();
refreshDarkMode(static_cast<bool>(wParam));
return TRUE;
}

Expand Down
9 changes: 7 additions & 2 deletions PowerEditor/src/NppDarkMode.cpp
Expand Up @@ -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<WPARAM>(!forceRefresh), 0);
}

bool isEnabled()
Expand Down Expand Up @@ -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<Params*>(lParam);
Expand Down

0 comments on commit 1214319

Please sign in to comment.