From a871229f8be965ed2c66cfc9002e327b932dea45 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 15 Jul 2019 15:13:42 +0200 Subject: [PATCH] Refactor wxGrid code to use SetNativeHeaderColXXX() functions Add two simple helpers: SetNativeHeaderColCount() and SetNativeHeaderColOrder() and call the latter from the former to ensure that the columns order is always correct when switching to the native control. --- include/wx/generic/grid.h | 6 ++++++ src/generic/grid.cpp | 29 +++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index ca5db2a18c..94f8c09679 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -2382,6 +2382,12 @@ private: void DoSetRowSize( int row, int height ); void DoSetColSize( int col, int width ); + // These methods can only be called when m_useNativeHeader is true and call + // SetColumnCount() and Set- or ResetColumnsOrder() as necessary on the + // native wxHeaderCtrl being used. Note that the first one already calls + // the second one, so it's never necessary to call both of them. + void SetNativeHeaderColCount(); + void SetNativeHeaderColOrder(); // these sets contain the indices of fixed, i.e. non-resizable // interactively, grid rows or columns and are NULL if there are no fixed diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index fcce59670d..a5ef612367 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -2438,7 +2438,7 @@ wxGrid::SetTable(wxGridTableBase *table, // Notice that this must be called after setting m_table as it uses it // indirectly, via wxGrid::GetColLabelValue(). if ( m_useNativeHeader ) - GetGridColHeader()->SetColumnCount(m_numCols); + SetNativeHeaderColCount(); m_selection = new wxGridSelection( this, selmode ); if (checkSelection) @@ -4569,10 +4569,7 @@ void wxGrid::RefreshAfterColPosChange() // and make the changes visible if ( m_useNativeHeader ) { - if ( m_colAt.empty() ) - GetGridColHeader()->ResetColumnsOrder(); - else - GetGridColHeader()->SetColumnsOrder(m_colAt); + SetNativeHeaderColOrder(); } else { @@ -5950,7 +5947,8 @@ void wxGrid::UseNativeColHeader(bool native) CreateColumnWindow(); if ( m_useNativeHeader ) - GetGridColHeader()->SetColumnCount(m_numCols); + SetNativeHeaderColCount(); + CalcWindowSizes(); } @@ -8494,6 +8492,25 @@ int wxGrid::GetRowMinimalAcceptableHeight() const return m_minAcceptableRowHeight; } +void wxGrid::SetNativeHeaderColCount() +{ + wxASSERT_MSG( m_useNativeHeader, "no column header window" ); + + GetGridColHeader()->SetColumnCount(m_numCols); + + SetNativeHeaderColOrder(); +} + +void wxGrid::SetNativeHeaderColOrder() +{ + wxASSERT_MSG( m_useNativeHeader, "no column header window" ); + + if ( !m_colAt.empty() ) + GetGridColHeader()->SetColumnsOrder(m_colAt); + else + GetGridColHeader()->ResetColumnsOrder(); +} + // ---------------------------------------------------------------------------- // auto sizing // ----------------------------------------------------------------------------