From: Vadim Zeitlin Date: Sun, 2 Mar 2008 14:55:43 +0000 (+0000) Subject: decouple item index from string value (patch 1905702) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/fdb47e62b9f47f234bb0d34aa45dd1a44fdd1cbe decouple item index from string value (patch 1905702) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52254 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/odcombo.h b/include/wx/odcombo.h index 7efe58f9e4..fe12434739 100644 --- a/include/wx/odcombo.h +++ b/include/wx/odcombo.h @@ -212,6 +212,8 @@ private: // Partial completion string wxString m_partialCompletionString; + wxString m_stringValue; + #if wxUSE_TIMER // Partial completion timer wxTimer m_partialCompletionTimer; diff --git a/src/generic/odcombo.cpp b/src/generic/odcombo.cpp index dc9234fc7f..d79d692b18 100644 --- a/src/generic/odcombo.cpp +++ b/src/generic/odcombo.cpp @@ -209,16 +209,15 @@ void wxVListBoxComboPopup::DismissWithEvent() Dismiss(); - wxString valStr; if ( selection != wxNOT_FOUND ) - valStr = m_strings[selection]; + m_stringValue = m_strings[selection]; else - valStr = wxEmptyString; + m_stringValue = wxEmptyString; - m_value = selection; + if ( m_stringValue != m_combo->GetValue() ) + m_combo->SetValueWithEvent(m_stringValue); - if ( valStr != m_combo->GetValue() ) - m_combo->SetValueWithEvent(valStr); + m_value = selection; SendComboBoxEvent(selection); } @@ -609,9 +608,7 @@ void wxVListBoxComboPopup::SetString( int item, const wxString& str ) wxString wxVListBoxComboPopup::GetStringValue() const { - if ( m_value >= 0 ) - return m_strings[m_value]; - return wxEmptyString; + return m_stringValue; } void wxVListBoxComboPopup::SetSelection( int item ) @@ -621,6 +618,11 @@ void wxVListBoxComboPopup::SetSelection( int item ) m_value = item; + if ( item >= 0 ) + m_stringValue = m_strings[item]; + else + m_stringValue = wxEmptyString; + if ( IsCreated() ) wxVListBox::SetSelection(item); } @@ -634,10 +636,13 @@ void wxVListBoxComboPopup::SetStringValue( const wxString& value ) { int index = m_strings.Index(value); - m_value = index; + m_stringValue = value; - if ( index >= -1 && index < (int)wxVListBox::GetItemCount() ) + if ( index >= 0 && index < (int)wxVListBox::GetItemCount() ) + { wxVListBox::SetSelection(index); + m_value = index; + } } void wxVListBoxComboPopup::CalcWidths()