diff --git a/include/wx/generic/imaglist.h b/include/wx/generic/imaglist.h index a720c36a2d..c2da30e487 100644 --- a/include/wx/generic/imaglist.h +++ b/include/wx/generic/imaglist.h @@ -22,10 +22,11 @@ class WXDLLIMPEXP_FWD_CORE wxColour; class WXDLLIMPEXP_CORE wxGenericImageList: public wxObject { public: - wxGenericImageList() { } + wxGenericImageList(); 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..2291407a2f 100644 --- a/include/wx/msw/imaglist.h +++ b/include/wx/msw/imaglist.h @@ -32,6 +32,7 @@ public: // from icons), and the initial size of the list. wxImageList(int width, int height, bool mask = true, int initialCount = 1) { + m_hImageList = 0; Create(width, height, mask, initialCount); } virtual ~wxImageList(); @@ -58,6 +59,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 b72dd29d51..de346d3373 100644 --- a/src/generic/imaglist.cpp +++ b/src/generic/imaglist.cpp @@ -29,14 +29,26 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxGenericImageList, wxObject); wxIMPLEMENT_DYNAMIC_CLASS(wxImageList, wxGenericImageList); +wxGenericImageList::wxGenericImageList() +{ + Create(0, 0, false); +} + wxGenericImageList::wxGenericImageList( int width, int height, bool mask, int initialCount ) { (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..de3b4fe564 100644 --- a/src/msw/imaglist.cpp +++ b/src/msw/imaglist.cpp @@ -73,6 +73,8 @@ wxImageList::wxImageList() // Creates an image list bool wxImageList::Create(int width, int height, bool mask, int initial) { + wxASSERT_MSG( m_hImageList == NULL, "Recreating existing wxImageList?" ); + // Prevent from storing negative dimensions m_size = wxSize(wxMax(width, 0), wxMax(height, 0)); UINT flags = 0; @@ -100,7 +102,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 +111,11 @@ wxImageList::~wxImageList() } } +wxImageList::~wxImageList() +{ + Destroy(); +} + // ---------------------------------------------------------------------------- // wxImageList attributes // ----------------------------------------------------------------------------