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)