From f1731fd6725338fa3d3f13e547fc5971e6abdf82 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Thu, 28 Dec 2023 12:49:47 -0800 Subject: [PATCH] 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 --- src/generic/imaglist.cpp | 3 ++- tests/graphics/imagelist.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/generic/imaglist.cpp b/src/generic/imaglist.cpp index 2a768cd12f..e78522633f 100644 --- a/src/generic/imaglist.cpp +++ b/src/generic/imaglist.cpp @@ -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 ) diff --git a/tests/graphics/imagelist.cpp b/tests/graphics/imagelist.cpp index 4e564ff91a..7823009dfc 100644 --- a/tests/graphics/imagelist.cpp +++ b/tests/graphics/imagelist.cpp @@ -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]")