]> git.saurik.com Git - wxWidgets.git/commitdiff
update the generic wxHeaderCtrl implementation after r57161
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 7 Dec 2008 16:00:10 +0000 (16:00 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 7 Dec 2008 16:00:10 +0000 (16:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57163 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/headerctrlg.h
src/generic/headerctrlg.cpp

index 6ffd3016252a0d64588a930a274a8f09cc79d206..6b7f3e410d2675aa0a35eb979d978815f229e2a8 100644 (file)
@@ -49,11 +49,10 @@ public:
 
 private:
     // implement base class pure virtuals
+    virtual void DoSetCount(unsigned int count);
     virtual unsigned int DoGetCount() const;
-    virtual void DoInsert(const wxHeaderColumn& col, unsigned int idx);
-    virtual void DoDelete(unsigned int idx);
-    virtual void DoShowColumn(unsigned int idx, bool show);
-    virtual void DoShowSortIndicator(unsigned int idx, int sortOrder);
+    virtual void DoUpdate(unsigned int idx);
+
     virtual void DoScrollHorz(int dx);
 
     // override wxWindow methods which must be implemented by a new control
@@ -75,6 +74,9 @@ private:
     // refresh all the controls starting from (and including) the given one
     void RefreshColsAfter(unsigned int idx);
 
+    // number of columns in the control currently
+    unsigned int m_numColumns;
+
     // index of the column under mouse or -1 if none
     unsigned int m_hover;
 
index bc0880a99021fbb83e2c1c86fb8793d06c19d4ea..f55b7e1f6f4b9b2a53819389331cbd34580e98a7 100644 (file)
@@ -56,6 +56,7 @@ const unsigned COL_NONE = (unsigned)-1;
 
 void wxHeaderCtrl::Init()
 {
+    m_numColumns = 0;
     m_hover = COL_NONE;
     m_scrollOffset = 0;
 }
@@ -86,9 +87,24 @@ wxHeaderCtrl::~wxHeaderCtrl()
 // wxHeaderCtrl columns manipulation
 // ----------------------------------------------------------------------------
 
+void wxHeaderCtrl::DoSetCount(unsigned int count)
+{
+    m_numColumns = count;
+
+    Refresh();
+}
+
 unsigned int wxHeaderCtrl::DoGetCount() const
 {
-    return m_cols.size();
+    return m_numColumns;
+}
+
+void wxHeaderCtrl::DoUpdate(unsigned int idx)
+{
+    // we need to refresh not only this column but also the ones after it in
+    // case it was shown or hidden or its width changed -- it would be nice to
+    // avoid doing this unnecessary by storing the old column width (TODO)
+    RefreshColsAfter(idx);
 }
 
 // ----------------------------------------------------------------------------
@@ -116,10 +132,12 @@ wxSize wxHeaderCtrl::DoGetBestSize() const
 
 int wxHeaderCtrl::GetColStart(unsigned int idx) const
 {
+    wxHeaderCtrl * const self = const_cast<wxHeaderCtrl *>(this);
+
     int pos = 0;
     for ( unsigned n = 0; n < idx; n++ )
     {
-        const wxHeaderColumn& col = m_cols[n];
+        const wxHeaderColumnBase& col = self->GetColumn(n);
         if ( col.IsShown() )
             pos += col.GetWidth();
     }
@@ -135,7 +153,7 @@ void wxHeaderCtrl::RefreshCol(unsigned int idx)
 {
     wxRect rect = GetClientRect();
     rect.x += GetColStart(idx);
-    rect.width = m_cols[idx].GetWidth();
+    rect.width = GetColumn(idx).GetWidth();
 
     RefreshRect(rect);
 }
@@ -173,34 +191,25 @@ void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
     // account for the horizontal scrollbar offset in the parent window
     dc.SetDeviceOrigin(m_scrollOffset, 0);
 
-    const unsigned int count = m_cols.size();
+    const unsigned int count = m_numColumns;
     int xpos = 0;
     for ( unsigned int i = 0; i < count; i++ )
     {
-        const wxHeaderColumn& col = m_cols[i];
+        const wxHeaderColumnBase& col = GetColumn(i);
         if ( col.IsHidden() )
             continue;
 
         const int colWidth = col.GetWidth();
 
         wxHeaderSortIconType sortArrow;
-        switch ( m_sortOrders[i] )
+        if ( col.IsSortKey() )
         {
-            default:
-                wxFAIL_MSG( "wrong sort order value" );
-                // fall through
-
-            case -1:
-                sortArrow = wxHDR_SORT_ICON_NONE;
-                break;
-
-            case 0:
-                sortArrow = wxHDR_SORT_ICON_DOWN;
-                break;
-
-            case 1:
-                sortArrow = wxHDR_SORT_ICON_UP;
-                break;
+            sortArrow = col.IsSortOrderAscending() ? wxHDR_SORT_ICON_UP
+                                                   : wxHDR_SORT_ICON_DOWN;
+        }
+        else // not sorting by this column
+        {
+            sortArrow = wxHDR_SORT_ICON_NONE;
         }
 
         int state = 0;