X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3aa1dc1ef5b87a3cce221ca5ea03353be06f5510..3c9f5d644b7cd3500658e8e14458b00d740de061:/src/common/listctrlcmn.cpp diff --git a/src/common/listctrlcmn.cpp b/src/common/listctrlcmn.cpp index a4cd12f288..4c89a84d26 100644 --- a/src/common/listctrlcmn.cpp +++ b/src/common/listctrlcmn.cpp @@ -216,4 +216,38 @@ wxSize wxListCtrlBase::DoGetBestClientSize() const return wxSize(totalWidth, 10*dc.GetCharHeight()); } +void wxListCtrlBase::SetAlternateRowColour(const wxColour& colour) +{ + wxASSERT(HasFlag(wxLC_VIRTUAL)); + m_alternateRowColour.SetBackgroundColour(colour); +} + +void wxListCtrlBase::EnableAlternateRowColours(bool enable) +{ + if ( enable ) + { + // This code is copied from wxDataViewMainWindow::OnPaint() + + // Determine the alternate rows colour automatically from the + // background colour. + const wxColour bgColour = GetBackgroundColour(); + + // Depending on the background, alternate row color + // will be 3% more dark or 50% brighter. + int alpha = bgColour.GetRGB() > 0x808080 ? 97 : 150; + SetAlternateRowColour(bgColour.ChangeLightness(alpha)); + } + else // Disable striping by setting invalid alternative colour. + { + SetAlternateRowColour(wxColour()); + } +} + +wxListItemAttr *wxListCtrlBase::OnGetItemAttr(long item) const +{ + return (m_alternateRowColour.GetBackgroundColour().IsOk() && (item % 2)) + ? wxConstCast(&m_alternateRowColour, wxListItemAttr) + : NULL; // no attributes by default +} + #endif // wxUSE_LISTCTRL