Return index of first added image in wxImageList::Add()

This is what MSW does. Broken in c374eefd34 (Fold wxOSX-specific wxImageList into
generic version, 2018-10-30)
See #10013
This commit is contained in:
Paul Cornett 2023-12-28 12:49:47 -08:00
parent ef326106c0
commit f1731fd672
2 changed files with 10 additions and 1 deletions

View file

@ -125,6 +125,7 @@ int wxGenericImageList::Add( const wxBitmap &bitmap )
// Cannot add image to invalid list
wxCHECK_MSG( m_size != wxSize(0, 0), -1, "Invalid image list" );
const int index = GetImageCount();
const wxSize bitmapSize = bitmap.GetSize();
// There is a special case: a bitmap may contain more than one image,
@ -155,7 +156,7 @@ int wxGenericImageList::Add( const wxBitmap &bitmap )
return -1;
}
return GetImageCount() - 1;
return index;
}
int wxGenericImageList::Add( const wxBitmap& bitmap, const wxBitmap& mask )

View file

@ -569,6 +569,14 @@ TEST_CASE_METHOD(ImageListTestCase,
CHECK(HasMaskOrAlpha(bmp2));
CHECK(bmp2.GetSize() == BITMAP_SIZE);
}
SECTION("Add 2x width image")
{
il.RemoveAll();
int idx = il.Add(wxBitmap(BITMAP_SIZE.x * 2, BITMAP_SIZE.y));
CHECK(idx == 0);
CHECK(il.GetImageCount() == 2);
}
}
TEST_CASE("ImageList:NegativeTests", "[imagelist][negative]")