From 7557b8fa49c29d2574041f1f50d96de9d9345103 Mon Sep 17 00:00:00 2001 From: Daniel Kulp Date: Tue, 21 Sep 2021 12:59:21 -0400 Subject: [PATCH 1/4] Don't adjust column sizes when wxDataViewCtrl is frozen in wxOSX Only do it after thawing it. --- include/wx/osx/dataview.h | 2 ++ src/osx/dataview_osx.cpp | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/wx/osx/dataview.h b/include/wx/osx/dataview.h index 457eddbebd..f24ca5c13a 100644 --- a/include/wx/osx/dataview.h +++ b/include/wx/osx/dataview.h @@ -285,6 +285,8 @@ protected: // event handling void OnSize(wxSizeEvent &event); + virtual void DoThaw() wxOVERRIDE; + private: // initializing of local variables: void Init(); diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index def9d099d4..02e0572f5f 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -74,7 +74,7 @@ public: virtual void Resort() wxOVERRIDE; // adjust wxCOL_WIDTH_AUTOSIZE columns to fit the data - void AdjustAutosizedColumns(); + void AdjustAutosizedColumns(bool force = false); protected: // if the dataview control can have a variable row height this method sets the dataview's control row height of @@ -297,8 +297,11 @@ void wxOSXDataViewModelNotifier::AdjustRowHeights(wxDataViewItemArray const& ite } } -void wxOSXDataViewModelNotifier::AdjustAutosizedColumns() +void wxOSXDataViewModelNotifier::AdjustAutosizedColumns(bool forced) { + if (m_DataViewCtrlPtr->IsFrozen() && !forced) + return; + unsigned count = m_DataViewCtrlPtr->GetColumnCount(); for ( unsigned col = 0; col < count; col++ ) { @@ -699,10 +702,20 @@ void wxDataViewCtrl::FinishCustomItemEditing() void wxDataViewCtrl::AdjustAutosizedColumns() const { - if ( m_ModelNotifier ) + if ( m_ModelNotifier && !IsFrozen() ) m_ModelNotifier->AdjustAutosizedColumns(); } +void wxDataViewCtrl::DoThaw() +{ + if ( m_ModelNotifier ) + { + // On thaw, we want to force the updating of the colum sizes + m_ModelNotifier->AdjustAutosizedColumns(true); + } + wxDataViewCtrlBase::DoThaw(); +} + /*static*/ wxVisualAttributes wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) From 8cc7d6d993680d35a0cdef756779e6cbfe99d8bd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 9 Dec 2021 23:19:33 +0100 Subject: [PATCH 2/4] Remove unnecessary test for IsFrozen() wxOSXDataViewModelNotifier::AdjustAutosizedColumns() does nothing if the control is frozen, so there is no need to test for it before calling it and this just made this call inconsistent with all the other ones. --- src/osx/dataview_osx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index 02e0572f5f..2cea873e54 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -702,7 +702,7 @@ void wxDataViewCtrl::FinishCustomItemEditing() void wxDataViewCtrl::AdjustAutosizedColumns() const { - if ( m_ModelNotifier && !IsFrozen() ) + if ( m_ModelNotifier ) m_ModelNotifier->AdjustAutosizedColumns(); } From 5545e35f42e22e09fb9c89061c878fb2dbfa16b2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 9 Dec 2021 23:20:44 +0100 Subject: [PATCH 3/4] Get rid of "bool force" AdjustAutosizedColumns() parameter It is better and more clear to use a separate functions rather than a "bool force" parameter. Also add OnThaw() instead to let wxOSXDataViewModelNotifier itself decide what it needs to do when the control is thawed. No real changes. --- src/osx/dataview_osx.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index 2cea873e54..d65526d8bd 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -73,8 +73,19 @@ public: virtual bool Cleared() wxOVERRIDE; virtual void Resort() wxOVERRIDE; - // adjust wxCOL_WIDTH_AUTOSIZE columns to fit the data - void AdjustAutosizedColumns(bool force = false); + // adjust wxCOL_WIDTH_AUTOSIZE columns to fit the data, does nothing if the + // control is frozen + void AdjustAutosizedColumns() + { + if (!m_DataViewCtrlPtr->IsFrozen()) + DoAdjustAutosizedColumns(); + } + + // called by the control when it is thawed to adjust the columns if necessary + void OnThaw() + { + DoAdjustAutosizedColumns(); + } protected: // if the dataview control can have a variable row height this method sets the dataview's control row height of @@ -84,6 +95,9 @@ protected: void AdjustRowHeights(wxDataViewItemArray const& items); private: + // adjust the columns unconditionally + void DoAdjustAutosizedColumns(); + wxDataViewCtrl* m_DataViewCtrlPtr; }; @@ -297,11 +311,8 @@ void wxOSXDataViewModelNotifier::AdjustRowHeights(wxDataViewItemArray const& ite } } -void wxOSXDataViewModelNotifier::AdjustAutosizedColumns(bool forced) +void wxOSXDataViewModelNotifier::DoAdjustAutosizedColumns() { - if (m_DataViewCtrlPtr->IsFrozen() && !forced) - return; - unsigned count = m_DataViewCtrlPtr->GetColumnCount(); for ( unsigned col = 0; col < count; col++ ) { @@ -709,10 +720,8 @@ void wxDataViewCtrl::AdjustAutosizedColumns() const void wxDataViewCtrl::DoThaw() { if ( m_ModelNotifier ) - { - // On thaw, we want to force the updating of the colum sizes - m_ModelNotifier->AdjustAutosizedColumns(true); - } + m_ModelNotifier->OnThaw(); + wxDataViewCtrlBase::DoThaw(); } From 65b9b1047ff942128378d44ca660675f141896ff Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 9 Dec 2021 23:30:44 +0100 Subject: [PATCH 4/4] Avoid adjusting columns unnecessary on thaw Remember if we actually need to do this and avoid doing anything if we don't, this could be expensive with the controls containing a lot of data. --- src/osx/dataview_osx.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index d65526d8bd..b2e66185e7 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -74,17 +74,24 @@ public: virtual void Resort() wxOVERRIDE; // adjust wxCOL_WIDTH_AUTOSIZE columns to fit the data, does nothing if the - // control is frozen + // control is frozen but remember it for later void AdjustAutosizedColumns() { if (!m_DataViewCtrlPtr->IsFrozen()) DoAdjustAutosizedColumns(); + else + m_needsAdjustmentOnThaw = true; } // called by the control when it is thawed to adjust the columns if necessary void OnThaw() { - DoAdjustAutosizedColumns(); + if (m_needsAdjustmentOnThaw) + { + DoAdjustAutosizedColumns(); + + m_needsAdjustmentOnThaw = false; + } } protected: @@ -99,6 +106,11 @@ private: void DoAdjustAutosizedColumns(); wxDataViewCtrl* m_DataViewCtrlPtr; + + // This is set to true only if AdjustAutosizedColumns() is called while the + // control is frozen and in this case OnThaw() readjusts the columns when it + // is thawed. + bool m_needsAdjustmentOnThaw; }; // @@ -109,6 +121,8 @@ wxOSXDataViewModelNotifier::wxOSXDataViewModelNotifier(wxDataViewCtrl* initDataV { if (initDataViewCtrlPtr == NULL) wxFAIL_MSG("Pointer to dataview control must not be NULL"); + + m_needsAdjustmentOnThaw = false; } bool wxOSXDataViewModelNotifier::ItemAdded(wxDataViewItem const& parent, wxDataViewItem const& item)