// Returns the number of lines int CScrolledTextBox::Wrap(const wxString& text, int widthMax, int *lineHeight) { const wxChar *lastSpace = NULL; wxString line; int height = 0, numLines = 0; const wxChar *lineStart = text.c_str(); for ( const wxChar *p = lineStart; ; p++ ) { if ( IsStartOfNewLine() ) { m_text += _T('\n'); lastSpace = NULL; line.clear(); lineStart = p; } if ( *p == _T('\n') || *p == _T('\0') ) { line.Trim(); OnOutputLine(line); m_eol = true; ++numLines; if ( *p == _T('\0') ) break; } else { // not EOL if ( *p == _T(' ') ) { lastSpace = p; } line += *p; if ( widthMax >= 0 && lastSpace ) { int width; GetTextExtent(line, &width, &height); if ( width > widthMax ) { // remove the last word from this line line.erase(lastSpace - lineStart, p + 1 - lineStart); line.Trim(); OnOutputLine(line); m_eol = true; ++numLines; // go back to the last word of this line which we didn't // output yet p = lastSpace; } } //else: no wrapping at all or impossible to wrap } } *lineHeight = height; return numLines; }
void pxTextWrapperBase::DoOutputLine(const wxString& line) { OnOutputLine(line); m_linecount++; m_eol = true; }
// call OnOutputLine() and set m_eol to true void DoOutputLine(const wxString& line) { OnOutputLine(line); m_eol = true; }