forward SetColPos() to the header window

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57263 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-12-11 22:16:38 +00:00
parent 38cd07c431
commit 3169a8e837

View File

@@ -6779,42 +6779,41 @@ void wxGrid::DoEndDragMoveCol()
SetColPos( m_dragRowOrCol, newPos ); SetColPos( m_dragRowOrCol, newPos );
} }
void wxGrid::SetColPos( int colID, int newPos ) void wxGrid::SetColPos(int idx, int pos)
{ {
if ( m_colAt.IsEmpty() ) if ( m_colAt.empty() )
{ {
m_colAt.Alloc( m_numCols ); // we're going to need m_colAt now, initialize it
m_colAt.reserve(m_numCols);
int i; for ( int i = 0; i < m_numCols; i++ )
for ( i = 0; i < m_numCols; i++ ) m_colAt.push_back(i);
{
m_colAt.Add( i );
}
} }
int oldPos = GetColPos( colID ); // create the updated copy of m_colAt
const unsigned count = m_colAt.size();
//Reshuffle the m_colAt array wxArrayInt colAt;
if ( newPos > oldPos ) colAt.reserve(count);
for ( unsigned n = 0; n < count; n++ )
{ {
int i; // NB: order of checks is important for this to work when the new
for ( i = oldPos; i < newPos; i++ ) // column position is the same as the old one
{
m_colAt[i] = m_colAt[i+1]; // insert the column at its new position
} if ( colAt.size() == static_cast<unsigned>(pos) )
} colAt.push_back(idx);
else
{ // delete the column from its old position
int i; const int idxOld = m_colAt[n];
for ( i = oldPos; i > newPos; i-- ) if ( idxOld == idx )
{ continue;
m_colAt[i] = m_colAt[i-1];
} colAt.push_back(idxOld);
} }
m_colAt[newPos] = colID; m_colAt = colAt;
//Recalculate the column rights // also recalculate the column rights
if ( !m_colWidths.IsEmpty() ) if ( !m_colWidths.IsEmpty() )
{ {
int colRight = 0; int colRight = 0;
@@ -6828,6 +6827,10 @@ void wxGrid::SetColPos( int colID, int newPos )
} }
} }
// and make the changes visible
if ( m_useNativeHeader )
GetColHeader()->SetColumnsOrder(m_colAt);
else
m_colWindow->Refresh(); m_colWindow->Refresh();
m_gridWin->Refresh(); m_gridWin->Refresh();
} }