Fix autosize columns width calculation in generic wxDataViewCtrl.

Column widths were recomputed too soon -- after the model changed, but
before the control's own data structures were updated to reflect the
change. This could lead to incorrect calculations or worse, crashes.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68806 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2011-08-21 09:07:02 +00:00
parent 5d9138be7f
commit ac0981084b

View File

@ -1969,7 +1969,6 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func )
bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item) bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
{ {
GetOwner()->InvalidateColBestWidths();
if (IsVirtualList()) if (IsVirtualList())
{ {
@ -2004,6 +2003,7 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData
m_count = -1; m_count = -1;
} }
GetOwner()->InvalidateColBestWidths();
UpdateDisplay(); UpdateDisplay();
return true; return true;
@ -2014,8 +2014,6 @@ static void DestroyTreeHelper( wxDataViewTreeNode * node);
bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent, bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
const wxDataViewItem& item) const wxDataViewItem& item)
{ {
GetOwner()->InvalidateColBestWidths();
if (IsVirtualList()) if (IsVirtualList())
{ {
wxDataViewVirtualListModel *list_model = wxDataViewVirtualListModel *list_model =
@ -2128,6 +2126,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
if( m_currentRow > GetRowCount() ) if( m_currentRow > GetRowCount() )
ChangeCurrentRow(m_count - 1); ChangeCurrentRow(m_count - 1);
GetOwner()->InvalidateColBestWidths();
UpdateDisplay(); UpdateDisplay();
return true; return true;
@ -2135,11 +2134,11 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent,
bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item) bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
{ {
GetOwner()->InvalidateColBestWidths();
SortPrepare(); SortPrepare();
g_model->Resort(); g_model->Resort();
GetOwner()->InvalidateColBestWidths();
// Send event // Send event
wxWindow *parent = GetParent(); wxWindow *parent = GetParent();
wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId()); wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
@ -2167,8 +2166,6 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
if (view_column == -1) if (view_column == -1)
return false; return false;
GetOwner()->InvalidateColBestWidth(view_column);
// NOTE: to be valid, we cannot use e.g. INT_MAX - 1 // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
/*#define MAX_VIRTUAL_WIDTH 100000 /*#define MAX_VIRTUAL_WIDTH 100000
@ -2181,6 +2178,8 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
SortPrepare(); SortPrepare();
g_model->Resort(); g_model->Resort();
GetOwner()->InvalidateColBestWidth(view_column);
// Send event // Send event
wxWindow *parent = GetParent(); wxWindow *parent = GetParent();
wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId()); wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, parent->GetId());
@ -2196,14 +2195,13 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i
bool wxDataViewMainWindow::Cleared() bool wxDataViewMainWindow::Cleared()
{ {
GetOwner()->InvalidateColBestWidths();
DestroyTree(); DestroyTree();
m_selection.Clear(); m_selection.Clear();
SortPrepare(); SortPrepare();
BuildTree( GetOwner()->GetModel() ); BuildTree( GetOwner()->GetModel() );
GetOwner()->InvalidateColBestWidths();
UpdateDisplay(); UpdateDisplay();
return true; return true;