mshtml: Share nsscript reference with nsnode.
[wine/multimedia.git] / dlls / shell32 / shfldr_fs.c
blob3bbe26eaccd4860d1ac793ee5f7be12c31966849
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
33 #define NONAMELESSSTRUCT
35 #include "winerror.h"
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winreg.h"
39 #include "wingdi.h"
40 #include "winuser.h"
42 #include "ole2.h"
43 #include "shlguid.h"
45 #include "pidl.h"
46 #include "undocshell.h"
47 #include "shell32_main.h"
48 #include "shresdef.h"
49 #include "shlwapi.h"
50 #include "shellfolder.h"
51 #include "wine/debug.h"
52 #include "debughlp.h"
53 #include "shfldr.h"
55 WINE_DEFAULT_DEBUG_CHANNEL (shell);
57 /***********************************************************************
58 * IShellFolder implementation
61 typedef struct {
62 const IUnknownVtbl *lpVtbl;
63 LONG ref;
64 const IShellFolder2Vtbl *lpvtblShellFolder;
65 const IPersistFolder3Vtbl *lpvtblPersistFolder3;
66 const IDropTargetVtbl *lpvtblDropTarget;
67 const ISFHelperVtbl *lpvtblSFHelper;
69 IUnknown *pUnkOuter; /* used for aggregation */
71 CLSID *pclsid;
73 /* both paths are parsible from the desktop */
74 LPWSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
76 LPITEMIDLIST pidlRoot; /* absolute pidl */
78 UINT cfShellIDList; /* clipboardformat for IDropTarget */
79 BOOL fAcceptFmt; /* flag for pending Drop */
80 } IGenericSFImpl;
82 static const IUnknownVtbl unkvt;
83 static const IShellFolder2Vtbl sfvt;
84 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3; /* IPersistFolder3 for a FS_Folder */
85 static const IDropTargetVtbl dtvt;
86 static const ISFHelperVtbl shvt;
88 static inline IGenericSFImpl *impl_from_IShellFolder2( IShellFolder2 *iface )
90 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblShellFolder));
93 static inline IGenericSFImpl *impl_from_IPersistFolder3( IPersistFolder3 *iface )
95 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblPersistFolder3));
98 static inline IGenericSFImpl *impl_from_IDropTarget( IDropTarget *iface )
100 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblDropTarget));
103 static inline IGenericSFImpl *impl_from_ISFHelper( ISFHelper *iface )
105 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblSFHelper));
110 converts This to an interface pointer
112 #define _IUnknown_(This) ((IUnknown*)&(This)->lpVtbl)
113 #define _IShellFolder_(This) ((IShellFolder*)&(This)->lpvtblShellFolder)
114 #define _IShellFolder2_(This) ((IShellFolder2*)&(This)->lpvtblShellFolder)
115 #define _IPersist_(This) (&(This)->lpvtblPersistFolder3)
116 #define _IPersistFolder_(This) (&(This)->lpvtblPersistFolder3)
117 #define _IPersistFolder2_(This) (&(This)->lpvtblPersistFolder3)
118 #define _IPersistFolder3_(This) (&(This)->lpvtblPersistFolder3)
119 #define _IDropTarget_(This) (&(This)->lpvtblDropTarget)
120 #define _ISFHelper_(This) (&(This)->lpvtblSFHelper)
122 /**************************************************************************
123 * registers clipboardformat once
125 static void SF_RegisterClipFmt (IGenericSFImpl * This)
127 TRACE ("(%p)\n", This);
129 if (!This->cfShellIDList) {
130 This->cfShellIDList = RegisterClipboardFormatW (CFSTR_SHELLIDLISTW);
134 /**************************************************************************
135 * we need a separate IUnknown to handle aggregation
136 * (inner IUnknown)
138 static HRESULT WINAPI IUnknown_fnQueryInterface (IUnknown * iface, REFIID riid, LPVOID * ppvObj)
140 IGenericSFImpl *This = (IGenericSFImpl *)iface;
142 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
144 *ppvObj = NULL;
146 if (IsEqualIID (riid, &IID_IUnknown))
147 *ppvObj = _IUnknown_ (This);
148 else if (IsEqualIID (riid, &IID_IShellFolder))
149 *ppvObj = _IShellFolder_ (This);
150 else if (IsEqualIID (riid, &IID_IShellFolder2))
151 *ppvObj = _IShellFolder_ (This);
152 else if (IsEqualIID (riid, &IID_IPersist))
153 *ppvObj = _IPersist_ (This);
154 else if (IsEqualIID (riid, &IID_IPersistFolder))
155 *ppvObj = _IPersistFolder_ (This);
156 else if (IsEqualIID (riid, &IID_IPersistFolder2))
157 *ppvObj = _IPersistFolder2_ (This);
158 else if (IsEqualIID (riid, &IID_IPersistFolder3))
159 *ppvObj = _IPersistFolder3_ (This);
160 else if (IsEqualIID (riid, &IID_ISFHelper))
161 *ppvObj = _ISFHelper_ (This);
162 else if (IsEqualIID (riid, &IID_IDropTarget)) {
163 *ppvObj = _IDropTarget_ (This);
164 SF_RegisterClipFmt (This);
167 if (*ppvObj) {
168 IUnknown_AddRef ((IUnknown *) (*ppvObj));
169 TRACE ("-- Interface = %p\n", *ppvObj);
170 return S_OK;
172 TRACE ("-- Interface: E_NOINTERFACE\n");
173 return E_NOINTERFACE;
176 static ULONG WINAPI IUnknown_fnAddRef (IUnknown * iface)
178 IGenericSFImpl *This = (IGenericSFImpl *)iface;
179 ULONG refCount = InterlockedIncrement(&This->ref);
181 TRACE ("(%p)->(count=%u)\n", This, refCount - 1);
183 return refCount;
186 static ULONG WINAPI IUnknown_fnRelease (IUnknown * iface)
188 IGenericSFImpl *This = (IGenericSFImpl *)iface;
189 ULONG refCount = InterlockedDecrement(&This->ref);
191 TRACE ("(%p)->(count=%u)\n", This, refCount + 1);
193 if (!refCount) {
194 TRACE ("-- destroying IShellFolder(%p)\n", This);
196 SHFree (This->pidlRoot);
197 SHFree (This->sPathTarget);
198 LocalFree (This);
200 return refCount;
203 static const IUnknownVtbl unkvt =
205 IUnknown_fnQueryInterface,
206 IUnknown_fnAddRef,
207 IUnknown_fnRelease,
210 static const shvheader GenericSFHeader[] = {
211 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
212 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
213 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
214 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
215 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
218 #define GENERICSHELLVIEWCOLUMNS 5
220 /**************************************************************************
221 * IFSFolder_Constructor
223 * NOTES
224 * creating undocumented ShellFS_Folder as part of an aggregation
225 * {F3364BA0-65B9-11CE-A9BA-00AA004AE837}
228 HRESULT WINAPI
229 IFSFolder_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
231 IGenericSFImpl *sf;
233 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
235 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
236 return CLASS_E_NOAGGREGATION;
237 sf = LocalAlloc (LMEM_ZEROINIT, sizeof (IGenericSFImpl));
238 if (!sf)
239 return E_OUTOFMEMORY;
241 sf->ref = 0;
242 sf->lpVtbl = &unkvt;
243 sf->lpvtblShellFolder = &sfvt;
244 sf->lpvtblPersistFolder3 = &vt_FSFldr_PersistFolder3;
245 sf->lpvtblDropTarget = &dtvt;
246 sf->lpvtblSFHelper = &shvt;
247 sf->pclsid = (CLSID *) & CLSID_ShellFSFolder;
248 sf->pUnkOuter = pUnkOuter ? pUnkOuter : _IUnknown_ (sf);
250 if (FAILED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv))) {
251 IUnknown_Release (_IUnknown_ (sf));
252 return E_NOINTERFACE;
255 TRACE ("--%p\n", *ppv);
256 return S_OK;
259 /**************************************************************************
260 * IShellFolder_fnQueryInterface
262 * PARAMETERS
263 * REFIID riid [in ] Requested InterfaceID
264 * LPVOID* ppvObject [out] Interface* to hold the result
266 static HRESULT WINAPI
267 IShellFolder_fnQueryInterface (IShellFolder2 * iface, REFIID riid,
268 LPVOID * ppvObj)
270 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
272 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
274 return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
277 /**************************************************************************
278 * IShellFolder_AddRef
281 static ULONG WINAPI IShellFolder_fnAddRef (IShellFolder2 * iface)
283 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
285 TRACE ("(%p)->(count=%u)\n", This, This->ref);
287 return IUnknown_AddRef (This->pUnkOuter);
290 /**************************************************************************
291 * IShellFolder_fnRelease
293 static ULONG WINAPI IShellFolder_fnRelease (IShellFolder2 * iface)
295 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
297 TRACE ("(%p)->(count=%u)\n", This, This->ref);
299 return IUnknown_Release (This->pUnkOuter);
302 /**************************************************************************
303 * SHELL32_CreatePidlFromBindCtx [internal]
305 * If the caller bound File System Bind Data, assume it is the
306 * find data for the path.
307 * This allows binding of paths that don't exist.
309 LPITEMIDLIST SHELL32_CreatePidlFromBindCtx(IBindCtx *pbc, LPCWSTR path)
311 static WCHAR szfsbc[] = {
312 'F','i','l','e',' ','S','y','s','t','e','m',' ',
313 'B','i','n','d',' ','D','a','t','a',0 };
314 IFileSystemBindData *fsbd = NULL;
315 LPITEMIDLIST pidl = NULL;
316 IUnknown *unk = NULL;
317 HRESULT r;
319 TRACE("%p %s\n", pbc, debugstr_w(path));
321 if (!pbc)
322 return NULL;
324 /* see if the caller bound File System Bind Data */
325 r = IBindCtx_GetObjectParam( pbc, szfsbc, &unk );
326 if (FAILED(r))
327 return NULL;
329 r = IUnknown_QueryInterface( unk, &IID_IFileSystemBindData, (void**)&fsbd );
330 if (SUCCEEDED(r))
332 WIN32_FIND_DATAW wfd;
334 r = IFileSystemBindData_GetFindData( fsbd, &wfd );
335 if (SUCCEEDED(r))
337 lstrcpynW( &wfd.cFileName[0], path, MAX_PATH );
338 pidl = _ILCreateFromFindDataW( &wfd );
340 IFileSystemBindData_Release( fsbd );
342 IUnknown_Release( unk );
344 return pidl;
347 /**************************************************************************
348 * IShellFolder_ParseDisplayName {SHELL32}
350 * Parse a display name.
352 * PARAMS
353 * hwndOwner [in] Parent window for any message's
354 * pbc [in] optional FileSystemBindData context
355 * lpszDisplayName [in] Unicode displayname.
356 * pchEaten [out] (unicode) characters processed
357 * ppidl [out] complex pidl to item
358 * pdwAttributes [out] items attributes
360 * NOTES
361 * Every folder tries to parse only its own (the leftmost) pidl and creates a
362 * subfolder to evaluate the remaining parts.
363 * Now we can parse into namespaces implemented by shell extensions
365 * Behaviour on win98: lpszDisplayName=NULL -> crash
366 * lpszDisplayName="" -> returns mycoputer-pidl
368 * FIXME
369 * pdwAttributes is not set
370 * pchEaten is not set like in windows
372 static HRESULT WINAPI
373 IShellFolder_fnParseDisplayName (IShellFolder2 * iface,
374 HWND hwndOwner,
375 LPBC pbc,
376 LPOLESTR lpszDisplayName,
377 DWORD * pchEaten, LPITEMIDLIST * ppidl,
378 DWORD * pdwAttributes)
380 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
382 HRESULT hr = E_INVALIDARG;
383 LPCWSTR szNext = NULL;
384 WCHAR szElement[MAX_PATH];
385 WCHAR szPath[MAX_PATH];
386 LPITEMIDLIST pidlTemp = NULL;
387 DWORD len;
389 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
390 This, hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
391 pchEaten, ppidl, pdwAttributes);
393 if (!lpszDisplayName || !ppidl)
394 return E_INVALIDARG;
396 if (pchEaten)
397 *pchEaten = 0; /* strange but like the original */
399 pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName);
400 if (!pidlTemp && *lpszDisplayName)
402 /* get the next element */
403 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
405 /* build the full pathname to the element */
406 lstrcpynW(szPath, This->sPathTarget, MAX_PATH - 1);
407 PathAddBackslashW(szPath);
408 len = lstrlenW(szPath);
409 lstrcpynW(szPath + len, szElement, MAX_PATH - len);
411 /* get the pidl */
412 hr = _ILCreateFromPathW(szPath, &pidlTemp);
414 if (SUCCEEDED(hr)) {
415 if (szNext && *szNext) {
416 /* try to analyse the next element */
417 hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc,
418 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
419 } else {
420 /* it's the last element */
421 if (pdwAttributes && *pdwAttributes) {
422 hr = SHELL32_GetItemAttributes (_IShellFolder_ (This),
423 pidlTemp, pdwAttributes);
429 if (SUCCEEDED(hr))
430 *ppidl = pidlTemp;
431 else
432 *ppidl = NULL;
434 TRACE ("(%p)->(-- pidl=%p ret=0x%08x)\n", This, *ppidl, hr);
436 return hr;
439 /**************************************************************************
440 * IShellFolder_fnEnumObjects
441 * PARAMETERS
442 * HWND hwndOwner, //[in ] Parent Window
443 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
444 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
446 static HRESULT WINAPI
447 IShellFolder_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner,
448 DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
450 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
451 IEnumIDListImpl *list;
453 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This, hwndOwner,
454 dwFlags, ppEnumIDList);
456 if (!(list = IEnumIDList_Constructor()))
457 return E_OUTOFMEMORY;
458 CreateFolderEnumList(list, This->sPathTarget, dwFlags);
459 *ppEnumIDList = &list->IEnumIDList_iface;
461 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
463 return S_OK;
466 /**************************************************************************
467 * IShellFolder_fnBindToObject
468 * PARAMETERS
469 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
470 * LPBC pbc, //[in ] optional FileSystemBindData context
471 * REFIID riid, //[in ] Initial Interface
472 * LPVOID* ppvObject //[out] Interface*
474 static HRESULT WINAPI
475 IShellFolder_fnBindToObject (IShellFolder2 * iface, LPCITEMIDLIST pidl,
476 LPBC pbc, REFIID riid, LPVOID * ppvOut)
478 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
480 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbc,
481 shdebugstr_guid (riid), ppvOut);
483 return SHELL32_BindToChild (This->pidlRoot, This->sPathTarget, pidl, riid,
484 ppvOut);
487 /**************************************************************************
488 * IShellFolder_fnBindToStorage
489 * PARAMETERS
490 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
491 * LPBC pbc, //[in ] reserved
492 * REFIID riid, //[in ] Initial storage interface
493 * LPVOID* ppvObject //[out] Interface* returned
495 static HRESULT WINAPI
496 IShellFolder_fnBindToStorage (IShellFolder2 * iface, LPCITEMIDLIST pidl,
497 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
499 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
501 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved,
502 shdebugstr_guid (riid), ppvOut);
504 *ppvOut = NULL;
505 return E_NOTIMPL;
508 /**************************************************************************
509 * IShellFolder_fnCompareIDs
512 static HRESULT WINAPI
513 IShellFolder_fnCompareIDs (IShellFolder2 * iface, LPARAM lParam,
514 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
516 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
518 int nReturn;
520 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
521 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
522 TRACE ("-- %i\n", nReturn);
523 return nReturn;
526 /**************************************************************************
527 * IShellFolder_fnCreateViewObject
529 static HRESULT WINAPI
530 IShellFolder_fnCreateViewObject (IShellFolder2 * iface, HWND hwndOwner,
531 REFIID riid, LPVOID * ppvOut)
533 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
535 LPSHELLVIEW pShellView;
536 HRESULT hr = E_INVALIDARG;
538 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid),
539 ppvOut);
541 if (ppvOut) {
542 *ppvOut = NULL;
544 if (IsEqualIID (riid, &IID_IDropTarget)) {
545 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, ppvOut);
546 } else if (IsEqualIID (riid, &IID_IContextMenu)) {
547 FIXME ("IContextMenu not implemented\n");
548 hr = E_NOTIMPL;
549 } else if (IsEqualIID (riid, &IID_IShellView)) {
550 pShellView = IShellView_Constructor ((IShellFolder *) iface);
551 if (pShellView) {
552 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
553 IShellView_Release (pShellView);
557 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
558 return hr;
561 /**************************************************************************
562 * IShellFolder_fnGetAttributesOf
564 * PARAMETERS
565 * UINT cidl, //[in ] num elements in pidl array
566 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
567 * ULONG* rgfInOut) //[out] result array
570 static HRESULT WINAPI
571 IShellFolder_fnGetAttributesOf (IShellFolder2 * iface, UINT cidl,
572 LPCITEMIDLIST * apidl, DWORD * rgfInOut)
574 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
576 HRESULT hr = S_OK;
578 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", This, cidl, apidl,
579 rgfInOut, rgfInOut ? *rgfInOut : 0);
581 if (!rgfInOut)
582 return E_INVALIDARG;
583 if (cidl && !apidl)
584 return E_INVALIDARG;
586 if (*rgfInOut == 0)
587 *rgfInOut = ~0;
589 if(cidl == 0){
590 IShellFolder *psfParent = NULL;
591 LPCITEMIDLIST rpidl = NULL;
593 hr = SHBindToParent(This->pidlRoot, &IID_IShellFolder, (LPVOID*)&psfParent, &rpidl);
594 if(SUCCEEDED(hr)) {
595 SHELL32_GetItemAttributes (psfParent, rpidl, rgfInOut);
596 IShellFolder_Release(psfParent);
599 else {
600 while (cidl > 0 && *apidl) {
601 pdump (*apidl);
602 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
603 apidl++;
604 cidl--;
607 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
608 *rgfInOut &= ~SFGAO_VALIDATE;
610 TRACE ("-- result=0x%08x\n", *rgfInOut);
612 return hr;
615 /**************************************************************************
616 * SHELL32_CreateExtensionUIObject (internal)
618 HRESULT SHELL32_CreateExtensionUIObject(IShellFolder2 *iface,
619 LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppvOut)
621 static const WCHAR reg_blockedW[] = {'S','o','f','t','w','a','r','e','\\',
622 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
623 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
624 'S','h','e','l','l',' ','E','x','t','e','n','s','i','o','n','s','\\',
625 'B','l','o','c','k','e','d',0};
626 static const WCHAR formatW[] = {'.','%','s','\\','S','h','e','l','l','E','x','\\',
627 '{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
628 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x',
629 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0};
631 IPersistFile *persist_file;
632 char extensionA[20];
633 WCHAR extensionW[20], buf[MAX_PATH];
634 DWORD size = MAX_PATH;
635 STRRET path;
636 WCHAR *file;
637 GUID guid;
638 HKEY key;
639 HRESULT hr;
642 if(!_ILGetExtension(pidl, extensionA, 20))
643 return S_FALSE;
645 MultiByteToWideChar(CP_ACP, 0, extensionA, -1, extensionW, 20);
647 sprintfW(buf, formatW, extensionW, riid->Data1, riid->Data2, riid->Data3,
648 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
649 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]);
651 if(RegGetValueW(HKEY_CLASSES_ROOT, buf, NULL, RRF_RT_REG_SZ,
652 NULL, buf, &size) != ERROR_SUCCESS)
653 return S_FALSE;
655 if(RegCreateKeyExW(HKEY_LOCAL_MACHINE, reg_blockedW, 0, 0, 0,
656 KEY_READ, NULL, &key, NULL) != ERROR_SUCCESS)
657 return E_FAIL;
658 if(RegQueryValueExW(key, buf, 0, NULL, NULL, NULL)
659 != ERROR_FILE_NOT_FOUND)
660 return E_ACCESSDENIED;
661 RegCloseKey(key);
663 if(RegCreateKeyExW(HKEY_CURRENT_USER, reg_blockedW, 0, 0, 0,
664 KEY_READ, NULL, &key, NULL) != ERROR_SUCCESS)
665 return E_FAIL;
666 if(RegQueryValueExW(key, buf, 0, NULL, NULL, NULL)
667 != ERROR_FILE_NOT_FOUND)
668 return E_ACCESSDENIED;
669 RegCloseKey(key);
671 if(!GUIDFromStringW(buf, &guid))
672 return E_FAIL;
674 hr = CoCreateInstance(&guid, NULL, CLSCTX_INPROC_SERVER,
675 &IID_IPersistFile, (void**)&persist_file);
676 if(FAILED(hr))
677 return hr;
679 hr = IShellFolder_GetDisplayNameOf(iface, pidl, SHGDN_FORPARSING, &path);
680 if(SUCCEEDED(hr))
681 hr = StrRetToStrW(&path, NULL, &file);
682 if(FAILED(hr)) {
683 IPersistFile_Release(persist_file);
684 return hr;
687 hr = IPersistFile_Load(persist_file, file, STGM_READ);
688 CoTaskMemFree(file);
689 if(FAILED(hr)) {
690 IPersistFile_Release(persist_file);
691 return hr;
694 hr = IPersistFile_QueryInterface(persist_file, riid, ppvOut);
695 IPersistFile_Release(persist_file);
696 return hr;
699 /**************************************************************************
700 * IShellFolder_fnGetUIObjectOf
702 * PARAMETERS
703 * HWND hwndOwner, //[in ] Parent window for any output
704 * UINT cidl, //[in ] array size
705 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
706 * REFIID riid, //[in ] Requested Interface
707 * UINT* prgfInOut, //[ ] reserved
708 * LPVOID* ppvObject) //[out] Resulting Interface
710 * NOTES
711 * This function gets asked to return "view objects" for one or more (multiple
712 * select) items:
713 * The viewobject typically is an COM object with one of the following
714 * interfaces:
715 * IExtractIcon,IDataObject,IContextMenu
716 * In order to support icon positions in the default Listview your DataObject
717 * must implement the SetData method (in addition to GetData :) - the shell
718 * passes a barely documented "Icon positions" structure to SetData when the
719 * drag starts, and GetData's it if the drop is in another explorer window that
720 * needs the positions.
722 static HRESULT WINAPI
723 IShellFolder_fnGetUIObjectOf (IShellFolder2 * iface,
724 HWND hwndOwner,
725 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
726 UINT * prgfInOut, LPVOID * ppvOut)
728 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
730 LPITEMIDLIST pidl;
731 IUnknown *pObj = NULL;
732 HRESULT hr = E_INVALIDARG;
734 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
735 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
737 if (ppvOut) {
738 *ppvOut = NULL;
740 if(cidl == 1) {
741 hr = SHELL32_CreateExtensionUIObject(iface, *apidl, riid, ppvOut);
742 if(hr != S_FALSE)
743 return hr;
746 if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
747 return ItemMenu_Constructor((IShellFolder*)iface, This->pidlRoot, apidl, cidl, riid, ppvOut);
748 } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
749 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner,
750 This->pidlRoot, apidl, cidl);
751 hr = S_OK;
752 } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
753 pidl = ILCombine (This->pidlRoot, apidl[0]);
754 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
755 SHFree (pidl);
756 hr = S_OK;
757 } else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1)) {
758 pidl = ILCombine (This->pidlRoot, apidl[0]);
759 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
760 SHFree (pidl);
761 hr = S_OK;
762 } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
763 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget,
764 (LPVOID *) & pObj);
765 } else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
766 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1)) {
767 pidl = ILCombine (This->pidlRoot, apidl[0]);
768 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
769 SHFree (pidl);
770 } else {
771 hr = E_NOINTERFACE;
774 if (SUCCEEDED(hr) && !pObj)
775 hr = E_OUTOFMEMORY;
777 *ppvOut = pObj;
779 TRACE ("(%p)->hr=0x%08x\n", This, hr);
780 return hr;
783 static const WCHAR AdvancedW[] = { 'S','O','F','T','W','A','R','E',
784 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
785 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
786 'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
787 static const WCHAR HideFileExtW[] = { 'H','i','d','e','F','i','l','e','E','x',
788 't',0 };
789 static const WCHAR NeverShowExtW[] = { 'N','e','v','e','r','S','h','o','w','E',
790 'x','t',0 };
792 /******************************************************************************
793 * SHELL_FS_HideExtension [Internal]
795 * Query the registry if the filename extension of a given path should be
796 * hidden.
798 * PARAMS
799 * szPath [I] Relative or absolute path of a file
801 * RETURNS
802 * TRUE, if the filename's extension should be hidden
803 * FALSE, otherwise.
805 BOOL SHELL_FS_HideExtension(LPCWSTR szPath)
807 HKEY hKey;
808 DWORD dwData;
809 DWORD dwDataSize = sizeof (DWORD);
810 BOOL doHide = FALSE; /* The default value is FALSE (win98 at least) */
812 if (!RegCreateKeyExW(HKEY_CURRENT_USER, AdvancedW, 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0)) {
813 if (!RegQueryValueExW(hKey, HideFileExtW, 0, 0, (LPBYTE) &dwData, &dwDataSize))
814 doHide = dwData;
815 RegCloseKey (hKey);
818 if (!doHide) {
819 LPWSTR ext = PathFindExtensionW(szPath);
821 if (*ext != '\0') {
822 WCHAR classname[MAX_PATH];
823 LONG classlen = sizeof(classname);
825 if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, classname, &classlen))
826 if (!RegOpenKeyW(HKEY_CLASSES_ROOT, classname, &hKey)) {
827 if (!RegQueryValueExW(hKey, NeverShowExtW, 0, NULL, NULL, NULL))
828 doHide = TRUE;
829 RegCloseKey(hKey);
833 return doHide;
836 void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath, DWORD dwFlags)
838 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
839 if (!(dwFlags & SHGDN_FORPARSING) &&
840 ((dwFlags & SHGDN_INFOLDER) || (dwFlags == SHGDN_NORMAL))) {
841 if (SHELL_FS_HideExtension(szPath) && szPath[0] != '.')
842 PathRemoveExtensionW(szPath);
846 /**************************************************************************
847 * IShellFolder_fnGetDisplayNameOf
848 * Retrieves the display name for the specified file object or subfolder
850 * PARAMETERS
851 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
852 * DWORD dwFlags, //[in ] SHGNO formatting flags
853 * LPSTRRET lpName) //[out] Returned display name
855 * FIXME
856 * if the name is in the pidl the ret value should be a STRRET_OFFSET
859 static HRESULT WINAPI
860 IShellFolder_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
861 DWORD dwFlags, LPSTRRET strRet)
863 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
864 LPWSTR pszPath;
866 HRESULT hr = S_OK;
867 int len = 0;
869 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
870 pdump (pidl);
872 if (!pidl || !strRet)
873 return E_INVALIDARG;
875 pszPath = CoTaskMemAlloc((MAX_PATH +1) * sizeof(WCHAR));
876 if (!pszPath)
877 return E_OUTOFMEMORY;
879 if (_ILIsDesktop(pidl)) { /* empty pidl */
880 if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) &&
881 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
883 if (This->sPathTarget)
884 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH);
885 } else {
886 /* pidl has to contain exactly one non null SHITEMID */
887 hr = E_INVALIDARG;
889 } else if (_ILIsPidlSimple(pidl)) {
890 if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) &&
891 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER) &&
892 This->sPathTarget)
894 lstrcpynW(pszPath, This->sPathTarget, MAX_PATH);
895 PathAddBackslashW(pszPath);
896 len = lstrlenW(pszPath);
898 _ILSimpleGetTextW(pidl, pszPath + len, MAX_PATH + 1 - len);
899 if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags);
900 } else {
901 hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, pszPath, MAX_PATH);
904 if (SUCCEEDED(hr)) {
905 /* Win9x always returns ANSI strings, NT always returns Unicode strings */
906 if (GetVersion() & 0x80000000) {
907 strRet->uType = STRRET_CSTR;
908 if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->u.cStr, MAX_PATH,
909 NULL, NULL))
910 strRet->u.cStr[0] = '\0';
911 CoTaskMemFree(pszPath);
912 } else {
913 strRet->uType = STRRET_WSTR;
914 strRet->u.pOleStr = pszPath;
916 } else
917 CoTaskMemFree(pszPath);
919 TRACE ("-- (%p)->(%s)\n", This, strRet->uType == STRRET_CSTR ? strRet->u.cStr : debugstr_w(strRet->u.pOleStr));
920 return hr;
923 /**************************************************************************
924 * IShellFolder_fnSetNameOf
925 * Changes the name of a file object or subfolder, possibly changing its item
926 * identifier in the process.
928 * PARAMETERS
929 * HWND hwndOwner, //[in ] Owner window for output
930 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
931 * LPCOLESTR lpszName, //[in ] the items new display name
932 * DWORD dwFlags, //[in ] SHGNO formatting flags
933 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
935 static HRESULT WINAPI IShellFolder_fnSetNameOf (IShellFolder2 * iface,
936 HWND hwndOwner,
937 LPCITEMIDLIST pidl,
938 LPCOLESTR lpName,
939 DWORD dwFlags,
940 LPITEMIDLIST * pPidlOut)
942 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
943 WCHAR szSrc[MAX_PATH + 1], szDest[MAX_PATH + 1];
944 LPWSTR ptr;
945 BOOL bIsFolder = _ILIsFolder (ILFindLastID (pidl));
947 TRACE ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl,
948 debugstr_w (lpName), dwFlags, pPidlOut);
950 /* build source path */
951 lstrcpynW(szSrc, This->sPathTarget, MAX_PATH);
952 ptr = PathAddBackslashW (szSrc);
953 if (ptr)
954 _ILSimpleGetTextW (pidl, ptr, MAX_PATH + 1 - (ptr - szSrc));
956 /* build destination path */
957 if (dwFlags == SHGDN_NORMAL || dwFlags & SHGDN_INFOLDER) {
958 lstrcpynW(szDest, This->sPathTarget, MAX_PATH);
959 ptr = PathAddBackslashW (szDest);
960 if (ptr)
961 lstrcpynW(ptr, lpName, MAX_PATH + 1 - (ptr - szDest));
962 } else
963 lstrcpynW(szDest, lpName, MAX_PATH);
965 if(!(dwFlags & SHGDN_FORPARSING) && SHELL_FS_HideExtension(szSrc)) {
966 WCHAR *ext = PathFindExtensionW(szSrc);
967 if(*ext != '\0') {
968 INT len = strlenW(szDest);
969 lstrcpynW(szDest + len, ext, MAX_PATH - len);
973 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc), debugstr_w(szDest));
975 if (MoveFileW (szSrc, szDest)) {
976 HRESULT hr = S_OK;
978 if (pPidlOut)
979 hr = _ILCreateFromPathW(szDest, pPidlOut);
981 SHChangeNotify (bIsFolder ? SHCNE_RENAMEFOLDER : SHCNE_RENAMEITEM,
982 SHCNF_PATHW, szSrc, szDest);
984 return hr;
987 return E_FAIL;
990 static HRESULT WINAPI IShellFolder_fnGetDefaultSearchGUID (IShellFolder2 *iface,
991 GUID * pguid)
993 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
994 FIXME ("(%p)\n", This);
995 return E_NOTIMPL;
997 static HRESULT WINAPI IShellFolder_fnEnumSearches (IShellFolder2 * iface,
998 IEnumExtraSearch ** ppenum)
1000 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
1001 FIXME ("(%p)\n", This);
1002 return E_NOTIMPL;
1005 static HRESULT WINAPI
1006 IShellFolder_fnGetDefaultColumn (IShellFolder2 * iface, DWORD dwRes,
1007 ULONG * pSort, ULONG * pDisplay)
1009 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
1011 TRACE ("(%p)\n", This);
1013 if (pSort)
1014 *pSort = 0;
1015 if (pDisplay)
1016 *pDisplay = 0;
1018 return S_OK;
1021 static HRESULT WINAPI
1022 IShellFolder_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn,
1023 DWORD * pcsFlags)
1025 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
1027 TRACE ("(%p)\n", This);
1029 if (!pcsFlags || iColumn >= GENERICSHELLVIEWCOLUMNS)
1030 return E_INVALIDARG;
1032 *pcsFlags = GenericSFHeader[iColumn].pcsFlags;
1034 return S_OK;
1037 static HRESULT WINAPI
1038 IShellFolder_fnGetDetailsEx (IShellFolder2 * iface, LPCITEMIDLIST pidl,
1039 const SHCOLUMNID * pscid, VARIANT * pv)
1041 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
1042 FIXME ("(%p)\n", This);
1044 return E_NOTIMPL;
1047 static HRESULT WINAPI
1048 IShellFolder_fnGetDetailsOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
1049 UINT iColumn, SHELLDETAILS * psd)
1051 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
1052 HRESULT hr = E_FAIL;
1054 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
1056 if (!psd || iColumn >= GENERICSHELLVIEWCOLUMNS)
1057 return E_INVALIDARG;
1059 if (!pidl) {
1060 /* the header titles */
1061 psd->fmt = GenericSFHeader[iColumn].fmt;
1062 psd->cxChar = GenericSFHeader[iColumn].cxChar;
1063 psd->str.uType = STRRET_CSTR;
1064 LoadStringA (shell32_hInstance, GenericSFHeader[iColumn].colnameid,
1065 psd->str.u.cStr, MAX_PATH);
1066 return S_OK;
1067 } else {
1068 hr = S_OK;
1069 psd->str.uType = STRRET_CSTR;
1070 /* the data from the pidl */
1071 switch (iColumn) {
1072 case 0: /* name */
1073 hr = IShellFolder_GetDisplayNameOf (iface, pidl,
1074 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
1075 break;
1076 case 1: /* size */
1077 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
1078 break;
1079 case 2: /* type */
1080 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
1081 break;
1082 case 3: /* date */
1083 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
1084 break;
1085 case 4: /* attributes */
1086 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
1087 break;
1091 return hr;
1094 static HRESULT WINAPI
1095 IShellFolder_fnMapColumnToSCID (IShellFolder2 * iface, UINT column,
1096 SHCOLUMNID * pscid)
1098 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
1099 FIXME ("(%p)\n", This);
1100 return E_NOTIMPL;
1103 static const IShellFolder2Vtbl sfvt =
1105 IShellFolder_fnQueryInterface,
1106 IShellFolder_fnAddRef,
1107 IShellFolder_fnRelease,
1108 IShellFolder_fnParseDisplayName,
1109 IShellFolder_fnEnumObjects,
1110 IShellFolder_fnBindToObject,
1111 IShellFolder_fnBindToStorage,
1112 IShellFolder_fnCompareIDs,
1113 IShellFolder_fnCreateViewObject,
1114 IShellFolder_fnGetAttributesOf,
1115 IShellFolder_fnGetUIObjectOf,
1116 IShellFolder_fnGetDisplayNameOf,
1117 IShellFolder_fnSetNameOf,
1118 /* ShellFolder2 */
1119 IShellFolder_fnGetDefaultSearchGUID,
1120 IShellFolder_fnEnumSearches,
1121 IShellFolder_fnGetDefaultColumn,
1122 IShellFolder_fnGetDefaultColumnState,
1123 IShellFolder_fnGetDetailsEx,
1124 IShellFolder_fnGetDetailsOf,
1125 IShellFolder_fnMapColumnToSCID
1128 /****************************************************************************
1129 * ISFHelper for IShellFolder implementation
1132 static HRESULT WINAPI
1133 ISFHelper_fnQueryInterface (ISFHelper * iface, REFIID riid, LPVOID * ppvObj)
1135 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1137 TRACE ("(%p)->(count=%u)\n", This, This->ref);
1139 return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
1142 static ULONG WINAPI ISFHelper_fnAddRef (ISFHelper * iface)
1144 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1146 TRACE ("(%p)->(count=%u)\n", This, This->ref);
1148 return IUnknown_AddRef (This->pUnkOuter);
1151 static ULONG WINAPI ISFHelper_fnRelease (ISFHelper * iface)
1153 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1155 TRACE ("(%p)\n", This);
1157 return IUnknown_Release (This->pUnkOuter);
1160 /****************************************************************************
1161 * ISFHelper_fnGetUniqueName
1163 * creates a unique folder name
1166 static HRESULT WINAPI
1167 ISFHelper_fnGetUniqueName (ISFHelper * iface, LPWSTR pwszName, UINT uLen)
1169 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1170 IEnumIDList *penum;
1171 HRESULT hr;
1172 WCHAR wszText[MAX_PATH];
1173 WCHAR wszNewFolder[25];
1174 const WCHAR wszFormat[] = {'%','s',' ','%','d',0 };
1176 TRACE ("(%p)(%p %u)\n", This, pwszName, uLen);
1178 LoadStringW(shell32_hInstance, IDS_NEWFOLDER, wszNewFolder, sizeof(wszNewFolder)/sizeof(WCHAR));
1179 if (uLen < sizeof(wszNewFolder)/sizeof(WCHAR) + 3)
1180 return E_POINTER;
1182 lstrcpynW (pwszName, wszNewFolder, uLen);
1184 hr = IShellFolder_fnEnumObjects (_IShellFolder2_ (This), 0,
1185 SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &penum);
1186 if (penum) {
1187 LPITEMIDLIST pidl;
1188 DWORD dwFetched;
1189 int i = 1;
1191 next:
1192 IEnumIDList_Reset (penum);
1193 while (S_OK == IEnumIDList_Next (penum, 1, &pidl, &dwFetched) &&
1194 dwFetched) {
1195 _ILSimpleGetTextW (pidl, wszText, MAX_PATH);
1196 if (0 == lstrcmpiW (wszText, pwszName)) {
1197 snprintfW (pwszName, uLen, wszFormat, wszNewFolder, i++);
1198 if (i > 99) {
1199 hr = E_FAIL;
1200 break;
1202 goto next;
1206 IEnumIDList_Release (penum);
1208 return hr;
1211 /****************************************************************************
1212 * ISFHelper_fnAddFolder
1214 * adds a new folder.
1217 static HRESULT WINAPI
1218 ISFHelper_fnAddFolder (ISFHelper * iface, HWND hwnd, LPCWSTR pwszName,
1219 LPITEMIDLIST * ppidlOut)
1221 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1222 WCHAR wszNewDir[MAX_PATH];
1223 DWORD bRes;
1224 HRESULT hres = E_FAIL;
1226 TRACE ("(%p)(%s %p)\n", This, debugstr_w(pwszName), ppidlOut);
1228 wszNewDir[0] = 0;
1229 if (This->sPathTarget)
1230 lstrcpynW(wszNewDir, This->sPathTarget, MAX_PATH);
1231 PathAppendW(wszNewDir, pwszName);
1233 bRes = CreateDirectoryW (wszNewDir, NULL);
1234 if (bRes) {
1235 LPITEMIDLIST relPidl;
1237 lstrcpyW(wszNewDir, pwszName);
1239 hres = IShellFolder_ParseDisplayName((IShellFolder*)&This->lpvtblShellFolder,
1240 hwnd, NULL, wszNewDir, NULL, &relPidl, NULL);
1242 if (SUCCEEDED(hres)) {
1243 LPITEMIDLIST fullPidl;
1245 fullPidl = ILCombine(This->pidlRoot, relPidl);
1247 if (fullPidl) {
1248 SHChangeNotify(SHCNE_MKDIR, SHCNF_IDLIST, fullPidl, NULL);
1249 ILFree(fullPidl);
1251 if (ppidlOut)
1252 *ppidlOut = relPidl;
1253 else
1254 ILFree(relPidl);
1255 } else {
1256 WARN("failed to combine %s into a full PIDL\n", wine_dbgstr_w(pwszName));
1257 ILFree(relPidl);
1260 } else
1261 WARN("failed to parse %s into a PIDL\n", wine_dbgstr_w(pwszName));
1263 } else {
1264 WCHAR wszText[128 + MAX_PATH];
1265 WCHAR wszTempText[128];
1266 WCHAR wszCaption[256];
1268 /* Cannot Create folder because of permissions */
1269 LoadStringW (shell32_hInstance, IDS_CREATEFOLDER_DENIED, wszTempText,
1270 sizeof (wszTempText)/sizeof (wszTempText[0]));
1271 LoadStringW (shell32_hInstance, IDS_CREATEFOLDER_CAPTION, wszCaption,
1272 sizeof (wszCaption)/sizeof (wszCaption[0]));
1273 sprintfW (wszText, wszTempText, wszNewDir);
1274 MessageBoxW (hwnd, wszText, wszCaption, MB_OK | MB_ICONEXCLAMATION);
1277 return hres;
1280 /****************************************************************************
1281 * build_paths_list
1283 * Builds a list of paths like the one used in SHFileOperation from a table of
1284 * PIDLs relative to the given base folder
1286 static WCHAR *build_paths_list(LPCWSTR wszBasePath, int cidl, const LPCITEMIDLIST *pidls)
1288 WCHAR *wszPathsList;
1289 WCHAR *wszListPos;
1290 int iPathLen;
1291 int i;
1293 iPathLen = lstrlenW(wszBasePath);
1294 wszPathsList = HeapAlloc(GetProcessHeap(), 0, MAX_PATH*sizeof(WCHAR)*cidl+1);
1295 wszListPos = wszPathsList;
1297 for (i = 0; i < cidl; i++) {
1298 if (!_ILIsFolder(pidls[i]) && !_ILIsValue(pidls[i]))
1299 continue;
1301 lstrcpynW(wszListPos, wszBasePath, MAX_PATH);
1302 /* FIXME: abort if path too long */
1303 _ILSimpleGetTextW(pidls[i], wszListPos+iPathLen, MAX_PATH-iPathLen);
1304 wszListPos += lstrlenW(wszListPos)+1;
1306 *wszListPos=0;
1307 return wszPathsList;
1310 /****************************************************************************
1311 * ISFHelper_fnDeleteItems
1313 * deletes items in folder
1315 static HRESULT WINAPI
1316 ISFHelper_fnDeleteItems (ISFHelper * iface, UINT cidl, LPCITEMIDLIST * apidl)
1318 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1319 UINT i;
1320 SHFILEOPSTRUCTW op;
1321 WCHAR wszPath[MAX_PATH];
1322 WCHAR *wszPathsList;
1323 HRESULT ret;
1324 WCHAR *wszCurrentPath;
1326 TRACE ("(%p)(%u %p)\n", This, cidl, apidl);
1327 if (cidl==0) return S_OK;
1329 if (This->sPathTarget)
1330 lstrcpynW(wszPath, This->sPathTarget, MAX_PATH);
1331 else
1332 wszPath[0] = '\0';
1333 PathAddBackslashW(wszPath);
1334 wszPathsList = build_paths_list(wszPath, cidl, apidl);
1336 ZeroMemory(&op, sizeof(op));
1337 op.hwnd = GetActiveWindow();
1338 op.wFunc = FO_DELETE;
1339 op.pFrom = wszPathsList;
1340 op.fFlags = FOF_ALLOWUNDO;
1341 if (SHFileOperationW(&op))
1343 WARN("SHFileOperation failed\n");
1344 ret = E_FAIL;
1346 else
1347 ret = S_OK;
1349 /* we currently need to manually send the notifies */
1350 wszCurrentPath = wszPathsList;
1351 for (i = 0; i < cidl; i++)
1353 LONG wEventId;
1355 if (_ILIsFolder(apidl[i]))
1356 wEventId = SHCNE_RMDIR;
1357 else if (_ILIsValue(apidl[i]))
1358 wEventId = SHCNE_DELETE;
1359 else
1360 continue;
1362 /* check if file exists */
1363 if (GetFileAttributesW(wszCurrentPath) == INVALID_FILE_ATTRIBUTES)
1365 LPITEMIDLIST pidl = ILCombine(This->pidlRoot, apidl[i]);
1366 SHChangeNotify(wEventId, SHCNF_IDLIST, pidl, NULL);
1367 SHFree(pidl);
1370 wszCurrentPath += lstrlenW(wszCurrentPath)+1;
1372 HeapFree(GetProcessHeap(), 0, wszPathsList);
1373 return ret;
1376 /****************************************************************************
1377 * ISFHelper_fnCopyItems
1379 * copies items to this folder
1381 static HRESULT WINAPI
1382 ISFHelper_fnCopyItems (ISFHelper * iface, IShellFolder * pSFFrom, UINT cidl,
1383 LPCITEMIDLIST * apidl)
1385 HRESULT ret=E_FAIL;
1386 IPersistFolder2 *ppf2 = NULL;
1387 WCHAR wszSrcPathRoot[MAX_PATH],
1388 wszDstPath[MAX_PATH+1];
1389 WCHAR *wszSrcPathsList;
1390 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1392 SHFILEOPSTRUCTW fop;
1394 TRACE ("(%p)->(%p,%u,%p)\n", This, pSFFrom, cidl, apidl);
1396 IShellFolder_QueryInterface (pSFFrom, &IID_IPersistFolder2,
1397 (LPVOID *) & ppf2);
1398 if (ppf2) {
1399 LPITEMIDLIST pidl;
1401 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2, &pidl))) {
1402 SHGetPathFromIDListW (pidl, wszSrcPathRoot);
1403 ZeroMemory(wszDstPath, MAX_PATH+1);
1404 if (This->sPathTarget)
1405 lstrcpynW(wszDstPath, This->sPathTarget, MAX_PATH);
1406 PathAddBackslashW(wszSrcPathRoot);
1407 PathAddBackslashW(wszDstPath);
1408 wszSrcPathsList = build_paths_list(wszSrcPathRoot, cidl, apidl);
1409 ZeroMemory(&fop, sizeof(fop));
1410 fop.hwnd = GetActiveWindow();
1411 fop.wFunc = FO_COPY;
1412 fop.pFrom = wszSrcPathsList;
1413 fop.pTo = wszDstPath;
1414 fop.fFlags = FOF_ALLOWUNDO;
1415 ret = S_OK;
1416 if(SHFileOperationW(&fop))
1418 WARN("Copy failed\n");
1419 ret = E_FAIL;
1421 HeapFree(GetProcessHeap(), 0, wszSrcPathsList);
1424 SHFree(pidl);
1425 IPersistFolder2_Release(ppf2);
1427 return ret;
1430 static const ISFHelperVtbl shvt =
1432 ISFHelper_fnQueryInterface,
1433 ISFHelper_fnAddRef,
1434 ISFHelper_fnRelease,
1435 ISFHelper_fnGetUniqueName,
1436 ISFHelper_fnAddFolder,
1437 ISFHelper_fnDeleteItems,
1438 ISFHelper_fnCopyItems
1441 /************************************************************************
1442 * IFSFldr_PersistFolder3_QueryInterface
1445 static HRESULT WINAPI
1446 IFSFldr_PersistFolder3_QueryInterface (IPersistFolder3 * iface, REFIID iid,
1447 LPVOID * ppvObj)
1449 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1451 TRACE ("(%p)\n", This);
1453 return IUnknown_QueryInterface (This->pUnkOuter, iid, ppvObj);
1456 /************************************************************************
1457 * IFSFldr_PersistFolder3_AddRef
1460 static ULONG WINAPI
1461 IFSFldr_PersistFolder3_AddRef (IPersistFolder3 * iface)
1463 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1465 TRACE ("(%p)->(count=%u)\n", This, This->ref);
1467 return IUnknown_AddRef (This->pUnkOuter);
1470 /************************************************************************
1471 * IFSFldr_PersistFolder3_Release
1474 static ULONG WINAPI
1475 IFSFldr_PersistFolder3_Release (IPersistFolder3 * iface)
1477 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1479 TRACE ("(%p)->(count=%u)\n", This, This->ref);
1481 return IUnknown_Release (This->pUnkOuter);
1484 /************************************************************************
1485 * IFSFldr_PersistFolder3_GetClassID
1487 static HRESULT WINAPI
1488 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3 * iface, CLSID * lpClassId)
1490 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1492 TRACE ("(%p)\n", This);
1494 if (!lpClassId)
1495 return E_POINTER;
1496 *lpClassId = *This->pclsid;
1498 return S_OK;
1501 /************************************************************************
1502 * IFSFldr_PersistFolder3_Initialize
1504 * NOTES
1505 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1507 static HRESULT WINAPI
1508 IFSFldr_PersistFolder3_Initialize (IPersistFolder3 * iface, LPCITEMIDLIST pidl)
1510 WCHAR wszTemp[MAX_PATH];
1512 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1514 TRACE ("(%p)->(%p)\n", This, pidl);
1516 SHFree (This->pidlRoot); /* free the old pidl */
1517 This->pidlRoot = ILClone (pidl); /* set my pidl */
1519 SHFree (This->sPathTarget);
1520 This->sPathTarget = NULL;
1522 /* set my path */
1523 if (SHGetPathFromIDListW (pidl, wszTemp)) {
1524 int len = strlenW(wszTemp);
1525 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1526 if (!This->sPathTarget)
1527 return E_OUTOFMEMORY;
1528 memcpy(This->sPathTarget, wszTemp, (len + 1) * sizeof(WCHAR));
1531 TRACE ("--(%p)->(%s)\n", This, debugstr_w(This->sPathTarget));
1532 return S_OK;
1535 /**************************************************************************
1536 * IFSFldr_PersistFolder3_GetCurFolder
1538 static HRESULT WINAPI
1539 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3 * iface,
1540 LPITEMIDLIST * pidl)
1542 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1544 TRACE ("(%p)->(%p)\n", This, pidl);
1546 if (!pidl) return E_POINTER;
1547 *pidl = ILClone (This->pidlRoot);
1548 return S_OK;
1551 /**************************************************************************
1552 * IFSFldr_PersistFolder3_InitializeEx
1554 * FIXME: error handling
1556 static HRESULT WINAPI
1557 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3 * iface,
1558 IBindCtx * pbc, LPCITEMIDLIST pidlRoot,
1559 const PERSIST_FOLDER_TARGET_INFO * ppfti)
1561 WCHAR wszTemp[MAX_PATH];
1563 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1565 TRACE ("(%p)->(%p,%p,%p)\n", This, pbc, pidlRoot, ppfti);
1566 if (ppfti)
1567 TRACE ("--%p %s %s 0x%08x 0x%08x\n",
1568 ppfti->pidlTargetFolder, debugstr_w (ppfti->szTargetParsingName),
1569 debugstr_w (ppfti->szNetworkProvider), ppfti->dwAttributes,
1570 ppfti->csidl);
1572 pdump (pidlRoot);
1573 if (ppfti && ppfti->pidlTargetFolder)
1574 pdump (ppfti->pidlTargetFolder);
1576 if (This->pidlRoot)
1577 __SHFreeAndNil (&This->pidlRoot); /* free the old */
1578 if (This->sPathTarget)
1579 __SHFreeAndNil (&This->sPathTarget);
1582 * Root path and pidl
1584 This->pidlRoot = ILClone (pidlRoot);
1587 * the target folder is specified in csidl OR pidlTargetFolder OR
1588 * szTargetParsingName
1590 if (ppfti) {
1591 if (ppfti->csidl != -1) {
1592 if (SHGetSpecialFolderPathW (0, wszTemp, ppfti->csidl,
1593 ppfti->csidl & CSIDL_FLAG_CREATE)) {
1594 int len = strlenW(wszTemp);
1595 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1596 if (!This->sPathTarget)
1597 return E_OUTOFMEMORY;
1598 memcpy(This->sPathTarget, wszTemp, (len + 1) * sizeof(WCHAR));
1600 } else if (ppfti->szTargetParsingName[0]) {
1601 int len = strlenW(ppfti->szTargetParsingName);
1602 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1603 if (!This->sPathTarget)
1604 return E_OUTOFMEMORY;
1605 memcpy(This->sPathTarget, ppfti->szTargetParsingName,
1606 (len + 1) * sizeof(WCHAR));
1607 } else if (ppfti->pidlTargetFolder) {
1608 if (SHGetPathFromIDListW(ppfti->pidlTargetFolder, wszTemp)) {
1609 int len = strlenW(wszTemp);
1610 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1611 if (!This->sPathTarget)
1612 return E_OUTOFMEMORY;
1613 memcpy(This->sPathTarget, wszTemp, (len + 1) * sizeof(WCHAR));
1618 TRACE ("--(%p)->(target=%s)\n", This, debugstr_w(This->sPathTarget));
1619 pdump (This->pidlRoot);
1620 return (This->sPathTarget) ? S_OK : E_FAIL;
1623 static HRESULT WINAPI
1624 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3 * iface,
1625 PERSIST_FOLDER_TARGET_INFO * ppfti)
1627 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1628 FIXME ("(%p)->(%p)\n", This, ppfti);
1629 ZeroMemory (ppfti, sizeof (*ppfti));
1630 return E_NOTIMPL;
1633 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3 =
1635 IFSFldr_PersistFolder3_QueryInterface,
1636 IFSFldr_PersistFolder3_AddRef,
1637 IFSFldr_PersistFolder3_Release,
1638 IFSFldr_PersistFolder3_GetClassID,
1639 IFSFldr_PersistFolder3_Initialize,
1640 IFSFldr_PersistFolder3_fnGetCurFolder,
1641 IFSFldr_PersistFolder3_InitializeEx,
1642 IFSFldr_PersistFolder3_GetFolderTargetInfo
1645 /****************************************************************************
1646 * ISFDropTarget implementation
1648 static BOOL
1649 ISFDropTarget_QueryDrop (IDropTarget * iface, DWORD dwKeyState,
1650 LPDWORD pdwEffect)
1652 DWORD dwEffect = *pdwEffect;
1654 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1656 *pdwEffect = DROPEFFECT_NONE;
1658 if (This->fAcceptFmt) { /* Does our interpretation of the keystate ... */
1659 *pdwEffect = KeyStateToDropEffect (dwKeyState);
1661 /* ... matches the desired effect ? */
1662 if (dwEffect & *pdwEffect) {
1663 return TRUE;
1666 return FALSE;
1669 static HRESULT WINAPI
1670 ISFDropTarget_QueryInterface (IDropTarget * iface, REFIID riid, LPVOID * ppvObj)
1672 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1674 TRACE ("(%p)\n", This);
1676 return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
1679 static ULONG WINAPI ISFDropTarget_AddRef (IDropTarget * iface)
1681 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1683 TRACE ("(%p)\n", This);
1685 return IUnknown_AddRef (This->pUnkOuter);
1688 static ULONG WINAPI ISFDropTarget_Release (IDropTarget * iface)
1690 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1692 TRACE ("(%p)\n", This);
1694 return IUnknown_Release (This->pUnkOuter);
1697 static HRESULT WINAPI
1698 ISFDropTarget_DragEnter (IDropTarget * iface, IDataObject * pDataObject,
1699 DWORD dwKeyState, POINTL pt, DWORD * pdwEffect)
1701 FORMATETC fmt;
1703 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1705 TRACE ("(%p)->(DataObject=%p)\n", This, pDataObject);
1707 InitFormatEtc (fmt, This->cfShellIDList, TYMED_HGLOBAL);
1709 This->fAcceptFmt = (S_OK == IDataObject_QueryGetData (pDataObject, &fmt)) ?
1710 TRUE : FALSE;
1712 ISFDropTarget_QueryDrop (iface, dwKeyState, pdwEffect);
1714 return S_OK;
1717 static HRESULT WINAPI
1718 ISFDropTarget_DragOver (IDropTarget * iface, DWORD dwKeyState, POINTL pt,
1719 DWORD * pdwEffect)
1721 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1723 TRACE ("(%p)\n", This);
1725 if (!pdwEffect)
1726 return E_INVALIDARG;
1728 ISFDropTarget_QueryDrop (iface, dwKeyState, pdwEffect);
1730 return S_OK;
1733 static HRESULT WINAPI ISFDropTarget_DragLeave (IDropTarget * iface)
1735 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1737 TRACE ("(%p)\n", This);
1739 This->fAcceptFmt = FALSE;
1741 return S_OK;
1744 static HRESULT WINAPI
1745 ISFDropTarget_Drop (IDropTarget * iface, IDataObject * pDataObject,
1746 DWORD dwKeyState, POINTL pt, DWORD * pdwEffect)
1748 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1750 FIXME ("(%p) object dropped\n", This);
1752 return E_NOTIMPL;
1755 static const IDropTargetVtbl dtvt = {
1756 ISFDropTarget_QueryInterface,
1757 ISFDropTarget_AddRef,
1758 ISFDropTarget_Release,
1759 ISFDropTarget_DragEnter,
1760 ISFDropTarget_DragOver,
1761 ISFDropTarget_DragLeave,
1762 ISFDropTarget_Drop