Fix sizing wxBitmapButton used as wxPropertyGrid editor button

Since wxBitmapButton doesn't rescale embedded bitmap we need
to do this on our own to display entire bitmap even the button
is small.

Closes #18715.
This commit is contained in:
Artur Wieczorek
2020-04-10 20:33:16 +02:00
parent c7aeba7ed5
commit f95d6463d3
2 changed files with 50 additions and 6 deletions

View File

@@ -2138,9 +2138,55 @@ void wxPGMultiButton::Add( const wxBitmap& bitmap, int itemid )
{ {
itemid = GenId(itemid); itemid = GenId(itemid);
wxSize sz = GetSize(); wxSize sz = GetSize();
wxButton* button = new wxBitmapButton( this, itemid, bitmap,
wxPoint(sz.x, 0), // Internal margins around the bitmap inside the button
wxSize(sz.y, sz.y) ); const int margins =
#if defined(__WXMSW__)
2*4;
#elif defined(__WXGTK3__)
2*4;
#elif defined(__WXGTK__)
2*8;
#elif defined(__WXOSX__)
2*3;
#else
0;
#endif
// Maximal heigth of the bitmap
const int hMax = sz.y - margins;
wxBitmap scaledBmp;
// Scale bitmap down if necessary
if ( bitmap.GetHeight() > hMax )
{
double scale = (double)hMax / bitmap.GetHeight();
int w = wxRound(bitmap.GetWidth()*scale);
int h = wxRound(bitmap.GetHeight()*scale);
#if wxUSE_IMAGE
// Here we use high-quality wxImage scaling functions available
wxImage img = bitmap.ConvertToImage();
img.Rescale(w, h, wxIMAGE_QUALITY_HIGH);
scaledBmp = img;
#else // !wxUSE_IMAGE
scaledBmp.Create(w, h, bitmap.GetDepth());
#if defined(__WXMSW__) || defined(__WXOSX__)
// wxBitmap::UseAlpha() is used only on wxMSW and wxOSX.
scaledBmp.UseAlpha(bitmap.HasAlpha());
#endif // __WXMSW__ || __WXOSX__
{
wxMemoryDC dc(scaledBmp);
dc.SetUserScale(scale, scale);
dc.DrawBitmap(bitmap, 0, 0);
}
#endif // wxUSE_IMAGE/!wxUSE_IMAGE
}
else
{
scaledBmp = bitmap;
}
wxBitmapButton* button = new wxBitmapButton(this, itemid, scaledBmp,
wxPoint(sz.x, 0), wxSize(wxDefaultCoord, sz.y));
DoAddButton( button, sz ); DoAddButton( button, sz );
} }
#endif #endif

View File

@@ -1331,9 +1331,7 @@ void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing )
GetTextExtent(wxS("jG"), &x, &y, 0, 0, &m_captionFont); GetTextExtent(wxS("jG"), &x, &y, 0, 0, &m_captionFont);
m_lineHeight = m_fontHeight+(2*m_spacingy)+1; m_lineHeight = m_fontHeight+(2*m_spacingy)+1;
#if defined(__WXGTK3__)
m_lineHeight = wxMax(35, m_lineHeight);
#endif
// button spacing // button spacing
m_buttonSpacingY = (m_lineHeight - m_iconHeight) / 2; m_buttonSpacingY = (m_lineHeight - m_iconHeight) / 2;
if ( m_buttonSpacingY < 0 ) m_buttonSpacingY = 0; if ( m_buttonSpacingY < 0 ) m_buttonSpacingY = 0;