X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/040b9528d149c2bb2497d47d9175635c03baffe2..595cf498a5f328907b8e446c0bdd040b7f22942b:/src/msw/headerctrl.cpp?ds=sidebyside diff --git a/src/msw/headerctrl.cpp b/src/msw/headerctrl.cpp index ef512e0e74..21d83f6388 100644 --- a/src/msw/headerctrl.cpp +++ b/src/msw/headerctrl.cpp @@ -23,6 +23,8 @@ #pragma hdrstop #endif +#if wxUSE_HEADERCTRL + #ifndef WX_PRECOMP #include "wx/log.h" #endif // WX_PRECOMP @@ -78,7 +80,7 @@ WXDWORD wxHeaderCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const { WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); - if ( style & wxHD_DRAGDROP ) + if ( style & wxHD_ALLOW_REORDER ) msStyle |= HDS_DRAGDROP; // the control looks nicer with these styles and there doesn't seem to be @@ -319,7 +321,7 @@ void wxHeaderCtrl::DoInsertItem(const wxHeaderColumn& col, unsigned int idx) } hdi.mask |= HDI_ORDER; - hdi.iOrder = m_colIndices.Index(idx); + hdi.iOrder = MSWToNativeOrder(m_colIndices.Index(idx)); if ( ::SendMessage(GetHwnd(), HDM_INSERTITEM, MSWToNativeIdx(idx), (LPARAM)&hdi) == -1 ) @@ -356,6 +358,10 @@ wxArrayInt wxHeaderCtrl::DoGetColumnsOrder() const return m_colIndices; } +// ---------------------------------------------------------------------------- +// wxHeaderCtrl indexes and positions translation +// ---------------------------------------------------------------------------- + int wxHeaderCtrl::MSWToNativeIdx(int idx) { // don't check for GetColumn(idx).IsShown() as it could have just became @@ -364,13 +370,16 @@ int wxHeaderCtrl::MSWToNativeIdx(int idx) "column must be visible to have an " "index in the native control" ); + int item = idx; for ( int i = 0; i < idx; i++ ) { if ( GetColumn(i).IsHidden() ) - idx--; // one less column the native control knows about + item--; // one less column the native control knows about } - return idx; + wxASSERT_MSG( item >= 0 && item <= GetShownColumnsCount(), "logic error" ); + + return item; } int wxHeaderCtrl::MSWFromNativeIdx(int item) @@ -379,37 +388,59 @@ int wxHeaderCtrl::MSWFromNativeIdx(int item) "column index out of range" ); // reverse the above function - for ( int i = 0; i <= item; i++ ) + + unsigned idx = item; + for ( unsigned n = 0; n < m_numColumns; n++ ) { - if ( GetColumn(i).IsHidden() ) - item++; + if ( n > idx ) + break; + + if ( GetColumn(n).IsHidden() ) + idx++; } - return item; + wxASSERT_MSG( MSWToNativeIdx(idx) == item, "logic error" ); + + return idx; } -int wxHeaderCtrl::MSWFromNativeOrder(int order) +int wxHeaderCtrl::MSWToNativeOrder(int pos) { - wxASSERT_MSG( order >= 0 && order < GetShownColumnsCount(), + wxASSERT_MSG( pos >= 0 && static_cast(pos) < m_numColumns, "column position out of range" ); - // notice that the loop condition is inclusive because if the column - // exactly at position order is hidden we should go to the next one - for ( int pos = 0; pos <= order; pos++ ) + int order = pos; + for ( int n = 0; n < pos; n++ ) { - if ( GetColumn(m_colIndices[pos]).IsHidden() ) - { - // order can't become greater than m_numColumns here because it is - // less than the number of shown columns initially and it is going - // to be incremented at most once for every hidden column and - // m_numColumns is the total columns number - order++; - } + if ( GetColumn(m_colIndices[n]).IsHidden() ) + order--; } + wxASSERT_MSG( order >= 0 && order <= GetShownColumnsCount(), "logic error" ); + return order; } +int wxHeaderCtrl::MSWFromNativeOrder(int order) +{ + wxASSERT_MSG( order >= 0 && order < GetShownColumnsCount(), + "native column position out of range" ); + + unsigned pos = order; + for ( unsigned n = 0; n < m_numColumns; n++ ) + { + if ( n > pos ) + break; + + if ( GetColumn(m_colIndices[n]).IsHidden() ) + pos++; + } + + wxASSERT_MSG( MSWToNativeOrder(pos) == order, "logic error" ); + + return pos; +} + // ---------------------------------------------------------------------------- // wxHeaderCtrl events // ---------------------------------------------------------------------------- @@ -631,3 +662,5 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) } #endif // wxHAS_GENERIC_HEADERCTRL + +#endif // wxUSE_HEADERCTRL