Remove double strlen call in wxSTCListBoxD2D

The length of a string in wxSTCListBoxD2D::OnDrawItemText was being
calculated twice - first when measured and again when drawn. Instead
store the length the first time it is calculated. Also, pass a copy of
the string in wx2stclen to allow the calculation to work in ASCII
builds.
This commit is contained in:
New Pagodi
2020-06-25 21:45:04 -05:00
parent a3a6938673
commit 01b3bf7eef

View File

@@ -3175,8 +3175,8 @@ public:
wxString ellipsizedLabel = label; wxString ellipsizedLabel = label;
wxCharBuffer buffer = wx2stc(ellipsizedLabel); wxCharBuffer buffer = wx2stc(ellipsizedLabel);
int curWidth = surface.WidthText(tempFont, buffer.data(), int ellipsizedLen = wx2stclen(ellipsizedLabel, buffer);
wx2stclen(wxString(), buffer)); int curWidth = surface.WidthText(tempFont, buffer.data(),ellipsizedLen);
for ( int i = label.length(); curWidth > rect.GetWidth() && i; --i ) for ( int i = label.length(); curWidth > rect.GetWidth() && i; --i )
{ {
@@ -3184,8 +3184,8 @@ public:
ellipsizedLabel << "..."; ellipsizedLabel << "...";
buffer = wx2stc(ellipsizedLabel); buffer = wx2stc(ellipsizedLabel);
curWidth = surface.WidthText(tempFont, buffer.data(), ellipsizedLen = wx2stclen(ellipsizedLabel, buffer);
wx2stclen(wxString(), buffer)); curWidth = surface.WidthText(tempFont, buffer.data(),ellipsizedLen);
} }
PRectangle prect = PRectangleFromwxRect(rect); PRectangle prect = PRectangleFromwxRect(rect);
@@ -3194,7 +3194,7 @@ public:
XYPOSITION ybase = rect.GetTop() + m_surfaceFontData->GetAscent(); XYPOSITION ybase = rect.GetTop() + m_surfaceFontData->GetAscent();
surface.DrawTextTransparent(prect, tempFont, ybase, buffer.data(), surface.DrawTextTransparent(prect, tempFont, ybase, buffer.data(),
wx2stclen(wxString(), buffer), fore); ellipsizedLen, fore);
tempFont.Release(); tempFont.Release();
surface.Release(); surface.Release();
} }