Fix wxBitmapComboBox size in high DPI

Convert hard-coded sizes to DPI depended size, remove unused size.
Implement MSWUpdateFontOnDPIChange() and update the control elements.
This commit is contained in:
Maarten Bent
2019-01-01 19:26:34 +01:00
parent 37be4adec6
commit 123da53306
3 changed files with 21 additions and 6 deletions

View File

@@ -104,6 +104,7 @@ protected:
WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const wxOVERRIDE; WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const wxOVERRIDE;
virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item) wxOVERRIDE; virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *item) wxOVERRIDE;
virtual bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item) wxOVERRIDE; virtual bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item) wxOVERRIDE;
virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI) wxOVERRIDE;
// Event handlers // Event handlers
void OnSize(wxSizeEvent& event); void OnSize(wxSizeEvent& event);

View File

@@ -68,7 +68,8 @@ void wxBitmapComboBoxBase::Init()
void wxBitmapComboBoxBase::UpdateInternals() 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() ) while ( m_bitmaps.GetCount() < GetItemContainer()->GetCount() )
m_bitmaps.Add( new wxBitmap() ); m_bitmaps.Add( new wxBitmap() );
@@ -159,7 +160,9 @@ int wxBitmapComboBoxBase::DetermineIndent()
if ( m_usedImgSize.x > 0 ) 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; m_imgAreaWidth = indent;
indent -= 3; indent -= 3;
@@ -214,9 +217,12 @@ void wxBitmapComboBoxBase::DrawItem(wxDC& dc,
wxCoord w = bmp.GetWidth(); wxCoord w = bmp.GetWidth();
wxCoord h = bmp.GetHeight(); wxCoord h = bmp.GetHeight();
const wxWindow* win = const_cast<wxBitmapComboBoxBase*>(this)->GetControl();
const int imgSpacingLeft = win->FromDIP(IMAGE_SPACING_LEFT);
// Draw the image centered // Draw the image centered
dc.DrawBitmap(bmp, 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, rect.y + (rect.height-h)/2,
true); true);
} }
@@ -235,7 +241,8 @@ wxCoord wxBitmapComboBoxBase::MeasureItem(size_t WXUNUSED(item)) const
return imgHeightArea > m_fontHeight ? imgHeightArea : m_fontHeight; return imgHeightArea > m_fontHeight ? imgHeightArea : m_fontHeight;
} }
return wxBCB_DEFAULT_ITEM_HEIGHT; const wxWindow* win = const_cast<wxBitmapComboBoxBase*>(this)->GetControl();
return win->FromDIP(wxBCB_DEFAULT_ITEM_HEIGHT);
} }
#endif // wxBITMAPCOMBOBOX_OWNERDRAWN_BASED #endif // wxBITMAPCOMBOBOX_OWNERDRAWN_BASED

View File

@@ -39,8 +39,6 @@
#include "wx/odcombo.h" #include "wx/odcombo.h"
#define IMAGE_SPACING_CTRL_VERTICAL 7 // Spacing used in control size calculation
// ============================================================================ // ============================================================================
// implementation // implementation
@@ -532,4 +530,13 @@ bool wxBitmapComboBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
return true; return true;
} }
void wxBitmapComboBox::MSWUpdateFontOnDPIChange(const wxSize& newDPI)
{
wxComboBox::MSWUpdateFontOnDPIChange(newDPI);
UpdateInternals();
RecreateControl();
}
#endif // wxUSE_BITMAPCOMBOBOX #endif // wxUSE_BITMAPCOMBOBOX