diff options
author | George Hazan <ghazan@miranda.im> | 2021-01-06 20:30:44 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-01-06 20:30:50 +0300 |
commit | becaeb14aee9db4455cc04c0e06bf2c352f6d458 (patch) | |
tree | e9d46e4abd9e64801f0ab73333eab3475b917fd2 /src | |
parent | 03132e1d9813b9250944969a5f55ec8cc452b114 (diff) |
fixes #2655 (Перемещённые подменю теряют своё содержимое до применения изменений)
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_core/src/CCtrlTreeView.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
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<TVINSERTSTRUCT> 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) |