diff --git a/dll/win32/browseui/addresseditbox.cpp b/dll/win32/browseui/addresseditbox.cpp index 7eb6581f731..ef15277a93f 100644 --- a/dll/win32/browseui/addresseditbox.cpp +++ b/dll/win32/browseui/addresseditbox.cpp @@ -1,28 +1,11 @@ /* - * ReactOS Explorer - * - * Copyright 2009 Andrew Hill - * Copyright 2023 Katayama Hirofumi MZ - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * PROJECT: ReactOS Explorer + * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) + * PURPOSE: The combo box of the address band + * COPYRIGHT: Copyright 2009 Andrew Hill + * Copyright 2023-2025 Katayama Hirofumi MZ */ -/* -This class handles the combo box of the address band. -*/ - #include "precomp.h" /* @@ -34,15 +17,12 @@ TODO: CAddressEditBox::CAddressEditBox() : fCombobox(WC_COMBOBOXEXW, this), fEditWindow(WC_EDITW, this), - fSite(NULL), - pidlLastParsed(NULL) + fSite(NULL) { } CAddressEditBox::~CAddressEditBox() { - if (pidlLastParsed) - ILFree(pidlLastParsed); } HRESULT STDMETHODCALLTYPE CAddressEditBox::SetOwner(IUnknown *pOwner) @@ -90,9 +70,11 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Init(HWND comboboxEx, HWND editContro return hResult; } -HRESULT STDMETHODCALLTYPE CAddressEditBox::SetCurrentDir(long paramC) +HRESULT STDMETHODCALLTYPE CAddressEditBox::SetCurrentDir(PCWSTR pszPath) { - return E_NOTIMPL; + m_pidlLastParsed.Free(); + m_pidlLastParsed.Attach(ILCreateFromPathW(pszPath)); + return m_pidlLastParsed ? S_OK : E_OUTOFMEMORY; } BOOL CAddressEditBox::GetComboBoxText(CComHeapPtr& pszText) @@ -196,19 +178,20 @@ BOOL CAddressEditBox::ExecuteCommandLine() HRESULT STDMETHODCALLTYPE CAddressEditBox::ParseNow(long paramC) { - ULONG eaten; - ULONG attributes; - HRESULT hr; - HWND topLevelWindow; - PIDLIST_ABSOLUTE pidlCurrent= NULL; - PIDLIST_RELATIVE pidlRelative = NULL; + ULONG eaten, attributes; + CComHeapPtr pidlCurrent; + CComHeapPtr pidlRelative; CComPtr psfCurrent; + HRESULT hr; + + ATLASSERT(!m_pidlLastParsed); CComPtr pbs; hr = IUnknown_QueryService(fSite, SID_SShellBrowser, IID_PPV_ARG(IBrowserService, &pbs)); if (FAILED_UNEXPECTEDLY(hr)) return hr; + HWND topLevelWindow; hr = IUnknown_GetWindow(pbs, &topLevelWindow); if (FAILED_UNEXPECTEDLY(hr)) return hr; @@ -231,7 +214,7 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::ParseNow(long paramC) CComPtr psfDesktop; hr = SHGetDesktopFolder(&psfDesktop); if (FAILED_UNEXPECTEDLY(hr)) - goto cleanup; + return hr; hr = pbs->GetPidl(&pidlCurrent); if (FAILED_UNEXPECTEDLY(hr)) @@ -244,18 +227,13 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::ParseNow(long paramC) hr = psfCurrent->ParseDisplayName(topLevelWindow, NULL, address, &eaten, &pidlRelative, &attributes); if (SUCCEEDED(hr)) { - pidlLastParsed = ILCombine(pidlCurrent, pidlRelative); - ILFree(pidlRelative); - goto cleanup; + m_pidlLastParsed.Attach(ILCombine(pidlCurrent, pidlRelative)); + return hr; } parseabsolute: /* We couldn't parse a relative path, attempt to parse an absolute path */ - hr = psfDesktop->ParseDisplayName(topLevelWindow, NULL, address, &eaten, &pidlLastParsed, &attributes); - -cleanup: - if (pidlCurrent) - ILFree(pidlCurrent); + hr = psfDesktop->ParseDisplayName(topLevelWindow, NULL, address, &eaten, &m_pidlLastParsed, &attributes); return hr; } @@ -277,7 +255,7 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Execute(long paramC) /* * Parse the path if it wasn't parsed */ - if (!pidlLastParsed) + if (!m_pidlLastParsed) { hr = ParseNow(0); @@ -290,7 +268,7 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Execute(long paramC) return ShowFileNotFoundError(hr); } - if (!pidlLastParsed) + if (!m_pidlLastParsed) return E_FAIL; } @@ -315,24 +293,20 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Execute(long paramC) if (FAILED(hr)) return hr; - hr = psf->CompareIDs(0, pidl, pidlLastParsed); + hr = psf->CompareIDs(0, pidl, m_pidlLastParsed); SHFree(pidl); - if (hr == 0) + if (hr == S_OK) { - if (pidlLastParsed) - { - ILFree(pidlLastParsed); - pidlLastParsed = NULL; - } + m_pidlLastParsed.Free(); return S_OK; } /* * Attempt to browse to the parsed pidl */ - hr = pisb->BrowseObject(pidlLastParsed, 0); + hr = pisb->BrowseObject(m_pidlLastParsed, 0); if (SUCCEEDED(hr)) return hr; @@ -346,7 +320,7 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Execute(long paramC) LPCITEMIDLIST pidlChild; CComPtr sf; - hr = SHBindToParent(pidlLastParsed, IID_PPV_ARG(IShellFolder, &sf), &pidlChild); + hr = SHBindToParent(m_pidlLastParsed, IID_PPV_ARG(IShellFolder, &sf), &pidlChild); if (FAILED(hr)) return hr; @@ -374,10 +348,15 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::OnWinEvent( { case WM_COMMAND: { - if (HIWORD(wParam) == CBN_SELCHANGE) + if (HIWORD(wParam) == CBN_SELCHANGE && fCombobox == (HWND)lParam) { - UINT selectedIndex = SendMessageW((HWND)lParam, CB_GETCURSEL, 0, 0); - pidlLastParsed = ILClone((LPITEMIDLIST)SendMessageW((HWND)lParam, CB_GETITEMDATA, selectedIndex, 0)); + INT iItem = (INT)fCombobox.SendMessage(CB_GETCURSEL); + PIDLIST_ABSOLUTE pidl = + (PIDLIST_ABSOLUTE)fCombobox.SendMessage(CB_GETITEMDATA, iItem); + m_pidlLastParsed.Free(); + if (pidl) + m_pidlLastParsed.Attach(ILClone(pidl)); + Execute(0); } break; @@ -460,12 +439,7 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Invoke(DISPID dispIdMember, REFIID ri { case DISPID_NAVIGATECOMPLETE2: case DISPID_DOCUMENTCOMPLETE: - if (pidlLastParsed) - { - ILFree(pidlLastParsed); - pidlLastParsed = NULL; - } - + m_pidlLastParsed.Free(); RefreshAddress(); break; } diff --git a/dll/win32/browseui/addresseditbox.h b/dll/win32/browseui/addresseditbox.h index cab0e7a5c4c..e91f129d0a0 100644 --- a/dll/win32/browseui/addresseditbox.h +++ b/dll/win32/browseui/addresseditbox.h @@ -1,21 +1,9 @@ /* - * ReactOS Explorer - * - * Copyright 2009 Andrew Hill - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * PROJECT: ReactOS Explorer + * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) + * PURPOSE: The combo box of the address band + * COPYRIGHT: Copyright 2009 Andrew Hill + * Copyright 2023-2025 Katayama Hirofumi MZ */ #pragma once @@ -37,7 +25,7 @@ private: CContainedWindow fEditWindow; DWORD fAdviseCookie; CComPtr fSite; - LPITEMIDLIST pidlLastParsed; + CComHeapPtr m_pidlLastParsed; HWND hComboBoxEx; public: CAddressEditBox(); @@ -62,7 +50,7 @@ public: // *** IAddressEditBox methods *** STDMETHOD(Init)(HWND comboboxEx, HWND editControl, long param14, IUnknown *param18) override; - STDMETHOD(SetCurrentDir)(long paramC) override; + STDMETHOD(SetCurrentDir)(PCWSTR pszPath) override; STDMETHOD(ParseNow)(long paramC) override; STDMETHOD(Execute)(long paramC) override; STDMETHOD(Save)(long paramC) override; diff --git a/sdk/include/reactos/shlobj_undoc.h b/sdk/include/reactos/shlobj_undoc.h index c7f080ede36..a8928315b55 100644 --- a/sdk/include/reactos/shlobj_undoc.h +++ b/sdk/include/reactos/shlobj_undoc.h @@ -354,7 +354,7 @@ DECLARE_INTERFACE_(IAddressEditBox, IUnknown) STDMETHOD_(ULONG,Release)(THIS) PURE; /*** IAddressEditBox ***/ STDMETHOD(Init)(THIS_ HWND comboboxEx, HWND editControl, long param14, IUnknown *param18) PURE; - STDMETHOD(SetCurrentDir)(THIS_ long paramC) PURE; + STDMETHOD(SetCurrentDir)(THIS_ PCWSTR pszPath) PURE; STDMETHOD(ParseNow)(THIS_ long paramC) PURE; STDMETHOD(Execute)(THIS_ long paramC) PURE; STDMETHOD(Save)(THIS_ long paramC) PURE;