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().
This commit is contained in:
Vadim Zeitlin
2021-10-17 01:01:26 +01:00
parent 6b3fd04e24
commit a66e5cdb38
5 changed files with 37 additions and 3 deletions

View File

@@ -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;

View File

@@ -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.

View File

@@ -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.

View File

@@ -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

View File

@@ -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
// ----------------------------------------------------------------------------