From 10c49631a3b4801b209986295de1025bcd4b6113 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 7 Feb 2020 19:21:33 +0100 Subject: [PATCH] Store any number of image lists in wxRibbonBar, not just two The same wxRibbonBar can use multiple button bars with different icon sizes, so 2 image lists are not enough. But OTOH there is no need to distinguish between small and large images neither, so 2 may be also 1 too many. Instead, use however many image lists we need, depending on the size. For now, just store them in a vector and use linear search in it, instead of using a map or, maybe, sorted vector, as we suppose there are never going to be more than a couple of elements in this vector anyhow. --- include/wx/ribbon/bar.h | 9 +++++---- src/ribbon/bar.cpp | 32 ++++++++++++-------------------- src/ribbon/buttonbar.cpp | 6 +++--- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/include/wx/ribbon/bar.h b/include/wx/ribbon/bar.h index db30dfcbe8..142e1bab3b 100644 --- a/include/wx/ribbon/bar.h +++ b/include/wx/ribbon/bar.h @@ -20,6 +20,8 @@ class WXDLLIMPEXP_FWD_CORE wxImageList; #include "wx/ribbon/control.h" #include "wx/ribbon/page.h" +#include "wx/vector.h" + enum wxRibbonBarOption { wxRIBBON_BAR_SHOW_PAGE_LABELS = 1 << 0, @@ -154,9 +156,9 @@ public: void HideIfExpanded(); - // Implementation only. + // Return the image list containing images of the given size, creating it + // if necessary. wxImageList* GetButtonImageList(wxSize size); - wxImageList* GetButtonSmallImageList(wxSize size); protected: friend class wxRibbonPage; @@ -214,8 +216,7 @@ protected: wxRibbonDisplayMode m_ribbon_state; - wxImageList* m_buttonImageList; - wxImageList* m_buttonSmallImageList; + wxVector m_image_lists; #ifndef SWIG wxDECLARE_CLASS(wxRibbonBar); diff --git a/src/ribbon/bar.cpp b/src/ribbon/bar.cpp index fefcffdccd..df2d57e1e8 100644 --- a/src/ribbon/bar.cpp +++ b/src/ribbon/bar.cpp @@ -736,8 +736,6 @@ wxRibbonBar::wxRibbonBar() m_tab_scroll_buttons_shown = false; m_arePanelsShown = true; m_help_button_hovered = false; - m_buttonImageList = NULL; - m_buttonSmallImageList = NULL; } @@ -755,8 +753,10 @@ wxRibbonBar::~wxRibbonBar() { SetArtProvider(NULL); - delete m_buttonImageList; - delete m_buttonSmallImageList; + for ( size_t n = 0; n < m_image_lists.size(); ++n ) + { + delete m_image_lists[n]; + } } bool wxRibbonBar::Create(wxWindow* parent, @@ -805,29 +805,21 @@ void wxRibbonBar::CommonInit(long style) m_bar_hovered = false; m_ribbon_state = wxRIBBON_BAR_PINNED; - - m_buttonImageList = NULL; - m_buttonSmallImageList = NULL; } wxImageList* wxRibbonBar::GetButtonImageList(wxSize size) { - if ( !m_buttonImageList ) + for ( size_t n = 0; n < m_image_lists.size(); ++n ) { - m_buttonImageList = new wxImageList(size.GetWidth(), size.GetHeight(), - /*mask*/false); + if ( m_image_lists[n]->GetSize() == size ) + return m_image_lists[n]; } - return m_buttonImageList; -} -wxImageList* wxRibbonBar::GetButtonSmallImageList(wxSize size) -{ - if ( !m_buttonSmallImageList ) - { - m_buttonSmallImageList = new wxImageList(size.GetWidth(), size.GetHeight(), - /*mask*/false); - } - return m_buttonSmallImageList; + wxImageList* const + il = new wxImageList(size.GetWidth(), size.GetHeight(), /*mask*/false); + m_image_lists.push_back(il); + + return il; } void wxRibbonBar::SetArtProvider(wxRibbonArtProvider* art) diff --git a/src/ribbon/buttonbar.cpp b/src/ribbon/buttonbar.cpp index 643f4cfbea..6ef786c656 100644 --- a/src/ribbon/buttonbar.cpp +++ b/src/ribbon/buttonbar.cpp @@ -151,7 +151,7 @@ public: } wxImageList* const - buttonSmallImageList = ribbon->GetButtonSmallImageList(bitmap_size_small); + buttonSmallImageList = ribbon->GetButtonImageList(bitmap_size_small); barButtonSmallImageListPos = buttonSmallImageList->Add(m_bitmap_small); m_bitmap_small = wxNullBitmap; @@ -164,12 +164,12 @@ public: wxSize bitmap_size_large, wxSize bitmap_size_small, wxBitmap& bitmap, - wxBitmap bitmap_small) const + wxBitmap& bitmap_small) const { if ( barButtonImageListPos != -1 && ribbon ) { wxImageList* buttonImageList = ribbon->GetButtonImageList(bitmap_size_large); - wxImageList* buttonSmallImageList = ribbon->GetButtonSmallImageList(bitmap_size_small); + wxImageList* buttonSmallImageList = ribbon->GetButtonImageList(bitmap_size_small); int pos = barButtonImageListPos; int pos_small = barButtonSmallImageListPos;