Dark mode enhancement

1. Add "Follow Windows dark/light mode".
2. Remember user's toolbar, tabbar and theme choices for dark mode and light mode separately.
3. Add 2 hidden options for applying tab background color from themes (for both dark mode and light mode).

Fix #9183, fix #9992, fix #10153, fix #10239, fix #10544, fix #10644, fix #11867, fix #10239, close #12466
This commit is contained in:
ozone10 2022-11-05 20:52:29 +01:00 committed by Don Ho
parent 6803b69c0b
commit e2a1234384
14 changed files with 563 additions and 126 deletions

View File

@ -235,7 +235,33 @@ LRESULT Notepad_plus::init(HWND hwnd)
pIconListVector.push_back(&_docTabIconListAlt); // 1 pIconListVector.push_back(&_docTabIconListAlt); // 1
pIconListVector.push_back(&_docTabIconListDarkMode);// 2 pIconListVector.push_back(&_docTabIconListDarkMode);// 2
unsigned char indexDocTabIcon = (((tabBarStatus & TAB_ALTICONS) == TAB_ALTICONS) ? 1 : NppDarkMode::isEnabled() ? 2 : 0); const int tabIconSet = NppDarkMode::getTabIconSet(NppDarkMode::isEnabled());
unsigned char indexDocTabIcon = 0;
switch (tabIconSet)
{
case 0:
{
nppGUI._tabStatus &= ~TAB_ALTICONS;
break;
}
case 1:
{
nppGUI._tabStatus |= TAB_ALTICONS;
indexDocTabIcon = 1;
break;
}
case 2:
{
nppGUI._tabStatus &= ~TAB_ALTICONS;
indexDocTabIcon = 2;
break;
}
//case -1:
default:
{
indexDocTabIcon = ((tabBarStatus & TAB_ALTICONS) == TAB_ALTICONS) ? 1 : (NppDarkMode::isEnabled() ? 2 : 0);
}
}
_mainDocTab.init(_pPublicInterface->getHinst(), hwnd, &_mainEditView, pIconListVector, indexDocTabIcon); _mainDocTab.init(_pPublicInterface->getHinst(), hwnd, &_mainEditView, pIconListVector, indexDocTabIcon);
_subDocTab.init(_pPublicInterface->getHinst(), hwnd, &_subEditView, pIconListVector, indexDocTabIcon); _subDocTab.init(_pPublicInterface->getHinst(), hwnd, &_subEditView, pIconListVector, indexDocTabIcon);
@ -605,6 +631,12 @@ LRESULT Notepad_plus::init(HWND hwnd)
//-- Tool Bar Section --// //-- Tool Bar Section --//
const int toolbarState = NppDarkMode::getToolBarIconSet(NppDarkMode::isEnabled());
if (toolbarState != -1)
{
nppGUI._toolBarStatus = static_cast<toolBarStatusType>(toolbarState);
}
toolBarStatusType tbStatus = nppGUI._toolBarStatus; toolBarStatusType tbStatus = nppGUI._toolBarStatus;
willBeShown = nppGUI._toolbarShow; willBeShown = nppGUI._toolbarShow;
@ -6707,7 +6739,7 @@ void Notepad_plus::launchClipboardHistoryPanel()
} }
void Notepad_plus::launchDocumentListPanel() void Notepad_plus::launchDocumentListPanel(bool changeFromBtnCmd)
{ {
if (!_pDocumentListPanel) if (!_pDocumentListPanel)
{ {
@ -6715,7 +6747,31 @@ void Notepad_plus::launchDocumentListPanel()
int tabBarStatus = nppParams.getNppGUI()._tabStatus; int tabBarStatus = nppParams.getNppGUI()._tabStatus;
_pDocumentListPanel = new VerticalFileSwitcher; _pDocumentListPanel = new VerticalFileSwitcher;
HIMAGELIST hImgLst = ((tabBarStatus & TAB_ALTICONS) ? _docTabIconListAlt.getHandle() : NppDarkMode::isEnabled() ? _docTabIconListDarkMode.getHandle() : _docTabIconList.getHandle());
HIMAGELIST hImgLst = nullptr;
const int tabIconSet = changeFromBtnCmd ? -1 : NppDarkMode::getTabIconSet(NppDarkMode::isEnabled());
switch (tabIconSet)
{
case 0:
{
hImgLst = _docTabIconList.getHandle();
break;
}
case 1:
{
hImgLst = _docTabIconListAlt.getHandle();
break;
}
case 2:
{
hImgLst = _docTabIconListDarkMode.getHandle();
break;
}
//case -1:
default:
hImgLst = (((tabBarStatus & TAB_ALTICONS) == TAB_ALTICONS) ? _docTabIconListAlt.getHandle() : NppDarkMode::isEnabled() ? _docTabIconListDarkMode.getHandle() : _docTabIconList.getHandle());
}
_pDocumentListPanel->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), hImgLst); _pDocumentListPanel->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), hImgLst);
NativeLangSpeaker *pNativeSpeaker = nppParams.getNativeLangSpeaker(); NativeLangSpeaker *pNativeSpeaker = nppParams.getNativeLangSpeaker();
bool isRTL = pNativeSpeaker->isRTL(); bool isRTL = pNativeSpeaker->isRTL();
@ -7814,13 +7870,23 @@ void Notepad_plus::refreshDarkMode(bool resetStyle)
::SendMessage(_pClipboardHistoryPanel->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, 0); ::SendMessage(_pClipboardHistoryPanel->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, 0);
} }
bool isChecked = _preference._generalSubDlg.isCheckedOrNot(IDC_CHECK_TAB_ALTICONS); const int tabIconSet = NppDarkMode::getTabIconSet(NppDarkMode::isEnabled());
if (tabIconSet != -1)
{
_preference._generalSubDlg.setTabbarAlternateIcons(tabIconSet == 1);
::SendMessage(_pPublicInterface->getHSelf(), NPPM_INTERNAL_CHANGETABBAEICONS, static_cast<WPARAM>(false), tabIconSet);
}
else
{
const bool isChecked = _preference._generalSubDlg.isCheckedOrNot(IDC_CHECK_TAB_ALTICONS);
if (!isChecked) if (!isChecked)
{ {
::SendMessage(_pPublicInterface->getHSelf(), NPPM_INTERNAL_CHANGETABBAEICONS, 0, NppDarkMode::isEnabled() ? 2 : 0); ::SendMessage(_pPublicInterface->getHSelf(), NPPM_INTERNAL_CHANGETABBAEICONS, static_cast<WPARAM>(false), NppDarkMode::isEnabled() ? 2 : 0);
}
} }
toolBarStatusType state = _toolBar.getState(); const int iconState = NppDarkMode::getToolBarIconSet(NppDarkMode::isEnabled());
toolBarStatusType state = (iconState == -1) ? _toolBar.getState() : static_cast<toolBarStatusType>(iconState);
switch (state) switch (state)
{ {
case TB_SMALL: case TB_SMALL:
@ -7840,20 +7906,19 @@ void Notepad_plus::refreshDarkMode(bool resetStyle)
break; break;
case TB_STANDARD: case TB_STANDARD:
// Force standard colorful icon to Fluent UI small icon in dark mode _toolBar.setToBmpIcons();
if (NppDarkMode::isEnabled())
_toolBar.reduce();
break; break;
} }
ThemeSwitcher& themeSwitcher = nppParams.getThemeSwitcher(); ThemeSwitcher& themeSwitcher = nppParams.getThemeSwitcher();
generic_string themePath; generic_string themePath;
generic_string themeName; generic_string themeName;
const TCHAR darkModeXmlFileName[] = TEXT("DarkModeDefault.xml");
if (NppDarkMode::isEnabled()) generic_string xmlFileName = NppDarkMode::getThemeName();
if (!xmlFileName.empty())
{ {
themePath = themeSwitcher.getThemeDirPath(); themePath = themeSwitcher.getThemeDirPath();
pathAppend(themePath, darkModeXmlFileName); pathAppend(themePath, xmlFileName);
themeName = themeSwitcher.getThemeFromXmlFileName(themePath.c_str()); themeName = themeSwitcher.getThemeFromXmlFileName(themePath.c_str());
} }

