From 6f01532b81b04df7d071526fb1f11f61a7f0039d Mon Sep 17 00:00:00 2001 From: Joachim Henze Date: Sun, 2 Apr 2023 02:30:13 +0200 Subject: [PATCH] [0.4.13][BROWSEUI] Port back several fixes and tweaks 0.4.15-dev-5688-g 460a01b167066f755e5ae06ac9fbd913f73065d2 [BROWSEUI] CORE-18646 Fix crash while editing a label in the folder tree, add missing break 0.4.15-dev-5686-g a777cc2cc4768bd25190863d4aeef7cbd356841c [BROWSEUI] CORE-18646 Fix crash on backspace while editing a label in the folder panel (#5059) 0.4.15-dev-4497-g beefb07d183d289397baa1360e3fd44636db15bc [BROWSEUI] CORE-12804 Remove useless variable and unreachable code (#4483) and strip EOL whitespace --- dll/win32/browseui/explorerband.cpp | 30 ++++++++++++++++------------- dll/win32/browseui/explorerband.h | 3 ++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/dll/win32/browseui/explorerband.cpp b/dll/win32/browseui/explorerband.cpp index 76bd7aa939c..fc3ce2a2a20 100644 --- a/dll/win32/browseui/explorerband.cpp +++ b/dll/win32/browseui/explorerband.cpp @@ -81,7 +81,7 @@ HRESULT GetDisplayName(LPCITEMIDLIST pidlDirectory,TCHAR *szDisplayName,UINT cch } /* - This is a Windows hack, because shell event messages in Windows gives an + This is a Windows hack, because shell event messages in Windows gives an ill-formed PIDL stripped from useful data that parses incorrectly with SHGetFileInfo. So we need to re-enumerate subfolders until we find one with the same name. */ @@ -144,7 +144,7 @@ Cleanup: } CExplorerBand::CExplorerBand() : - pSite(NULL), fVisible(FALSE), bNavigating(FALSE), dwBandID(0), pidlCurrent(NULL) + pSite(NULL), fVisible(FALSE), bNavigating(FALSE), dwBandID(0), m_isEditing(FALSE), pidlCurrent(NULL) { } @@ -343,7 +343,7 @@ BOOL CExplorerBand::OnTreeItemDeleted(LPNMTREEVIEW pnmtv) /* Destroy memory associated to our node */ NodeInfo* ptr = GetNodeInfo(pnmtv->itemNew.hItem); if (ptr) - { + { ILFree(ptr->relativePidl); ILFree(ptr->absolutePidl); delete ptr; @@ -721,7 +721,6 @@ BOOL CExplorerBand::NavigateToPIDL(LPITEMIDLIST dest, HTREEITEM *item, BOOL bExp HTREEITEM current; HTREEITEM tmp; HTREEITEM parent; - BOOL found; NodeInfo *nodeData; LPITEMIDLIST relativeChild; TVITEM tvItem; @@ -729,10 +728,9 @@ BOOL CExplorerBand::NavigateToPIDL(LPITEMIDLIST dest, HTREEITEM *item, BOOL bExp if (!item) return FALSE; - found = FALSE; current = hRoot; parent = NULL; - while(!found) + while (TRUE) { nodeData = GetNodeInfo(current); if (!nodeData) @@ -771,7 +769,7 @@ BOOL CExplorerBand::NavigateToPIDL(LPITEMIDLIST dest, HTREEITEM *item, BOOL bExp // Try to get a child tmp = TreeView_GetChild(m_hWnd, current); if (tmp) - { + { // We have a child, let's continue with it parent = current; current = tmp; @@ -806,7 +804,6 @@ BOOL CExplorerBand::NavigateToPIDL(LPITEMIDLIST dest, HTREEITEM *item, BOOL bExp *item = NULL; return FALSE; } - return FALSE; } BOOL CExplorerBand::NavigateToCurrentFolder() @@ -815,7 +812,7 @@ BOOL CExplorerBand::NavigateToCurrentFolder() CComPtr pBrowserService; HRESULT hr; HTREEITEM dummy; - BOOL result; + BOOL result; explorerPidl = NULL; hr = IUnknown_QueryService(pSite, SID_STopLevelBrowser, IID_PPV_ARG(IBrowserService, &pBrowserService)); @@ -1136,7 +1133,7 @@ HRESULT STDMETHODCALLTYPE CExplorerBand::SetSite(IUnknown *pUnkSite) return E_INVALIDARG; } - pSite = pUnkSite; + pSite = pUnkSite; if (m_hWnd) { @@ -1214,7 +1211,8 @@ HRESULT STDMETHODCALLTYPE CExplorerBand::HasFocusIO() HRESULT STDMETHODCALLTYPE CExplorerBand::TranslateAcceleratorIO(LPMSG lpMsg) { - if (lpMsg->hwnd == m_hWnd) + if (lpMsg->hwnd == m_hWnd || + (m_isEditing && IsChild(lpMsg->hwnd))) { TranslateMessage(lpMsg); DispatchMessage(lpMsg); @@ -1291,6 +1289,7 @@ HRESULT STDMETHODCALLTYPE CExplorerBand::OnWinEvent(HWND hWnd, UINT uMsg, WPARAM case TVN_BEGINDRAG: case TVN_BEGINRDRAG: OnTreeItemDragging((LPNMTREEVIEW)lParam, pNotifyHeader->code == TVN_BEGINRDRAG); + break; case TVN_BEGINLABELEDITW: { // TODO: put this in a function ? (mostly copypasta from CDefView) @@ -1310,8 +1309,12 @@ HRESULT STDMETHODCALLTYPE CExplorerBand::OnWinEvent(HWND hWnd, UINT uMsg, WPARAM return E_FAIL; hr = pParent->GetAttributesOf(1, &pChild, &dwAttr); - if (SUCCEEDED(hr) && (dwAttr & SFGAO_CANRENAME) && theResult) - *theResult = 0; + if (SUCCEEDED(hr) && (dwAttr & SFGAO_CANRENAME)) + { + if (theResult) + *theResult = 0; + m_isEditing = TRUE; + } return S_OK; } case TVN_ENDLABELEDITW: @@ -1320,6 +1323,7 @@ HRESULT STDMETHODCALLTYPE CExplorerBand::OnWinEvent(HWND hWnd, UINT uMsg, WPARAM NodeInfo *info = GetNodeInfo(dispInfo->item.hItem); HRESULT hr; + m_isEditing = FALSE; if (theResult) *theResult = 0; if (dispInfo->item.pszText) diff --git a/dll/win32/browseui/explorerband.h b/dll/win32/browseui/explorerband.h index 33d84dde3ba..85f07c696ab 100644 --- a/dll/win32/browseui/explorerband.h +++ b/dll/win32/browseui/explorerband.h @@ -59,6 +59,7 @@ private: BOOL bNavigating; BOOL bFocused; DWORD dwBandID; + BOOL m_isEditing; HIMAGELIST hImageList; HTREEITEM hRoot; HTREEITEM oldSelected; @@ -95,7 +96,7 @@ private: HRESULT UpdateBrowser(LPITEMIDLIST pidlGoto); HTREEITEM InsertItem(HTREEITEM hParent, IShellFolder *psfParent, LPITEMIDLIST pElt, LPITEMIDLIST pEltRelative, BOOL bSort); HTREEITEM InsertItem(HTREEITEM hParent, LPITEMIDLIST pElt, LPITEMIDLIST pEltRelative, BOOL bSort); - BOOL InsertSubitems(HTREEITEM hItem, NodeInfo *pNodeInfo); + BOOL InsertSubitems(HTREEITEM hItem, NodeInfo *pNodeInfo); BOOL NavigateToPIDL(LPITEMIDLIST dest, HTREEITEM *item, BOOL bExpand, BOOL bInsert, BOOL bSelect); BOOL DeleteItem(LPITEMIDLIST toDelete); BOOL RenameItem(HTREEITEM toRename, LPITEMIDLIST newPidl);