From 884c3a2dc2912acdf5cf45b8d97f1c679b5635b3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 7 Feb 2020 17:44:08 +0100 Subject: [PATCH] Use wxImageList in wxRibbonBar unconditionally There shouldn't be any reason not to do it other than possible bugs in wxImageList itself, that should be fixed there. --- include/wx/ribbon/bar.h | 8 ++------ interface/wx/ribbon/bar.h | 22 ---------------------- src/ribbon/bar.cpp | 27 +++++++++++---------------- src/ribbon/buttonbar.cpp | 8 ++++---- 4 files changed, 17 insertions(+), 48 deletions(-) diff --git a/include/wx/ribbon/bar.h b/include/wx/ribbon/bar.h index 76d36a31b7..db30dfcbe8 100644 --- a/include/wx/ribbon/bar.h +++ b/include/wx/ribbon/bar.h @@ -154,12 +154,9 @@ public: void HideIfExpanded(); - void UseImageList(bool useImageList = true) { m_useImageList = useImageList; } - bool UsesImageList() const { return m_useImageList; } // Implementation only. - wxImageList* GetButtonImageList(wxSize* isize = NULL); - // Implementation only. - wxImageList* GetButtonSmallImageList(wxSize* isize = NULL); + wxImageList* GetButtonImageList(wxSize size); + wxImageList* GetButtonSmallImageList(wxSize size); protected: friend class wxRibbonPage; @@ -217,7 +214,6 @@ protected: wxRibbonDisplayMode m_ribbon_state; - bool m_useImageList; wxImageList* m_buttonImageList; wxImageList* m_buttonSmallImageList; diff --git a/interface/wx/ribbon/bar.h b/interface/wx/ribbon/bar.h index acd040998a..615d07e30b 100644 --- a/interface/wx/ribbon/bar.h +++ b/interface/wx/ribbon/bar.h @@ -453,26 +453,4 @@ public: Also calls wxRibbonPage::Realize() on each child page. */ virtual bool Realize(); - - /** - If the ribbon bar has many buttons, wxImageList can be used to reduce - bitmap resources. Call SetUseImageList after creating the ribbon bar, - and any subsequent AddButton or InsertButton calls will have their - images stored in an image list instead. Note that the conversion might - cause some images created from icons with alpha layers to have a black - background. Such images need to be edited before use. - - @since 3.1.4 - */ - void UseImageList(bool useImageList = true); - - /** - Returns whether a wxImageList is being used for buttons. - - @see SetUseImageList() - - @since 3.1.4 - */ - bool UsesImageList() const; - }; diff --git a/src/ribbon/bar.cpp b/src/ribbon/bar.cpp index 8ed66a313f..fefcffdccd 100644 --- a/src/ribbon/bar.cpp +++ b/src/ribbon/bar.cpp @@ -736,7 +736,6 @@ wxRibbonBar::wxRibbonBar() m_tab_scroll_buttons_shown = false; m_arePanelsShown = true; m_help_button_hovered = false; - m_useImageList = false; m_buttonImageList = NULL; m_buttonSmallImageList = NULL; @@ -755,14 +754,9 @@ wxRibbonBar::wxRibbonBar(wxWindow* parent, wxRibbonBar::~wxRibbonBar() { SetArtProvider(NULL); - if (m_buttonImageList) - { - delete m_buttonImageList; m_buttonImageList = NULL; - } - if (m_buttonSmallImageList) - { - delete m_buttonSmallImageList; m_buttonSmallImageList = NULL; - } + + delete m_buttonImageList; + delete m_buttonSmallImageList; } bool wxRibbonBar::Create(wxWindow* parent, @@ -812,25 +806,26 @@ void wxRibbonBar::CommonInit(long style) m_ribbon_state = wxRIBBON_BAR_PINNED; - m_useImageList = false; m_buttonImageList = NULL; m_buttonSmallImageList = NULL; } -wxImageList* wxRibbonBar::GetButtonImageList(wxSize* isize) +wxImageList* wxRibbonBar::GetButtonImageList(wxSize size) { - if (m_useImageList && m_buttonImageList == NULL) + if ( !m_buttonImageList ) { - m_buttonImageList = new wxImageList(isize->GetWidth(), isize->GetHeight(), /*mask*/false); + m_buttonImageList = new wxImageList(size.GetWidth(), size.GetHeight(), + /*mask*/false); } return m_buttonImageList; } -wxImageList* wxRibbonBar::GetButtonSmallImageList(wxSize* isize) +wxImageList* wxRibbonBar::GetButtonSmallImageList(wxSize size) { - if (m_useImageList && m_buttonSmallImageList == NULL) + if ( !m_buttonSmallImageList ) { - m_buttonSmallImageList = new wxImageList(isize->GetWidth(), isize->GetHeight(), /*mask*/false); + m_buttonSmallImageList = new wxImageList(size.GetWidth(), size.GetHeight(), + /*mask*/false); } return m_buttonSmallImageList; } diff --git a/src/ribbon/buttonbar.cpp b/src/ribbon/buttonbar.cpp index d4946a1aee..201e467d50 100644 --- a/src/ribbon/buttonbar.cpp +++ b/src/ribbon/buttonbar.cpp @@ -352,8 +352,8 @@ wxRibbonButtonBarButtonBase* wxRibbonButtonBar::InsertButton( wxImageList* buttonSmallImageList = NULL; if (m_ownerRibbonBar) { - buttonImageList = m_ownerRibbonBar->GetButtonImageList(&m_bitmap_size_large); - buttonSmallImageList = m_ownerRibbonBar->GetButtonSmallImageList(&m_bitmap_size_small); + buttonImageList = m_ownerRibbonBar->GetButtonImageList(m_bitmap_size_large); + buttonSmallImageList = m_ownerRibbonBar->GetButtonSmallImageList(m_bitmap_size_small); } if (base->bitmap_large.IsOk() && buttonImageList) { @@ -882,8 +882,8 @@ void wxRibbonButtonBar::OnPaint(wxPaintEvent& WXUNUSED(evt)) wxRect rect(button.position + m_layout_offset, base->sizes[button.size].size); if (base->barButtonImageListPos != -1 && m_ownerRibbonBar) { - wxImageList* buttonImageList = m_ownerRibbonBar->GetButtonImageList(); - wxImageList* buttonSmallImageList = m_ownerRibbonBar->GetButtonSmallImageList(); + wxImageList* buttonImageList = m_ownerRibbonBar->GetButtonImageList(m_bitmap_size_large); + wxImageList* buttonSmallImageList = m_ownerRibbonBar->GetButtonSmallImageList(m_bitmap_size_small); wxBitmap bitmap; wxBitmap bitmap_small;