View File

@ -602,7 +602,7 @@ private:
void removeDuplicateLines(); void removeDuplicateLines();
void launchAnsiCharPanel(); void launchAnsiCharPanel();
void launchClipboardHistoryPanel(); void launchClipboardHistoryPanel();
void launchDocumentListPanel(); void launchDocumentListPanel(bool changeFromBtnCmd = false);
void checkProjectMenuItem(); void checkProjectMenuItem();
void launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int panelID); void launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int panelID);
void launchDocMap(); void launchDocMap();

View File

@ -260,6 +260,29 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
} }
} }
if (NppDarkMode::isWindowsModeEnabled())
{
generic_string themePath;
generic_string xmlFileName = NppDarkMode::getThemeName();
if (!xmlFileName.empty())
{
themePath = themeSwitcher.getThemeDirPath();
pathAppend(themePath, xmlFileName);
}
else
{
auto& themeInfo = themeSwitcher.getElementFromIndex(0);
themePath = themeInfo.second;
}
if (::PathFileExists(themePath.c_str()))
{
nppGUI._themeName.assign(themePath);
nppParams.reloadStylers(themePath.c_str());
::SendMessage(_hSelf, WM_UPDATESCINTILLAS, 0, 0);
}
}
// Restore all dockable panels from the last session // Restore all dockable panels from the last session
for (size_t i = 0, len = _notepad_plus_plus_core._internalFuncIDs.size() ; i < len ; ++i) for (size_t i = 0, len = _notepad_plus_plus_core._internalFuncIDs.size() ; i < len ; ++i)
::SendMessage(_hSelf, WM_COMMAND, _notepad_plus_plus_core._internalFuncIDs[i], 0); ::SendMessage(_hSelf, WM_COMMAND, _notepad_plus_plus_core._internalFuncIDs[i], 0);

View File

@ -194,6 +194,54 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
NppDarkMode::handleSettingChange(hwnd, lParam); NppDarkMode::handleSettingChange(hwnd, lParam);
const bool enableDarkMode = NppDarkMode::isExperimentalActive();
NppParameters& nppParam = NppParameters::getInstance();
NppGUI& nppGUI = nppParam.getNppGUI();
// Windows mode is enabled
// and don't change if Notepad++ is already in same mode as OS after changing OS mode
if (NppDarkMode::isWindowsModeEnabled() && (enableDarkMode != NppDarkMode::isEnabled()))
{
nppGUI._darkmode._isEnabled = enableDarkMode;
if (!_preference.isCreated())
{
const int iconState = NppDarkMode::getToolBarIconSet(NppDarkMode::isEnabled());
toolBarStatusType state = (iconState == -1) ? _toolBar.getState() : static_cast<toolBarStatusType>(iconState);
switch (state)
{
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:
_toolBar.setToBmpIcons();
break;
}
NppDarkMode::refreshDarkMode(hwnd, false);
}
else
{
HWND hSubDlg = _preference._darkModeSubDlg.getHSelf();
// don't use IDC_RADIO_DARKMODE_FOLLOWWINDOWS, it is only for button,
// it calls NppDarkMode::handleSettingChange, which is not needed here
::SendMessage(hSubDlg, WM_COMMAND, IDC_RADIO_DARKMODE_DARKMODE, 0);
}
}
return ::DefWindowProc(hwnd, message, wParam, lParam); return ::DefWindowProc(hwnd, message, wParam, lParam);
} }
@ -781,7 +829,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
_pDocumentListPanel = nullptr; _pDocumentListPanel = nullptr;
//relaunch with new icons //relaunch with new icons
launchDocumentListPanel(); launchDocumentListPanel(static_cast<bool>(wParam));
} }
else //if doclist is closed else //if doclist is closed
{ {
@ -790,7 +838,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
_pDocumentListPanel = nullptr; _pDocumentListPanel = nullptr;
//relaunch doclist with new icons and close it //relaunch doclist with new icons and close it
launchDocumentListPanel(); launchDocumentListPanel(static_cast<bool>(wParam));
if (_pDocumentListPanel) if (_pDocumentListPanel)
{ {
_pDocumentListPanel->display(false); _pDocumentListPanel->display(false);

View File

@ -338,6 +338,7 @@ namespace NppDarkMode
} }
static Options _options; // actual runtime options static Options _options; // actual runtime options
static AdvancedOptions g_advOptions;
Options configuredOptions() Options configuredOptions()
{ {
@ -361,10 +362,26 @@ namespace NppDarkMode
_options = configuredOptions(); _options = configuredOptions();
initExperimentalDarkMode(); initExperimentalDarkMode();
initAdvancedOptions();
if (NppDarkMode::isWindowsModeEnabled() && NppDarkMode::isWindows10())
{
NppParameters& nppParam = NppParameters::getInstance();
NppGUI& nppGUI = nppParam.getNppGUI();
nppGUI._darkmode._isEnabled = NppDarkMode::isDarkModeReg() && !IsHighContrast();
_options.enable = nppGUI._darkmode._isEnabled;
_options.enableMenubar = _options.enable;
}
setDarkMode(_options.enable, true); setDarkMode(_options.enable, true);
g_isAtLeastWindows10 = NppDarkMode::isWindows10(); g_isAtLeastWindows10 = NppDarkMode::isWindows10();
if (!g_isAtLeastWindows10)
{
g_advOptions._enableWindowsMode = false;
}
using PWINEGETVERSION = const CHAR* (__cdecl *)(void); using PWINEGETVERSION = const CHAR* (__cdecl *)(void);
PWINEGETVERSION pWGV = nullptr; PWINEGETVERSION pWGV = nullptr;
@ -411,6 +428,12 @@ namespace NppDarkMode
::SendMessage(hwndRoot, NPPM_INTERNAL_REFRESHDARKMODE, static_cast<WPARAM>(!forceRefresh), 0); ::SendMessage(hwndRoot, NPPM_INTERNAL_REFRESHDARKMODE, static_cast<WPARAM>(!forceRefresh), 0);
} }
void initAdvancedOptions()
{
NppGUI& nppGui = NppParameters::getInstance().getNppGUI();
g_advOptions = nppGui._darkmode._advOptions;
}
bool isEnabled() bool isEnabled()
{ {
return _options.enable; return _options.enable;
@ -436,6 +459,74 @@ namespace NppDarkMode
return g_darkModeSupported; return g_darkModeSupported;
} }
bool isWindowsModeEnabled()
{
return g_advOptions._enableWindowsMode;
}
void setWindowsMode(bool enable)
{
g_advOptions._enableWindowsMode = enable;
}
void setThemeName(const generic_string& newThemeName)
{
if (NppDarkMode::isEnabled())
g_advOptions._darkDefaults._xmlFileName = newThemeName;
else
g_advOptions._lightDefaults._xmlFileName = newThemeName;
}
generic_string getThemeName()
{
return NppDarkMode::isEnabled() ? g_advOptions._darkDefaults._xmlFileName : g_advOptions._lightDefaults._xmlFileName;
}
static bool g_isCustomToolIconUsed = NppParameters::getInstance().getCustomizedToolIcons() != nullptr;
void setToolBarIconSet(int state2Set, bool useDark)
{
if (useDark)
g_advOptions._darkDefaults._toolBarIconSet = state2Set;
else
g_advOptions._lightDefaults._toolBarIconSet = state2Set;
}
int getToolBarIconSet(bool useDark)
{
if (g_isCustomToolIconUsed)
{
return -1;
}
return useDark ? g_advOptions._darkDefaults._toolBarIconSet : g_advOptions._lightDefaults._toolBarIconSet;
}
void setTabIconSet(bool useAltIcons, bool useDark)
{
if (useDark)
g_advOptions._darkDefaults._tabIconSet = useAltIcons ? 1 : 2;
else
g_advOptions._lightDefaults._tabIconSet = useAltIcons ? 1 : 0;
}
int getTabIconSet(bool useDark)
{
return useDark ? g_advOptions._darkDefaults._tabIconSet : g_advOptions._lightDefaults._tabIconSet;
}
bool useTabTheme()
{
return NppDarkMode::isEnabled() ? g_advOptions._darkDefaults._tabUseTheme : g_advOptions._lightDefaults._tabUseTheme;
}
void setAdvancedOptions()
{
NppGUI& nppGui = NppParameters::getInstance().getNppGUI();
auto& advOpt = nppGui._darkmode._advOptions;
advOpt = g_advOptions;
}
bool isWindows10() bool isWindows10()
{ {
return IsWindows10(); return IsWindows10();
@ -623,7 +714,7 @@ namespace NppDarkMode
// handle events // handle events
void handleSettingChange(HWND hwnd, LPARAM lParam) void handleSettingChange(HWND hwnd, LPARAM lParam, bool isFromBtn)
{ {
UNREFERENCED_PARAMETER(hwnd); UNREFERENCED_PARAMETER(hwnd);
@ -632,12 +723,30 @@ namespace NppDarkMode
return; return;
} }
if (IsColorSchemeChangeMessage(lParam)) if (IsColorSchemeChangeMessage(lParam) || isFromBtn)
{ {
g_darkModeEnabled = ShouldAppsUseDarkMode() && !IsHighContrast(); // ShouldAppsUseDarkMode() is not reliable from 1903+, use NppDarkMode::isDarkModeReg() instead
g_darkModeEnabled = NppDarkMode::isDarkModeReg() && !IsHighContrast();
} }
} }
bool isDarkModeReg()
{
DWORD data{};
DWORD dwBufSize = sizeof(data);
LPCTSTR lpSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
LPCTSTR lpValue = L"AppsUseLightTheme";
auto result = RegGetValue(HKEY_CURRENT_USER, lpSubKey, lpValue, RRF_RT_REG_DWORD, nullptr, &data, &dwBufSize);
if (result != ERROR_SUCCESS)
{
return false;
}
// dark mode is 0, light mode is 1
return data == 0UL;
}
// processes messages related to UAH / custom menubar drawing. // processes messages related to UAH / custom menubar drawing.
// return true if handled, false to continue with normal processing in your wndproc // return true if handled, false to continue with normal processing in your wndproc
bool runUAHWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT* lr) bool runUAHWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT* lr)

