diff --git a/include/wx/generic/headerctrlg.h b/include/wx/generic/headerctrlg.h index 6ffd301625..6b7f3e410d 100644 --- a/include/wx/generic/headerctrlg.h +++ b/include/wx/generic/headerctrlg.h @@ -49,11 +49,10 @@ public: private: // implement base class pure virtuals + virtual void DoSetCount(unsigned int count); virtual unsigned int DoGetCount() const; - virtual void DoInsert(const wxHeaderColumn& col, unsigned int idx); - virtual void DoDelete(unsigned int idx); - virtual void DoShowColumn(unsigned int idx, bool show); - virtual void DoShowSortIndicator(unsigned int idx, int sortOrder); + virtual void DoUpdate(unsigned int idx); + virtual void DoScrollHorz(int dx); // override wxWindow methods which must be implemented by a new control @@ -75,6 +74,9 @@ private: // refresh all the controls starting from (and including) the given one void RefreshColsAfter(unsigned int idx); + // number of columns in the control currently + unsigned int m_numColumns; + // index of the column under mouse or -1 if none unsigned int m_hover; diff --git a/src/generic/headerctrlg.cpp b/src/generic/headerctrlg.cpp index bc0880a990..f55b7e1f6f 100644 --- a/src/generic/headerctrlg.cpp +++ b/src/generic/headerctrlg.cpp @@ -56,6 +56,7 @@ const unsigned COL_NONE = (unsigned)-1; void wxHeaderCtrl::Init() { + m_numColumns = 0; m_hover = COL_NONE; m_scrollOffset = 0; } @@ -86,9 +87,24 @@ wxHeaderCtrl::~wxHeaderCtrl() // wxHeaderCtrl columns manipulation // ---------------------------------------------------------------------------- +void wxHeaderCtrl::DoSetCount(unsigned int count) +{ + m_numColumns = count; + + Refresh(); +} + unsigned int wxHeaderCtrl::DoGetCount() const { - return m_cols.size(); + return m_numColumns; +} + +void wxHeaderCtrl::DoUpdate(unsigned int idx) +{ + // we need to refresh not only this column but also the ones after it in + // case it was shown or hidden or its width changed -- it would be nice to + // avoid doing this unnecessary by storing the old column width (TODO) + RefreshColsAfter(idx); } // ---------------------------------------------------------------------------- @@ -116,10 +132,12 @@ wxSize wxHeaderCtrl::DoGetBestSize() const int wxHeaderCtrl::GetColStart(unsigned int idx) const { + wxHeaderCtrl * const self = const_cast(this); + int pos = 0; for ( unsigned n = 0; n < idx; n++ ) { - const wxHeaderColumn& col = m_cols[n]; + const wxHeaderColumnBase& col = self->GetColumn(n); if ( col.IsShown() ) pos += col.GetWidth(); } @@ -135,7 +153,7 @@ void wxHeaderCtrl::RefreshCol(unsigned int idx) { wxRect rect = GetClientRect(); rect.x += GetColStart(idx); - rect.width = m_cols[idx].GetWidth(); + rect.width = GetColumn(idx).GetWidth(); RefreshRect(rect); } @@ -173,34 +191,25 @@ void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) // account for the horizontal scrollbar offset in the parent window dc.SetDeviceOrigin(m_scrollOffset, 0); - const unsigned int count = m_cols.size(); + const unsigned int count = m_numColumns; int xpos = 0; for ( unsigned int i = 0; i < count; i++ ) { - const wxHeaderColumn& col = m_cols[i]; + const wxHeaderColumnBase& col = GetColumn(i); if ( col.IsHidden() ) continue; const int colWidth = col.GetWidth(); wxHeaderSortIconType sortArrow; - switch ( m_sortOrders[i] ) + if ( col.IsSortKey() ) { - default: - wxFAIL_MSG( "wrong sort order value" ); - // fall through - - case -1: - sortArrow = wxHDR_SORT_ICON_NONE; - break; - - case 0: - sortArrow = wxHDR_SORT_ICON_DOWN; - break; - - case 1: - sortArrow = wxHDR_SORT_ICON_UP; - break; + sortArrow = col.IsSortOrderAscending() ? wxHDR_SORT_ICON_UP + : wxHDR_SORT_ICON_DOWN; + } + else // not sorting by this column + { + sortArrow = wxHDR_SORT_ICON_NONE; } int state = 0;