From a66e5cdb38c89e2c13b6adb384c882a9d3b0c2bd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 17 Oct 2021 01:01:26 +0100 Subject: [PATCH] Add wxImageList::Destroy() This will be useful in wxMSW implementation and seems to make sense to have as a public function, as long as we have Create(). --- include/wx/generic/imaglist.h | 1 + include/wx/msw/imaglist.h | 3 +++ interface/wx/imaglist.h | 20 +++++++++++++++++++- src/generic/imaglist.cpp | 9 ++++++++- src/msw/imaglist.cpp | 7 ++++++- 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/include/wx/generic/imaglist.h b/include/wx/generic/imaglist.h index b29c495571..c2da30e487 100644 --- a/include/wx/generic/imaglist.h +++ b/include/wx/generic/imaglist.h @@ -26,6 +26,7 @@ public: wxGenericImageList( int width, int height, bool mask = true, int initialCount = 1 ); virtual ~wxGenericImageList(); bool Create( int width, int height, bool mask = true, int initialCount = 1 ); + void Destroy(); virtual int GetImageCount() const; virtual bool GetSize( int index, int &width, int &height ) const; diff --git a/include/wx/msw/imaglist.h b/include/wx/msw/imaglist.h index f86654eb89..44078ef53a 100644 --- a/include/wx/msw/imaglist.h +++ b/include/wx/msw/imaglist.h @@ -58,6 +58,9 @@ public: // initialNumber is the initial number of images to reserve. bool Create(int width, int height, bool mask = true, int initialNumber = 1); + // Destroys the image list, Create() may then be called again later. + void Destroy(); + // Adds a bitmap, and optionally a mask bitmap. // Note that wxImageList creates *new* bitmaps, so you may delete // 'bitmap' and 'mask' after calling Add. diff --git a/interface/wx/imaglist.h b/interface/wx/imaglist.h index a0536b7bc9..9d60830add 100644 --- a/interface/wx/imaglist.h +++ b/interface/wx/imaglist.h @@ -124,11 +124,29 @@ public: int Add(const wxIcon& icon); /** - Initializes the list. See wxImageList() for details. + Initializes the list. + + See wxImageList() for details. + + This function can be called only once after creating the object using + its default ctor or after calling Destroy(). */ bool Create(int width, int height, bool mask = true, int initialCount = 1); + /** + Destroys the current list. + + This function resets the object to its initial state and does more than + just RemoveAll() in the native wxMSW version. + + After calling it, Create() may be called again to recreate the image + list, e.g. using a different size. + + @since 3.1.6 + */ + void Destroy(); + /** Draws a specified image onto a device context. diff --git a/src/generic/imaglist.cpp b/src/generic/imaglist.cpp index 83e5173ab8..de346d3373 100644 --- a/src/generic/imaglist.cpp +++ b/src/generic/imaglist.cpp @@ -39,9 +39,16 @@ wxGenericImageList::wxGenericImageList( int width, int height, bool mask, int in (void)Create(width, height, mask, initialCount); } -wxGenericImageList::~wxGenericImageList() +void wxGenericImageList::Destroy() { (void)RemoveAll(); + + // Make it invalid. + m_size = wxSize(0, 0); +} + +wxGenericImageList::~wxGenericImageList() +{ } int wxGenericImageList::GetImageCount() const diff --git a/src/msw/imaglist.cpp b/src/msw/imaglist.cpp index 65997291fc..ac20046311 100644 --- a/src/msw/imaglist.cpp +++ b/src/msw/imaglist.cpp @@ -100,7 +100,7 @@ bool wxImageList::Create(int width, int height, bool mask, int initial) return m_hImageList != 0; } -wxImageList::~wxImageList() +void wxImageList::Destroy() { if ( m_hImageList ) { @@ -109,6 +109,11 @@ wxImageList::~wxImageList() } } +wxImageList::~wxImageList() +{ + Destroy(); +} + // ---------------------------------------------------------------------------- // wxImageList attributes // ----------------------------------------------------------------------------