Don't store wxImage/wxBitmap objects on the heap in wxImageFileProperty
To simplify managing the life cycle of the objects.
This commit is contained in:
@@ -296,11 +296,11 @@ public:
|
||||
const wxRect& rect, wxPGPaintData& paintdata ) wxOVERRIDE;
|
||||
|
||||
protected:
|
||||
wxBitmap* m_pBitmap; // final thumbnail area
|
||||
wxImage* m_pImage; // intermediate thumbnail area
|
||||
wxBitmap m_bitmap; // final thumbnail area
|
||||
wxImage m_image; // intermediate thumbnail area
|
||||
|
||||
private:
|
||||
// Initialize m_pImage using the current file name.
|
||||
// Initialize m_image using the current file name.
|
||||
void LoadImageFromFile();
|
||||
};
|
||||
|
||||
|
||||
@@ -250,8 +250,8 @@ public:
|
||||
const wxRect& rect, wxPGPaintData& paintdata );
|
||||
|
||||
protected:
|
||||
wxBitmap* m_pBitmap; // final thumbnail area
|
||||
wxImage* m_pImage; // intermediate thumbnail area
|
||||
wxBitmap m_bitmap; // final thumbnail area
|
||||
wxImage m_image; // intermediate thumbnail area
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1838,18 +1838,11 @@ wxImageFileProperty::wxImageFileProperty( const wxString& label, const wxString&
|
||||
{
|
||||
m_wildcard = wxPGGetDefaultImageWildcard();
|
||||
|
||||
m_pImage = NULL;
|
||||
m_pBitmap = NULL;
|
||||
|
||||
LoadImageFromFile();
|
||||
}
|
||||
|
||||
wxImageFileProperty::~wxImageFileProperty()
|
||||
{
|
||||
if ( m_pBitmap )
|
||||
delete m_pBitmap;
|
||||
if ( m_pImage )
|
||||
delete m_pImage;
|
||||
}
|
||||
|
||||
void wxImageFileProperty::OnSetValue()
|
||||
@@ -1857,8 +1850,8 @@ void wxImageFileProperty::OnSetValue()
|
||||
wxFileProperty::OnSetValue();
|
||||
|
||||
// Delete old image
|
||||
wxDELETE(m_pImage);
|
||||
wxDELETE(m_pBitmap);
|
||||
m_image = wxNullImage;
|
||||
m_bitmap = wxNullBitmap;
|
||||
|
||||
LoadImageFromFile();
|
||||
}
|
||||
@@ -1870,7 +1863,7 @@ void wxImageFileProperty::LoadImageFromFile()
|
||||
// Create the image thumbnail
|
||||
if ( filename.FileExists() )
|
||||
{
|
||||
m_pImage = new wxImage( filename.GetFullPath() );
|
||||
m_image.LoadFile(filename.GetFullPath());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1883,25 +1876,24 @@ void wxImageFileProperty::OnCustomPaint( wxDC& dc,
|
||||
const wxRect& rect,
|
||||
wxPGPaintData& )
|
||||
{
|
||||
if ( m_pBitmap || (m_pImage && m_pImage->IsOk() ) )
|
||||
if ( m_bitmap.IsOk() || m_image.IsOk() )
|
||||
{
|
||||
// Draw the thumbnail
|
||||
// Create the bitmap here because required size is not known in OnSetValue().
|
||||
|
||||
// Delete the cache if required size changed
|
||||
if ( m_pBitmap && (m_pBitmap->GetWidth() != rect.width || m_pBitmap->GetHeight() != rect.height) )
|
||||
if ( m_bitmap.IsOk() && (m_bitmap.GetWidth() != rect.width || m_bitmap.GetHeight() != rect.height) )
|
||||
{
|
||||
delete m_pBitmap;
|
||||
m_pBitmap = NULL;
|
||||
m_bitmap = wxNullBitmap;
|
||||
}
|
||||
|
||||
if ( !m_pBitmap )
|
||||
if ( !m_bitmap.IsOk() )
|
||||
{
|
||||
m_pImage->Rescale( rect.width, rect.height );
|
||||
m_pBitmap = new wxBitmap( *m_pImage );
|
||||
m_image.Rescale( rect.width, rect.height );
|
||||
m_bitmap = wxBitmap(m_image, dc);
|
||||
}
|
||||
|
||||
dc.DrawBitmap( *m_pBitmap, rect.x, rect.y, false );
|
||||
dc.DrawBitmap( m_bitmap, rect.x, rect.y, false );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user