- wxCoord widthTextMax = 0, widthLine,
- heightTextTotal = 0, heightLineDefault = 0, heightLine = 0;
-
- wxString curLine;
- for ( wxString::const_iterator pc = text.begin(); ; ++pc )
- {
- if ( pc == text.end() || *pc == wxT('\n') )
- {
- if ( curLine.empty() )
- {
- // we can't use GetTextExtent - it will return 0 for both width
- // and height and an empty line should count in height
- // calculation
-
- // assume that this line has the same height as the previous
- // one
- if ( !heightLineDefault )
- heightLineDefault = heightLine;
-
- if ( !heightLineDefault )
- {
- // but we don't know it yet - choose something reasonable
- DoGetTextExtent(wxT("W"), NULL, &heightLineDefault,
- NULL, NULL, font);
- }
-
- heightTextTotal += heightLineDefault;
- }
- else
- {
- DoGetTextExtent(curLine, &widthLine, &heightLine,
- NULL, NULL, font);
- if ( widthLine > widthTextMax )
- widthTextMax = widthLine;
- heightTextTotal += heightLine;
- }
-
- if ( pc == text.end() )
- {
- break;
- }
- else // '\n'
- {
- curLine.clear();
- }
- }
- else
- {
- curLine += *pc;
- }
- }
-
- if ( x )
- *x = widthTextMax;
- if ( y )
- *y = heightTextTotal;
- if ( h )
- *h = heightLine;
+ wxTextMeasure tm(GetOwner(), font && font->IsOk() ? font : &m_font);
+ tm.GetMultiLineTextExtent(text, x, y, h);