From b825c49c2eab4662c45466741e5da1b81c9a6c4c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2018 22:49:33 +0100 Subject: [PATCH] Document and test wxItemContainer::Delete() selection handling Add test checking that selection is reset when deleting the selected item or any item before, but not after, it. Also explicitly document this behaviour. --- interface/wx/ctrlsub.h | 6 ++++++ tests/controls/itemcontainertest.cpp | 27 +++++++++++++++++++++++++++ tests/controls/itemcontainertest.h | 2 ++ 3 files changed, 35 insertions(+) diff --git a/interface/wx/ctrlsub.h b/interface/wx/ctrlsub.h index 3e1d8d0da6..a9582e7b10 100644 --- a/interface/wx/ctrlsub.h +++ b/interface/wx/ctrlsub.h @@ -354,6 +354,12 @@ public: failure in debug builds) to remove an item with the index negative or greater or equal than the number of items in the control. + If there is a currently selected item below the item being deleted, + i.e. if GetSelection() returns a valid index greater than or equal to + @a n, the selection is invalidated when this function is called. + However if the selected item appears before the item being deleted, the + selection is preserved unchanged. + @param n The zero-based item index. diff --git a/tests/controls/itemcontainertest.cpp b/tests/controls/itemcontainertest.cpp index 874e926794..ffc49d0197 100644 --- a/tests/controls/itemcontainertest.cpp +++ b/tests/controls/itemcontainertest.cpp @@ -270,6 +270,33 @@ void ItemContainerTestCase::SetString() #endif } +void ItemContainerTestCase::SelectionAfterDelete() +{ + wxItemContainer * const container = GetContainer(); + + container->Append("item 0"); + container->Append("item 1"); + container->Append("item 2"); + container->Append("item 3"); + + container->SetSelection(1); + CHECK( container->GetSelection() == 1 ); + + container->Delete(3); + CHECK( container->GetSelection() == 1 ); + + container->Delete(1); + CHECK( container->GetSelection() == wxNOT_FOUND ); + + container->SetSelection(1); + container->Delete(1); + CHECK( container->GetSelection() == wxNOT_FOUND ); + + container->SetSelection(0); + container->Delete(0); + CHECK( container->GetSelection() == wxNOT_FOUND ); +} + void ItemContainerTestCase::SetSelection() { wxItemContainer * const container = GetContainer(); diff --git a/tests/controls/itemcontainertest.h b/tests/controls/itemcontainertest.h index 63923d25e8..49ca3fdcab 100644 --- a/tests/controls/itemcontainertest.h +++ b/tests/controls/itemcontainertest.h @@ -40,6 +40,7 @@ protected: CPPUNIT_TEST( Set ); \ CPPUNIT_TEST( SetSelection ); \ CPPUNIT_TEST( SetString ); \ + CPPUNIT_TEST( SelectionAfterDelete ); \ WXUISIM_TEST( SimSelect ); void Append(); @@ -52,6 +53,7 @@ protected: void Set(); void SetSelection(); void SetString(); + void SelectionAfterDelete(); #if wxUSE_UIACTIONSIMULATOR virtual void SimSelect(); #endif