mirror of
https://github.com/reactos/reactos.git
synced 2025-02-20 15:35:04 +00:00
[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
This commit is contained in:
parent
621439d6f2
commit
bb67913156
2 changed files with 53 additions and 68 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 *);
|
||||
|
|
Loading…
Reference in a new issue