diff --git a/include/wx/withimages.h b/include/wx/withimages.h index 89120d3eb7..9c4d7e785c 100644 --- a/include/wx/withimages.h +++ b/include/wx/withimages.h @@ -15,7 +15,7 @@ #include "wx/imaglist.h" // ---------------------------------------------------------------------------- -// wxWithImages: mix-in class providing access to wxImageList. +// wxWithImages: mix-in for classes using indices for image access // ---------------------------------------------------------------------------- class WXDLLIMPEXP_CORE wxWithImages @@ -37,6 +37,18 @@ public: FreeIfNeeded(); } + // 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; + } + // Sets the image list to use, it is *not* deleted by the control. virtual void SetImageList(wxImageList* imageList) { diff --git a/interface/wx/withimages.h b/interface/wx/withimages.h index 3adc3e0d84..011718b22f 100644 --- a/interface/wx/withimages.h +++ b/interface/wx/withimages.h @@ -18,6 +18,27 @@ public: wxWithImages(); virtual ~wxWithImages(); + /** + Return the number of images in this control. + + The returned value may be 0 if there are no images associated with the + control. + + @see HasImages() + + @since 3.1.6 + */ + int GetImageCount() const; + + /** + Return true if the control has any images associated with it. + + @see GetImageCount() + + @since 3.1.6 + */ + bool HasImages() const; + /** Sets the image list for the page control and takes ownership of the list. diff --git a/samples/notebook/notebook.cpp b/samples/notebook/notebook.cpp index 4bfcbf563e..b009ad5f5f 100644 --- a/samples/notebook/notebook.cpp +++ b/samples/notebook/notebook.cpp @@ -157,9 +157,9 @@ wxPanel *CreateInsertPage(wxBookCtrlBase *parent) int GetIconIndex(wxBookCtrlBase* bookCtrl) { - if (bookCtrl && bookCtrl->GetImageList()) + if (bookCtrl) { - int nImages = bookCtrl->GetImageList()->GetImageCount(); + const int nImages = bookCtrl->GetImageCount(); if (nImages > 0) { return bookCtrl->GetPageCount() % nImages; diff --git a/samples/widgets/notebook.cpp b/samples/widgets/notebook.cpp index 90bb0c39e6..bafbb3251a 100644 --- a/samples/widgets/notebook.cpp +++ b/samples/widgets/notebook.cpp @@ -412,9 +412,9 @@ int BookWidgetsPage::GetTextValue(wxTextCtrl *text) const int BookWidgetsPage::GetIconIndex() const { - if ( m_imageList ) + if ( m_book ) { - int nImages = m_imageList->GetImageCount(); + const int nImages = m_book->GetImageCount(); if ( nImages > 0 ) { return m_book->GetPageCount() % nImages;