Fix URL Link controls color in dark mode consistent issue for plugins

Fix #16537, close #16538
This commit is contained in:
Shridhar Kumar 2025-05-11 14:22:20 -04:00 committed by Don Ho
parent f677a0c5db
commit 3310a613e4

View File

@ -620,7 +620,7 @@ namespace NppDarkMode
{ {
NppDarkMode::setToolbarFluentMonochrome(setMonochrome, NppDarkMode::isEnabled()); NppDarkMode::setToolbarFluentMonochrome(setMonochrome, NppDarkMode::isEnabled());
} }
void setToolbarFluentCustomColor(COLORREF color, bool useDark) void setToolbarFluentCustomColor(COLORREF color, bool useDark)
{ {
if (useDark) if (useDark)
@ -638,7 +638,7 @@ namespace NppDarkMode
{ {
if (useDark) if (useDark)
g_advOptions._darkDefaults._tabIconSet = useAltIcons ? 1 : 2; g_advOptions._darkDefaults._tabIconSet = useAltIcons ? 1 : 2;
else else
g_advOptions._lightDefaults._tabIconSet = useAltIcons ? 1 : 0; g_advOptions._lightDefaults._tabIconSet = useAltIcons ? 1 : 0;
} }
@ -1835,7 +1835,7 @@ namespace NppDarkMode
::InflateRect(&rcItem, -1, -1); ::InflateRect(&rcItem, -1, -1);
rcItem.right += 1; rcItem.right += 1;
// for consistency getBackgroundBrush() // for consistency getBackgroundBrush()
// would be better, than getCtrlBackgroundBrush(), // would be better, than getCtrlBackgroundBrush(),
// however default getBackgroundBrush() has same color // however default getBackgroundBrush() has same color
// as getDlgBackgroundBrush() // as getDlgBackgroundBrush()
@ -2637,6 +2637,19 @@ namespace NppDarkMode
return false; return false;
} }
static void setUrlLinkControlColor(HWND hWnd, NppDarkModeParams p)
{
if (p._theme)
{
LITEM item{};
item.iLink = 0; // for now colorize only 1st item
item.mask = LIF_ITEMINDEX | LIF_STATE;
item.state = NppDarkMode::isEnabled() ? LIS_DEFAULTCOLORS : 0;
item.stateMask = LIS_DEFAULTCOLORS;
::SendMessage(hWnd, LM_SETITEM, 0, reinterpret_cast<LPARAM>(&item));
}
}
void autoSubclassAndThemeChildControls(HWND hwndParent, bool subclass, bool theme) void autoSubclassAndThemeChildControls(HWND hwndParent, bool subclass, bool theme)
{ {
NppDarkModeParams p{ NppDarkModeParams p{
@ -2715,8 +2728,15 @@ namespace NppDarkMode
return TRUE; return TRUE;
} }
// For plugins: Prep SysLink so that colors can be set later in WM_CTLCOLORSTATIC
if (wcscmp(className, WC_LINK) == 0)
{
NppDarkMode::setUrlLinkControlColor(hwnd, p);
return TRUE;
}
/* /*
// for debugging // for debugging
if (wcscmp(className, L"#32770") == 0) if (wcscmp(className, L"#32770") == 0)
{ {
return TRUE; return TRUE;
@ -3373,15 +3393,27 @@ namespace NppDarkMode
{ {
if (NppDarkMode::isEnabled()) if (NppDarkMode::isEnabled())
{ {
constexpr size_t classNameLen = 16; auto hChild = reinterpret_cast<HWND>(lParam);
wchar_t className[classNameLen]{}; const bool isChildEnabled = ::IsWindowEnabled(hChild) == TRUE;
auto hwndEdit = reinterpret_cast<HWND>(lParam); std::wstring className = getWndClassName(hChild);
GetClassName(hwndEdit, className, classNameLen);
if (wcscmp(className, WC_EDIT) == 0) auto hdc = reinterpret_cast<HDC>(wParam);
if (className == WC_EDIT)
{ {
return NppDarkMode::onCtlColor(reinterpret_cast<HDC>(wParam)); if (isChildEnabled)
{
return NppDarkMode::onCtlColor(hdc);
}
return NppDarkMode::onCtlColorDlg(hdc);
} }
return NppDarkMode::onCtlColorDlg(reinterpret_cast<HDC>(wParam));
if (className == WC_LINK)
{
return NppDarkMode::onCtlColorDlgLinkText(hdc, isChildEnabled);
}
return NppDarkMode::onCtlColorDlg(hdc);
} }
break; break;
} }
@ -3481,7 +3513,7 @@ namespace NppDarkMode
constexpr ULONG dmfRequiredMask = dmfSubclassParent | dmfSubclassChildren | dmfSetThemeChildren | dmfSetTitleBar | dmfSetThemeDirectly; constexpr ULONG dmfRequiredMask = dmfSubclassParent | dmfSubclassChildren | dmfSetThemeChildren | dmfSetTitleBar | dmfSetThemeDirectly;
//constexpr ULONG dmfAllMask = dmfSubclassParent | dmfSubclassChildren | dmfSetThemeChildren | dmfSetTitleBar | dmfSetThemeDirectly; //constexpr ULONG dmfAllMask = dmfSubclassParent | dmfSubclassChildren | dmfSetThemeChildren | dmfSetTitleBar | dmfSetThemeDirectly;
if (hwnd == nullptr || (dmFlags & dmfRequiredMask) == 0) if (hwnd == nullptr || (dmFlags & dmfRequiredMask) == 0)
{ {
return 0; return 0;
@ -4006,7 +4038,7 @@ namespace NppDarkMode
::SetBkColor(hdc, NppDarkMode::getErrorBackgroundColor()); ::SetBkColor(hdc, NppDarkMode::getErrorBackgroundColor());
return reinterpret_cast<LRESULT>(NppDarkMode::getErrorBackgroundBrush()); return reinterpret_cast<LRESULT>(NppDarkMode::getErrorBackgroundBrush());
} }
LRESULT onCtlColorDlgStaticText(HDC hdc, bool isTextEnabled) LRESULT onCtlColorDlgStaticText(HDC hdc, bool isTextEnabled)
{ {
if (!NppDarkMode::isEnabled()) if (!NppDarkMode::isEnabled())