Only use DarkMode_DarkTheme if available
Use DarkMode_DarkTheme for wxListBox use DarkMode_DarkTheme for wxListBox, if available. This improves the appearance of the simple border style
Implement wxMDIChildFrame::GetDefaultAttributes() in wxMSW Ensure that the correct background colour is returned for MDI children. See #26603.
Update background brush in MSWSetDarkOrLightMode() Remap the colour used for the background brush to the new mode. Closes #26603.
Fix dark mode switching for wxStatusBar When switching to light mode, always use the theme name L"Explorer" rather than using MSWGetDarkModeSupport(). The theme name and id needed for dark mode does not always work for light mode. For example, for wxStatusBar combination name=nullptr id=L"ExplorerStatusBar" results in an un-themed status bar with strange internal borders and missing gripper. Closes #26608.
Merge branch 'windows10-darkmode_darktheme2' of github.com:stevecor/wxWidgets Only use DarkMode_DarkTheme if available by testing for the earliest Windows version in which it appeared. See #26613.
| ... | ... | @@ -226,6 +226,8 @@ public: |
| 226 | 226 | |
| 227 | 227 | void OnIdle(wxIdleEvent& event);
|
| 228 | 228 | |
| 229 | + virtual wxVisualAttributes GetDefaultAttributes() const override;
|
|
| 230 | + |
|
| 229 | 231 | protected:
|
| 230 | 232 | virtual void DoGetScreenPosition(int *x, int *y) const override;
|
| 231 | 233 | virtual void DoGetPosition(int *x, int *y) const override;
|
| ... | ... | @@ -564,15 +564,6 @@ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name, |
| 564 | 564 | return gs_regClassesInfo[n].GetRequestedName(flags);
|
| 565 | 565 | }
|
| 566 | 566 | |
| 567 | - // In dark mode, use the dark background brush instead of specified colour
|
|
| 568 | - // which would result in light background.
|
|
| 569 | - HBRUSH hbrBackground;
|
|
| 570 | - if ( wxMSWDarkMode::IsActive() )
|
|
| 571 | - hbrBackground = wxMSWDarkMode::GetBackgroundBrush();
|
|
| 572 | - else
|
|
| 573 | - hbrBackground = (HBRUSH)wxUIntToPtr(bgBrushCol + 1);
|
|
| 574 | - |
|
| 575 | - |
|
| 576 | 567 | // we need to register this class
|
| 577 | 568 | WNDCLASS wndclass;
|
| 578 | 569 | wxZeroMemory(wndclass);
|
| ... | ... | @@ -580,7 +571,7 @@ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name, |
| 580 | 571 | wndclass.lpfnWndProc = (WNDPROC)wxWndProc;
|
| 581 | 572 | wndclass.hInstance = wxGetInstance();
|
| 582 | 573 | wndclass.hCursor = ::LoadCursor(nullptr, IDC_ARROW);
|
| 583 | - wndclass.hbrBackground = hbrBackground;
|
|
| 574 | + wndclass.hbrBackground = (HBRUSH)wxUIntToPtr(bgBrushCol + 1);
|
|
| 584 | 575 | wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | extraStyles;
|
| 585 | 576 | |
| 586 | 577 |
| ... | ... | @@ -225,7 +225,13 @@ void wxChoice::MSWSetDarkOrLightMode(SetMode setmode) |
| 225 | 225 | WinStruct<COMBOBOXINFO> info;
|
| 226 | 226 | if ( ::GetComboBoxInfo(GetHwnd(), &info) && info.hwndList )
|
| 227 | 227 | {
|
| 228 | - wxMSWDarkMode::AllowForWindow(info.hwndList, L"DarkMode_DarkTheme");
|
|
| 228 | + // The default theme does not look good on starting with Windows 11
|
|
| 229 | + // build 26300.8553. DarkMode_DarkTheme looks OK and was available
|
|
| 230 | + // starting with Windows 11 build 26200.
|
|
| 231 | + if ( wxCheckOsVersion(10, 0, 26200) )
|
|
| 232 | + wxMSWDarkMode::AllowForWindow(info.hwndList, L"DarkMode_DarkTheme");
|
|
| 233 | + else
|
|
| 234 | + wxMSWDarkMode::AllowForWindow(info.hwndList);
|
|
| 229 | 235 | }
|
| 230 | 236 | }
|
| 231 | 237 |
| ... | ... | @@ -175,8 +175,13 @@ WXDWORD wxListBox::MSWGetStyle(long style, WXDWORD *exstyle) const |
| 175 | 175 | |
| 176 | 176 | void wxListBox::MSWGetDarkModeSupport(MSWDarkModeSupport& support) const
|
| 177 | 177 | {
|
| 178 | - support.themeName = L"Explorer";
|
|
| 179 | - support.themeId = L"ScrollBar";
|
|
| 178 | + // The default theme does not look good on starting with Windows 11
|
|
| 179 | + // build 26300.8553. DarkMode_DarkTheme looks OK and was available
|
|
| 180 | + // starting with Windows 11 build 26200.
|
|
| 181 | + if ( wxCheckOsVersion(10, 0, 26200) )
|
|
| 182 | + support.themeName = L"DarkMode_DarkTheme";
|
|
| 183 | + else
|
|
| 184 | + wxListBoxBase::MSWGetDarkModeSupport(support);
|
|
| 180 | 185 | }
|
| 181 | 186 | |
| 182 | 187 | void wxListBox::MSWUpdateFontOnDPIChange(const wxSize& newDPI)
|
| ... | ... | @@ -1466,6 +1466,13 @@ void wxMDIChildFrame::OnIdle(wxIdleEvent& event) |
| 1466 | 1466 | event.Skip();
|
| 1467 | 1467 | }
|
| 1468 | 1468 | |
| 1469 | +wxVisualAttributes wxMDIChildFrame::GetDefaultAttributes() const
|
|
| 1470 | +{
|
|
| 1471 | + auto attrs = wxMDIChildFrameBase::GetDefaultAttributes();
|
|
| 1472 | + attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
|
| 1473 | + return attrs;
|
|
| 1474 | +}
|
|
| 1475 | + |
|
| 1469 | 1476 | // ---------------------------------------------------------------------------
|
| 1470 | 1477 | // private helper functions
|
| 1471 | 1478 | // ---------------------------------------------------------------------------
|
| ... | ... | @@ -3875,15 +3875,21 @@ wxWindowMSW::MSWHandleMessage(WXLRESULT *result, |
| 3875 | 3875 | |
| 3876 | 3876 | // Draw the theme border and background.
|
| 3877 | 3877 | |
| 3878 | - // The EDIT theme gives a good general purpose border in light mode.
|
|
| 3879 | - // There does not seem to be a dark mode EDIT theme that looks good.
|
|
| 3880 | - // The ListView theme below looks good in dark mode.
|
|
| 3881 | - wxUxThemeHandle hTheme(this, L"EDIT", L"DarkMode_DarkTheme::ListView");
|
|
| 3882 | - |
|
| 3883 | - // Ensure that the part and state we use have the same
|
|
| 3884 | - // values for both EDIT and ListView.
|
|
| 3878 | + // The EDIT class gives a good general purpose border in light mode.
|
|
| 3879 | + // There does not seem to be a dark mode EDIT class that looks good.
|
|
| 3880 | + // The ListView class below looks good in dark mode but was not
|
|
| 3881 | + // available until Windows 11 build 26200. The Button class below
|
|
| 3882 | + // looks OK in dark mode on older Windows.
|
|
| 3883 | + const auto darkClass = wxCheckOsVersion(10, 0, 26200) ?
|
|
| 3884 | + L"DarkMode_DarkTheme::ListView" :
|
|
| 3885 | + L"DarkMode_Explorer::Button";
|
|
| 3886 | + wxUxThemeHandle hTheme(this, L"EDIT", darkClass);
|
|
| 3887 | + |
|
| 3888 | + // The part and state values match for the themes we use.
|
|
| 3885 | 3889 | static_assert((int)EP_EDITTEXT == (int)LVP_LISTITEM, "parts differ?");
|
| 3890 | + static_assert((int)EP_EDITTEXT == (int)BP_PUSHBUTTON, "parts differ?");
|
|
| 3886 | 3891 | static_assert((int)ETS_NORMAL == (int)LISS_NORMAL, "states differ?");
|
| 3892 | + static_assert((int)ETS_NORMAL == (int)PBS_NORMAL, "states differ?");
|
|
| 3887 | 3893 | |
| 3888 | 3894 | // Make sure the background is in a proper state
|
| 3889 | 3895 | if (::IsThemeBackgroundPartiallyTransparent(hTheme, EP_EDITTEXT, ETS_NORMAL))
|
| ... | ... | @@ -4105,6 +4111,7 @@ WXHWND wxWindowMSW::MSWCreateWindowAtAnyPosition(WXDWORD exStyle, const wxChar* |
| 4105 | 4111 | |
| 4106 | 4112 | void wxWindowMSW::MSWGetDarkModeSupport(MSWDarkModeSupport& support) const
|
| 4107 | 4113 | {
|
| 4114 | + // This is the default theme name for dark mode.
|
|
| 4108 | 4115 | // This theme works for a few controls (buttons, texts, comboboxes) and
|
| 4109 | 4116 | // doesn't seem to do any harm for those that don't support it, so use it
|
| 4110 | 4117 | // by default.
|
| ... | ... | @@ -4114,10 +4121,31 @@ void wxWindowMSW::MSWGetDarkModeSupport(MSWDarkModeSupport& support) const |
| 4114 | 4121 | void wxWindowMSW::MSWSetDarkOrLightMode(SetMode WXUNUSED(setmode))
|
| 4115 | 4122 | {
|
| 4116 | 4123 | MSWDarkModeSupport support;
|
| 4117 | - MSWGetDarkModeSupport(support);
|
|
| 4124 | + if ( wxMSWDarkMode::IsActive() )
|
|
| 4125 | + {
|
|
| 4126 | + MSWGetDarkModeSupport(support);
|
|
| 4127 | + }
|
|
| 4128 | + else
|
|
| 4129 | + {
|
|
| 4130 | + // This is the theme name for light mode.
|
|
| 4131 | + support.themeName = L"Explorer";
|
|
| 4132 | + }
|
|
| 4118 | 4133 | |
| 4119 | 4134 | // This updates scroll bars, if there are any.
|
| 4120 | 4135 | wxMSWDarkMode::AllowForWindow(m_hWnd, support.themeName, support.themeId);
|
| 4136 | + |
|
| 4137 | + // If the window class has a background brush, update it.
|
|
| 4138 | + // This is the value in WNDCLASS::hbrBackground.
|
|
| 4139 | + if ( ::GetClassLongPtr(m_hWnd, GCLP_HBRBACKGROUND) != 0 )
|
|
| 4140 | + {
|
|
| 4141 | + // The brush value was originally a colour index plus 1, for example
|
|
| 4142 | + // wxSYS_COLOUR_WINDOW+1. Assume that colour index matches the colour
|
|
| 4143 | + // returned by GetDefaultAttributes().
|
|
| 4144 | + wxColour colBg = GetDefaultAttributes().colBg;
|
|
| 4145 | + wxBrush* brush = wxTheBrushList->FindOrCreateBrush(colBg);
|
|
| 4146 | + HBRUSH hbr = GetHbrushOf(*brush);
|
|
| 4147 | + ::SetClassLongPtr(m_hWnd, GCLP_HBRBACKGROUND, LONG_PTR(hbr));
|
|
| 4148 | + }
|
|
| 4121 | 4149 | }
|
| 4122 | 4150 | |
| 4123 | 4151 | // ===========================================================================
|
—
View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help