From: Václav Slavík Date: Wed, 31 Aug 2011 09:04:41 +0000 (+0000) Subject: Generic wxDataViewCtrl: resize autosized columns at idle time. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/bed74e488fd6f8dfcb06d9492ac5b34d0af2ec00 Generic wxDataViewCtrl: resize autosized columns at idle time. This is much more efficient than doing it immediately when adding large number of items into a control with lots of them. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68964 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index ce3540749d..e4f69aec2d 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -220,17 +220,23 @@ public: // utility functions not part of the API // return the column displayed at the given position in the control wxDataViewColumn *GetColumnAt(unsigned int pos) const; + virtual void OnInternalIdle(); + private: virtual wxDataViewItem DoGetCurrentItem() const; virtual void DoSetCurrentItem(const wxDataViewItem& item); - void UpdateColBestWidths(); - void UpdateColBestWidth(int idx); + void InvalidateColBestWidths(); + void InvalidateColBestWidth(int idx); + void UpdateColWidths(); wxDataViewColumnList m_cols; // cached column best widths or 0 if not computed, values are for // respective columns from m_cols and the arrays have same size wxVector m_colsBestWidths; + // m_colsBestWidths partially invalid, needs recomputing + bool m_colsDirty; + wxDataViewModelNotifier *m_notifier; wxDataViewMainWindow *m_clientArea; wxDataViewHeaderWindow *m_headerArea; diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 8143e146c9..32f9ee47ac 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -2034,7 +2034,7 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData m_count = -1; } - GetOwner()->UpdateColBestWidths(); + GetOwner()->InvalidateColBestWidths(); UpdateDisplay(); return true; @@ -2169,7 +2169,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent, if( m_currentRow > GetRowCount() ) ChangeCurrentRow(m_count - 1); - GetOwner()->UpdateColBestWidths(); + GetOwner()->InvalidateColBestWidths(); UpdateDisplay(); return true; @@ -2180,7 +2180,7 @@ bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item) SortPrepare(); g_model->Resort(); - GetOwner()->UpdateColBestWidths(); + GetOwner()->InvalidateColBestWidths(); // Send event wxWindow *parent = GetParent(); @@ -2221,7 +2221,7 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i SortPrepare(); g_model->Resort(); - GetOwner()->UpdateColBestWidth(view_column); + GetOwner()->InvalidateColBestWidth(view_column); // Send event wxWindow *parent = GetParent(); @@ -2244,7 +2244,7 @@ bool wxDataViewMainWindow::Cleared() SortPrepare(); BuildTree( GetModel() ); - GetOwner()->UpdateColBestWidths(); + GetOwner()->InvalidateColBestWidths(); UpdateDisplay(); return true; @@ -3931,6 +3931,8 @@ void wxDataViewCtrl::Init() m_sortingColumnIdx = wxNOT_FOUND; m_headerArea = NULL; + + m_colsDirty = false; } bool wxDataViewCtrl::Create(wxWindow *parent, @@ -4340,24 +4342,41 @@ bool wxDataViewCtrl::ClearColumns() return true; } -void wxDataViewCtrl::UpdateColBestWidth(int idx) +void wxDataViewCtrl::InvalidateColBestWidth(int idx) { m_colsBestWidths[idx] = 0; - - if ( m_headerArea ) - m_headerArea->UpdateColumn(idx); + m_colsDirty = true; } -void wxDataViewCtrl::UpdateColBestWidths() +void wxDataViewCtrl::InvalidateColBestWidths() { m_colsBestWidths.clear(); m_colsBestWidths.resize(m_cols.size()); + m_colsDirty = true; +} - if ( m_headerArea ) +void wxDataViewCtrl::UpdateColWidths() +{ + if ( !m_headerArea ) + return; + + for ( wxVector::const_iterator i = m_colsBestWidths.begin(); + i != m_colsBestWidths.end(); + ++i ) + { + if ( m_colsBestWidths[*i] == 0 ) + m_headerArea->UpdateColumn(*i); + } +} + +void wxDataViewCtrl::OnInternalIdle() +{ + wxDataViewCtrlBase::OnInternalIdle(); + + if ( m_colsDirty ) { - const unsigned cols = m_headerArea->GetColumnCount(); - for ( unsigned i = 0; i < cols; i++ ) - m_headerArea->UpdateColumn(i); + m_colsDirty = false; + UpdateColWidths(); } }