]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/headerctrlcmn.cpp
don't assert at startup because of the static initialization of a wxLocale object...
[wxWidgets.git] / src / common / headerctrlcmn.cpp
index 2cc69b4566a2ba7f6e1f14a43ab00994d0b990e6..66548a1ff998e490fea32b76b0a0d7a07bde3ce1 100644 (file)
@@ -64,6 +64,13 @@ void wxHeaderCtrlBase::ScrollWindow(int dx,
     DoScrollHorz(dx);
 }
 
+void wxHeaderCtrlBase::SetColumnCount(unsigned int count)
+{
+    OnColumnCountChanging(count);
+
+    DoSetCount(count);
+}
+
 // ----------------------------------------------------------------------------
 // wxHeaderCtrlBase event handling
 // ----------------------------------------------------------------------------
@@ -73,7 +80,7 @@ void wxHeaderCtrlBase::OnSeparatorDClick(wxHeaderCtrlEvent& event)
     const unsigned col = event.GetColumn();
 
     int w = wxWindowBase::GetTextExtent(GetColumn(col).GetTitle()).x;
-    w += 2*GetCharWidth(); // add some arbitrary margins around text
+    w += 4*GetCharWidth(); // add some arbitrary margins around text
 
     if ( !UpdateColumnWidthToFit(col, w) )
         event.Skip();
@@ -140,6 +147,38 @@ unsigned int wxHeaderCtrlBase::GetColumnPos(unsigned int idx) const
     return wxNO_COLUMN;
 }
 
+/* static */
+void wxHeaderCtrlBase::MoveColumnInOrderArray(wxArrayInt& order,
+                                              unsigned int idx,
+                                              unsigned int pos)
+{
+    const unsigned count = order.size();
+
+    wxArrayInt orderNew;
+    orderNew.reserve(count);
+    for ( unsigned n = 0; ; n++ )
+    {
+        // NB: order of checks is important for this to work when the new
+        //     column position is the same as the old one
+
+        // insert the column at its new position
+        if ( orderNew.size() == pos )
+            orderNew.push_back(idx);
+
+        if ( n == count )
+            break;
+
+        // delete the column from its old position
+        const unsigned idxOld = order[n];
+        if ( idxOld == idx )
+            continue;
+
+        orderNew.push_back(idxOld);
+    }
+
+    order.swap(orderNew);
+}
+
 // ============================================================================
 // wxHeaderCtrlSimple implementation
 // ============================================================================
@@ -220,7 +259,6 @@ wxHeaderCtrlSimple::UpdateColumnWidthToFit(unsigned int idx, int widthTitle)
         return false;
 
     m_cols[idx].SetWidth(wxMax(widthContents, widthTitle));
-    UpdateColumn(idx);
 
     return true;
 }