Add option to apply different color to fluent toolbar icons

Fix #16369, fix #15430, close #16370
This commit is contained in:
ozone10 2025-04-03 17:46:00 +02:00 committed by Don Ho
parent f2b13814e8
commit 5447ef7623
14 changed files with 722 additions and 193 deletions

View File

@ -948,11 +948,13 @@ Translation note:
<Global title="General"> <Global title="General">
<Item id="6101" name="Toolbar"/> <Item id="6101" name="Toolbar"/>
<Item id="6102" name="Hide"/> <Item id="6102" name="Hide"/>
<Item id="6103" name="Fluent UI: small"/> <ComboBox id="6135">
<Item id="6104" name="Fluent UI: large"/> <Element name="Fluent UI: small"/>
<Item id="6129" name="Filled Fluent UI: small"/> <Element name="Fluent UI: large"/>
<Item id="6130" name="Filled Fluent UI: large"/> <Element name="Filled Fluent UI: small"/>
<Item id="6105" name="Standard icons: small"/> <Element name="Filled Fluent UI: large"/>
<Element name="Standard icons: small"/>
</ComboBox>
<Item id="6106" name="Tab Bar"/> <Item id="6106" name="Tab Bar"/>
<Item id="6107" name="Reduce"/> <Item id="6107" name="Reduce"/>

View File

@ -948,11 +948,13 @@ Translation note:
<Global title="General"> <Global title="General">
<Item id="6101" name="Toolbar"/> <Item id="6101" name="Toolbar"/>
<Item id="6102" name="Hide"/> <Item id="6102" name="Hide"/>
<Item id="6103" name="Fluent UI: small"/> <ComboBox id="6135">
<Item id="6104" name="Fluent UI: large"/> <Element name="Fluent UI: small"/>
<Item id="6129" name="Filled Fluent UI: small"/> <Element name="Fluent UI: large"/>
<Item id="6130" name="Filled Fluent UI: large"/> <Element name="Filled Fluent UI: small"/>
<Item id="6105" name="Standard icons: small"/> <Element name="Filled Fluent UI: large"/>
<Element name="Standard icons: small"/>
</ComboBox>
<Item id="6106" name="Tab Bar"/> <Item id="6106" name="Tab Bar"/>
<Item id="6107" name="Reduce"/> <Item id="6107" name="Reduce"/>

View File

