+ break;
+
+ case wxELLIPSIZE_NONE:
+ default:
+ wxFAIL_MSG("invalid ellipsize mode");
+ return curLine;
+ }
+
+ wxString ret(curLine);
+ if (nChars >= len)
+ {
+ // need to remove the entire row!
+ ret.clear();
+ }
+ else
+ {
+ // erase nChars characters after initialChar (included):
+ ret.erase(initialChar, nChars+1);
+
+ // if there is space for the replacement dots, add them
+ if (maxFinalWidth > replacementWidth)
+ ret.insert(initialChar, wxELLIPSE_REPLACEMENT);
+ }
+
+ // if everything was ok, we should have shortened this line
+ // enough to make it fit in maxFinalWidth:
+ wxASSERT(dc.GetTextExtent(ret).GetWidth() < maxFinalWidth);
+
+ return ret;
+}
+
+/* static */
+wxString wxControlBase::Ellipsize(const wxString& label, const wxDC& dc,
+ wxEllipsizeMode mode, int maxFinalWidth,
+ int flags)
+{
+ wxString ret;
+
+ // these cannot be cached between different Ellipsize() calls as they can
+ // change because of e.g. a font change; however we calculate them only once
+ // when ellipsizing multiline labels:
+ int replacementWidth = dc.GetTextExtent(wxELLIPSE_REPLACEMENT).GetWidth();
+ int marginWidth = dc.GetCharWidth();
+
+ // NB: we must handle correctly labels with newlines:
+ wxString curLine;
+ for ( wxString::const_iterator pc = label.begin(); ; ++pc )
+ {
+ if ( pc == label.end() || *pc == wxS('\n') )
+ {
+ curLine = DoEllipsizeSingleLine(curLine, dc, mode, maxFinalWidth,
+ replacementWidth, marginWidth);