Sync with trunk r65656.
[reactos.git] / dll / win32 / shell32 / folders / CNetFolder.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 = _ILCreateGuid(PT_GUID, CLSID_NetworkPlaces); /* 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, PIDLIST_RELATIVE *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(PCUIDLIST_RELATIVE 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(PCUIDLIST_RELATIVE 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, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE 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 CComPtr<IShellView> 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 }
171 }
172 TRACE("-- (%p)->(interface=%p)\n", this, ppvOut);
173 return hr;
174 }
175
176 /**************************************************************************
177 * CNetFolder::GetAttributesOf
178 */
179 HRESULT WINAPI CNetFolder::GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut)
180 {
181 static const DWORD dwNethoodAttributes =
182 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
183 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER | SFGAO_CANRENAME | SFGAO_CANDELETE;
184 HRESULT hr = S_OK;
185
186 TRACE("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", this,
187 cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
188
189 if (!rgfInOut)
190 return E_INVALIDARG;
191 if (cidl && !apidl)
192 return E_INVALIDARG;
193
194 if (*rgfInOut == 0)
195 *rgfInOut = ~0;
196
197 if(cidl == 0)
198 *rgfInOut = dwNethoodAttributes;
199 else
200 {
201 while (cidl > 0 && *apidl)
202 {
203 pdump(*apidl);
204 SHELL32_GetItemAttributes(this, *apidl, rgfInOut);
205 apidl++;
206 cidl--;
207 }
208 }
209
210 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
211 *rgfInOut &= ~SFGAO_VALIDATE;
212
213 TRACE("-- result=0x%08x\n", *rgfInOut);
214 return hr;
215 }
216
217 /**************************************************************************
218 * CNetFolder::GetUIObjectOf
219 *
220 * PARAMETERS
221 * hwndOwner [in] Parent window for any output
222 * cidl [in] array size
223 * apidl [in] simple pidl array
224 * riid [in] Requested Interface
225 * prgfInOut [ ] reserved
226 * ppvObject [out] Resulting Interface
227 *
228 */
229 HRESULT WINAPI CNetFolder::GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid,
230 UINT * prgfInOut, LPVOID * ppvOut)
231 {
232 LPITEMIDLIST pidl;
233 IUnknown *pObj = NULL;
234 HRESULT hr = E_INVALIDARG;
235
236 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", this,
237 hwndOwner, cidl, apidl, shdebugstr_guid (&riid), prgfInOut, ppvOut);
238
239 if (!ppvOut)
240 return hr;
241
242 *ppvOut = NULL;
243
244 if (IsEqualIID(riid, IID_IContextMenu) && (cidl >= 1))
245 {
246 IContextMenu * pCm = NULL;
247 hr = CDefFolderMenu_Create2(pidlRoot, hwndOwner, cidl, apidl, static_cast<IShellFolder*>(this), NULL, 0, NULL, &pCm);
248 pObj = pCm;
249 }
250 else if (IsEqualIID(riid, IID_IDataObject) && (cidl >= 1))
251 {
252 IDataObject * pDo = NULL;
253 hr = IDataObject_Constructor (hwndOwner, pidlRoot, apidl, cidl, &pDo);
254 pObj = pDo;
255 }
256 else if (IsEqualIID(riid, IID_IExtractIconA) && (cidl == 1))
257 {
258 pidl = ILCombine (pidlRoot, apidl[0]);
259 pObj = IExtractIconA_Constructor (pidl);
260 SHFree (pidl);
261 hr = S_OK;
262 }
263 else if (IsEqualIID(riid, IID_IExtractIconW) && (cidl == 1))
264 {
265 pidl = ILCombine (pidlRoot, apidl[0]);
266 pObj = IExtractIconW_Constructor (pidl);
267 SHFree (pidl);
268 hr = S_OK;
269 }
270 else if (IsEqualIID(riid, IID_IDropTarget) && (cidl >= 1))
271 {
272 IDropTarget * pDt = NULL;
273 hr = this->QueryInterface(IID_PPV_ARG(IDropTarget, &pDt));
274 pObj = pDt;
275 }
276 else
277 hr = E_NOINTERFACE;
278
279 if (SUCCEEDED(hr) && !pObj)
280 hr = E_OUTOFMEMORY;
281
282 *ppvOut = pObj;
283 TRACE("(%p)->hr=0x%08x\n", this, hr);
284 return hr;
285 }
286
287 /**************************************************************************
288 * CNetFolder::GetDisplayNameOf
289 *
290 */
291 HRESULT WINAPI CNetFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET strRet)
292 {
293 FIXME("(%p)->(pidl=%p,0x%08x,%p)\n", this, pidl, dwFlags, strRet);
294 pdump(pidl);
295
296 if (!strRet)
297 return E_INVALIDARG;
298
299 return E_NOTIMPL;
300 }
301
302 /**************************************************************************
303 * CNetFolder::SetNameOf
304 * Changes the name of a file object or subfolder, possibly changing its item
305 * identifier in the process.
306 *
307 * PARAMETERS
308 * hwndOwner [in] Owner window for output
309 * pidl [in] simple pidl of item to change
310 * lpszName [in] the items new display name
311 * dwFlags [in] SHGNO formatting flags
312 * ppidlOut [out] simple pidl returned
313 */
314 HRESULT WINAPI CNetFolder::SetNameOf(HWND hwndOwner, PCUITEMID_CHILD pidl, /*simple pidl */
315 LPCOLESTR lpName, DWORD dwFlags, PITEMID_CHILD *pPidlOut)
316 {
317 FIXME("(%p)->(%p,pidl=%p,%s,%u,%p)\n", this,
318 hwndOwner, pidl, debugstr_w (lpName), dwFlags, pPidlOut);
319 return E_FAIL;
320 }
321
322 HRESULT WINAPI CNetFolder::GetDefaultSearchGUID(GUID *pguid)
323 {
324 FIXME("(%p)\n", this);
325 return E_NOTIMPL;
326 }
327
328 HRESULT WINAPI CNetFolder::EnumSearches(IEnumExtraSearch ** ppenum)
329 {
330 FIXME("(%p)\n", this);
331 return E_NOTIMPL;
332 }
333
334 HRESULT WINAPI CNetFolder::GetDefaultColumn (DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
335 {
336 TRACE("(%p)\n", this);
337
338 if (pSort)
339 *pSort = 0;
340 if (pDisplay)
341 *pDisplay = 0;
342
343 return S_OK;
344 }
345
346 HRESULT WINAPI CNetFolder::GetDefaultColumnState(UINT iColumn, DWORD *pcsFlags)
347 {
348 TRACE("(%p)\n", this);
349
350 if (!pcsFlags || iColumn >= NETWORKPLACESSHELLVIEWCOLUMNS)
351 return E_INVALIDARG;
352 *pcsFlags = NetworkPlacesSFHeader[iColumn].pcsFlags;
353 return S_OK;
354 }
355
356 HRESULT WINAPI CNetFolder::GetDetailsEx(PCUITEMID_CHILD pidl, const SHCOLUMNID *pscid, VARIANT *pv)
357 {
358 FIXME("(%p)\n", this);
359 return E_NOTIMPL;
360 }
361
362 HRESULT WINAPI CNetFolder::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *psd)
363 {
364 WCHAR buffer[MAX_PATH] = {0};
365 HRESULT hr = E_FAIL;
366
367 if (iColumn >= NETWORKPLACESSHELLVIEWCOLUMNS)
368 return E_FAIL;
369
370 psd->fmt = NetworkPlacesSFHeader[iColumn].fmt;
371 psd->cxChar = NetworkPlacesSFHeader[iColumn].cxChar;
372 if (pidl == NULL)
373 {
374 psd->str.uType = STRRET_WSTR;
375 if (LoadStringW(shell32_hInstance, NetworkPlacesSFHeader[iColumn].colnameid, buffer, _countof(buffer)))
376 hr = SHStrDupW(buffer, &psd->str.pOleStr);
377
378 return hr;
379 }
380
381 if (iColumn == COLUMN_NAME)
382 return GetDisplayNameOf(pidl, SHGDN_NORMAL, &psd->str);
383
384 FIXME("(%p)->(%p %i %p)\n", this, pidl, iColumn, psd);
385
386 return E_NOTIMPL;
387 }
388
389 HRESULT WINAPI CNetFolder::MapColumnToSCID(UINT column, SHCOLUMNID *pscid)
390 {
391 FIXME("(%p)\n", this);
392
393 return E_NOTIMPL;
394 }
395
396 /************************************************************************
397 * CNetFolder::GetClassID
398 */
399 HRESULT WINAPI CNetFolder::GetClassID(CLSID *lpClassId)
400 {
401 TRACE("(%p)\n", this);
402
403 if (!lpClassId)
404 return E_POINTER;
405
406 *lpClassId = CLSID_NetworkPlaces;
407
408 return S_OK;
409 }
410
411 /************************************************************************
412 * CNetFolder::Initialize
413 *
414 * NOTES: it makes no sense to change the pidl
415 */
416 HRESULT WINAPI CNetFolder::Initialize(LPCITEMIDLIST pidl)
417 {
418 TRACE("(%p)->(%p)\n", this, pidl);
419
420 return E_NOTIMPL;
421 }
422
423 /**************************************************************************
424 * CNetFolder::GetCurFolder
425 */
426 HRESULT WINAPI CNetFolder::GetCurFolder(LPITEMIDLIST *pidl)
427 {
428 TRACE("(%p)->(%p)\n", this, pidl);
429
430 if (!pidl)
431 return E_POINTER;
432
433 *pidl = ILClone(pidlRoot);
434
435 return S_OK;
436 }