From 4ed28f681fd9f88decf1b66e39ebe38feeb768bc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2018 23:00:55 +0100 Subject: [PATCH 1/6] Add a common tag for wxItemContainer-derived classes tests This makes it possible to run the tests for all controls implementing wxItemContainer interface by just passing "[item-container]" on the test command line. --- tests/controls/bitmapcomboboxtest.cpp | 8 ++------ tests/controls/checklistboxtest.cpp | 7 ++----- tests/controls/choicetest.cpp | 7 ++----- tests/controls/comboboxtest.cpp | 7 ++----- tests/controls/htmllboxtest.cpp | 7 ++----- tests/controls/listboxtest.cpp | 7 ++----- tests/controls/ownerdrawncomboboxtest.cpp | 8 ++------ tests/controls/rearrangelisttest.cpp | 7 ++----- 8 files changed, 16 insertions(+), 42 deletions(-) diff --git a/tests/controls/bitmapcomboboxtest.cpp b/tests/controls/bitmapcomboboxtest.cpp index 7ac6c112d5..0ae29e3457 100644 --- a/tests/controls/bitmapcomboboxtest.cpp +++ b/tests/controls/bitmapcomboboxtest.cpp @@ -77,12 +77,8 @@ private: wxDECLARE_NO_COPY_CLASS(BitmapComboBoxTestCase); }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( BitmapComboBoxTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BitmapComboBoxTestCase, - "BitmapComboBoxTestCase" ); +wxREGISTER_UNIT_TEST_WITH_TAGS(BitmapComboBoxTestCase, + "[BitmapComboBoxTestCase][item-container]"); void BitmapComboBoxTestCase::setUp() { diff --git a/tests/controls/checklistboxtest.cpp b/tests/controls/checklistboxtest.cpp index 27a33ccf54..1c22990298 100644 --- a/tests/controls/checklistboxtest.cpp +++ b/tests/controls/checklistboxtest.cpp @@ -46,11 +46,8 @@ private: wxDECLARE_NO_COPY_CLASS(CheckListBoxTestCase); }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( CheckListBoxTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CheckListBoxTestCase, "CheckListBoxTestCase" ); +wxREGISTER_UNIT_TEST_WITH_TAGS(CheckListBoxTestCase, + "[CheckListBoxTestCase][item-container]"); void CheckListBoxTestCase::setUp() { diff --git a/tests/controls/choicetest.cpp b/tests/controls/choicetest.cpp index eacb0e88e6..f08cf515fe 100644 --- a/tests/controls/choicetest.cpp +++ b/tests/controls/choicetest.cpp @@ -45,11 +45,8 @@ private: wxDECLARE_NO_COPY_CLASS(ChoiceTestCase); }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( ChoiceTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ChoiceTestCase, "ChoiceTestCase" ); +wxREGISTER_UNIT_TEST_WITH_TAGS(ChoiceTestCase, + "[ChoiceTestCase][item-container]"); void ChoiceTestCase::setUp() { diff --git a/tests/controls/comboboxtest.cpp b/tests/controls/comboboxtest.cpp index 6bec622644..c72373321e 100644 --- a/tests/controls/comboboxtest.cpp +++ b/tests/controls/comboboxtest.cpp @@ -88,11 +88,8 @@ private: wxDECLARE_NO_COPY_CLASS(ComboBoxTestCase); }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( ComboBoxTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComboBoxTestCase, "ComboBoxTestCase" ); +wxREGISTER_UNIT_TEST_WITH_TAGS(ComboBoxTestCase, + "[ComboBoxTestCase][item-container]"); // ---------------------------------------------------------------------------- // test initialization diff --git a/tests/controls/htmllboxtest.cpp b/tests/controls/htmllboxtest.cpp index e9a675a971..28acba6830 100644 --- a/tests/controls/htmllboxtest.cpp +++ b/tests/controls/htmllboxtest.cpp @@ -43,11 +43,8 @@ private: wxDECLARE_NO_COPY_CLASS(HtmlListBoxTestCase); }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( HtmlListBoxTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HtmlListBoxTestCase, "HtmlListBoxTestCase" ); +wxREGISTER_UNIT_TEST_WITH_TAGS(HtmlListBoxTestCase, + "[HtmlListBoxTestCase][item-container]"); void HtmlListBoxTestCase::setUp() { diff --git a/tests/controls/listboxtest.cpp b/tests/controls/listboxtest.cpp index f7e37a375d..2f89a76a50 100644 --- a/tests/controls/listboxtest.cpp +++ b/tests/controls/listboxtest.cpp @@ -68,11 +68,8 @@ private: wxDECLARE_NO_COPY_CLASS(ListBoxTestCase); }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( ListBoxTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListBoxTestCase, "ListBoxTestCase" ); +wxREGISTER_UNIT_TEST_WITH_TAGS(ListBoxTestCase, + "[ListBoxTestCase][item-container]"); //initialise the static variable bool ListBoxTestCase::ms_ownerdrawn = false; diff --git a/tests/controls/ownerdrawncomboboxtest.cpp b/tests/controls/ownerdrawncomboboxtest.cpp index abeb7a90a1..ffba96a4dc 100644 --- a/tests/controls/ownerdrawncomboboxtest.cpp +++ b/tests/controls/ownerdrawncomboboxtest.cpp @@ -75,12 +75,8 @@ private: wxDECLARE_NO_COPY_CLASS(OwnerDrawnComboBoxTestCase); }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( OwnerDrawnComboBoxTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OwnerDrawnComboBoxTestCase, - "OwnerDrawnComboBoxTestCase" ); +wxREGISTER_UNIT_TEST_WITH_TAGS(OwnerDrawnComboBoxTestCase, + "[OwnerDrawnComboBoxTestCase][item-container]"); // ---------------------------------------------------------------------------- // test initialization diff --git a/tests/controls/rearrangelisttest.cpp b/tests/controls/rearrangelisttest.cpp index ec83a40f66..e7f6038502 100644 --- a/tests/controls/rearrangelisttest.cpp +++ b/tests/controls/rearrangelisttest.cpp @@ -46,11 +46,8 @@ private: wxDECLARE_NO_COPY_CLASS(RearrangeListTestCase); }; -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( RearrangeListTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RearrangeListTestCase, "RearrangeListTestCase" ); +wxREGISTER_UNIT_TEST_WITH_TAGS(RearrangeListTestCase, + "[RearrangeListTestCase][item-container]"); void RearrangeListTestCase::setUp() { From e0e4f162827173ac0d17d0756beb5be55b09aa71 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2018 23:03:31 +0100 Subject: [PATCH 2/6] Fix a typo in ItemContainerTestCase comment No real changes, just fix a copy-and-pasto. --- tests/controls/itemcontainertest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/controls/itemcontainertest.h b/tests/controls/itemcontainertest.h index 981b6f98cf..63923d25e8 100644 --- a/tests/controls/itemcontainertest.h +++ b/tests/controls/itemcontainertest.h @@ -24,7 +24,7 @@ protected: // and this one must be overridden to return the window which implements // wxItemContainer interface -- usually it will return the same pointer as - // GetTestEntry(), just as a different type + // GetContainer(), just as a different type virtual wxWindow *GetContainerWindow() const = 0; // this should be inserted in the derived class CPPUNIT_TEST_SUITE From cdd0430b372e16f903abd1ce3bf9e385c513e6d3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2018 23:34:01 +0100 Subject: [PATCH 3/6] Remove hard TABs from documentation files No real changes. --- interface/wx/aui/framemanager.h | 2 +- interface/wx/listbox.h | 6 +++--- interface/wx/log.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/wx/aui/framemanager.h b/interface/wx/aui/framemanager.h index 0c0ba66a0f..9daa9d888a 100644 --- a/interface/wx/aui/framemanager.h +++ b/interface/wx/aui/framemanager.h @@ -908,7 +908,7 @@ public: "Safe parts" are all non-UI elements (e.g. all layout determining parameters like the size, position etc.). "Unsafe parts" (pointers to button, frame and window) are not modified by this write operation. - + @remark This method is used when loading perspectives. */ void SafeSet(wxAuiPaneInfo source); diff --git a/interface/wx/listbox.h b/interface/wx/listbox.h index 00b4c53338..7ccb4513e3 100644 --- a/interface/wx/listbox.h +++ b/interface/wx/listbox.h @@ -61,9 +61,9 @@ list is selected or the selection changes. @event{EVT_LISTBOX_DCLICK(id, func)} Process a @c wxEVT_LISTBOX_DCLICK event, when the listbox - is double-clicked. On some platforms (notably wxGTK2) - pressing the enter key is handled as an equivalent of a - double-click. + is double-clicked. On some platforms (notably wxGTK2) + pressing the enter key is handled as an equivalent of a + double-click. @endEventTable @library{wxcore} diff --git a/interface/wx/log.h b/interface/wx/log.h index a701af81af..53bb403bc6 100644 --- a/interface/wx/log.h +++ b/interface/wx/log.h @@ -801,7 +801,7 @@ public: The messages will be written in the encoding specified by the given @c wxMBConv. - The @a conv argument is only available in wxWidgets 3.1.1 and later. + The @a conv argument is only available in wxWidgets 3.1.1 and later. @note In practice, it is only advisable to specify @c wxConvUTF8 as From abc4576ffe65e8621e901e83dc92626a6ce75173 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2018 23:37:36 +0100 Subject: [PATCH 4/6] Invalidate selection after deleting wxListBox item with GTK+ 3 For consistency with the other ports, invalidate the selection when deleting the selected item or any item before it. Closes #18267. --- docs/changes.txt | 4 ++++ src/gtk/listbox.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index fc7fcb1e00..33b8cece02 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -113,6 +113,10 @@ All (GUI): - Fix wxInfoBar close button size in high DPI (Stefan Ziegler). - Make disabling the window before creating it actually work. +wxGTK: + +- Invalidate selection after deleting wxListBox item with GTK+ 3 too. + 3.1.2: (released 2018-12-10) ---------------------------- diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 0a0f6a8c0f..954fb060a0 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -497,6 +497,25 @@ void wxListBox::DoDeleteOneItem(unsigned int n) // this returns false if iter is invalid (e.g. deleting item at end) but // since we don't use iter, we ignore the return value gtk_list_store_remove(m_liststore, &iter); + +#ifdef __WXGTK3__ + // Invalidate selection in a single-selection control for consistency with + // MSW and GTK+ 2 where this happens automatically when deleting the + // selected item or any item before it. + if ( !HasMultipleSelection() ) + { + const int sel = GetSelection(); + if ( sel != wxNOT_FOUND && static_cast(sel) >= n ) + { + // Don't call SetSelection() from here, it's not totally clear if + // it is safe to do, so just do this at GTK+ level. + gtk_tree_selection_unselect_all + ( + gtk_tree_view_get_selection(m_treeview) + ); + } + } +#endif // __WXGTK3__ } // ---------------------------------------------------------------------------- From c8d2195791a752bfd046f1a9042b08ccf5340bce Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2018 23:44:01 +0100 Subject: [PATCH 5/6] Make wxSimpleHtmlListBox::Delete() consistent with wxListBox Also remove the selection when deleting the selected item, or any item before it, in this class, for consistency with the native wxListBox. --- src/generic/htmllbox.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/generic/htmllbox.cpp b/src/generic/htmllbox.cpp index 507badf53b..cc7ef82ac1 100644 --- a/src/generic/htmllbox.cpp +++ b/src/generic/htmllbox.cpp @@ -672,6 +672,18 @@ void wxSimpleHtmlListBox::Clear() void wxSimpleHtmlListBox::DoDeleteOneItem(unsigned int n) { + // For consistency with the other wxItemContainer-derived classes, deselect + // the currently selected item if it, or any item before it, is being + // deleted, from a single-selection control. + if ( !HasMultipleSelection() ) + { + const int sel = GetSelection(); + if ( sel != wxNOT_FOUND && static_cast(sel) >= n ) + { + SetSelection(wxNOT_FOUND); + } + } + m_items.RemoveAt(n); m_HTMLclientData.RemoveAt(n); From b825c49c2eab4662c45466741e5da1b81c9a6c4c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Dec 2018 22:49:33 +0100 Subject: [PATCH 6/6] 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