From: Vadim Zeitlin Date: Tue, 15 Feb 2005 12:22:07 +0000 (+0000) Subject: reuse code from wxDC::GetMultiLineTextExtent() instead of duplicating it here X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/8812e0986833a7b3cdf8cf113974c7c23f05ad18 reuse code from wxDC::GetMultiLineTextExtent() instead of duplicating it here git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32073 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/stattext.cpp b/src/msw/stattext.cpp index dcc6433985..59725f6c38 100644 --- a/src/msw/stattext.cpp +++ b/src/msw/stattext.cpp @@ -127,74 +127,17 @@ WXDWORD wxStaticText::MSWGetStyle(long style, WXDWORD *exstyle) const wxSize wxStaticText::DoGetBestSize() const { - wxString text(wxGetWindowText(GetHWND())); + wxClientDC dc(wx_const_cast(wxStaticText *, this)); + dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); - int widthTextMax = 0, widthLine, - heightTextTotal = 0, heightLineDefault = 0, heightLine = 0; + wxCoord widthTextMax, heightTextTotal; + dc.GetMultiLineTextExtent(GetLabel(), &widthTextMax, &heightTextTotal); - bool lastWasAmpersand = false; - - wxString curLine; - for ( const wxChar *pc = text; ; pc++ ) - { - if ( *pc == wxT('\n') || *pc == wxT('\0') ) - { - if ( !curLine ) - { - // we can't use GetTextExtent - it will return 0 for both width - // and height and an empty line should count in height - // calculation - if ( !heightLineDefault ) - heightLineDefault = heightLine; - if ( !heightLineDefault ) - GetTextExtent(_T("W"), NULL, &heightLineDefault); - - heightTextTotal += heightLineDefault; - } - else - { - GetTextExtent(curLine, &widthLine, &heightLine); - if ( widthLine > widthTextMax ) - widthTextMax = widthLine; - heightTextTotal += heightLine; - } - - if ( *pc == wxT('\n') ) - { - curLine.Empty(); - } - else - { - // the end of string - break; - } - } - else - { - // we shouldn't take into account the '&' which just introduces the - // mnemonic characters and so are not shown on the screen -- except - // when it is preceded by another '&' in which case it stands for a - // literal ampersand - if ( *pc == _T('&') ) - { - if ( !lastWasAmpersand ) - { - lastWasAmpersand = true; - - // skip the statement adding pc to curLine below - continue; - } - - // it is a literal ampersand - lastWasAmpersand = false; - } - - curLine += *pc; - } - } #ifdef __WXWINCE__ - if(widthTextMax) widthTextMax += 2; -#endif + if ( widthTextMax ) + widthTextMax += 2; +#endif // __WXWINCE__ + return wxSize(widthTextMax, heightTextTotal); }