From 5d904856aaf0b7e25827e8fc243e78a8ca95a4ad Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 30 Sep 2019 18:19:01 +0200 Subject: [PATCH 1/3] Make client size computation more parallel to OnPaint() code Make it more clear that we do what we do in DoGetBestClientSize() because of what our OnPaint() does. Incidentally fix off by 1 (or 2 under non-MSW platforms) mismatch between the 2 methods: the gap between the button and the text is actually just 2 DIPs, not 4, but we need to add another 1 DIP for the focus rectangle under MSW. --- src/generic/collheaderctrlg.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/generic/collheaderctrlg.cpp b/src/generic/collheaderctrlg.cpp index ac5527a312..7d0d2cd034 100644 --- a/src/generic/collheaderctrlg.cpp +++ b/src/generic/collheaderctrlg.cpp @@ -77,17 +77,28 @@ bool wxGenericCollapsibleHeaderCtrl::Create(wxWindow *parent, wxSize wxGenericCollapsibleHeaderCtrl::DoGetBestClientSize() const { - wxClientDC dc(const_cast(this)); - wxSize btnSize = wxRendererNative::Get().GetCollapseButtonSize(const_cast(this), dc); + wxGenericCollapsibleHeaderCtrl* const + self = const_cast(this); + + // The code here parallels that of OnPaint() -- except without drawing. + wxClientDC dc(self); + + wxSize size = wxRendererNative::Get().GetCollapseButtonSize(self, dc); + wxString text; wxControl::FindAccelIndex(GetLabel(), &text); - wxSize textSize = dc.GetTextExtent(text); - // Add some padding if the label is not empty - if ( textSize.x > 0 ) - textSize.x += FromDIP(4); - return wxSize(btnSize.x + textSize.x, - wxMax(textSize.y, btnSize.y)); + const wxSize textSize = dc.GetTextExtent(text); + + size.x += FromDIP(2) + textSize.x; + if ( textSize.y > size.y ) + size.y = textSize.y; + +#ifdef __WXMSW__ + size.IncBy(1); +#endif // __WXMSW__ + + return size; } void wxGenericCollapsibleHeaderCtrl::SetCollapsed(bool collapsed) From ef7ab7320611fa27d5b61a0d59623ec03c115e65 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 30 Sep 2019 23:28:40 +0200 Subject: [PATCH 2/3] Fix wxGenericCollapsiblePane best size calculation DoGetBestSize() actually calculated the best client size and not the full size, as it didn't take the pane border into account. Fix this in the simplest possible way, by just renaming the function to DoGetBestClientSize() instead. This ensures that the pane is actually big enough to show its contents, without cutting off the text shown in its header. Closes #18515. --- include/wx/generic/collpaneg.h | 2 +- src/generic/collpaneg.cpp | 2 +- src/osx/dataview_osx.cpp | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/wx/generic/collpaneg.h b/include/wx/generic/collpaneg.h index 27f1e87a75..7ea14bb26c 100644 --- a/include/wx/generic/collpaneg.h +++ b/include/wx/generic/collpaneg.h @@ -73,7 +73,7 @@ public: protected: // overridden methods - virtual wxSize DoGetBestSize() const wxOVERRIDE; + virtual wxSize DoGetBestClientSize() const wxOVERRIDE; int GetBorder() const; diff --git a/src/generic/collpaneg.cpp b/src/generic/collpaneg.cpp index 6a7a17af4d..37f8f90f22 100644 --- a/src/generic/collpaneg.cpp +++ b/src/generic/collpaneg.cpp @@ -112,7 +112,7 @@ wxGenericCollapsiblePane::~wxGenericCollapsiblePane() wxDELETE(m_sz); } -wxSize wxGenericCollapsiblePane::DoGetBestSize() const +wxSize wxGenericCollapsiblePane::DoGetBestClientSize() const { // NB: do not use GetSize() but rather GetMinSize() wxSize sz = m_sz->GetMinSize(); diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index 60e57b70f2..ee20e3bfaf 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -220,7 +220,15 @@ bool wxOSXDataViewModelNotifier::ValueChanged(wxDataViewItem const& item, unsign bool wxOSXDataViewModelNotifier::Cleared() { - return m_DataViewCtrlPtr->GetDataViewPeer()->Reload(); + // As when individual items are deleted, we must ensure that we don't touch + // the model item possibly being edited, as it's not valid any more. + m_DataViewCtrlPtr->SetDeleting(true); + + const bool rc = m_DataViewCtrlPtr->GetDataViewPeer()->Reload(); + + m_DataViewCtrlPtr->SetDeleting(false); + + return rc; } void wxOSXDataViewModelNotifier::Resort() From 45a4db125e19d731629af91d4b138096442e9ccb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 30 Sep 2019 23:31:18 +0200 Subject: [PATCH 3/3] Add right margin around wxGenericCollapsiblePane header too This makes the collapsible pane allocated exactly its best size better looking, as the header is centered now, instead of having a border on the left side, but not on the right one. See #18515. --- src/generic/collpaneg.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/generic/collpaneg.cpp b/src/generic/collpaneg.cpp index 37f8f90f22..5c570df37a 100644 --- a/src/generic/collpaneg.cpp +++ b/src/generic/collpaneg.cpp @@ -84,8 +84,7 @@ bool wxGenericCollapsiblePane::Create(wxWindow *parent, m_pButton = new wxCollapsibleHeaderCtrl(this, wxID_ANY, label, wxPoint(0, 0), wxDefaultSize); - // on other platforms we put the static line and the button horizontally - m_sz->Add(m_pButton, 0, wxLEFT|wxTOP|wxBOTTOM, GetBorder()); + m_sz->Add(m_pButton, wxSizerFlags().Border(wxALL, GetBorder())); // FIXME: at least under wxGTK1 the background is black if we don't do // this, no idea why...