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:
@@ -20,6 +20,8 @@ class WXDLLIMPEXP_FWD_CORE wxImageList;
|
|||||||
#include "wx/ribbon/control.h"
|
#include "wx/ribbon/control.h"
|
||||||
#include "wx/ribbon/page.h"
|
#include "wx/ribbon/page.h"
|
||||||
|
|
||||||
|
#include "wx/vector.h"
|
||||||
|
|
||||||
enum wxRibbonBarOption
|
enum wxRibbonBarOption
|
||||||
{
|
{
|
||||||
wxRIBBON_BAR_SHOW_PAGE_LABELS = 1 << 0,
|
wxRIBBON_BAR_SHOW_PAGE_LABELS = 1 << 0,
|
||||||
@@ -154,9 +156,9 @@ public:
|
|||||||
|
|
||||||
void HideIfExpanded();
|
void HideIfExpanded();
|
||||||
|
|
||||||
// Implementation only.
|
// Return the image list containing images of the given size, creating it
|
||||||
|
// if necessary.
|
||||||
wxImageList* GetButtonImageList(wxSize size);
|
wxImageList* GetButtonImageList(wxSize size);
|
||||||
wxImageList* GetButtonSmallImageList(wxSize size);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class wxRibbonPage;
|
friend class wxRibbonPage;
|
||||||
@@ -214,8 +216,7 @@ protected:
|
|||||||
|
|
||||||
wxRibbonDisplayMode m_ribbon_state;
|
wxRibbonDisplayMode m_ribbon_state;
|
||||||
|
|
||||||
wxImageList* m_buttonImageList;
|
wxVector<wxImageList*> m_image_lists;
|
||||||
wxImageList* m_buttonSmallImageList;
|
|
||||||
|
|
||||||
#ifndef SWIG
|
#ifndef SWIG
|
||||||
wxDECLARE_CLASS(wxRibbonBar);
|
wxDECLARE_CLASS(wxRibbonBar);
|
||||||
|
@@ -736,8 +736,6 @@ wxRibbonBar::wxRibbonBar()
|
|||||||
m_tab_scroll_buttons_shown = false;
|
m_tab_scroll_buttons_shown = false;
|
||||||
m_arePanelsShown = true;
|
m_arePanelsShown = true;
|
||||||
m_help_button_hovered = false;
|
m_help_button_hovered = false;
|
||||||
m_buttonImageList = NULL;
|
|
||||||
m_buttonSmallImageList = NULL;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -755,8 +753,10 @@ wxRibbonBar::~wxRibbonBar()
|
|||||||
{
|
{
|
||||||
SetArtProvider(NULL);
|
SetArtProvider(NULL);
|
||||||
|
|
||||||
delete m_buttonImageList;
|
for ( size_t n = 0; n < m_image_lists.size(); ++n )
|
||||||
delete m_buttonSmallImageList;
|
{
|
||||||
|
delete m_image_lists[n];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxRibbonBar::Create(wxWindow* parent,
|
bool wxRibbonBar::Create(wxWindow* parent,
|
||||||
@@ -805,29 +805,21 @@ void wxRibbonBar::CommonInit(long style)
|
|||||||
m_bar_hovered = false;
|
m_bar_hovered = false;
|
||||||
|
|
||||||
m_ribbon_state = wxRIBBON_BAR_PINNED;
|
m_ribbon_state = wxRIBBON_BAR_PINNED;
|
||||||
|
|
||||||
m_buttonImageList = NULL;
|
|
||||||
m_buttonSmallImageList = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxImageList* wxRibbonBar::GetButtonImageList(wxSize size)
|
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(),
|
if ( m_image_lists[n]->GetSize() == size )
|
||||||
/*mask*/false);
|
return m_image_lists[n];
|
||||||
}
|
}
|
||||||
return m_buttonImageList;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxImageList* wxRibbonBar::GetButtonSmallImageList(wxSize size)
|
wxImageList* const
|
||||||
{
|
il = new wxImageList(size.GetWidth(), size.GetHeight(), /*mask*/false);
|
||||||
if ( !m_buttonSmallImageList )
|
m_image_lists.push_back(il);
|
||||||
{
|
|
||||||
m_buttonSmallImageList = new wxImageList(size.GetWidth(), size.GetHeight(),
|
return il;
|
||||||
/*mask*/false);
|
|
||||||
}
|
|
||||||
return m_buttonSmallImageList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxRibbonBar::SetArtProvider(wxRibbonArtProvider* art)
|
void wxRibbonBar::SetArtProvider(wxRibbonArtProvider* art)
|
||||||
|
@@ -151,7 +151,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxImageList* const
|
wxImageList* const
|
||||||
buttonSmallImageList = ribbon->GetButtonSmallImageList(bitmap_size_small);
|
buttonSmallImageList = ribbon->GetButtonImageList(bitmap_size_small);
|
||||||
|
|
||||||
barButtonSmallImageListPos = buttonSmallImageList->Add(m_bitmap_small);
|
barButtonSmallImageListPos = buttonSmallImageList->Add(m_bitmap_small);
|
||||||
m_bitmap_small = wxNullBitmap;
|
m_bitmap_small = wxNullBitmap;
|
||||||
@@ -164,12 +164,12 @@ public:
|
|||||||
wxSize bitmap_size_large,
|
wxSize bitmap_size_large,
|
||||||
wxSize bitmap_size_small,
|
wxSize bitmap_size_small,
|
||||||
wxBitmap& bitmap,
|
wxBitmap& bitmap,
|
||||||
wxBitmap bitmap_small) const
|
wxBitmap& bitmap_small) const
|
||||||
{
|
{
|
||||||
if ( barButtonImageListPos != -1 && ribbon )
|
if ( barButtonImageListPos != -1 && ribbon )
|
||||||
{
|
{
|
||||||
wxImageList* buttonImageList = ribbon->GetButtonImageList(bitmap_size_large);
|
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 = barButtonImageListPos;
|
||||||
int pos_small = barButtonSmallImageListPos;
|
int pos_small = barButtonSmallImageListPos;
|
||||||
|
Reference in New Issue
Block a user