From 325641898272f1d9380ffe877bc27569fcf758bf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 25 Dec 2010 13:19:00 +0000 Subject: [PATCH] Document wxItemContainer::SetStringSelection() as case-insensitive. Add unit tests checking that the behaviour really corresponds to the documentation too. And also mention that it's not a good idea to have strings differing by case only in wxComboBox anyhow. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66442 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- interface/wx/combobox.h | 5 ++++- interface/wx/ctrlsub.h | 11 ++++++++--- tests/controls/itemcontainertest.cpp | 13 +++++++++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/interface/wx/combobox.h b/interface/wx/combobox.h index 314a30e24e..4ea775ec23 100644 --- a/interface/wx/combobox.h +++ b/interface/wx/combobox.h @@ -23,7 +23,10 @@ Please refer to wxTextEntry documentation for the description of methods operating with the text entry part of the combobox and to wxItemContainer - for the methods operating with the list of strings. + for the methods operating with the list of strings. Notice that at least + under MSW wxComboBox doesn't behave correctly if it contains strings + differing in case only so portable programs should avoid adding such + strings to this control. @beginStyleTable @style{wxCB_SIMPLE} diff --git a/interface/wx/ctrlsub.h b/interface/wx/ctrlsub.h index f039101782..3f0c41bcd3 100644 --- a/interface/wx/ctrlsub.h +++ b/interface/wx/ctrlsub.h @@ -123,12 +123,17 @@ public: virtual int GetSelection() const = 0; /** - Selects the item with the specified string in the control. This doesn't - cause any command events to be emitted. + Selects the item with the specified string in the control. + + This method doesn't cause any command events to be emitted. + + Notice that this method is case-insensitive, i.e. the string is + compared with all the elements of the control case-insensitively and + the first matching entry is selected, even if it doesn't have exactly + the same case as this string and there is an exact match afterwards. @param string The string to select. - @return @true if the specified string has been selected, @false if it wasn't found in the control. */ diff --git a/tests/controls/itemcontainertest.cpp b/tests/controls/itemcontainertest.cpp index ad0d8982cc..ab8b9807fb 100644 --- a/tests/controls/itemcontainertest.cpp +++ b/tests/controls/itemcontainertest.cpp @@ -105,22 +105,27 @@ void ItemContainerTestCase::ItemSelection() testitems.Add("item 0"); testitems.Add("item 1"); testitems.Add("item 2"); - testitems.Add("item 3"); + testitems.Add("ITEM 2"); // The same as the last one except for case. container->Append(testitems); container->SetSelection(wxNOT_FOUND); - CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, container->GetSelection()); CPPUNIT_ASSERT_EQUAL("", container->GetStringSelection()); container->SetSelection(1); - CPPUNIT_ASSERT_EQUAL(1, container->GetSelection()); CPPUNIT_ASSERT_EQUAL("item 1", container->GetStringSelection()); - container->SetStringSelection("item 2"); + CPPUNIT_ASSERT( container->SetStringSelection("item 2") ); + CPPUNIT_ASSERT_EQUAL(2, container->GetSelection()); + CPPUNIT_ASSERT_EQUAL("item 2", container->GetStringSelection()); + + // Check that selecting a non-existent item fails. + CPPUNIT_ASSERT( !container->SetStringSelection("bloordyblop") ); + // Check that SetStringSelection() is case-insensitive. + CPPUNIT_ASSERT( container->SetStringSelection("ITEM 2") ); CPPUNIT_ASSERT_EQUAL(2, container->GetSelection()); CPPUNIT_ASSERT_EQUAL("item 2", container->GetStringSelection()); } -- 2.47.2