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.
This commit is contained in:
Vadim Zeitlin
2019-09-30 18:19:01 +02:00
parent 8d2b2c0f56
commit 5d904856aa

View File

@@ -77,17 +77,28 @@ bool wxGenericCollapsibleHeaderCtrl::Create(wxWindow *parent,
wxSize wxGenericCollapsibleHeaderCtrl::DoGetBestClientSize() const
{
wxClientDC dc(const_cast<wxGenericCollapsibleHeaderCtrl*>(this));
wxSize btnSize = wxRendererNative::Get().GetCollapseButtonSize(const_cast<wxGenericCollapsibleHeaderCtrl*>(this), dc);
wxGenericCollapsibleHeaderCtrl* const
self = const_cast<wxGenericCollapsibleHeaderCtrl*>(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)