From 123da5330605e6b8c1c44655c82232b9e7cffdae Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 1 Jan 2019 19:26:34 +0100 Subject: [PATCH] Fix wxBitmapComboBox size in high DPI Convert hard-coded sizes to DPI depended size, remove unused size. Implement MSWUpdateFontOnDPIChange() and update the control elements. --- include/wx/msw/bmpcbox.h | 1 + src/common/bmpcboxcmn.cpp | 15 +++++++++++---- src/msw/bmpcbox.cpp | 11 +++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/wx/msw/bmpcbox.h b/include/wx/msw/bmpcbox.h index b6d5a47998..d71fc8d728 100644 --- a/include/wx/msw/bmpcbox.h +++ b/include/wx/msw/bmpcbox.h @@ -104,6 +104,7 @@ protected: WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const wxOVERRIDE; virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item) wxOVERRIDE; virtual bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item) wxOVERRIDE; + virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI) wxOVERRIDE; // Event handlers void OnSize(wxSizeEvent& event); diff --git a/src/common/bmpcboxcmn.cpp b/src/common/bmpcboxcmn.cpp index 1fa3c83ffa..103da719e1 100644 --- a/src/common/bmpcboxcmn.cpp +++ b/src/common/bmpcboxcmn.cpp @@ -68,7 +68,8 @@ void wxBitmapComboBoxBase::Init() void wxBitmapComboBoxBase::UpdateInternals() { - m_fontHeight = GetControl()->GetCharHeight() + EXTRA_FONT_HEIGHT; + m_fontHeight = GetControl()->GetCharHeight() + + GetControl()->FromDIP(EXTRA_FONT_HEIGHT); while ( m_bitmaps.GetCount() < GetItemContainer()->GetCount() ) m_bitmaps.Add( new wxBitmap() ); @@ -159,7 +160,9 @@ int wxBitmapComboBoxBase::DetermineIndent() if ( m_usedImgSize.x > 0 ) { - indent = m_usedImgSize.x + IMAGE_SPACING_LEFT + IMAGE_SPACING_RIGHT; + indent = m_usedImgSize.x + + GetControl()->FromDIP(IMAGE_SPACING_LEFT) + + GetControl()->FromDIP(IMAGE_SPACING_RIGHT); m_imgAreaWidth = indent; indent -= 3; @@ -214,9 +217,12 @@ void wxBitmapComboBoxBase::DrawItem(wxDC& dc, wxCoord w = bmp.GetWidth(); wxCoord h = bmp.GetHeight(); + const wxWindow* win = const_cast(this)->GetControl(); + const int imgSpacingLeft = win->FromDIP(IMAGE_SPACING_LEFT); + // Draw the image centered dc.DrawBitmap(bmp, - rect.x + (m_usedImgSize.x-w)/2 + IMAGE_SPACING_LEFT, + rect.x + (m_usedImgSize.x-w)/2 + imgSpacingLeft, rect.y + (rect.height-h)/2, true); } @@ -235,7 +241,8 @@ wxCoord wxBitmapComboBoxBase::MeasureItem(size_t WXUNUSED(item)) const return imgHeightArea > m_fontHeight ? imgHeightArea : m_fontHeight; } - return wxBCB_DEFAULT_ITEM_HEIGHT; + const wxWindow* win = const_cast(this)->GetControl(); + return win->FromDIP(wxBCB_DEFAULT_ITEM_HEIGHT); } #endif // wxBITMAPCOMBOBOX_OWNERDRAWN_BASED diff --git a/src/msw/bmpcbox.cpp b/src/msw/bmpcbox.cpp index 6f1b9bd0e1..d2d48ab06c 100644 --- a/src/msw/bmpcbox.cpp +++ b/src/msw/bmpcbox.cpp @@ -39,8 +39,6 @@ #include "wx/odcombo.h" -#define IMAGE_SPACING_CTRL_VERTICAL 7 // Spacing used in control size calculation - // ============================================================================ // implementation @@ -532,4 +530,13 @@ bool wxBitmapComboBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item) return true; } +void wxBitmapComboBox::MSWUpdateFontOnDPIChange(const wxSize& newDPI) +{ + wxComboBox::MSWUpdateFontOnDPIChange(newDPI); + + UpdateInternals(); + + RecreateControl(); +} + #endif // wxUSE_BITMAPCOMBOBOX