From becaeb14aee9db4455cc04c0e06bf2c352f6d458 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 6 Jan 2021 20:30:44 +0300 Subject: =?UTF-8?q?fixes=20#2655=20(=D0=9F=D0=B5=D1=80=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D1=89=D1=91=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=8E=20=D1=82=D0=B5=D1=80=D1=8F=D1=8E=D1=82=20?= =?UTF-8?q?=D1=81=D0=B2=D0=BE=D1=91=20=D1=81=D0=BE=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=B8=D0=BC=D0=BE=D0=B5=20=D0=B4=D0=BE=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mir_core/src/CCtrlTreeView.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/mir_core') diff --git a/src/mir_core/src/CCtrlTreeView.cpp b/src/mir_core/src/CCtrlTreeView.cpp index ec51000756..92b296a904 100644 --- a/src/mir_core/src/CCtrlTreeView.cpp +++ b/src/mir_core/src/CCtrlTreeView.cpp @@ -93,6 +93,23 @@ HTREEITEM CCtrlTreeView::MoveItemAbove(HTREEITEM hItem, HTREEITEM hInsertAfter, if (!GetItem(&tvis.itemex)) return nullptr; + OBJLIST arChildren(1); + for (HTREEITEM p = GetChild(hItem); p; p = GetNextSibling(p)) { + wchar_t buf[128]; + TVINSERTSTRUCT tvis2 = {}; + tvis2.itemex.mask = (UINT)-1; + tvis2.itemex.pszText = buf; + tvis2.itemex.cchTextMax = _countof(buf); + tvis2.itemex.hItem = p; + if (GetItem(&tvis2.itemex)) { + tvis2.itemex.pszText = mir_wstrdup(tvis2.itemex.pszText); + arChildren.insert(new TVINSERTSTRUCT(tvis2)); + + tvis2.itemex.lParam = 0; + SetItem(&tvis2.itemex); + } + } + // the pointed lParam will be freed inside TVN_DELETEITEM // so lets substitute it with 0 LPARAM saveOldData = tvis.itemex.lParam; @@ -102,11 +119,25 @@ HTREEITEM CCtrlTreeView::MoveItemAbove(HTREEITEM hItem, HTREEITEM hInsertAfter, // now current item contain lParam = 0 we can delete it. the memory will be kept. DeleteItem(hItem); + for (auto &it : arChildren) + DeleteItem(it->itemex.hItem); + tvis.itemex.stateMask = tvis.itemex.state; tvis.itemex.lParam = saveOldData; tvis.hParent = hParent; tvis.hInsertAfter = hInsertAfter; - return InsertItem(&tvis); + auto hNewItem = InsertItem(&tvis); + + hInsertAfter = nullptr; + for (auto &it : arChildren) { + it->hParent = hNewItem; + it->hInsertAfter = hInsertAfter; + hInsertAfter = InsertItem(it); + + mir_free(it->itemex.pszText); + } + + return hNewItem; } LRESULT CCtrlTreeView::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lParam) -- cgit v1.2.3