From 6af316b537d15b43fd839579a5c48accf7de27e0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 19 Oct 2019 22:02:20 +0200 Subject: [PATCH] Auto size last visible column in generic wxDataViewCtrl Resize the last visible column and not just the last column, which might be hidden, to fill up all the available space. See #18295. --- src/generic/datavgen.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index bca358a7e0..22627a3ea2 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -5070,8 +5070,35 @@ void wxDataViewMainWindow::UpdateColumnSizes() int fullWinWidth = GetSize().x; - wxDataViewColumn *lastCol = owner->GetColumn(colsCount - 1); - int colswidth = GetEndOfLastCol(); + // Find the last shown column: we shouldn't bother to resize the columns + // that are hidden anyhow. + int lastColIndex = -1; + wxDataViewColumn *lastCol wxDUMMY_INITIALIZE(NULL); + for ( int colIndex = colsCount - 1; colIndex >= 0; --colIndex ) + { + lastCol = owner->GetColumnAt(colIndex); + if ( !lastCol->IsHidden() ) + { + lastColIndex = colIndex; + break; + } + } + + if ( lastColIndex == -1 ) + { + // All columns are hidden. + return; + } + + int colswidth = 0; + for ( int colIndex = 0; colIndex < lastColIndex; ++colIndex ) + { + const wxDataViewColumn *c = owner->GetColumnAt(colIndex); + + if ( !c->IsHidden() ) + colswidth += c->GetWidth(); + } + int lastColX = colswidth - lastCol->GetWidth(); if ( lastColX < fullWinWidth ) {