-
- updateTopLeft = m_selectedTopLeft;
- if (m_selectedTopLeft != wxGridCellCoords( topRow, leftCol ) )
- {
- m_selectedTopLeft = wxGridCellCoords( topRow, leftCol );
- if (updateTopLeft == wxGridNoCellCoords)
- {
- updateTopLeft = m_selectedTopLeft;
- }
- else
- {
- if(updateTopLeft.GetRow() > topRow)
- updateTopLeft.SetRow(topRow);
- if (updateTopLeft.GetCol() > leftCol)
- updateTopLeft.SetCol(leftCol);
- }
- changed = true;
- }
-
- updateBottomRight = m_selectedBottomRight;
- if (m_selectedBottomRight != wxGridCellCoords( bottomRow, rightCol ) )
- {
- m_selectedBottomRight = wxGridCellCoords( bottomRow, rightCol );
- if (updateBottomRight == wxGridNoCellCoords)
- {
- updateBottomRight = m_selectedBottomRight;
- }
- else
- {
- if (updateBottomRight.GetRow() < bottomRow)
- updateBottomRight.SetRow(bottomRow);
- if (updateBottomRight.GetCol() < rightCol)
- updateBottomRight.SetCol(rightCol);
- }
- changed = true;
- }
-
- if (changed)
- {
- wxRect r( BlockToDeviceRect( updateTopLeft, updateBottomRight ) );
- m_gridWin->Refresh( TRUE, &r );
+
+ updateTopLeft = wxGridCellCoords( topRow, leftCol );
+ updateBottomRight = wxGridCellCoords( bottomRow, rightCol );
+
+ if ( m_selectedTopLeft != updateTopLeft ||
+ m_selectedBottomRight != updateBottomRight )
+ {
+ // Compute two optimal update rectangles:
+ // Either one rectangle is a real subset of the
+ // other, or they are (almost) disjoint!
+ wxRect rect[4];
+ bool need_refresh[4] = { FALSE, FALSE, FALSE, FALSE };
+ int i;
+
+ // Store intermediate values
+ wxCoord oldLeft = m_selectedTopLeft.GetCol();
+ wxCoord oldTop = m_selectedTopLeft.GetRow();
+ wxCoord oldRight = m_selectedBottomRight.GetCol();
+ wxCoord oldBottom = m_selectedBottomRight.GetRow();
+
+ // Determine the outer/inner coordinates.
+ if (oldLeft > leftCol)
+ {
+ temp = oldLeft;
+ oldLeft = leftCol;
+ leftCol = temp;
+ }
+ if (oldTop > topRow )
+ {
+ temp = oldTop;
+ oldTop = topRow;
+ topRow = temp;
+ }
+ if (oldRight < rightCol )
+ {
+ temp = oldRight;
+ oldRight = rightCol;
+ rightCol = temp;
+ }
+ if (oldBottom < bottomRow)
+ {
+ temp = oldBottom;
+ oldBottom = bottomRow;
+ bottomRow = temp;
+ }
+
+ // Now, either the stuff marked old is the outer
+ // rectangle or we don't have a situation where one
+ // is contained in the other.
+
+ if ( oldLeft < leftCol )
+ {
+ need_refresh[0] = TRUE;
+ rect[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
+ oldLeft ),
+ wxGridCellCoords ( oldBottom,
+ leftCol - 1 ) );
+ }
+
+ if ( oldTop < topRow )
+ {
+ need_refresh[1] = TRUE;
+ rect[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
+ leftCol ),
+ wxGridCellCoords ( topRow - 1,
+ rightCol ) );
+ }
+
+ if ( oldRight > rightCol )
+ {
+ need_refresh[2] = TRUE;
+ rect[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
+ rightCol + 1 ),
+ wxGridCellCoords ( oldBottom,
+ oldRight ) );
+ }
+
+ if ( oldBottom > bottomRow )
+ {
+ need_refresh[3] = TRUE;
+ rect[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow + 1,
+ leftCol ),
+ wxGridCellCoords ( oldBottom,
+ rightCol ) );
+ }
+
+
+ // Change Selection
+ m_selectedTopLeft = updateTopLeft;
+ m_selectedBottomRight = updateBottomRight;
+
+ // various Refresh() calls
+ for (i = 0; i < 4; i++ )
+ if ( need_refresh[i] && rect[i] != wxGridNoCellRect )
+ m_gridWin->Refresh( FALSE, &(rect[i]) );