From b02fbafb9608f6362256ac034cd5b7e6f6fbeb01 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 19 Jan 2020 03:28:13 +0100 Subject: [PATCH] Don't update wxDataViewColumn after it was resized interactively Previously, the column was updated, i.e. wxHeaderCtrl::UpdateColumn() was called, after the column width was changed interactively by the user. This was unnecessary and actually harmful as it resulted in recursion and display corruption. Stop doing this by adding yet another width-related function to the generic wxDataViewColumn called WXOnResize(), which just updates the main window display, but doesn't update the header at all, and calling it instead of SetWidth(), which does both, when the column is resized. Closes #18245. --- include/wx/generic/dataview.h | 10 +++++++++- src/generic/datavgen.cpp | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index d250d5bec6..a96e53db6b 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -150,6 +150,10 @@ public: UpdateWidth(); } + // This method is also internal and called when the column is resized by + // user interactively. + void WXOnResize(int width); + int WXGetManuallySetWidth() const { return m_manuallySetWidth; } private: @@ -331,7 +335,11 @@ public: // utility functions not part of the API // update the display after a change to an individual column void OnColumnChange(unsigned int idx); - // update after the column width changes, also calls OnColumnChange() + // update after the column width changes due to interactive resizing + void OnColumnResized(); + + // update after the column width changes because of e.g. title or bitmap + // change, invalidates the column best width and calls OnColumnChange() void OnColumnWidthChange(unsigned int idx); // update after a change to the number of columns diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 1ce4bb53ae..042f7216eb 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -204,6 +204,14 @@ int wxDataViewColumn::GetWidth() const } } +void wxDataViewColumn::WXOnResize(int width) +{ + m_width = + m_manuallySetWidth = width; + + m_owner->OnColumnResized(); +} + void wxDataViewColumn::UpdateDisplay() { if (m_owner) @@ -401,7 +409,7 @@ private: wxDataViewCtrl * const owner = GetOwner(); const unsigned col = event.GetColumn(); - owner->GetColumn(col)->SetWidth(event.GetWidth()); + owner->GetColumn(col)->WXOnResize(event.GetWidth()); } void OnEndReorder(wxHeaderCtrlEvent& event) @@ -5454,6 +5462,11 @@ bool wxDataViewCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col ) return true; } +void wxDataViewCtrl::OnColumnResized() +{ + m_clientArea->UpdateDisplay(); +} + void wxDataViewCtrl::OnColumnWidthChange(unsigned int idx) { InvalidateColBestWidth(idx);