1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/withimages.h
3 // Purpose: Declaration of a simple wxWithImages class.
4 // Author: Vadim Zeitlin
6 // RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $
7 // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_WITHIMAGES_H_
12 #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
27 m_ownsImageList
= false;
30 virtual ~wxWithImages()
35 // Sets the image list to use, it is *not* deleted by the control.
36 virtual void SetImageList(wxImageList
* imageList
)
39 m_imageList
= imageList
;
42 // As SetImageList() but we will delete the image list ourselves.
43 void AssignImageList(wxImageList
* imageList
)
45 SetImageList(imageList
);
46 m_ownsImageList
= true;
49 // Get pointer (may be NULL) to the associated image list.
50 wxImageList
* GetImageList() const { return m_imageList
; }
53 // Return true if we have a valid image list.
54 bool HasImageList() const { return m_imageList
!= NULL
; }
56 // Return the image with the given index from the image list.
58 // If there is no image list or if index == -1 (which traditionally means
59 // that no image should be used for the given item), silently returns
61 wxIcon
GetImage(int iconIndex
) const
63 return m_imageList
&& iconIndex
!= -1 ? m_imageList
->GetIcon(iconIndex
)
68 // Free the image list if necessary, i.e. if we own it.
71 if ( m_ownsImageList
)
76 // We don't own it any more.
77 m_ownsImageList
= false;
82 // The associated image list or NULL.
83 wxImageList
* m_imageList
;
85 // False by default, if true then we delete m_imageList.
88 wxDECLARE_NO_COPY_CLASS(wxWithImages
);
91 #endif // _WX_WITHIMAGES_H_