From 3d3f3e3749fa5812c1937736b8745d696263a8b5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Jul 2006 23:16:37 +0000 Subject: [PATCH] allow customization of individual grid lines appearance (patch 1496015) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40291 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + docs/latex/wx/grid.tex | 56 +++++++++++++++++++++++++++++++++++++++ include/wx/generic/grid.h | 6 +++++ src/generic/grid.cpp | 21 +++++++++++++-- 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 9efa044396..6b6668c545 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -164,6 +164,7 @@ All (GUI): - wxNB_HITTEST_* flags renamed to wxBK_HITTEST_* to serve all book controls. - Added wxTopLevelWindow::SetTransparent and CanSetTransparent, with implementations (so far) for wxMSW and wxMac. +- Allow customizing individual grid lines appearance (Søren Lassen) wxMSW: diff --git a/docs/latex/wx/grid.tex b/docs/latex/wx/grid.tex index de383355c7..0fdfd59eb6 100644 --- a/docs/latex/wx/grid.tex +++ b/docs/latex/wx/grid.tex @@ -845,6 +845,62 @@ Returns the current grid cell row position. Returns the colour used for grid lines. +\wxheading{See also} + +\helpref{GetDefaultGridLinePen()}{wxgridgetdefaultgridlinepen} + + +\membersection{wxGrid::GetDefaultGridLinePen}\label{wxgridgetdefaultgridlinepen} + +\func{wxPen}{GetDefaultGridLinePen}{\void} + +Returns the pen used for grid lines. This virtual function may be overridden in +derived classes in order to change the appearance of grid lines. Note that +currently the pen width must be $1$. + +\wxheading{See also} + +\helpref{GetColGridLinePen()}{wxgridgetcolgridlinepen},\\ +\helpref{GetRowGridLinePen()}{wxgridgetrowgridlinepen} + + + + +\membersection{wxGrid::GetRowGridLinePen}\label{wxgridgetrowgridlinepen} + +\func{wxPen}{GetRowGridLinePen}{\param{int }{row}} + +Returns the pen used for horizontal grid lines. This virtual function may be +overridden in derived classes in order to change the appearance of individual +grid line for the given row \arg{row}. + +Example: \\ +\\ +\begin{verbatim} + // in a grid displaying music notation, use a solid black pen between + // octaves (C0=row 127, C1=row 115 etc.) + wxPen MidiGrid::GetRowGridLinePen(int row) + { + if ( row%12 == 7 ) + return wxPen(*wxBLACK, 1, wxSOLID); + else + return GetDefaultGridLinePen(); + } +\end{verbatim} + + + +\membersection{wxGrid::GetColGridLinePen}\label{wxgridgetcolgridlinepen} + +\func{wxPen}{GetColGridLinePen}{\param{int }{col}} + +Returns the pen used for vertical grid lines. This virtual function may be +overridden in derived classes in order to change the appearance of individual +grid lines for the given column \arg{col}. + +See \helpref{GetRowGridLinePen()}{wxgridgetrowgridlinepen} for an example. + + \membersection{wxGrid::GridLinesEnabled}\label{wxgridgridlinesenabled} diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index a262d1b953..5631332d21 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -1282,6 +1282,12 @@ public: wxString GetRowLabelValue( int row ); wxString GetColLabelValue( int col ); wxColour GetGridLineColour() { 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() { return m_cellHighlightColour; } int GetCellHighlightPenWidth() { return m_cellHighlightPenWidth; } int GetCellHighlightROPenWidth() { return m_cellHighlightROPenWidth; } diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 284143a62e..7be6a92d1f 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -7533,6 +7533,21 @@ void wxGrid::DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ) #endif } +wxPen wxGrid::GetDefaultGridLinePen() +{ + return wxPen(GetGridLineColour(), 1, wxSOLID); +} + +wxPen wxGrid::GetRowGridLinePen(int WXUNUSED(row)) +{ + return GetDefaultGridLinePen(); +} + +wxPen wxGrid::GetColGridLinePen(int WXUNUSED(col)) +{ + return GetDefaultGridLinePen(); +} + void wxGrid::DrawCellBorder( wxDC& dc, const wxGridCellCoords& coords ) { int row = coords.GetRow(); @@ -7540,15 +7555,16 @@ void wxGrid::DrawCellBorder( wxDC& dc, const wxGridCellCoords& coords ) if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) return; - dc.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID) ); wxRect rect = CellToRect( row, col ); // right hand border + dc.SetPen( GetColGridLinePen(col) ); dc.DrawLine( rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height + 1 ); // bottom border + dc.SetPen( GetRowGridLinePen(row) ); dc.DrawLine( rect.x, rect.y + rect.height, rect.x + rect.width, rect.y + rect.height); } @@ -7693,7 +7709,6 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) ) dc.SetClippingRegion( clippedcells ); - dc.SetPen( wxPen(GetGridLineColour(), 1, wxSOLID) ); // horizontal grid lines // @@ -7709,6 +7724,7 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) ) if ( bot >= top ) { + dc.SetPen( GetRowGridLinePen(i) ); dc.DrawLine( left, bot, right, bot ); } } @@ -7728,6 +7744,7 @@ void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) ) if ( colRight >= left ) { + dc.SetPen( GetColGridLinePen(i) ); dc.DrawLine( colRight, top, colRight, bottom ); } } -- 2.45.2