]> git.saurik.com Git - wxWidgets.git/commitdiff
Improve resetting table via SetTable (extended version of patch #1636377).
authorStefan Neis <Stefan.Neis@t-online.de>
Sun, 21 Jan 2007 22:39:56 +0000 (22:39 +0000)
committerStefan Neis <Stefan.Neis@t-online.de>
Sun, 21 Jan 2007 22:39:56 +0000 (22:39 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44284 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/generic/grid.cpp

index 2fab29c85ccc76a2033ec514e9f80223e7e63f22..035334b56a9ba8bc6b58a282cf43b859b8fca275 100644 (file)
@@ -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;