From 80a736250e2aa60ac494cf48c32df5fc68d4a31e Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 25 May 2022 15:22:15 +0200 Subject: [PATCH] Fix margin between wxBitmapComboBox images and text in high DPI Don't use FromDIP() with m_usedImgSize which is expressed in logical, and not DPI-independent, pixels already and also update the image size when the DPI changes. Closes #22436. --- src/common/bmpcboxcmn.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/common/bmpcboxcmn.cpp b/src/common/bmpcboxcmn.cpp index 86a3dd6d24..7fc297982a 100644 --- a/src/common/bmpcboxcmn.cpp +++ b/src/common/bmpcboxcmn.cpp @@ -56,7 +56,7 @@ void wxBitmapComboBoxBase::Init() m_fontHeight = 0; m_imgAreaWidth = 0; m_indent = 0; - m_usedImgSize = wxSize(-1, -1); + m_usedImgSize = wxDefaultSize; } void wxBitmapComboBoxBase::UpdateInternals() @@ -66,6 +66,9 @@ void wxBitmapComboBoxBase::UpdateInternals() while ( m_bitmapbundles.size() < GetItemContainer()->GetCount() ) m_bitmapbundles.push_back( wxBitmapBundle() ); + + if ( m_usedImgSize.x != -1 && m_bitmapbundles.size() > 0 ) + m_usedImgSize = m_bitmapbundles[0].GetPreferredLogicalSizeFor(GetControl()); } // ---------------------------------------------------------------------------- @@ -94,8 +97,7 @@ void wxBitmapComboBoxBase::BCBDoClear() { m_bitmapbundles.clear(); - m_usedImgSize.x = -1; - m_usedImgSize.y = -1; + m_usedImgSize = wxDefaultSize; DetermineIndent(); } @@ -117,14 +119,11 @@ bool wxBitmapComboBoxBase::OnAddBitmap(const wxBitmapBundle& bitmap) if ( bitmap.IsOk() ) { wxSize bmpDefaultSize = bitmap.GetPreferredLogicalSizeFor(GetControl()); - int width = bmpDefaultSize.GetWidth(); - int height = bmpDefaultSize.GetHeight(); if ( m_usedImgSize.x < 0 ) { // If size not yet determined, get it from this image. - m_usedImgSize.x = width; - m_usedImgSize.y = height; + m_usedImgSize = bmpDefaultSize; // Adjust control size to vertically fit the bitmap wxWindow* ctrl = GetControl(); @@ -137,7 +136,7 @@ bool wxBitmapComboBoxBase::OnAddBitmap(const wxBitmapBundle& bitmap) DetermineIndent(); } - wxCHECK_MSG( width == m_usedImgSize.x && height == m_usedImgSize.y, + wxCHECK_MSG( bmpDefaultSize == m_usedImgSize, false, "you can only add images of same size" ); @@ -155,7 +154,7 @@ int wxBitmapComboBoxBase::DetermineIndent() if ( m_usedImgSize.x > 0 ) { - indent = GetControl()->FromDIP(m_usedImgSize.x) + indent = m_usedImgSize.x + GetControl()->FromDIP(IMAGE_SPACING_LEFT) + GetControl()->FromDIP(IMAGE_SPACING_RIGHT); m_imgAreaWidth = indent;