From 6c59a4e7af6bdbc072273daa7eb29388302e0269 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 16 May 2019 22:10:43 +0200 Subject: [PATCH] Fix wxStaticBitmap auto-resizing under MSW wxStaticBitmap tried to automatically resize itself to its new size, but did it wrongly (since what looks like ever, or at least since the first version in the VCS, which is 2bda0e173844e8e0f8acf4e8ad8b5c26e5c6fe5d, from 21 years ago) because it assumed that the size of wxStaticBitmap window is the same as the size of the bitmap it is showing, which is not the case when it uses border style such as wxBORDER_RAISED. Fix this by resizing it to the current size adjusted by the difference between the old and new bitmap sizes. Alternative approach would be to just use SetSize(GetBestSize()), as the other ports do, but keep the changes to the minimum for now. Closes #18398. --- src/msw/statbmp.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/msw/statbmp.cpp b/src/msw/statbmp.cpp index c574663f6c..c21fbd8fa0 100644 --- a/src/msw/statbmp.cpp +++ b/src/msw/statbmp.cpp @@ -278,6 +278,14 @@ void wxStaticBitmap::MSWReplaceImageHandle(WXLPARAM handle) void wxStaticBitmap::SetImageNoCopy( wxGDIImage* image) { + wxSize sizeOld; + if ( m_image ) + sizeOld = m_image->GetSize(); + + wxSize sizeNew; + if ( image ) + sizeNew = image->GetSize(); + Free(); InvalidateBestSize(); @@ -324,17 +332,12 @@ void wxStaticBitmap::SetImageNoCopy( wxGDIImage* image) m_currentHandle = (WXHANDLE)handle; m_ownsCurrentHandle = handle != handleOrig; - if ( ImageIsOk() ) + if ( sizeNew != sizeOld ) { - int width = image->GetWidth(), - height = image->GetHeight(); - if ( width && height ) - { - w = width; - h = height; + w += sizeNew.x - sizeOld.x; + h += sizeNew.y - sizeOld.y; - MSWMoveWindowToAnyPosition(GetHwnd(), x, y, width, height, false); - } + MSWMoveWindowToAnyPosition(GetHwnd(), x, y, w, h, false); } RECT rect;