From 6dbe83dc76483b9c3072e0f5f9bc4e7019c6cc05 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Thu, 2 Jun 2005 02:19:43 +0000 Subject: Tweaked autocompletion width a little so that it is more likely to fit all strings when the string with the most characters contains narrow characters. --- win32/PlatWin.cxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index c7435f212..db572a5dd 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -1121,9 +1121,9 @@ PRectangle ListBoxX::GetDesiredRect() { int len = widestItem ? strlen(widestItem) : 0; if (unicodeMode) { wchar_t tbuf[MAX_US_LEN]; - int tlen = UCS2FromUTF8(widestItem, len, tbuf, sizeof(tbuf)/sizeof(wchar_t)-1); - tbuf[tlen] = L'\0'; - ::GetTextExtentPoint32W(hdc, tbuf, tlen, &textSize); + len = UCS2FromUTF8(widestItem, len, tbuf, sizeof(tbuf)/sizeof(wchar_t)-1); + tbuf[len] = L'\0'; + ::GetTextExtentPoint32W(hdc, tbuf, len, &textSize); } else { ::GetTextExtentPoint32(hdc, widestItem, len, &textSize); } @@ -1132,8 +1132,10 @@ PRectangle ListBoxX::GetDesiredRect() { maxCharWidth = tm.tmMaxCharWidth; SelectFont(hdc, oldFont); ::ReleaseDC(lb, hdc); - if (textSize.cx > width) - width = textSize.cx; + + int widthDesired = Platform::Maximum(textSize.cx, (len + 1) * tm.tmAveCharWidth); + if (width < widthDesired) + width = widthDesired; rcDesired.right = rcDesired.left + TextOffset() + width + (TextInset.x * 2); if (Length() > rows) -- cgit v1.2.3