int GetColLabelTextOrientation() const;
wxString GetRowLabelValue( int row ) const;
wxString GetColLabelValue( int col ) const;
- wxColour GetGridLineColour() const { return m_gridLineColour; }
- // these methods may be overridden to customize individual grid lines
- // appearance
- virtual wxPen GetDefaultGridLinePen();
- virtual wxPen GetRowGridLinePen(int row);
- virtual wxPen GetColGridLinePen(int col);
wxColour GetCellHighlightColour() const { return m_cellHighlightColour; }
int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; }
int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth; }
void SetColLabelTextOrientation( int textOrientation );
void SetRowLabelValue( int row, const wxString& );
void SetColLabelValue( int col, const wxString& );
- void SetGridLineColour( const wxColour& );
void SetCellHighlightColour( const wxColour& );
void SetCellHighlightPenWidth(int width);
void SetCellHighlightROPenWidth(int width);
void DisableDragCell() { EnableDragCell( false ); }
bool CanDragCell() const { return m_canDragCell; }
+
+ // grid lines
+ // ----------
+
+ // enable or disable drawing of the lines
+ void EnableGridLines(bool enable = true);
+ bool GridLinesEnabled() const { return m_gridLinesEnabled; }
+
+ // by default grid lines stop at last column/row, but this may be changed
+ void ClipHorzGridLines(bool clip)
+ { DoClipGridLines(m_gridLinesClipHorz, clip); }
+ void ClipVertGridLines(bool clip)
+ { DoClipGridLines(m_gridLinesClipVert, clip); }
+ bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz; }
+ bool AreVertGridLinesClipped() const { return m_gridLinesClipVert; }
+
+ // this can be used to change the global grid lines colour
+ void SetGridLineColour(const wxColour& col);
+ wxColour GetGridLineColour() const { return m_gridLineColour; }
+
+ // these methods may be overridden to customize individual grid lines
+ // appearance
+ virtual wxPen GetDefaultGridLinePen();
+ virtual wxPen GetRowGridLinePen(int row);
+ virtual wxPen GetColGridLinePen(int col);
+
+
+ // attributes
+ // ----------
+
// this sets the specified attribute for this cell or in this row/col
void SetAttr(int row, int col, wxGridCellAttr *attr);
void SetRowAttr(int row, wxGridCellAttr *attr);
void SetColFormatFloat(int col, int width = -1, int precision = -1);
void SetColFormatCustom(int col, const wxString& typeName);
- void EnableGridLines( bool enable = true );
- bool GridLinesEnabled() const { return m_gridLinesEnabled; }
-
// ------ row and col formatting
//
int GetDefaultRowSize() const;
wxColour m_gridLineColour;
bool m_gridLinesEnabled;
+ bool m_gridLinesClipHorz,
+ m_gridLinesClipVert;
wxColour m_cellHighlightColour;
int m_cellHighlightPenWidth;
int m_cellHighlightROPenWidth;
// implement wxScrolledWindow method to return m_gridWin size
virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
+ // redraw the grid lines, should be called after changing their attributes
+ void RedrawGridLines();
+
+ // common part of Clip{Horz,Vert}GridLines
+ void DoClipGridLines(bool& var, bool clip);
+
+
// event handlers and their helpers
// --------------------------------
*/
bool AppendRows(int numRows = 1, bool updateLabels = true);
+ /**
+ Return @true if the horizontal grid lines stop at the last column
+ boundary or @false if they continue to the end of the window.
+
+ The default is to clip grid lines.
+
+ @see ClipHorzGridLines(), AreVertGridLinesClipped()
+ */
+ bool AreHorzGridLinesClipped() const;
+
+ /**
+ Return @true if the vertical grid lines stop at the last row
+ boundary or @false if they continue to the end of the window.
+
+ The default is to clip grid lines.
+
+ @see ClipVertGridLines(), AreHorzGridLinesClipped()
+ */
+ bool AreVertGridLinesClipped() const;
+
/**
Automatically sets the height and width of all rows and columns to fit their
contents.
*/
void ClearSelection();
+ /**
+ Change whether the horizontal grid lines are clipped by the end of the
+ last column.
+
+ By default the grid lines are not drawn beyond the end of the last
+ column but after calling this function with @a clip set to @false they
+ will be drawn across the entire grid window.
+
+ @see AreHorzGridLinesClipped(), ClipVertGridLines()
+ */
+ void ClipHorzGridLines(bool clip);
+
+ /**
+ Change whether the vertical grid lines are clipped by the end of the
+ last row.
+
+ By default the grid lines are not drawn beyond the end of the last
+ row but after calling this function with @a clip set to @false they
+ will be drawn across the entire grid window.
+
+ @see AreVertzGridLinesClipped(), ClipHorzGridLines()
+ */
+ void ClipVertzGridLines(bool clip);
+
/**
Creates a grid with the specified initial number of rows and columns.
wxGridCellCoordsArray dirtyCells = m_owner->CalcCellsExposed( reg );
m_owner->DrawGridCellArea( dc, dirtyCells );
+ m_owner->DrawGridSpace( dc );
+
m_owner->DrawAllGridLines( dc, reg );
- m_owner->DrawGridSpace( dc );
m_owner->DrawHighlight( dc, dirtyCells );
}
m_gridLineColour = wxColour( 192,192,192 );
m_gridLinesEnabled = true;
+ m_gridLinesClipHorz =
+ m_gridLinesClipVert = true;
m_cellHighlightColour = *wxBLACK;
m_cellHighlightPenWidth = 2;
m_cellHighlightROPenWidth = 1;
//
void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) )
{
- if ( !m_gridLinesEnabled || !m_numRows || !m_numCols )
+ if ( !m_gridLinesEnabled )
return;
int top, bottom, left, right;
CalcUnscrolledPosition( cw, ch, &right, &bottom );
// avoid drawing grid lines past the last row and col
- //
- right = wxMin( right, GetColRight(GetColAt( m_numCols - 1 )) );
- bottom = wxMin( bottom, GetRowBottom(m_numRows - 1) );
+ if ( m_gridLinesClipHorz )
+ {
+ if ( !m_numCols )
+ return;
+
+ const int lastColRight = GetColRight(GetColAt(m_numCols - 1));
+ if ( right > lastColRight )
+ right = lastColRight;
+ }
+
+ if ( m_gridLinesClipVert )
+ {
+ if ( !m_numRows )
+ return;
+
+ const int lastRowBottom = GetRowBottom(m_numRows - 1);
+ if ( bottom > lastRowBottom )
+ bottom = lastRowBottom;
+ }
// no gridlines inside multicells, clip them out
int leftCol = GetColPos( internalXToCol(left) );
{
m_gridLineColour = colour;
- wxClientDC dc( m_gridWin );
- PrepareDC( dc );
- DrawAllGridLines( dc, wxRegion() );
+ if ( GridLinesEnabled() )
+ RedrawGridLines();
}
}
}
}
+void wxGrid::RedrawGridLines()
+{
+ // the lines will be redrawn when the window is thawn
+ if ( GetBatchCount() )
+ return;
+
+ if ( GridLinesEnabled() )
+ {
+ wxClientDC dc( m_gridWin );
+ PrepareDC( dc );
+ DrawAllGridLines( dc, wxRegion() );
+ }
+ else // remove the grid lines
+ {
+ m_gridWin->Refresh();
+ }
+}
+
void wxGrid::EnableGridLines( bool enable )
{
if ( enable != m_gridLinesEnabled )
{
m_gridLinesEnabled = enable;
- if ( !GetBatchCount() )
- {
- if ( enable )
- {
- wxClientDC dc( m_gridWin );
- PrepareDC( dc );
- DrawAllGridLines( dc, wxRegion() );
- }
- else
- {
- m_gridWin->Refresh();
- }
- }
+ RedrawGridLines();
+ }
+}
+
+void wxGrid::DoClipGridLines(bool& var, bool clip)
+{
+ if ( clip != var )
+ {
+ var = clip;
+
+ if ( GridLinesEnabled() )
+ RedrawGridLines();
}
}