use wxDC::GetMultiLineTextExtent() instead of duplicating its code in wxButton::DoGetBestSize()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32051 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -216,38 +216,16 @@ WXDWORD wxButton::MSWGetStyle(long style, WXDWORD *exstyle) const
|
|||||||
|
|
||||||
wxSize wxButton::DoGetBestSize() const
|
wxSize wxButton::DoGetBestSize() const
|
||||||
{
|
{
|
||||||
int wBtn = 0;
|
wxClientDC dc(wx_const_cast(wxButton *, this));
|
||||||
int wChar, hChar, hBtn;
|
dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
|
||||||
wxGetCharSize(GetHWND(), &wChar, &hChar, GetFont());
|
|
||||||
|
|
||||||
wxString label = wxGetWindowText(GetHWND());
|
wxCoord wBtn,
|
||||||
if ( label.find(_T('\n')) != wxString::npos )
|
hBtn;
|
||||||
{
|
dc.GetMultiLineTextExtent(GetLabel(), &wBtn, &hBtn);
|
||||||
wxStringTokenizer tokens( label, wxT("\n") );
|
|
||||||
|
|
||||||
// the button height is proportional to the height of the font used
|
|
||||||
hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
|
|
||||||
hBtn += hChar*(tokens.CountTokens()-1);
|
|
||||||
|
|
||||||
while (tokens.HasMoreTokens())
|
|
||||||
{
|
|
||||||
wxString sub = tokens.GetNextToken();
|
|
||||||
int w;
|
|
||||||
GetTextExtent( sub, &w, NULL);
|
|
||||||
if (w > wBtn)
|
|
||||||
wBtn = w;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GetTextExtent( label, &wBtn, NULL);
|
|
||||||
|
|
||||||
// the button height is proportional to the height of the font used
|
|
||||||
hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add a margin -- the button is wider than just its label
|
// add a margin -- the button is wider than just its label
|
||||||
wBtn += 3*wChar;
|
wBtn += 3*GetCharWidth();
|
||||||
|
hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hBtn);
|
||||||
|
|
||||||
// all buttons have at least the standard size unless the user explicitly
|
// 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
|
// wants them to be of smaller size and used wxBU_EXACTFIT style when
|
||||||
|
Reference in New Issue
Block a user