From a7dde52f0acc761e9b63148c7c672693586d5572 Mon Sep 17 00:00:00 2001 From: Stefan Neis Date: Sun, 21 Jan 2007 22:39:56 +0000 Subject: [PATCH] Improve resetting table via SetTable (extended version of patch #1636377). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44284 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/grid.cpp | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 2fab29c85c..035334b56a 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -4357,24 +4357,33 @@ wxGrid::wxGridSelectionModes wxGrid::GetSelectionMode() const bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership, wxGrid::wxGridSelectionModes selmode ) { + bool checkSelection = false; if ( m_created ) { // stop all processing m_created = false; - if (m_ownTable) + if (m_table) { - wxGridTableBase *t = m_table; + m_table->SetView(0); + if( m_ownTable ) + delete m_table; m_table = NULL; - delete t; } delete m_selection; - - m_table = NULL; m_selection = NULL; + + m_ownTable = false; m_numRows = 0; m_numCols = 0; + checkSelection = true; + + // kill row and column size arrays + m_colWidths.Empty(); + m_colRights.Empty(); + m_rowHeights.Empty(); + m_rowBottoms.Empty(); } if (table) @@ -4386,7 +4395,28 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership, m_table->SetView( this ); m_ownTable = takeOwnership; m_selection = new wxGridSelection( this, selmode ); - + if (checkSelection) + { + // If the newly set table is smaller than the + // original one current cell and selection regions + // might be invalid, + m_selectingKeyboard = wxGridNoCellCoords; + m_currentCellCoords = + wxGridCellCoords(wxMin(m_numRows, m_currentCellCoords.GetRow()), + wxMin(m_numCols, m_currentCellCoords.GetCol())); + if (m_selectingTopLeft.GetRow() >= m_numRows || + m_selectingTopLeft.GetCol() >= m_numCols) + { + m_selectingTopLeft = wxGridNoCellCoords; + m_selectingBottomRight = wxGridNoCellCoords; + } + else + m_selectingBottomRight = + wxGridCellCoords(wxMin(m_numRows, + m_selectingBottomRight.GetRow()), + wxMin(m_numCols, + m_selectingBottomRight.GetCol())); + } CalcDimensions(); m_created = true; -- 2.45.2