X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/84140dc956d0f29350c239329f2e8bb1fd49963f..0bd2681966523df88ad5cf8e505b532843e58d74:/src/generic/bmpcboxg.cpp diff --git a/src/generic/bmpcboxg.cpp b/src/generic/bmpcboxg.cpp index fb993f38ad..a9b1eb0a3e 100644 --- a/src/generic/bmpcboxg.cpp +++ b/src/generic/bmpcboxg.cpp @@ -4,7 +4,7 @@ // Author: Jaakko Salli // Modified by: // Created: Aug-31-2006 -// RCS-ID: $Id: +// RCS-ID: $Id$ // Copyright: (c) 2005 Jaakko Salli // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -66,7 +66,7 @@ const wxChar wxBitmapComboBoxNameStr[] = wxT("bitmapComboBox"); BEGIN_EVENT_TABLE(wxBitmapComboBox, wxOwnerDrawnComboBox) - EVT_SIZE(wxBitmapComboBox::OnResize) + EVT_SIZE(wxBitmapComboBox::OnSize) END_EVENT_TABLE() @@ -146,6 +146,9 @@ bool wxBitmapComboBox::Create(wxWindow *parent, void wxBitmapComboBox::PostCreate() { m_fontHeight = GetCharHeight() + EXTRA_FONT_HEIGHT; + + while ( m_bitmaps.GetCount() < GetCount() ) + m_bitmaps.Add( new wxBitmap() ); } wxBitmapComboBox::~wxBitmapComboBox() @@ -159,7 +162,7 @@ wxBitmapComboBox::~wxBitmapComboBox() void wxBitmapComboBox::SetItemBitmap(unsigned int n, const wxBitmap& bitmap) { - wxCHECK_RET( n < m_bitmaps.size(), wxT("invalid item index") ); + wxCHECK_RET( n < GetCount(), wxT("invalid item index") ); OnAddBitmap(bitmap); *GetBitmapPtr(n) = bitmap; @@ -169,27 +172,90 @@ void wxBitmapComboBox::SetItemBitmap(unsigned int n, const wxBitmap& bitmap) wxBitmap wxBitmapComboBox::GetItemBitmap(unsigned int n) const { - wxCHECK_MSG( n < m_bitmaps.size(), wxNullBitmap, wxT("invalid item index") ); + wxCHECK_MSG( n < GetCount(), wxNullBitmap, wxT("invalid item index") ); return *GetBitmapPtr(n); } +int wxBitmapComboBox::DoInsertItems(const wxArrayStringsAdapter & items, + unsigned int pos, + void **clientData, wxClientDataType type) +{ + const unsigned int numItems = items.GetCount(); + const unsigned int countNew = GetCount() + numItems; + + m_bitmaps.Alloc(countNew); + + for ( unsigned int i = 0; i < numItems; ++i ) + { + m_bitmaps.Insert(new wxBitmap(wxNullBitmap), pos + i); + } + + const int index = wxOwnerDrawnComboBox::DoInsertItems(items, pos, + clientData, type); + + if ( index == wxNOT_FOUND ) + { + for ( int i = countNew - GetCount(); i > 0; --i ) + { + wxBitmap *bmp = GetBitmapPtr(pos); + m_bitmaps.RemoveAt(pos); + delete bmp; + } + } + return index; +} + +int wxBitmapComboBox::Append(const wxString& item, const wxBitmap& bitmap) +{ + const int n = wxOwnerDrawnComboBox::Append(item); + if(n != wxNOT_FOUND) + SetItemBitmap(n, bitmap); + return n; +} + +int wxBitmapComboBox::Append(const wxString& item, const wxBitmap& bitmap, + void *clientData) +{ + const int n = wxOwnerDrawnComboBox::Append(item, clientData); + if(n != wxNOT_FOUND) + SetItemBitmap(n, bitmap); + return n; +} + +int wxBitmapComboBox::Append(const wxString& item, const wxBitmap& bitmap, + wxClientData *clientData) +{ + const int n = wxOwnerDrawnComboBox::Append(item, clientData); + if(n != wxNOT_FOUND) + SetItemBitmap(n, bitmap); + return n; +} + +int wxBitmapComboBox::Insert(const wxString& item, + const wxBitmap& bitmap, + unsigned int pos) +{ + const int n = wxOwnerDrawnComboBox::Insert(item, pos); + if(n != wxNOT_FOUND) + SetItemBitmap(n, bitmap); + return n; +} + int wxBitmapComboBox::Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos, void *clientData) { - int n = DoInsertWithImage(item, bitmap, pos); - if ( n != wxNOT_FOUND ) - SetClientData(n, clientData); - + const int n = wxOwnerDrawnComboBox::Insert(item, pos, clientData); + if(n != wxNOT_FOUND) + SetItemBitmap(n, bitmap); return n; } int wxBitmapComboBox::Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos, wxClientData *clientData) { - int n = DoInsertWithImage(item, bitmap, pos); - if ( n != wxNOT_FOUND ) - SetClientObject(n, clientData); - + const int n = wxOwnerDrawnComboBox::Insert(item, pos, clientData); + if(n != wxNOT_FOUND) + SetItemBitmap(n, bitmap); return n; } @@ -224,65 +290,9 @@ bool wxBitmapComboBox::OnAddBitmap(const wxBitmap& bitmap) return true; } -bool wxBitmapComboBox::DoInsertBitmap(const wxBitmap& bitmap, unsigned int pos) -{ - if ( !OnAddBitmap(bitmap) ) - return false; - - // NB: We must try to set the image before DoInsert or - // DoAppend because OnMeasureItem might be called - // before it returns. - m_bitmaps.Insert( new wxBitmap(bitmap), pos); - - return true; -} - -int wxBitmapComboBox::DoAppendWithImage(const wxString& item, const wxBitmap& image) -{ - unsigned int pos = m_bitmaps.size(); - - if ( !DoInsertBitmap(image, pos) ) - return wxNOT_FOUND; - - int index = wxOwnerDrawnComboBox::DoAppend(item); - - if ( index < 0 ) - index = m_bitmaps.size(); - - // Need to re-check the index incase DoAppend sorted - if ( (unsigned int) index != pos ) - { - wxBitmap* bmp = GetBitmapPtr(pos); - m_bitmaps.RemoveAt(pos); - m_bitmaps.Insert(bmp, index); - } - - return index; -} - -int wxBitmapComboBox::DoInsertWithImage(const wxString& item, - const wxBitmap& image, - unsigned int pos) -{ - if ( !DoInsertBitmap(image, pos) ) - return wxNOT_FOUND; - - return wxOwnerDrawnComboBox::DoInsert(item, pos); -} - -int wxBitmapComboBox::DoAppend(const wxString& item) -{ - return DoAppendWithImage(item, wxNullBitmap); -} - -int wxBitmapComboBox::DoInsert(const wxString& item, unsigned int pos) -{ - return DoInsertWithImage(item, wxNullBitmap, pos); -} - -void wxBitmapComboBox::Clear() +void wxBitmapComboBox::DoClear() { - wxOwnerDrawnComboBox::Clear(); + wxOwnerDrawnComboBox::DoClear(); unsigned int i; @@ -297,9 +307,9 @@ void wxBitmapComboBox::Clear() DetermineIndent(); } -void wxBitmapComboBox::Delete(unsigned int n) +void wxBitmapComboBox::DoDeleteOneItem(unsigned int n) { - wxOwnerDrawnComboBox::Delete(n); + wxOwnerDrawnComboBox::DoDeleteOneItem(n); delete GetBitmapPtr(n); m_bitmaps.RemoveAt(n); } @@ -317,7 +327,7 @@ void wxBitmapComboBox::DetermineIndent() if ( m_usedImgSize.x > 0 ) { - indent = m_usedImgSize.y + IMAGE_SPACING_LEFT + IMAGE_SPACING_RIGHT; + indent = m_usedImgSize.x + IMAGE_SPACING_LEFT + IMAGE_SPACING_RIGHT; m_imgAreaWidth = indent; indent -= 3; @@ -326,7 +336,7 @@ void wxBitmapComboBox::DetermineIndent() SetCustomPaintWidth(indent); } -void wxBitmapComboBox::OnResize(wxSizeEvent& event) +void wxBitmapComboBox::OnSize(wxSizeEvent& event) { // Prevent infinite looping if ( !m_inResize ) @@ -375,7 +385,8 @@ void wxBitmapComboBox::OnDrawBackground(wxDC& dc, { if ( GetCustomPaintWidth() == 0 || !(flags & wxODCB_PAINTING_SELECTED) || - item < 0 ) + item < 0 || + ( (flags & wxODCB_PAINTING_CONTROL) && (GetInternalFlags() & wxCC_FULL_BUTTON)) ) { wxOwnerDrawnComboBox::OnDrawBackground(dc, rect, item, flags); return;