From ebf5e8813ebce8c1c88d642e191316015779ee8f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 28 Apr 2022 17:24:58 +0100 Subject: [PATCH] Show images added to its wxImageList later in wxListbook again Fix a regression in 3.1.6 which resulted in not showing any images if the associated image list was empty when it was associated with the control, as HasImages() returned false in this case and so wxLC_ICON style was not set. The fix is to return true from HasImages() if we have image list even if it is currently empty, as we can't know when (or if) it will become non-empty and it's better to assume that it will be used (as nothing really catastrophic should happen if it is not used, finally) rather than not taking into account the images added to it later. Closes #22364. --- include/wx/withimages.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/wx/withimages.h b/include/wx/withimages.h index 9626cb1dca..3a1cf4f7b5 100644 --- a/include/wx/withimages.h +++ b/include/wx/withimages.h @@ -55,10 +55,17 @@ public: return m_imageList ? m_imageList->GetImageCount() : 0; } - // Return true if we have any images at all. + // Return true if we are using any images. bool HasImages() const { - return GetImageCount() != 0; + // Note that the sole presence of the image list indicates that we're + // using images, even if it is currently empty, because images can be + // added to it at any moment (it's common and valid to create an image + // list and associate it with the control first and fill it later) and + // it's better to err on the side of having the images and not showing + // anything if there are really none than decide that we don't have any + // and not show those that we do have. + return !m_images.empty() || m_imageList; } // Sets the images to use.