From 5325ccfda6a98d244e531dffb9772bec1a7a80d2 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Mon, 13 Jul 2020 20:26:59 -0700 Subject: [PATCH] Update generic wxTreeCtrl appearance when theme changes See #18823 --- include/wx/generic/treectlg.h | 4 +++ src/generic/treectlg.cpp | 62 ++++++++++++++++------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index c171916537..e8c9abb17c 100644 --- a/include/wx/generic/treectlg.h +++ b/include/wx/generic/treectlg.h @@ -351,6 +351,10 @@ protected: virtual wxSize DoGetBestSize() const wxOVERRIDE; private: + bool m_hasExplicitFont; + + void OnSysColourChanged(wxSysColourChangedEvent&); + // Reset the state of the last find (i.e. keyboard incremental search) // operation. void ResetFindState(); diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 9c92f35100..9c445298d2 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -917,6 +917,7 @@ wxBEGIN_EVENT_TABLE(wxGenericTreeCtrl, wxTreeCtrlBase) EVT_SET_FOCUS (wxGenericTreeCtrl::OnSetFocus) EVT_KILL_FOCUS (wxGenericTreeCtrl::OnKillFocus) EVT_TREE_ITEM_GETTOOLTIP(wxID_ANY, wxGenericTreeCtrl::OnGetToolTip) + EVT_SYS_COLOUR_CHANGED(wxGenericTreeCtrl::OnSysColourChanged) wxEND_EVENT_TABLE() // ----------------------------------------------------------------------------- @@ -936,24 +937,8 @@ void wxGenericTreeCtrl::Init() m_indent = 15; m_spacing = 18; - m_hilightBrush = new wxBrush - ( - wxSystemSettings::GetColour - ( - wxSYS_COLOUR_HIGHLIGHT - ), - wxBRUSHSTYLE_SOLID - ); - - m_hilightUnfocusedBrush = new wxBrush - ( - wxSystemSettings::GetColour - ( - wxSYS_COLOUR_BTNSHADOW - ), - wxBRUSHSTYLE_SOLID - ); - + m_hilightBrush = NULL; + m_hilightUnfocusedBrush = NULL; m_imageListButtons = NULL; m_ownsImageListButtons = false; @@ -974,13 +959,6 @@ void wxGenericTreeCtrl::Init() m_dndEffectItem = NULL; m_lastOnSame = false; - -#if defined( __WXMAC__ ) - m_normalFont = wxFont(wxOSX_SYSTEM_FONT_VIEWS); -#else - m_normalFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); -#endif - m_boldFont = m_normalFont.Bold(); } bool wxGenericTreeCtrl::Create(wxWindow *parent, @@ -1006,14 +984,9 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, m_spacing = 10; } - wxVisualAttributes attr = GetDefaultAttributes(); - SetOwnForegroundColour( attr.colFg ); - SetOwnBackgroundColour( attr.colBg ); - if (!m_hasFont) - SetOwnFont(attr.font); - - m_dottedPen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT), - 1, wxPENSTYLE_DOT); + m_hasExplicitFont = m_hasFont; + wxSysColourChangedEvent evt; + OnSysColourChanged(evt); SetInitialSize(size); @@ -1039,6 +1012,29 @@ void wxGenericTreeCtrl::EnableBellOnNoMatch( bool on ) m_findBell = on; } +void wxGenericTreeCtrl::OnSysColourChanged(wxSysColourChangedEvent&) +{ + const wxVisualAttributes attr(GetDefaultAttributes()); + SetOwnForegroundColour(attr.colFg); + SetOwnBackgroundColour(attr.colBg); + if (!m_hasExplicitFont) + SetOwnFont(attr.font); + + delete m_hilightBrush; + m_hilightBrush = new wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); + delete m_hilightUnfocusedBrush; + m_hilightUnfocusedBrush = new wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)); + + m_dottedPen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT), 1, wxPENSTYLE_DOT); + +#if defined(__WXOSX__) + m_normalFont = wxFont(wxOSX_SYSTEM_FONT_VIEWS); +#else + m_normalFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); +#endif + m_boldFont = m_normalFont.Bold(); +} + // ----------------------------------------------------------------------------- // accessors // -----------------------------------------------------------------------------