diff --git a/include/wx/bmpcbox.h b/include/wx/bmpcbox.h index 25cc727e26..e380660213 100644 --- a/include/wx/bmpcbox.h +++ b/include/wx/bmpcbox.h @@ -97,8 +97,8 @@ protected: void UpdateInternals(); - wxArrayPtrVoid m_bitmapbundles;// Images associated with items - wxSize m_usedImgSize; // Size of bitmaps + wxVector m_bitmapbundles;// Images associated with items + wxSize m_usedImgSize; // Size of bitmaps int m_imgAreaWidth; // Width and height of area next to text field int m_fontHeight; diff --git a/src/common/bmpcboxcmn.cpp b/src/common/bmpcboxcmn.cpp index fd983f6434..86a3dd6d24 100644 --- a/src/common/bmpcboxcmn.cpp +++ b/src/common/bmpcboxcmn.cpp @@ -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(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(this)->GetControl(); diff --git a/src/msw/bmpcbox.cpp b/src/msw/bmpcbox.cpp index bfec96c274..011bd4f534 100644 --- a/src/msw/bmpcbox.cpp +++ b/src/msw/bmpcbox.cpp @@ -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") ); }