From 60f6c0f4e13e60daee91926c47fa334c4bdfad4f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 11 Dec 2023 02:19:02 +0100 Subject: [PATCH] Adjust indent and spacing after DPI change if necessary Although wxGenericTreeCtrl is not used under MSW by default, it still doesn't hurt to adjust its metrics when DPI changes there. Note that this shouldn't be done for the platforms using DIPs. --- include/wx/generic/treectlg.h | 2 ++ src/generic/treectlg.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/wx/generic/treectlg.h b/include/wx/generic/treectlg.h index 22469cf547..8475561619 100644 --- a/include/wx/generic/treectlg.h +++ b/include/wx/generic/treectlg.h @@ -357,6 +357,8 @@ protected: virtual wxSize DoGetBestSize() const override; private: + void OnDPIChanged(wxDPIChangedEvent& event); + void OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) { InitVisualAttributes(); diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 62dfa103bc..02f21c659c 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -947,6 +947,7 @@ wxBEGIN_EVENT_TABLE(wxGenericTreeCtrl, wxTreeCtrlBase) EVT_KILL_FOCUS (wxGenericTreeCtrl::OnKillFocus) EVT_TREE_ITEM_GETTOOLTIP(wxID_ANY, wxGenericTreeCtrl::OnGetToolTip) EVT_SYS_COLOUR_CHANGED(wxGenericTreeCtrl::OnSysColourChanged) + EVT_DPI_CHANGED(wxGenericTreeCtrl::OnDPIChanged) wxEND_EVENT_TABLE() // ----------------------------------------------------------------------------- @@ -4208,4 +4209,16 @@ wxSize wxGenericTreeCtrl::DoGetBestSize() const return size; } +void wxGenericTreeCtrl::OnDPIChanged(wxDPIChangedEvent& event) +{ + // For the platforms using DPI-dependent pixels we need to adjust various + // metrics after the DPI change. +#ifndef wxHAS_DPI_INDEPENDENT_PIXELS + m_indent = event.ScaleX(m_indent); + m_spacing = event.ScaleX(m_spacing); +#endif // !wxHAS_DPI_INDEPENDENT_PIXELS + + event.Skip(); +} + #endif // wxUSE_TREECTRL