1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/withimages.h
3 // Purpose: Declaration of a simple wxWithImages class.
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_WITHIMAGES_H_
11 #define _WX_WITHIMAGES_H_
15 #include "wx/imaglist.h"
17 // ----------------------------------------------------------------------------
18 // wxWithImages: mix-in class providing access to wxImageList.
19 // ----------------------------------------------------------------------------
21 class WXDLLIMPEXP_CORE wxWithImages
32 m_ownsImageList
= false;
35 virtual ~wxWithImages()
40 // Sets the image list to use, it is *not* deleted by the control.
41 virtual void SetImageList(wxImageList
* imageList
)
44 m_imageList
= imageList
;
47 // As SetImageList() but we will delete the image list ourselves.
48 void AssignImageList(wxImageList
* imageList
)
50 SetImageList(imageList
);
51 m_ownsImageList
= true;
54 // Get pointer (may be NULL) to the associated image list.
55 wxImageList
* GetImageList() const { return m_imageList
; }
58 // Return true if we have a valid image list.
59 bool HasImageList() const { return m_imageList
!= NULL
; }
61 // Return the image with the given index from the image list.
63 // If there is no image list or if index == NO_IMAGE, silently returns
65 wxIcon
GetImage(int iconIndex
) const
67 return m_imageList
&& iconIndex
!= NO_IMAGE
68 ? m_imageList
->GetIcon(iconIndex
)
73 // Free the image list if necessary, i.e. if we own it.
76 if ( m_ownsImageList
)
81 // We don't own it any more.
82 m_ownsImageList
= false;
87 // The associated image list or NULL.
88 wxImageList
* m_imageList
;
90 // False by default, if true then we delete m_imageList.
93 wxDECLARE_NO_COPY_CLASS(wxWithImages
);
96 #endif // _WX_WITHIMAGES_H_