From d9d05bc2217ddf9e20161ffeb061a9ecd70feea4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 14 Aug 2018 17:24:08 +0200 Subject: [PATCH 1/2] Document that wxTreeCtrl::DeleteChildren() does send events Contrary to what the documentation stated previously, this function does generate the wxEVT_TREE_DELETE_ITEM events for all the items being deleted, in both MSW and generic implementations. Update the documentation and add a new unit test checking that the behaviour really conforms to it. --- interface/wx/treectrl.h | 6 ++++-- tests/controls/treectrltest.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/interface/wx/treectrl.h b/interface/wx/treectrl.h index 246165055d..bf52ba9e78 100644 --- a/interface/wx/treectrl.h +++ b/interface/wx/treectrl.h @@ -317,8 +317,10 @@ public: virtual void DeleteAllItems(); /** - Deletes all children of the given item (but not the item itself). Note - that this will @b not generate any events unlike Delete() method. + Deletes all children of the given item (but not the item itself). + + A @c wxEVT_TREE_DELETE_ITEM event will be generated for every item + being deleted. If you have called SetItemHasChildren(), you may need to call it again since DeleteChildren() does not automatically clear the setting. diff --git a/tests/controls/treectrltest.cpp b/tests/controls/treectrltest.cpp index 6f8e8ff514..1bf179deae 100644 --- a/tests/controls/treectrltest.cpp +++ b/tests/controls/treectrltest.cpp @@ -45,6 +45,7 @@ private: CPPUNIT_TEST_SUITE( TreeCtrlTestCase ); WXUISIM_TEST( ItemClick ); CPPUNIT_TEST( DeleteItem ); + CPPUNIT_TEST( DeleteChildren ); WXUISIM_TEST( LabelEdit ); WXUISIM_TEST( KeyDown ); #ifndef __WXGTK__ @@ -72,6 +73,7 @@ private: void ItemClick(); void DeleteItem(); + void DeleteChildren(); void LabelEdit(); void KeyDown(); #ifndef __WXGTK__ @@ -275,6 +277,16 @@ void TreeCtrlTestCase::DeleteItem() CPPUNIT_ASSERT_EQUAL(1, deleteitem.GetCount()); } +void TreeCtrlTestCase::DeleteChildren() +{ + EventCounter deletechildren(m_tree, wxEVT_TREE_DELETE_ITEM); + + m_tree->AppendItem(m_child1, "another grandchild"); + m_tree->DeleteChildren(m_child1); + + CHECK( deletechildren.GetCount() == 2 ); +} + #if wxUSE_UIACTIONSIMULATOR void TreeCtrlTestCase::LabelEdit() From 3c8b9589d8f1c56646d01bf26669fcdfe243ea9f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 14 Aug 2018 17:50:28 +0200 Subject: [PATCH 2/2] Test that wxTreeCtrl::DeleteAllItems() does send events This seems to be the case under all still supported MSW versions, so remove the note saying that the events might not be sent from the documentation and add a unit test verifying that they are indeed sent. --- interface/wx/treectrl.h | 8 +++++--- tests/controls/treectrltest.cpp | 13 +++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/interface/wx/treectrl.h b/interface/wx/treectrl.h index bf52ba9e78..f737d20d3c 100644 --- a/interface/wx/treectrl.h +++ b/interface/wx/treectrl.h @@ -310,9 +310,11 @@ public: virtual void Delete(const wxTreeItemId& item); /** - Deletes all items in the control. Note that this may not generate - @c EVT_TREE_DELETE_ITEM events under some Windows versions although - normally such event is generated for each removed item. + Deletes all items in the control. + + This function generates @c wxEVT_TREE_DELETE_ITEM events for each item + being deleted, including the root one if it is shown, i.e. unless + wxTR_HIDE_ROOT style is used. */ virtual void DeleteAllItems(); diff --git a/tests/controls/treectrltest.cpp b/tests/controls/treectrltest.cpp index 1bf179deae..433c32ce61 100644 --- a/tests/controls/treectrltest.cpp +++ b/tests/controls/treectrltest.cpp @@ -46,6 +46,7 @@ private: WXUISIM_TEST( ItemClick ); CPPUNIT_TEST( DeleteItem ); CPPUNIT_TEST( DeleteChildren ); + CPPUNIT_TEST( DeleteAllItems ); WXUISIM_TEST( LabelEdit ); WXUISIM_TEST( KeyDown ); #ifndef __WXGTK__ @@ -74,6 +75,7 @@ private: void ItemClick(); void DeleteItem(); void DeleteChildren(); + void DeleteAllItems(); void LabelEdit(); void KeyDown(); #ifndef __WXGTK__ @@ -271,8 +273,6 @@ void TreeCtrlTestCase::DeleteItem() wxTreeItemId todelete = m_tree->AppendItem(m_root, "deleteme"); m_tree->Delete(todelete); - // We do not test DeleteAllItems() as under some versions of Windows events - // are not generated. CPPUNIT_ASSERT_EQUAL(1, deleteitem.GetCount()); } @@ -287,6 +287,15 @@ void TreeCtrlTestCase::DeleteChildren() CHECK( deletechildren.GetCount() == 2 ); } +void TreeCtrlTestCase::DeleteAllItems() +{ + EventCounter deleteall(m_tree, wxEVT_TREE_DELETE_ITEM); + + m_tree->DeleteAllItems(); + + CHECK( deleteall.GetCount() == 4 ); +} + #if wxUSE_UIACTIONSIMULATOR void TreeCtrlTestCase::LabelEdit()