return false;
m_cols.Append( col );
- m_colsBestWidths.push_back(0);
+ m_colsBestWidths.push_back(CachedColWidthInfo());
OnColumnsCountChanged();
return true;
}
return false;
m_cols.Insert( col );
- m_colsBestWidths.insert(m_colsBestWidths.begin(), 0);
+ m_colsBestWidths.insert(m_colsBestWidths.begin(), CachedColWidthInfo());
OnColumnsCountChanged();
return true;
}
return false;
m_cols.Insert( pos, col );
- m_colsBestWidths.insert(m_colsBestWidths.begin() + pos, 0);
+ m_colsBestWidths.insert(m_colsBestWidths.begin() + pos, CachedColWidthInfo());
OnColumnsCountChanged();
return true;
}
unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const
{
- if ( m_colsBestWidths[idx] != 0 )
- return m_colsBestWidths[idx];
+ if ( m_colsBestWidths[idx].width != 0 )
+ return m_colsBestWidths[idx].width;
const int count = m_clientArea->GetRowCount();
wxDataViewColumn *column = GetColumn(idx);
GetModel(), column->GetModelColumn(),
m_clientArea->GetRowHeight());
+ calculator.UpdateWithWidth(column->GetMinWidth());
+
if ( m_headerArea )
calculator.UpdateWithWidth(m_headerArea->GetColumnTitleWidth(*column));
if ( max_width > 0 )
max_width += 2 * PADDING_RIGHTLEFT;
- const_cast<wxDataViewCtrl*>(this)->m_colsBestWidths[idx] = max_width;
+ const_cast<wxDataViewCtrl*>(this)->m_colsBestWidths[idx].width = max_width;
return max_width;
}
void wxDataViewCtrl::InvalidateColBestWidth(int idx)
{
- m_colsBestWidths[idx] = 0;
+ m_colsBestWidths[idx].width = 0;
+ m_colsBestWidths[idx].dirty = true;
m_colsDirty = true;
}
void wxDataViewCtrl::InvalidateColBestWidths()
{
+ // mark all columns as dirty:
m_colsBestWidths.clear();
m_colsBestWidths.resize(m_cols.size());
m_colsDirty = true;
void wxDataViewCtrl::UpdateColWidths()
{
+ m_colsDirty = false;
+
if ( !m_headerArea )
return;
const unsigned len = m_colsBestWidths.size();
for ( unsigned i = 0; i < len; i++ )
{
- if ( m_colsBestWidths[i] == 0 )
+ // Note that we have to have an explicit 'dirty' flag here instead of
+ // checking if the width==0, as is done in GetBestColumnWidth().
+ //
+ // Testing width==0 wouldn't work correctly if some code called
+ // GetWidth() after col. width invalidation but before
+ // wxDataViewCtrl::UpdateColWidths() was called at idle time. This
+ // would result in the header's column width getting out of sync with
+ // the control itself.
+ if ( m_colsBestWidths[i].dirty )
+ {
m_headerArea->UpdateColumn(i);
+ m_colsBestWidths[i].dirty = false;
+ }
}
}
wxDataViewCtrlBase::OnInternalIdle();
if ( m_colsDirty )
- {
- m_colsDirty = false;
UpdateColWidths();
- }
}
int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
int row = m_clientArea->GetRowByItem( item );
if (row != -1)
+ {
m_clientArea->Expand(row);
+ InvalidateColBestWidths();
+ }
}
void wxDataViewCtrl::Collapse( const wxDataViewItem & item )
{
int row = m_clientArea->GetRowByItem( item );
if (row != -1)
+ {
m_clientArea->Collapse(row);
+ InvalidateColBestWidths();
+ }
}
bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const