Don't allow adding image to invalid wxImageList (generic)

Native wxMSW implementation doesn't allow to do this.
This commit is contained in:
Artur Wieczorek
2021-04-04 21:07:15 +02:00
parent 4b7ca0b33d
commit f1c3ff4037

View File

@@ -150,16 +150,14 @@ wxBitmap GetImageListBitmap(const wxBitmap& bitmap, bool useMask, const wxSize&
int wxGenericImageList::Add( const wxBitmap &bitmap ) int wxGenericImageList::Add( const wxBitmap &bitmap )
{ {
// We use the scaled, i.e. logical, size here as image list images size is // Cannot add image to invalid list
// specified in logical pixels, just as window coordinates and sizes are.
const wxSize bitmapSize = bitmap.GetScaledSize();
if ( m_size == wxSize(0, 0) ) if ( m_size == wxSize(0, 0) )
return -1;
if ( m_images.empty() )
{ {
// This is the first time Add() is called and we hadn't had any fixed // This is the first time Add() is called so we should save
// size: adopt the size of our first bitmap as image size. // scale factor to check if further images will have the same scaling
m_size = bitmapSize;
// Save scale factor to check if all images have the same scaling
m_scaleFactor = bitmap.GetScaleFactor(); m_scaleFactor = bitmap.GetScaleFactor();
} }
else if ( bitmap.GetScaleFactor() != m_scaleFactor ) else if ( bitmap.GetScaleFactor() != m_scaleFactor )
@@ -168,6 +166,10 @@ int wxGenericImageList::Add( const wxBitmap &bitmap )
return -1; return -1;
} }
// We use the scaled, i.e. logical, size here as image list images size is
// specified in logical pixels, just as window coordinates and sizes are.
const wxSize bitmapSize = bitmap.GetScaledSize();
// There is a special case: a bitmap may contain more than one image, // There is a special case: a bitmap may contain more than one image,
// in which case we're supposed to chop it in parts, just as Windows // in which case we're supposed to chop it in parts, just as Windows
// ImageList_Add() does. // ImageList_Add() does.