diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index e8c9abb17c..2388eedc9c 100644 --- a/include/wx/generic/treectlg.h +++ b/include/wx/generic/treectlg.h @@ -13,8 +13,9 @@ #if wxUSE_TREECTRL -#include "wx/scrolwin.h" +#include "wx/brush.h" #include "wx/pen.h" +#include "wx/scrolwin.h" // ----------------------------------------------------------------------------- // forward declaration @@ -243,8 +244,8 @@ protected: unsigned short m_indent; int m_lineHeight; wxPen m_dottedPen; - wxBrush *m_hilightBrush, - *m_hilightUnfocusedBrush; + wxBrush m_hilightBrush, + m_hilightUnfocusedBrush; bool m_hasFocus; bool m_dirty; bool m_ownsImageListButtons; @@ -351,9 +352,14 @@ protected: virtual wxSize DoGetBestSize() const wxOVERRIDE; private: - bool m_hasExplicitFont; + void OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) + { + InitVisualAttributes(); + } - void OnSysColourChanged(wxSysColourChangedEvent&); + // (Re)initialize colours, fonts, pens, brushes used by the control using + // the current system colours and font. + void InitVisualAttributes(); // Reset the state of the last find (i.e. keyboard incremental search) // operation. diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 9c445298d2..7bae8ce932 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -937,8 +937,6 @@ void wxGenericTreeCtrl::Init() m_indent = 15; m_spacing = 18; - m_hilightBrush = NULL; - m_hilightUnfocusedBrush = NULL; m_imageListButtons = NULL; m_ownsImageListButtons = false; @@ -984,9 +982,7 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, m_spacing = 10; } - m_hasExplicitFont = m_hasFont; - wxSysColourChangedEvent evt; - OnSysColourChanged(evt); + InitVisualAttributes(); SetInitialSize(size); @@ -995,9 +991,6 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, wxGenericTreeCtrl::~wxGenericTreeCtrl() { - delete m_hilightBrush; - delete m_hilightUnfocusedBrush; - DeleteAllItems(); delete m_renameTimer; @@ -1012,18 +1005,35 @@ void wxGenericTreeCtrl::EnableBellOnNoMatch( bool on ) m_findBell = on; } -void wxGenericTreeCtrl::OnSysColourChanged(wxSysColourChangedEvent&) +void wxGenericTreeCtrl::InitVisualAttributes() { + // We want to use the default system colours/fonts here unless the user + // explicitly configured something different. We also need to reset the + // various m_hasXXX variables to false to prevent them from being left set + // to "true", as otherwise we wouldn't update the colours/fonts the next + // time the system colours change. const wxVisualAttributes attr(GetDefaultAttributes()); - SetOwnForegroundColour(attr.colFg); - SetOwnBackgroundColour(attr.colBg); - if (!m_hasExplicitFont) - SetOwnFont(attr.font); + if ( !m_hasFgCol ) + { + SetOwnForegroundColour(attr.colFg); + m_hasFgCol = false; + } - delete m_hilightBrush; - m_hilightBrush = new wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); - delete m_hilightUnfocusedBrush; - m_hilightUnfocusedBrush = new wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)); + if ( !m_hasBgCol ) + { + SetOwnBackgroundColour(attr.colBg); + m_hasBgCol = false; + } + + if ( !m_hasFont ) + { + SetOwnFont(attr.font); + m_hasFont = false; + } + + + m_hilightBrush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); + m_hilightUnfocusedBrush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)); m_dottedPen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT), 1, wxPENSTYLE_DOT); @@ -2544,7 +2554,7 @@ void wxGenericTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc) if ( item->IsSelected() ) { - dc.SetBrush(*(m_hasFocus ? m_hilightBrush : m_hilightUnfocusedBrush)); + dc.SetBrush(m_hasFocus ? m_hilightBrush : m_hilightUnfocusedBrush); drawItemBackground = true; } else