Implement wxDV_ROW_LINES for generic wxDataViewCtrl.

Provide wxDataViewCtrl::SetAlternateRowColour() to specify the colour to use
for odd rows explicitly but determine it automatically from the background
colour if no explicit colour was specified.

Closes #12834.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70576 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-02-12 22:19:04 +00:00
parent 8b6af8eedd
commit 4bdc891f54
3 changed files with 45 additions and 0 deletions

View File

@@ -1745,6 +1745,37 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
x_last += col->GetWidth();
}
// Draw background of alternate rows specially if required
if ( m_owner->HasFlag(wxDV_ROW_LINES) )
{
wxColour altRowColour = m_owner->m_alternateRowColour;
if ( !altRowColour.IsOk() )
{
// Determine the alternate rows colour automatically from the
// background colour.
const wxColour bgColour = m_owner->GetBackgroundColour();
// Depending on the background, alternate row color
// will be 3% more dark or 50% brighter.
int alpha = bgColour.GetRGB() > 0x808080 ? 97 : 150;
altRowColour = bgColour.ChangeLightness(alpha);
}
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxBrush(altRowColour));
for (unsigned int item = item_start; item < item_last; item++)
{
if ( item % 2 )
{
dc.DrawRectangle(x_start,
GetLineStart(item),
GetClientSize().GetWidth(),
GetLineHeight(item));
}
}
}
// Draw horizontal rules if required
if ( m_owner->HasFlag(wxDV_HORIZ_RULES) )
{
@@ -4931,6 +4962,11 @@ bool wxDataViewCtrl::IsSelected( const wxDataViewItem & item ) const
return false;
}
void wxDataViewCtrl::SetAlternateRowColour(const wxColour& colour)
{
m_alternateRowColour = colour;
}
void wxDataViewCtrl::SelectAll()
{
m_clientArea->SelectAllRows(true);