Make wxCOL_WIDTH_AUTOSIZE work dynamically in generic wxDataViewCtrl

Caching the best column widths broke autosizing behaviour if the column title
was updated after setting the width to wxCOL_WIDTH_AUTOSIZE.

Fix this by invaliding the column cached width if its text changes.
This commit is contained in:
Vadim Zeitlin
2016-03-17 22:34:14 +01:00
parent a9be974d5b
commit db6e1c5b38
2 changed files with 28 additions and 5 deletions

View File

@@ -55,7 +55,7 @@ public:
virtual void SetTitle(const wxString& title) wxOVERRIDE
{
m_title = title;
UpdateDisplay();
UpdateWidth();
}
virtual wxString GetTitle() const wxOVERRIDE
{
@@ -65,7 +65,7 @@ public:
virtual void SetWidth(int width) wxOVERRIDE
{
// As a small optimization, use this method to avoid calling
// UpdateDisplay() if the width didn't really change, even if we don't
// UpdateWidth() if the width didn't really change, even if we don't
// care about its return value.
(void)WXUpdateWidth(width);
}
@@ -74,7 +74,7 @@ public:
virtual void SetMinWidth(int minWidth) wxOVERRIDE
{
m_minWidth = minWidth;
UpdateDisplay();
UpdateWidth();
}
virtual int GetMinWidth() const wxOVERRIDE
{
@@ -118,7 +118,7 @@ public:
virtual void SetBitmap( const wxBitmap& bitmap ) wxOVERRIDE
{
wxDataViewColumnBase::SetBitmap(bitmap);
UpdateDisplay();
UpdateWidth();
}
// This method is specific to the generic implementation and is used only
@@ -129,7 +129,7 @@ public:
return false;
m_width = width;
UpdateDisplay();
UpdateWidth();
return true;
}
@@ -138,7 +138,11 @@ private:
// common part of all ctors
void Init(int width, wxAlignment align, int flags);
// These methods forward to wxDataViewCtrl::OnColumnChange() and
// OnColumnWidthChange() respectively, i.e. the latter is stronger than the
// former.
void UpdateDisplay();
void UpdateWidth();
wxString m_title;
int m_width,
@@ -289,6 +293,9 @@ public: // utility functions not part of the API
// update the display after a change to an individual column
void OnColumnChange(unsigned int idx);
// update after the column width changes, also calls OnColumnChange()
void OnColumnWidthChange(unsigned int idx);
// update after a change to the number of columns
void OnColumnsCountChanged();

View File

@@ -186,6 +186,15 @@ void wxDataViewColumn::UpdateDisplay()
}
}
void wxDataViewColumn::UpdateWidth()
{
if (m_owner)
{
int idx = m_owner->GetColumnIndex( this );
m_owner->OnColumnWidthChange( idx );
}
}
void wxDataViewColumn::UnsetAsSortKey()
{
m_sort = false;
@@ -4846,6 +4855,13 @@ bool wxDataViewCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col )
return true;
}
void wxDataViewCtrl::OnColumnWidthChange(unsigned int idx)
{
InvalidateColBestWidth(idx);
OnColumnChange(idx);
}
void wxDataViewCtrl::OnColumnChange(unsigned int idx)
{
if ( m_headerArea )