From: Vadim Zeitlin Date: Wed, 10 Dec 2008 16:24:08 +0000 (+0000) Subject: properly implement Do[GS]etColumnsOrder() in the generic wxHeaderCtrl X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/74d283aac44903607326730427b4bbf66dc83a06 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 --- diff --git a/include/wx/generic/headerctrlg.h b/include/wx/generic/headerctrlg.h index dd943a8deb..489dad5acc 100644 --- a/include/wx/generic/headerctrlg.h +++ b/include/wx/generic/headerctrlg.h @@ -89,7 +89,7 @@ private: // 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; diff --git a/src/generic/headerctrlg.cpp b/src/generic/headerctrlg.cpp index 6b9c1a399b..6ed2e6caa8 100644 --- a/src/generic/headerctrlg.cpp +++ b/src/generic/headerctrlg.cpp @@ -90,8 +90,31 @@ wxHeaderCtrl::~wxHeaderCtrl() 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(); } @@ -139,7 +162,7 @@ int wxHeaderCtrl::GetColStart(unsigned int idx) const 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(); } @@ -147,7 +170,7 @@ int wxHeaderCtrl::GetColStart(unsigned int idx) const return pos; } -int wxHeaderCtrl::FindColumnAtPos(int x, bool& onSeparator) const +int wxHeaderCtrl::FindColumnAtPoint(int x, bool& onSeparator) const { wxHeaderCtrl * const self = const_cast(this); @@ -155,7 +178,7 @@ int wxHeaderCtrl::FindColumnAtPos(int x, bool& onSeparator) const 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; @@ -175,7 +198,7 @@ int wxHeaderCtrl::FindColumnAtPos(int x, bool& onSeparator) const if ( x < pos ) { onSeparator = false; - return n; + return GetColumnAt(n); } } @@ -367,7 +390,7 @@ void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) 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; @@ -461,7 +484,7 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent) bool onSeparator; const unsigned col = mevent.Leaving() ? (onSeparator = false, COL_NONE) - : FindColumnAtPos(xLogical, onSeparator); + : FindColumnAtPoint(xLogical, onSeparator); // update the highlighted column if it changed