Fix selection corner cases in wxOSX wxComboBox.

Don't crash in wxComboBox::GetString() if it's passed an invalid index.

Don't call GetString() with invalid index from GetStringSelection() if there
is no selection.

Do accept wxNOT_FOUND in SetSelectedItem() as it means, according to the docs,
that the existing selection should be reset.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65384 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2010-08-22 22:15:32 +00:00
parent 5623dce7cd
commit 6f07c007a5
2 changed files with 18 additions and 3 deletions

View File

@ -95,9 +95,21 @@ int wxNSComboBoxControl::GetSelectedItem() const
void wxNSComboBoxControl::SetSelectedItem(int item)
{
wxASSERT_MSG(item >= 0 && item < [m_comboBox numberOfItems], "Inavlid item index.");
SendEvents(false);
[m_comboBox selectItemAtIndex: item];
if ( item != wxNOT_FOUND )
{
wxASSERT_MSG( item >= 0 && item < [m_comboBox numberOfItems],
"Inavlid item index." );
[m_comboBox selectItemAtIndex: item];
}
else // remove current selection (if we have any)
{
const int sel = GetSelectedItem();
if ( sel != wxNOT_FOUND )
[m_comboBox deselectItemAtIndex:sel];
}
SendEvents(true);
}

View File

@ -186,12 +186,15 @@ int wxComboBox::FindString(const wxString& s, bool bCase) const
wxString wxComboBox::GetString(unsigned int n) const
{
wxCHECK_MSG( n < GetCount(), wxString(), "Invalid combobox index" );
return GetComboPeer()->GetStringAtIndex(n);
}
wxString wxComboBox::GetStringSelection() const
{
return GetString(GetSelection());
const int sel = GetSelection();
return sel == wxNOT_FOUND ? wxString() : GetString(sel);
}
void wxComboBox::SetString(unsigned int n, const wxString& s)