6075856e00971a1b2295ad0fa9e8abd2e556bef4
[reactos.git] / dll / win32 / shell32 / folders / netplaces.cpp
1 /*
2 * Network Places (Neighbourhood) folder
3 *
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998, 1999, 2002 Juergen Schmied
6 * Copyright 2003 Mike McCormack for Codeweavers
7 * Copyright 2009 Andrew Hill
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24 #include <precomp.h>
25
26 WINE_DEFAULT_DEBUG_CHANNEL (shell);
27
28 /***********************************************************************
29 * IShellFolder implementation
30 */
31
32 static shvheader NetworkPlacesSFHeader[] = {
33 {IDS_SHV_COLUMN8, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
34 {IDS_SHV_COLUMN13, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
35 {IDS_SHV_COLUMN_WORKGROUP, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
36 {IDS_SHV_NETWORKLOCATION, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15}
37 };
38
39 #define COLUMN_NAME 0
40 #define COLUMN_CATEGORY 1
41 #define COLUMN_WORKGROUP 2
42 #define COLUMN_NETLOCATION 3
43
44 #define NETWORKPLACESSHELLVIEWCOLUMNS 4
45
46 CNetFolder::CNetFolder()
47 {
48 pidlRoot = NULL;
49 }
50
51 CNetFolder::~CNetFolder()
52 {
53 TRACE("-- destroying IShellFolder(%p)\n", this);
54 SHFree(pidlRoot);
55 }
56
57 HRESULT WINAPI CNetFolder::FinalConstruct()
58 {
59 pidlRoot = _ILCreateNetHood(); /* my qualified pidl */
60 if (pidlRoot == NULL)
61 return E_OUTOFMEMORY;
62 return S_OK;
63 }
64
65 /**************************************************************************
66 * CNetFolder::ParseDisplayName
67 */
68 HRESULT WINAPI CNetFolder::ParseDisplayName(HWND hwndOwner, LPBC pbcReserved, LPOLESTR lpszDisplayName,
69 DWORD *pchEaten, LPITEMIDLIST *ppidl, DWORD *pdwAttributes)
70 {
71 HRESULT hr = E_UNEXPECTED;
72
73 TRACE("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n", this,
74 hwndOwner, pbcReserved, lpszDisplayName, debugstr_w (lpszDisplayName),
75 pchEaten, ppidl, pdwAttributes);
76
77 *ppidl = 0;
78 if (pchEaten)
79 *pchEaten = 0; /* strange but like the original */
80
81 TRACE("(%p)->(-- ret=0x%08x)\n", this, hr);
82
83 return hr;
84 }
85
86 /**************************************************************************
87 * CNetFolder::EnumObjects
88 */
89 HRESULT WINAPI CNetFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
90 {
91 TRACE("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", this,
92 hwndOwner, dwFlags, ppEnumIDList);
93
94 *ppEnumIDList = NULL; //IEnumIDList_Constructor();
95
96 TRACE("-- (%p)->(new ID List: %p)\n", this, *ppEnumIDList);
97 return S_FALSE;
98 // return (*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
99 }
100
101 /**************************************************************************
102 * CNetFolder::BindToObject
103 */
104 HRESULT WINAPI CNetFolder::BindToObject(LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
105 {
106 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", this,
107 pidl, pbcReserved, shdebugstr_guid (&riid), ppvOut);
108
109 return SHELL32_BindToChild(pidlRoot, NULL, pidl, riid, ppvOut);
110 }
111
112 /**************************************************************************
113 * CNetFolder::BindToStorage
114 */
115 HRESULT WINAPI CNetFolder::BindToStorage(LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
116 {
117 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", this,
118 pidl, pbcReserved, shdebugstr_guid (&riid), ppvOut);
119
120 *ppvOut = NULL;
121 return E_NOTIMPL;
122 }
123
124 /**************************************************************************
125 * CNetFolder::CompareIDs
126 */
127
128 HRESULT WINAPI CNetFolder::CompareIDs(LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
129 {
130 int nReturn;
131
132 TRACE("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", this, lParam, pidl1, pidl2);
133 nReturn = SHELL32_CompareIDs(this, lParam, pidl1, pidl2);
134 TRACE("-- %i\n", nReturn);
135 return nReturn;
136 }
137
138 /**************************************************************************
139 * CNetFolder::CreateViewObject
140 */
141 HRESULT WINAPI CNetFolder::CreateViewObject(HWND hwndOwner, REFIID riid, LPVOID *ppvOut)
142 {
143 LPSHELLVIEW pShellView;
144 HRESULT hr = E_INVALIDARG;
145
146 TRACE("(%p)->(hwnd=%p,%s,%p)\n", this,
147 hwndOwner, shdebugstr_guid (&riid), ppvOut);
148
149 if (!ppvOut)
150 return hr;
151
152 *ppvOut = NULL;
153
154 if (IsEqualIID(riid, IID_IDropTarget))
155 {
156 WARN("IDropTarget not implemented\n");
157 hr = E_NOTIMPL;
158 }
159 else if (IsEqualIID(riid, IID_IContextMenu))
160 {
161 WARN("IContextMenu not implemented\n");
162 hr = E_NOTIMPL;
163 }
164 else if (IsEqualIID(riid, IID_IShellView))
165 {
166 hr = IShellView_Constructor((IShellFolder *)this, &pShellView);
167 if (pShellView)
168 {
169 hr = pShellView->QueryInterface(riid, ppvOut);
170 pShellView->Release();
171 }
172 }
173 TRACE("-- (%p)->(interface=%p)\n", this, ppvOut);
174 return hr;
175 }
176
177 /**************************************************************************
178 * CNetFolder::GetAttributesOf
179 */
180 HRESULT WINAPI CNetFolder::GetAttributesOf(UINT cidl, LPCITEMIDLIST *apidl, DWORD *rgfInOut)
181 {
182 static const DWORD dwNethoodAttributes =
183 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
184 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER | SFGAO_CANRENAME | SFGAO_CANDELETE;
185 HRESULT hr = S_OK;
186
187 TRACE("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", this,
188 cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
189
190 if (!rgfInOut)
191 return E_INVALIDARG;
192 if (cidl && !apidl)
193 return E_INVALIDARG;
194
195 if (*rgfInOut == 0)
196 *rgfInOut = ~0;
197
198 if(cidl == 0)
199 *rgfInOut = dwNethoodAttributes;
200 else
201 {
202 while (cidl > 0 && *apidl)
203 {
204 pdump(*apidl);
205 SHELL32_GetItemAttributes(this, *apidl, rgfInOut);
206 apidl++;
207 cidl--;
208 }
209 }
210
211 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
212 *rgfInOut &= ~SFGAO_VALIDATE;
213
214 TRACE("-- result=0x%08x\n", *rgfInOut);
215 return hr;
216 }
217
218 /**************************************************************************
219 * CNetFolder::GetUIObjectOf
220 *
221 * PARAMETERS
222 * hwndOwner [in] Parent window for any output
223 * cidl [in] array size
224 * apidl [in] simple pidl array
225 * riid [in] Requested Interface
226 * prgfInOut [ ] reserved
227 * ppvObject [out] Resulting Interface
228 *
229 */
230 HRESULT WINAPI CNetFolder::GetUIObjectOf(HWND hwndOwner, UINT cidl, LPCITEMIDLIST *apidl, REFIID riid,
231 UINT * prgfInOut, LPVOID * ppvOut)
232 {
233 LPITEMIDLIST pidl;
234 IUnknown *pObj = NULL;
235 HRESULT hr = E_INVALIDARG;
236
237 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", this,
238 hwndOwner, cidl, apidl, shdebugstr_guid (&riid), prgfInOut, ppvOut);
239
240 if (!ppvOut)
241 return hr;
242
243 *ppvOut = NULL;
244
245 if (IsEqualIID(riid, IID_IContextMenu) && (cidl >= 1))
246 {
247 hr = CDefFolderMenu_Create2(pidlRoot, hwndOwner, cidl, apidl, (IShellFolder*)this, NULL, 0, NULL, (IContextMenu**)&pObj);
248 }
249 else if (IsEqualIID(riid, IID_IDataObject) && (cidl >= 1))
250 {
251 hr = IDataObject_Constructor (hwndOwner, pidlRoot, apidl, cidl, (IDataObject **)&pObj);
252 }
253 else if (IsEqualIID(riid, IID_IExtractIconA) && (cidl == 1))
254 {
255 pidl = ILCombine (pidlRoot, apidl[0]);
256 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
257 SHFree (pidl);
258 hr = S_OK;
259 }
260 else if (IsEqualIID(riid, IID_IExtractIconW) && (cidl == 1))
261 {
262 pidl = ILCombine (pidlRoot, apidl[0]);
263 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
264 SHFree (pidl);
265 hr = S_OK;
266 }
267 else if (IsEqualIID(riid, IID_IDropTarget) && (cidl >= 1))
268 {
269 hr = this->QueryInterface(IID_IDropTarget, (LPVOID *) & pObj);
270 }
271 else
272 hr = E_NOINTERFACE;
273
274 if (SUCCEEDED(hr) && !pObj)
275 hr = E_OUTOFMEMORY;
276
277 *ppvOut = pObj;
278 TRACE("(%p)->hr=0x%08x\n", this, hr);
279 return hr;
280 }
281
282 /**************************************************************************
283 * CNetFolder::GetDisplayNameOf
284 *
285 */
286 HRESULT WINAPI CNetFolder::GetDisplayNameOf(LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
287 {
288 FIXME("(%p)->(pidl=%p,0x%08x,%p)\n", this, pidl, dwFlags, strRet);
289 pdump(pidl);
290
291 if (!strRet)
292 return E_INVALIDARG;
293
294 return E_NOTIMPL;
295 }
296
297 /**************************************************************************
298 * CNetFolder::SetNameOf
299 * Changes the name of a file object or subfolder, possibly changing its item
300 * identifier in the process.
301 *
302 * PARAMETERS
303 * hwndOwner [in] Owner window for output
304 * pidl [in] simple pidl of item to change
305 * lpszName [in] the items new display name
306 * dwFlags [in] SHGNO formatting flags
307 * ppidlOut [out] simple pidl returned
308 */
309 HRESULT WINAPI CNetFolder::SetNameOf(HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */
310 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
311 {
312 FIXME("(%p)->(%p,pidl=%p,%s,%u,%p)\n", this,
313 hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
314 return E_FAIL;
315 }
316
317 HRESULT WINAPI CNetFolder::GetDefaultSearchGUID(GUID *pguid)
318 {
319 FIXME("(%p)\n", this);
320 return E_NOTIMPL;
321 }
322
323 HRESULT WINAPI CNetFolder::EnumSearches(IEnumExtraSearch ** ppenum)
324 {
325 FIXME("(%p)\n", this);
326 return E_NOTIMPL;
327 }
328
329 HRESULT WINAPI CNetFolder::GetDefaultColumn (DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
330 {
331 TRACE("(%p)\n", this);
332
333 if (pSort)
334 *pSort = 0;
335 if (pDisplay)
336 *pDisplay = 0;
337
338 return S_OK;
339 }
340
341 HRESULT WINAPI CNetFolder::GetDefaultColumnState(UINT iColumn, DWORD *pcsFlags)
342 {
343 TRACE("(%p)\n", this);
344
345 if (!pcsFlags || iColumn >= NETWORKPLACESSHELLVIEWCOLUMNS)
346 return E_INVALIDARG;
347 *pcsFlags = NetworkPlacesSFHeader[iColumn].pcsFlags;
348 return S_OK;
349 }
350
351 HRESULT WINAPI CNetFolder::GetDetailsEx(LPCITEMIDLIST pidl, const SHCOLUMNID *pscid, VARIANT *pv)
352 {
353 FIXME("(%p)\n", this);
354 return E_NOTIMPL;
355 }
356
357 HRESULT WINAPI CNetFolder::GetDetailsOf(LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS *psd)
358 {
359 WCHAR buffer[MAX_PATH] = {0};
360 HRESULT hr = E_FAIL;
361
362 if (iColumn >= NETWORKPLACESSHELLVIEWCOLUMNS)
363 return E_FAIL;
364
365 psd->fmt = NetworkPlacesSFHeader[iColumn].fmt;
366 psd->cxChar = NetworkPlacesSFHeader[iColumn].cxChar;
367 if (pidl == NULL)
368 {
369 psd->str.uType = STRRET_WSTR;
370 if (LoadStringW(shell32_hInstance, NetworkPlacesSFHeader[iColumn].colnameid, buffer, _countof(buffer)))
371 hr = SHStrDupW(buffer, &psd->str.pOleStr);
372
373 return hr;
374 }
375
376 if (iColumn == COLUMN_NAME)
377 return GetDisplayNameOf(pidl, SHGDN_NORMAL, &psd->str);
378
379 FIXME("(%p)->(%p %i %p)\n", this, pidl, iColumn, psd);
380
381 return E_NOTIMPL;
382 }
383
384 HRESULT WINAPI CNetFolder::MapColumnToSCID(UINT column, SHCOLUMNID *pscid)
385 {
386 FIXME("(%p)\n", this);
387
388 return E_NOTIMPL;
389 }
390
391 /************************************************************************
392 * CNetFolder::GetClassID
393 */
394 HRESULT WINAPI CNetFolder::GetClassID(CLSID *lpClassId)
395 {
396 TRACE("(%p)\n", this);
397
398 if (!lpClassId)
399 return E_POINTER;
400
401 *lpClassId = CLSID_NetworkPlaces;
402
403 return S_OK;
404 }
405
406 /************************************************************************
407 * CNetFolder::Initialize
408 *
409 * NOTES: it makes no sense to change the pidl
410 */
411 HRESULT WINAPI CNetFolder::Initialize(LPCITEMIDLIST pidl)
412 {
413 TRACE("(%p)->(%p)\n", this, pidl);
414
415 return E_NOTIMPL;
416 }
417
418 /**************************************************************************
419 * CNetFolder::GetCurFolder
420 */
421 HRESULT WINAPI CNetFolder::GetCurFolder(LPITEMIDLIST *pidl)
422 {
423 TRACE("(%p)->(%p)\n", this, pidl);
424
425 if (!pidl)
426 return E_POINTER;
427
428 *pidl = ILClone(pidlRoot);
429
430 return S_OK;
431 }