git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57343
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
int MSWFromNativeIdx(int item);
// this is the same as above but for order, not index
int MSWFromNativeIdx(int item);
// this is the same as above but for order, not index
+ int MSWToNativeOrder(int order);
int MSWFromNativeOrder(int order);
// get the event type corresponding to a click or double click event
int MSWFromNativeOrder(int order);
// get the event type corresponding to a click or double click event
- hdi.iOrder = m_colIndices.Index(idx);
+ hdi.iOrder = MSWToNativeOrder(m_colIndices.Index(idx));
if ( ::SendMessage(GetHwnd(), HDM_INSERTITEM,
MSWToNativeIdx(idx), (LPARAM)&hdi) == -1 )
if ( ::SendMessage(GetHwnd(), HDM_INSERTITEM,
MSWToNativeIdx(idx), (LPARAM)&hdi) == -1 )
+// ----------------------------------------------------------------------------
+// wxHeaderCtrl indexes and positions translation
+// ----------------------------------------------------------------------------
+
int wxHeaderCtrl::MSWToNativeIdx(int idx)
{
// don't check for GetColumn(idx).IsShown() as it could have just became
int wxHeaderCtrl::MSWToNativeIdx(int idx)
{
// don't check for GetColumn(idx).IsShown() as it could have just became
"column must be visible to have an "
"index in the native control" );
"column must be visible to have an "
"index in the native control" );
for ( int i = 0; i < idx; i++ )
{
if ( GetColumn(i).IsHidden() )
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
+ wxASSERT_MSG( item >= 0 && item <= GetShownColumnsCount(), "logic error" );
+
+ return item;
}
int wxHeaderCtrl::MSWFromNativeIdx(int item)
}
int wxHeaderCtrl::MSWFromNativeIdx(int item)
"column index out of range" );
// reverse the above function
"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++;
+ 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<unsigned>(pos) < m_numColumns,
"column position out of range" );
"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" );
+
+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
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxHeaderCtrl events
// ----------------------------------------------------------------------------