From a4feb3fb6522d2c951031e0357eea919a09aaf2f Mon Sep 17 00:00:00 2001 From: Giannis Adamopoulos Date: Sun, 26 Oct 2014 23:46:35 +0000 Subject: [PATCH] [BROWSUI] - Fix CAddressBand::Invoke to correctly detect if an item exists in the list and select the correct item when it does. - Improve CAddressEditBox::Execute to check if the passed pidl is the one that is being displayed. - Also fix it to parse the path if needed. - Directly call CAddressEditBox::Execute when enter is pressed or the Go button is pressed - Should fix most issues with the address bar svn path=/branches/shell-experiments/; revision=65036 --- dll/win32/browseui/addressband.cpp | 10 +++- dll/win32/browseui/addresseditbox.cpp | 80 ++++++++++++++++++++++----- 2 files changed, 73 insertions(+), 17 deletions(-) diff --git a/dll/win32/browseui/addressband.cpp b/dll/win32/browseui/addressband.cpp index dc3d6c7173d..9b89069cbb0 100644 --- a/dll/win32/browseui/addressband.cpp +++ b/dll/win32/browseui/addressband.cpp @@ -489,12 +489,17 @@ HRESULT STDMETHODCALLTYPE CAddressBand::Invoke(DISPID dispIdMember, REFIID riid, oldIndex = SendMessage(m_hWnd, CB_GETCURSEL, 0, 0); + itemExists = FALSE; + pidlPrevious = NULL; + + ZeroMemory(&item, sizeof(item)); item.mask = CBEIF_LPARAM; item.iItem = 0; - itemExists = SendMessage(m_hWnd, CBEM_GETITEM, 0, reinterpret_cast(&item)); - if (itemExists) + if (SendMessage(m_hWnd, CBEM_GETITEM, 0, reinterpret_cast(&item))) { pidlPrevious = reinterpret_cast(item.lParam); + if (pidlPrevious) + itemExists = TRUE; } hr = IUnknown_QueryService(fSite, SID_STopLevelBrowser, IID_PPV_ARG(IBrowserService, &isb)); @@ -520,6 +525,7 @@ HRESULT STDMETHODCALLTYPE CAddressBand::Invoke(DISPID dispIdMember, REFIID riid, if (itemExists) { result = SendMessage(m_hWnd, CBEM_SETITEM, 0, reinterpret_cast(&item)); + oldIndex = 0; if (result) { diff --git a/dll/win32/browseui/addresseditbox.cpp b/dll/win32/browseui/addresseditbox.cpp index 12b9d520b89..97094d161dd 100644 --- a/dll/win32/browseui/addresseditbox.cpp +++ b/dll/win32/browseui/addresseditbox.cpp @@ -149,30 +149,72 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Execute(long paramC) { HRESULT hr; + /* + * Parse the path is it wasn't parsed + */ + if (!pidlLastParsed) + ParseNow(0); + if (!pidlLastParsed) return E_FAIL; + /* + * Get the IShellBrowser and IBrowserService interfaces of the shell browser + */ CComPtr pisb; hr = IUnknown_QueryService(fSite, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &pisb)); + if (FAILED(hr)) + return hr; + + CComPtr pbs; + pisb->QueryInterface(IID_PPV_ARG(IBrowserService, &pbs)); + if (FAILED(hr)) + return hr; + + /* + * Get the current pidl of the shellbrowser and check if it is the same with the parsed one + */ + PIDLIST_ABSOLUTE pidl; + hr = pbs->GetPidl(&pidl); + if (FAILED(hr)) + return hr; + + CComPtr psf; + hr = SHGetDesktopFolder(&psf); + if (FAILED(hr)) + return hr; + + hr = psf->CompareIDs(0, pidl, pidlLastParsed); + + SHFree(pidl); + if (hr == 0) + return S_OK; + + /* + * Attempt to browse to the parsed pidl + */ + hr = pisb->BrowseObject(pidlLastParsed, 0); if (SUCCEEDED(hr)) - { - hr = pisb->BrowseObject(pidlLastParsed, 0); - if (FAILED_UNEXPECTEDLY(hr)) - { - HWND topLevelWindow; - LPCITEMIDLIST pidlChild; - CComPtr sf; - CComPtr pisb; + return hr; - hr = IUnknown_QueryService(fSite, SID_SShellBrowser, IID_PPV_ARG(IShellBrowser, &pisb)); + /* + * Browsing to the pidl failed so it's not a folder. So invoke its defaule command. + */ + HWND topLevelWindow; + hr = IUnknown_GetWindow(pisb, &topLevelWindow); + if (FAILED(hr)) + return hr; - IUnknown_GetWindow(pisb, &topLevelWindow); + LPCITEMIDLIST pidlChild; + CComPtr sf; + hr = SHBindToParent(pidlLastParsed, IID_PPV_ARG(IShellFolder, &sf), &pidlChild); + if (FAILED(hr)) + return hr; - hr = SHBindToParent(pidlLastParsed, IID_PPV_ARG(IShellFolder, &sf), &pidlChild); + hr = SHInvokeDefaultCommand(topLevelWindow, sf, pidlChild); + if (FAILED(hr)) + return hr; - SHInvokeDefaultCommand(topLevelWindow, sf, pidlChild); - } - } return hr; } @@ -194,7 +236,15 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::OnWinEvent( hdr = (LPNMHDR) lParam; if (hdr->code == CBEN_ENDEDIT) { - ParseNow(0); + NMCBEENDEDITW *endEdit = (NMCBEENDEDITW*) lParam; + if (endEdit->iWhy == CBENF_RETURN) + { + Execute(0); + } + else if (endEdit->iWhy == CBENF_ESCAPE) + { + /* Reset the contents of the combo box */ + } } break; }