View File

@ -18,6 +18,8 @@
#include <windows.h> #include <windows.h>
#include "Common.h" // for generic_string
constexpr COLORREF HEXRGB(DWORD rrggbb) { constexpr COLORREF HEXRGB(DWORD rrggbb) {
// from 0xRRGGBB like natural #RRGGBB // from 0xRRGGBB like natural #RRGGBB
// to the little-endian 0xBBGGRR // to the little-endian 0xBBGGRR
@ -86,14 +88,44 @@ namespace NppDarkMode
dark = 2 dark = 2
}; };
struct AdvOptDefaults
{
generic_string _xmlFileName;
int _toolBarIconSet = -1;
int _tabIconSet = -1;
bool _tabUseTheme = false;
};
struct AdvancedOptions
{
bool _enableWindowsMode = false;
NppDarkMode::AdvOptDefaults _darkDefaults{};
NppDarkMode::AdvOptDefaults _lightDefaults{};
};
void initDarkMode(); // pulls options from NppParameters void initDarkMode(); // pulls options from NppParameters
void refreshDarkMode(HWND hwnd, bool forceRefresh = false); // attempts to apply new options from NppParameters, sends NPPM_INTERNAL_REFRESHDARKMODE to hwnd's top level parent void refreshDarkMode(HWND hwnd, bool forceRefresh = false); // attempts to apply new options from NppParameters, sends NPPM_INTERNAL_REFRESHDARKMODE to hwnd's top level parent
void initAdvancedOptions();
bool isEnabled(); bool isEnabled();
bool isDarkMenuEnabled(); bool isDarkMenuEnabled();
bool isEnabledForPlugins(); bool isEnabledForPlugins();
bool isExperimentalActive();
bool isExperimentalSupported(); bool isExperimentalSupported();
bool isWindowsModeEnabled();
void setWindowsMode(bool enable);
generic_string getThemeName();
void setThemeName(const generic_string& newThemeName);
int getToolBarIconSet(bool useDark);
void setToolBarIconSet(int state2Set, bool useDark);
int getTabIconSet(bool useDark);
void setTabIconSet(bool useAltIcons, bool useDark);
bool useTabTheme();
void setAdvancedOptions();
bool isWindows10(); bool isWindows10();
bool isWindows11(); bool isWindows11();
@ -152,7 +184,8 @@ namespace NppDarkMode
void changeCustomTheme(const Colors& colors); void changeCustomTheme(const Colors& colors);
// handle events // handle events
void handleSettingChange(HWND hwnd, LPARAM lParam); void handleSettingChange(HWND hwnd, LPARAM lParam, bool isFromBtn = false);
bool isDarkModeReg();
// processes messages related to UAH / custom menubar drawing. // processes messages related to UAH / custom menubar drawing.
// return true if handled, false to continue with normal processing in your wndproc // return true if handled, false to continue with normal processing in your wndproc

View File

