]> git.saurik.com Git - wxWidgets.git/commitdiff
properly implement Do[GS]etColumnsOrder() in the generic wxHeaderCtrl
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 10 Dec 2008 16:24:08 +0000 (16:24 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 10 Dec 2008 16:24:08 +0000 (16:24 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57236 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

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

index dd943a8deb36a24f98c189b940ff5134e5a1b6a6..489dad5accb30db3c7898a08196f4bc863ea9be7 100644 (file)
@@ -89,7 +89,7 @@ private:
     // position is near the divider at the right end of this column (notice
     // that this means that we return column 0 even if the position is over
     // column 1 but close enough to the divider separating it from column 0)
-    int FindColumnAtPos(int x, bool& onSeparator) const;
+    int FindColumnAtPoint(int x, bool& onSeparator) const;
 
     // return true if a drag resizing operation is currently in progress
     bool IsResizing() const;
index 6b9c1a399b409890946e72aac47bcf826b5a5983..6ed2e6caa8f7d274fc77f3e8c898ad83f26db8c4 100644 (file)
@@ -90,8 +90,31 @@ wxHeaderCtrl::~wxHeaderCtrl()
 
 void wxHeaderCtrl::DoSetCount(unsigned int count)
 {
+    // update the column indices array if necessary
+    if ( count > m_numColumns )
+    {
+        // all new columns have default positions equal to their indices
+        for ( unsigned n = m_numColumns; n < count; n++ )
+            m_colIndices.push_back(n);
+    }
+    else if ( count < m_numColumns )
+    {
+        // filter out all the positions which are invalid now while keeping the
+        // order of the remaining ones
+        wxArrayInt colIndices;
+        for ( unsigned n = 0; n < m_numColumns; n++ )
+        {
+            const unsigned idx = m_colIndices[n];
+            if ( idx < count )
+                colIndices.push_back(idx);
+        }
+
+        wxASSERT_MSG( colIndices.size() == count, "logic error" );
+
+        m_colIndices = colIndices;
+    }
+
     m_numColumns = count;
-    m_colIndices.resize(count);
 
     Refresh();
 }
@@ -139,7 +162,7 @@ int wxHeaderCtrl::GetColStart(unsigned int idx) const
     int pos = m_scrollOffset;
     for ( unsigned n = 0; n < idx; n++ )
     {
-        const wxHeaderColumnBase& col = self->GetColumn(n);
+        const wxHeaderColumnBase& col = self->GetColumn(m_colIndices[n]);
         if ( col.IsShown() )
             pos += col.GetWidth();
     }
@@ -147,7 +170,7 @@ int wxHeaderCtrl::GetColStart(unsigned int idx) const
     return pos;
 }
 
-int wxHeaderCtrl::FindColumnAtPos(int x, bool& onSeparator) const
+int wxHeaderCtrl::FindColumnAtPoint(int x, bool& onSeparator) const
 {
     wxHeaderCtrl * const self = const_cast<wxHeaderCtrl *>(this);
 
@@ -155,7 +178,7 @@ int wxHeaderCtrl::FindColumnAtPos(int x, bool& onSeparator) const
     const unsigned count = GetColumnCount();
     for ( unsigned n = 0; n < count; n++ )
     {
-        const wxHeaderColumnBase& col = self->GetColumn(n);
+        const wxHeaderColumnBase& col = self->GetColumn(m_colIndices[n]);
         if ( col.IsHidden() )
             continue;
 
@@ -175,7 +198,7 @@ int wxHeaderCtrl::FindColumnAtPos(int x, bool& onSeparator) const
         if ( x < pos )
         {
             onSeparator = false;
-            return n;
+            return GetColumnAt(n);
         }
     }
 
@@ -367,7 +390,7 @@ void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
     int xpos = 0;
     for ( unsigned int i = 0; i < count; i++ )
     {
-        const wxHeaderColumnBase& col = GetColumn(i);
+        const wxHeaderColumnBase& col = GetColumn(m_colIndices[i]);
         if ( col.IsHidden() )
             continue;
 
@@ -461,7 +484,7 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent)
     bool onSeparator;
     const unsigned col = mevent.Leaving()
                             ? (onSeparator = false, COL_NONE)
-                            : FindColumnAtPos(xLogical, onSeparator);
+                            : FindColumnAtPoint(xLogical, onSeparator);
 
 
     // update the highlighted column if it changed