@ -689,11 +689,10 @@ LRESULT Notepad_plus::init(HWND hwnd)
//-- Tool Bar Section --// //-- Tool Bar Section --//
const int toolbarState = NppDarkMode::getToolBarIconSet(NppDarkMode::isEnabled()); const NppDarkMode::TbIconInfo toolbarIconInfo = NppDarkMode::getToolbarIconInfo();
if (toolbarState != -1) nppGUI._tbIconInfo = toolbarIconInfo;
{ nppGUI._toolBarStatus = static_cast<toolBarStatusType>(nppGUI._tbIconInfo._tbIconSet);
nppGUI._toolBarStatus = static_cast<toolBarStatusType>(toolbarState);
}
toolBarStatusType tbStatus = nppGUI._toolBarStatus; toolBarStatusType tbStatus = nppGUI._toolBarStatus;
willBeShown = nppGUI._toolbarShow; willBeShown = nppGUI._toolbarShow;
@ -8522,8 +8521,12 @@ void Notepad_plus::refreshDarkMode(bool resetStyle)
} }
} }
const int iconState = NppDarkMode::getToolBarIconSet(NppDarkMode::isEnabled()); toolBarStatusType state = TB_STANDARD;
toolBarStatusType state = (iconState == -1) ? _toolBar.getState() : static_cast<toolBarStatusType>(iconState); auto& nppGUITbInfo = nppParams.getNppGUI()._tbIconInfo;
const NppDarkMode::TbIconInfo toolbarIconInfo = NppDarkMode::getToolbarIconInfo();
nppGUITbInfo = toolbarIconInfo;
state = static_cast<toolBarStatusType>(nppGUITbInfo._tbIconSet);
switch (state) switch (state)
{ {
case TB_SMALL: case TB_SMALL:

View File

@ -322,8 +322,12 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
nppGUI._darkmode._isEnabled = enableDarkMode; nppGUI._darkmode._isEnabled = enableDarkMode;
if (!_preference.isCreated()) if (!_preference.isCreated())
{ {
const int iconState = NppDarkMode::getToolBarIconSet(NppDarkMode::isEnabled()); toolBarStatusType state = TB_STANDARD;
toolBarStatusType state = (iconState == -1) ? _toolBar.getState() : static_cast<toolBarStatusType>(iconState); auto& nppGUITbInfo = nppGUI._tbIconInfo;
const NppDarkMode::TbIconInfo toolbarIconInfo = NppDarkMode::getToolbarIconInfo();
nppGUITbInfo = toolbarIconInfo;
state = static_cast<toolBarStatusType>(nppGUITbInfo._tbIconSet);
switch (state) switch (state)
{ {
case TB_SMALL: case TB_SMALL:
@ -3920,7 +3924,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
toolBarStatusType state = _toolBar.getState(); toolBarStatusType state = _toolBar.getState();
if (state != TB_SMALL) if (state != TB_SMALL || static_cast<BOOL>(wParam))
{ {
_toolBar.reduce(); _toolBar.reduce();
} }
@ -3931,7 +3935,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
toolBarStatusType state = _toolBar.getState(); toolBarStatusType state = _toolBar.getState();
if (state != TB_LARGE) if (state != TB_LARGE || static_cast<BOOL>(wParam))
{ {
_toolBar.enlarge(); _toolBar.enlarge();
} }
@ -3942,7 +3946,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
toolBarStatusType state = _toolBar.getState(); toolBarStatusType state = _toolBar.getState();
if (state != TB_SMALL2) if (state != TB_SMALL2 || static_cast<BOOL>(wParam))
{ {
_toolBar.reduceToSet2(); _toolBar.reduceToSet2();
} }
@ -3953,7 +3957,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
toolBarStatusType state = _toolBar.getState(); toolBarStatusType state = _toolBar.getState();
if (state != TB_LARGE2) if (state != TB_LARGE2 || static_cast<BOOL>(wParam))
{ {
_toolBar.enlargeToSet2(); _toolBar.enlargeToSet2();
} }

View File

@ -34,6 +34,7 @@
#ifdef __GNUC__ #ifdef __GNUC__
#include <cmath> #include <cmath>
#include <memory>
#define WINAPI_LAMBDA WINAPI #define WINAPI_LAMBDA WINAPI
#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE #ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 #define DWMWA_USE_IMMERSIVE_DARK_MODE 20
@ -392,6 +393,56 @@ namespace NppDarkMode
return opt; return opt;
} }
constexpr COLORREF cDefaultMainDark = RGB(0xDE, 0xDE, 0xDE);
constexpr COLORREF cDefaultSecondaryDark = RGB(0x4C, 0xC2, 0xFF);
constexpr COLORREF cDefaultMainLight = RGB(0x21, 0x21, 0x21);
constexpr COLORREF cDefaultSecondaryLight = RGB(0x00, 0x78, 0xD4);
static COLORREF cAccentDark = cDefaultSecondaryDark;
static COLORREF cAccentLight = cDefaultSecondaryLight;
static COLORREF adjustClrLightness(COLORREF clr, bool useDark)
{
WORD h = 0;
WORD s = 0;
WORD l = 0;
::ColorRGBToHLS(clr, &h, &l, &s);
constexpr double lightnessThreshold = 50.0 - 3.0;
if (NppDarkMode::calculatePerceivedLightness(clr) < lightnessThreshold)
{
s -= 20;
l += 50;
return useDark ? ::ColorHLSToRGB(h, l, s) : clr;
}
else
{
s += 20;
l -= 50;
return useDark ? clr : ::ColorHLSToRGB(h, l, s);
}
}
static bool initAccentColor()
{
BOOL opaque = TRUE;
COLORREF cAccent = 0;
if (SUCCEEDED(::DwmGetColorizationColor(&cAccent, &opaque)))
{
cAccent = RGB(GetBValue(cAccent), GetGValue(cAccent), GetRValue(cAccent));
cAccentDark = NppDarkMode::adjustClrLightness(cAccent, true);
cAccentLight = NppDarkMode::adjustClrLightness(cAccent, false);
return true;
}
cAccentDark = cDefaultSecondaryDark;
cAccentLight = cDefaultSecondaryLight;
return false;
}
static bool g_isAtLeastWindows10 = false; static bool g_isAtLeastWindows10 = false;
static bool g_isWine = false; static bool g_isWine = false;
@ -401,6 +452,7 @@ namespace NppDarkMode
initExperimentalDarkMode(); initExperimentalDarkMode();
initAdvancedOptions(); initAdvancedOptions();
initAccentColor();
g_isAtLeastWindows10 = NppDarkMode::isWindows10(); g_isAtLeastWindows10 = NppDarkMode::isWindows10();
@ -520,23 +572,72 @@ namespace NppDarkMode
return (lstrcmp(theme.c_str(), L"stylers.xml") == 0) ? L"" : theme; return (lstrcmp(theme.c_str(), L"stylers.xml") == 0) ? L"" : theme;
} }
static bool g_isCustomToolIconUsed = NppParameters::getInstance().getCustomizedToolButtons() != nullptr; TbIconInfo getToolbarIconInfo(bool useDark)
{
auto& toolbarInfo = useDark ? g_advOptions._darkDefaults._tbIconInfo
: g_advOptions._lightDefaults._tbIconInfo;
void setToolBarIconSet(int state2Set, bool useDark) if (toolbarInfo._tbCustomColor == 0)
toolbarInfo._tbCustomColor = NppDarkMode::getAccentColor();
return toolbarInfo;
}
TbIconInfo getToolbarIconInfo()
{
return NppDarkMode::getToolbarIconInfo(NppDarkMode::isEnabled());
}
void setToolbarIconSet(int state2Set, bool useDark)
{ {
if (useDark) if (useDark)
g_advOptions._darkDefaults._toolBarIconSet = state2Set; g_advOptions._darkDefaults._tbIconInfo._tbIconSet = state2Set;
else else
g_advOptions._lightDefaults._toolBarIconSet = state2Set; g_advOptions._lightDefaults._tbIconInfo._tbIconSet = state2Set;
} }
int getToolBarIconSet(bool useDark) void setToolbarIconSet(int state2Set)
{ {
if (g_isCustomToolIconUsed) NppDarkMode::setToolbarIconSet(state2Set, NppDarkMode::isEnabled());
{
return -1;
} }
return useDark ? g_advOptions._darkDefaults._toolBarIconSet : g_advOptions._lightDefaults._toolBarIconSet;
void setToolbarFluentColor(FluentColor color2Set, bool useDark)
{
if (useDark)
g_advOptions._darkDefaults._tbIconInfo._tbColor = color2Set;
else
g_advOptions._lightDefaults._tbIconInfo._tbColor = color2Set;
}
void setToolbarFluentColor(FluentColor color2Set)
{
NppDarkMode::setToolbarFluentColor(color2Set, NppDarkMode::isEnabled());
}
void setToolbarFluentMonochrome(bool setMonochrome, bool useDark)
{
if (useDark)
g_advOptions._darkDefaults._tbIconInfo._tbUseMono = setMonochrome;
else
g_advOptions._lightDefaults._tbIconInfo._tbUseMono = setMonochrome;
}
void setToolbarFluentMonochrome(bool setMonochrome)
{
NppDarkMode::setToolbarFluentMonochrome(setMonochrome, NppDarkMode::isEnabled());
}
void setToolbarFluentCustomColor(COLORREF color, bool useDark)
{
if (useDark)
g_advOptions._darkDefaults._tbIconInfo._tbCustomColor = color;
else
g_advOptions._lightDefaults._tbIconInfo._tbCustomColor = color;
}
void setToolbarFluentCustomColor(COLORREF color)
{
NppDarkMode::setToolbarFluentCustomColor(color, NppDarkMode::isEnabled());
} }
void setTabIconSet(bool useAltIcons, bool useDark) void setTabIconSet(bool useAltIcons, bool useDark)
@ -620,6 +721,11 @@ namespace NppDarkMode
return lightness; return lightness;
} }
COLORREF getAccentColor()
{
return NppDarkMode::isEnabled() ? cAccentDark : cAccentLight;
}
COLORREF getBackgroundColor() { return getTheme()._colors.background; } COLORREF getBackgroundColor() { return getTheme()._colors.background; }
COLORREF getCtrlBackgroundColor() { return getTheme()._colors.softerBackground; } COLORREF getCtrlBackgroundColor() { return getTheme()._colors.softerBackground; }
COLORREF getHotBackgroundColor() { return getTheme()._colors.hotBackground; } COLORREF getHotBackgroundColor() { return getTheme()._colors.hotBackground; }
@ -3751,4 +3857,203 @@ namespace NppDarkMode
return NppDarkMode::onCtlColor(hdc); return NppDarkMode::onCtlColor(hdc);
} }
bool changeFluentIconColor(HICON* phIcon, const std::vector<std::pair<COLORREF, COLORREF>>& colorMappings, int tolerance)
{
if (!*phIcon)
{
return false;
}
HDC hdcScreen = nullptr;
HDC hdcBitmap = nullptr;
BITMAP bm{};
ICONINFO ii{};
HBITMAP hbmNew = nullptr;
std::unique_ptr<RGBQUAD[]> pixels;
const bool changeEverything = colorMappings[0].first == 0;
auto cleanup = [&]()
{
if (hdcScreen) ::ReleaseDC(nullptr, hdcScreen);
if (hdcBitmap) ::DeleteDC(hdcBitmap);
if (ii.hbmColor) ::DeleteObject(ii.hbmColor);
if (ii.hbmMask) ::DeleteObject(ii.hbmMask);
if (hbmNew) ::DeleteObject(hbmNew);
};
hdcScreen = ::GetDC(nullptr);
hdcBitmap = ::CreateCompatibleDC(nullptr);
if (!hdcScreen || !hdcBitmap || !::GetIconInfo(*phIcon, &ii) || !ii.hbmColor || !::GetObject(ii.hbmColor, sizeof(BITMAP), &bm))
{
cleanup();
return false;
}
BITMAPINFO bmi{};
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = bm.bmWidth;
bmi.bmiHeader.biHeight = -bm.bmHeight; // Top-down bitmap
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
pixels = std::make_unique<RGBQUAD[]>(static_cast<size_t>(bm.bmWidth) * bm.bmHeight);
if (!pixels || !::GetDIBits(hdcBitmap, ii.hbmColor, 0, bm.bmHeight, pixels.get(), &bmi, DIB_RGB_COLORS))
{
cleanup();
return false;
}
for (int i = 0; i < bm.bmWidth * bm.bmHeight; i++)
{
if (pixels[i].rgbReserved != 0) // Modify non-transparent pixels
{
if (changeEverything)
{
COLORREF cNew = colorMappings[0].second == 0 ? NppDarkMode::getAccentColor() : colorMappings[0].second;
pixels[i].rgbRed = GetRValue(cNew);
pixels[i].rgbGreen = GetGValue(cNew);
pixels[i].rgbBlue = GetBValue(cNew);
}
else
{
for (const auto& [cToChange, cNew] : colorMappings)
{
if (std::abs(pixels[i].rgbRed - GetRValue(cToChange)) <= tolerance &&
std::abs(pixels[i].rgbGreen - GetGValue(cToChange)) <= tolerance &&
std::abs(pixels[i].rgbBlue - GetBValue(cToChange)) <= tolerance)
{
COLORREF finalNewColor = (cNew == 0) ? NppDarkMode::getAccentColor() : cNew;
pixels[i].rgbRed = GetRValue(finalNewColor);
pixels[i].rgbGreen = GetGValue(finalNewColor);
pixels[i].rgbBlue = GetBValue(finalNewColor);
break;
}
}
}
}
}
hbmNew = ::CreateCompatibleBitmap(hdcScreen, bm.bmWidth, bm.bmHeight);
if (!hbmNew || !::SetDIBits(hdcBitmap, hbmNew, 0, bm.bmHeight, pixels.get(), &bmi, DIB_RGB_COLORS))
{
cleanup();
return false;
}
if (ii.hbmColor)
{
::DeleteObject(ii.hbmColor);
ii.hbmColor = nullptr;
}
ii.hbmColor = hbmNew;
HICON hIconNew = ::CreateIconIndirect(&ii);
if (!hIconNew)
{
cleanup();
return false;
}
::DestroyIcon(*phIcon);
*phIcon = hIconNew;
cleanup();
return true;
}
bool changeFluentIconColor(HICON* phIcon)
{
const auto cMain = NppDarkMode::isEnabled() ? cDefaultMainDark : cDefaultMainLight;
const auto cSecondary = NppDarkMode::isEnabled() ? cDefaultSecondaryDark : cDefaultSecondaryLight;
std::vector<std::pair<COLORREF, COLORREF>> colorMappings;
NppParameters& nppParams = NppParameters::getInstance();
const auto& tbInfo = nppParams.getNppGUI()._tbIconInfo;
COLORREF cOld = tbInfo._tbUseMono ? 0 : cSecondary;
COLORREF cNew = 0;
switch (tbInfo._tbColor)
{
case FluentColor::accent:
{
cNew = 0;
break;
}
case FluentColor::red:
{
cNew = RGB(0xE8, 0x11, 0x23);
break;
}
case FluentColor::green:
{
cNew = RGB(0x00, 0x8B, 0x00);
break;
}
case FluentColor::blue:
{
cNew = RGB(0x00, 0x78, 0xD4);
break;
}
case FluentColor::purple:
{
cNew = RGB(0xB1, 0x46, 0xC2);
break;
}
case FluentColor::cyan:
{
cNew = RGB(0x00, 0xB7, 0xC3);
break;
}
case FluentColor::olive:
{
cNew = RGB(0x49, 0x82, 0x05);
break;
}
case FluentColor::yellow:
{
cNew = RGB(0xFF, 0xB9, 0x00);
break;
}
case FluentColor::custom:
{
if (tbInfo._tbCustomColor != 0)
{
cNew = tbInfo._tbCustomColor;
break;
}
[[fallthrough]];
}
case FluentColor::defaultColor:
{
if (tbInfo._tbUseMono)
{
cNew = cMain;
break;
}
[[fallthrough]];
}
default:
{
return false;
}
}
colorMappings = { {cOld, cNew} };
return NppDarkMode::changeFluentIconColor(phIcon, colorMappings);
}
} }