@ -5673,7 +5673,7 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
_nppGUI._darkmode._isEnabled = parseYesNoBoolAttribute(TEXT("enable")); _nppGUI._darkmode._isEnabled = parseYesNoBoolAttribute(TEXT("enable"));
//_nppGUI._darkmode._isEnabledPlugin = parseYesNoBoolAttribute(TEXT("enablePlugin")); //_nppGUI._darkmode._isEnabledPlugin = parseYesNoBoolAttribute(TEXT("enablePlugin", true));
int i; int i;
const TCHAR* val; const TCHAR* val;
@ -5729,6 +5729,48 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
val = element->Attribute(TEXT("customColorDisabledEdge"), &i); val = element->Attribute(TEXT("customColorDisabledEdge"), &i);
if (val) if (val)
_nppGUI._darkmode._customColors.disabledEdge = i; _nppGUI._darkmode._customColors.disabledEdge = i;
// advanced options section
auto parseStringAttribute = [&element](const TCHAR* name, const TCHAR* defaultName = TEXT("")) -> const TCHAR* {
const TCHAR* val = element->Attribute(name);
if (val != nullptr && val[0])
{
return element->Attribute(name);
}
return defaultName;
};
auto parseToolBarIconsAttribute = [&element](const TCHAR* name, int defaultValue = -1) -> int {
int val;
const TCHAR* valStr = element->Attribute(name, &val);
if (valStr != nullptr && (val >= 0 && val <= 4))
{
return val;
}
return defaultValue;
};
auto parseTabIconsAttribute = [&element](const TCHAR* name, int defaultValue = -1) -> int {
int val;
const TCHAR* valStr = element->Attribute(name, &val);
if (valStr != nullptr && (val >= 0 && val <= 2))
{
return val;
}
return defaultValue;
};
_nppGUI._darkmode._advOptions._enableWindowsMode = parseYesNoBoolAttribute(TEXT("enableWindowsMode"));
_nppGUI._darkmode._advOptions._darkDefaults._xmlFileName = parseStringAttribute(TEXT("darkThemeName"), TEXT("DarkModeDefault.xml"));
_nppGUI._darkmode._advOptions._darkDefaults._toolBarIconSet = parseToolBarIconsAttribute(TEXT("darkToolBarIconSet"), 0);
_nppGUI._darkmode._advOptions._darkDefaults._tabIconSet = parseTabIconsAttribute(TEXT("darkTabIconSet"), 2);
_nppGUI._darkmode._advOptions._darkDefaults._tabUseTheme = parseYesNoBoolAttribute(TEXT("darkTabUseTheme"));
_nppGUI._darkmode._advOptions._lightDefaults._xmlFileName = parseStringAttribute(TEXT("lightThemeName"));
_nppGUI._darkmode._advOptions._lightDefaults._toolBarIconSet = parseToolBarIconsAttribute(TEXT("lightToolBarIconSet"), 4);
_nppGUI._darkmode._advOptions._lightDefaults._tabIconSet = parseTabIconsAttribute(TEXT("lightTabIconSet"), 0);
_nppGUI._darkmode._advOptions._lightDefaults._tabUseTheme = parseYesNoBoolAttribute(TEXT("lightTabUseTheme"), true);
} }
} }
} }
@ -6850,13 +6892,14 @@ void NppParameters::createXmlTreeFromGUIParams()
TiXmlElement* GUIConfigElement = (newGUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); TiXmlElement* GUIConfigElement = (newGUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement();
GUIConfigElement->SetAttribute(TEXT("name"), TEXT("DarkMode")); GUIConfigElement->SetAttribute(TEXT("name"), TEXT("DarkMode"));
NppDarkMode::setAdvancedOptions();
auto setYesNoBoolAttribute = [&GUIConfigElement](const TCHAR* name, bool value) { auto setYesNoBoolAttribute = [&GUIConfigElement](const TCHAR* name, bool value) {
const TCHAR* pStr = value ? TEXT("yes") : TEXT("no"); const TCHAR* pStr = value ? TEXT("yes") : TEXT("no");
GUIConfigElement->SetAttribute(name, pStr); GUIConfigElement->SetAttribute(name, pStr);
}; };
setYesNoBoolAttribute(TEXT("enable"), _nppGUI._darkmode._isEnabled); setYesNoBoolAttribute(TEXT("enable"), _nppGUI._darkmode._isEnabled);
//setYesNoBoolAttribute(TEXT("enablePlugin"), _nppGUI._darkmode._isEnabledPlugin);
GUIConfigElement->SetAttribute(TEXT("colorTone"), _nppGUI._darkmode._colorTone); GUIConfigElement->SetAttribute(TEXT("colorTone"), _nppGUI._darkmode._colorTone);
GUIConfigElement->SetAttribute(TEXT("customColorTop"), _nppGUI._darkmode._customColors.pureBackground); GUIConfigElement->SetAttribute(TEXT("customColorTop"), _nppGUI._darkmode._customColors.pureBackground);
@ -6871,6 +6914,19 @@ void NppParameters::createXmlTreeFromGUIParams()
GUIConfigElement->SetAttribute(TEXT("customColorEdge"), _nppGUI._darkmode._customColors.edge); GUIConfigElement->SetAttribute(TEXT("customColorEdge"), _nppGUI._darkmode._customColors.edge);
GUIConfigElement->SetAttribute(TEXT("customColorHotEdge"), _nppGUI._darkmode._customColors.hotEdge); GUIConfigElement->SetAttribute(TEXT("customColorHotEdge"), _nppGUI._darkmode._customColors.hotEdge);
GUIConfigElement->SetAttribute(TEXT("customColorDisabledEdge"), _nppGUI._darkmode._customColors.disabledEdge); GUIConfigElement->SetAttribute(TEXT("customColorDisabledEdge"), _nppGUI._darkmode._customColors.disabledEdge);
// advanced options section
setYesNoBoolAttribute(TEXT("enableWindowsMode"), _nppGUI._darkmode._advOptions._enableWindowsMode);
GUIConfigElement->SetAttribute(TEXT("darkThemeName"), _nppGUI._darkmode._advOptions._darkDefaults._xmlFileName.c_str());
GUIConfigElement->SetAttribute(TEXT("darkToolBarIconSet"), _nppGUI._darkmode._advOptions._darkDefaults._toolBarIconSet);
GUIConfigElement->SetAttribute(TEXT("darkTabIconSet"), _nppGUI._darkmode._advOptions._darkDefaults._tabIconSet);
setYesNoBoolAttribute(TEXT("darkTabUseTheme"), _nppGUI._darkmode._advOptions._darkDefaults._tabUseTheme);
GUIConfigElement->SetAttribute(TEXT("lightThemeName"), _nppGUI._darkmode._advOptions._lightDefaults._xmlFileName.c_str());
GUIConfigElement->SetAttribute(TEXT("lightToolBarIconSet"), _nppGUI._darkmode._advOptions._lightDefaults._toolBarIconSet);
GUIConfigElement->SetAttribute(TEXT("lightTabIconSet"), _nppGUI._darkmode._advOptions._lightDefaults._tabIconSet);
setYesNoBoolAttribute(TEXT("lightTabUseTheme"), _nppGUI._darkmode._advOptions._lightDefaults._tabUseTheme);
} }
// <GUIConfig name="ScintillaPrimaryView" lineNumberMargin="show" bookMarkMargin="show" indentGuideLine="show" folderMarkStyle="box" lineWrapMethod="aligned" currentLineHilitingShow="show" scrollBeyondLastLine="no" rightClickKeepsSelection="no" disableAdvancedScrolling="no" wrapSymbolShow="hide" Wrap="no" borderEdge="yes" edge="no" edgeNbColumn="80" zoom="0" zoom2="0" whiteSpaceShow="hide" eolShow="hide" borderWidth="2" smoothFont="no" /> // <GUIConfig name="ScintillaPrimaryView" lineNumberMargin="show" bookMarkMargin="show" indentGuideLine="show" folderMarkStyle="box" lineWrapMethod="aligned" currentLineHilitingShow="show" scrollBeyondLastLine="no" rightClickKeepsSelection="no" disableAdvancedScrolling="no" wrapSymbolShow="hide" Wrap="no" borderEdge="yes" edge="no" edgeNbColumn="80" zoom="0" zoom2="0" whiteSpaceShow="hide" eolShow="hide" borderWidth="2" smoothFont="no" />

View File

@ -720,6 +720,7 @@ struct DarkModeConf final
bool _isEnabledPlugin = true; bool _isEnabledPlugin = true;
NppDarkMode::ColorTone _colorTone = NppDarkMode::blackTone; NppDarkMode::ColorTone _colorTone = NppDarkMode::blackTone;
NppDarkMode::Colors _customColors = NppDarkMode::getDarkModeDefaultColors(); NppDarkMode::Colors _customColors = NppDarkMode::getDarkModeDefaultColors();
NppDarkMode::AdvancedOptions _advOptions{};
}; };
@ -905,7 +906,6 @@ struct NppGUI final
bool _shouldSortFunctionList = false; bool _shouldSortFunctionList = false;
DarkModeConf _darkmode; DarkModeConf _darkmode;
DarkModeConf _darkmodeplugins;
LargeFileRestriction _largeFileRestriction; LargeFileRestriction _largeFileRestriction;
}; };
@ -1667,7 +1667,7 @@ public:
bool isLocal() const { bool isLocal() const {
return _isLocal; return _isLocal;
}; }
void saveConfig_xml(); void saveConfig_xml();

View File

@ -404,6 +404,9 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0); ::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0);
::SendMessage(_hParent, WM_UPDATEMAINMENUBITMAPS, 0, 0); ::SendMessage(_hParent, WM_UPDATEMAINMENUBITMAPS, 0, 0);
const TCHAR* fn = ::PathFindFileName(_themeName.c_str());
NppDarkMode::setThemeName(fn);
return TRUE; return TRUE;
} }

View File

