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.
This commit is contained in:
Vadim Zeitlin
2018-08-14 17:24:08 +02:00
parent de1322a02d
commit d9d05bc221
2 changed files with 16 additions and 2 deletions

View File

@@ -317,8 +317,10 @@ public:
virtual void DeleteAllItems(); virtual void DeleteAllItems();
/** /**
Deletes all children of the given item (but not the item itself). Note Deletes all children of the given item (but not the item itself).
that this will @b not generate any events unlike Delete() method.
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 If you have called SetItemHasChildren(), you may need to call it again
since DeleteChildren() does not automatically clear the setting. since DeleteChildren() does not automatically clear the setting.

View File

@@ -45,6 +45,7 @@ private:
CPPUNIT_TEST_SUITE( TreeCtrlTestCase ); CPPUNIT_TEST_SUITE( TreeCtrlTestCase );
WXUISIM_TEST( ItemClick ); WXUISIM_TEST( ItemClick );
CPPUNIT_TEST( DeleteItem ); CPPUNIT_TEST( DeleteItem );
CPPUNIT_TEST( DeleteChildren );
WXUISIM_TEST( LabelEdit ); WXUISIM_TEST( LabelEdit );
WXUISIM_TEST( KeyDown ); WXUISIM_TEST( KeyDown );
#ifndef __WXGTK__ #ifndef __WXGTK__
@@ -72,6 +73,7 @@ private:
void ItemClick(); void ItemClick();
void DeleteItem(); void DeleteItem();
void DeleteChildren();
void LabelEdit(); void LabelEdit();
void KeyDown(); void KeyDown();
#ifndef __WXGTK__ #ifndef __WXGTK__
@@ -275,6 +277,16 @@ void TreeCtrlTestCase::DeleteItem()
CPPUNIT_ASSERT_EQUAL(1, deleteitem.GetCount()); 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 #if wxUSE_UIACTIONSIMULATOR
void TreeCtrlTestCase::LabelEdit() void TreeCtrlTestCase::LabelEdit()