// position is near the divider at the right end of this column (notice
// that this means that we return column 0 even if the position is over
// column 1 but close enough to the divider separating it from column 0)
- int FindColumnAtPos(int x, bool& onSeparator) const;
+ int FindColumnAtPoint(int x, bool& onSeparator) const;
// return true if a drag resizing operation is currently in progress
bool IsResizing() const;
void wxHeaderCtrl::DoSetCount(unsigned int count)
{
+ // update the column indices array if necessary
+ if ( count > m_numColumns )
+ {
+ // 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;
+ }
+
m_numColumns = count;
- m_colIndices.resize(count);
Refresh();
}
int pos = m_scrollOffset;
for ( unsigned n = 0; n < idx; n++ )
{
- const wxHeaderColumnBase& col = self->GetColumn(n);
+ const wxHeaderColumnBase& col = self->GetColumn(m_colIndices[n]);
if ( col.IsShown() )
pos += col.GetWidth();
}
return pos;
}
-int wxHeaderCtrl::FindColumnAtPos(int x, bool& onSeparator) const
+int wxHeaderCtrl::FindColumnAtPoint(int x, bool& onSeparator) const
{
wxHeaderCtrl * const self = const_cast<wxHeaderCtrl *>(this);
const unsigned count = GetColumnCount();
for ( unsigned n = 0; n < count; n++ )
{
- const wxHeaderColumnBase& col = self->GetColumn(n);
+ const wxHeaderColumnBase& col = self->GetColumn(m_colIndices[n]);
if ( col.IsHidden() )
continue;
if ( x < pos )
{
onSeparator = false;
- return n;
+ return GetColumnAt(n);
}
}
int xpos = 0;
for ( unsigned int i = 0; i < count; i++ )
{
- const wxHeaderColumnBase& col = GetColumn(i);
+ const wxHeaderColumnBase& col = GetColumn(m_colIndices[i]);
if ( col.IsHidden() )
continue;
bool onSeparator;
const unsigned col = mevent.Leaving()
? (onSeparator = false, COL_NONE)
- : FindColumnAtPos(xLogical, onSeparator);
+ : FindColumnAtPoint(xLogical, onSeparator);
// update the highlighted column if it changed