From 5d904856aaf0b7e25827e8fc243e78a8ca95a4ad Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 30 Sep 2019 18:19:01 +0200 Subject: [PATCH] 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)