Restore button size calculation when not using manifest in wxMSW

This fixes regression introduced in de10f054c4 (Improve calculating
wxButton best size under wxMSW, 2021-04-08) which didn't check whether
BCM_GETIDEALSIZE succeeded -- as we must do, because in some situations
(when using very old systems or not using a manifest even under newer
ones), it does indeed fail.
This commit is contained in:
Vadim Zeitlin
2021-04-24 14:56:49 +01:00
parent 31b983bad1
commit 6f888df474

View File

@@ -580,17 +580,23 @@ wxSize wxAnyButton::DoGetBestSize() const
wxSize size; wxSize size;
// BCM_GETIDEALSIZE works properly only it there is a text label in the button. // The preferred way is to use BCM_GETIDEALSIZE, but it only works properly
if ( !IsOwnerDrawn() && ShowsLabel() ) // if there is a text label in the button and can't be used under old
// systems or without a manifest.
if ( !IsOwnerDrawn() && ShowsLabel() &&
wxGetWinVersion() >= wxWinVersion_Vista )
{ {
SIZE idealSize = { 0, 0 }; SIZE idealSize = { 0, 0 };
::SendMessage(GetHwnd(), BCM_GETIDEALSIZE, 0, (LPARAM)&idealSize); if ( ::SendMessage(GetHwnd(), BCM_GETIDEALSIZE, 0, (LPARAM)&idealSize) )
size.Set(idealSize.cx, idealSize.cy); size.Set(idealSize.cx, idealSize.cy);
if ( m_imageData ) if ( m_imageData )
AdjustForBitmapMargins(size); AdjustForBitmapMargins(size);
} }
else
// If we failed to set the size using BCM_GETIDEALSIZE above, determine it
// ourselves.
if ( size == wxSize() )
{ {
// Account for the text part if we have it. // Account for the text part if we have it.
if ( ShowsLabel() ) if ( ShowsLabel() )