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
24 #include "wine/port.h"
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
41 #include "enumidlist.h"
42 #include "undocshell.h"
43 #include "shell32_main.h"
45 #include "wine/debug.h"
46 #include "wine/unicode.h"
50 WINE_DEFAULT_DEBUG_CHANNEL (shell);
52 /***********************************************************************
53 * IShellFolder implementation
57 const IShellFolder2Vtbl *lpVtbl;
59 const IPersistFolder2Vtbl *lpVtblPersistFolder2;
61 /* both paths are parsible from the desktop */
62 LPITEMIDLIST pidlRoot; /* absolute pidl */
65 static const IShellFolder2Vtbl vt_ShellFolder2;
66 static const IPersistFolder2Vtbl vt_NP_PersistFolder2;
68 static inline IGenericSFImpl *impl_from_IPersistFolder2(IPersistFolder2 *iface)
70 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpVtblPersistFolder2));
73 #define _IUnknown_(This) ((IUnknown*)&(This)->lpVtbl)
74 #define _IShellFolder_(This) ((IShellFolder*)&(This)->lpVtbl)
75 #define _IPersistFolder2_(This) (&(This)->lpVtblPersistFolder2)
77 static const shvheader networkplaces_header[] = {
78 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
79 {IDS_SHV_COLUMN9, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10}
82 #define NETWORKPLACESSHELLVIEWCOLUMNS sizeof(networkplaces_header)/sizeof(shvheader)
84 /**************************************************************************
85 * ISF_NetworkPlaces_Constructor
87 HRESULT WINAPI ISF_NetworkPlaces_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
91 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
96 return CLASS_E_NOAGGREGATION;
98 sf = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (IGenericSFImpl));
100 return E_OUTOFMEMORY;
103 sf->lpVtbl = &vt_ShellFolder2;
104 sf->lpVtblPersistFolder2 = &vt_NP_PersistFolder2;
105 sf->pidlRoot = _ILCreateNetHood(); /* my qualified pidl */
107 if (FAILED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv)))
109 IUnknown_Release (_IUnknown_ (sf));
110 return E_NOINTERFACE;
113 TRACE ("--(%p)\n", sf);
117 /**************************************************************************
118 * ISF_NetworkPlaces_fnQueryInterface
121 * supports not IPersist/IPersistFolder
123 static HRESULT WINAPI ISF_NetworkPlaces_fnQueryInterface (IShellFolder2 *iface, REFIID riid, LPVOID *ppvObj)
125 IGenericSFImpl *This = (IGenericSFImpl *)iface;
127 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
131 if (IsEqualIID (riid, &IID_IUnknown) ||
132 IsEqualIID (riid, &IID_IShellFolder) ||
133 IsEqualIID (riid, &IID_IShellFolder2))
137 else if (IsEqualIID (riid, &IID_IPersist) ||
138 IsEqualIID (riid, &IID_IPersistFolder) ||
139 IsEqualIID (riid, &IID_IPersistFolder2))
141 *ppvObj = _IPersistFolder2_ (This);
146 IUnknown_AddRef ((IUnknown *) (*ppvObj));
147 TRACE ("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
150 TRACE ("-- Interface: E_NOINTERFACE\n");
151 return E_NOINTERFACE;
154 static ULONG WINAPI ISF_NetworkPlaces_fnAddRef (IShellFolder2 * iface)
156 IGenericSFImpl *This = (IGenericSFImpl *)iface;
157 ULONG refCount = InterlockedIncrement(&This->ref);
159 TRACE ("(%p)->(count=%u)\n", This, refCount - 1);
164 static ULONG WINAPI ISF_NetworkPlaces_fnRelease (IShellFolder2 * iface)
166 IGenericSFImpl *This = (IGenericSFImpl *)iface;
167 ULONG refCount = InterlockedDecrement(&This->ref);
169 TRACE ("(%p)->(count=%u)\n", This, refCount + 1);
172 TRACE ("-- destroying IShellFolder(%p)\n", This);
173 SHFree (This->pidlRoot);
174 HeapFree (GetProcessHeap(), 0, This);
179 /**************************************************************************
180 * ISF_NetworkPlaces_fnParseDisplayName
182 static HRESULT WINAPI ISF_NetworkPlaces_fnParseDisplayName (IShellFolder2 * iface,
183 HWND hwndOwner, LPBC pbcReserved, LPOLESTR lpszDisplayName,
184 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
186 static const WCHAR wszEntireNetwork[] = {'E','n','t','i','r','e','N','e','t','w','o','r','k'}; /* not nul-terminated */
187 IGenericSFImpl *This = (IGenericSFImpl *)iface;
188 HRESULT hr = E_INVALIDARG;
189 LPCWSTR szNext = NULL;
190 WCHAR szElement[MAX_PATH];
191 LPITEMIDLIST pidlTemp = NULL;
194 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n", This,
195 hwndOwner, pbcReserved, lpszDisplayName, debugstr_w (lpszDisplayName),
196 pchEaten, ppidl, pdwAttributes);
200 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
201 len = strlenW(szElement);
202 if (len == sizeof(wszEntireNetwork)/sizeof(wszEntireNetwork[0]) &&
203 !strncmpiW(szElement, wszEntireNetwork, sizeof(wszEntireNetwork)/sizeof(wszEntireNetwork[0])))
205 pidlTemp = _ILCreateEntireNetwork();
212 FIXME("not implemented for %s\n", debugstr_w(lpszDisplayName));
214 if (SUCCEEDED(hr) && pidlTemp)
216 if (szNext && *szNext)
218 hr = SHELL32_ParseNextElement(iface, hwndOwner, pbcReserved,
219 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
223 if (pdwAttributes && *pdwAttributes)
224 hr = SHELL32_GetItemAttributes(_IShellFolder_ (This),
225 pidlTemp, pdwAttributes);
234 TRACE ("(%p)->(-- ret=0x%08x)\n", This, hr);
239 /**************************************************************************
240 * ISF_NetworkPlaces_fnEnumObjects
242 static HRESULT WINAPI ISF_NetworkPlaces_fnEnumObjects (IShellFolder2 * iface,
243 HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
245 IGenericSFImpl *This = (IGenericSFImpl *)iface;
247 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This,
248 hwndOwner, dwFlags, ppEnumIDList);
250 *ppEnumIDList = IEnumIDList_Constructor();
252 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
254 return (*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
257 /**************************************************************************
258 * ISF_NetworkPlaces_fnBindToObject
260 static HRESULT WINAPI ISF_NetworkPlaces_fnBindToObject (IShellFolder2 * iface,
261 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
263 IGenericSFImpl *This = (IGenericSFImpl *)iface;
265 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This,
266 pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
268 return SHELL32_BindToChild (This->pidlRoot, NULL, pidl, riid, ppvOut);
271 /**************************************************************************
272 * ISF_NetworkPlaces_fnBindToStorage
274 static HRESULT WINAPI ISF_NetworkPlaces_fnBindToStorage (IShellFolder2 * iface,
275 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
277 IGenericSFImpl *This = (IGenericSFImpl *)iface;
279 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This,
280 pidl, pbcReserved, shdebugstr_guid (riid), ppvOut);
286 /**************************************************************************
287 * ISF_NetworkPlaces_fnCompareIDs
290 static HRESULT WINAPI ISF_NetworkPlaces_fnCompareIDs (IShellFolder2 * iface,
291 LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
293 IGenericSFImpl *This = (IGenericSFImpl *)iface;
296 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
297 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
298 TRACE ("-- %i\n", nReturn);
302 /**************************************************************************
303 * ISF_NetworkPlaces_fnCreateViewObject
305 static HRESULT WINAPI ISF_NetworkPlaces_fnCreateViewObject (IShellFolder2 * iface,
306 HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
308 IGenericSFImpl *This = (IGenericSFImpl *)iface;
309 LPSHELLVIEW pShellView;
310 HRESULT hr = E_INVALIDARG;
312 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This,
313 hwndOwner, shdebugstr_guid (riid), ppvOut);
320 if (IsEqualIID (riid, &IID_IDropTarget))
322 WARN ("IDropTarget not implemented\n");
325 else if (IsEqualIID (riid, &IID_IContextMenu))
327 WARN ("IContextMenu not implemented\n");
330 else if (IsEqualIID (riid, &IID_IShellView))
332 pShellView = IShellView_Constructor ((IShellFolder *) iface);
335 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
336 IShellView_Release (pShellView);
339 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
343 /**************************************************************************
344 * ISF_NetworkPlaces_fnGetAttributesOf
346 static HRESULT WINAPI ISF_NetworkPlaces_fnGetAttributesOf (IShellFolder2 * iface,
347 UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
349 IGenericSFImpl *This = (IGenericSFImpl *)iface;
352 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", This,
353 cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
365 IShellFolder *psfParent = NULL;
366 LPCITEMIDLIST rpidl = NULL;
368 hr = SHBindToParent(This->pidlRoot, &IID_IShellFolder, (LPVOID*)&psfParent, (LPCITEMIDLIST*)&rpidl);
371 SHELL32_GetItemAttributes (psfParent, rpidl, rgfInOut);
372 IShellFolder_Release(psfParent);
377 while (cidl > 0 && *apidl)
380 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
386 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
387 *rgfInOut &= ~SFGAO_VALIDATE;
389 TRACE ("-- result=0x%08x\n", *rgfInOut);
393 /**************************************************************************
394 * ISF_NetworkPlaces_fnGetUIObjectOf
397 * hwndOwner [in] Parent window for any output
398 * cidl [in] array size
399 * apidl [in] simple pidl array
400 * riid [in] Requested Interface
401 * prgfInOut [ ] reserved
402 * ppvObject [out] Resulting Interface
405 static HRESULT WINAPI ISF_NetworkPlaces_fnGetUIObjectOf (IShellFolder2 * iface,
406 HWND hwndOwner, UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
407 UINT * prgfInOut, LPVOID * ppvOut)
409 IGenericSFImpl *This = (IGenericSFImpl *)iface;
412 IUnknown *pObj = NULL;
413 HRESULT hr = E_INVALIDARG;
415 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", This,
416 hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
423 if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1))
425 pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
428 else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1))
430 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner, This->pidlRoot, apidl, cidl);
433 else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1))
435 pidl = ILCombine (This->pidlRoot, apidl[0]);
436 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
440 else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1))
442 pidl = ILCombine (This->pidlRoot, apidl[0]);
443 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
447 else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1))
449 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, (LPVOID *) & pObj);
454 if (SUCCEEDED(hr) && !pObj)
458 TRACE ("(%p)->hr=0x%08x\n", This, hr);
462 /**************************************************************************
463 * ISF_NetworkPlaces_fnGetDisplayNameOf
466 static HRESULT WINAPI ISF_NetworkPlaces_fnGetDisplayNameOf (IShellFolder2 * iface,
467 LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
469 IGenericSFImpl *This = (IGenericSFImpl *)iface;
471 FIXME ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
480 /**************************************************************************
481 * ISF_NetworkPlaces_fnSetNameOf
482 * Changes the name of a file object or subfolder, possibly changing its item
483 * identifier in the process.
486 * hwndOwner [in] Owner window for output
487 * pidl [in] simple pidl of item to change
488 * lpszName [in] the items new display name
489 * dwFlags [in] SHGNO formatting flags
490 * ppidlOut [out] simple pidl returned
492 static HRESULT WINAPI ISF_NetworkPlaces_fnSetNameOf (IShellFolder2 * iface,
493 HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */
494 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
496 IGenericSFImpl *This = (IGenericSFImpl *)iface;
497 FIXME ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This,
498 hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
502 static HRESULT WINAPI ISF_NetworkPlaces_fnGetDefaultSearchGUID (
503 IShellFolder2 * iface, GUID * pguid)
505 IGenericSFImpl *This = (IGenericSFImpl *)iface;
506 FIXME ("(%p)\n", This);
510 static HRESULT WINAPI ISF_NetworkPlaces_fnEnumSearches (IShellFolder2 * iface,
511 IEnumExtraSearch ** ppenum)
513 IGenericSFImpl *This = (IGenericSFImpl *)iface;
514 FIXME ("(%p)\n", This);
518 static HRESULT WINAPI ISF_NetworkPlaces_fnGetDefaultColumn (IShellFolder2 * iface,
519 DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
521 IGenericSFImpl *This = (IGenericSFImpl *)iface;
523 TRACE ("(%p)\n", This);
533 static HRESULT WINAPI ISF_NetworkPlaces_fnGetDefaultColumnState (
534 IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
536 IGenericSFImpl *This = (IGenericSFImpl *)iface;
538 TRACE ("(%p)->(%d %p)\n", This, iColumn, pcsFlags);
540 if (!pcsFlags || iColumn >= NETWORKPLACESSHELLVIEWCOLUMNS)
543 *pcsFlags = networkplaces_header[iColumn].pcsFlags;
548 static HRESULT WINAPI ISF_NetworkPlaces_fnGetDetailsEx (IShellFolder2 * iface,
549 LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
551 IGenericSFImpl *This = (IGenericSFImpl *)iface;
552 FIXME ("(%p)\n", This);
556 static HRESULT WINAPI ISF_NetworkPlaces_fnGetDetailsOf (IShellFolder2 * iface,
557 LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
559 IGenericSFImpl *This = (IGenericSFImpl *)iface;
561 FIXME ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
566 static HRESULT WINAPI ISF_NetworkPlaces_fnMapColumnToSCID (IShellFolder2 * iface,
567 UINT column, SHCOLUMNID * pscid)
569 IGenericSFImpl *This = (IGenericSFImpl *)iface;
571 FIXME ("(%p)\n", This);
576 static const IShellFolder2Vtbl vt_ShellFolder2 = {
577 ISF_NetworkPlaces_fnQueryInterface,
578 ISF_NetworkPlaces_fnAddRef,
579 ISF_NetworkPlaces_fnRelease,
580 ISF_NetworkPlaces_fnParseDisplayName,
581 ISF_NetworkPlaces_fnEnumObjects,
582 ISF_NetworkPlaces_fnBindToObject,
583 ISF_NetworkPlaces_fnBindToStorage,
584 ISF_NetworkPlaces_fnCompareIDs,
585 ISF_NetworkPlaces_fnCreateViewObject,
586 ISF_NetworkPlaces_fnGetAttributesOf,
587 ISF_NetworkPlaces_fnGetUIObjectOf,
588 ISF_NetworkPlaces_fnGetDisplayNameOf,
589 ISF_NetworkPlaces_fnSetNameOf,
591 ISF_NetworkPlaces_fnGetDefaultSearchGUID,
592 ISF_NetworkPlaces_fnEnumSearches,
593 ISF_NetworkPlaces_fnGetDefaultColumn,
594 ISF_NetworkPlaces_fnGetDefaultColumnState,
595 ISF_NetworkPlaces_fnGetDetailsEx,
596 ISF_NetworkPlaces_fnGetDetailsOf,
597 ISF_NetworkPlaces_fnMapColumnToSCID
600 /************************************************************************
601 * INPFldr_PersistFolder2_QueryInterface
603 static HRESULT WINAPI INPFldr_PersistFolder2_QueryInterface (IPersistFolder2 * iface,
604 REFIID iid, LPVOID * ppvObj)
606 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
608 TRACE ("(%p)\n", This);
610 return IUnknown_QueryInterface (_IUnknown_ (This), iid, ppvObj);
613 /************************************************************************
614 * INPFldr_PersistFolder2_AddRef
616 static ULONG WINAPI INPFldr_PersistFolder2_AddRef (IPersistFolder2 * iface)
618 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
620 TRACE ("(%p)->(count=%u)\n", This, This->ref);
622 return IUnknown_AddRef (_IUnknown_ (This));
625 /************************************************************************
626 * ISFPersistFolder_Release
628 static ULONG WINAPI INPFldr_PersistFolder2_Release (IPersistFolder2 * iface)
630 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
632 TRACE ("(%p)->(count=%u)\n", This, This->ref);
634 return IUnknown_Release (_IUnknown_ (This));
637 /************************************************************************
638 * INPFldr_PersistFolder2_GetClassID
640 static HRESULT WINAPI INPFldr_PersistFolder2_GetClassID (
641 IPersistFolder2 * iface, CLSID * lpClassId)
643 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
645 TRACE ("(%p)\n", This);
650 *lpClassId = CLSID_NetworkPlaces;
655 /************************************************************************
656 * INPFldr_PersistFolder2_Initialize
658 * NOTES: it makes no sense to change the pidl
660 static HRESULT WINAPI INPFldr_PersistFolder2_Initialize (
661 IPersistFolder2 * iface, LPCITEMIDLIST pidl)
663 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
665 TRACE ("(%p)->(%p)\n", This, pidl);
670 /**************************************************************************
671 * IPersistFolder2_fnGetCurFolder
673 static HRESULT WINAPI INPFldr_PersistFolder2_GetCurFolder (
674 IPersistFolder2 * iface, LPITEMIDLIST * pidl)
676 IGenericSFImpl *This = impl_from_IPersistFolder2(iface);
678 TRACE ("(%p)->(%p)\n", This, pidl);
683 *pidl = ILClone (This->pidlRoot);
688 static const IPersistFolder2Vtbl vt_NP_PersistFolder2 =
690 INPFldr_PersistFolder2_QueryInterface,
691 INPFldr_PersistFolder2_AddRef,
692 INPFldr_PersistFolder2_Release,
693 INPFldr_PersistFolder2_GetClassID,
694 INPFldr_PersistFolder2_Initialize,
695 INPFldr_PersistFolder2_GetCurFolder