Fix background colour drawing in wxGenericTreeCtrl under Mac

Revert 8535cde836 (Remove apparently unnecessary m_hasExplicitFont,
2020-07-14) and make 9cd3ab5ebd (Improve wxGenericTreeCtrl colours/fonts
updating on theme change, 2020-07-14) really work as expected by using
not only m_hasExplicitFont, but also m_hasExplicit{Fg,Bg}Col in order to
ensure that we only update the attributes if they hadn't been explicitly
set.

This is necessary because the hack with reusing m_has{Fg,Bg}Col didn't
work under Mac where the colour wasn't used at all when they were false.
This still seems to be a problem as the behaviour is different from that
of the other ports, but fixing this in wxOSX doesn't seem to be simple,
so don't rely on this working and use separate variables instead.

Closes #18940.
This commit is contained in:
Vadim Zeitlin
2021-01-16 19:17:57 +01:00
parent 9c66a9a8db
commit 4a5de04ece
2 changed files with 30 additions and 10 deletions

View File

@@ -365,6 +365,14 @@ private:
// operation.
void ResetFindState();
// True if we're using custom colours/font, respectively, or false if we're
// using the default colours and should update them whenever system colours
// change.
bool m_hasExplicitFgCol:1,
m_hasExplicitBgCol:1,
m_hasExplicitFont:1;
wxDECLARE_EVENT_TABLE();
wxDECLARE_DYNAMIC_CLASS(wxGenericTreeCtrl);
wxDECLARE_NO_COPY_CLASS(wxGenericTreeCtrl);

View File

@@ -979,6 +979,10 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent,
m_spacing = 10;
}
m_hasExplicitFgCol = m_hasFgCol;
m_hasExplicitBgCol = m_hasBgCol;
m_hasExplicitFont = m_hasFont;
InitVisualAttributes();
SetInitialSize(size);
@@ -1006,26 +1010,27 @@ 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.
// m_hasExplicitXXX variables to false to prevent them from being left set
// to "true" after calling the corresponding SetXXX(), as otherwise we
// wouldn't update the colours/fonts the next time the system colours
// change.
const wxVisualAttributes attr(GetDefaultAttributes());
if ( !m_hasFgCol )
if ( !m_hasExplicitFgCol )
{
SetOwnForegroundColour(attr.colFg);
m_hasFgCol = false;
m_hasExplicitFgCol = false;
}
if ( !m_hasBgCol )
if ( !m_hasExplicitBgCol )
{
SetOwnBackgroundColour(attr.colBg);
m_hasBgCol = false;
m_hasExplicitBgCol = false;
}
if ( !m_hasFont )
if ( !m_hasExplicitFont )
{
SetOwnFont(attr.font);
m_hasFont = false;
m_hasExplicitFont = false;
}
@@ -1279,7 +1284,10 @@ wxGenericTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font)
bool wxGenericTreeCtrl::SetFont( const wxFont &font )
{
wxTreeCtrlBase::SetFont(font);
if ( !wxTreeCtrlBase::SetFont(font) )
return false;
m_hasExplicitFont = true;
m_normalFont = font;
m_boldFont = m_normalFont.Bold();
@@ -4094,6 +4102,8 @@ bool wxGenericTreeCtrl::SetBackgroundColour(const wxColour& colour)
if ( !wxWindow::SetBackgroundColour(colour) )
return false;
m_hasExplicitBgCol = true;
Refresh();
return true;
@@ -4104,6 +4114,8 @@ bool wxGenericTreeCtrl::SetForegroundColour(const wxColour& colour)
if ( !wxWindow::SetForegroundColour(colour) )
return false;
m_hasExplicitFgCol = true;
Refresh();
return true;