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:
@@ -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<int> m_colsBestWidths;
|
||||
// m_colsBestWidths partially invalid, needs recomputing
|
||||
bool m_colsDirty;
|
||||
|
||||
wxDataViewModelNotifier *m_notifier;
|
||||
wxDataViewMainWindow *m_clientArea;
|
||||
wxDataViewHeaderWindow *m_headerArea;
|
||||
|
@@ -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()
|
||||
{
|
||||
const unsigned cols = m_headerArea->GetColumnCount();
|
||||
for ( unsigned i = 0; i < cols; i++ )
|
||||
m_headerArea->UpdateColumn(i);
|
||||
if ( !m_headerArea )
|
||||
return;
|
||||
|
||||
for ( wxVector<int>::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 )
|
||||
{
|
||||
m_colsDirty = false;
|
||||
UpdateColWidths();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user