11/*
2- * ReactOS Explorer
3- *
4- * Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
5- * Copyright 2023 Katayama Hirofumi MZ <[email protected] > 6- *
7- * This library is free software; you can redistribute it and/or
8- * modify it under the terms of the GNU Lesser General Public
9- * License as published by the Free Software Foundation; either
10- * version 2.1 of the License, or (at your option) any later version.
11- *
12- * This library is distributed in the hope that it will be useful,
13- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15- * Lesser General Public License for more details.
16- *
17- * You should have received a copy of the GNU Lesser General Public
18- * License along with this library; if not, write to the Free Software
19- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2+ * PROJECT: ReactOS Explorer
3+ * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4+ * PURPOSE: The combo box of the address band
5+ * COPYRIGHT: Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
6+ * Copyright 2023-2025 Katayama Hirofumi MZ <[email protected] > 207 */
218
22- /*
23- This class handles the combo box of the address band.
24- */
25-
269#include " precomp.h"
2710
2811/*
@@ -34,15 +17,12 @@ This class handles the combo box of the address band.
3417CAddressEditBox::CAddressEditBox () :
3518 fCombobox(WC_COMBOBOXEXW, this ),
3619 fEditWindow(WC_EDITW, this ),
37- fSite(NULL ),
38- pidlLastParsed(NULL )
20+ fSite(NULL )
3921{
4022}
4123
4224CAddressEditBox::~CAddressEditBox ()
4325{
44- if (pidlLastParsed)
45- ILFree (pidlLastParsed);
4626}
4727
4828HRESULT STDMETHODCALLTYPE CAddressEditBox::SetOwner (IUnknown *pOwner)
@@ -90,9 +70,11 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Init(HWND comboboxEx, HWND editContro
9070 return hResult;
9171}
9272
93- HRESULT STDMETHODCALLTYPE CAddressEditBox::SetCurrentDir (long paramC )
73+ HRESULT STDMETHODCALLTYPE CAddressEditBox::SetCurrentDir (PCWSTR pszPath )
9474{
95- return E_NOTIMPL;
75+ m_pidlLastParsed.Free ();
76+ m_pidlLastParsed.Attach (ILCreateFromPathW (pszPath));
77+ return m_pidlLastParsed ? S_OK : E_OUTOFMEMORY;
9678}
9779
9880BOOL CAddressEditBox::GetComboBoxText (CComHeapPtr<WCHAR>& pszText)
@@ -196,19 +178,20 @@ BOOL CAddressEditBox::ExecuteCommandLine()
196178
197179HRESULT STDMETHODCALLTYPE CAddressEditBox::ParseNow (long paramC)
198180{
199- ULONG eaten;
200- ULONG attributes;
201- HRESULT hr;
202- HWND topLevelWindow;
203- PIDLIST_ABSOLUTE pidlCurrent= NULL ;
204- PIDLIST_RELATIVE pidlRelative = NULL ;
181+ ULONG eaten, attributes;
182+ CComHeapPtr<ITEMIDLIST_ABSOLUTE> pidlCurrent;
183+ CComHeapPtr<ITEMIDLIST_RELATIVE> pidlRelative;
205184 CComPtr<IShellFolder> psfCurrent;
185+ HRESULT hr;
186+
187+ ATLASSERT (!m_pidlLastParsed);
206188
207189 CComPtr<IBrowserService> pbs;
208190 hr = IUnknown_QueryService (fSite , SID_SShellBrowser, IID_PPV_ARG (IBrowserService, &pbs));
209191 if (FAILED_UNEXPECTEDLY (hr))
210192 return hr;
211193
194+ HWND topLevelWindow;
212195 hr = IUnknown_GetWindow (pbs, &topLevelWindow);
213196 if (FAILED_UNEXPECTEDLY (hr))
214197 return hr;
@@ -231,7 +214,7 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::ParseNow(long paramC)
231214 CComPtr<IShellFolder> psfDesktop;
232215 hr = SHGetDesktopFolder (&psfDesktop);
233216 if (FAILED_UNEXPECTEDLY (hr))
234- goto cleanup ;
217+ return hr ;
235218
236219 hr = pbs->GetPidl (&pidlCurrent);
237220 if (FAILED_UNEXPECTEDLY (hr))
@@ -244,18 +227,13 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::ParseNow(long paramC)
244227 hr = psfCurrent->ParseDisplayName (topLevelWindow, NULL , address, &eaten, &pidlRelative, &attributes);
245228 if (SUCCEEDED (hr))
246229 {
247- pidlLastParsed = ILCombine (pidlCurrent, pidlRelative);
248- ILFree (pidlRelative);
249- goto cleanup;
230+ m_pidlLastParsed.Attach (ILCombine (pidlCurrent, pidlRelative));
231+ return hr;
250232 }
251233
252234parseabsolute:
253235 /* We couldn't parse a relative path, attempt to parse an absolute path */
254- hr = psfDesktop->ParseDisplayName (topLevelWindow, NULL , address, &eaten, &pidlLastParsed, &attributes);
255-
256- cleanup:
257- if (pidlCurrent)
258- ILFree (pidlCurrent);
236+ hr = psfDesktop->ParseDisplayName (topLevelWindow, NULL , address, &eaten, &m_pidlLastParsed, &attributes);
259237 return hr;
260238}
261239
@@ -277,7 +255,7 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Execute(long paramC)
277255 /*
278256 * Parse the path if it wasn't parsed
279257 */
280- if (!pidlLastParsed )
258+ if (!m_pidlLastParsed )
281259 {
282260 hr = ParseNow (0 );
283261
@@ -290,7 +268,7 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Execute(long paramC)
290268 return ShowFileNotFoundError (hr);
291269 }
292270
293- if (!pidlLastParsed )
271+ if (!m_pidlLastParsed )
294272 return E_FAIL;
295273 }
296274
@@ -315,24 +293,20 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Execute(long paramC)
315293 if (FAILED (hr))
316294 return hr;
317295
318- hr = psf->CompareIDs (0 , pidl, pidlLastParsed );
296+ hr = psf->CompareIDs (0 , pidl, m_pidlLastParsed );
319297
320298 SHFree (pidl);
321299
322- if (hr == 0 )
300+ if (hr == S_OK )
323301 {
324- if (pidlLastParsed)
325- {
326- ILFree (pidlLastParsed);
327- pidlLastParsed = NULL ;
328- }
302+ m_pidlLastParsed.Free ();
329303 return S_OK;
330304 }
331305
332306 /*
333307 * Attempt to browse to the parsed pidl
334308 */
335- hr = pisb->BrowseObject (pidlLastParsed , 0 );
309+ hr = pisb->BrowseObject (m_pidlLastParsed , 0 );
336310 if (SUCCEEDED (hr))
337311 return hr;
338312
@@ -346,7 +320,7 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Execute(long paramC)
346320
347321 LPCITEMIDLIST pidlChild;
348322 CComPtr<IShellFolder> sf;
349- hr = SHBindToParent (pidlLastParsed , IID_PPV_ARG (IShellFolder, &sf), &pidlChild);
323+ hr = SHBindToParent (m_pidlLastParsed , IID_PPV_ARG (IShellFolder, &sf), &pidlChild);
350324 if (FAILED (hr))
351325 return hr;
352326
@@ -374,10 +348,15 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::OnWinEvent(
374348 {
375349 case WM_COMMAND:
376350 {
377- if (HIWORD (wParam) == CBN_SELCHANGE)
351+ if (HIWORD (wParam) == CBN_SELCHANGE && fCombobox == (HWND)lParam )
378352 {
379- UINT selectedIndex = SendMessageW ((HWND)lParam, CB_GETCURSEL, 0 , 0 );
380- pidlLastParsed = ILClone ((LPITEMIDLIST)SendMessageW ((HWND)lParam, CB_GETITEMDATA, selectedIndex, 0 ));
353+ INT iItem = (INT)fCombobox .SendMessage (CB_GETCURSEL);
354+ PIDLIST_ABSOLUTE pidl =
355+ (PIDLIST_ABSOLUTE)fCombobox .SendMessage (CB_GETITEMDATA, iItem);
356+ m_pidlLastParsed.Free ();
357+ if (pidl)
358+ m_pidlLastParsed.Attach (ILClone (pidl));
359+
381360 Execute (0 );
382361 }
383362 break ;
@@ -460,12 +439,7 @@ HRESULT STDMETHODCALLTYPE CAddressEditBox::Invoke(DISPID dispIdMember, REFIID ri
460439 {
461440 case DISPID_NAVIGATECOMPLETE2:
462441 case DISPID_DOCUMENTCOMPLETE:
463- if (pidlLastParsed)
464- {
465- ILFree (pidlLastParsed);
466- pidlLastParsed = NULL ;
467- }
468-
442+ m_pidlLastParsed.Free ();
469443 RefreshAddress ();
470444 break ;
471445 }
0 commit comments