+ // The following loop is ONLY necessary to detect and handle merged cells.
+ int cw, ch;
+ m_gridWin->GetClientSize( &cw, &ch );
+
+ // Get the origin coordinates: notice that they will be negative if the
+ // grid is scrolled downwards/to the right.
+ int gridOriginX = 0;
+ int gridOriginY = 0;
+ CalcScrolledPosition(gridOriginX, gridOriginY, &gridOriginX, &gridOriginY);
+
+ int onScreenLeftmostCol = internalXToCol(-gridOriginX);
+ int onScreenUppermostRow = internalYToRow(-gridOriginY);
+
+ int onScreenRightmostCol = internalXToCol(-gridOriginX + cw);
+ int onScreenBottommostRow = internalYToRow(-gridOriginY + ch);
+
+ // Bound our loop so that we only examine the portion of the selected block
+ // that is shown on screen. Therefore, we compare the Top-Left block values
+ // to the Top-Left screen values, and the Bottom-Right block values to the
+ // Bottom-Right screen values, choosing appropriately.
+ const int visibleTopRow = wxMax(topRow, onScreenUppermostRow);
+ const int visibleBottomRow = wxMin(bottomRow, onScreenBottommostRow);
+ const int visibleLeftCol = wxMax(leftCol, onScreenLeftmostCol);
+ const int visibleRightCol = wxMin(rightCol, onScreenRightmostCol);
+
+ for ( int j = visibleTopRow; j <= visibleBottomRow; j++ )