2 * Network Places (Neighbourhood) folder
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998, 1999, 2002 Juergen Schmied
6 * Copyright 2003 Mike McCormack for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
36 #include "shell32_main.h"
38 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL (shell
);
44 /***********************************************************************
45 * IShellFolder implementation
49 IShellFolder2 IShellFolder2_iface
;
50 IPersistFolder2 IPersistFolder2_iface
;
53 /* both paths are parsible from the desktop */
54 LPITEMIDLIST pidlRoot
; /* absolute pidl */
57 static const IShellFolder2Vtbl vt_ShellFolder2
;
58 static const IPersistFolder2Vtbl vt_NP_PersistFolder2
;
60 static inline IGenericSFImpl
*impl_from_IShellFolder2(IShellFolder2
*iface
)
62 return CONTAINING_RECORD(iface
, IGenericSFImpl
, IShellFolder2_iface
);
65 static inline IGenericSFImpl
*impl_from_IPersistFolder2(IPersistFolder2
*iface
)
67 return CONTAINING_RECORD(iface
, IGenericSFImpl
, IPersistFolder2_iface
);
71 static const shvheader networkplaces_header
[] =
73 { NULL
, 0, IDS_SHV_COLUMN1
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 15 },
74 { NULL
, 0, IDS_SHV_COLUMN9
, SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
, LVCFMT_RIGHT
, 10 },
77 /**************************************************************************
78 * ISF_NetworkPlaces_Constructor
80 HRESULT WINAPI
ISF_NetworkPlaces_Constructor (IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
)
84 TRACE ("unkOut=%p %s\n", pUnkOuter
, shdebugstr_guid (riid
));
89 return CLASS_E_NOAGGREGATION
;
91 sf
= calloc (1, sizeof (*sf
));
96 sf
->IShellFolder2_iface
.lpVtbl
= &vt_ShellFolder2
;
97 sf
->IPersistFolder2_iface
.lpVtbl
= &vt_NP_PersistFolder2
;
98 sf
->pidlRoot
= _ILCreateNetHood(); /* my qualified pidl */
100 if (FAILED (IShellFolder2_QueryInterface (&sf
->IShellFolder2_iface
, riid
, ppv
)))
102 IShellFolder2_Release (&sf
->IShellFolder2_iface
);
103 return E_NOINTERFACE
;
106 TRACE ("--(%p)\n", sf
);
110 /**************************************************************************
111 * ISF_NetworkPlaces_fnQueryInterface
114 * supports not IPersist/IPersistFolder
116 static HRESULT WINAPI
ISF_NetworkPlaces_fnQueryInterface (IShellFolder2
*iface
, REFIID riid
, LPVOID
*ppvObj
)
118 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
120 TRACE ("(%p)->(%s,%p)\n", This
, shdebugstr_guid (riid
), ppvObj
);
124 if (IsEqualIID (riid
, &IID_IUnknown
) ||
125 IsEqualIID (riid
, &IID_IShellFolder
) ||
126 IsEqualIID (riid
, &IID_IShellFolder2
))
128 *ppvObj
= &This
->IShellFolder2_iface
;
130 else if (IsEqualIID (riid
, &IID_IPersist
) ||
131 IsEqualIID (riid
, &IID_IPersistFolder
) ||
132 IsEqualIID (riid
, &IID_IPersistFolder2
))
134 *ppvObj
= &This
->IPersistFolder2_iface
;
139 IUnknown_AddRef ((IUnknown
*) (*ppvObj
));
140 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
143 TRACE ("-- Interface: E_NOINTERFACE\n");
144 return E_NOINTERFACE
;
147 static ULONG WINAPI
ISF_NetworkPlaces_fnAddRef (IShellFolder2
* iface
)
149 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
150 ULONG refCount
= InterlockedIncrement(&This
->ref
);
152 TRACE ("(%p)->(count=%lu)\n", This
, refCount
- 1);
157 static ULONG WINAPI
ISF_NetworkPlaces_fnRelease (IShellFolder2
* iface
)
159 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
160 ULONG refCount
= InterlockedDecrement(&This
->ref
);
162 TRACE ("(%p)->(count=%lu)\n", This
, refCount
+ 1);
165 TRACE ("-- destroying IShellFolder(%p)\n", This
);
166 SHFree (This
->pidlRoot
);
172 /**************************************************************************
173 * ISF_NetworkPlaces_fnParseDisplayName
175 static HRESULT WINAPI
ISF_NetworkPlaces_fnParseDisplayName (IShellFolder2
* iface
,
176 HWND hwndOwner
, LPBC pbcReserved
, LPOLESTR lpszDisplayName
,
177 DWORD
* pchEaten
, LPITEMIDLIST
* ppidl
, DWORD
* pdwAttributes
)
179 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
180 HRESULT hr
= E_INVALIDARG
;
181 LPCWSTR szNext
= NULL
;
182 WCHAR szElement
[MAX_PATH
];
183 LPITEMIDLIST pidlTemp
= NULL
;
185 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n", This
,
186 hwndOwner
, pbcReserved
, lpszDisplayName
, debugstr_w (lpszDisplayName
),
187 pchEaten
, ppidl
, pdwAttributes
);
191 szNext
= GetNextElementW (lpszDisplayName
, szElement
, MAX_PATH
);
192 if (!wcsicmp(szElement
, L
"EntireNetwork"))
194 pidlTemp
= _ILCreateEntireNetwork();
201 FIXME("not implemented for %s\n", debugstr_w(lpszDisplayName
));
203 if (SUCCEEDED(hr
) && pidlTemp
)
205 if (szNext
&& *szNext
)
207 hr
= SHELL32_ParseNextElement(iface
, hwndOwner
, pbcReserved
,
208 &pidlTemp
, (LPOLESTR
) szNext
, pchEaten
, pdwAttributes
);
212 if (pdwAttributes
&& *pdwAttributes
)
213 hr
= SHELL32_GetItemAttributes(&This
->IShellFolder2_iface
, pidlTemp
, pdwAttributes
);
222 TRACE ("(%p)->(-- ret=0x%08lx)\n", This
, hr
);
227 /**************************************************************************
228 * ISF_NetworkPlaces_fnEnumObjects
230 static HRESULT WINAPI
ISF_NetworkPlaces_fnEnumObjects (IShellFolder2
* iface
,
231 HWND hwndOwner
, DWORD dwFlags
, LPENUMIDLIST
* ppEnumIDList
)
233 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
234 IEnumIDListImpl
*list
;
236 TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This
,
237 hwndOwner
, dwFlags
, ppEnumIDList
);
239 if (!(list
= IEnumIDList_Constructor()))
240 return E_OUTOFMEMORY
;
241 *ppEnumIDList
= &list
->IEnumIDList_iface
;
243 TRACE ("-- (%p)->(new ID List: %p)\n", This
, *ppEnumIDList
);
248 /**************************************************************************
249 * ISF_NetworkPlaces_fnBindToObject
251 static HRESULT WINAPI
ISF_NetworkPlaces_fnBindToObject (IShellFolder2
* iface
,
252 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
254 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
256 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This
,
257 pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
259 return SHELL32_BindToChild (This
->pidlRoot
, &CLSID_ShellFSFolder
, NULL
, pidl
, riid
, ppvOut
);
262 /**************************************************************************
263 * ISF_NetworkPlaces_fnBindToStorage
265 static HRESULT WINAPI
ISF_NetworkPlaces_fnBindToStorage (IShellFolder2
* iface
,
266 LPCITEMIDLIST pidl
, LPBC pbcReserved
, REFIID riid
, LPVOID
* ppvOut
)
268 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
270 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This
,
271 pidl
, pbcReserved
, shdebugstr_guid (riid
), ppvOut
);
277 /**************************************************************************
278 * ISF_NetworkPlaces_fnCompareIDs
281 static HRESULT WINAPI
ISF_NetworkPlaces_fnCompareIDs (IShellFolder2
* iface
,
282 LPARAM lParam
, LPCITEMIDLIST pidl1
, LPCITEMIDLIST pidl2
)
284 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
287 TRACE ("(%p)->(0x%08Ix,pidl1=%p,pidl2=%p)\n", This
, lParam
, pidl1
, pidl2
);
288 nReturn
= SHELL32_CompareIDs(&This
->IShellFolder2_iface
, lParam
, pidl1
, pidl2
);
289 TRACE ("-- %i\n", nReturn
);
293 /**************************************************************************
294 * ISF_NetworkPlaces_fnCreateViewObject
296 static HRESULT WINAPI
ISF_NetworkPlaces_fnCreateViewObject (IShellFolder2
* iface
,
297 HWND hwndOwner
, REFIID riid
, LPVOID
* ppvOut
)
299 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
300 LPSHELLVIEW pShellView
;
301 HRESULT hr
= E_INVALIDARG
;
303 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This
,
304 hwndOwner
, shdebugstr_guid (riid
), ppvOut
);
311 if (IsEqualIID (riid
, &IID_IDropTarget
))
313 WARN ("IDropTarget not implemented\n");
316 else if (IsEqualIID (riid
, &IID_IShellView
))
318 pShellView
= IShellView_Constructor ((IShellFolder
*) iface
);
321 hr
= IShellView_QueryInterface (pShellView
, riid
, ppvOut
);
322 IShellView_Release (pShellView
);
327 FIXME ("invalid/unsupported interface %s\n", shdebugstr_guid (riid
));
330 TRACE ("-- (%p)->(interface=%p)\n", This
, ppvOut
);
334 /**************************************************************************
335 * ISF_NetworkPlaces_fnGetAttributesOf
337 static HRESULT WINAPI
ISF_NetworkPlaces_fnGetAttributesOf (IShellFolder2
* iface
,
338 UINT cidl
, LPCITEMIDLIST
* apidl
, DWORD
* rgfInOut
)
340 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
343 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\n", This
,
344 cidl
, apidl
, rgfInOut
, rgfInOut
? *rgfInOut
: 0);
356 IShellFolder2
*parent
= NULL
;
357 LPCITEMIDLIST rpidl
= NULL
;
359 hr
= SHBindToParent(This
->pidlRoot
, &IID_IShellFolder2
, (void **)&parent
, &rpidl
);
362 SHELL32_GetItemAttributes(parent
, rpidl
, rgfInOut
);
363 IShellFolder2_Release(parent
);
368 while (cidl
> 0 && *apidl
)
371 SHELL32_GetItemAttributes(&This
->IShellFolder2_iface
, *apidl
, rgfInOut
);
377 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
378 *rgfInOut
&= ~SFGAO_VALIDATE
;
380 TRACE ("-- result=0x%08lx\n", *rgfInOut
);
384 /**************************************************************************
385 * ISF_NetworkPlaces_fnGetUIObjectOf
388 * hwndOwner [in] Parent window for any output
389 * cidl [in] array size
390 * apidl [in] simple pidl array
391 * riid [in] Requested Interface
392 * prgfInOut [ ] reserved
393 * ppvObject [out] Resulting Interface
396 static HRESULT WINAPI
ISF_NetworkPlaces_fnGetUIObjectOf (IShellFolder2
* iface
,
397 HWND hwndOwner
, UINT cidl
, LPCITEMIDLIST
* apidl
, REFIID riid
,
398 UINT
* prgfInOut
, LPVOID
* ppvOut
)
400 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
403 IUnknown
*pObj
= NULL
;
404 HRESULT hr
= E_INVALIDARG
;
406 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", This
,
407 hwndOwner
, cidl
, apidl
, shdebugstr_guid (riid
), prgfInOut
, ppvOut
);
414 if (IsEqualIID (riid
, &IID_IContextMenu
) && (cidl
>= 1))
416 return ItemMenu_Constructor((IShellFolder
*)iface
, This
->pidlRoot
, apidl
, cidl
, riid
, ppvOut
);
418 else if (IsEqualIID (riid
, &IID_IDataObject
) && (cidl
>= 1))
420 pObj
= (LPUNKNOWN
) IDataObject_Constructor (hwndOwner
, This
->pidlRoot
, apidl
, cidl
);
423 else if (IsEqualIID (riid
, &IID_IExtractIconA
) && (cidl
== 1))
425 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
426 pObj
= (LPUNKNOWN
) IExtractIconA_Constructor (pidl
);
430 else if (IsEqualIID (riid
, &IID_IExtractIconW
) && (cidl
== 1))
432 pidl
= ILCombine (This
->pidlRoot
, apidl
[0]);
433 pObj
= (LPUNKNOWN
) IExtractIconW_Constructor (pidl
);
437 else if (IsEqualIID (riid
, &IID_IDropTarget
) && (cidl
>= 1))
439 hr
= IShellFolder2_QueryInterface (iface
, &IID_IDropTarget
, (LPVOID
*) & pObj
);
444 if (SUCCEEDED(hr
) && !pObj
)
448 TRACE ("(%p)->hr=0x%08lx\n", This
, hr
);
452 /**************************************************************************
453 * ISF_NetworkPlaces_fnGetDisplayNameOf
456 static HRESULT WINAPI
ISF_NetworkPlaces_fnGetDisplayNameOf (IShellFolder2
* iface
,
457 LPCITEMIDLIST pidl
, DWORD dwFlags
, LPSTRRET strRet
)
459 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
461 FIXME ("(%p)->(pidl=%p,0x%08lx,%p)\n", This
, pidl
, dwFlags
, strRet
);
470 /**************************************************************************
471 * ISF_NetworkPlaces_fnSetNameOf
472 * Changes the name of a file object or subfolder, possibly changing its item
473 * identifier in the process.
476 * hwndOwner [in] Owner window for output
477 * pidl [in] simple pidl of item to change
478 * lpszName [in] the items new display name
479 * dwFlags [in] SHGNO formatting flags
480 * ppidlOut [out] simple pidl returned
482 static HRESULT WINAPI
ISF_NetworkPlaces_fnSetNameOf (IShellFolder2
* iface
,
483 HWND hwndOwner
, LPCITEMIDLIST pidl
, /*simple pidl */
484 LPCOLESTR lpName
, DWORD dwFlags
, LPITEMIDLIST
* pPidlOut
)
486 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
488 FIXME ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This
,
489 hwndOwner
, pidl
, debugstr_w (lpName
), dwFlags
, pPidlOut
);
493 static HRESULT WINAPI
ISF_NetworkPlaces_fnGetDefaultSearchGUID(IShellFolder2
*iface
, GUID
*guid
)
495 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
496 TRACE("(%p)->(%p)\n", This
, guid
);
500 static HRESULT WINAPI
ISF_NetworkPlaces_fnEnumSearches (IShellFolder2
* iface
,
501 IEnumExtraSearch
** ppenum
)
503 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
505 FIXME ("(%p)\n", This
);
509 static HRESULT WINAPI
ISF_NetworkPlaces_fnGetDefaultColumn(IShellFolder2
*iface
, DWORD reserved
,
510 ULONG
*sort
, ULONG
*display
)
512 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
514 TRACE("(%p)->(%#lx, %p, %p)\n", This
, reserved
, sort
, display
);
519 static HRESULT WINAPI
ISF_NetworkPlaces_fnGetDefaultColumnState (
520 IShellFolder2
* iface
, UINT iColumn
, DWORD
* pcsFlags
)
522 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
524 TRACE ("(%p)->(%d %p)\n", This
, iColumn
, pcsFlags
);
526 if (!pcsFlags
|| iColumn
>= ARRAY_SIZE(networkplaces_header
))
529 *pcsFlags
= networkplaces_header
[iColumn
].pcsFlags
;
534 static HRESULT WINAPI
ISF_NetworkPlaces_fnGetDetailsEx (IShellFolder2
* iface
,
535 LPCITEMIDLIST pidl
, const SHCOLUMNID
* pscid
, VARIANT
* pv
)
537 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
539 FIXME ("(%p)\n", This
);
543 static HRESULT WINAPI
ISF_NetworkPlaces_fnGetDetailsOf (IShellFolder2
* iface
,
544 LPCITEMIDLIST pidl
, UINT iColumn
, SHELLDETAILS
* psd
)
546 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
548 FIXME ("(%p)->(%p %i %p)\n", This
, pidl
, iColumn
, psd
);
553 static HRESULT WINAPI
ISF_NetworkPlaces_fnMapColumnToSCID (IShellFolder2
*iface
, UINT column
, SHCOLUMNID
*scid
)
555 IGenericSFImpl
*This
= impl_from_IShellFolder2(iface
);
557 TRACE("(%p)->(%u %p)\n", This
, column
, scid
);
559 if (column
>= ARRAY_SIZE(networkplaces_header
))
562 return shellfolder_map_column_to_scid(networkplaces_header
, column
, scid
);
565 static const IShellFolder2Vtbl vt_ShellFolder2
= {
566 ISF_NetworkPlaces_fnQueryInterface
,
567 ISF_NetworkPlaces_fnAddRef
,
568 ISF_NetworkPlaces_fnRelease
,
569 ISF_NetworkPlaces_fnParseDisplayName
,
570 ISF_NetworkPlaces_fnEnumObjects
,
571 ISF_NetworkPlaces_fnBindToObject
,
572 ISF_NetworkPlaces_fnBindToStorage
,
573 ISF_NetworkPlaces_fnCompareIDs
,
574 ISF_NetworkPlaces_fnCreateViewObject
,
575 ISF_NetworkPlaces_fnGetAttributesOf
,
576 ISF_NetworkPlaces_fnGetUIObjectOf
,
577 ISF_NetworkPlaces_fnGetDisplayNameOf
,
578 ISF_NetworkPlaces_fnSetNameOf
,
580 ISF_NetworkPlaces_fnGetDefaultSearchGUID
,
581 ISF_NetworkPlaces_fnEnumSearches
,
582 ISF_NetworkPlaces_fnGetDefaultColumn
,
583 ISF_NetworkPlaces_fnGetDefaultColumnState
,
584 ISF_NetworkPlaces_fnGetDetailsEx
,
585 ISF_NetworkPlaces_fnGetDetailsOf
,
586 ISF_NetworkPlaces_fnMapColumnToSCID
589 /************************************************************************
590 * INPFldr_PersistFolder2_QueryInterface
592 static HRESULT WINAPI
INPFldr_PersistFolder2_QueryInterface (IPersistFolder2
* iface
,
593 REFIID iid
, LPVOID
* ppvObj
)
595 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
597 TRACE ("(%p)\n", This
);
599 return IShellFolder2_QueryInterface (&This
->IShellFolder2_iface
, iid
, ppvObj
);
602 /************************************************************************
603 * INPFldr_PersistFolder2_AddRef
605 static ULONG WINAPI
INPFldr_PersistFolder2_AddRef (IPersistFolder2
* iface
)
607 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
609 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
611 return IShellFolder2_AddRef (&This
->IShellFolder2_iface
);
614 /************************************************************************
615 * ISFPersistFolder_Release
617 static ULONG WINAPI
INPFldr_PersistFolder2_Release (IPersistFolder2
* iface
)
619 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
621 TRACE ("(%p)->(count=%lu)\n", This
, This
->ref
);
623 return IShellFolder2_Release (&This
->IShellFolder2_iface
);
626 /************************************************************************
627 * INPFldr_PersistFolder2_GetClassID
629 static HRESULT WINAPI
INPFldr_PersistFolder2_GetClassID (
630 IPersistFolder2
* iface
, CLSID
* lpClassId
)
632 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
634 TRACE ("(%p)\n", This
);
639 *lpClassId
= CLSID_NetworkPlaces
;
644 /************************************************************************
645 * INPFldr_PersistFolder2_Initialize
647 * NOTES: it makes no sense to change the pidl
649 static HRESULT WINAPI
INPFldr_PersistFolder2_Initialize (
650 IPersistFolder2
* iface
, LPCITEMIDLIST pidl
)
652 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
654 TRACE ("(%p)->(%p)\n", This
, pidl
);
659 /**************************************************************************
660 * IPersistFolder2_fnGetCurFolder
662 static HRESULT WINAPI
INPFldr_PersistFolder2_GetCurFolder (
663 IPersistFolder2
* iface
, LPITEMIDLIST
* pidl
)
665 IGenericSFImpl
*This
= impl_from_IPersistFolder2(iface
);
667 TRACE ("(%p)->(%p)\n", This
, pidl
);
672 *pidl
= ILClone (This
->pidlRoot
);
677 static const IPersistFolder2Vtbl vt_NP_PersistFolder2
=
679 INPFldr_PersistFolder2_QueryInterface
,
680 INPFldr_PersistFolder2_AddRef
,
681 INPFldr_PersistFolder2_Release
,
682 INPFldr_PersistFolder2_GetClassID
,
683 INPFldr_PersistFolder2_Initialize
,
684 INPFldr_PersistFolder2_GetCurFolder