Update generic wxTreeCtrl appearance when theme changes

See #18823
This commit is contained in:
Paul Cornett 2020-07-13 20:26:59 -07:00
parent f1f27bc37c
commit 5325ccfda6
2 changed files with 33 additions and 33 deletions

View File

@ -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();

View File

@ -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
// -----------------------------------------------------------------------------