@ -107,29 +107,31 @@ IDD_PREFERENCE_SUB_DARKMODE DIALOGEX 0, 0, 455, 185
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
FONT 8, "MS Shell Dlg", 0, 0, 0x1 FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN BEGIN
CONTROL "Enable &dark mode",IDC_CHECK_DARKMODE_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,12,150,10 CONTROL "Light mode",IDC_RADIO_DARKMODE_LIGHTMODE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,11,3,150,10
GROUPBOX "Tones",IDC_DARKMODE_TONES_GB_STATIC,10,25,440,154,BS_CENTER CONTROL "Dark mode",IDC_RADIO_DARKMODE_DARKMODE,"Button",BS_AUTORADIOBUTTON,11,18,131,10
CONTROL "Black",IDC_RADIO_DARKMODE_BLACK,"Button",BS_AUTORADIOBUTTON | WS_GROUP,15,35,80,10 CONTROL "Follow Windows",IDC_RADIO_DARKMODE_FOLLOWWINDOWS,"Button",BS_AUTORADIOBUTTON,11,33,172,10
CONTROL "Red",IDC_RADIO_DARKMODE_RED,"Button",BS_AUTORADIOBUTTON ,15,50,80,10 GROUPBOX "Tones",IDC_DARKMODE_TONES_GB_STATIC,3,47,435,132,BS_CENTER
CONTROL "Green",IDC_RADIO_DARKMODE_GREEN,"Button",BS_AUTORADIOBUTTON ,15,65,80,10 CONTROL "Black",IDC_RADIO_DARKMODE_BLACK,"Button",BS_AUTORADIOBUTTON | WS_GROUP,11,60,80,10
CONTROL "Blue",IDC_RADIO_DARKMODE_BLUE,"Button",BS_AUTORADIOBUTTON ,15,80,80,10 CONTROL "Red",IDC_RADIO_DARKMODE_RED,"Button",BS_AUTORADIOBUTTON,11,75,80,10
CONTROL "Purple",IDC_RADIO_DARKMODE_PURPLE,"Button",BS_AUTORADIOBUTTON ,15,95,80,10 CONTROL "Green",IDC_RADIO_DARKMODE_GREEN,"Button",BS_AUTORADIOBUTTON,11,90,80,10
CONTROL "Cyan",IDC_RADIO_DARKMODE_CYAN,"Button",BS_AUTORADIOBUTTON ,15,110,80,10 CONTROL "Blue",IDC_RADIO_DARKMODE_BLUE,"Button",BS_AUTORADIOBUTTON,11,105,80,10
CONTROL "Olive",IDC_RADIO_DARKMODE_OLIVE,"Button",BS_AUTORADIOBUTTON ,15,125,80,10 CONTROL "Purple",IDC_RADIO_DARKMODE_PURPLE,"Button",BS_AUTORADIOBUTTON,11,120,80,10
CONTROL "Customized",IDC_RADIO_DARKMODE_CUSTOMIZED,"Button",BS_AUTORADIOBUTTON,100,35,120,10 CONTROL "Cyan",IDC_RADIO_DARKMODE_CYAN,"Button",BS_AUTORADIOBUTTON,11,135,80,10
LTEXT "Top",IDD_CUSTOMIZED_COLOR1_STATIC,125,55,95,8 CONTROL "Olive",IDC_RADIO_DARKMODE_OLIVE,"Button",BS_AUTORADIOBUTTON,11,150,80,10
LTEXT "Menu hot track",IDD_CUSTOMIZED_COLOR2_STATIC,125,75,95,8 CONTROL "Customized",IDC_RADIO_DARKMODE_CUSTOMIZED,"Button",BS_AUTORADIOBUTTON,96,60,120,10
LTEXT "Active",IDD_CUSTOMIZED_COLOR3_STATIC,125,95,95,8 LTEXT "Top",IDD_CUSTOMIZED_COLOR1_STATIC,112,80,95,8
LTEXT "Main",IDD_CUSTOMIZED_COLOR4_STATIC,125,115,95,8 LTEXT "Menu hot track",IDD_CUSTOMIZED_COLOR2_STATIC,112,100,95,8
LTEXT "Error",IDD_CUSTOMIZED_COLOR5_STATIC,125,135,95,8 LTEXT "Active",IDD_CUSTOMIZED_COLOR3_STATIC,112,120,95,8
LTEXT "Text",IDD_CUSTOMIZED_COLOR6_STATIC,240,55,95,8 LTEXT "Main",IDD_CUSTOMIZED_COLOR4_STATIC,112,140,95,8
LTEXT "Darker text",IDD_CUSTOMIZED_COLOR7_STATIC,240,75,95,8 LTEXT "Error",IDD_CUSTOMIZED_COLOR5_STATIC,112,160,95,8
LTEXT "Disabled text",IDD_CUSTOMIZED_COLOR8_STATIC,240,95,95,8 LTEXT "Text",IDD_CUSTOMIZED_COLOR6_STATIC,227,80,95,8
LTEXT "Link",IDD_CUSTOMIZED_COLOR10_STATIC, 240,115,95,8 LTEXT "Darker text",IDD_CUSTOMIZED_COLOR7_STATIC,227,100,95,8
LTEXT "Edge",IDD_CUSTOMIZED_COLOR9_STATIC,355,55,94,8 LTEXT "Disabled text",IDD_CUSTOMIZED_COLOR8_STATIC,227,120,95,8
LTEXT "Edge highlight",IDD_CUSTOMIZED_COLOR11_STATIC,355,75,94,8 LTEXT "Link",IDD_CUSTOMIZED_COLOR10_STATIC,227,140,95,8
LTEXT "Edge disabled",IDD_CUSTOMIZED_COLOR12_STATIC,355,95,94,8 LTEXT "Edge",IDD_CUSTOMIZED_COLOR9_STATIC,342,80,94,8
PUSHBUTTON "Reset",IDD_CUSTOMIZED_RESET_BUTTON,252,155,45,14 LTEXT "Edge highlight",IDD_CUSTOMIZED_COLOR11_STATIC,342,100,94,8
LTEXT "Edge disabled",IDD_CUSTOMIZED_COLOR12_STATIC,342,120,94,8
PUSHBUTTON "Reset",IDD_CUSTOMIZED_RESET_BUTTON,340,158,45,14
END END
IDD_PREFERENCE_SUB_MARGING_BORDER_EDGE DIALOGEX 0, 0, 455, 185 IDD_PREFERENCE_SUB_MARGING_BORDER_EDGE DIALOGEX 0, 0, 455, 185

View File

