]> git.saurik.com Git - wxWidgets.git/blame - include/wx/withimages.h
Revert HasModifiers() change in behaviour, add HasAnyModifiers().
[wxWidgets.git] / include / wx / withimages.h
CommitLineData
abfdefed
VZ
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"
665ec08c 15#include "wx/icon.h"
abfdefed
VZ
16#include "wx/imaglist.h"
17
18// ----------------------------------------------------------------------------
19// wxWithImages: mix-in class providing access to wxImageList.
20// ----------------------------------------------------------------------------
21
22class WXDLLIMPEXP_CORE wxWithImages
23{
24public:
1871b9fa
VZ
25 enum
26 {
27 NO_IMAGE = -1
28 };
29
abfdefed
VZ
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
58protected:
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 //
1871b9fa 64 // If there is no image list or if index == NO_IMAGE, silently returns
abfdefed
VZ
65 // wxNullIcon.
66 wxIcon GetImage(int iconIndex) const
67 {
1871b9fa
VZ
68 return m_imageList && iconIndex != NO_IMAGE
69 ? m_imageList->GetIcon(iconIndex)
70 : wxNullIcon;
abfdefed
VZ
71 }
72
73private:
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_