Merge branch 'generic-treectrl-cleanup'
Improve wxGenericTreeCtrl code handling system colours/theme changes. See #18823.
This commit is contained in:
@@ -13,8 +13,9 @@
|
|||||||
|
|
||||||
#if wxUSE_TREECTRL
|
#if wxUSE_TREECTRL
|
||||||
|
|
||||||
#include "wx/scrolwin.h"
|
#include "wx/brush.h"
|
||||||
#include "wx/pen.h"
|
#include "wx/pen.h"
|
||||||
|
#include "wx/scrolwin.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// forward declaration
|
// forward declaration
|
||||||
@@ -243,8 +244,8 @@ protected:
|
|||||||
unsigned short m_indent;
|
unsigned short m_indent;
|
||||||
int m_lineHeight;
|
int m_lineHeight;
|
||||||
wxPen m_dottedPen;
|
wxPen m_dottedPen;
|
||||||
wxBrush *m_hilightBrush,
|
wxBrush m_hilightBrush,
|
||||||
*m_hilightUnfocusedBrush;
|
m_hilightUnfocusedBrush;
|
||||||
bool m_hasFocus;
|
bool m_hasFocus;
|
||||||
bool m_dirty;
|
bool m_dirty;
|
||||||
bool m_ownsImageListButtons;
|
bool m_ownsImageListButtons;
|
||||||
@@ -351,9 +352,14 @@ protected:
|
|||||||
virtual wxSize DoGetBestSize() const wxOVERRIDE;
|
virtual wxSize DoGetBestSize() const wxOVERRIDE;
|
||||||
|
|
||||||
private:
|
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)
|
// Reset the state of the last find (i.e. keyboard incremental search)
|
||||||
// operation.
|
// operation.
|
||||||
|
@@ -937,8 +937,6 @@ void wxGenericTreeCtrl::Init()
|
|||||||
m_indent = 15;
|
m_indent = 15;
|
||||||
m_spacing = 18;
|
m_spacing = 18;
|
||||||
|
|
||||||
m_hilightBrush = NULL;
|
|
||||||
m_hilightUnfocusedBrush = NULL;
|
|
||||||
m_imageListButtons = NULL;
|
m_imageListButtons = NULL;
|
||||||
m_ownsImageListButtons = false;
|
m_ownsImageListButtons = false;
|
||||||
|
|
||||||
@@ -984,9 +982,7 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
|
|||||||
m_spacing = 10;
|
m_spacing = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_hasExplicitFont = m_hasFont;
|
InitVisualAttributes();
|
||||||
wxSysColourChangedEvent evt;
|
|
||||||
OnSysColourChanged(evt);
|
|
||||||
|
|
||||||
SetInitialSize(size);
|
SetInitialSize(size);
|
||||||
|
|
||||||
@@ -995,9 +991,6 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
|
|||||||
|
|
||||||
wxGenericTreeCtrl::~wxGenericTreeCtrl()
|
wxGenericTreeCtrl::~wxGenericTreeCtrl()
|
||||||
{
|
{
|
||||||
delete m_hilightBrush;
|
|
||||||
delete m_hilightUnfocusedBrush;
|
|
||||||
|
|
||||||
DeleteAllItems();
|
DeleteAllItems();
|
||||||
|
|
||||||
delete m_renameTimer;
|
delete m_renameTimer;
|
||||||
@@ -1012,18 +1005,35 @@ void wxGenericTreeCtrl::EnableBellOnNoMatch( bool on )
|
|||||||
m_findBell = 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());
|
const wxVisualAttributes attr(GetDefaultAttributes());
|
||||||
SetOwnForegroundColour(attr.colFg);
|
if ( !m_hasFgCol )
|
||||||
SetOwnBackgroundColour(attr.colBg);
|
{
|
||||||
if (!m_hasExplicitFont)
|
SetOwnForegroundColour(attr.colFg);
|
||||||
SetOwnFont(attr.font);
|
m_hasFgCol = false;
|
||||||
|
}
|
||||||
|
|
||||||
delete m_hilightBrush;
|
if ( !m_hasBgCol )
|
||||||
m_hilightBrush = new wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
|
{
|
||||||
delete m_hilightUnfocusedBrush;
|
SetOwnBackgroundColour(attr.colBg);
|
||||||
m_hilightUnfocusedBrush = new wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
|
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);
|
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() )
|
if ( item->IsSelected() )
|
||||||
{
|
{
|
||||||
dc.SetBrush(*(m_hasFocus ? m_hilightBrush : m_hilightUnfocusedBrush));
|
dc.SetBrush(m_hasFocus ? m_hilightBrush : m_hilightUnfocusedBrush);
|
||||||
drawItemBackground = true;
|
drawItemBackground = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user