From ac0981084be17e806d08ffdde0215b3c2585e749 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sun, 21 Aug 2011 09:07:02 +0000 Subject: [PATCH] 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 --- src/generic/datavgen.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 233b83f5b3..38ccff89df 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -1969,7 +1969,6 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func ) bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item) { - GetOwner()->InvalidateColBestWidths(); if (IsVirtualList()) { @@ -2004,6 +2003,7 @@ bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxData m_count = -1; } + GetOwner()->InvalidateColBestWidths(); UpdateDisplay(); return true; @@ -2014,8 +2014,6 @@ static void DestroyTreeHelper( wxDataViewTreeNode * node); bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent, const wxDataViewItem& item) { - GetOwner()->InvalidateColBestWidths(); - if (IsVirtualList()) { wxDataViewVirtualListModel *list_model = @@ -2128,6 +2126,7 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent, if( m_currentRow > GetRowCount() ) ChangeCurrentRow(m_count - 1); + GetOwner()->InvalidateColBestWidths(); UpdateDisplay(); return true; @@ -2135,11 +2134,11 @@ bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem& parent, bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item) { - GetOwner()->InvalidateColBestWidths(); - SortPrepare(); g_model->Resort(); + GetOwner()->InvalidateColBestWidths(); + // Send event wxWindow *parent = GetParent(); 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) return false; - GetOwner()->InvalidateColBestWidth(view_column); - // NOTE: to be valid, we cannot use e.g. INT_MAX - 1 /*#define MAX_VIRTUAL_WIDTH 100000 @@ -2181,6 +2178,8 @@ bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned i SortPrepare(); g_model->Resort(); + GetOwner()->InvalidateColBestWidth(view_column); + // Send event wxWindow *parent = GetParent(); 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() { - GetOwner()->InvalidateColBestWidths(); - DestroyTree(); m_selection.Clear(); SortPrepare(); BuildTree( GetOwner()->GetModel() ); + GetOwner()->InvalidateColBestWidths(); UpdateDisplay(); return true; -- 2.45.2