comctl32/button: Use WM_GETTEXTLENGTH to see if the button has any text.

There's no reason to allocate and then parse the entire string just to see
if its length is zero.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Gabriel Ivăncescu 2019-04-04 14:39:49 +03:00 committed by Alexandre Julliard
parent 715065feb3
commit 8ee1e3453e
1 changed files with 9 additions and 21 deletions

View File

@ -1276,20 +1276,16 @@ static BOOL GB_GetIdealSize(BUTTON_INFO *infoPtr, SIZE *size)
static BOOL CB_GetIdealSize(BUTTON_INFO *infoPtr, SIZE *size) static BOOL CB_GetIdealSize(BUTTON_INFO *infoPtr, SIZE *size)
{ {
LONG style = GetWindowLongW(infoPtr->hwnd, GWL_STYLE); LONG style = GetWindowLongW(infoPtr->hwnd, GWL_STYLE);
WCHAR *text = get_button_text(infoPtr);
HDC hdc; HDC hdc;
HFONT hfont; HFONT hfont;
SIZE labelSize; SIZE labelSize;
INT textOffset; INT textOffset;
INT textLength = 0;
double scaleX; double scaleX;
double scaleY; double scaleY;
LONG checkboxWidth, checkboxHeight; LONG checkboxWidth, checkboxHeight;
LONG maxWidth = 0; LONG maxWidth = 0;
if (text) textLength = lstrlenW(text); if (SendMessageW(infoPtr->hwnd, WM_GETTEXTLENGTH, 0, 0) == 0)
heap_free(text);
if (textLength == 0)
{ {
BUTTON_GetClientRectSize(infoPtr, size); BUTTON_GetClientRectSize(infoPtr, size);
return TRUE; return TRUE;
@ -1325,26 +1321,18 @@ static BOOL CB_GetIdealSize(BUTTON_INFO *infoPtr, SIZE *size)
static BOOL PB_GetIdealSize(BUTTON_INFO *infoPtr, SIZE *size) static BOOL PB_GetIdealSize(BUTTON_INFO *infoPtr, SIZE *size)
{ {
WCHAR *text = get_button_text(infoPtr);
SIZE labelSize; SIZE labelSize;
INT textLength = 0;
if (text) textLength = lstrlenW(text); if (SendMessageW(infoPtr->hwnd, WM_GETTEXTLENGTH, 0, 0) == 0)
if (textLength == 0)
{
BUTTON_GetClientRectSize(infoPtr, size); BUTTON_GetClientRectSize(infoPtr, size);
heap_free(text); else
return TRUE; {
}
heap_free(text);
/* Ideal size include text size even if image only flags(BS_ICON, BS_BITMAP) are specified */ /* Ideal size include text size even if image only flags(BS_ICON, BS_BITMAP) are specified */
BUTTON_GetLabelIdealSize(infoPtr, size->cx, &labelSize); BUTTON_GetLabelIdealSize(infoPtr, size->cx, &labelSize);
size->cx = labelSize.cx; size->cx = labelSize.cx;
size->cy = labelSize.cy; size->cy = labelSize.cy;
}
return TRUE; return TRUE;
} }