From 04828b722584554e7c8a23449cbb201d1cfc47b5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 21 Oct 2021 19:05:07 +0100 Subject: [PATCH] Update wxStaticBitmap in wxMSW on DPI change Use the appropriately sized bitmap when the resolution changes. --- include/wx/msw/statbmp.h | 2 ++ src/msw/statbmp.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/wx/msw/statbmp.h b/include/wx/msw/statbmp.h index 56cdaef1c2..015b2d44ae 100644 --- a/include/wx/msw/statbmp.h +++ b/include/wx/msw/statbmp.h @@ -112,7 +112,9 @@ private: // can we leave it to it) void DoPaintManually(wxPaintEvent& event); + // event handlers void WXHandleSize(wxSizeEvent& event); + void WXHandleDPIChanged(wxDPIChangedEvent& event); // return the size of m_icon or the appropriate size of m_bitmapBundle at // the current DPI scaling (may still be invalid of both of them are) diff --git a/src/msw/statbmp.cpp b/src/msw/statbmp.cpp index 96bc6ea05d..87c223b1eb 100644 --- a/src/msw/statbmp.cpp +++ b/src/msw/statbmp.cpp @@ -45,6 +45,7 @@ wxBEGIN_EVENT_TABLE(wxStaticBitmap, wxStaticBitmapBase) EVT_SIZE(wxStaticBitmap::WXHandleSize) + EVT_DPI_CHANGED(wxStaticBitmap::WXHandleDPIChanged) wxEND_EVENT_TABLE() // =========================================================================== @@ -190,6 +191,16 @@ void wxStaticBitmap::WXHandleSize(wxSizeEvent& event) event.Skip(); } +void wxStaticBitmap::WXHandleDPIChanged(wxDPIChangedEvent& event) +{ + // Icons only exist in a single resolution, so don't bother updating in + // this case. + if ( !m_icon.IsOk() && m_bitmapBundle.IsOk() ) + DoUpdateImage(wxSize(), false /* not using an icon */); + + event.Skip(); +} + void wxStaticBitmap::DoPaintManually(wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this);