Move code accessing bitmaps to wxRibbonButtonBarButtonBase too

This also improves encapsulation and allows to avoid duplicating calls
to DrawButtonBarButton().
This commit is contained in:
Vadim Zeitlin 2020-02-07 19:02:24 +01:00
parent c6b3a6f2b4
commit 18e8a68c1b

View File

@ -160,6 +160,45 @@ public:
} }
} }
void GetBitmaps(wxRibbonBar* ribbon,
wxSize bitmap_size_large,
wxSize bitmap_size_small,
wxBitmap& bitmap,
wxBitmap bitmap_small) const
{
if ( barButtonImageListPos != -1 && ribbon )
{
wxImageList* buttonImageList = ribbon->GetButtonImageList(bitmap_size_large);
wxImageList* buttonSmallImageList = ribbon->GetButtonSmallImageList(bitmap_size_small);
int pos = barButtonImageListPos;
int pos_small = barButtonSmallImageListPos;
if (state & wxRIBBON_BUTTONBAR_BUTTON_DISABLED)
{
// Disabled buttons are stored after the normal ones.
pos++;
pos_small++;
}
bitmap = buttonImageList->GetBitmap(pos);
bitmap_small = buttonSmallImageList->GetBitmap(pos_small);
}
else
{
if(state & wxRIBBON_BUTTONBAR_BUTTON_DISABLED)
{
bitmap = m_bitmap_large_disabled;
bitmap_small = m_bitmap_small_disabled;
}
else
{
bitmap = m_bitmap_large;
bitmap_small = m_bitmap_small;
}
}
}
wxRibbonButtonBarButtonInstance NewInstance() wxRibbonButtonBarButtonInstance NewInstance()
{ {
wxRibbonButtonBarButtonInstance i; wxRibbonButtonBarButtonInstance i;
@ -930,6 +969,8 @@ void wxRibbonButtonBar::OnPaint(wxPaintEvent& WXUNUSED(evt))
wxRibbonButtonBarLayout* layout = m_layouts.Item(m_current_layout); wxRibbonButtonBarLayout* layout = m_layouts.Item(m_current_layout);
wxRibbonBar* const ribbon = GetAncestorRibbonBar();
size_t btn_count = layout->buttons.Count(); size_t btn_count = layout->buttons.Count();
size_t btn_i; size_t btn_i;
for(btn_i = 0; btn_i < btn_count; ++btn_i) for(btn_i = 0; btn_i < btn_count; ++btn_i)
@ -938,40 +979,12 @@ void wxRibbonButtonBar::OnPaint(wxPaintEvent& WXUNUSED(evt))
wxRibbonButtonBarButtonBase* base = button.base; wxRibbonButtonBarButtonBase* base = button.base;
wxRect rect(button.position + m_layout_offset, base->sizes[button.size].size); wxRect rect(button.position + m_layout_offset, base->sizes[button.size].size);
wxRibbonBar* const ribbon = GetAncestorRibbonBar(); wxBitmap bitmap, bitmap_small;
if ( base->barButtonImageListPos != -1 && ribbon ) base->GetBitmaps(ribbon,
{ m_bitmap_size_large, m_bitmap_size_small, bitmap,
wxImageList* buttonImageList = ribbon->GetButtonImageList(m_bitmap_size_large); bitmap_small);
wxImageList* buttonSmallImageList = ribbon->GetButtonSmallImageList(m_bitmap_size_small); m_art->DrawButtonBarButton(dc, this, rect, base->kind,
base->state | button.size, base->label, bitmap, bitmap_small);
wxBitmap bitmap;
wxBitmap bitmap_small;
if (base->state & wxRIBBON_BUTTONBAR_BUTTON_DISABLED)
{
bitmap = buttonImageList->GetBitmap(base->barButtonImageListPos+1);
bitmap_small = buttonSmallImageList->GetBitmap(base->barButtonSmallImageListPos+1);
}
else
{
bitmap = buttonImageList->GetBitmap(base->barButtonImageListPos);
bitmap_small = buttonSmallImageList->GetBitmap(base->barButtonSmallImageListPos);
}
m_art->DrawButtonBarButton(dc, this, rect, base->kind,
base->state | button.size, base->label, bitmap, bitmap_small);
}
else
{
wxBitmap* bitmap = &base->m_bitmap_large;
wxBitmap* bitmap_small = &base->m_bitmap_small;
if(base->state & wxRIBBON_BUTTONBAR_BUTTON_DISABLED)
{
bitmap = &base->m_bitmap_large_disabled;
bitmap_small = &base->m_bitmap_small_disabled;
}
m_art->DrawButtonBarButton(dc, this, rect, base->kind,
base->state | button.size, base->label, *bitmap, *bitmap_small);
}
} }
} }