X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6a629e51df9e8034ac3a0f9c2c871cbfafd1632a..5e0d7b6bce53ad3ceb3c832925c25d2e614a0d62:/src/msw/stattext.cpp diff --git a/src/msw/stattext.cpp b/src/msw/stattext.cpp index 14c62eca20..5248292eea 100644 --- a/src/msw/stattext.cpp +++ b/src/msw/stattext.cpp @@ -5,8 +5,8 @@ // Modified by: // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Copyright: (c) Julian Smart +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -42,6 +42,10 @@ bool wxStaticText::Create(wxWindow *parent, long style, const wxString& name) { + // By default, a static text should have no border. + if ((style & wxBORDER_MASK) == wxBORDER_DEFAULT) + style |= wxBORDER_NONE; + if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) ) return FALSE; @@ -76,10 +80,15 @@ wxSize wxStaticText::DoGetBestSize() const int widthTextMax = 0, widthLine, heightTextTotal = 0, heightLineDefault = 0, heightLine = 0; + bool lastWasAmpersand = FALSE; + wxString curLine; - for ( const wxChar *pc = text; ; pc++ ) { - if ( *pc == wxT('\n') || *pc == wxT('\0') ) { - if ( !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 @@ -90,26 +99,45 @@ wxSize wxStaticText::DoGetBestSize() const heightTextTotal += heightLineDefault; } - else { + else + { GetTextExtent(curLine, &widthLine, &heightLine); if ( widthLine > widthTextMax ) widthTextMax = widthLine; heightTextTotal += heightLine; } - if ( *pc == wxT('\n') ) { + if ( *pc == wxT('\n') ) + { curLine.Empty(); } - else { + else + { // the end of string break; } } - else { - // we shouldn't take into account the '&' which just introduce the - // mnemonic characters and so are not shown on the screen - if ( pc != _T('&') ) - curLine += *pc; + 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; } }