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.
This commit is contained in:
parent
18e8a68c1b
commit
10c49631a3
@ -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<wxImageList*> m_image_lists;
|
||||
|
||||
#ifndef SWIG
|
||||
wxDECLARE_CLASS(wxRibbonBar);
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user