Fix wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK name in the documentation.
[wxWidgets.git] / src / common / listctrlcmn.cpp
index a4cd12f2889ac372a1d384ee5a5565f691bcc330..4c89a84d266c6bef75f6b869f199a772cfa4e910 100644 (file)
@@ -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