From f9a22962e011d043f8d5c635c347e5c31f32ff22 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 26 Oct 2023 01:46:00 +0200 Subject: [PATCH] Add wxTreeCtrl::GetStateImageCount() and HasStateImages() Add these functions for consistency with SetStateImages() and to avoid using GetStateImageList() in the treectrl sample, which can now use GetStateImageCount() instead. --- include/wx/treectrl.h | 5 +++++ interface/wx/treectrl.h | 28 ++++++++++++++++++++++++++++ samples/treectrl/treetest.cpp | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/wx/treectrl.h b/include/wx/treectrl.h index d72655227e..a0579011d9 100644 --- a/include/wx/treectrl.h +++ b/include/wx/treectrl.h @@ -62,6 +62,11 @@ public: // (for example, checked/unchecked). virtual void SetStateImages(const wxVector& images) = 0; + // Simple accessors similar to the inherited from wxWithImages + // HasImages() and GetImageCount() for normal images. + bool HasStateImages() const { return m_imagesState.HasImages(); } + int GetStateImageCount() const { return m_imagesState.GetImageCount(); } + // These functions parallel {Set,Get,Assign}ImageList() methods // inherited from wxWithImages, but correspond to SetStateImages(). // As with the other functions using wxImageList, they still work but diff --git a/interface/wx/treectrl.h b/interface/wx/treectrl.h index 5fafa5efd8..30fa4fb572 100644 --- a/interface/wx/treectrl.h +++ b/interface/wx/treectrl.h @@ -699,12 +699,38 @@ public: */ virtual size_t GetSelections(wxArrayTreeItemIds& selection) const; + /** + Returns the number of state images used by the control. + + Returns the number of images passed to the last call to + SetStateImages() or 0 if it had been never called. + + @see HasImages() + + @since 3.3.0 + */ + int GetStateImageCount() const; + /** Returns the state image list (from which application-defined state images are taken). + + @see HasStateImages(), GetStateImageCount() */ wxImageList* GetStateImageList() const; + /** + Returns true if the control uses any state images. + + This is equivalent to comparing GetStateImageCount() return value with + 0 but more clear. + + @see SetStateImages(), GetStateImageCount() + + @since 3.3.0 + */ + bool HasStateImages() const; + /** Calculates which (if any) item is under the given @a point, returning the tree item id at this point plus extra information @a flags. @a flags @@ -994,6 +1020,8 @@ public: resolutions for each state. If the vector is empty, no state images are shown. + @see HasStateImages(), GetStateImageCount() + @since 3.3.0 */ virtual void SetStateImages(const wxVector& images); diff --git a/samples/treectrl/treetest.cpp b/samples/treectrl/treetest.cpp index 9a8d4c7cc1..85439caf2c 100644 --- a/samples/treectrl/treetest.cpp +++ b/samples/treectrl/treetest.cpp @@ -1288,7 +1288,7 @@ void MyTreeCtrl::DoToggleState(const wxTreeItemId& item) srand (time(nullptr)); do { - nState = rand() % GetStateImageList()->GetImageCount(); + nState = rand() % GetStateImageCount(); } while (nState == state); SetItemState(item, nState);