From 2340a16d180472b1efc4009a693d7aaf0771f21c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2018 14:27:52 +0100 Subject: [PATCH] Allow increasing the size of the last column in wxDataViewCtrl Previously, the last column couldn't be effectively resized at all, as its size was always automatically set to the remaining width of the window after subtracting the widths of all the previous columns. Now this is only done if this remaining width is greater than the width given to the column by the user or by the program. Effectively, this means that the user can now drag-resize the column to increase its size (at the price of showing the horizontal scrollbar). See #18295. --- include/wx/generic/dataview.h | 12 ++++++++++++ samples/dataview/dataview.cpp | 2 +- src/generic/datavgen.cpp | 16 +++++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 815dfcb75b..bef6ab1f97 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -74,6 +74,11 @@ public: // UpdateWidth() if the width didn't really change, even if we don't // care about its return value. (void)WXUpdateWidth(width); + + // Do remember the last explicitly set width: this is used to prevent + // UpdateColumnSizes() from resizing the last column to be smaller than + // this size. + m_manuallySetWidth = width; } virtual int GetWidth() const wxOVERRIDE; @@ -137,9 +142,15 @@ public: m_width = width; UpdateWidth(); + // We must not update m_manuallySetWidth here as this method is called by + // UpdateColumnSizes() which resizes the column automatically, and not + // "manually". + return true; } + int WXGetManuallySetWidth() const { return m_manuallySetWidth; } + private: // common part of all ctors void Init(int width, wxAlignment align, int flags); @@ -152,6 +163,7 @@ private: wxString m_title; int m_width, + m_manuallySetWidth, m_minWidth; wxAlignment m_align; int m_flags; diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index 51273a6106..9d654828d6 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -793,7 +793,7 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l lc->AppendColumn(colRadio, "bool"); lc->AppendTextColumn( "Text" ); - lc->AppendProgressColumn( "Progress" ); + lc->AppendProgressColumn( "Progress" )->SetMinWidth(100); wxVector data; for (unsigned int i=0; i<10; i++) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index c5aad72db8..80c7c7aa2c 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -180,7 +180,8 @@ wxTextCtrl *CreateEditorTextCtrl(wxWindow *parent, const wxRect& labelRect, cons void wxDataViewColumn::Init(int width, wxAlignment align, int flags) { - m_width = width; + m_width = + m_manuallySetWidth = width; m_minWidth = 0; m_align = align; m_flags = flags; @@ -5022,20 +5023,25 @@ void wxDataViewMainWindow::UpdateColumnSizes() int lastColX = colswidth - lastCol->GetWidth(); if ( lastColX < fullWinWidth ) { - int desiredWidth = wxMax(fullWinWidth - lastColX, lastCol->GetMinWidth()); - if ( !lastCol->WXUpdateWidth(desiredWidth) ) + const int availableWidth = fullWinWidth - lastColX; + + // Never make the column automatically smaller than the last width it + // was explicitly given nor its minimum width. + if ( availableWidth <= wxMax(lastCol->GetMinWidth(), + lastCol->WXGetManuallySetWidth()) ) { - // The column width didn't change, no need to do anything else. return; } + lastCol->WXUpdateWidth(availableWidth); + // All columns fit on screen, so we don't need horizontal scrolling. // To prevent flickering scrollbar when resizing the window to be // narrower, force-set the virtual width to 0 here. It will eventually // be corrected at idle time. SetVirtualSize(0, m_virtualSize.y); - RefreshRect(wxRect(lastColX, 0, fullWinWidth - lastColX, GetSize().y)); + RefreshRect(wxRect(lastColX, 0, availableWidth, GetSize().y)); } else {