+ break;
+
+ case wxELLIPSIZE_END:
+ {
+ int maxWidthPx = totalWidthPx - excessPx;
+
+ // go backward from the end of the string toward the start
+ for ( initialCharToRemove = len-1;
+ initialCharToRemove > 0 && charOffsetsPx[initialCharToRemove-1] > maxWidthPx;
+ initialCharToRemove-- )
+ ;
+ nCharsToRemove = len - initialCharToRemove;
+ }
+ break;
+
+ case wxELLIPSIZE_NONE:
+ default:
+ wxFAIL_MSG("invalid ellipsize mode");
+ return curLine;
+ }
+
+#ifdef __VMS
+#pragma message disable unscomzer
+ // suppress warnings on comparison of unsigned numbers
+#endif
+ wxASSERT(initialCharToRemove >= 0 && initialCharToRemove <= len-1); // see valid range for initialCharToRemove above
+#ifdef __VMS
+#pragma message enable unscomzer
+ // suppress warnings on comparison of unsigned numbers
+#endif
+ wxASSERT(nCharsToRemove >= 1 && nCharsToRemove <= len-initialCharToRemove); // see valid range for nCharsToRemove above
+
+ // erase nCharsToRemove characters after initialCharToRemove (included);
+ // e.g. if we have the string "foobar" (len = 6)
+ // ^
+ // \--- initialCharToRemove = 2
+ // and nCharsToRemove = 2, then we get "foar"
+ wxString ret(curLine);
+ ret.erase(initialCharToRemove, nCharsToRemove);
+
+ int removedPx;
+ if (initialCharToRemove >= 1)
+ removedPx = charOffsetsPx[initialCharToRemove+nCharsToRemove-1] - charOffsetsPx[initialCharToRemove-1];
+ else
+ removedPx = charOffsetsPx[initialCharToRemove+nCharsToRemove-1];
+ wxASSERT(removedPx >= excessPx);
+
+ // if there is space for the replacement dots, add them
+ if ((int)totalWidthPx-removedPx+replacementWidthPx < maxFinalWidthPx)
+ ret.insert(initialCharToRemove, wxELLIPSE_REPLACEMENT);
+
+ // if everything was ok, we should have shortened this line
+ // enough to make it fit in maxFinalWidthPx:
+ wxASSERT_LEVEL_2(dc.GetTextExtent(ret).GetWidth() <= maxFinalWidthPx);
+
+ 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);