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

@ -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,6 +2728,13 @@ 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)
@ -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;
} }