+// ----------------------------------------------------------------------------
+// wxControlBase - ellipsization code
+// ----------------------------------------------------------------------------
+
+#define wxELLIPSE_REPLACEMENT wxS("...")
+
+/* static and protected */
+wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxDC& dc,
+ wxEllipsizeMode mode, int maxFinalWidthPx,
+ int replacementWidthPx, int marginWidthPx)
+{
+ wxASSERT_MSG(replacementWidthPx > 0 && marginWidthPx > 0,
+ "Invalid parameters");
+ wxASSERT_LEVEL_2_MSG(!curLine.Contains('\n'),
+ "Use Ellipsize() instead!");
+
+ wxASSERT_MSG( mode != wxELLIPSIZE_NONE, "shouldn't be called at all then" );
+
+ // NOTE: this function assumes that any mnemonic/tab character has already
+ // been handled if it was necessary to handle them (see Ellipsize())
+
+ if (maxFinalWidthPx <= 0)
+ return wxEmptyString;
+
+ wxArrayInt charOffsetsPx;
+ size_t len = curLine.length();
+ if (len == 0 ||
+ !dc.GetPartialTextExtents(curLine, charOffsetsPx))
+ return curLine;
+
+ wxASSERT(charOffsetsPx.GetCount() == len);
+
+ // NOTE: charOffsetsPx[n] is the width in pixels of the first n characters (with the last one INCLUDED)
+ // thus charOffsetsPx[len-1] is the total width of the string
+ size_t totalWidthPx = charOffsetsPx.Last();
+ if ( totalWidthPx <= (size_t)maxFinalWidthPx )
+ return curLine; // we don't need to do any ellipsization!
+
+ int excessPx = wxMin(totalWidthPx - maxFinalWidthPx +
+ replacementWidthPx +
+ marginWidthPx, // security margin
+ totalWidthPx);
+ wxASSERT(excessPx>0); // excessPx should be in the [1;totalWidthPx] range
+
+ // REMEMBER: indexes inside the string have a valid range of [0;len-1] if not otherwise constrained
+ // lengths/counts of characters (e.g. nCharsToRemove) have a valid range of [0;len] if not otherwise constrained
+ // NOTE: since this point we know we have for sure a non-empty string from which we need
+ // to remove _at least_ one character (thus nCharsToRemove below is constrained to be >= 1)
+
+ size_t initialCharToRemove, // index of first character to erase, valid range is [0;len-1]
+ nCharsToRemove; // how many chars do we need to erase? valid range is [1;len-initialCharToRemove]
+
+ // let's compute the range of characters to remove depending on the ellipsization mode:
+ switch (mode)