diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index facf98e1b0..ea207b6719 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -1313,7 +1313,20 @@ bool wxPGProperty::SetValueFromInt( long number, int argFlags ) wxSize wxPGProperty::OnMeasureImage( int WXUNUSED(item) ) const { if ( m_valueBitmap ) - return wxSize(m_valueBitmap->GetWidth(), wxDefaultCoord); + { + wxPropertyGrid* pg = GetGrid(); + double scale = 1.0; + if ( pg ) + { + int hMax = pg->GetImageSize().GetHeight(); + if ( m_valueBitmap->GetHeight() > hMax ) + { + scale = (double)hMax / m_valueBitmap->GetHeight(); + } + } + + return wxSize(wxRound(scale*m_valueBitmap->GetWidth()), wxDefaultCoord); + } return wxSize(0,0); } @@ -1343,11 +1356,23 @@ void wxPGProperty::OnCustomPaint( wxDC& dc, const wxRect& rect, wxPGPaintData& ) { - wxBitmap* bmp = m_valueBitmap; + wxCHECK_RET( m_valueBitmap && m_valueBitmap->IsOk(), wxS("invalid bitmap") ); - wxCHECK_RET( bmp && bmp->IsOk(), wxS("invalid bitmap") ); + wxBitmap scaledBmp; + int yOfs; + if ( m_valueBitmap->GetHeight() <= rect.height ) + { + scaledBmp = *m_valueBitmap; + yOfs = (rect.height - m_valueBitmap->GetHeight()) / 2; + } + else + { + double scale = (double)rect.height / m_valueBitmap->GetHeight(); + scaledBmp = wxPropertyGrid::RescaleBitmap(*m_valueBitmap, scale, scale); + yOfs = 0; + } - dc.DrawBitmap(*bmp,rect.x,rect.y); + dc.DrawBitmap(scaledBmp,rect.x, rect.y + yOfs); } const wxPGEditor* wxPGProperty::DoGetEditorClass() const @@ -2160,7 +2185,6 @@ bool wxPGProperty::RecreateEditor() void wxPGProperty::SetValueImage( wxBitmap& bmp ) { - // We need PG to obtain default image size wxCHECK_RET( GetGrid(), wxS("Cannot set image for detached property") ); @@ -2168,20 +2192,7 @@ void wxPGProperty::SetValueImage( wxBitmap& bmp ) if ( bmp.IsOk() ) { - // Resize the image - wxSize maxSz = GetGrid()->GetImageSize(); - wxSize imSz = bmp.GetSize(); - - if ( imSz.y != maxSz.y ) - { - double scaleY = (double)maxSz.y / (double)imSz.y; - m_valueBitmap = new wxBitmap(wxPropertyGrid::RescaleBitmap(bmp, scaleY, scaleY)); - } - else - { - m_valueBitmap = new wxBitmap(bmp); - } - + m_valueBitmap = new wxBitmap(bmp); m_flags |= wxPG_PROP_CUSTOMIMAGE; } else