Update bitmap size automatically on DPI change in wxMSW wxToolBar

Remove the now unnecessary wxEVT_DPI_CHANGED event handler in the
sample.
This commit is contained in:
Vadim Zeitlin
2021-09-27 18:41:45 +01:00
parent 7337bf1da1
commit 9a578b9c8f
2 changed files with 4 additions and 12 deletions

View File

@@ -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();

View File

@@ -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;