+// common implementation of wxButton and wxToggleButton::DoGetBestSize()
+inline wxSize ComputeBestSize(wxControl *btn)
+{
+ wxClientDC dc(btn);
+
+ wxCoord wBtn,
+ hBtn;
+ dc.GetMultiLineTextExtent(btn->GetLabelText(), &wBtn, &hBtn);
+
+ // FIXME: this is pure guesswork, need to retrieve the real button margins
+ wBtn += 3*btn->GetCharWidth();
+ hBtn = 11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(hBtn)/10;
+
+ // all buttons have at least the standard size unless the user explicitly
+ // wants them to be of smaller size and used wxBU_EXACTFIT style when
+ // creating the button
+ if ( !btn->HasFlag(wxBU_EXACTFIT) )
+ {
+ wxSize sz = wxButton::GetDefaultSize();
+ if ( wBtn < sz.x )
+ wBtn = sz.x;
+ if ( hBtn < sz.y )
+ hBtn = sz.y;
+ }
+
+ wxSize best(wBtn, hBtn);
+ btn->CacheBestSize(best);
+ return best;
+}
+