]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxGrid::DrawRangeGridLines().
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 27 May 2012 13:00:13 +0000 (13:00 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 27 May 2012 13:00:13 +0000 (13:00 +0000)
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
src/generic/grid.cpp

index bee18f2a5c905c43dbe87b54c7ea78bec746442e..b360283b9ca47d95dfd81955e96acf6e803dffe8 100644 (file)
@@ -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
index 695499108a216e1be632118aaab57a7de200eee0..85edc0dbf42b60abd3506352f6a70463a6a2c3df 100644 (file)
@@ -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
 //