mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-08-17 17:02:51 +08:00
Fix wxSpinButton dark mode switching under Windows 11 22H2
Add call to MSWSetDarkOrLightMode() upon control creation to get correct dark mode drawing under Windows 11 22H2 and later and avoid inverting colours if they are already drawn correctly for dark mode. Closes #26683.
This commit is contained in:
committed by
Vadim Zeitlin
parent
aa52238256
commit
6de4ddb544
+11
-3
@@ -144,6 +144,9 @@ bool wxSpinButton::Create(wxWindow *parent,
|
||||
|
||||
SetInitialSize(size);
|
||||
|
||||
if ( wxMSWDarkMode::IsActive() )
|
||||
MSWSetDarkOrLightMode(SetMode::Initial);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -178,8 +181,9 @@ void wxSpinButton::OnPaint(wxPaintEvent& event)
|
||||
{
|
||||
if ( wxMSWDarkMode::IsActive() )
|
||||
{
|
||||
// Unfortunately PaintIfNecessary() can't be used here as we need to
|
||||
// handle the extra border below, so duplicate what it does here.
|
||||
// Have the updown control draw itself, then modify the result with a
|
||||
// border and possibly inverted colours.
|
||||
|
||||
const RECT rc = wxGetClientRect(GetHwnd());
|
||||
const wxSize size{rc.right - rc.left, rc.bottom - rc.top};
|
||||
|
||||
@@ -213,6 +217,10 @@ void wxSpinButton::OnPaint(wxPaintEvent& event)
|
||||
|
||||
wxImage image = bmp.ConvertToImage();
|
||||
|
||||
// Prior to Windows 11 22H2 (build 22621), the updown control always
|
||||
// draws in light mode, so invert the colours to make it dark.
|
||||
const bool shouldInvert = !wxCheckOsVersion(10, 0, 22621);
|
||||
|
||||
const int width = image.GetWidth();
|
||||
const int height = image.GetHeight();
|
||||
unsigned char *data = image.GetData();
|
||||
@@ -230,7 +238,7 @@ void wxSpinButton::OnPaint(wxPaintEvent& event)
|
||||
if ( alpha )
|
||||
*alpha = wxALPHA_OPAQUE;
|
||||
}
|
||||
else
|
||||
else if ( shouldInvert )
|
||||
{
|
||||
// This uses a slightly different formula than the one in
|
||||
// InvertBitmapPixel() because the one there results in the
|
||||
|
||||
Reference in New Issue
Block a user