From 1ec7ae9a6f3b6c1078d0a80a8e0304d143ced4ec Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 14 Jul 2020 15:43:23 +0200 Subject: [PATCH] Use wxBrush objects instead of pointers in wxGenericTreeCtrl There is no need for double indirection, wxBrush object is already pointer-like internally. No real changes, just simplify/optimize the code a little. --- include/wx/generic/treectlg.h | 7 ++++--- src/generic/treectlg.cpp | 13 +++---------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index e8c9abb17c..1892000920 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; diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 9c445298d2..cb09103d89 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; @@ -995,9 +993,6 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, wxGenericTreeCtrl::~wxGenericTreeCtrl() { - delete m_hilightBrush; - delete m_hilightUnfocusedBrush; - DeleteAllItems(); delete m_renameTimer; @@ -1020,10 +1015,8 @@ void wxGenericTreeCtrl::OnSysColourChanged(wxSysColourChangedEvent&) 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_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 +2537,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