2011-08-21 10:08:43 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/withimages.h
|
|
|
|
// Purpose: Declaration of a simple wxWithImages class.
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2011-08-17
|
|
|
|
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_WITHIMAGES_H_
|
|
|
|
#define _WX_WITHIMAGES_H_
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
2011-08-21 10:52:16 -04:00
|
|
|
#include "wx/icon.h"
|
2011-08-21 10:08:43 -04:00
|
|
|
#include "wx/imaglist.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2021-10-31 12:34:44 -04:00
|
|
|
// wxWithImages: mix-in for classes using indices for image access
|
2011-08-21 10:08:43 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxWithImages
|
|
|
|
{
|
|
|
|
public:
|
2011-08-21 10:08:49 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
NO_IMAGE = -1
|
|
|
|
};
|
|
|
|
|
2011-08-21 10:08:43 -04:00
|
|
|
wxWithImages()
|
|
|
|
{
|
|
|
|
m_imageList = NULL;
|
|
|
|
m_ownsImageList = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~wxWithImages()
|
|
|
|
{
|
|
|
|
FreeIfNeeded();
|
|
|
|
}
|
|
|
|
|
2021-10-31 12:34:44 -04:00
|
|
|
// Return the number of images, possibly 0.
|
|
|
|
int GetImageCount() const
|
|
|
|
{
|
|
|
|
return m_imageList ? m_imageList->GetImageCount() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if we have any images at all.
|
|
|
|
bool HasImages() const
|
|
|
|
{
|
|
|
|
return GetImageCount() != 0;
|
|
|
|
}
|
|
|
|
|
2011-08-21 10:08:43 -04:00
|
|
|
// Sets the image list to use, it is *not* deleted by the control.
|
|
|
|
virtual void SetImageList(wxImageList* imageList)
|
|
|
|
{
|
|
|
|
FreeIfNeeded();
|
|
|
|
m_imageList = imageList;
|
|
|
|
}
|
|
|
|
|
|
|
|
// As SetImageList() but we will delete the image list ourselves.
|
|
|
|
void AssignImageList(wxImageList* imageList)
|
|
|
|
{
|
|
|
|
SetImageList(imageList);
|
|
|
|
m_ownsImageList = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get pointer (may be NULL) to the associated image list.
|
|
|
|
wxImageList* GetImageList() const { return m_imageList; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Return true if we have a valid image list.
|
|
|
|
bool HasImageList() const { return m_imageList != NULL; }
|
|
|
|
|
|
|
|
// Return the image with the given index from the image list.
|
|
|
|
//
|
2011-08-21 10:08:49 -04:00
|
|
|
// If there is no image list or if index == NO_IMAGE, silently returns
|
2011-08-21 10:08:43 -04:00
|
|
|
// wxNullIcon.
|
|
|
|
wxIcon GetImage(int iconIndex) const
|
|
|
|
{
|
2011-08-21 10:08:49 -04:00
|
|
|
return m_imageList && iconIndex != NO_IMAGE
|
|
|
|
? m_imageList->GetIcon(iconIndex)
|
|
|
|
: wxNullIcon;
|
2011-08-21 10:08:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Free the image list if necessary, i.e. if we own it.
|
|
|
|
void FreeIfNeeded()
|
|
|
|
{
|
|
|
|
if ( m_ownsImageList )
|
|
|
|
{
|
|
|
|
delete m_imageList;
|
|
|
|
m_imageList = NULL;
|
|
|
|
|
|
|
|
// We don't own it any more.
|
|
|
|
m_ownsImageList = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The associated image list or NULL.
|
|
|
|
wxImageList* m_imageList;
|
|
|
|
|
|
|
|
// False by default, if true then we delete m_imageList.
|
|
|
|
bool m_ownsImageList;
|
|
|
|
|
|
|
|
wxDECLARE_NO_COPY_CLASS(wxWithImages);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _WX_WITHIMAGES_H_
|