View File

@ -17,6 +17,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <vector>
#include <windows.h> #include <windows.h>
@ -79,10 +80,36 @@ namespace NppDarkMode
dark = 2 dark = 2
}; };
enum class FluentColor
{
defaultColor = 0,
accent = 1,
red = 2,
green = 3,
blue = 4,
purple = 5,
cyan = 6,
olive = 7,
yellow = 8,
custom = 9,
maxValue = 10
};
struct TbIconInfo
{
int _tbIconSet = 4;
// fluent icon color
FluentColor _tbColor = FluentColor::defaultColor;
// fluent icon custom color, used when _tbColor == FluentColor::custom
COLORREF _tbCustomColor = 0;
// does fluent icon use monochrome colorization
bool _tbUseMono = false;
};
struct AdvOptDefaults struct AdvOptDefaults
{ {
std::wstring _xmlFileName; std::wstring _xmlFileName;
int _toolBarIconSet = -1; TbIconInfo _tbIconInfo{};
int _tabIconSet = -1; int _tabIconSet = -1;
bool _tabUseTheme = false; bool _tabUseTheme = false;
}; };
@ -91,8 +118,8 @@ namespace NppDarkMode
{ {
bool _enableWindowsMode = false; bool _enableWindowsMode = false;
NppDarkMode::AdvOptDefaults _darkDefaults{ L"DarkModeDefault.xml", 0, 2, false }; NppDarkMode::AdvOptDefaults _darkDefaults{ L"DarkModeDefault.xml", {0, FluentColor::defaultColor, 0, false}, 2, false};
NppDarkMode::AdvOptDefaults _lightDefaults{ L"", 4, 0, true }; NppDarkMode::AdvOptDefaults _lightDefaults{ L"", { 4, FluentColor::defaultColor, 0, false }, 0, true };
}; };
constexpr UINT WM_SETBUTTONIDEALSIZE = (WM_USER + 4200); constexpr UINT WM_SETBUTTONIDEALSIZE = (WM_USER + 4200);
@ -112,8 +139,16 @@ namespace NppDarkMode
void setWindowsMode(bool enable); void setWindowsMode(bool enable);
std::wstring getThemeName(); std::wstring getThemeName();
void setThemeName(const std::wstring& newThemeName); void setThemeName(const std::wstring& newThemeName);
int getToolBarIconSet(bool useDark); TbIconInfo getToolbarIconInfo(bool useDark);
void setToolBarIconSet(int state2Set, bool useDark); TbIconInfo getToolbarIconInfo();
void setToolbarIconSet(int state2Set, bool useDark);
void setToolbarIconSet(int state2Set);
void setToolbarFluentColor(FluentColor color2Set, bool useDark);
void setToolbarFluentColor(FluentColor color2Set);
void setToolbarFluentMonochrome(bool setMonochrome, bool useDark);
void setToolbarFluentMonochrome(bool setMonochrome);
void setToolbarFluentCustomColor(COLORREF color, bool useDark);
void setToolbarFluentCustomColor(COLORREF color);
int getTabIconSet(bool useDark); int getTabIconSet(bool useDark);
void setTabIconSet(bool useAltIcons, bool useDark); void setTabIconSet(bool useAltIcons, bool useDark);
bool useTabTheme(); bool useTabTheme();
@ -128,6 +163,8 @@ namespace NppDarkMode
void setDarkTone(ColorTone colorToneChoice); void setDarkTone(ColorTone colorToneChoice);
COLORREF getAccentColor();
COLORREF getBackgroundColor(); COLORREF getBackgroundColor();
COLORREF getCtrlBackgroundColor(); COLORREF getCtrlBackgroundColor();
COLORREF getHotBackgroundColor(); COLORREF getHotBackgroundColor();
@ -240,4 +277,7 @@ namespace NppDarkMode
LRESULT onCtlColorError(HDC hdc); LRESULT onCtlColorError(HDC hdc);
LRESULT onCtlColorDlgStaticText(HDC hdc, bool isTextEnabled); LRESULT onCtlColorDlgStaticText(HDC hdc, bool isTextEnabled);
LRESULT onCtlColorListbox(WPARAM wParam, LPARAM lParam); LRESULT onCtlColorListbox(WPARAM wParam, LPARAM lParam);
bool changeFluentIconColor(HICON* phIcon, const std::vector<std::pair<COLORREF, COLORREF>>& colorMappings, int tolerance = 3);
bool changeFluentIconColor(HICON* phIcon);
} }

View File

