When ellipsizing kicks in, the text is much shorter than the available
space -- there's a "safety margin" of one character's width that is
always left unused. This appears to be some kludge that worked around
algorithm defects, not something that should really be needed.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66870
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// Ellipsize() helper:
static wxString DoEllipsizeSingleLine(const wxString& label, const wxDC& dc,
wxEllipsizeMode mode, int maxWidth,
// Ellipsize() helper:
static wxString DoEllipsizeSingleLine(const wxString& label, const wxDC& dc,
wxEllipsizeMode mode, int maxWidth,
- int replacementWidth, int marginWidth);
// this field contains the label in wx format, i.e. with '&' mnemonics,
// as it was passed to the last SetLabel() call
// this field contains the label in wx format, i.e. with '&' mnemonics,
// as it was passed to the last SetLabel() call
/* static and protected */
wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxDC& dc,
wxEllipsizeMode mode, int maxFinalWidthPx,
/* static and protected */
wxString wxControlBase::DoEllipsizeSingleLine(const wxString& curLine, const wxDC& dc,
wxEllipsizeMode mode, int maxFinalWidthPx,
- int replacementWidthPx, int marginWidthPx)
+ int replacementWidthPx)
- wxASSERT_MSG(replacementWidthPx > 0 && marginWidthPx > 0,
- "Invalid parameters");
+ wxASSERT_MSG(replacementWidthPx > 0, "Invalid parameters");
wxASSERT_LEVEL_2_MSG(!curLine.Contains('\n'),
"Use Ellipsize() instead!");
wxASSERT_LEVEL_2_MSG(!curLine.Contains('\n'),
"Use Ellipsize() instead!");
return curLine; // we don't need to do any ellipsization!
int excessPx = wxMin(totalWidthPx - 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
totalWidthPx);
wxASSERT(excessPx>0); // excessPx should be in the [1;totalWidthPx] range
wxASSERT(removedPx >= excessPx);
// if there is space for the replacement dots, add them
wxASSERT(removedPx >= excessPx);
// if there is space for the replacement dots, add them
- if ((int)totalWidthPx-removedPx+replacementWidthPx < maxFinalWidthPx)
+ 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:
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);
+ wxASSERT(dc.GetTextExtent(ret).GetWidth() <= maxFinalWidthPx);
// 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();
// 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;
// NB: we must handle correctly labels with newlines:
wxString curLine;
if ( pc == label.end() || *pc == wxS('\n') )
{
curLine = DoEllipsizeSingleLine(curLine, dc, mode, maxFinalWidth,
if ( pc == label.end() || *pc == wxS('\n') )
{
curLine = DoEllipsizeSingleLine(curLine, dc, mode, maxFinalWidth,
- replacementWidth, marginWidth);
// add this (ellipsized) row to the rest of the label
ret << curLine;
// add this (ellipsized) row to the rest of the label
ret << curLine;