properly implement Do[GS]etColumnsOrder() in the generic wxHeaderCtrl

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57236 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-12-10 16:24:08 +00:00
parent 7dfb6dc4a9
commit 74d283aac4
2 changed files with 31 additions and 8 deletions

View File

@@ -89,7 +89,7 @@ private:
// position is near the divider at the right end of this column (notice // 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 // 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) // 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 // return true if a drag resizing operation is currently in progress
bool IsResizing() const; bool IsResizing() const;

View File

@@ -90,8 +90,31 @@ wxHeaderCtrl::~wxHeaderCtrl()
void wxHeaderCtrl::DoSetCount(unsigned int count) 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_numColumns = count;
m_colIndices.resize(count);
Refresh(); Refresh();
} }
@@ -139,7 +162,7 @@ int wxHeaderCtrl::GetColStart(unsigned int idx) const
int pos = m_scrollOffset; int pos = m_scrollOffset;
for ( unsigned n = 0; n < idx; n++ ) for ( unsigned n = 0; n < idx; n++ )
{ {
const wxHeaderColumnBase& col = self->GetColumn(n); const wxHeaderColumnBase& col = self->GetColumn(m_colIndices[n]);
if ( col.IsShown() ) if ( col.IsShown() )
pos += col.GetWidth(); pos += col.GetWidth();
} }
@@ -147,7 +170,7 @@ int wxHeaderCtrl::GetColStart(unsigned int idx) const
return pos; 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); wxHeaderCtrl * const self = const_cast<wxHeaderCtrl *>(this);
@@ -155,7 +178,7 @@ int wxHeaderCtrl::FindColumnAtPos(int x, bool& onSeparator) const
const unsigned count = GetColumnCount(); const unsigned count = GetColumnCount();
for ( unsigned n = 0; n < count; n++ ) for ( unsigned n = 0; n < count; n++ )
{ {
const wxHeaderColumnBase& col = self->GetColumn(n); const wxHeaderColumnBase& col = self->GetColumn(m_colIndices[n]);
if ( col.IsHidden() ) if ( col.IsHidden() )
continue; continue;
@@ -175,7 +198,7 @@ int wxHeaderCtrl::FindColumnAtPos(int x, bool& onSeparator) const
if ( x < pos ) if ( x < pos )
{ {
onSeparator = false; onSeparator = false;
return n; return GetColumnAt(n);
} }
} }
@@ -367,7 +390,7 @@ void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
int xpos = 0; int xpos = 0;
for ( unsigned int i = 0; i < count; i++ ) for ( unsigned int i = 0; i < count; i++ )
{ {
const wxHeaderColumnBase& col = GetColumn(i); const wxHeaderColumnBase& col = GetColumn(m_colIndices[i]);
if ( col.IsHidden() ) if ( col.IsHidden() )
continue; continue;
@@ -461,7 +484,7 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent)
bool onSeparator; bool onSeparator;
const unsigned col = mevent.Leaving() const unsigned col = mevent.Leaving()
? (onSeparator = false, COL_NONE) ? (onSeparator = false, COL_NONE)
: FindColumnAtPos(xLogical, onSeparator); : FindColumnAtPoint(xLogical, onSeparator);
// update the highlighted column if it changed // update the highlighted column if it changed