Add support for using custom theme class in dark mode
This is needed for at least wxStatusBar, although the gripper is still not drawn correctly even when this particular theme class is used -- but at least the main part of the status bar now uses the correct colours.
This commit is contained in:
parent
7a84c0b25d
commit
bd281c2cc9
6 changed files with 27 additions and 8 deletions
|
|
@ -124,6 +124,12 @@ protected:
|
|||
// Look in our GetSubcontrols() for the windows with the given ID.
|
||||
virtual wxWindow *MSWFindItem(long id, WXHWND hWnd) const override;
|
||||
|
||||
// Return the theme class to use for this control in dark mode. Default is
|
||||
// not to use any special class, but use "Explorer" as app name, as this
|
||||
// works for several controls, but not all of them and the other must
|
||||
// override this function.
|
||||
virtual const wchar_t* MSWGetDarkThemeClass() const { return nullptr; }
|
||||
|
||||
|
||||
// for controls like radiobuttons which are really composite this array
|
||||
// holds the ids (not HWNDs!) of the sub controls
|
||||
|
|
|
|||
|
|
@ -21,7 +21,10 @@ bool IsActive();
|
|||
void EnableForTLW(HWND hwnd);
|
||||
|
||||
// Set dark theme for the given (child) window if appropriate.
|
||||
void AllowForWindow(HWND hwnd);
|
||||
//
|
||||
// Optional theme class can be specified if a particular class must be used,
|
||||
// otherwise the default one is used for it.
|
||||
void AllowForWindow(HWND hwnd, const wchar_t* themeClass = nullptr);
|
||||
|
||||
} // namespace wxMSWDarkMode
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,8 @@ protected:
|
|||
virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result) override;
|
||||
#endif
|
||||
|
||||
virtual const wchar_t* MSWGetDarkThemeClass() const override;
|
||||
|
||||
// implementation of the public SetStatusWidths()
|
||||
void MSWUpdateFieldsWidths();
|
||||
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ bool wxControl::MSWCreateControl(const wxChar *classname,
|
|||
return false;
|
||||
}
|
||||
|
||||
wxMSWDarkMode::AllowForWindow(m_hWnd);
|
||||
wxMSWDarkMode::AllowForWindow(m_hWnd, MSWGetDarkThemeClass());
|
||||
|
||||
// saving the label in m_labelOrig to return it verbatim
|
||||
// later in GetLabel()
|
||||
|
|
|
|||
|
|
@ -246,15 +246,17 @@ void EnableForTLW(HWND hwnd)
|
|||
wxMSWImpl::AllowDarkModeForWindow(hwnd, TRUE);
|
||||
}
|
||||
|
||||
void AllowForWindow(HWND hwnd)
|
||||
void AllowForWindow(HWND hwnd, const wchar_t* themeClass)
|
||||
{
|
||||
if ( wxMSWImpl::ShouldUseDarkMode() )
|
||||
{
|
||||
// Using "DARK_EXPLORER" theme works as well, but is subtly different
|
||||
// and it seems better to use the explicit (even if undocumented) API
|
||||
// provided for this instead of relying on this special theme name.
|
||||
wxMSWImpl::AllowDarkModeForWindow(hwnd, TRUE);
|
||||
::SetWindowTheme(hwnd, L"EXPLORER", nullptr);
|
||||
|
||||
// For some reason using a theme class is incompatible with using
|
||||
// "Explorer" as the app name, even though it looks like it ought to
|
||||
// be, but passing ("Explorer", "ExplorerStatusBar") here, for example,
|
||||
// does _not_ work, while omitting the app name in this case does work.
|
||||
::SetWindowTheme(hwnd, themeClass ? nullptr : L"Explorer", themeClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -279,7 +281,7 @@ void EnableForTLW(HWND WXUNUSED(hwnd))
|
|||
{
|
||||
}
|
||||
|
||||
void AllowForWindow(HWND WXUNUSED(hwnd))
|
||||
void AllowForWindow(HWND WXUNUSED(hwnd), const wchar_t* WXUNUSED(themeClass))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -679,4 +679,10 @@ bool wxStatusBar::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM* W
|
|||
}
|
||||
#endif // wxUSE_TOOLTIPS
|
||||
|
||||
const wchar_t* wxStatusBar::MSWGetDarkThemeClass() const
|
||||
{
|
||||
// This is not documented anywhere but seems to work.
|
||||
return L"ExplorerStatusBar";
|
||||
}
|
||||
|
||||
#endif // wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue