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:
parent
5623dce7cd
commit
6f07c007a5
@ -95,9 +95,21 @@ int wxNSComboBoxControl::GetSelectedItem() const
|
|||||||
|
|
||||||
void wxNSComboBoxControl::SetSelectedItem(int item)
|
void wxNSComboBoxControl::SetSelectedItem(int item)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG(item >= 0 && item < [m_comboBox numberOfItems], "Inavlid item index.");
|
|
||||||
SendEvents(false);
|
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);
|
SendEvents(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,12 +186,15 @@ int wxComboBox::FindString(const wxString& s, bool bCase) const
|
|||||||
|
|
||||||
wxString wxComboBox::GetString(unsigned int n) const
|
wxString wxComboBox::GetString(unsigned int n) const
|
||||||
{
|
{
|
||||||
|
wxCHECK_MSG( n < GetCount(), wxString(), "Invalid combobox index" );
|
||||||
|
|
||||||
return GetComboPeer()->GetStringAtIndex(n);
|
return GetComboPeer()->GetStringAtIndex(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxComboBox::GetStringSelection() const
|
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)
|
void wxComboBox::SetString(unsigned int n, const wxString& s)
|
||||||
|
Loading…
Reference in New Issue
Block a user