@ -4797,6 +4797,32 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
else// if (!lstrcmp(val, L"yes")) else// if (!lstrcmp(val, L"yes"))
_nppGUI._toolbarShow = true; _nppGUI._toolbarShow = true;
} }
int i = 0;
val = element->Attribute(L"fluentColor", &i);
if (val)
{
auto& tbColor = _nppGUI._tbIconInfo._tbColor;
tbColor = static_cast<NppDarkMode::FluentColor>(i);
}
val = element->Attribute(L"fluentCustomColor", &i);
if (val)
{
auto& tbColor = _nppGUI._tbIconInfo._tbCustomColor;
tbColor = i;
}
val = element->Attribute(L"fluentMono");
if (val)
{
auto& tbMono = _nppGUI._tbIconInfo._tbUseMono;
if (!lstrcmp(val, L"no"))
tbMono = false;
else// if (!lstrcmp(val, L"yes"))
tbMono = true;
}
TiXmlNode *n = childNode->FirstChild(); TiXmlNode *n = childNode->FirstChild();
if (n) if (n)
{ {
@ -4814,6 +4840,7 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
else //if (!lstrcmp(val, L"standard")) else //if (!lstrcmp(val, L"standard"))
_nppGUI._toolBarStatus = TB_STANDARD; _nppGUI._toolBarStatus = TB_STANDARD;
} }
} }
} }
else if (!lstrcmp(nm, L"StatusBar")) else if (!lstrcmp(nm, L"StatusBar"))
@ -6343,20 +6370,20 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
return defaultName; return defaultName;
}; };
auto parseToolBarIconsAttribute = [&element](const wchar_t* name, int defaultValue = -1) -> int { auto parseMinMaxAttribute = [&element](const wchar_t* name, int defaultValue = -1, int maxValue = 2, int minValue = 0) -> int {
int val; int val;
const wchar_t* valStr = element->Attribute(name, &val); const wchar_t* valStr = element->Attribute(name, &val);
if (valStr != nullptr && (val >= 0 && val <= 4)) if (valStr != nullptr && (val >= minValue && val <= maxValue))
{ {
return val; return val;
} }
return defaultValue; return defaultValue;
}; };
auto parseTabIconsAttribute = [&element](const wchar_t* name, int defaultValue = -1) -> int { auto parseIntAttribute = [&element](const wchar_t* name, int defaultValue = -1) -> int {
int val; int val;
const wchar_t* valStr = element->Attribute(name, &val); const wchar_t* valStr = element->Attribute(name, &val);
if (valStr != nullptr && (val >= 0 && val <= 2)) if (valStr != nullptr)
{ {
return val; return val;
} }
@ -6366,18 +6393,28 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
auto& windowsMode = _nppGUI._darkmode._advOptions._enableWindowsMode; auto& windowsMode = _nppGUI._darkmode._advOptions._enableWindowsMode;
windowsMode = parseYesNoBoolAttribute(L"enableWindowsMode"); windowsMode = parseYesNoBoolAttribute(L"enableWindowsMode");
constexpr int fluentColorMaxValue = static_cast<int>(NppDarkMode::FluentColor::maxValue) - 1;
auto& darkDefaults = _nppGUI._darkmode._advOptions._darkDefaults; auto& darkDefaults = _nppGUI._darkmode._advOptions._darkDefaults;
auto& darkThemeName = darkDefaults._xmlFileName; auto& darkThemeName = darkDefaults._xmlFileName;
auto& darkTbInfo = darkDefaults._tbIconInfo;
darkThemeName = parseStringAttribute(L"darkThemeName", L"DarkModeDefault.xml"); darkThemeName = parseStringAttribute(L"darkThemeName", L"DarkModeDefault.xml");
darkDefaults._toolBarIconSet = parseToolBarIconsAttribute(L"darkToolBarIconSet", 0); darkTbInfo._tbIconSet = parseMinMaxAttribute(L"darkToolBarIconSet", 0, 4);
darkDefaults._tabIconSet = parseTabIconsAttribute(L"darkTabIconSet", 2); darkTbInfo._tbColor = static_cast<NppDarkMode::FluentColor>(parseMinMaxAttribute(L"darkTbFluentColor", 0, fluentColorMaxValue));
darkTbInfo._tbCustomColor = parseIntAttribute(L"darkTbFluentCustomColor", 0);
darkTbInfo._tbUseMono = parseYesNoBoolAttribute(L"darkTbFluentMono");
darkDefaults._tabIconSet = parseMinMaxAttribute(L"darkTabIconSet", 2);
darkDefaults._tabUseTheme = parseYesNoBoolAttribute(L"darkTabUseTheme"); darkDefaults._tabUseTheme = parseYesNoBoolAttribute(L"darkTabUseTheme");
auto& lightDefaults = _nppGUI._darkmode._advOptions._lightDefaults; auto& lightDefaults = _nppGUI._darkmode._advOptions._lightDefaults;
auto& lightThemeName = lightDefaults._xmlFileName; auto& lightThemeName = lightDefaults._xmlFileName;
auto& lightTbInfo = lightDefaults._tbIconInfo;
lightThemeName = parseStringAttribute(L"lightThemeName"); lightThemeName = parseStringAttribute(L"lightThemeName");
lightDefaults._toolBarIconSet = parseToolBarIconsAttribute(L"lightToolBarIconSet", 4); lightTbInfo._tbIconSet = parseMinMaxAttribute(L"lightToolBarIconSet", 4, 4);
lightDefaults._tabIconSet = parseTabIconsAttribute(L"lightTabIconSet", 0); lightTbInfo._tbColor = static_cast<NppDarkMode::FluentColor>(parseMinMaxAttribute(L"lightTbFluentColor", 0, fluentColorMaxValue));
lightTbInfo._tbCustomColor = parseIntAttribute(L"lightTbFluentCustomColor", 0);
lightTbInfo._tbUseMono = parseYesNoBoolAttribute(L"lightTbFluentMono");
lightDefaults._tabIconSet = parseMinMaxAttribute(L"lightTabIconSet", 0);
lightDefaults._tabUseTheme = parseYesNoBoolAttribute(L"lightTabUseTheme", true); lightDefaults._tabUseTheme = parseYesNoBoolAttribute(L"lightTabUseTheme", true);
// Windows mode is handled later in Notepad_plus_Window::init from Notepad_plus_Window.cpp // Windows mode is handled later in Notepad_plus_Window::init from Notepad_plus_Window.cpp
@ -7267,6 +7304,10 @@ void NppParameters::createXmlTreeFromGUIParams()
GUIConfigElement->SetAttribute(L"name", L"ToolBar"); GUIConfigElement->SetAttribute(L"name", L"ToolBar");
const wchar_t *pStr = (_nppGUI._toolbarShow) ? L"yes" : L"no"; const wchar_t *pStr = (_nppGUI._toolbarShow) ? L"yes" : L"no";
GUIConfigElement->SetAttribute(L"visible", pStr); GUIConfigElement->SetAttribute(L"visible", pStr);
GUIConfigElement->SetAttribute(L"fluentColor", static_cast<int>(_nppGUI._tbIconInfo._tbColor));
GUIConfigElement->SetAttribute(L"fluentCustomColor", _nppGUI._tbIconInfo._tbCustomColor);
pStr = (_nppGUI._tbIconInfo._tbUseMono) ? L"yes" : L"no";
GUIConfigElement->SetAttribute(L"fluentMono", pStr);
if (_nppGUI._toolBarStatus == TB_SMALL) if (_nppGUI._toolBarStatus == TB_SMALL)
pStr = L"small"; pStr = L"small";
@ -7841,17 +7882,30 @@ void NppParameters::createXmlTreeFromGUIParams()
GUIConfigElement->SetAttribute(L"customColorDisabledEdge", _nppGUI._darkmode._customColors.disabledEdge); GUIConfigElement->SetAttribute(L"customColorDisabledEdge", _nppGUI._darkmode._customColors.disabledEdge);
// advanced options section // advanced options section
setYesNoBoolAttribute(L"enableWindowsMode", _nppGUI._darkmode._advOptions._enableWindowsMode); const auto& advOpt = _nppGUI._darkmode._advOptions;
setYesNoBoolAttribute(L"enableWindowsMode", advOpt._enableWindowsMode);
GUIConfigElement->SetAttribute(L"darkThemeName", _nppGUI._darkmode._advOptions._darkDefaults._xmlFileName.c_str()); const auto& darkDefaults = advOpt._darkDefaults;
GUIConfigElement->SetAttribute(L"darkToolBarIconSet", _nppGUI._darkmode._advOptions._darkDefaults._toolBarIconSet); auto& darkThemeName = darkDefaults._xmlFileName;
GUIConfigElement->SetAttribute(L"darkTabIconSet", _nppGUI._darkmode._advOptions._darkDefaults._tabIconSet); auto& darkTbInfo = darkDefaults._tbIconInfo;
setYesNoBoolAttribute(L"darkTabUseTheme", _nppGUI._darkmode._advOptions._darkDefaults._tabUseTheme); GUIConfigElement->SetAttribute(L"darkThemeName", darkThemeName.c_str());
GUIConfigElement->SetAttribute(L"darkToolBarIconSet", darkTbInfo._tbIconSet);
GUIConfigElement->SetAttribute(L"darkTbFluentColor", static_cast<int>(darkTbInfo._tbColor));
GUIConfigElement->SetAttribute(L"darkTbFluentCustomColor", darkTbInfo._tbCustomColor);
setYesNoBoolAttribute(L"darkTbFluentMono", darkTbInfo._tbUseMono);
GUIConfigElement->SetAttribute(L"darkTabIconSet", darkDefaults._tabIconSet);
setYesNoBoolAttribute(L"darkTabUseTheme", darkDefaults._tabUseTheme);
GUIConfigElement->SetAttribute(L"lightThemeName", _nppGUI._darkmode._advOptions._lightDefaults._xmlFileName.c_str()); const auto& lightDefaults = advOpt._lightDefaults;
GUIConfigElement->SetAttribute(L"lightToolBarIconSet", _nppGUI._darkmode._advOptions._lightDefaults._toolBarIconSet); const auto& lightThemeName = lightDefaults._xmlFileName;
GUIConfigElement->SetAttribute(L"lightTabIconSet", _nppGUI._darkmode._advOptions._lightDefaults._tabIconSet); const auto& lightTbInfo = lightDefaults._tbIconInfo;
setYesNoBoolAttribute(L"lightTabUseTheme", _nppGUI._darkmode._advOptions._lightDefaults._tabUseTheme); GUIConfigElement->SetAttribute(L"lightThemeName", lightThemeName.c_str());
GUIConfigElement->SetAttribute(L"lightToolBarIconSet", lightTbInfo._tbIconSet);
GUIConfigElement->SetAttribute(L"lightTbFluentColor", static_cast<int>(lightTbInfo._tbColor));
GUIConfigElement->SetAttribute(L"lightTbFluentCustomColor", lightTbInfo._tbCustomColor);
setYesNoBoolAttribute(L"lightTbFluentMono", lightTbInfo._tbUseMono);
GUIConfigElement->SetAttribute(L"lightTabIconSet", lightDefaults._tabIconSet);
setYesNoBoolAttribute(L"lightTabUseTheme", 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

@ -792,6 +792,7 @@ struct LargeFileRestriction final
struct NppGUI final struct NppGUI final
{ {
toolBarStatusType _toolBarStatus = TB_STANDARD; toolBarStatusType _toolBarStatus = TB_STANDARD;
NppDarkMode::TbIconInfo _tbIconInfo{ TB_STANDARD, NppDarkMode::FluentColor::defaultColor, 0, false };
bool _toolbarShow = true; bool _toolbarShow = true;
bool _statusBarShow = true; bool _statusBarShow = true;
bool _menuBarShow = true; bool _menuBarShow = true;

View File

@ -43,7 +43,7 @@ void IconList::create(int iconSize, HINSTANCE hInst, int* iconIDArray, int iconI
addIcon(iconIDArray[i], iconSize, iconSize); addIcon(iconIDArray[i], iconSize, iconSize);
} }
void IconList::addIcon(int iconID, int cx, int cy, int failIconID) const void IconList::addIcon(int iconID, int cx, int cy, int failIconID, bool isToolbarNormal) const
{ {
HICON hIcon = nullptr; HICON hIcon = nullptr;
DPIManagerV2::loadIcon(_hInst, MAKEINTRESOURCE(iconID), cx, cy, &hIcon, LR_DEFAULTSIZE); DPIManagerV2::loadIcon(_hInst, MAKEINTRESOURCE(iconID), cx, cy, &hIcon, LR_DEFAULTSIZE);
@ -81,6 +81,8 @@ void IconList::addIcon(int iconID, int cx, int cy, int failIconID) const
if (hIcon != nullptr) if (hIcon != nullptr)
{ {
if (isToolbarNormal)
NppDarkMode::changeFluentIconColor(&hIcon);
::ImageList_AddIcon(_hImglst, hIcon); ::ImageList_AddIcon(_hImglst, hIcon);
::DestroyIcon(hIcon); ::DestroyIcon(hIcon);
} }
@ -134,14 +136,14 @@ void ToolBarIcons::reInit(int size)
{ {
if (_tbiis[i]._defaultIcon != -1) if (_tbiis[i]._defaultIcon != -1)
{ {
_iconListVector[HLIST_DEFAULT].addIcon(_tbiis[i]._defaultIcon, size, size, _tbiis[i]._stdIcon); _iconListVector[HLIST_DEFAULT].addIcon(_tbiis[i]._defaultIcon, size, size, _tbiis[i]._stdIcon, true);
_iconListVector[HLIST_DISABLE].addIcon(_tbiis[i]._grayIcon, size, size, _tbiis[i]._stdIcon); _iconListVector[HLIST_DISABLE].addIcon(_tbiis[i]._grayIcon, size, size, _tbiis[i]._stdIcon);
_iconListVector[HLIST_DEFAULT2].addIcon(_tbiis[i]._defaultIcon2, size, size, _tbiis[i]._stdIcon); _iconListVector[HLIST_DEFAULT2].addIcon(_tbiis[i]._defaultIcon2, size, size, _tbiis[i]._stdIcon, true);
_iconListVector[HLIST_DISABLE2].addIcon(_tbiis[i]._grayIcon2, size, size, _tbiis[i]._stdIcon); _iconListVector[HLIST_DISABLE2].addIcon(_tbiis[i]._grayIcon2, size, size, _tbiis[i]._stdIcon);
_iconListVector[HLIST_DEFAULT_DM].addIcon(_tbiis[i]._defaultDarkModeIcon, size, size, _tbiis[i]._stdIcon); _iconListVector[HLIST_DEFAULT_DM].addIcon(_tbiis[i]._defaultDarkModeIcon, size, size, _tbiis[i]._stdIcon, true);
_iconListVector[HLIST_DISABLE_DM].addIcon(_tbiis[i]._grayDarkModeIcon, size, size, _tbiis[i]._stdIcon); _iconListVector[HLIST_DISABLE_DM].addIcon(_tbiis[i]._grayDarkModeIcon, size, size, _tbiis[i]._stdIcon);
_iconListVector[HLIST_DEFAULT_DM2].addIcon(_tbiis[i]._defaultDarkModeIcon2, size, size, _tbiis[i]._stdIcon); _iconListVector[HLIST_DEFAULT_DM2].addIcon(_tbiis[i]._defaultDarkModeIcon2, size, size, _tbiis[i]._stdIcon, true);
_iconListVector[HLIST_DISABLE_DM2].addIcon(_tbiis[i]._grayDarkModeIcon2, size, size, _tbiis[i]._stdIcon); _iconListVector[HLIST_DISABLE_DM2].addIcon(_tbiis[i]._grayDarkModeIcon2, size, size, _tbiis[i]._stdIcon);
} }
} }

View File

@ -39,7 +39,7 @@ public :
}; };
HIMAGELIST getHandle() const {return _hImglst;}; HIMAGELIST getHandle() const {return _hImglst;};
void addIcon(int iconID, int cx = 16, int cy = 16, int failIconID = -1) const; void addIcon(int iconID, int cx = 16, int cy = 16, int failIconID = -1, bool isToolbarNormal = false) const;
void addIcon(HICON hIcon) const; void addIcon(HICON hIcon) const;
bool changeIcon(size_t index, const wchar_t *iconLocation) const; bool changeIcon(size_t index, const wchar_t *iconLocation) const;

View File

@ -47,11 +47,11 @@ BEGIN
GROUPBOX "Toolbar",IDC_TOOLBAR_GB_STATIC,39,75,186,91,BS_CENTER GROUPBOX "Toolbar",IDC_TOOLBAR_GB_STATIC,39,75,186,91,BS_CENTER
CONTROL "Hide",IDC_CHECK_HIDE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,84,100,10 CONTROL "Hide",IDC_CHECK_HIDE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,84,100,10
CONTROL "Fluent UI: small",IDC_RADIO_SMALLICON,"Button",BS_AUTORADIOBUTTON,45,100,174,10 COMBOBOX IDC_COMBO_TOOLBAR_ICON,45,97,174,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "Fluent UI: large",IDC_RADIO_BIGICON,"Button",BS_AUTORADIOBUTTON,45,113,174,10 LTEXT "Fluent icon color",IDC_STATIC_TOOLBAR_ICON_COLOR,48,115,171,8
CONTROL "Filled Fluent UI: small",IDC_RADIO_SMALLICON2,"Button",BS_AUTORADIOBUTTON,45,126,174,10 COMBOBOX IDC_COMBO_TOOLBAR_ICON_COLOR,45,125,154,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "Filled Fluent UI: large",IDC_RADIO_BIGICON2,"Button",BS_AUTORADIOBUTTON,45,139,174,10 LTEXT "",IDC_STATIC,223,127,1,8
CONTROL "Standard icons: small",IDC_RADIO_STANDARD,"Button",BS_AUTORADIOBUTTON,45,152,174,10 CONTROL "Use monochrome color for Fluent UI",IDC_CHECK_TOOLBAR_ICON_MONO,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,143,174,10
GROUPBOX "Status Bar",IDC_STATUSBAR_GB_STATIC,39,169,186,26,BS_CENTER GROUPBOX "Status Bar",IDC_STATUSBAR_GB_STATIC,39,169,186,26,BS_CENTER
CONTROL "Hide",IDC_CHECK_HIDESTATUSBAR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,179,174,10 CONTROL "Hide",IDC_CHECK_HIDESTATUSBAR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,179,174,10

View File

@ -290,80 +290,22 @@ intptr_t CALLBACK PreferenceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
{ {
const HWND hGeneralSubDlg = _generalSubDlg.getHSelf(); const HWND hGeneralSubDlg = _generalSubDlg.getHSelf();
auto checkOrUncheckBtn = [&hGeneralSubDlg](int id, WPARAM check = BST_UNCHECKED) -> void
{
::SendDlgItemMessage(hGeneralSubDlg, id, BM_SETCHECK, check, 0);
};
const int iconState = NppDarkMode::getToolBarIconSet(static_cast<bool>(wParam));
NppParameters& nppParams = NppParameters::getInstance(); NppParameters& nppParams = NppParameters::getInstance();
NppGUI& nppGUI = nppParams.getNppGUI(); NppGUI& nppGUI = nppParams.getNppGUI();
auto& nppGUITbInfo = nppGUI._tbIconInfo;
const NppDarkMode::TbIconInfo toolbarIconInfo = NppDarkMode::getToolbarIconInfo(static_cast<bool>(wParam));
nppGUITbInfo = toolbarIconInfo;
nppGUI._toolBarStatus = static_cast<toolBarStatusType>(nppGUITbInfo._tbIconSet);
if (iconState != -1) ::SendDlgItemMessage(hGeneralSubDlg, IDC_COMBO_TOOLBAR_ICON, CB_SETCURSEL, nppGUI._toolBarStatus, 0);
{ ::SendDlgItemMessage(hGeneralSubDlg, IDC_COMBO_TOOLBAR_ICON_COLOR, CB_SETCURSEL, static_cast<WPARAM>(nppGUITbInfo._tbColor), 0);
nppGUI._toolBarStatus = static_cast<toolBarStatusType>(iconState); ::SendDlgItemMessage(hGeneralSubDlg, IDC_CHECK_TOOLBAR_ICON_MONO, BM_SETCHECK, nppGUITbInfo._tbUseMono ? BST_CHECKED : BST_UNCHECKED, 0);
}
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); const bool enable = nppGUI._toolBarStatus != TB_STANDARD;
checkOrUncheckBtn(IDC_RADIO_SMALLICON); ::EnableWindow(::GetDlgItem(hGeneralSubDlg, IDC_COMBO_TOOLBAR_ICON_COLOR), enable ? TRUE : FALSE);
checkOrUncheckBtn(IDC_RADIO_BIGICON); ::EnableWindow(::GetDlgItem(hGeneralSubDlg, IDC_CHECK_TOOLBAR_ICON_MONO), enable ? TRUE : FALSE);
checkOrUncheckBtn(IDC_RADIO_SMALLICON2);
checkOrUncheckBtn(IDC_RADIO_BIGICON2);
switch (nppGUI._toolBarStatus) _generalSubDlg.enableColorPicker(static_cast<bool>(wParam), enable);
{
case TB_LARGE:
{
checkOrUncheckBtn(IDC_RADIO_BIGICON, BST_CHECKED);
//::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_TOOLBARENLARGE, 0, 0);
break;
}
case TB_SMALL2:
{
checkOrUncheckBtn(IDC_RADIO_SMALLICON2, BST_CHECKED);
//::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_TOOLBARREDUCESET2, 0, 0);
break;
}
case TB_LARGE2:
{
checkOrUncheckBtn(IDC_RADIO_BIGICON2, BST_CHECKED);
//::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_TOOLBARENLARGESET2, 0, 0);
break;
}
case TB_STANDARD:
{
checkOrUncheckBtn(IDC_RADIO_STANDARD, BST_CHECKED);
//::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_TOOLBARSTANDARD, 0, 0);
break;
}
//case TB_SMALL:
default:
{
checkOrUncheckBtn(IDC_RADIO_SMALLICON, BST_CHECKED);
//::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_TOOLBARREDUCE, 0, 0);
}
}
return TRUE; return TRUE;
} }
@ -559,7 +501,94 @@ void GeneralSubDlg::setTabbarAlternateIcons(bool enable)
} }
} }
intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) void GeneralSubDlg::enableColorPicker(bool useDark, bool doEnable)
{
NppParameters& nppParam = NppParameters::getInstance();
NppGUI& nppGUI = nppParam.getNppGUI();
const auto& tbInfo = nppGUI._tbIconInfo;
const bool enable = doEnable && (tbInfo._tbColor == NppDarkMode::FluentColor::custom);
::EnableWindow(_pIconColorPicker->getHSelf(), enable ? TRUE : FALSE);
if (enable)
{
_pIconColorPicker->setColour(tbInfo._tbCustomColor);
}
else
{
COLORREF disabledColor = useDark ? NppDarkMode::getDlgBackgroundColor() : ::GetSysColor(COLOR_3DFACE);
_pIconColorPicker->setColour(disabledColor);
}
_pIconColorPicker->setEnabled(enable);
_pIconColorPicker->redraw();
}
UINT GeneralSubDlg::getToolbarIconSetMsg(int* idxIconSet)
{
const auto idx = std::min<int>(static_cast<int>(::SendDlgItemMessage(_hSelf, IDC_COMBO_TOOLBAR_ICON, CB_GETCURSEL, 0, 0)), TB_STANDARD);
UINT msg = NPPM_INTERNAL_TOOLBARSTANDARD;
switch (idx)
{
case 0:
{
msg = NPPM_INTERNAL_TOOLBARREDUCE;
break;
}
case 1:
{
msg = NPPM_INTERNAL_TOOLBARENLARGE;
break;
}
case 2:
{
msg = NPPM_INTERNAL_TOOLBARREDUCESET2;
break;
}
case 3:
{
msg = NPPM_INTERNAL_TOOLBARENLARGESET2;
break;
}
case 4:
default:
{
break;
}
}
if (idxIconSet != nullptr)
{
*idxIconSet = idx;
}
return msg;
}
void GeneralSubDlg::move2CtrlLeft(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight)
{
POINT p{};
RECT rc{};
::GetWindowRect(::GetDlgItem(_hSelf, ctrlID), &rc);
NppParameters& nppParam = NppParameters::getInstance();
if (nppParam.getNativeLangSpeaker()->isRTL())
p.x = rc.right + _dpiManager.scale(5) + handle2MoveWidth;
else
p.x = rc.left - _dpiManager.scale(5) - handle2MoveWidth;
p.y = rc.top + ((rc.bottom - rc.top) / 2) - handle2MoveHeight / 2;
::ScreenToClient(_hSelf, &p);
::MoveWindow(handle2Move, p.x, p.y, handle2MoveWidth, handle2MoveHeight, TRUE);
}
intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{ {
NppParameters& nppParam = NppParameters::getInstance(); NppParameters& nppParam = NppParameters::getInstance();
NppGUI& nppGUI = nppParam.getNppGUI(); NppGUI& nppGUI = nppParam.getNppGUI();
@ -569,33 +598,59 @@ intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
toolBarStatusType tbStatus = nppGUI._toolBarStatus; toolBarStatusType tbStatus = nppGUI._toolBarStatus;
auto& nppGUITbInfo = nppGUI._tbIconInfo;
const auto fluentColor = static_cast<int>(nppGUITbInfo._tbColor);
int tabBarStatus = nppGUI._tabStatus; int tabBarStatus = nppGUI._tabStatus;
bool showTool = nppGUI._toolbarShow; bool showTool = nppGUI._toolbarShow;
bool showStatus = nppGUI._statusBarShow; bool showStatus = nppGUI._statusBarShow;
bool showMenu = nppGUI._menuBarShow; bool showMenu = nppGUI._menuBarShow;
bool hideRightShortcutsFromMenu = nppGUI._hideMenuRightShortcuts; bool hideRightShortcutsFromMenu = nppGUI._hideMenuRightShortcuts;
::SendDlgItemMessage(_hSelf, IDC_CHECK_HIDE, BM_SETCHECK, showTool?BST_UNCHECKED:BST_CHECKED, 0); auto addComboItem = [&](int comboBoxId, const wchar_t* itemText) -> void
int ID2Check = 0;
switch (tbStatus)
{ {
case TB_SMALL : ::SendDlgItemMessage(_hSelf, comboBoxId, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(itemText));
ID2Check = IDC_RADIO_SMALLICON; };
break;
case TB_LARGE : ::SendDlgItemMessage(_hSelf, IDC_CHECK_HIDE, BM_SETCHECK, showTool ? BST_UNCHECKED:BST_CHECKED, 0);
ID2Check = IDC_RADIO_BIGICON;
break; addComboItem(IDC_COMBO_TOOLBAR_ICON, L"Fluent UI: small");
case TB_SMALL2 : addComboItem(IDC_COMBO_TOOLBAR_ICON, L"Fluent UI: large");
ID2Check = IDC_RADIO_SMALLICON2; addComboItem(IDC_COMBO_TOOLBAR_ICON, L"Filled Fluent UI: small");
break; addComboItem(IDC_COMBO_TOOLBAR_ICON, L"Filled Fluent UI: large");
case TB_LARGE2 : addComboItem(IDC_COMBO_TOOLBAR_ICON, L"Standard icons: small");
ID2Check = IDC_RADIO_BIGICON2;
break; ::SendDlgItemMessage(_hSelf, IDC_COMBO_TOOLBAR_ICON, CB_SETCURSEL, tbStatus, 0);
case TB_STANDARD:
default : addComboItem(IDC_COMBO_TOOLBAR_ICON_COLOR, L"Default color");
ID2Check = IDC_RADIO_STANDARD; addComboItem(IDC_COMBO_TOOLBAR_ICON_COLOR, L"Accent");
} addComboItem(IDC_COMBO_TOOLBAR_ICON_COLOR, L"Red");
::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0); addComboItem(IDC_COMBO_TOOLBAR_ICON_COLOR, L"Green");
addComboItem(IDC_COMBO_TOOLBAR_ICON_COLOR, L"Blue");
addComboItem(IDC_COMBO_TOOLBAR_ICON_COLOR, L"Purple");
addComboItem(IDC_COMBO_TOOLBAR_ICON_COLOR, L"Cyan");
addComboItem(IDC_COMBO_TOOLBAR_ICON_COLOR, L"Olive");
addComboItem(IDC_COMBO_TOOLBAR_ICON_COLOR, L"Yellow");
addComboItem(IDC_COMBO_TOOLBAR_ICON_COLOR, L"Custom");
::SendDlgItemMessage(_hSelf, IDC_COMBO_TOOLBAR_ICON_COLOR, CB_SETCURSEL, fluentColor, 0);
setChecked(IDC_CHECK_TOOLBAR_ICON_MONO, nppGUITbInfo._tbUseMono);
const bool enable = tbStatus != TB_STANDARD;
::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_TOOLBAR_ICON_COLOR), enable ? TRUE : FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_TOOLBAR_ICON_MONO), enable ? TRUE : FALSE);
_dpiManager.setDpi(_hSelf);
const int cpDynamicalSize = _dpiManager.scale(25);
_pIconColorPicker = new ColourPicker;
_pIconColorPicker->init(_hInst, _hSelf);
move2CtrlLeft(IDC_STATIC, _pIconColorPicker->getHSelf(), cpDynamicalSize, cpDynamicalSize);
enableColorPicker(NppDarkMode::isEnabled(), enable);
_pIconColorPicker->display();
::SendDlgItemMessage(_hSelf, IDC_CHECK_REDUCE, BM_SETCHECK, tabBarStatus & TAB_REDUCE, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_REDUCE, BM_SETCHECK, tabBarStatus & TAB_REDUCE, 0);
::SendDlgItemMessage(_hSelf, IDC_CHECK_LOCK, BM_SETCHECK, !(tabBarStatus & TAB_DRAGNDROP), 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_LOCK, BM_SETCHECK, !(tabBarStatus & TAB_DRAGNDROP), 0);
@ -663,8 +718,20 @@ intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
} }
case WM_CTLCOLORDLG: case WM_CTLCOLORDLG:
{
return NppDarkMode::onCtlColorDlg(reinterpret_cast<HDC>(wParam));
}
case WM_CTLCOLORSTATIC: case WM_CTLCOLORSTATIC:
{ {
int dlgCtrlID = ::GetDlgCtrlID(reinterpret_cast<HWND>(lParam));
// handle blurry text with disabled states for the affected static controls
if (dlgCtrlID == IDC_STATIC_TOOLBAR_ICON_COLOR)
{
const bool isEnabled = ::IsWindowEnabled(::GetDlgItem(_hSelf, IDC_COMBO_TOOLBAR_ICON_COLOR));
return NppDarkMode::onCtlColorDlgStaticText(reinterpret_cast<HDC>(wParam), isEnabled);
}
return NppDarkMode::onCtlColorDlg(reinterpret_cast<HDC>(wParam)); return NppDarkMode::onCtlColorDlg(reinterpret_cast<HDC>(wParam));
} }
@ -677,6 +744,13 @@ intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
break; break;
} }
case WM_DESTROY:
{
_pIconColorPicker->destroy();
delete _pIconColorPicker;
return TRUE;
}
case WM_COMMAND: case WM_COMMAND:
{ {
switch (wParam) switch (wParam)
@ -923,34 +997,35 @@ intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
} }
return TRUE; return TRUE;
case IDC_RADIO_SMALLICON : case IDC_CHECK_TOOLBAR_ICON_MONO:
::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_TOOLBARREDUCE, 0, 0); {
NppDarkMode::setToolBarIconSet(0, NppDarkMode::isEnabled()); const bool isChecked = isCheckedOrNot(IDC_CHECK_TOOLBAR_ICON_MONO);
return TRUE; NppDarkMode::setToolbarFluentMonochrome(isChecked);
nppGUI._tbIconInfo._tbUseMono = isChecked;
case IDC_RADIO_BIGICON : UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_TOOLBARENLARGE, 0, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
NppDarkMode::setToolBarIconSet(1, NppDarkMode::isEnabled());
return TRUE;
case IDC_RADIO_SMALLICON2:
::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_TOOLBARREDUCESET2, 0, 0);
NppDarkMode::setToolBarIconSet(2, NppDarkMode::isEnabled());
return TRUE;
case IDC_RADIO_BIGICON2:
::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_TOOLBARENLARGESET2, 0, 0);
NppDarkMode::setToolBarIconSet(3, NppDarkMode::isEnabled());
return TRUE;
case IDC_RADIO_STANDARD :
::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_TOOLBARSTANDARD, 0, 0);
NppDarkMode::setToolBarIconSet(4, NppDarkMode::isEnabled());
return TRUE; return TRUE;
}
default: default:
switch (HIWORD(wParam)) switch (HIWORD(wParam))
{ {
case CPN_COLOURPICKED:
{
if (reinterpret_cast<HWND>(lParam) == _pIconColorPicker->getHSelf())
{
COLORREF c = _pIconColorPicker->getColour();
nppGUI._tbIconInfo._tbCustomColor = c;
NppDarkMode::setToolbarFluentCustomColor(c);
UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
return TRUE;
}
break;
}
case CBN_SELCHANGE : // == case LBN_SELCHANGE : case CBN_SELCHANGE : // == case LBN_SELCHANGE :
{ {
switch (LOWORD(wParam)) switch (LOWORD(wParam))
@ -980,8 +1055,41 @@ intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
::InvalidateRect(_hParent, NULL, TRUE); ::InvalidateRect(_hParent, NULL, TRUE);
} }
} }
}
return TRUE; return TRUE;
}
case IDC_COMBO_TOOLBAR_ICON:
{
int idxIconSet = 0;
UINT msg = getToolbarIconSetMsg(&idxIconSet);
::SendMessage(::GetParent(_hParent), msg, 0, 0);
NppDarkMode::setToolbarIconSet(idxIconSet, NppDarkMode::isEnabled());
const bool enable = idxIconSet != TB_STANDARD;
::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_TOOLBAR_ICON_COLOR), enable ? TRUE : FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_TOOLBAR_ICON_MONO), enable ? TRUE : FALSE);
redrawDlgItem(IDC_STATIC_TOOLBAR_ICON_COLOR);
enableColorPicker(NppDarkMode::isEnabled(), enable);
return TRUE;
}
case IDC_COMBO_TOOLBAR_ICON_COLOR:
{
const auto boundMax = static_cast<int>(NppDarkMode::FluentColor::maxValue) - 1;
auto idxFluentColor = static_cast<NppDarkMode::FluentColor>(::SendDlgItemMessage(_hSelf, IDC_COMBO_TOOLBAR_ICON_COLOR, CB_GETCURSEL, 0, 0));
idxFluentColor = static_cast<NppDarkMode::FluentColor>(std::min<int>(static_cast<int>(idxFluentColor), boundMax));
NppDarkMode::setToolbarFluentColor(idxFluentColor);
nppGUI._tbIconInfo._tbColor = idxFluentColor;
enableColorPicker(NppDarkMode::isEnabled());
UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
return TRUE;
}
default: default:
break; break;
} }

