Use wxCompositeWindow for generic wxDataViewCtrl implementation

This makes several methods that didn't have any effect before work
correctly, including SetToolTip(), whose effect is now shown in the
sample, but also SetCursor() and SetLayoutDirection().

Some methods would now actually work too well: SetForegroundColour() and
SetBackgroundColour() implementations in wxCompositeWindow apply to all
sub-windows, but in wxDataViewCtrl they are only supposed to affect the
items, but not the header, so we need to override them to prevent the
base class version from being used. It is still preferable to explicitly
disable these two methods and inherit all the other ones (including any
possibly added in the future) from wxCompositeWindow to implementing all
the methods manually in wxDataViewCtrl itself.
This commit is contained in:
Vadim Zeitlin
2021-05-23 14:14:29 +01:00
parent fa00fd24f0
commit 3ed930c736
3 changed files with 51 additions and 10 deletions

View File

@@ -5584,6 +5584,14 @@ bool wxDataViewCtrl::Create(wxWindow *parent,
return true;
}
wxWindowList wxDataViewCtrl::GetCompositeWindowParts() const
{
wxWindowList parts;
parts.push_back(m_headerArea); // It's ok to add it even if it's null.
parts.push_back(m_clientArea);
return parts;
}
wxBorder wxDataViewCtrl::GetDefaultBorder() const
{
return wxBORDER_THEME;
@@ -5679,15 +5687,11 @@ void wxDataViewCtrl::SetFocus()
bool wxDataViewCtrl::SetFont(const wxFont & font)
{
if (!wxControl::SetFont(font))
if (!BaseType::SetFont(font))
return false;
if (m_headerArea)
m_headerArea->SetFont(font);
if (m_clientArea)
{
m_clientArea->SetFont(font);
m_clientArea->SetRowHeight(m_clientArea->GetDefaultRowHeight());
}
@@ -5700,6 +5704,35 @@ bool wxDataViewCtrl::SetFont(const wxFont & font)
return true;
}
bool wxDataViewCtrl::SetForegroundColour(const wxColour& colour)
{
// Previous versions of this class, not using wxCompositeWindow, as well as
// the native versions of this control, don't change the header foreground
// when this method is called and this could be more desirable in practice,
// as well we being more compatible, so skip calling the base class version
// that would change it as well and change only the main items area colour
// here too.
if ( !wxDataViewCtrlBase::SetForegroundColour(colour) )
return false;
if ( m_clientArea )
m_clientArea->SetForegroundColour(colour);
return true;
}
bool wxDataViewCtrl::SetBackgroundColour(const wxColour& colour)
{
// See SetForegroundColour() above.
if ( !wxDataViewCtrlBase::SetBackgroundColour(colour) )
return false;
if ( m_clientArea )
m_clientArea->SetBackgroundColour(colour);
return true;
}
#if wxUSE_ACCESSIBILITY
bool wxDataViewCtrl::Show(bool show)
{