From 9a578b9c8f50972a1d46755b63878a004a2e6311 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 27 Sep 2021 18:41:45 +0100 Subject: [PATCH] Update bitmap size automatically on DPI change in wxMSW wxToolBar Remove the now unnecessary wxEVT_DPI_CHANGED event handler in the sample. --- samples/toolbar/toolbar.cpp | 12 ------------ src/msw/toolbar.cpp | 4 ++++ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index 22490a3b6b..d002567538 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -111,7 +111,6 @@ public: void OnAbout(wxCommandEvent& event); void OnSize(wxSizeEvent& event); - void OnDPIChanged(wxDPIChangedEvent& event); void OnToggleToolbar(wxCommandEvent& event); void OnToggleAnotherToolbar(wxCommandEvent& event); @@ -242,7 +241,6 @@ enum wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_SIZE(MyFrame::OnSize) - EVT_DPI_CHANGED(MyFrame::OnDPIChanged) EVT_MENU(wxID_EXIT, MyFrame::OnQuit) EVT_MENU(wxID_HELP, MyFrame::OnAbout) @@ -698,16 +696,6 @@ void MyFrame::OnSize(wxSizeEvent& event) } } -void MyFrame::OnDPIChanged(wxDPIChangedEvent& event) -{ - event.Skip(); - - // We check the DPI scaling factor when the toolbar is created, so just - // recreate it whenever DPI changes. We could also just update the tools - // bitmaps, but this is simpler and doesn't have any significant drawbacks. - RecreateToolbar(); -} - void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event)) { wxToolBar *tbar = GetToolBar(); diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 36d5840058..fe7b8f49d2 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -1949,6 +1949,10 @@ void wxToolBar::RealizeHelper() void wxToolBar::OnDPIChanged(wxDPIChangedEvent& event) { + // Ensure that when Realize() is called, the bitmaps size corresponding to + // the new resolution will be used. + SetToolBitmapSize(event.Scale(wxSize(m_defaultWidth, m_defaultHeight))); + // Manually scale the size of the controls. Even though the font has been // updated, the internal size of the controls does not. wxToolBarToolsList::compatibility_iterator node;