From 6c017076276a8f4f4dc00f22eb779d6682d1f68d Mon Sep 17 00:00:00 2001 From: Artur Sochirca Date: Wed, 13 Sep 2017 18:13:49 +0300 Subject: [PATCH] Don't use wxTreeCtrl item insertion workaround under modern MSW Don't refresh the control unnecessarily after inserting the first child node when using modern (i.e. post-XP) MSW version, this just slows down inserting of the first child item in big trees. Closes https://github.com/wxWidgets/wxWidgets/pull/555 --- src/msw/treectrl.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 7b706d442e..db3f171292 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -1505,10 +1505,17 @@ wxTreeItemId wxTreeCtrl::DoInsertAfter(const wxTreeItemId& parent, tvIns.item.lParam = (LPARAM)param; tvIns.item.mask = mask; - // don't use the hack below for the children of hidden root: this results - // in a crash inside comctl32.dll when we call TreeView_GetItemRect() - const bool firstChild = !IsHiddenRoot(parent) && - !TreeView_GetChild(GetHwnd(), HITEM(parent)); + // apparently some Windows versions (2000 and XP are reported to do this) + // sometimes don't refresh the tree after adding the first child and so we + // need this to make the "[+]" appear + // + // don't use this hack below for the children of hidden root nor for modern + // MSW versions as it would just unnecessarily slow down the item insertion + // at best + const bool refreshFirstChild = + (wxGetWinVersion() < wxWinVersion_Vista) && + !IsHiddenRoot(parent) && + !TreeView_GetChild(GetHwnd(), HITEM(parent)); HTREEITEM id = TreeView_InsertItem(GetHwnd(), &tvIns); if ( id == 0 ) @@ -1516,10 +1523,7 @@ wxTreeItemId wxTreeCtrl::DoInsertAfter(const wxTreeItemId& parent, wxLogLastError(wxT("TreeView_InsertItem")); } - // apparently some Windows versions (2000 and XP are reported to do this) - // sometimes don't refresh the tree after adding the first child and so we - // need this to make the "[+]" appear - if ( firstChild ) + if ( refreshFirstChild ) { TVGetItemRectParam param2;