From 6f7f387b1b8ace2171e29886254285567377cfe2 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 19 Aug 2020 21:21:26 +0200 Subject: [PATCH 1/3] Use GDI Scaling for dpi-unaware system dialogs Fall back to system scaling when GDI scaling fails or is unavailable. --- include/wx/msw/private/dpiaware.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/wx/msw/private/dpiaware.h b/include/wx/msw/private/dpiaware.h index 8467ef3b30..cab54e8af2 100644 --- a/include/wx/msw/private/dpiaware.h +++ b/include/wx/msw/private/dpiaware.h @@ -22,13 +22,14 @@ namespace wxMSWImpl { // ---------------------------------------------------------------------------- -// Temporarily change the DPI Awareness context to System +// Temporarily change the DPI Awareness context to GDIScaled or System // ---------------------------------------------------------------------------- class AutoSystemDpiAware { - #define WXDPI_AWARENESS_CONTEXT_UNAWARE ((WXDPI_AWARENESS_CONTEXT)-1) - #define WXDPI_AWARENESS_CONTEXT_SYSTEM_AWARE ((WXDPI_AWARENESS_CONTEXT)-2) + #define WXDPI_AWARENESS_CONTEXT_UNAWARE ((WXDPI_AWARENESS_CONTEXT)-1) + #define WXDPI_AWARENESS_CONTEXT_SYSTEM_AWARE ((WXDPI_AWARENESS_CONTEXT)-2) + #define WXDPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED ((WXDPI_AWARENESS_CONTEXT)-5) typedef WXDPI_AWARENESS_CONTEXT (WINAPI *SetThreadDpiAwarenessContext_t)(WXDPI_AWARENESS_CONTEXT); @@ -46,7 +47,12 @@ public: if ( m_pfnSetThreadDpiAwarenessContext ) { m_prevContext = m_pfnSetThreadDpiAwarenessContext( - WXDPI_AWARENESS_CONTEXT_SYSTEM_AWARE); + WXDPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED); + if ( !m_prevContext ) + { + m_prevContext = m_pfnSetThreadDpiAwarenessContext( + WXDPI_AWARENESS_CONTEXT_SYSTEM_AWARE); + } } } From c661be4fc9e8fdd38d7b333adfc5d8052e0586de Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 19 Aug 2020 21:21:45 +0200 Subject: [PATCH 2/3] Make custom renderer in dataview sample DPI Aware --- samples/dataview/dataview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index e80295515c..b4c4400fe0 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -262,7 +262,7 @@ public: virtual wxSize GetSize() const wxOVERRIDE { - return wxSize(60,20); + return GetView()->FromDIP(wxSize(60, 20)); } virtual bool SetValue( const wxVariant &value ) wxOVERRIDE From 8cb0d0741c2a2b66e7aadb14266f46290e4f5f90 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 19 Aug 2020 21:21:53 +0200 Subject: [PATCH 3/3] Don't iterate all item of wxListCtrl on DPI change This can take multiple seconds in big lists, meanwhile the UI is frozen at the display border. Adjust the font of the attribute to the DPI when it is used for drawing. --- src/msw/listctrl.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index a29c51d477..b5d912a764 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -429,17 +429,6 @@ void wxListCtrl::MSWUpdateFontOnDPIChange(const wxSize& newDPI) { wxListCtrlBase::MSWUpdateFontOnDPIChange(newDPI); - for ( int i = 0; i < GetItemCount(); i++ ) - { - wxMSWListItemData *data = MSWGetItemData(i); - if ( data && data->attr && data->attr->HasFont() ) - { - wxFont f = data->attr->GetFont(); - f.WXAdjustToPPI(newDPI); - SetItemFont(i, f); - } - } - if ( m_headerCustomDraw && m_headerCustomDraw->m_attr.HasFont() ) { wxItemAttr item(m_headerCustomDraw->m_attr); @@ -1014,13 +1003,6 @@ bool wxListCtrl::SetItem(wxListItem& info) data->attr->AssignFrom(attrNew); else data->attr = new wxItemAttr(attrNew); - - if ( data->attr->HasFont() ) - { - wxFont f = data->attr->GetFont(); - f.WXAdjustToPPI(GetDPI()); - data->attr->SetFont(f); - } } } @@ -3182,6 +3164,7 @@ static WXLPARAM HandleItemPrepaint(wxListCtrl *listctrl, if ( attr->HasFont() ) { wxFont font = attr->GetFont(); + font.WXAdjustToPPI(listctrl->GetDPI()); if ( font.GetEncoding() != wxFONTENCODING_SYSTEM ) { // the standard control ignores the font encoding/charset, at least