https://git.reactos.org/?p=reactos.git;a=commitdiff;h=bb67913156f6a7b2a734c…
commit bb67913156f6a7b2a734cf4dc2ce2c9c09b3c6df
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Fri Feb 17 12:29:30 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Feb 17 12:29:30 2023 +0900
[BROWSEUI] Add CAddressEditBox::RefreshAddress and use it (#5062)
Follow-up of #5026 [BROWSEUI] Execute command line from address bar. Elegantly reset
the address bar after command line execution. CORE-15453
---
dll/win32/browseui/addresseditbox.cpp | 120 +++++++++++++++-------------------
dll/win32/browseui/addresseditbox.h | 1 +
2 files changed, 53 insertions(+), 68 deletions(-)
diff --git a/dll/win32/browseui/addresseditbox.cpp
b/dll/win32/browseui/addresseditbox.cpp
index e1faf69b38f..6051b43fb5b 100644
--- a/dll/win32/browseui/addresseditbox.cpp
+++ b/dll/win32/browseui/addresseditbox.cpp
@@ -104,6 +104,52 @@ BOOL CAddressEditBox::GetComboBoxText(CComHeapPtr<WCHAR>&
pszText)
return fCombobox.GetWindowText(pszText, cchMax);
}
+HRESULT CAddressEditBox::RefreshAddress()
+{
+ /* Get the current pidl of the browser */
+ CComHeapPtr<ITEMIDLIST> absolutePIDL;
+ HRESULT hr = GetAbsolutePidl(&absolutePIDL);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ /* Fill the combobox */
+ ATLASSERT(absolutePIDL != NULL);
+ PopulateComboBox(absolutePIDL);
+
+ /* Get pShellFolder and pidlChild */
+ CComPtr<IShellFolder> pShellFolder;
+ PCITEMID_CHILD pidlChild;
+ hr = SHBindToParent(absolutePIDL, IID_PPV_ARG(IShellFolder, &pShellFolder),
&pidlChild);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ /* Get ready to set the displayed item */
+ COMBOBOXEXITEMW item = { CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_TEXT |
CBEIF_LPARAM };
+ item.iItem = -1; /* -1 to specify the displayed item */
+ item.iImage = SHMapPIDLToSystemImageListIndex(pShellFolder, pidlChild,
&item.iSelectedImage);
+
+ /* Set the path if filesystem; otherwise use the name */
+ WCHAR szPathOrName[MAX_PATH];
+ if (!SHGetPathFromIDListW(absolutePIDL, szPathOrName))
+ {
+ STRRET ret;
+ hr = pShellFolder->GetDisplayNameOf(pidlChild, SHGDN_FORADDRESSBAR |
SHGDN_FORPARSING, &ret);
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+
+ hr = StrRetToBufW(&ret, pidlChild, szPathOrName, _countof(szPathOrName));
+ if (FAILED_UNEXPECTEDLY(hr))
+ return hr;
+ }
+ item.pszText = szPathOrName;
+
+ /* Ownership of absolutePIDL will be moved to fCombobox. See CBEN_DELETEITEM */
+ item.lParam = reinterpret_cast<LPARAM>(absolutePIDL.Detach());
+
+ fCombobox.SendMessage(CBEM_SETITEM, 0, reinterpret_cast<LPARAM>(&item)); /*
Set it! */
+ return S_OK;
+}
+
HRESULT CAddressEditBox::GetAbsolutePidl(PIDLIST_ABSOLUTE *pAbsolutePIDL)
{
CComPtr<IBrowserService> isb;
@@ -150,10 +196,7 @@ BOOL CAddressEditBox::ExecuteCommandLine()
if (!::ShellExecuteExW(&info)) /* Execute! */
return FALSE;
- /* Execution succeeded. Reset the combobox. */
- if (dir[0] != UNICODE_NULL)
- fCombobox.SetWindowText(dir);
-
+ RefreshAddress();
return TRUE;
}
@@ -350,6 +393,7 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::OnWinEvent(
else if (endEdit->iWhy == CBENF_ESCAPE)
{
/* Reset the contents of the combo box */
+ RefreshAddress();
}
}
else if (hdr->code == CBEN_DELETEITEM)
@@ -407,13 +451,6 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::GetIDsOfNames(
HRESULT STDMETHODCALLTYPE CAddressEditBox::Invoke(DISPID dispIdMember, REFIID riid, LCID
lcid,
WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
UINT *puArgErr)
{
- CComPtr<IShellFolder> sf;
- HRESULT hr;
- PIDLIST_ABSOLUTE absolutePIDL;
- LPCITEMIDLIST pidlChild;
- STRRET ret;
- WCHAR buf[4096];
-
if (pDispParams == NULL)
return E_INVALIDARG;
@@ -421,67 +458,14 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Invoke(DISPID
dispIdMember, REFIID ri
{
case DISPID_NAVIGATECOMPLETE2:
case DISPID_DOCUMENTCOMPLETE:
-
if (pidlLastParsed)
- ILFree(pidlLastParsed);
- pidlLastParsed = NULL;
-
- /* Get the current pidl of the browser */
- hr = GetAbsolutePidl(&absolutePIDL);
- if (FAILED(hr))
- return hr;
-
- if (!absolutePIDL)
{
- ERR("Got no PIDL, investigate me!\n");
- return S_OK;
+ ILFree(pidlLastParsed);
+ pidlLastParsed = NULL;
}
- /* Fill the combobox */
- PopulateComboBox(absolutePIDL);
-
- /* Find the current item in the combobox and select it */
- CComPtr<IShellFolder> psfDesktop;
- hr = SHGetDesktopFolder(&psfDesktop);
- if (FAILED_UNEXPECTEDLY(hr))
- return S_OK;
-
- hr = psfDesktop->GetDisplayNameOf(absolutePIDL, SHGDN_FORADDRESSBAR,
&ret);
- if (FAILED_UNEXPECTEDLY(hr))
- return S_OK;
-
- hr = StrRetToBufW(&ret, absolutePIDL, buf, 4095);
- if (FAILED_UNEXPECTEDLY(hr))
- return S_OK;
-
- int index = SendMessageW(hComboBoxEx, CB_FINDSTRINGEXACT, 0, (LPARAM)buf);
- if (index != -1)
- SendMessageW(hComboBoxEx, CB_SETCURSEL, index, 0);
-
- /* Add the item that will be visible when the combobox is not expanded */
- hr = SHBindToParent(absolutePIDL, IID_PPV_ARG(IShellFolder, &sf),
&pidlChild);
- if (FAILED_UNEXPECTEDLY(hr))
- return hr;
-
- hr = sf->GetDisplayNameOf(pidlChild, SHGDN_FORADDRESSBAR | SHGDN_FORPARSING,
&ret);
- if (FAILED_UNEXPECTEDLY(hr))
- return hr;
-
- hr = StrRetToBufW(&ret, pidlChild, buf, 4095);
- if (FAILED_UNEXPECTEDLY(hr))
- return hr;
-
- INT indexClosed, indexOpen;
- indexClosed = SHMapPIDLToSystemImageListIndex(sf, pidlChild, &indexOpen);
-
- COMBOBOXEXITEMW item = {0};
- item.mask = CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_TEXT | CBEIF_LPARAM;
- item.iItem = -1;
- item.iImage = indexClosed;
- item.iSelectedImage = indexOpen;
- item.pszText = buf;
- item.lParam = reinterpret_cast<LPARAM>(absolutePIDL);
- fCombobox.SendMessage(CBEM_SETITEM, 0,
reinterpret_cast<LPARAM>(&item));
+ RefreshAddress();
+ break;
}
return S_OK;
}
diff --git a/dll/win32/browseui/addresseditbox.h b/dll/win32/browseui/addresseditbox.h
index 1f0e003d06a..336f38ff0c9 100644
--- a/dll/win32/browseui/addresseditbox.h
+++ b/dll/win32/browseui/addresseditbox.h
@@ -51,6 +51,7 @@ private:
HRESULT GetAbsolutePidl(PIDLIST_ABSOLUTE *pAbsolutePIDL);
BOOL ExecuteCommandLine();
BOOL GetComboBoxText(CComHeapPtr<WCHAR>& pszText);
+ HRESULT RefreshAddress();
public:
// *** IShellService methods ***
virtual HRESULT STDMETHODCALLTYPE SetOwner(IUnknown *);