wxSize wxToggleButton::DoGetBestSize() const { wxString label = wxGetWindowText(GetHWND()); int wBtn; wxFont vFont = GetFont(); int wChar; int hChar; GetTextExtent(label, &wBtn, NULL); wxGetCharSize(GetHWND(), &wChar, &hChar, &vFont); // add a margin - the button is wider than just its label wBtn += 3*wChar; // the button height is proportional to the height of the font used int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar); #if wxUSE_BUTTON wxSize sz = wxButton::GetDefaultSize(); if (wBtn > sz.x) sz.x = wBtn; if (hBtn > sz.y) sz.y = hBtn; #else wxSize sz(wBtn, hBtn); #endif return sz; }
wxSize wxToggleButton::DoGetBestSize() const { wxString label = wxGetWindowText(GetHWND()); int wBtn; GetTextExtent(GetLabelText(label), &wBtn, NULL); int wChar, hChar; wxGetCharSize(GetHWND(), &wChar, &hChar, GetFont()); // add a margin - the button is wider than just its label wBtn += 3*wChar; // the button height is proportional to the height of the font used int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar); #if wxUSE_BUTTON // make all buttons of at least standard size unless wxBU_EXACTFIT is given if ( !HasFlag(wxBU_EXACTFIT) ) { const wxSize szMin = wxButton::GetDefaultSize(); if ( wBtn < szMin.x ) wBtn = szMin.x; if ( hBtn < szMin.y ) hBtn = szMin.y; } #endif // wxUSE_BUTTON wxSize sz(wBtn, hBtn); CacheBestSize(sz); return sz; }
wxSize wxButton::DoGetBestSize() const { wxString rsLabel = wxGetWindowText(GetHWND()); int nWidthButton; int nWidthChar; int nHeightChar; wxFont vFont = (wxFont)GetFont(); GetTextExtent( rsLabel ,&nWidthButton ,NULL ); wxGetCharSize( GetHWND() ,&nWidthChar ,&nHeightChar ,&vFont ); // // Add a margin - the button is wider than just its label // nWidthButton += 3 * nWidthChar; // // The button height is proportional to the height of the font used // int nHeightButton = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(nHeightChar); // // Need a little extra to make it look right // nHeightButton += (int)(nHeightChar/1.5); if (!HasFlag(wxBU_EXACTFIT)) { wxSize vSize = GetDefaultSize(); if (nWidthButton > vSize.x) vSize.x = nWidthButton; if (nHeightButton > vSize.y) vSize.y = nHeightButton; return vSize; } return wxSize( nWidthButton ,nHeightButton ); } // end of wxButton::DoGetBestSize
// ---------------------------------------------------------------------------- // size management including autosizing // ---------------------------------------------------------------------------- wxSize wxButton::DoGetBestSize() const { wxClientDC dc(wx_const_cast(wxButton *, this)); dc.SetFont(GetFont()); wxCoord wBtn, hBtn; dc.GetMultiLineTextExtent(GetLabel(), &wBtn, &hBtn); // add a margin -- the button is wider than just its label wBtn += 3*GetCharWidth(); hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hBtn); // 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 ( !HasFlag(wxBU_EXACTFIT) ) { wxSize sz = GetDefaultSize(); if (wBtn > sz.x) sz.x = wBtn; if (hBtn > sz.y) sz.y = hBtn; return sz; }