View File

@ -46,9 +46,13 @@ class GeneralSubDlg : public StaticDialog
public : public :
GeneralSubDlg() = default; GeneralSubDlg() = default;
void setTabbarAlternateIcons(bool enable = false); void setTabbarAlternateIcons(bool enable = false);
void enableColorPicker(bool useDark, bool doEnable = true);
private : private :
intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override; intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override;
UINT getToolbarIconSetMsg(int* idxIconSet);
void move2CtrlLeft(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight);
ColourPicker* _pIconColorPicker = nullptr;
}; };
class EditingSubDlg : public StaticDialog class EditingSubDlg : public StaticDialog

View File

@ -24,9 +24,9 @@
#define IDD_PREFERENCE_SUB_GENRAL 6100 //(IDD_PREFERENCE_BOX + 100) #define IDD_PREFERENCE_SUB_GENRAL 6100 //(IDD_PREFERENCE_BOX + 100)
#define IDC_TOOLBAR_GB_STATIC (IDD_PREFERENCE_SUB_GENRAL + 1) #define IDC_TOOLBAR_GB_STATIC (IDD_PREFERENCE_SUB_GENRAL + 1)
#define IDC_CHECK_HIDE (IDD_PREFERENCE_SUB_GENRAL + 2) #define IDC_CHECK_HIDE (IDD_PREFERENCE_SUB_GENRAL + 2)
#define IDC_RADIO_SMALLICON (IDD_PREFERENCE_SUB_GENRAL + 3) //#define IDC_RADIO_SMALLICON (IDD_PREFERENCE_SUB_GENRAL + 3)
#define IDC_RADIO_BIGICON (IDD_PREFERENCE_SUB_GENRAL + 4) //#define IDC_RADIO_BIGICON (IDD_PREFERENCE_SUB_GENRAL + 4)
#define IDC_RADIO_STANDARD (IDD_PREFERENCE_SUB_GENRAL + 5) //#define IDC_RADIO_STANDARD (IDD_PREFERENCE_SUB_GENRAL + 5)
#define IDC_TABBAR_GB_STATIC (IDD_PREFERENCE_SUB_GENRAL + 6) #define IDC_TABBAR_GB_STATIC (IDD_PREFERENCE_SUB_GENRAL + 6)
#define IDC_CHECK_REDUCE (IDD_PREFERENCE_SUB_GENRAL + 7) #define IDC_CHECK_REDUCE (IDD_PREFERENCE_SUB_GENRAL + 7)
@ -48,13 +48,17 @@
#define IDC_LOCALIZATION_GB_STATIC (IDD_PREFERENCE_SUB_GENRAL + 23) #define IDC_LOCALIZATION_GB_STATIC (IDD_PREFERENCE_SUB_GENRAL + 23)
#define IDC_COMBO_LOCALIZATION (IDD_PREFERENCE_SUB_GENRAL + 24) #define IDC_COMBO_LOCALIZATION (IDD_PREFERENCE_SUB_GENRAL + 24)
#define IDC_CHECK_TAB_ALTICONS (IDD_PREFERENCE_SUB_GENRAL + 28) #define IDC_CHECK_TAB_ALTICONS (IDD_PREFERENCE_SUB_GENRAL + 28)
#define IDC_RADIO_SMALLICON2 (IDD_PREFERENCE_SUB_GENRAL + 29) //#define IDC_RADIO_SMALLICON2 (IDD_PREFERENCE_SUB_GENRAL + 29)
#define IDC_RADIO_BIGICON2 (IDD_PREFERENCE_SUB_GENRAL + 30) //#define IDC_RADIO_BIGICON2 (IDD_PREFERENCE_SUB_GENRAL + 30)
#define IDC_MENU_GB_STATIC (IDD_PREFERENCE_SUB_GENRAL + 31) #define IDC_MENU_GB_STATIC (IDD_PREFERENCE_SUB_GENRAL + 31)
#define IDC_CHECK_HIDERIGHTSHORTCUTSOFMENUBAR (IDD_PREFERENCE_SUB_GENRAL + 32) #define IDC_CHECK_HIDERIGHTSHORTCUTSOFMENUBAR (IDD_PREFERENCE_SUB_GENRAL + 32)
#define IDC_STATUSBAR_GB_STATIC (IDD_PREFERENCE_SUB_GENRAL + 33) #define IDC_STATUSBAR_GB_STATIC (IDD_PREFERENCE_SUB_GENRAL + 33)
#define IDC_CHECK_HIDESTATUSBAR (IDD_PREFERENCE_SUB_GENRAL + 34) #define IDC_CHECK_HIDESTATUSBAR (IDD_PREFERENCE_SUB_GENRAL + 34)
#define IDC_CHECK_SHOWONLYPINNEDBUTTON (IDD_PREFERENCE_SUB_GENRAL + 35) #define IDC_CHECK_SHOWONLYPINNEDBUTTON (IDD_PREFERENCE_SUB_GENRAL + 35)
#define IDC_COMBO_TOOLBAR_ICON (IDD_PREFERENCE_SUB_GENRAL + 36)
#define IDC_STATIC_TOOLBAR_ICON_COLOR (IDD_PREFERENCE_SUB_GENRAL + 37)
#define IDC_COMBO_TOOLBAR_ICON_COLOR (IDD_PREFERENCE_SUB_GENRAL + 38)
#define IDC_CHECK_TOOLBAR_ICON_MONO (IDD_PREFERENCE_SUB_GENRAL + 39)
#define IDD_PREFERENCE_SUB_MULTIINSTANCE 6150 //(IDD_PREFERENCE_BOX + 150) #define IDD_PREFERENCE_SUB_MULTIINSTANCE 6150 //(IDD_PREFERENCE_BOX + 150)
#define IDC_MULTIINST_GB_STATIC (IDD_PREFERENCE_SUB_MULTIINSTANCE + 1) #define IDC_MULTIINST_GB_STATIC (IDD_PREFERENCE_SUB_MULTIINSTANCE + 1)