From a6b92cb313624f1d2ffe62a4eb270a4340851bb8 Mon Sep 17 00:00:00 2001 From: Igor Korot Date: Mon, 29 Jul 2019 22:40:55 -0500 Subject: [PATCH] Don't send EXPANDED in generic wxTreeCtrl if not really expanded On demand expandable items can fail to be actually expanded when the user attempts to expand them, but the generic version of wxTreeCtrl still sent an EXPANDED event in this case, which wasn't useful and differed from the native MSW version. Fix this and only send the event if the item was really expanded. Closes https://github.com/wxWidgets/wxWidgets/pull/1450 Closes #13886. --- src/generic/treectlg.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 761aa65e20..11d5283394 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -1886,8 +1886,16 @@ void wxGenericTreeCtrl::Expand(const wxTreeItemId& itemId) m_dirty = true; } - event.SetEventType(wxEVT_TREE_ITEM_EXPANDED); - GetEventHandler()->ProcessEvent( event ); + // Don't send EXPANDED event unconditionally: if this is an item for which + // SetItemHasChildren(true) had been called before, but no children have + // been added from the EXPANDING handler, we shouldn't consider the item to + // be really expanded. + wxTreeItemIdValue cookie; + if ( GetFirstChild(item, cookie).IsOk() ) + { + event.SetEventType(wxEVT_TREE_ITEM_EXPANDED); + GetEventHandler()->ProcessEvent( event ); + } } void wxGenericTreeCtrl::Collapse(const wxTreeItemId& itemId)