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
This commit is contained in:
Václav Slavík
2011-08-31 09:04:41 +00:00
parent 685a9fa61d
commit bed74e488f
2 changed files with 41 additions and 16 deletions

View File

@@ -220,17 +220,23 @@ public: // utility functions not part of the API
// return the column displayed at the given position in the control // return the column displayed at the given position in the control
wxDataViewColumn *GetColumnAt(unsigned int pos) const; wxDataViewColumn *GetColumnAt(unsigned int pos) const;
virtual void OnInternalIdle();
private: private:
virtual wxDataViewItem DoGetCurrentItem() const; virtual wxDataViewItem DoGetCurrentItem() const;
virtual void DoSetCurrentItem(const wxDataViewItem& item); virtual void DoSetCurrentItem(const wxDataViewItem& item);
void UpdateColBestWidths(); void InvalidateColBestWidths();
void UpdateColBestWidth(int idx); void InvalidateColBestWidth(int idx);
void UpdateColWidths();
wxDataViewColumnList m_cols; wxDataViewColumnList m_cols;
// cached column best widths or 0 if not computed, values are for // cached column best widths or 0 if not computed, values are for
// respective columns from m_cols and the arrays have same size // respective columns from m_cols and the arrays have same size
wxVector<int> m_colsBestWidths; wxVector<int> m_colsBestWidths;
// m_colsBestWidths partially invalid, needs recomputing
bool m_colsDirty;
wxDataViewModelNotifier *m_notifier; wxDataViewModelNotifier *m_notifier;
wxDataViewMainWindow *m_clientArea; wxDataViewMainWindow *m_clientArea;
wxDataViewHeaderWindow *m_headerArea; wxDataViewHeaderWindow *m_headerArea;

View File

@@ -2034,7 +2034,7 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData
m_count = -1; m_count = -1;
} }
GetOwner()->UpdateColBestWidths(); GetOwner()->InvalidateColBestWidths();
UpdateDisplay(); UpdateDisplay();
return true; return true;
@@ -2169,7 +2169,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
if( m_currentRow > GetRowCount() ) if( m_currentRow > GetRowCount() )
ChangeCurrentRow(m_count - 1); ChangeCurrentRow(m_count - 1);
GetOwner()->UpdateColBestWidths(); GetOwner()->InvalidateColBestWidths();
UpdateDisplay(); UpdateDisplay();
return true; return true;
@@ -2180,7 +2180,7 @@ bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
SortPrepare(); SortPrepare();
g_model->Resort(); g_model->Resort();
GetOwner()->UpdateColBestWidths(); GetOwner()->InvalidateColBestWidths();
// Send event // Send event
wxWindow *parent = GetParent(); wxWindow *parent = GetParent();
@@ -2221,7 +2221,7 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
SortPrepare(); SortPrepare();
g_model->Resort(); g_model->Resort();
GetOwner()->UpdateColBestWidth(view_column); GetOwner()->InvalidateColBestWidth(view_column);
// Send event // Send event
wxWindow *parent = GetParent(); wxWindow *parent = GetParent();
@@ -2244,7 +2244,7 @@ bool wxDataViewMainWindow::Cleared()
SortPrepare(); SortPrepare();
BuildTree( GetModel() ); BuildTree( GetModel() );
GetOwner()->UpdateColBestWidths(); GetOwner()->InvalidateColBestWidths();
UpdateDisplay(); UpdateDisplay();
return true; return true;
@@ -3931,6 +3931,8 @@ void wxDataViewCtrl::Init()
m_sortingColumnIdx = wxNOT_FOUND; m_sortingColumnIdx = wxNOT_FOUND;
m_headerArea = NULL; m_headerArea = NULL;
m_colsDirty = false;
} }
bool wxDataViewCtrl::Create(wxWindow *parent, bool wxDataViewCtrl::Create(wxWindow *parent,
@@ -4340,24 +4342,41 @@ bool wxDataViewCtrl::ClearColumns()
return true; return true;
} }
void wxDataViewCtrl::UpdateColBestWidth(int idx) void wxDataViewCtrl::InvalidateColBestWidth(int idx)
{ {
m_colsBestWidths[idx] = 0; m_colsBestWidths[idx] = 0;
m_colsDirty = true;
if ( m_headerArea )
m_headerArea->UpdateColumn(idx);
} }
void wxDataViewCtrl::UpdateColBestWidths() void wxDataViewCtrl::InvalidateColBestWidths()
{ {
m_colsBestWidths.clear(); m_colsBestWidths.clear();
m_colsBestWidths.resize(m_cols.size()); m_colsBestWidths.resize(m_cols.size());
m_colsDirty = true;
}
if ( m_headerArea ) void wxDataViewCtrl::UpdateColWidths()
{
if ( !m_headerArea )
return;
for ( wxVector<int>::const_iterator i = m_colsBestWidths.begin();
i != m_colsBestWidths.end();
++i )
{ {
const unsigned cols = m_headerArea->GetColumnCount(); if ( m_colsBestWidths[*i] == 0 )
for ( unsigned i = 0; i < cols; i++ ) m_headerArea->UpdateColumn(*i);
m_headerArea->UpdateColumn(i); }
}
void wxDataViewCtrl::OnInternalIdle()
{
wxDataViewCtrlBase::OnInternalIdle();
if ( m_colsDirty )
{
m_colsDirty = false;
UpdateColWidths();
} }
} }