From b55d57aa2499200346dc15eaf9a65f519b0206fd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 27 May 2012 13:00:13 +0000 Subject: [PATCH] Add wxGrid::DrawRangeGridLines(). This method draws only the grid lines for the cells in the specified range and not for all of them. It is not used yet but will be by the upcoming wxGrid::Render(), see #14294. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71576 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/grid.h | 6 ++++ src/generic/grid.cpp | 61 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index bee18f2a5c..b360283b9c 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -2133,6 +2133,12 @@ private: // redraw the grid lines, should be called after changing their attributes void RedrawGridLines(); + // draw all grid lines in the given cell region (unlike the public + // DrawAllGridLines() which just draws all of them) + void DrawRangeGridLines(wxDC& dc, const wxRegion& reg, + const wxGridCellCoords& topLeft, + const wxGridCellCoords& bottomRight); + // draw all lines from top to bottom row and left to right column in the // rectangle determined by (top, left)-(bottom, right) -- but notice that // the caller must have set up the clipping correctly, this rectangle is diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 695499108a..85edc0dbf4 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -5346,6 +5346,67 @@ void wxGrid::DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells) } } +// Used by wxGrid::Render() to draw the grid lines only for the cells in the +// specified range. +void +wxGrid::DrawRangeGridLines(wxDC& dc, + const wxRegion& reg, + const wxGridCellCoords& topLeft, + const wxGridCellCoords& bottomRight) +{ + if ( !m_gridLinesEnabled ) + return; + + int top, left, width, height; + reg.GetBox( left, top, width, height ); + + // create a clipping region + wxRegion clippedcells( dc.LogicalToDeviceX( left ), + dc.LogicalToDeviceY( top ), + dc.LogicalToDeviceXRel( width ), + dc.LogicalToDeviceYRel( height ) ); + + // subtract multi cell span area from clipping region for lines + wxRect rect; + for ( int row = topLeft.GetRow(); row <= bottomRight.GetRow(); row++ ) + { + for ( int col = topLeft.GetCol(); col <= bottomRight.GetCol(); col++ ) + { + int cell_rows, cell_cols; + GetCellSize( row, col, &cell_rows, &cell_cols ); + if ( cell_rows > 1 || cell_cols > 1 ) // multi cell + { + rect = CellToRect( row, col ); + // cater for scaling + // device origin already set in ::Render() for x, y + rect.x = dc.LogicalToDeviceX( rect.x ); + rect.y = dc.LogicalToDeviceY( rect.y ); + rect.width = dc.LogicalToDeviceXRel( rect.width ); + rect.height = dc.LogicalToDeviceYRel( rect.height ) - 1; + clippedcells.Subtract( rect ); + } + else if ( cell_rows < 0 || cell_cols < 0 ) // part of multicell + { + rect = CellToRect( row + cell_rows, col + cell_cols ); + rect.x = dc.LogicalToDeviceX( rect.x ); + rect.y = dc.LogicalToDeviceY( rect.y ); + rect.width = dc.LogicalToDeviceXRel( rect.width ); + rect.height = dc.LogicalToDeviceYRel( rect.height ) - 1; + clippedcells.Subtract( rect ); + } + } + } + + dc.SetDeviceClippingRegion( clippedcells ); + + DoDrawGridLines(dc, + top, left, top + height, left + width, + topLeft.GetRow(), topLeft.GetCol(), + bottomRight.GetRow(), bottomRight.GetCol()); + + dc.DestroyClippingRegion(); +} + // This is used to redraw all grid lines e.g. when the grid line colour // has been changed // -- 2.45.2