From 01d0deb5bfd576f81f048c4233191ecd9a573fdd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Jan 2020 16:15:13 +0100 Subject: [PATCH 1/3] Get rid of unnecessary variable in wxListCtrl::SetColumnWidth() No real changes, just remove a variable assigned and used exactly once. --- src/generic/listctrl.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index e4ce5b2672..b8acd1b983 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -3279,8 +3279,6 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) wxListHeaderData *column = node->GetData(); - size_t count = GetItemCount(); - if ( width == wxLIST_AUTOSIZE_USEHEADER || width == wxLIST_AUTOSIZE ) { wxListCtrlMaxWidthCalculator calculator(this, col); @@ -3297,7 +3295,8 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) size_t first_visible, last_visible; GetVisibleLinesRange(&first_visible, &last_visible); - calculator.ComputeBestColumnWidth(count, first_visible, last_visible); + calculator.ComputeBestColumnWidth(GetItemCount(), + first_visible, last_visible); pWidthInfo->nMaxWidth = calculator.GetMaxWidth(); pWidthInfo->bNeedsUpdate = false; } From 101487730262180a20f0b05c32a81a66535aef8a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Jan 2020 16:18:41 +0100 Subject: [PATCH 2/3] Slightly reorganize last column width calculation No real changes, just make it more obvious that we increase the last column width to the remaining margin if it's smaller than it. --- src/generic/listctrl.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index b8acd1b983..8056238d6d 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -3305,17 +3305,19 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) calculator.UpdateWithWidth(pWidthInfo->nMaxWidth); } + width = calculator.GetMaxWidth() + AUTOSIZE_COL_MARGIN; + // expand the last column to fit the client size // only for AUTOSIZE_USEHEADER to mimic MSW behaviour - int margin = 0; if ( (width == wxLIST_AUTOSIZE_USEHEADER) && (col == GetColumnCount() - 1) ) { - margin = GetClientSize().GetX(); + int margin = GetClientSize().GetX(); for ( int i = 0; i < col && margin > 0; ++i ) margin -= m_columns.Item(i)->GetData()->GetWidth(); - } - width = wxMax(margin, calculator.GetMaxWidth() + AUTOSIZE_COL_MARGIN); + if ( margin > width ) + width = margin; + } } column->SetWidth( width ); From e1fce68be6ae17e0164b2df07c79302f2b8853e6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Jan 2020 16:22:49 +0100 Subject: [PATCH 3/3] Account for checkboxes when autosizing wxListCtrl first column Without this, the text of the first column was truncated when using checkboxes. Closes #18661. --- src/generic/listctrl.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 8056238d6d..141531cc75 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -3307,6 +3307,13 @@ void wxListMainWindow::SetColumnWidth( int col, int width ) width = calculator.GetMaxWidth() + AUTOSIZE_COL_MARGIN; + if ( col == 0 && HasCheckBoxes() ) + { + // also account for the space needed by the checkbox + width += wxRendererNative::Get().GetCheckBoxSize(this).x + + 2*MARGIN_AROUND_CHECKBOX; + } + // expand the last column to fit the client size // only for AUTOSIZE_USEHEADER to mimic MSW behaviour if ( (width == wxLIST_AUTOSIZE_USEHEADER) && (col == GetColumnCount() - 1) )