From 025b8a447c45cced894728d4c6aec07e6fd6d8a3 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Wed, 22 Dec 2021 09:23:41 -0800 Subject: [PATCH] Avoid unreadable text with unfocused selected item With non-themed MSW renderer, avoid using wxSYS_COLOUR_BTNFACE for unfocused item selection unless it has sufficient contrast with the text color. --- src/msw/renderer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index 96b6d0e689..e402b283cf 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -368,7 +368,13 @@ void wxRendererMSWBase::DrawItemSelectionRect(wxWindow *win, wxColour color(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); if ((flags & wxCONTROL_FOCUSED) == 0) { - color = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); + // Use wxSYS_COLOUR_BTNFACE for unfocused selection, but only if it + // has enough contrast with wxSYS_COLOUR_HIGHLIGHTTEXT, as otherwise + // the text will be unreadable + const wxColour btnface(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); + const wxColour highlightText(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT)); + if (fabs(btnface.GetLuminance() - highlightText.GetLuminance()) > 0.5) + color = btnface; } wxDCBrushChanger setBrush(dc, wxBrush(color));