wxBitmapComboBox: store bitmaps in wxVector

This commit is contained in:
Alexander Koshelev
2022-02-07 15:44:00 +03:00
committed by Vadim Zeitlin
parent d225b8d56c
commit d57bc78eea
3 changed files with 22 additions and 27 deletions

View File

@@ -97,7 +97,7 @@ protected:
void UpdateInternals();
wxArrayPtrVoid m_bitmapbundles;// Images associated with items
wxVector<wxBitmapBundle> m_bitmapbundles;// Images associated with items
wxSize m_usedImgSize; // Size of bitmaps
int m_imgAreaWidth; // Width and height of area next to text field

View File

@@ -47,10 +47,6 @@ const char wxBitmapComboBoxNameStr[] = "bitmapComboBox";
#define wxBCB_DEFAULT_ITEM_HEIGHT 13
// This macros allows wxArrayPtrVoid to be used in more convenient manner
#define GetBitmapBundlePtr(n) ((wxBitmapBundle*)m_bitmapbundles[n])
// ----------------------------------------------------------------------------
// Initialization
// ----------------------------------------------------------------------------
@@ -68,8 +64,8 @@ void wxBitmapComboBoxBase::UpdateInternals()
m_fontHeight = GetControl()->GetCharHeight()
+ GetControl()->FromDIP(EXTRA_FONT_HEIGHT);
while ( m_bitmapbundles.GetCount() < GetItemContainer()->GetCount() )
m_bitmapbundles.Add( new wxBitmapBundle() );
while ( m_bitmapbundles.size() < GetItemContainer()->GetCount() )
m_bitmapbundles.push_back( wxBitmapBundle() );
}
// ----------------------------------------------------------------------------
@@ -79,13 +75,13 @@ void wxBitmapComboBoxBase::UpdateInternals()
void wxBitmapComboBoxBase::DoSetItemBitmap(unsigned int n, const wxBitmapBundle& bitmap)
{
wxCHECK_RET( n < m_bitmapbundles.size(), "invalid item index" );
*GetBitmapBundlePtr(n) = bitmap;
m_bitmapbundles.at(n) = bitmap;
}
wxBitmap wxBitmapComboBoxBase::GetItemBitmap(unsigned int n) const
{
wxCHECK_MSG( n < m_bitmapbundles.size(), wxNullBitmap, "invalid item index" );
return (*GetBitmapBundlePtr(n)).GetBitmapFor(
return m_bitmapbundles.at(n).GetBitmapFor(
const_cast<wxBitmapComboBoxBase*>(this)->GetControl()
);
}
@@ -96,10 +92,7 @@ wxBitmap wxBitmapComboBoxBase::GetItemBitmap(unsigned int n) const
void wxBitmapComboBoxBase::BCBDoClear()
{
for ( unsigned i = 0; i < m_bitmapbundles.size(); i++ )
delete GetBitmapBundlePtr(i);
m_bitmapbundles.Empty();
m_bitmapbundles.clear();
m_usedImgSize.x = -1;
m_usedImgSize.y = -1;
@@ -109,8 +102,10 @@ void wxBitmapComboBoxBase::BCBDoClear()
void wxBitmapComboBoxBase::BCBDoDeleteOneItem(unsigned int n)
{
delete GetBitmapBundlePtr(n);
m_bitmapbundles.RemoveAt(n);
if ( n < m_bitmapbundles.size() )
{
m_bitmapbundles.erase(m_bitmapbundles.begin() + n);
}
}
// ----------------------------------------------------------------------------
@@ -211,7 +206,7 @@ void wxBitmapComboBoxBase::DrawItem(wxDC& dc,
const wxString& text,
int WXUNUSED(flags)) const
{
const wxBitmapBundle& bb = *GetBitmapBundlePtr(item);
const wxBitmapBundle& bb = m_bitmapbundles.at(item);
if ( bb.IsOk() )
{
const wxWindow* win = const_cast<wxBitmapComboBoxBase*>(this)->GetControl();

View File

@@ -332,16 +332,16 @@ int wxBitmapComboBox::DoInsertItems(const wxArrayStringsAdapter & items,
}
// Update the bitmap array.
if ( GetCount() > m_bitmapbundles.Count() )
if ( GetCount() > m_bitmapbundles.size() )
{
wxASSERT_MSG( GetCount() == m_bitmapbundles.Count() + 1,
wxASSERT_MSG( GetCount() == m_bitmapbundles.size() + 1,
wxS("Invalid wxBitmapComboBox state") );
// Control is in the normal state.
// New item has been just added.
// Insert bitmap at the given index into the array.
wxASSERT_MSG( (size_t)index <= m_bitmapbundles.Count(),
wxASSERT_MSG( (size_t)index <= m_bitmapbundles.size(),
wxS("wxBitmapComboBox item index out of bound") );
m_bitmapbundles.Insert(new wxBitmapBundle(wxNullBitmap), index);
m_bitmapbundles.insert(m_bitmapbundles.begin() + index, wxBitmapBundle());
}
else
{
@@ -350,7 +350,7 @@ int wxBitmapComboBox::DoInsertItems(const wxArrayStringsAdapter & items,
// In this case existing bitmaps are reused.
// Required and actual indices should be the same to assure
// consistency between list of items and bitmap array.
wxASSERT_MSG( (size_t)index < m_bitmapbundles.Count(),
wxASSERT_MSG( (size_t)index < m_bitmapbundles.size(),
wxS("wxBitmapComboBox item index out of bound") );
wxASSERT_MSG( (unsigned int)index == pos+i,
wxS("Invalid index for wxBitmapComboBox item") );
@@ -359,28 +359,28 @@ int wxBitmapComboBox::DoInsertItems(const wxArrayStringsAdapter & items,
}
else
{
if ( GetCount() == m_bitmapbundles.Count() )
if ( GetCount() == m_bitmapbundles.size() )
{
// Control is in the normal state.
// Just insert new bitmaps into the array.
const unsigned int countNew = GetCount() + numItems;
m_bitmapbundles.Alloc(countNew);
m_bitmapbundles.reserve(countNew);
for ( unsigned int i = 0; i < numItems; i++ )
{
m_bitmapbundles.Insert(new wxBitmapBundle(wxNullBitmap), pos + i);
m_bitmapbundles.insert(m_bitmapbundles.begin() + pos + i, wxBitmapBundle());
}
}
else
{
wxASSERT_MSG( GetCount() < m_bitmapbundles.Count(),
wxASSERT_MSG( GetCount() < m_bitmapbundles.size(),
wxS("Invalid wxBitmapComboBox state") );
// There are less items then bitmaps.
// (This can happen if control is e.g. recreated with RecreateControl).
// In this case existing bitmaps are reused.
// The whole block of inserted items should be within the range
// of indices of the existing bitmap array.
wxASSERT_MSG( pos + numItems <= m_bitmapbundles.Count(),
wxASSERT_MSG( pos + numItems <= m_bitmapbundles.size(),
wxS("wxBitmapComboBox item index out of bound") );
}