@ -270,23 +270,97 @@ intptr_t CALLBACK PreferenceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
return TRUE; return TRUE;
} }
case PREF_MSG_ISCHECKED_GENERALPAGE: case PREF_MSG_SETGUITOOLICONSSET:
{ {
if (!lParam) const HWND generalSubDlg = _generalSubDlg.getHSelf();
return FALSE;
auto checkOrUncheckBtn = [&generalSubDlg](int id, WPARAM check = BST_UNCHECKED) -> void
{
::SendDlgItemMessage(generalSubDlg, id, BM_SETCHECK, check, 0);
};
const int iconState = NppDarkMode::getToolBarIconSet(static_cast<bool>(wParam));
NppParameters& nppParams = NppParameters::getInstance();
NppGUI& nppGUI = nppParams.getNppGUI();
if (iconState != -1)
{
nppGUI._toolBarStatus = static_cast<toolBarStatusType>(iconState);
}
else
{
auto state = TB_STANDARD;
if (_generalSubDlg.isCheckedOrNot(IDC_RADIO_SMALLICON))
{
state = TB_SMALL;
}
else if (_generalSubDlg.isCheckedOrNot(IDC_RADIO_BIGICON))
{
state = TB_LARGE;
}
else if (_generalSubDlg.isCheckedOrNot(IDC_RADIO_SMALLICON2))
{
state = TB_SMALL2;
}
else if (_generalSubDlg.isCheckedOrNot(IDC_RADIO_BIGICON2))
{
state = TB_LARGE2;
}
nppGUI._toolBarStatus = state;
}
checkOrUncheckBtn(IDC_RADIO_STANDARD);
checkOrUncheckBtn(IDC_RADIO_SMALLICON);
checkOrUncheckBtn(IDC_RADIO_BIGICON);
checkOrUncheckBtn(IDC_RADIO_SMALLICON2);
checkOrUncheckBtn(IDC_RADIO_BIGICON2);
switch (nppGUI._toolBarStatus)
{
case TB_LARGE:
{
checkOrUncheckBtn(IDC_RADIO_BIGICON, BST_CHECKED);
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_ENLARGE, 0);
break;
}
case TB_SMALL2:
{
checkOrUncheckBtn(IDC_RADIO_SMALLICON2, BST_CHECKED);
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_REDUCE_SET2, 0);
break;
}
case TB_LARGE2:
{
checkOrUncheckBtn(IDC_RADIO_BIGICON2, BST_CHECKED);
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_ENLARGE_SET2, 0);
break;
}
case TB_STANDARD:
{
checkOrUncheckBtn(IDC_RADIO_STANDARD, BST_CHECKED);
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_STANDARD, 0);
break;
}
//case TB_SMALL:
default:
{
checkOrUncheckBtn(IDC_RADIO_SMALLICON, BST_CHECKED);
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_REDUCE, 0);
}
}
bool isChecked = _generalSubDlg.isCheckedOrNot(static_cast<int>(wParam));
*((bool*)lParam) = isChecked;
return TRUE; return TRUE;
} }
case PREF_MSG_SETTOOLICONSFROMSTDTOSMALL: case PREF_MSG_SETGUITABBARICONS:
_generalSubDlg.setToolIconsFromStdToSmall(); {
return TRUE; const int tabIconSet = NppDarkMode::getTabIconSet(static_cast<bool>(wParam));
if (tabIconSet != -1)
case PREF_MSG_DISABLETABBARALTERNATEICONS: {
_generalSubDlg.disableTabbarAlternateIcons(); _generalSubDlg.setTabbarAlternateIcons(tabIconSet == 1);
}
return TRUE; return TRUE;
}
case WM_COMMAND : case WM_COMMAND :
{ {
@ -434,21 +508,20 @@ void PreferenceDlg::destroy()
_performanceSubDlg.destroy(); _performanceSubDlg.destroy();
} }
void GeneralSubDlg::setToolIconsFromStdToSmall() void GeneralSubDlg::setTabbarAlternateIcons(bool enable)
{
::SendDlgItemMessage(_hSelf, IDC_RADIO_STANDARD, BM_SETCHECK, BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_RADIO_SMALLICON, BM_SETCHECK, BST_CHECKED, 0);
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_REDUCE, 0);
}
void GeneralSubDlg::disableTabbarAlternateIcons()
{ {
NppGUI& nppGUI = NppParameters::getInstance().getNppGUI(); NppGUI& nppGUI = NppParameters::getInstance().getNppGUI();
int altIconsBit = TAB_ALTICONS; if (!enable)
nppGUI._tabStatus &= ~altIconsBit; {
nppGUI._tabStatus &= ~TAB_ALTICONS;
::SendDlgItemMessage(_hSelf, IDC_CHECK_TAB_ALTICONS, BM_SETCHECK, BST_UNCHECKED, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_TAB_ALTICONS, BM_SETCHECK, BST_UNCHECKED, 0);
} }
else
{
nppGUI._tabStatus |= TAB_ALTICONS;
::SendDlgItemMessage(_hSelf, IDC_CHECK_TAB_ALTICONS, BM_SETCHECK, BST_CHECKED, 0);
}
}
intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
{ {
@ -617,8 +690,10 @@ intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
{ {
NppGUI& nppGUI = nppParam.getNppGUI(); NppGUI& nppGUI = nppParam.getNppGUI();
nppGUI._tabStatus ^= TAB_ALTICONS; nppGUI._tabStatus ^= TAB_ALTICONS;
bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_TAB_ALTICONS, BM_GETCHECK, 0, 0)); const bool isChecked = isCheckedOrNot(IDC_CHECK_TAB_ALTICONS);
::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_CHANGETABBAEICONS, 0, isChecked ? 1 : (nppGUI._darkmode._isEnabled ? 2 : 0)); const bool isBtnCmd = true;
::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_CHANGETABBAEICONS, static_cast<WPARAM>(isBtnCmd), isChecked ? 1 : (nppGUI._darkmode._isEnabled ? 2 : 0));
NppDarkMode::setTabIconSet(isChecked, NppDarkMode::isEnabled());
return TRUE; return TRUE;
} }
@ -655,22 +730,27 @@ intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
case IDC_RADIO_SMALLICON : case IDC_RADIO_SMALLICON :
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_REDUCE, 0); ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_REDUCE, 0);
NppDarkMode::setToolBarIconSet(0, NppDarkMode::isEnabled());
return TRUE; return TRUE;
case IDC_RADIO_BIGICON : case IDC_RADIO_BIGICON :
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_ENLARGE, 0); ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_ENLARGE, 0);
NppDarkMode::setToolBarIconSet(1, NppDarkMode::isEnabled());
return TRUE; return TRUE;
case IDC_RADIO_SMALLICON2: case IDC_RADIO_SMALLICON2:
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_REDUCE_SET2, 0); ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_REDUCE_SET2, 0);
NppDarkMode::setToolBarIconSet(2, NppDarkMode::isEnabled());
return TRUE; return TRUE;
case IDC_RADIO_BIGICON2: case IDC_RADIO_BIGICON2:
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_ENLARGE_SET2, 0); ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_ENLARGE_SET2, 0);
NppDarkMode::setToolBarIconSet(3, NppDarkMode::isEnabled());
return TRUE; return TRUE;
case IDC_RADIO_STANDARD : case IDC_RADIO_STANDARD :
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_STANDARD, 0); ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_STANDARD, 0);
NppDarkMode::setToolBarIconSet(4, NppDarkMode::isEnabled());
return TRUE; return TRUE;
default : default :
@ -1133,7 +1213,9 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
::SendDlgItemMessage(_hSelf, IDC_CHECK_DARKMODE_ENABLE, BM_SETCHECK, nppGUI._darkmode._isEnabled, 0); ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_DARKMODE_FOLLOWWINDOWS), NppDarkMode::isWindows10());
const int topControlID = NppDarkMode::isWindowsModeEnabled() && NppDarkMode::isWindows10() ? IDC_RADIO_DARKMODE_FOLLOWWINDOWS : NppDarkMode::isEnabled() ? IDC_RADIO_DARKMODE_DARKMODE : IDC_RADIO_DARKMODE_LIGHTMODE;
::SendDlgItemMessage(_hSelf, topControlID, BM_SETCHECK, BST_CHECKED, 0);
int id = IDC_RADIO_DARKMODE_BLACK; int id = IDC_RADIO_DARKMODE_BLACK;
switch (nppGUI._darkmode._colorTone) switch (nppGUI._darkmode._colorTone)
@ -1313,9 +1395,17 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
bool doEnableCustomizedColorCtrls = false; bool doEnableCustomizedColorCtrls = false;
switch (wParam) switch (wParam)
{ {
case IDC_CHECK_DARKMODE_ENABLE: case IDC_RADIO_DARKMODE_FOLLOWWINDOWS:
{ {
bool enableDarkMode = isCheckedOrNot(static_cast<int>(wParam)); NppDarkMode::handleSettingChange(nullptr, 0, true);
}
case IDC_RADIO_DARKMODE_LIGHTMODE:
case IDC_RADIO_DARKMODE_DARKMODE:
{
const bool isFollowWindows = isCheckedOrNot(IDC_RADIO_DARKMODE_FOLLOWWINDOWS);
NppDarkMode::setWindowsMode(isFollowWindows);
const bool enableDarkMode = isCheckedOrNot(IDC_RADIO_DARKMODE_DARKMODE) || (isFollowWindows && NppDarkMode::isExperimentalActive());
nppGUI._darkmode._isEnabled = enableDarkMode; nppGUI._darkmode._isEnabled = enableDarkMode;
::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_DARKMODE_BLACK), enableDarkMode); ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_DARKMODE_BLACK), enableDarkMode);
@ -1330,18 +1420,8 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
doEnableCustomizedColorCtrls = enableDarkMode && nppGUI._darkmode._colorTone == NppDarkMode::customizedTone; doEnableCustomizedColorCtrls = enableDarkMode && nppGUI._darkmode._colorTone == NppDarkMode::customizedTone;
enableCustomizedColorCtrls(doEnableCustomizedColorCtrls); enableCustomizedColorCtrls(doEnableCustomizedColorCtrls);
// Maintain the coherence in preferences ::SendMessage(_hParent, PREF_MSG_SETGUITOOLICONSSET, static_cast<WPARAM>(enableDarkMode), 0);
if (nppGUI._darkmode._isEnabled) ::SendMessage(_hParent, PREF_MSG_SETGUITABBARICONS, static_cast<WPARAM>(enableDarkMode), 0);
{
// For toolbar: if dark mode enabled & TB_STANDARD is selected, switch to TB_SMALL
bool isStandardChecked = false;
::SendMessage(_hParent, PREF_MSG_ISCHECKED_GENERALPAGE, IDC_RADIO_STANDARD, LPARAM(&isStandardChecked));
if (isStandardChecked)
::SendMessage(_hParent, PREF_MSG_SETTOOLICONSFROMSTDTOSMALL, 0, 0);
// For tabbar: uncheck Alternate icons checkbox
::SendMessage(_hParent, PREF_MSG_DISABLETABBARALTERNATEICONS, 0, 0);
}
changed = true; changed = true;
} }
@ -1356,6 +1436,7 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
case IDC_RADIO_DARKMODE_OLIVE: case IDC_RADIO_DARKMODE_OLIVE:
case IDC_RADIO_DARKMODE_CUSTOMIZED: case IDC_RADIO_DARKMODE_CUSTOMIZED:
case IDD_CUSTOMIZED_RESET_BUTTON: case IDD_CUSTOMIZED_RESET_BUTTON:
{
if (wParam == IDC_RADIO_DARKMODE_BLACK) if (wParam == IDC_RADIO_DARKMODE_BLACK)
{ {
if (nppGUI._darkmode._colorTone == NppDarkMode::blackTone) if (nppGUI._darkmode._colorTone == NppDarkMode::blackTone)
@ -1421,6 +1502,7 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
forceRefresh = true; forceRefresh = true;
enableCustomizedColorCtrls(doEnableCustomizedColorCtrls); enableCustomizedColorCtrls(doEnableCustomizedColorCtrls);
}
break; break;
default: default:

View File

@ -37,8 +37,7 @@ class GeneralSubDlg : public StaticDialog
{ {
public : public :
GeneralSubDlg() = default; GeneralSubDlg() = default;
void setToolIconsFromStdToSmall(); void setTabbarAlternateIcons(bool enable = false);
void disableTabbarAlternateIcons();
private : private :
intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);

View File

@ -17,9 +17,9 @@
#ifndef PREFERENCE_RC_H #ifndef PREFERENCE_RC_H
#define PREFERENCE_RC_H #define PREFERENCE_RC_H
#define PREF_MSG_ISCHECKED_GENERALPAGE (WM_USER + 1) // wParam:checkbox/radiobutton ID in General page. lParam is type of "bool *" to get result //#define PREF_MSG_ISCHECKED_GENERALPAGE (WM_USER + 1) // wParam:checkbox/radiobutton ID in General page. lParam is type of "bool *" to get result
#define PREF_MSG_SETTOOLICONSFROMSTDTOSMALL (WM_USER + 2) #define PREF_MSG_SETGUITOOLICONSSET (WM_USER + 2)
#define PREF_MSG_DISABLETABBARALTERNATEICONS (WM_USER + 3) #define PREF_MSG_SETGUITABBARICONS (WM_USER + 3)
#define IDD_PREFERENCE_BOX 6000 #define IDD_PREFERENCE_BOX 6000
#define IDC_BUTTON_CLOSE (IDD_PREFERENCE_BOX + 1) #define IDC_BUTTON_CLOSE (IDD_PREFERENCE_BOX + 1)
@ -410,7 +410,7 @@
#define IDC_CHECK_FILL_FIND_FIELD_SELECT_CARET (IDD_PREFERENCE_SUB_SEARCHING + 9) #define IDC_CHECK_FILL_FIND_FIELD_SELECT_CARET (IDD_PREFERENCE_SUB_SEARCHING + 9)
#define IDD_PREFERENCE_SUB_DARKMODE 7100 //(IDD_PREFERENCE_BOX + 1100) #define IDD_PREFERENCE_SUB_DARKMODE 7100 //(IDD_PREFERENCE_BOX + 1100)
#define IDC_CHECK_DARKMODE_ENABLE (IDD_PREFERENCE_SUB_DARKMODE + 1) //#define IDC_CHECK_DARKMODE_ENABLE (IDD_PREFERENCE_SUB_DARKMODE + 1)
#define IDC_RADIO_DARKMODE_BLACK (IDD_PREFERENCE_SUB_DARKMODE + 2) #define IDC_RADIO_DARKMODE_BLACK (IDD_PREFERENCE_SUB_DARKMODE + 2)
#define IDC_RADIO_DARKMODE_RED (IDD_PREFERENCE_SUB_DARKMODE + 3) #define IDC_RADIO_DARKMODE_RED (IDD_PREFERENCE_SUB_DARKMODE + 3)
#define IDC_RADIO_DARKMODE_GREEN (IDD_PREFERENCE_SUB_DARKMODE + 4) #define IDC_RADIO_DARKMODE_GREEN (IDD_PREFERENCE_SUB_DARKMODE + 4)
@ -433,6 +433,9 @@
#define IDD_CUSTOMIZED_COLOR11_STATIC (IDD_PREFERENCE_SUB_DARKMODE + 26) #define IDD_CUSTOMIZED_COLOR11_STATIC (IDD_PREFERENCE_SUB_DARKMODE + 26)
#define IDD_CUSTOMIZED_COLOR12_STATIC (IDD_PREFERENCE_SUB_DARKMODE + 27) #define IDD_CUSTOMIZED_COLOR12_STATIC (IDD_PREFERENCE_SUB_DARKMODE + 27)
#define IDD_CUSTOMIZED_RESET_BUTTON (IDD_PREFERENCE_SUB_DARKMODE + 30) #define IDD_CUSTOMIZED_RESET_BUTTON (IDD_PREFERENCE_SUB_DARKMODE + 30)
#define IDC_RADIO_DARKMODE_LIGHTMODE (IDD_PREFERENCE_SUB_DARKMODE + 31)
#define IDC_RADIO_DARKMODE_DARKMODE (IDD_PREFERENCE_SUB_DARKMODE + 32)
#define IDC_RADIO_DARKMODE_FOLLOWWINDOWS (IDD_PREFERENCE_SUB_DARKMODE + 33)
#define IDC_DARKMODE_TONES_GB_STATIC (IDD_PREFERENCE_SUB_DARKMODE + 35) #define IDC_DARKMODE_TONES_GB_STATIC (IDD_PREFERENCE_SUB_DARKMODE + 35)
#define IDD_PREFERENCE_SUB_PERFORMANCE 7140 //(IDD_PREFERENCE_BOX + 1100) #define IDD_PREFERENCE_SUB_PERFORMANCE 7140 //(IDD_PREFERENCE_BOX + 1100)

View File

@ -1007,8 +1007,8 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
} }
bool isSelected = (nTab == ::SendMessage(_hSelf, TCM_GETCURSEL, 0, 0)); bool isSelected = (nTab == ::SendMessage(_hSelf, TCM_GETCURSEL, 0, 0));
TCHAR label[MAX_PATH]; TCHAR label[MAX_PATH] = { '\0' };
TCITEM tci; TCITEM tci{};
tci.mask = TCIF_TEXT|TCIF_IMAGE; tci.mask = TCIF_TEXT|TCIF_IMAGE;
tci.pszText = label; tci.pszText = label;
tci.cchTextMax = MAX_PATH-1; tci.cchTextMax = MAX_PATH-1;
@ -1017,12 +1017,33 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
{ {
::MessageBox(NULL, TEXT("! TCM_GETITEM"), TEXT(""), MB_OK); ::MessageBox(NULL, TEXT("! TCM_GETITEM"), TEXT(""), MB_OK);
} }
const COLORREF colorActiveBg = isDarkMode ? NppDarkMode::getSofterBackgroundColor() : ::GetSysColor(COLOR_BTNFACE);
const COLORREF colorInactiveBgBase = isDarkMode ? NppDarkMode::getBackgroundColor() : ::GetSysColor(COLOR_BTNFACE);
COLORREF colorInactiveBg = liteGrey;
COLORREF colorActiveText = ::GetSysColor(COLOR_BTNTEXT);
COLORREF colorInactiveText = grey;
if (!NppDarkMode::useTabTheme() && isDarkMode)
{
colorInactiveBg = NppDarkMode::getBackgroundColor();
colorActiveText = NppDarkMode::getTextColor();
colorInactiveText = NppDarkMode::getDarkerTextColor();
}
else
{
colorInactiveBg = _inactiveBgColour;
colorActiveText = _activeTextColour;
colorInactiveText = _inactiveTextColour;
}
HDC hDC = pDrawItemStruct->hDC; HDC hDC = pDrawItemStruct->hDC;
int nSavedDC = ::SaveDC(hDC); int nSavedDC = ::SaveDC(hDC);
::SetBkMode(hDC, TRANSPARENT); ::SetBkMode(hDC, TRANSPARENT);
HBRUSH hBrush = ::CreateSolidBrush(!isDarkMode ? ::GetSysColor(COLOR_BTNFACE) : NppDarkMode::getBackgroundColor()); HBRUSH hBrush = ::CreateSolidBrush(colorInactiveBgBase);
::FillRect(hDC, &rect, hBrush); ::FillRect(hDC, &rect, hBrush);
::DeleteObject((HGDIOBJ)hBrush); ::DeleteObject((HGDIOBJ)hBrush);
@ -1085,10 +1106,10 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
RECT barRect = rect; RECT barRect = rect;
if (isSelected) if (isSelected)
{ {
if (isDarkMode) hBrush = ::CreateSolidBrush(colorActiveBg);
{ ::FillRect(hDC, &pDrawItemStruct->rcItem, hBrush);
::FillRect(hDC, &pDrawItemStruct->rcItem, NppDarkMode::getSofterBackgroundBrush()); ::DeleteObject(static_cast<HGDIOBJ>(hBrush));
}
if (_drawTopBar) if (_drawTopBar)
{ {
int topBarHeight = NppParameters::getInstance()._dpiManager.scaleX(4); int topBarHeight = NppParameters::getInstance()._dpiManager.scaleX(4);
@ -1121,28 +1142,26 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
} }
else // inactive tabs else // inactive tabs
{ {
bool draw = false;
RECT rect = _isCtrlMultiLine ? pDrawItemStruct->rcItem : barRect; RECT rect = _isCtrlMultiLine ? pDrawItemStruct->rcItem : barRect;
COLORREF brushColour{}; COLORREF brushColour{};
if (_drawInactiveTab && individualColourId == -1 && !isDarkMode) if (_drawInactiveTab && individualColourId == -1)
{ {
brushColour = _inactiveBgColour; brushColour = colorInactiveBg;
draw = true;
} }
else if (individualColourId != -1) else if (individualColourId != -1)
{ {
brushColour = NppDarkMode::getIndividualTabColour(individualColourId, isDarkMode, false); brushColour = NppDarkMode::getIndividualTabColour(individualColourId, isDarkMode, false);
draw = true; }
else
{
brushColour = colorActiveBg;
} }
if (draw)
{
hBrush = ::CreateSolidBrush(brushColour); hBrush = ::CreateSolidBrush(brushColour);
::FillRect(hDC, &rect, hBrush); ::FillRect(hDC, &rect, hBrush);
::DeleteObject((HGDIOBJ)hBrush); ::DeleteObject((HGDIOBJ)hBrush);
} }
}
// draw close button // draw close button
if (_drawTabCloseButton) if (_drawTabCloseButton)
@ -1158,10 +1177,9 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
else else
idCloseImg = isSelected ? (isDarkMode ? IDR_CLOSETAB_DM : IDR_CLOSETAB) : (isDarkMode ? IDR_CLOSETAB_INACT_DM : IDR_CLOSETAB_INACT); idCloseImg = isSelected ? (isDarkMode ? IDR_CLOSETAB_DM : IDR_CLOSETAB) : (isDarkMode ? IDR_CLOSETAB_INACT_DM : IDR_CLOSETAB_INACT);
HDC hdcMemory; HDC hdcMemory = ::CreateCompatibleDC(hDC);
hdcMemory = ::CreateCompatibleDC(hDC);
HBITMAP hBmp = ::LoadBitmap(_hInst, MAKEINTRESOURCE(idCloseImg)); HBITMAP hBmp = ::LoadBitmap(_hInst, MAKEINTRESOURCE(idCloseImg));
BITMAP bmp; BITMAP bmp{};
::GetObject(hBmp, sizeof(bmp), &bmp); ::GetObject(hBmp, sizeof(bmp), &bmp);
int bmDpiDynamicalWidth = NppParameters::getInstance()._dpiManager.scaleX(bmp.bmWidth); int bmDpiDynamicalWidth = NppParameters::getInstance()._dpiManager.scaleX(bmp.bmWidth);
@ -1180,7 +1198,7 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
if (hImgLst && tci.iImage >= 0) if (hImgLst && tci.iImage >= 0)
{ {
IMAGEINFO info; IMAGEINFO info{};
ImageList_GetImageInfo(hImgLst, tci.iImage, &info); ImageList_GetImageInfo(hImgLst, tci.iImage, &info);
RECT& imageRect = info.rcImage; RECT& imageRect = info.rcImage;
@ -1221,11 +1239,11 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
else else
SelectObject(hDC, _hLargeFont); SelectObject(hDC, _hLargeFont);
} }
SIZE charPixel; SIZE charPixel{};
::GetTextExtentPoint(hDC, TEXT(" "), 1, &charPixel); ::GetTextExtentPoint(hDC, TEXT(" "), 1, &charPixel);
int spaceUnit = charPixel.cx; int spaceUnit = charPixel.cx;
TEXTMETRIC textMetrics; TEXTMETRIC textMetrics{};
GetTextMetrics(hDC, &textMetrics); GetTextMetrics(hDC, &textMetrics);
int textHeight = textMetrics.tmHeight; int textHeight = textMetrics.tmHeight;
int textDescent = textMetrics.tmDescent; int textDescent = textMetrics.tmDescent;
@ -1235,7 +1253,7 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
// This code will read in one character at a time and remove every first ampersand (&). // This code will read in one character at a time and remove every first ampersand (&).
// ex. If input "test && test &&& test &&&&" then output will be "test & test && test &&&". // ex. If input "test && test &&& test &&&&" then output will be "test & test && test &&&".
// Tab's caption must be encoded like this because otherwise tab control would make tab too small or too big for the text. // Tab's caption must be encoded like this because otherwise tab control would make tab too small or too big for the text.
TCHAR decodedLabel[MAX_PATH]; TCHAR decodedLabel[MAX_PATH] = { '\0' };
const TCHAR* in = label; const TCHAR* in = label;
TCHAR* out = decodedLabel; TCHAR* out = decodedLabel;
while (*in != 0) while (*in != 0)
@ -1275,11 +1293,7 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
rect.left += spaceUnit; rect.left += spaceUnit;
} }
COLORREF textColor = isSelected ? _activeTextColour : _inactiveTextColour; COLORREF textColor = isSelected ? colorActiveText : colorInactiveText;
if (isDarkMode)
{
textColor = NppDarkMode::invertLightnessSofter(textColor);
}
::SetTextColor(hDC, textColor); ::SetTextColor(hDC, textColor);