From 48aa18c000b0133853d5bb2fa9a23b196d7ce6cd Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Mon, 9 Dec 2002 10:26:21 +0000 Subject: [PATCH] Applied patch [ 650078 ] Add better checking to wxComboBox This patch adds extra checks, checks to see and report if the provided item index is valid. An other thing: - IMHO wxComboBox::GetSelection() was wrong, I corrected this (now it behaves the same as wxMSW, don't know about wxGTK and others...). Hans Van Leemputten (hansvl) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18142 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/univ/combobox.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/univ/combobox.cpp b/src/univ/combobox.cpp index ea372f27c2..256853fbcc 100644 --- a/src/univ/combobox.cpp +++ b/src/univ/combobox.cpp @@ -724,10 +724,16 @@ void wxComboBox::SetEditable(bool editable) void wxComboBox::Clear() { GetLBox()->Clear(); + GetText()->SetValue(wxEmptyString); } void wxComboBox::Delete(int n) { + wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid index in wxComboBox::Delete") ); + + if (GetSelection() == n) + GetText()->SetValue(wxEmptyString); + GetLBox()->Delete(n); } @@ -738,11 +744,15 @@ int wxComboBox::GetCount() const wxString wxComboBox::GetString(int n) const { + wxCHECK_MSG( (n >= 0) && (n < GetCount()), wxEmptyString, _T("invalid index in wxComboBox::GetString") ); + return GetLBox()->GetString(n); } void wxComboBox::SetString(int n, const wxString& s) { + wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid index in wxComboBox::SetString") ); + GetLBox()->SetString(n, s); } @@ -753,7 +763,7 @@ int wxComboBox::FindString(const wxString& s) const void wxComboBox::Select(int n) { - wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid combobox index") ); + wxCHECK_RET( (n >= 0) && (n < GetCount()), _T("invalid index in wxComboBox::Select") ); GetLBox()->SetSelection(n); GetText()->SetValue(GetLBox()->GetString(n)); @@ -761,8 +771,15 @@ void wxComboBox::Select(int n) int wxComboBox::GetSelection() const { +#if 1 // FIXME:: What is the correct behavior? // if the current value isn't one of the listbox strings, return -1 + return GetLBox()->GetSelection(); +#else + // Why oh why is this done this way? + // It is not because the value displayed in the text can be found + // in the list that it is the item that is selected! return FindString(GetText()->GetValue()); +#endif } int wxComboBox::DoAppend(const wxString& item) -- 2.45.2