no changes, just refactoring: extracted the code to update the column indices array when the number of columns changes to the common code to be able to reuse it from the MSW version
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57340 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -140,6 +140,11 @@ protected:
|
|||||||
// columns in the control changes
|
// columns in the control changes
|
||||||
virtual void OnColumnCountChanging(unsigned int WXUNUSED(count)) { }
|
virtual void OnColumnCountChanging(unsigned int WXUNUSED(count)) { }
|
||||||
|
|
||||||
|
|
||||||
|
// helper function for the derived classes: update the array of column
|
||||||
|
// indices after the number of columns changed
|
||||||
|
void DoResizeColumnIndices(wxArrayInt& colIndices, unsigned int count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// methods implementing our public API and defined in platform-specific
|
// methods implementing our public API and defined in platform-specific
|
||||||
// implementations
|
// implementations
|
||||||
|
@@ -66,6 +66,9 @@ void wxHeaderCtrlBase::ScrollWindow(int dx,
|
|||||||
|
|
||||||
void wxHeaderCtrlBase::SetColumnCount(unsigned int count)
|
void wxHeaderCtrlBase::SetColumnCount(unsigned int count)
|
||||||
{
|
{
|
||||||
|
if ( count == GetColumnCount() )
|
||||||
|
return;
|
||||||
|
|
||||||
OnColumnCountChanging(count);
|
OnColumnCountChanging(count);
|
||||||
|
|
||||||
DoSetCount(count);
|
DoSetCount(count);
|
||||||
@@ -189,6 +192,40 @@ void wxHeaderCtrlBase::MoveColumnInOrderArray(wxArrayInt& order,
|
|||||||
order.swap(orderNew);
|
order.swap(orderNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wxHeaderCtrlBase::DoResizeColumnIndices(wxArrayInt& colIndices, unsigned int count)
|
||||||
|
{
|
||||||
|
// update the column indices array if necessary
|
||||||
|
const unsigned countOld = colIndices.size();
|
||||||
|
if ( count > countOld )
|
||||||
|
{
|
||||||
|
// all new columns have default positions equal to their indices
|
||||||
|
for ( unsigned n = countOld; n < count; n++ )
|
||||||
|
colIndices.push_back(n);
|
||||||
|
}
|
||||||
|
else if ( count < countOld )
|
||||||
|
{
|
||||||
|
// filter out all the positions which are invalid now while keeping the
|
||||||
|
// order of the remaining ones
|
||||||
|
wxArrayInt colIndicesNew;
|
||||||
|
colIndicesNew.reserve(count);
|
||||||
|
for ( unsigned n = 0; n < countOld; n++ )
|
||||||
|
{
|
||||||
|
const unsigned idx = colIndices[n];
|
||||||
|
if ( idx < count )
|
||||||
|
colIndicesNew.push_back(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
colIndices.swap(colIndicesNew);
|
||||||
|
}
|
||||||
|
else // count didn't really change, we shouldn't even be called
|
||||||
|
{
|
||||||
|
wxFAIL_MSG( "useless call to DoResizeColumnIndices()" );
|
||||||
|
}
|
||||||
|
|
||||||
|
wxASSERT_MSG( colIndices.size() == count, "logic error" );
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxHeaderCtrlSimple implementation
|
// wxHeaderCtrlSimple implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@@ -92,33 +92,8 @@ wxHeaderCtrl::~wxHeaderCtrl()
|
|||||||
|
|
||||||
void wxHeaderCtrl::DoSetCount(unsigned int count)
|
void wxHeaderCtrl::DoSetCount(unsigned int count)
|
||||||
{
|
{
|
||||||
// update the column indices array if necessary
|
// update the column indices order array before changing m_numColumns
|
||||||
if ( count > m_numColumns )
|
DoResizeColumnIndices(m_colIndices, count);
|
||||||
{
|
|
||||||
// all new columns have default positions equal to their indices
|
|
||||||
for ( unsigned n = m_numColumns; n < count; n++ )
|
|
||||||
m_colIndices.push_back(n);
|
|
||||||
}
|
|
||||||
else if ( count < m_numColumns )
|
|
||||||
{
|
|
||||||
// filter out all the positions which are invalid now while keeping the
|
|
||||||
// order of the remaining ones
|
|
||||||
wxArrayInt colIndices;
|
|
||||||
for ( unsigned n = 0; n < m_numColumns; n++ )
|
|
||||||
{
|
|
||||||
const unsigned idx = m_colIndices[n];
|
|
||||||
if ( idx < count )
|
|
||||||
colIndices.push_back(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxASSERT_MSG( colIndices.size() == count, "logic error" );
|
|
||||||
|
|
||||||
m_colIndices = colIndices;
|
|
||||||
}
|
|
||||||
else // count didn't really change
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_numColumns = count;
|
m_numColumns = count;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user