added the possibility to draw grid lines across the entire window
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56085 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1372,13 +1372,7 @@ public:
|
||||
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; }
|
||||
@@ -1396,7 +1390,6 @@ public:
|
||||
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);
|
||||
@@ -1418,6 +1411,36 @@ public:
|
||||
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);
|
||||
@@ -1438,9 +1461,6 @@ public:
|
||||
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;
|
||||
@@ -1961,6 +1981,8 @@ protected:
|
||||
|
||||
wxColour m_gridLineColour;
|
||||
bool m_gridLinesEnabled;
|
||||
bool m_gridLinesClipHorz,
|
||||
m_gridLinesClipVert;
|
||||
wxColour m_cellHighlightColour;
|
||||
int m_cellHighlightPenWidth;
|
||||
int m_cellHighlightROPenWidth;
|
||||
@@ -2160,6 +2182,13 @@ private:
|
||||
// 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
|
||||
// --------------------------------
|
||||
|
||||
|
@@ -1358,6 +1358,26 @@ public:
|
||||
*/
|
||||
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.
|
||||
@@ -1504,6 +1524,30 @@ public:
|
||||
*/
|
||||
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.
|
||||
|
||||
|
@@ -4349,9 +4349,10 @@ void wxGridWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
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 );
|
||||
}
|
||||
|
||||
@@ -4819,6 +4820,8 @@ void wxGrid::Init()
|
||||
|
||||
m_gridLineColour = wxColour( 192,192,192 );
|
||||
m_gridLinesEnabled = true;
|
||||
m_gridLinesClipHorz =
|
||||
m_gridLinesClipVert = true;
|
||||
m_cellHighlightColour = *wxBLACK;
|
||||
m_cellHighlightPenWidth = 2;
|
||||
m_cellHighlightROPenWidth = 1;
|
||||
@@ -7910,7 +7913,7 @@ void wxGrid::DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells)
|
||||
//
|
||||
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;
|
||||
@@ -7921,9 +7924,25 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) )
|
||||
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) );
|
||||
@@ -9413,9 +9432,8 @@ void wxGrid::SetGridLineColour( const wxColour& colour )
|
||||
{
|
||||
m_gridLineColour = colour;
|
||||
|
||||
wxClientDC dc( m_gridWin );
|
||||
PrepareDC( dc );
|
||||
DrawAllGridLines( dc, wxRegion() );
|
||||
if ( GridLinesEnabled() )
|
||||
RedrawGridLines();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9470,25 +9488,42 @@ void wxGrid::SetCellHighlightROPenWidth(int width)
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user