X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dcb6cbecc890c65e15ade46ca416b4c353bb7e8f..3e23102435cb5c97a71548232ae37978a6755e8d:/src/common/headerctrlcmn.cpp diff --git a/src/common/headerctrlcmn.cpp b/src/common/headerctrlcmn.cpp index 2cc69b4566..66548a1ff9 100644 --- a/src/common/headerctrlcmn.cpp +++ b/src/common/headerctrlcmn.cpp @@ -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; }