]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement wxDV_ROW_LINES for generic wxDataViewCtrl.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 12 Feb 2012 22:19:04 +0000 (22:19 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 12 Feb 2012 22:19:04 +0000 (22:19 +0000)
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

docs/changes.txt
include/wx/generic/dataview.h
src/generic/datavgen.cpp

index a9d343bf7ce3ae5c70263031b7dbbeb1b7bab010..8854459475ff47258ee170e0775e84e83b18b64a 100644 (file)
@@ -487,6 +487,7 @@ All (GUI):
 - Implement wxMenuBar::IsEnabledTop() for all major ports (Igor Korot).
 - Implement best size calculation for report mode wxListCtrl.
 - Fix setting of the frame icon when using non-standard icon sizes (vid).
+- Implement wxDV_ROW_LINES in generic wxDataViewCtrl (RedCAT).
 
 GTK:
 
index 32e7723fd97d9a53cb34946785c7ea2cc8c45049..c2cf345a4c69e5fdec7e227e28d19e7e05dc916d 100644 (file)
@@ -191,6 +191,11 @@ public:
 
     virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column);
 
+    // These methods are specific to generic wxDataViewCtrl implementation and
+    // should not be used in portable code.
+    wxColour GetAlternateRowColour() const { return m_alternateRowColour; }
+    void SetAlternateRowColour(const wxColour& colour);
+
 protected:
     virtual void EnsureVisible( int row, int column );
 
@@ -245,6 +250,9 @@ private:
     wxDataViewMainWindow     *m_clientArea;
     wxDataViewHeaderWindow   *m_headerArea;
 
+    // user defined color to draw row lines, may be invalid
+    wxColour m_alternateRowColour;
+
     // the index of the column currently used for sorting or -1
     int m_sortingColumnIdx;
 
index 5fd5797d8cdf44cc9a49f3d0b8356eff3e22ebc0..8d386708761284f5e7cb65f2df7dc44f1cf1f983 100644 (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);