From 1e17e8f500692df5d8e431596d3fe856f03de8b8 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sat, 13 Feb 2021 01:41:34 +0100 Subject: [PATCH] Improve per-monitor DPI in wxVListBoxComboPopup Adjust the default item height before the drawing size is calculated. --- include/wx/odcombo.h | 1 + src/generic/odcombo.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/wx/odcombo.h b/include/wx/odcombo.h index d147cd49b0..a8ffa9570a 100644 --- a/include/wx/odcombo.h +++ b/include/wx/odcombo.h @@ -93,6 +93,7 @@ public: virtual void OnComboDoubleClick() wxOVERRIDE; virtual bool LazyCreate() wxOVERRIDE; virtual bool FindItem(const wxString& item, wxString* trueItem) wxOVERRIDE; + virtual void OnDPIChanged(wxDPIChangedEvent& event); // Item management void SetSelection( int item ); diff --git a/src/generic/odcombo.cpp b/src/generic/odcombo.cpp index 49a3cd8141..22b4eefeda 100644 --- a/src/generic/odcombo.cpp +++ b/src/generic/odcombo.cpp @@ -84,6 +84,10 @@ bool wxVListBoxComboPopup::Create(wxWindow* parent) // TODO: Move this to SetFont m_itemHeight = m_combo->GetCharHeight(); + // Bind to the DPI event of the combobox. We get our own once the popup + // is shown, but this is too late, m_itemHeight is already being used. + m_combo->Bind(wxEVT_DPI_CHANGED, &wxVListBoxComboPopup::OnDPIChanged, this); + return true; } @@ -104,6 +108,11 @@ void wxVListBoxComboPopup::SetFocus() #endif } +void wxVListBoxComboPopup::OnDPIChanged(wxDPIChangedEvent& WXUNUSED(event)) +{ + m_itemHeight = m_combo->GetCharHeight(); +} + bool wxVListBoxComboPopup::LazyCreate() { // NB: There is a bug with wxVListBox that can be avoided by creating