msvideo.dll16: Check if any 16 bit thunks have been allocated before accessing pointer.
[wine.git] / dlls / shell32 / shfldr_fs.c
blobc7259276d1d6c5d67e32c95ac66b401f4e0f881f
2 /*
3 * file system folder
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998, 1999, 2002 Juergen Schmied
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
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
31 #define COBJMACROS
32 #define NONAMELESSUNION
34 #include "winerror.h"
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winreg.h"
38 #include "wingdi.h"
39 #include "winuser.h"
41 #include "ole2.h"
42 #include "shlguid.h"
44 #include "pidl.h"
45 #include "undocshell.h"
46 #include "shell32_main.h"
47 #include "shresdef.h"
48 #include "shlwapi.h"
49 #include "shellfolder.h"
50 #include "wine/debug.h"
51 #include "debughlp.h"
52 #include "shfldr.h"
54 WINE_DEFAULT_DEBUG_CHANNEL (shell);
56 /***********************************************************************
57 * IShellFolder implementation
60 typedef struct {
61 IUnknown IUnknown_inner;
62 LONG ref;
63 IShellFolder2 IShellFolder2_iface;
64 IPersistFolder3 IPersistFolder3_iface;
65 IDropTarget IDropTarget_iface;
66 ISFHelper ISFHelper_iface;
67 IUnknown *outer_unk;
69 CLSID *pclsid;
71 /* both paths are parsible from the desktop */
72 LPWSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
74 LPITEMIDLIST pidlRoot; /* absolute pidl */
76 UINT cfShellIDList; /* clipboardformat for IDropTarget */
77 BOOL fAcceptFmt; /* flag for pending Drop */
78 } IGenericSFImpl;
80 static inline IGenericSFImpl *impl_from_IUnknown(IUnknown *iface)
82 return CONTAINING_RECORD(iface, IGenericSFImpl, IUnknown_inner);
85 static inline IGenericSFImpl *impl_from_IShellFolder2(IShellFolder2 *iface)
87 return CONTAINING_RECORD(iface, IGenericSFImpl, IShellFolder2_iface);
90 static inline IGenericSFImpl *impl_from_IPersistFolder3(IPersistFolder3 *iface)
92 return CONTAINING_RECORD(iface, IGenericSFImpl, IPersistFolder3_iface);
95 static inline IGenericSFImpl *impl_from_IDropTarget(IDropTarget *iface)
97 return CONTAINING_RECORD(iface, IGenericSFImpl, IDropTarget_iface);
100 static inline IGenericSFImpl *impl_from_ISFHelper(ISFHelper *iface)
102 return CONTAINING_RECORD(iface, IGenericSFImpl, ISFHelper_iface);
105 /**************************************************************************
106 * registers clipboardformat once
108 static void SF_RegisterClipFmt (IGenericSFImpl * This)
110 TRACE ("(%p)\n", This);
112 if (!This->cfShellIDList) {
113 This->cfShellIDList = RegisterClipboardFormatW (CFSTR_SHELLIDLISTW);
117 /**************************************************************************
118 * inner IUnknown
120 static HRESULT WINAPI IUnknown_fnQueryInterface(IUnknown *iface, REFIID riid, void **ppvObj)
122 IGenericSFImpl *This = impl_from_IUnknown(iface);
124 TRACE("(%p)->(%s,%p)\n", This, shdebugstr_guid(riid), ppvObj);
126 *ppvObj = NULL;
128 if (IsEqualIID (riid, &IID_IUnknown))
129 *ppvObj = &This->IUnknown_inner;
130 else if (IsEqualIID(riid, &IID_IShellFolder) || IsEqualIID(riid, &IID_IShellFolder2))
131 *ppvObj = &This->IShellFolder2_iface;
132 else if (IsEqualIID(riid, &IID_IPersist) || IsEqualIID(riid, &IID_IPersistFolder) ||
133 IsEqualIID(riid, &IID_IPersistFolder2) || IsEqualIID(riid, &IID_IPersistFolder3))
134 *ppvObj = &This->IPersistFolder3_iface;
135 else if (IsEqualIID (riid, &IID_ISFHelper))
136 *ppvObj = &This->ISFHelper_iface;
137 else if (IsEqualIID (riid, &IID_IDropTarget)) {
138 *ppvObj = &This->IDropTarget_iface;
139 SF_RegisterClipFmt(This);
142 if (*ppvObj) {
143 IUnknown_AddRef((IUnknown *)*ppvObj);
144 TRACE ("-- Interface = %p\n", *ppvObj);
145 return S_OK;
147 TRACE ("-- Interface: E_NOINTERFACE\n");
148 return E_NOINTERFACE;
151 static ULONG WINAPI IUnknown_fnAddRef(IUnknown *iface)
153 IGenericSFImpl *This = impl_from_IUnknown(iface);
154 ULONG ref = InterlockedIncrement(&This->ref);
156 TRACE("(%p) ref=%d\n", This, ref);
158 return ref;
161 static ULONG WINAPI IUnknown_fnRelease(IUnknown *iface)
163 IGenericSFImpl *This = impl_from_IUnknown(iface);
164 ULONG ref = InterlockedDecrement(&This->ref);
166 TRACE("(%p) ref=%d\n", This, ref);
168 if (!ref) {
169 TRACE("-- destroying IShellFolder(%p)\n", This);
171 SHFree(This->pidlRoot);
172 SHFree(This->sPathTarget);
173 LocalFree(This);
175 return ref;
178 static const IUnknownVtbl unkvt =
180 IUnknown_fnQueryInterface,
181 IUnknown_fnAddRef,
182 IUnknown_fnRelease,
185 static const shvheader GenericSFHeader[] = {
186 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
187 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
188 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
189 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
190 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
193 #define GENERICSHELLVIEWCOLUMNS 5
195 /**************************************************************************
196 * IShellFolder_fnQueryInterface
198 static HRESULT WINAPI IShellFolder_fnQueryInterface(IShellFolder2 *iface, REFIID riid,
199 void **ppvObj)
201 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
203 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
206 /**************************************************************************
207 * IShellFolder_AddRef
209 static ULONG WINAPI IShellFolder_fnAddRef(IShellFolder2 *iface)
211 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
213 return IUnknown_AddRef(This->outer_unk);
216 /**************************************************************************
217 * IShellFolder_fnRelease
219 static ULONG WINAPI IShellFolder_fnRelease(IShellFolder2 *iface)
221 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
223 return IUnknown_Release(This->outer_unk);
226 /**************************************************************************
227 * SHELL32_CreatePidlFromBindCtx [internal]
229 * If the caller bound File System Bind Data, assume it is the
230 * find data for the path.
231 * This allows binding of paths that don't exist.
233 LPITEMIDLIST SHELL32_CreatePidlFromBindCtx(IBindCtx *pbc, LPCWSTR path)
235 static WCHAR szfsbc[] = {
236 'F','i','l','e',' ','S','y','s','t','e','m',' ',
237 'B','i','n','d',' ','D','a','t','a',0 };
238 IFileSystemBindData *fsbd = NULL;
239 LPITEMIDLIST pidl = NULL;
240 IUnknown *unk = NULL;
241 HRESULT r;
243 TRACE("%p %s\n", pbc, debugstr_w(path));
245 if (!pbc)
246 return NULL;
248 /* see if the caller bound File System Bind Data */
249 r = IBindCtx_GetObjectParam( pbc, szfsbc, &unk );
250 if (FAILED(r))
251 return NULL;
253 r = IUnknown_QueryInterface( unk, &IID_IFileSystemBindData, (void**)&fsbd );
254 if (SUCCEEDED(r))
256 WIN32_FIND_DATAW wfd;
258 r = IFileSystemBindData_GetFindData( fsbd, &wfd );
259 if (SUCCEEDED(r))
261 lstrcpynW( &wfd.cFileName[0], path, MAX_PATH );
262 pidl = _ILCreateFromFindDataW( &wfd );
264 IFileSystemBindData_Release( fsbd );
266 IUnknown_Release( unk );
268 return pidl;
271 /**************************************************************************
272 * IShellFolder_ParseDisplayName {SHELL32}
274 * Parse a display name.
276 * PARAMS
277 * hwndOwner [in] Parent window for any message's
278 * pbc [in] optional FileSystemBindData context
279 * lpszDisplayName [in] Unicode displayname.
280 * pchEaten [out] (unicode) characters processed
281 * ppidl [out] complex pidl to item
282 * pdwAttributes [out] items attributes
284 * NOTES
285 * Every folder tries to parse only its own (the leftmost) pidl and creates a
286 * subfolder to evaluate the remaining parts.
287 * Now we can parse into namespaces implemented by shell extensions
289 * Behaviour on win98: lpszDisplayName=NULL -> crash
290 * lpszDisplayName="" -> returns mycoputer-pidl
292 * FIXME
293 * pdwAttributes is not set
294 * pchEaten is not set like in windows
296 static HRESULT WINAPI
297 IShellFolder_fnParseDisplayName (IShellFolder2 * iface,
298 HWND hwndOwner,
299 LPBC pbc,
300 LPOLESTR lpszDisplayName,
301 DWORD * pchEaten, LPITEMIDLIST * ppidl,
302 DWORD * pdwAttributes)
304 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
306 HRESULT hr = E_INVALIDARG;
307 LPCWSTR szNext = NULL;
308 WCHAR szElement[MAX_PATH];
309 WCHAR szPath[MAX_PATH];
310 LPITEMIDLIST pidlTemp = NULL;
311 DWORD len;
313 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
314 This, hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
315 pchEaten, ppidl, pdwAttributes);
317 if (!lpszDisplayName || !ppidl)
318 return E_INVALIDARG;
320 if (pchEaten)
321 *pchEaten = 0; /* strange but like the original */
323 pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName);
324 if (!pidlTemp && *lpszDisplayName)
326 /* get the next element */
327 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
329 /* build the full pathname to the element */
330 lstrcpynW(szPath, This->sPathTarget, MAX_PATH - 1);
331 PathAddBackslashW(szPath);
332 len = lstrlenW(szPath);
333 lstrcpynW(szPath + len, szElement, MAX_PATH - len);
335 /* get the pidl */
336 hr = _ILCreateFromPathW(szPath, &pidlTemp);
338 if (SUCCEEDED(hr)) {
339 if (szNext && *szNext) {
340 /* try to analyse the next element */
341 hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc,
342 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
343 } else {
344 /* it's the last element */
345 if (pdwAttributes && *pdwAttributes)
346 hr = SHELL32_GetItemAttributes(&This->IShellFolder2_iface, pidlTemp, pdwAttributes);
351 if (SUCCEEDED(hr))
352 *ppidl = pidlTemp;
353 else
354 *ppidl = NULL;
356 TRACE ("(%p)->(-- pidl=%p ret=0x%08x)\n", This, *ppidl, hr);
358 return hr;
361 /**************************************************************************
362 * IShellFolder_fnEnumObjects
363 * PARAMETERS
364 * HWND hwndOwner, //[in ] Parent Window
365 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
366 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
368 static HRESULT WINAPI
369 IShellFolder_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner,
370 DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
372 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
373 IEnumIDListImpl *list;
375 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This, hwndOwner,
376 dwFlags, ppEnumIDList);
378 if (!(list = IEnumIDList_Constructor()))
379 return E_OUTOFMEMORY;
380 CreateFolderEnumList(list, This->sPathTarget, dwFlags);
381 *ppEnumIDList = &list->IEnumIDList_iface;
383 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
385 return S_OK;
388 /**************************************************************************
389 * IShellFolder_fnBindToObject
390 * PARAMETERS
391 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
392 * LPBC pbc, //[in ] optional FileSystemBindData context
393 * REFIID riid, //[in ] Initial Interface
394 * LPVOID* ppvObject //[out] Interface*
396 static HRESULT WINAPI
397 IShellFolder_fnBindToObject (IShellFolder2 * iface, LPCITEMIDLIST pidl,
398 LPBC pbc, REFIID riid, LPVOID * ppvOut)
400 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
402 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbc,
403 shdebugstr_guid (riid), ppvOut);
405 return SHELL32_BindToChild (This->pidlRoot, This->sPathTarget, pidl, riid,
406 ppvOut);
409 /**************************************************************************
410 * IShellFolder_fnBindToStorage
411 * PARAMETERS
412 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
413 * LPBC pbc, //[in ] reserved
414 * REFIID riid, //[in ] Initial storage interface
415 * LPVOID* ppvObject //[out] Interface* returned
417 static HRESULT WINAPI
418 IShellFolder_fnBindToStorage (IShellFolder2 * iface, LPCITEMIDLIST pidl,
419 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
421 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
423 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved,
424 shdebugstr_guid (riid), ppvOut);
426 *ppvOut = NULL;
427 return E_NOTIMPL;
430 /**************************************************************************
431 * IShellFolder_fnCompareIDs
434 static HRESULT WINAPI
435 IShellFolder_fnCompareIDs (IShellFolder2 * iface, LPARAM lParam,
436 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
438 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
440 int nReturn;
442 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
443 nReturn = SHELL32_CompareIDs(&This->IShellFolder2_iface, lParam, pidl1, pidl2);
444 TRACE ("-- %i\n", nReturn);
445 return nReturn;
448 /**************************************************************************
449 * IShellFolder_fnCreateViewObject
451 static HRESULT WINAPI
452 IShellFolder_fnCreateViewObject (IShellFolder2 * iface, HWND hwndOwner,
453 REFIID riid, LPVOID * ppvOut)
455 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
457 LPSHELLVIEW pShellView;
458 HRESULT hr = E_INVALIDARG;
460 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid),
461 ppvOut);
463 if (ppvOut) {
464 *ppvOut = NULL;
466 if (IsEqualIID (riid, &IID_IDropTarget)) {
467 hr = IShellFolder2_QueryInterface (iface, &IID_IDropTarget, ppvOut);
468 } else if (IsEqualIID (riid, &IID_IContextMenu)) {
469 FIXME ("IContextMenu not implemented\n");
470 hr = E_NOTIMPL;
471 } else if (IsEqualIID (riid, &IID_IShellView)) {
472 pShellView = IShellView_Constructor ((IShellFolder *) iface);
473 if (pShellView) {
474 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
475 IShellView_Release (pShellView);
479 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
480 return hr;
483 /**************************************************************************
484 * IShellFolder_fnGetAttributesOf
486 * PARAMETERS
487 * UINT cidl, //[in ] num elements in pidl array
488 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
489 * ULONG* rgfInOut) //[out] result array
492 static HRESULT WINAPI
493 IShellFolder_fnGetAttributesOf (IShellFolder2 * iface, UINT cidl,
494 LPCITEMIDLIST * apidl, DWORD * rgfInOut)
496 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
498 HRESULT hr = S_OK;
500 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", This, cidl, apidl,
501 rgfInOut, rgfInOut ? *rgfInOut : 0);
503 if (!rgfInOut)
504 return E_INVALIDARG;
505 if (cidl && !apidl)
506 return E_INVALIDARG;
508 if (*rgfInOut == 0)
509 *rgfInOut = ~0;
511 if(cidl == 0){
512 IShellFolder2 *parent = NULL;
513 LPCITEMIDLIST rpidl = NULL;
515 hr = SHBindToParent(This->pidlRoot, &IID_IShellFolder2, (void **)&parent, &rpidl);
516 if(SUCCEEDED(hr)) {
517 SHELL32_GetItemAttributes(parent, rpidl, rgfInOut);
518 IShellFolder2_Release(parent);
521 else {
522 while (cidl > 0 && *apidl) {
523 pdump (*apidl);
524 SHELL32_GetItemAttributes(&This->IShellFolder2_iface, *apidl, rgfInOut);
525 apidl++;
526 cidl--;
529 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
530 *rgfInOut &= ~SFGAO_VALIDATE;
532 TRACE ("-- result=0x%08x\n", *rgfInOut);
534 return hr;
537 /**************************************************************************
538 * SHELL32_CreateExtensionUIObject (internal)
540 HRESULT SHELL32_CreateExtensionUIObject(IShellFolder2 *iface,
541 LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppvOut)
543 static const WCHAR reg_blockedW[] = {'S','o','f','t','w','a','r','e','\\',
544 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
545 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
546 'S','h','e','l','l',' ','E','x','t','e','n','s','i','o','n','s','\\',
547 'B','l','o','c','k','e','d',0};
548 static const WCHAR formatW[] = {'.','%','s','\\','S','h','e','l','l','E','x','\\',
549 '{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
550 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
551 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
553 IPersistFile *persist_file;
554 char extensionA[20];
555 WCHAR extensionW[20], buf[MAX_PATH];
556 DWORD size = MAX_PATH;
557 STRRET path;
558 WCHAR *file;
559 GUID guid;
560 HKEY key;
561 HRESULT hr;
564 if(!_ILGetExtension(pidl, extensionA, 20))
565 return S_FALSE;
567 MultiByteToWideChar(CP_ACP, 0, extensionA, -1, extensionW, 20);
569 sprintfW(buf, formatW, extensionW, riid->Data1, riid->Data2, riid->Data3,
570 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
571 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]);
573 if(RegGetValueW(HKEY_CLASSES_ROOT, buf, NULL, RRF_RT_REG_SZ,
574 NULL, buf, &size) != ERROR_SUCCESS)
575 return S_FALSE;
577 if(RegCreateKeyExW(HKEY_LOCAL_MACHINE, reg_blockedW, 0, 0, 0,
578 KEY_READ, NULL, &key, NULL) != ERROR_SUCCESS)
579 return E_FAIL;
580 if(RegQueryValueExW(key, buf, 0, NULL, NULL, NULL)
581 != ERROR_FILE_NOT_FOUND)
582 return E_ACCESSDENIED;
583 RegCloseKey(key);
585 if(RegCreateKeyExW(HKEY_CURRENT_USER, reg_blockedW, 0, 0, 0,
586 KEY_READ, NULL, &key, NULL) != ERROR_SUCCESS)
587 return E_FAIL;
588 if(RegQueryValueExW(key, buf, 0, NULL, NULL, NULL)
589 != ERROR_FILE_NOT_FOUND)
590 return E_ACCESSDENIED;
591 RegCloseKey(key);
593 if(!GUIDFromStringW(buf, &guid))
594 return E_FAIL;
596 hr = CoCreateInstance(&guid, NULL, CLSCTX_INPROC_SERVER,
597 &IID_IPersistFile, (void**)&persist_file);
598 if(FAILED(hr))
599 return hr;
601 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_FORPARSING, &path);
602 if(SUCCEEDED(hr))
603 hr = StrRetToStrW(&path, NULL, &file);
604 if(FAILED(hr)) {
605 IPersistFile_Release(persist_file);
606 return hr;
609 hr = IPersistFile_Load(persist_file, file, STGM_READ);
610 CoTaskMemFree(file);
611 if(FAILED(hr)) {
612 IPersistFile_Release(persist_file);
613 return hr;
616 hr = IPersistFile_QueryInterface(persist_file, riid, ppvOut);
617 IPersistFile_Release(persist_file);
618 return hr;
621 /**************************************************************************
622 * IShellFolder_fnGetUIObjectOf
624 * PARAMETERS
625 * HWND hwndOwner, //[in ] Parent window for any output
626 * UINT cidl, //[in ] array size
627 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
628 * REFIID riid, //[in ] Requested Interface
629 * UINT* prgfInOut, //[ ] reserved
630 * LPVOID* ppvObject) //[out] Resulting Interface
632 * NOTES
633 * This function gets asked to return "view objects" for one or more (multiple
634 * select) items:
635 * The viewobject typically is an COM object with one of the following
636 * interfaces:
637 * IExtractIcon,IDataObject,IContextMenu
638 * In order to support icon positions in the default Listview your DataObject
639 * must implement the SetData method (in addition to GetData :) - the shell
640 * passes a barely documented "Icon positions" structure to SetData when the
641 * drag starts, and GetData's it if the drop is in another explorer window that
642 * needs the positions.
644 static HRESULT WINAPI
645 IShellFolder_fnGetUIObjectOf (IShellFolder2 * iface,
646 HWND hwndOwner,
647 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
648 UINT * prgfInOut, LPVOID * ppvOut)
650 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
652 LPITEMIDLIST pidl;
653 IUnknown *pObj = NULL;
654 HRESULT hr = E_INVALIDARG;
656 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
657 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
659 if (ppvOut) {
660 *ppvOut = NULL;
662 if(cidl == 1) {
663 hr = SHELL32_CreateExtensionUIObject(iface, *apidl, riid, ppvOut);
664 if(hr != S_FALSE)
665 return hr;
668 if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
669 return ItemMenu_Constructor((IShellFolder*)iface, This->pidlRoot, apidl, cidl, riid, ppvOut);
670 } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
671 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner,
672 This->pidlRoot, apidl, cidl);
673 hr = S_OK;
674 } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
675 pidl = ILCombine (This->pidlRoot, apidl[0]);
676 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
677 SHFree (pidl);
678 hr = S_OK;
679 } else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1)) {
680 pidl = ILCombine (This->pidlRoot, apidl[0]);
681 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
682 SHFree (pidl);
683 hr = S_OK;
684 } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
685 hr = IShellFolder2_QueryInterface (iface, &IID_IDropTarget,
686 (LPVOID *) & pObj);
687 } else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
688 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1)) {
689 pidl = ILCombine (This->pidlRoot, apidl[0]);
690 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, &pObj);
691 SHFree (pidl);
692 } else {
693 hr = E_NOINTERFACE;
696 if (SUCCEEDED(hr) && !pObj)
697 hr = E_OUTOFMEMORY;
699 *ppvOut = pObj;
701 TRACE ("(%p)->hr=0x%08x\n", This, hr);
702 return hr;
705 static const WCHAR AdvancedW[] = { 'S','O','F','T','W','A','R','E',
706 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
707 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
708 'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
709 static const WCHAR HideFileExtW[] = { 'H','i','d','e','F','i','l','e','E','x',
710 't',0 };
711 static const WCHAR NeverShowExtW[] = { 'N','e','v','e','r','S','h','o','w','E',
712 'x','t',0 };
714 /******************************************************************************
715 * SHELL_FS_HideExtension [Internal]
717 * Query the registry if the filename extension of a given path should be
718 * hidden.
720 * PARAMS
721 * szPath [I] Relative or absolute path of a file
723 * RETURNS
724 * TRUE, if the filename's extension should be hidden
725 * FALSE, otherwise.
727 BOOL SHELL_FS_HideExtension(LPCWSTR szPath)
729 HKEY hKey;
730 DWORD dwData;
731 DWORD dwDataSize = sizeof (DWORD);
732 BOOL doHide = FALSE; /* The default value is FALSE (win98 at least) */
734 if (!RegCreateKeyExW(HKEY_CURRENT_USER, AdvancedW, 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0)) {
735 if (!RegQueryValueExW(hKey, HideFileExtW, 0, 0, (LPBYTE) &dwData, &dwDataSize))
736 doHide = dwData;
737 RegCloseKey (hKey);
740 if (!doHide) {
741 LPWSTR ext = PathFindExtensionW(szPath);
743 if (*ext != '\0') {
744 WCHAR classname[MAX_PATH];
745 LONG classlen = sizeof(classname);
747 if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, classname, &classlen))
748 if (!RegOpenKeyW(HKEY_CLASSES_ROOT, classname, &hKey)) {
749 if (!RegQueryValueExW(hKey, NeverShowExtW, 0, NULL, NULL, NULL))
750 doHide = TRUE;
751 RegCloseKey(hKey);
755 return doHide;
758 void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath, DWORD dwFlags)
760 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
761 if (!(dwFlags & SHGDN_FORPARSING) &&
762 ((dwFlags & SHGDN_INFOLDER) || (dwFlags == SHGDN_NORMAL))) {
763 if (SHELL_FS_HideExtension(szPath) && szPath[0] != '.')
764 PathRemoveExtensionW(szPath);
768 /**************************************************************************
769 * IShellFolder_fnGetDisplayNameOf
770 * Retrieves the display name for the specified file object or subfolder
772 * PARAMETERS
773 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
774 * DWORD dwFlags, //[in ] SHGNO formatting flags
775 * LPSTRRET lpName) //[out] Returned display name
777 * FIXME
778 * if the name is in the pidl the ret value should be a STRRET_OFFSET
781 static HRESULT WINAPI
782 IShellFolder_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
783 DWORD dwFlags, LPSTRRET strRet)
785 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
786 LPWSTR pszPath;
788 HRESULT hr = S_OK;
789 int len = 0;
791 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
792 pdump (pidl);
794 if (!pidl || !strRet)
795 return E_INVALIDARG;
797 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
798 if (!pszPath)
799 return E_OUTOFMEMORY;
801 if (_ILIsDesktop(pidl)) { /* empty pidl */
802 if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) &&
803 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
805 if (This->sPathTarget)
806 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH);
807 } else {
808 /* pidl has to contain exactly one non null SHITEMID */
809 hr = E_INVALIDARG;
811 } else if (_ILIsPidlSimple(pidl)) {
812 if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) &&
813 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER) &&
814 This->sPathTarget)
816 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH);
817 PathAddBackslashW(pszPath);
818 len = lstrlenW(pszPath);
820 _ILSimpleGetTextW(pidl, pszPath + len, MAX_PATH + 1 - len);
821 if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
822 } else {
823 hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, pszPath, MAX_PATH);
826 if (SUCCEEDED(hr)) {
827 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
828 if (GetVersion() & 0x80000000) {
829 strRet->uType = STRRET_CSTR;
830 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
831 NULL, NULL))
832 strRet->u.cStr[0] = '\0';
833 CoTaskMemFree(pszPath);
834 } else {
835 strRet->uType = STRRET_WSTR;
836 strRet->u.pOleStr = pszPath;
838 } else
839 CoTaskMemFree(pszPath);
841 TRACE ("-- (%p)->(%s)\n", This, strRet->uType == STRRET_CSTR ? strRet->u.cStr : debugstr_w(strRet->u.pOleStr));
842 return hr;
845 /**************************************************************************
846 * IShellFolder_fnSetNameOf
847 * Changes the name of a file object or subfolder, possibly changing its item
848 * identifier in the process.
850 * PARAMETERS
851 * HWND hwndOwner, //[in ] Owner window for output
852 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
853 * LPCOLESTR lpszName, //[in ] the items new display name
854 * DWORD dwFlags, //[in ] SHGNO formatting flags
855 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
857 static HRESULT WINAPI IShellFolder_fnSetNameOf (IShellFolder2 * iface,
858 HWND hwndOwner,
859 LPCITEMIDLIST pidl,
860 LPCOLESTR lpName,
861 DWORD dwFlags,
862 LPITEMIDLIST * pPidlOut)
864 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
865 WCHAR szSrc[MAX_PATH + 1], szDest[MAX_PATH + 1];
866 LPWSTR ptr;
867 BOOL bIsFolder = _ILIsFolder (ILFindLastID (pidl));
869 TRACE ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl,
870 debugstr_w (lpName), dwFlags, pPidlOut);
872 /* build source path */
873 lstrcpynW(szSrc, This->sPathTarget, MAX_PATH);
874 ptr = PathAddBackslashW (szSrc);
875 if (ptr)
876 _ILSimpleGetTextW (pidl, ptr, MAX_PATH + 1 - (ptr - szSrc));
878 /* build destination path */
879 if (dwFlags == SHGDN_NORMAL || dwFlags & SHGDN_INFOLDER) {
880 lstrcpynW(szDest, This->sPathTarget, MAX_PATH);
881 ptr = PathAddBackslashW (szDest);
882 if (ptr)
883 lstrcpynW(ptr, lpName, MAX_PATH + 1 - (ptr - szDest));
884 } else
885 lstrcpynW(szDest, lpName, MAX_PATH);
887 if(!(dwFlags & SHGDN_FORPARSING) && SHELL_FS_HideExtension(szSrc)) {
888 WCHAR *ext = PathFindExtensionW(szSrc);
889 if(*ext != '\0') {
890 INT len = strlenW(szDest);
891 lstrcpynW(szDest + len, ext, MAX_PATH - len);
895 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc), debugstr_w(szDest));
897 if (MoveFileW (szSrc, szDest)) {
898 HRESULT hr = S_OK;
900 if (pPidlOut)
901 hr = _ILCreateFromPathW(szDest, pPidlOut);
903 SHChangeNotify (bIsFolder ? SHCNE_RENAMEFOLDER : SHCNE_RENAMEITEM,
904 SHCNF_PATHW, szSrc, szDest);
906 return hr;
909 return E_FAIL;
912 static HRESULT WINAPI IShellFolder_fnGetDefaultSearchGUID (IShellFolder2 *iface,
913 GUID * pguid)
915 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
916 FIXME ("(%p)\n", This);
917 return E_NOTIMPL;
919 static HRESULT WINAPI IShellFolder_fnEnumSearches (IShellFolder2 * iface,
920 IEnumExtraSearch ** ppenum)
922 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
923 FIXME ("(%p)\n", This);
924 return E_NOTIMPL;
927 static HRESULT WINAPI
928 IShellFolder_fnGetDefaultColumn (IShellFolder2 * iface, DWORD dwRes,
929 ULONG * pSort, ULONG * pDisplay)
931 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
933 TRACE ("(%p)\n", This);
935 if (pSort)
936 *pSort = 0;
937 if (pDisplay)
938 *pDisplay = 0;
940 return S_OK;
943 static HRESULT WINAPI
944 IShellFolder_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn,
945 DWORD * pcsFlags)
947 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
949 TRACE ("(%p)\n", This);
951 if (!pcsFlags || iColumn >= GENERICSHELLVIEWCOLUMNS)
952 return E_INVALIDARG;
954 *pcsFlags = GenericSFHeader[iColumn].pcsFlags;
956 return S_OK;
959 static HRESULT WINAPI
960 IShellFolder_fnGetDetailsEx (IShellFolder2 * iface, LPCITEMIDLIST pidl,
961 const SHCOLUMNID * pscid, VARIANT * pv)
963 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
964 FIXME ("(%p)\n", This);
966 return E_NOTIMPL;
969 static HRESULT WINAPI
970 IShellFolder_fnGetDetailsOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
971 UINT iColumn, SHELLDETAILS * psd)
973 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
974 HRESULT hr = E_FAIL;
976 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
978 if (!psd || iColumn >= GENERICSHELLVIEWCOLUMNS)
979 return E_INVALIDARG;
981 if (!pidl) {
982 /* the header titles */
983 psd->fmt = GenericSFHeader[iColumn].fmt;
984 psd->cxChar = GenericSFHeader[iColumn].cxChar;
985 psd->str.uType = STRRET_CSTR;
986 LoadStringA (shell32_hInstance, GenericSFHeader[iColumn].colnameid,
987 psd->str.u.cStr, MAX_PATH);
988 return S_OK;
989 } else {
990 hr = S_OK;
991 psd->str.uType = STRRET_CSTR;
992 /* the data from the pidl */
993 switch (iColumn) {
994 case 0: /* name */
995 hr = IShellFolder2_GetDisplayNameOf (iface, pidl,
996 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
997 break;
998 case 1: /* size */
999 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
1000 break;
1001 case 2: /* type */
1002 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
1003 break;
1004 case 3: /* date */
1005 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
1006 break;
1007 case 4: /* attributes */
1008 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
1009 break;
1013 return hr;
1016 static HRESULT WINAPI
1017 IShellFolder_fnMapColumnToSCID (IShellFolder2 * iface, UINT column,
1018 SHCOLUMNID * pscid)
1020 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
1021 FIXME ("(%p)\n", This);
1022 return E_NOTIMPL;
1025 static const IShellFolder2Vtbl sfvt =
1027 IShellFolder_fnQueryInterface,
1028 IShellFolder_fnAddRef,
1029 IShellFolder_fnRelease,
1030 IShellFolder_fnParseDisplayName,
1031 IShellFolder_fnEnumObjects,
1032 IShellFolder_fnBindToObject,
1033 IShellFolder_fnBindToStorage,
1034 IShellFolder_fnCompareIDs,
1035 IShellFolder_fnCreateViewObject,
1036 IShellFolder_fnGetAttributesOf,
1037 IShellFolder_fnGetUIObjectOf,
1038 IShellFolder_fnGetDisplayNameOf,
1039 IShellFolder_fnSetNameOf,
1040 /* ShellFolder2 */
1041 IShellFolder_fnGetDefaultSearchGUID,
1042 IShellFolder_fnEnumSearches,
1043 IShellFolder_fnGetDefaultColumn,
1044 IShellFolder_fnGetDefaultColumnState,
1045 IShellFolder_fnGetDetailsEx,
1046 IShellFolder_fnGetDetailsOf,
1047 IShellFolder_fnMapColumnToSCID
1050 /****************************************************************************
1051 * ISFHelper for IShellFolder implementation
1054 static HRESULT WINAPI ISFHelper_fnQueryInterface(ISFHelper *iface, REFIID riid, void **ppvObj)
1056 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1058 return IUnknown_QueryInterface(This->outer_unk, riid, ppvObj);
1061 static ULONG WINAPI ISFHelper_fnAddRef(ISFHelper *iface)
1063 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1065 return IUnknown_AddRef(This->outer_unk);
1068 static ULONG WINAPI ISFHelper_fnRelease(ISFHelper *iface)
1070 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1072 return IUnknown_Release(This->outer_unk);
1075 /****************************************************************************
1076 * ISFHelper_fnGetUniqueName
1078 * creates a unique folder name
1081 static HRESULT WINAPI
1082 ISFHelper_fnGetUniqueName (ISFHelper * iface, LPWSTR pwszName, UINT uLen)
1084 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1085 IEnumIDList *penum;
1086 HRESULT hr;
1087 WCHAR wszText[MAX_PATH];
1088 WCHAR wszNewFolder[25];
1089 const WCHAR wszFormat[] = {'%','s',' ','%','d',0 };
1091 TRACE ("(%p)(%p %u)\n", This, pwszName, uLen);
1093 LoadStringW(shell32_hInstance, IDS_NEWFOLDER, wszNewFolder, sizeof(wszNewFolder)/sizeof(WCHAR));
1094 if (uLen < sizeof(wszNewFolder)/sizeof(WCHAR) + 3)
1095 return E_POINTER;
1097 lstrcpynW (pwszName, wszNewFolder, uLen);
1099 hr = IShellFolder2_EnumObjects(&This->IShellFolder2_iface, 0,
1100 SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &penum);
1101 if (penum) {
1102 LPITEMIDLIST pidl;
1103 DWORD dwFetched;
1104 int i = 1;
1106 next:
1107 IEnumIDList_Reset (penum);
1108 while (S_OK == IEnumIDList_Next (penum, 1, &pidl, &dwFetched) &&
1109 dwFetched) {
1110 _ILSimpleGetTextW (pidl, wszText, MAX_PATH);
1111 if (0 == lstrcmpiW (wszText, pwszName)) {
1112 snprintfW (pwszName, uLen, wszFormat, wszNewFolder, i++);
1113 if (i > 99) {
1114 hr = E_FAIL;
1115 break;
1117 goto next;
1121 IEnumIDList_Release (penum);
1123 return hr;
1126 /****************************************************************************
1127 * ISFHelper_fnAddFolder
1129 * adds a new folder.
1132 static HRESULT WINAPI
1133 ISFHelper_fnAddFolder (ISFHelper * iface, HWND hwnd, LPCWSTR pwszName,
1134 LPITEMIDLIST * ppidlOut)
1136 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1137 WCHAR wszNewDir[MAX_PATH];
1138 BOOL bRes;
1139 HRESULT hres = E_FAIL;
1141 TRACE ("(%p)(%s %p)\n", This, debugstr_w(pwszName), ppidlOut);
1143 wszNewDir[0] = 0;
1144 if (This->sPathTarget)
1145 lstrcpynW(wszNewDir, This->sPathTarget, MAX_PATH);
1146 PathAppendW(wszNewDir, pwszName);
1148 bRes = CreateDirectoryW (wszNewDir, NULL);
1149 if (bRes) {
1150 LPITEMIDLIST relPidl;
1152 lstrcpyW(wszNewDir, pwszName);
1154 hres = IShellFolder2_ParseDisplayName(&This->IShellFolder2_iface, hwnd, NULL, wszNewDir,
1155 NULL, &relPidl, NULL);
1157 if (SUCCEEDED(hres)) {
1158 LPITEMIDLIST fullPidl;
1160 fullPidl = ILCombine(This->pidlRoot, relPidl);
1162 if (fullPidl) {
1163 SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST, fullPidl, NULL);
1164 ILFree(fullPidl);
1166 if (ppidlOut)
1167 *ppidlOut = relPidl;
1168 else
1169 ILFree(relPidl);
1170 } else {
1171 WARN("failed to combine %s into a full PIDL\n", wine_dbgstr_w(pwszName));
1172 ILFree(relPidl);
1175 } else
1176 WARN("failed to parse %s into a PIDL\n", wine_dbgstr_w(pwszName));
1178 } else {
1179 WCHAR wszText[128 + MAX_PATH];
1180 WCHAR wszTempText[128];
1181 WCHAR wszCaption[256];
1183 /* Cannot Create folder because of permissions */
1184 LoadStringW (shell32_hInstance, IDS_CREATEFOLDER_DENIED, wszTempText,
1185 sizeof (wszTempText)/sizeof (wszTempText[0]));
1186 LoadStringW (shell32_hInstance, IDS_CREATEFOLDER_CAPTION, wszCaption,
1187 sizeof (wszCaption)/sizeof (wszCaption[0]));
1188 sprintfW (wszText, wszTempText, wszNewDir);
1189 MessageBoxW (hwnd, wszText, wszCaption, MB_OK | MB_ICONEXCLAMATION);
1192 return hres;
1195 /****************************************************************************
1196 * build_paths_list
1198 * Builds a list of paths like the one used in SHFileOperation from a table of
1199 * PIDLs relative to the given base folder
1201 static WCHAR *build_paths_list(LPCWSTR wszBasePath, int cidl, const LPCITEMIDLIST *pidls)
1203 WCHAR *wszPathsList;
1204 WCHAR *wszListPos;
1205 int iPathLen;
1206 int i;
1208 iPathLen = lstrlenW(wszBasePath);
1209 wszPathsList = HeapAlloc(GetProcessHeap(), 0, MAX_PATH*sizeof(WCHAR)*cidl+1);
1210 wszListPos = wszPathsList;
1212 for (i = 0; i < cidl; i++) {
1213 if (!_ILIsFolder(pidls[i]) && !_ILIsValue(pidls[i]))
1214 continue;
1216 lstrcpynW(wszListPos, wszBasePath, MAX_PATH);
1217 /* FIXME: abort if path too long */
1218 _ILSimpleGetTextW(pidls[i], wszListPos+iPathLen, MAX_PATH-iPathLen);
1219 wszListPos += lstrlenW(wszListPos)+1;
1221 *wszListPos=0;
1222 return wszPathsList;
1225 /****************************************************************************
1226 * ISFHelper_fnDeleteItems
1228 * deletes items in folder
1230 static HRESULT WINAPI
1231 ISFHelper_fnDeleteItems (ISFHelper * iface, UINT cidl, LPCITEMIDLIST * apidl)
1233 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1234 UINT i;
1235 SHFILEOPSTRUCTW op;
1236 WCHAR wszPath[MAX_PATH];
1237 WCHAR *wszPathsList;
1238 HRESULT ret;
1239 WCHAR *wszCurrentPath;
1241 TRACE ("(%p)(%u %p)\n", This, cidl, apidl);
1242 if (cidl==0) return S_OK;
1244 if (This->sPathTarget)
1245 lstrcpynW(wszPath, This->sPathTarget, MAX_PATH);
1246 else
1247 wszPath[0] = '\0';
1248 PathAddBackslashW(wszPath);
1249 wszPathsList = build_paths_list(wszPath, cidl, apidl);
1251 ZeroMemory(&op, sizeof(op));
1252 op.hwnd = GetActiveWindow();
1253 op.wFunc = FO_DELETE;
1254 op.pFrom = wszPathsList;
1255 op.fFlags = FOF_ALLOWUNDO;
1256 if (SHFileOperationW(&op))
1258 WARN("SHFileOperation failed\n");
1259 ret = E_FAIL;
1261 else
1262 ret = S_OK;
1264 /* we currently need to manually send the notifies */
1265 wszCurrentPath = wszPathsList;
1266 for (i = 0; i < cidl; i++)
1268 LONG wEventId;
1270 if (_ILIsFolder(apidl[i]))
1271 wEventId = SHCNE_RMDIR;
1272 else if (_ILIsValue(apidl[i]))
1273 wEventId = SHCNE_DELETE;
1274 else
1275 continue;
1277 /* check if file exists */
1278 if (GetFileAttributesW(wszCurrentPath) == INVALID_FILE_ATTRIBUTES)
1280 LPITEMIDLIST pidl = ILCombine(This->pidlRoot, apidl[i]);
1281 SHChangeNotify(wEventId, SHCNF_IDLIST, pidl, NULL);
1282 SHFree(pidl);
1285 wszCurrentPath += lstrlenW(wszCurrentPath)+1;
1287 HeapFree(GetProcessHeap(), 0, wszPathsList);
1288 return ret;
1291 /****************************************************************************
1292 * ISFHelper_fnCopyItems
1294 * copies items to this folder
1296 static HRESULT WINAPI
1297 ISFHelper_fnCopyItems (ISFHelper * iface, IShellFolder * pSFFrom, UINT cidl,
1298 LPCITEMIDLIST * apidl)
1300 HRESULT ret=E_FAIL;
1301 IPersistFolder2 *ppf2 = NULL;
1302 WCHAR wszSrcPathRoot[MAX_PATH],
1303 wszDstPath[MAX_PATH+1];
1304 WCHAR *wszSrcPathsList;
1305 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1307 SHFILEOPSTRUCTW fop;
1309 TRACE ("(%p)->(%p,%u,%p)\n", This, pSFFrom, cidl, apidl);
1311 IShellFolder_QueryInterface (pSFFrom, &IID_IPersistFolder2,
1312 (LPVOID *) & ppf2);
1313 if (ppf2) {
1314 LPITEMIDLIST pidl;
1316 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2, &pidl))) {
1317 SHGetPathFromIDListW (pidl, wszSrcPathRoot);
1318 ZeroMemory(wszDstPath, MAX_PATH+1);
1319 if (This->sPathTarget)
1320 lstrcpynW(wszDstPath, This->sPathTarget, MAX_PATH);
1321 PathAddBackslashW(wszSrcPathRoot);
1322 PathAddBackslashW(wszDstPath);
1323 wszSrcPathsList = build_paths_list(wszSrcPathRoot, cidl, apidl);
1324 ZeroMemory(&fop, sizeof(fop));
1325 fop.hwnd = GetActiveWindow();
1326 fop.wFunc = FO_COPY;
1327 fop.pFrom = wszSrcPathsList;
1328 fop.pTo = wszDstPath;
1329 fop.fFlags = FOF_ALLOWUNDO;
1330 ret = S_OK;
1331 if(SHFileOperationW(&fop))
1333 WARN("Copy failed\n");
1334 ret = E_FAIL;
1336 HeapFree(GetProcessHeap(), 0, wszSrcPathsList);
1339 SHFree(pidl);
1340 IPersistFolder2_Release(ppf2);
1342 return ret;
1345 static const ISFHelperVtbl shvt =
1347 ISFHelper_fnQueryInterface,
1348 ISFHelper_fnAddRef,
1349 ISFHelper_fnRelease,
1350 ISFHelper_fnGetUniqueName,
1351 ISFHelper_fnAddFolder,
1352 ISFHelper_fnDeleteItems,
1353 ISFHelper_fnCopyItems
1356 /************************************************************************
1357 * IFSFldr_PersistFolder3_QueryInterface
1360 static HRESULT WINAPI IFSFldr_PersistFolder3_QueryInterface(IPersistFolder3 *iface, REFIID iid,
1361 void **ppv)
1363 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1365 return IUnknown_QueryInterface(This->outer_unk, iid, ppv);
1368 /************************************************************************
1369 * IFSFldr_PersistFolder3_AddRef
1372 static ULONG WINAPI IFSFldr_PersistFolder3_AddRef(IPersistFolder3 *iface)
1374 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1376 return IUnknown_AddRef(This->outer_unk);
1379 /************************************************************************
1380 * IFSFldr_PersistFolder3_Release
1383 static ULONG WINAPI IFSFldr_PersistFolder3_Release(IPersistFolder3 *iface)
1385 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1387 return IUnknown_Release(This->outer_unk);
1390 /************************************************************************
1391 * IFSFldr_PersistFolder3_GetClassID
1393 static HRESULT WINAPI
1394 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3 * iface, CLSID * lpClassId)
1396 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1398 TRACE ("(%p)\n", This);
1400 if (!lpClassId)
1401 return E_POINTER;
1402 *lpClassId = *This->pclsid;
1404 return S_OK;
1407 /************************************************************************
1408 * IFSFldr_PersistFolder3_Initialize
1410 * NOTES
1411 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1413 static HRESULT WINAPI
1414 IFSFldr_PersistFolder3_Initialize (IPersistFolder3 * iface, LPCITEMIDLIST pidl)
1416 WCHAR wszTemp[MAX_PATH];
1418 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1420 TRACE ("(%p)->(%p)\n", This, pidl);
1422 SHFree (This->pidlRoot); /* free the old pidl */
1423 This->pidlRoot = ILClone (pidl); /* set my pidl */
1425 SHFree (This->sPathTarget);
1426 This->sPathTarget = NULL;
1428 /* set my path */
1429 if (SHGetPathFromIDListW (pidl, wszTemp)) {
1430 int len = strlenW(wszTemp);
1431 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1432 if (!This->sPathTarget)
1433 return E_OUTOFMEMORY;
1434 memcpy(This->sPathTarget, wszTemp, (len + 1) * sizeof(WCHAR));
1437 TRACE ("--(%p)->(%s)\n", This, debugstr_w(This->sPathTarget));
1438 return S_OK;
1441 /**************************************************************************
1442 * IFSFldr_PersistFolder3_GetCurFolder
1444 static HRESULT WINAPI
1445 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3 * iface,
1446 LPITEMIDLIST * pidl)
1448 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1450 TRACE ("(%p)->(%p)\n", This, pidl);
1452 if (!pidl) return E_POINTER;
1453 *pidl = ILClone (This->pidlRoot);
1454 return S_OK;
1457 /**************************************************************************
1458 * IFSFldr_PersistFolder3_InitializeEx
1460 * FIXME: error handling
1462 static HRESULT WINAPI
1463 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3 * iface,
1464 IBindCtx * pbc, LPCITEMIDLIST pidlRoot,
1465 const PERSIST_FOLDER_TARGET_INFO * ppfti)
1467 WCHAR wszTemp[MAX_PATH];
1469 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1471 TRACE ("(%p)->(%p,%p,%p)\n", This, pbc, pidlRoot, ppfti);
1472 if (ppfti)
1473 TRACE ("--%p %s %s 0x%08x 0x%08x\n",
1474 ppfti->pidlTargetFolder, debugstr_w (ppfti->szTargetParsingName),
1475 debugstr_w (ppfti->szNetworkProvider), ppfti->dwAttributes,
1476 ppfti->csidl);
1478 pdump (pidlRoot);
1479 if (ppfti && ppfti->pidlTargetFolder)
1480 pdump (ppfti->pidlTargetFolder);
1482 if (This->pidlRoot)
1484 SHFree(This->pidlRoot);
1485 This->pidlRoot = NULL;
1487 if (This->sPathTarget)
1489 SHFree(This->sPathTarget);
1490 This->sPathTarget = NULL;
1494 * Root path and pidl
1496 This->pidlRoot = ILClone (pidlRoot);
1499 * the target folder is specified in csidl OR pidlTargetFolder OR
1500 * szTargetParsingName
1502 if (ppfti) {
1503 if (ppfti->csidl != -1) {
1504 if (SHGetSpecialFolderPathW (0, wszTemp, ppfti->csidl,
1505 ppfti->csidl & CSIDL_FLAG_CREATE)) {
1506 int len = strlenW(wszTemp);
1507 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1508 if (!This->sPathTarget)
1509 return E_OUTOFMEMORY;
1510 memcpy(This->sPathTarget, wszTemp, (len + 1) * sizeof(WCHAR));
1512 } else if (ppfti->szTargetParsingName[0]) {
1513 int len = strlenW(ppfti->szTargetParsingName);
1514 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1515 if (!This->sPathTarget)
1516 return E_OUTOFMEMORY;
1517 memcpy(This->sPathTarget, ppfti->szTargetParsingName,
1518 (len + 1) * sizeof(WCHAR));
1519 } else if (ppfti->pidlTargetFolder) {
1520 if (SHGetPathFromIDListW(ppfti->pidlTargetFolder, wszTemp)) {
1521 int len = strlenW(wszTemp);
1522 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1523 if (!This->sPathTarget)
1524 return E_OUTOFMEMORY;
1525 memcpy(This->sPathTarget, wszTemp, (len + 1) * sizeof(WCHAR));
1530 TRACE ("--(%p)->(target=%s)\n", This, debugstr_w(This->sPathTarget));
1531 pdump (This->pidlRoot);
1532 return (This->sPathTarget) ? S_OK : E_FAIL;
1535 static HRESULT WINAPI
1536 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3 * iface,
1537 PERSIST_FOLDER_TARGET_INFO * ppfti)
1539 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1540 FIXME ("(%p)->(%p)\n", This, ppfti);
1541 ZeroMemory (ppfti, sizeof (*ppfti));
1542 return E_NOTIMPL;
1545 static const IPersistFolder3Vtbl pfvt =
1547 IFSFldr_PersistFolder3_QueryInterface,
1548 IFSFldr_PersistFolder3_AddRef,
1549 IFSFldr_PersistFolder3_Release,
1550 IFSFldr_PersistFolder3_GetClassID,
1551 IFSFldr_PersistFolder3_Initialize,
1552 IFSFldr_PersistFolder3_fnGetCurFolder,
1553 IFSFldr_PersistFolder3_InitializeEx,
1554 IFSFldr_PersistFolder3_GetFolderTargetInfo
1557 /****************************************************************************
1558 * ISFDropTarget implementation
1560 static HRESULT WINAPI ISFDropTarget_QueryInterface(IDropTarget *iface, REFIID riid, void **ppv)
1562 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1564 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
1567 static ULONG WINAPI ISFDropTarget_AddRef(IDropTarget *iface)
1569 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1571 return IUnknown_AddRef(This->outer_unk);
1574 static ULONG WINAPI ISFDropTarget_Release(IDropTarget *iface)
1576 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1578 return IUnknown_Release(This->outer_unk);
1581 static HRESULT WINAPI
1582 ISFDropTarget_DragEnter (IDropTarget * iface, IDataObject * pDataObject,
1583 DWORD dwKeyState, POINTL pt, DWORD * pdwEffect)
1585 FORMATETC fmt;
1587 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1589 TRACE ("(%p)->(DataObject=%p)\n", This, pDataObject);
1591 InitFormatEtc (fmt, This->cfShellIDList, TYMED_HGLOBAL);
1592 This->fAcceptFmt = IDataObject_QueryGetData (pDataObject, &fmt) == S_OK;
1593 if (This->fAcceptFmt)
1594 *pdwEffect = KeyStateToDropEffect(dwKeyState);
1595 else
1596 *pdwEffect = DROPEFFECT_NONE;
1598 return S_OK;
1601 static HRESULT WINAPI
1602 ISFDropTarget_DragOver (IDropTarget * iface, DWORD dwKeyState, POINTL pt,
1603 DWORD * pdwEffect)
1605 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1607 TRACE ("(%p)\n", This);
1609 if (!pdwEffect)
1610 return E_INVALIDARG;
1612 if (This->fAcceptFmt)
1613 *pdwEffect = KeyStateToDropEffect(dwKeyState);
1614 else
1615 *pdwEffect = DROPEFFECT_NONE;
1617 return S_OK;
1620 static HRESULT WINAPI ISFDropTarget_DragLeave (IDropTarget * iface)
1622 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1624 TRACE ("(%p)\n", This);
1626 This->fAcceptFmt = FALSE;
1628 return S_OK;
1631 static HRESULT WINAPI
1632 ISFDropTarget_Drop (IDropTarget * iface, IDataObject * pDataObject,
1633 DWORD dwKeyState, POINTL pt, DWORD * pdwEffect)
1635 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1637 FIXME ("(%p) object dropped\n", This);
1639 return E_NOTIMPL;
1642 static const IDropTargetVtbl dtvt = {
1643 ISFDropTarget_QueryInterface,
1644 ISFDropTarget_AddRef,
1645 ISFDropTarget_Release,
1646 ISFDropTarget_DragEnter,
1647 ISFDropTarget_DragOver,
1648 ISFDropTarget_DragLeave,
1649 ISFDropTarget_Drop
1652 HRESULT WINAPI IFSFolder_Constructor(IUnknown *outer_unk, REFIID riid, void **ppv)
1654 IGenericSFImpl *sf;
1655 HRESULT hr;
1657 TRACE("outer_unk=%p %s\n", outer_unk, shdebugstr_guid(riid));
1659 if (outer_unk && !IsEqualIID(riid, &IID_IUnknown))
1660 return CLASS_E_NOAGGREGATION;
1662 sf = LocalAlloc(LMEM_ZEROINIT, sizeof(*sf));
1663 if (!sf)
1664 return E_OUTOFMEMORY;
1666 sf->ref = 1;
1667 sf->IUnknown_inner.lpVtbl = &unkvt;
1668 sf->IShellFolder2_iface.lpVtbl = &sfvt;
1669 sf->IPersistFolder3_iface.lpVtbl = &pfvt;
1670 sf->IDropTarget_iface.lpVtbl = &dtvt;
1671 sf->ISFHelper_iface.lpVtbl = &shvt;
1672 sf->pclsid = (CLSID *) & CLSID_ShellFSFolder;
1673 sf->outer_unk = outer_unk ? outer_unk : &sf->IUnknown_inner;
1675 hr = IUnknown_QueryInterface(&sf->IUnknown_inner, riid, ppv);
1676 IUnknown_Release(&sf->IUnknown_inner);
1678 TRACE ("--%p\n", *ppv);
1679 return hr;