X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fdb47e62b9f47f234bb0d34aa45dd1a44fdd1cbe..4f38397bacc45417d9d710094b4b7f3c99363716:/src/generic/odcombo.cpp diff --git a/src/generic/odcombo.cpp b/src/generic/odcombo.cpp index d79d692b18..9759b33a33 100644 --- a/src/generic/odcombo.cpp +++ b/src/generic/odcombo.cpp @@ -246,19 +246,29 @@ void wxVListBoxComboPopup::SendComboBoxEvent( int selection ) // returns true if key was consumed bool wxVListBoxComboPopup::HandleKey( int keycode, bool saturate, wxChar unicode ) { + const int itemCount = GetCount(); + + // keys do nothing in the empty control and returning immediately avoids + // using invalid indices below + if ( !itemCount ) + return false; + int value = m_value; - int itemCount = GetCount(); int comboStyle = m_combo->GetWindowStyle(); // this is the character equivalent of the code - wxChar keychar=0; - if ((keycode >= WXK_SPACE) && (keycode <=255) && (keycode != WXK_DELETE) && wxIsprint(keycode)) - { - keychar = (wxChar)keycode; - } - else if (unicode>0) + wxChar keychar = 0; + if ( keycode < WXK_START ) { - keychar = unicode; + if ( unicode > 0 ) + { + if ( wxIsprint(unicode) ) + keychar = unicode; + } + else if ( wxIsprint(keycode) ) + { + keychar = (wxChar) keycode; + } } if ( keycode == WXK_DOWN || keycode == WXK_RIGHT ) @@ -281,7 +291,7 @@ bool wxVListBoxComboPopup::HandleKey( int keycode, bool saturate, wxChar unicode value-=10; StopPartialCompletion(); } - else if ( comboStyle & wxCB_READONLY ) + else if ( keychar && (comboStyle & wxCB_READONLY) ) { // Try partial completion @@ -471,7 +481,8 @@ void wxVListBoxComboPopup::Insert( const wxString& item, int pos ) } m_strings.Insert(item,pos); - m_clientDatas.Insert(NULL, pos); + if ( (int)m_clientDatas.size() >= pos ) + m_clientDatas.Insert(NULL, pos); m_widths.Insert(-1,pos); m_widthsDirty = true; @@ -1021,13 +1032,29 @@ int wxOwnerDrawnComboBox::DoInsertItems(const wxArrayStringsAdapter& items, EnsurePopupControl(); const unsigned int count = items.GetCount(); - for( unsigned int i = 0; i < count; ++i, ++pos ) + + if ( HasFlag(wxCB_SORT) ) { - GetVListBoxComboPopup()->Insert(items[i], pos); - AssignNewItemClientData(pos, clientData, i, type); + int n = pos; + + for ( unsigned int i = 0; i < count; ++i ) + { + int n = GetVListBoxComboPopup()->Append(items[i]); + AssignNewItemClientData(n, clientData, i, type); + } + + return n; } + else + { + for ( unsigned int i = 0; i < count; ++i, ++pos ) + { + GetVListBoxComboPopup()->Insert(items[i], pos); + AssignNewItemClientData(pos, clientData, i, type); + } - return pos - 1; + return pos - 1; + } } void wxOwnerDrawnComboBox::DoSetItemClientData(unsigned int n, void* clientData)