]> git.saurik.com Git - wxWidgets.git/commitdiff
Document wxItemContainer::SetStringSelection() as case-insensitive.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 25 Dec 2010 13:19:00 +0000 (13:19 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 25 Dec 2010 13:19:00 +0000 (13:19 +0000)
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
interface/wx/ctrlsub.h
tests/controls/itemcontainertest.cpp

index 314a30e24efd5e7f8ea0901b881faa5acea1c46e..4ea775ec238dfa2d1af656169eecd3b18a51b891 100644 (file)
 
     Please refer to wxTextEntry documentation for the description of methods
     operating with the text entry part of the combobox and to wxItemContainer
 
     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}
 
     @beginStyleTable
     @style{wxCB_SIMPLE}
index f03910178252df5a10f3ca8abae54a83aa98ceab..3f0c41bcd3a2f2c1fa1c480aaf366a056cf12909 100644 (file)
@@ -123,12 +123,17 @@ public:
     virtual int GetSelection() const = 0;
 
     /**
     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.
 
         @param string
             The string to select.
-
         @return @true if the specified string has been selected, @false if it
                 wasn't found in the control.
     */
         @return @true if the specified string has been selected, @false if it
                 wasn't found in the control.
     */
index ad0d8982cc67306280590933b1d4947f61139efe..ab8b9807fbd75e3768168c3e83f2602658ab3d9f 100644 (file)
@@ -105,22 +105,27 @@ void ItemContainerTestCase::ItemSelection()
     testitems.Add("item 0");
     testitems.Add("item 1");
     testitems.Add("item 2");
     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);
 
     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(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());
 
     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());
 }
     CPPUNIT_ASSERT_EQUAL(2, container->GetSelection());
     CPPUNIT_ASSERT_EQUAL("item 2", container->GetStringSelection());
 }