]> git.saurik.com Git - wxWidgets.git/blob - include/wx/withimages.h
Convert wxFSW_EVENT_{WARNING,ERROR} to string correctly.
[wxWidgets.git] / include / wx / withimages.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/withimages.h
3 // Purpose: Declaration of a simple wxWithImages class.
4 // Author: Vadim Zeitlin
5 // Created: 2011-08-17
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 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_WITHIMAGES_H_
12 #define _WX_WITHIMAGES_H_
13
14 #include "wx/defs.h"
15 #include "wx/icon.h"
16 #include "wx/imaglist.h"
17
18 // ----------------------------------------------------------------------------
19 // wxWithImages: mix-in class providing access to wxImageList.
20 // ----------------------------------------------------------------------------
21
22 class WXDLLIMPEXP_CORE wxWithImages
23 {
24 public:
25 enum
26 {
27 NO_IMAGE = -1
28 };
29
30 wxWithImages()
31 {
32 m_imageList = NULL;
33 m_ownsImageList = false;
34 }
35
36 virtual ~wxWithImages()
37 {
38 FreeIfNeeded();
39 }
40
41 // Sets the image list to use, it is *not* deleted by the control.
42 virtual void SetImageList(wxImageList* imageList)
43 {
44 FreeIfNeeded();
45 m_imageList = imageList;
46 }
47
48 // As SetImageList() but we will delete the image list ourselves.
49 void AssignImageList(wxImageList* imageList)
50 {
51 SetImageList(imageList);
52 m_ownsImageList = true;
53 }
54
55 // Get pointer (may be NULL) to the associated image list.
56 wxImageList* GetImageList() const { return m_imageList; }
57
58 protected:
59 // Return true if we have a valid image list.
60 bool HasImageList() const { return m_imageList != NULL; }
61
62 // Return the image with the given index from the image list.
63 //
64 // If there is no image list or if index == NO_IMAGE, silently returns
65 // wxNullIcon.
66 wxIcon GetImage(int iconIndex) const
67 {
68 return m_imageList && iconIndex != NO_IMAGE
69 ? m_imageList->GetIcon(iconIndex)
70 : wxNullIcon;
71 }
72
73 private:
74 // Free the image list if necessary, i.e. if we own it.
75 void FreeIfNeeded()
76 {
77 if ( m_ownsImageList )
78 {
79 delete m_imageList;
80 m_imageList = NULL;
81
82 // We don't own it any more.
83 m_ownsImageList = false;
84 }
85 }
86
87
88 // The associated image list or NULL.
89 wxImageList* m_imageList;
90
91 // False by default, if true then we delete m_imageList.
92 bool m_ownsImageList;
93
94 wxDECLARE_NO_COPY_CLASS(wxWithImages);
95 };
96
97 #endif // _WX_WITHIMAGES_H_