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 2bda0e1738,
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user