- Implement IPersistFolder2.
[wine] / dlls / shell32 / shfldr_fs.c
1
2 /*
3  * file system folder
4  *
5  * Copyright 1997             Marcus Meissner
6  * Copyright 1998, 1999, 2002 Juergen Schmied
7  *
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.
12  *
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.
17  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24 #include "wine/port.h"
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30
31 #define COBJMACROS
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
34
35 #include "winerror.h"
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winreg.h"
39 #include "wingdi.h"
40 #include "winuser.h"
41
42 #include "ole2.h"
43 #include "shlguid.h"
44
45 #include "enumidlist.h"
46 #include "pidl.h"
47 #include "undocshell.h"
48 #include "shell32_main.h"
49 #include "shresdef.h"
50 #include "shlwapi.h"
51 #include "shellfolder.h"
52 #include "wine/debug.h"
53 #include "debughlp.h"
54 #include "shfldr.h"
55
56 WINE_DEFAULT_DEBUG_CHANNEL (shell);
57
58 /***********************************************************************
59 *   IShellFolder implementation
60 */
61
62 typedef struct {
63     IUnknownVtbl        *lpVtbl;
64     DWORD                ref;
65     IShellFolder2Vtbl   *lpvtblShellFolder;
66     IPersistFolder3Vtbl *lpvtblPersistFolder3;
67     IDropTargetVtbl     *lpvtblDropTarget;
68     ISFHelperVtbl       *lpvtblSFHelper;
69
70     IUnknown *pUnkOuter; /* used for aggregation */
71
72     CLSID *pclsid;
73
74     /* both paths are parsible from the desktop */
75     LPSTR sPathTarget;     /* complete path to target used for enumeration and ChangeNotify */
76
77     LPITEMIDLIST pidlRoot; /* absolute pidl */
78
79     int dwAttributes;      /* attributes returned by GetAttributesOf FIXME: use it */
80
81     UINT cfShellIDList;    /* clipboardformat for IDropTarget */
82     BOOL fAcceptFmt;       /* flag for pending Drop */
83 } IGenericSFImpl;
84
85 static struct IUnknownVtbl unkvt;
86 static struct IShellFolder2Vtbl sfvt;
87 static struct IPersistFolder3Vtbl vt_FSFldr_PersistFolder3; /* IPersistFolder3 for a FS_Folder */
88 static struct IDropTargetVtbl dtvt;
89 static struct ISFHelperVtbl shvt;
90
91 #define _IShellFolder2_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblShellFolder)))
92 #define _ICOM_THIS_From_IShellFolder2(class, name) class* This = (class*)(((char*)name)-_IShellFolder2_Offset);
93
94 #define _IPersistFolder2_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblPersistFolder3)))
95 #define _ICOM_THIS_From_IPersistFolder2(class, name) class* This = (class*)(((char*)name)-_IPersistFolder2_Offset);
96
97 #define _IPersistFolder3_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblPersistFolder3)))
98 #define _ICOM_THIS_From_IPersistFolder3(class, name) class* This = (class*)(((char*)name)-_IPersistFolder3_Offset);
99
100 #define _IDropTarget_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblDropTarget)))
101 #define _ICOM_THIS_From_IDropTarget(class, name) class* This = (class*)(((char*)name)-_IDropTarget_Offset);
102
103 #define _ISFHelper_Offset ((int)(&(((IGenericSFImpl*)0)->lpvtblSFHelper)))
104 #define _ICOM_THIS_From_ISFHelper(class, name) class* This = (class*)(((char*)name)-_ISFHelper_Offset);
105
106 /*
107   converts This to an interface pointer
108 */
109 #define _IUnknown_(This)        (IUnknown*)&(This->lpVtbl)
110 #define _IShellFolder_(This)    (IShellFolder*)&(This->lpvtblShellFolder)
111 #define _IShellFolder2_(This)   (IShellFolder2*)&(This->lpvtblShellFolder)
112 #define _IPersist_(This)        (IPersist*)&(This->lpvtblPersistFolder3)
113 #define _IPersistFolder_(This)  (IPersistFolder*)&(This->lpvtblPersistFolder3)
114 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpvtblPersistFolder3)
115 #define _IPersistFolder3_(This) (IPersistFolder3*)&(This->lpvtblPersistFolder3)
116 #define _IDropTarget_(This)     (IDropTarget*)&(This->lpvtblDropTarget)
117 #define _ISFHelper_(This)       (ISFHelper*)&(This->lpvtblSFHelper)
118
119 /**************************************************************************
120 * registers clipboardformat once
121 */
122 static void SF_RegisterClipFmt (IGenericSFImpl * This)
123 {
124     TRACE ("(%p)\n", This);
125
126     if (!This->cfShellIDList) {
127         This->cfShellIDList = RegisterClipboardFormatA (CFSTR_SHELLIDLIST);
128     }
129 }
130
131 /**************************************************************************
132 * we need a separate IUnknown to handle aggregation
133 * (inner IUnknown)
134 */
135 static HRESULT WINAPI IUnknown_fnQueryInterface (IUnknown * iface, REFIID riid, LPVOID * ppvObj)
136 {
137     IGenericSFImpl *This = (IGenericSFImpl *)iface;
138
139     TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
140
141     *ppvObj = NULL;
142
143     if (IsEqualIID (riid, &IID_IUnknown))
144         *ppvObj = _IUnknown_ (This);
145     else if (IsEqualIID (riid, &IID_IShellFolder))
146         *ppvObj = _IShellFolder_ (This);
147     else if (IsEqualIID (riid, &IID_IShellFolder2))
148         *ppvObj = _IShellFolder_ (This);
149     else if (IsEqualIID (riid, &IID_IPersist))
150         *ppvObj = _IPersist_ (This);
151     else if (IsEqualIID (riid, &IID_IPersistFolder))
152         *ppvObj = _IPersistFolder_ (This);
153     else if (IsEqualIID (riid, &IID_IPersistFolder2))
154         *ppvObj = _IPersistFolder2_ (This);
155     else if (IsEqualIID (riid, &IID_IPersistFolder3))
156         *ppvObj = _IPersistFolder3_ (This);
157     else if (IsEqualIID (riid, &IID_ISFHelper))
158         *ppvObj = _ISFHelper_ (This);
159     else if (IsEqualIID (riid, &IID_IDropTarget)) {
160         *ppvObj = _IDropTarget_ (This);
161         SF_RegisterClipFmt (This);
162     }
163
164     if (*ppvObj) {
165         IUnknown_AddRef ((IUnknown *) (*ppvObj));
166         TRACE ("-- Interface = %p\n", *ppvObj);
167         return S_OK;
168     }
169     TRACE ("-- Interface: E_NOINTERFACE\n");
170     return E_NOINTERFACE;
171 }
172
173 static ULONG WINAPI IUnknown_fnAddRef (IUnknown * iface)
174 {
175     IGenericSFImpl *This = (IGenericSFImpl *)iface;
176     ULONG refCount = InterlockedIncrement(&This->ref);
177
178     TRACE ("(%p)->(count=%lu)\n", This, refCount - 1);
179
180     return refCount;
181 }
182
183 static ULONG WINAPI IUnknown_fnRelease (IUnknown * iface)
184 {
185     IGenericSFImpl *This = (IGenericSFImpl *)iface;
186     ULONG refCount = InterlockedDecrement(&This->ref);
187
188     TRACE ("(%p)->(count=%lu)\n", This, refCount + 1);
189
190     if (!refCount) {
191         TRACE ("-- destroying IShellFolder(%p)\n", This);
192
193         if (This->pidlRoot)
194             SHFree (This->pidlRoot);
195         if (This->sPathTarget)
196             SHFree (This->sPathTarget);
197         LocalFree ((HLOCAL) This);
198     }
199     return refCount;
200 }
201
202 static IUnknownVtbl unkvt =
203 {
204       IUnknown_fnQueryInterface,
205       IUnknown_fnAddRef,
206       IUnknown_fnRelease,
207 };
208
209 static shvheader GenericSFHeader[] = {
210     {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
211     {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
212     {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
213     {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
214     {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
215 };
216
217 #define GENERICSHELLVIEWCOLUMNS 5
218
219 /**************************************************************************
220 * IFSFolder_Constructor
221 *
222 * NOTES
223 *  creating undocumented ShellFS_Folder as part of an aggregation
224 *  {F3364BA0-65B9-11CE-A9BA-00AA004AE837}
225 *
226 */
227 HRESULT WINAPI
228 IFSFolder_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
229 {
230     IGenericSFImpl *sf;
231
232     TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
233
234     if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
235         return CLASS_E_NOAGGREGATION;
236     sf = (IGenericSFImpl *) LocalAlloc (LMEM_ZEROINIT, sizeof (IGenericSFImpl));
237     if (!sf)
238         return E_OUTOFMEMORY;
239
240     sf->ref = 0;
241     sf->lpVtbl = &unkvt;
242     sf->lpvtblShellFolder = &sfvt;
243     sf->lpvtblPersistFolder3 = &vt_FSFldr_PersistFolder3;
244     sf->lpvtblDropTarget = &dtvt;
245     sf->lpvtblSFHelper = &shvt;
246     sf->pclsid = (CLSID *) & CLSID_ShellFSFolder;
247     sf->pUnkOuter = pUnkOuter ? pUnkOuter : _IUnknown_ (sf);
248
249     if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv))) {
250         IUnknown_Release (_IUnknown_ (sf));
251         return E_NOINTERFACE;
252     }
253
254     TRACE ("--%p\n", *ppv);
255     return S_OK;
256 }
257
258 /**************************************************************************
259  *  IShellFolder_fnQueryInterface
260  *
261  * PARAMETERS
262  *  REFIID riid       [in ] Requested InterfaceID
263  *  LPVOID* ppvObject [out] Interface* to hold the result
264  */
265 static HRESULT WINAPI
266 IShellFolder_fnQueryInterface (IShellFolder2 * iface, REFIID riid,
267                                LPVOID * ppvObj)
268 {
269     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
270
271     TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
272
273     return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
274 }
275
276 /**************************************************************************
277 *  IShellFolder_AddRef
278 */
279
280 static ULONG WINAPI IShellFolder_fnAddRef (IShellFolder2 * iface)
281 {
282     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
283
284     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
285
286     return IUnknown_AddRef (This->pUnkOuter);
287 }
288
289 /**************************************************************************
290  *  IShellFolder_fnRelease
291  */
292 static ULONG WINAPI IShellFolder_fnRelease (IShellFolder2 * iface)
293 {
294     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
295
296     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
297
298     return IUnknown_Release (This->pUnkOuter);
299 }
300
301 /**************************************************************************
302  *  SHELL32_CreatePidlFromBindCtx  [internal]
303  *
304  *  If the caller bound File System Bind Data, assume it is the 
305  *   find data for the path.
306  *  This allows binding of paths that don't exist.
307  */
308 LPITEMIDLIST SHELL32_CreatePidlFromBindCtx(IBindCtx *pbc, LPCWSTR path)
309 {
310     static const WCHAR szfsbc[] = {
311         'F','i','l','e',' ','S','y','s','t','e','m',' ',
312         'B','i','n','d',' ','D','a','t','a',0 };
313     IFileSystemBindData *fsbd = NULL;
314     LPITEMIDLIST pidl = NULL;
315     IUnknown *param = NULL;
316     WIN32_FIND_DATAW wfd;
317     HRESULT r;
318
319     TRACE("%p %s\n", pbc, debugstr_w(path));
320
321     if (!pbc)
322         return NULL;
323
324     /* see if the caller bound File System Bind Data */
325     r = IBindCtx_GetObjectParam( pbc, (LPOLESTR) szfsbc, &param );
326     if (FAILED(r))
327         return NULL;
328
329     r = IUnknown_QueryInterface( param, &IID_IFileSystemBindData,
330                                  (LPVOID*) &fsbd );
331     if (SUCCEEDED(r))
332     {
333         r = IFileSystemBindData_GetFindData( fsbd, &wfd );
334         if (SUCCEEDED(r))
335         {
336             lstrcpynW( &wfd.cFileName[0], path, MAX_PATH );
337             pidl = _ILCreateFromFindDataW( &wfd );
338         }
339         IFileSystemBindData_Release( fsbd );
340     }
341     
342     return pidl;
343 }
344
345 /**************************************************************************
346 * IShellFolder_ParseDisplayName {SHELL32}
347 *
348 * Parse a display name.
349 *
350 * PARAMS
351 *  hwndOwner       [in]  Parent window for any message's
352 *  pbc             [in]  optional FileSystemBindData context
353 *  lpszDisplayName [in]  Unicode displayname.
354 *  pchEaten        [out] (unicode) characters processed
355 *  ppidl           [out] complex pidl to item
356 *  pdwAttributes   [out] items attributes
357 *
358 * NOTES
359 *  Every folder tries to parse only its own (the leftmost) pidl and creates a
360 *  subfolder to evaluate the remaining parts.
361 *  Now we can parse into namespaces implemented by shell extensions
362 *
363 *  Behaviour on win98: lpszDisplayName=NULL -> crash
364 *                      lpszDisplayName="" -> returns mycoputer-pidl
365 *
366 * FIXME
367 *    pdwAttributes is not set
368 *    pchEaten is not set like in windows
369 */
370 static HRESULT WINAPI
371 IShellFolder_fnParseDisplayName (IShellFolder2 * iface,
372                                  HWND hwndOwner,
373                                  LPBC pbc,
374                                  LPOLESTR lpszDisplayName,
375                                  DWORD * pchEaten, LPITEMIDLIST * ppidl,
376                                  DWORD * pdwAttributes)
377 {
378     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
379
380     HRESULT hr = E_INVALIDARG;
381     LPCWSTR szNext = NULL;
382     WCHAR szElement[MAX_PATH];
383     WCHAR szPath[MAX_PATH];
384     LPITEMIDLIST pidlTemp = NULL;
385     DWORD len;
386
387     TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
388      This, hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
389      pchEaten, ppidl, pdwAttributes);
390
391     if (!lpszDisplayName || !ppidl)
392         return E_INVALIDARG;
393
394     if (pchEaten)
395         *pchEaten = 0; /* strange but like the original */
396
397     pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName);
398     if (!pidlTemp && *lpszDisplayName)
399     {
400         /* get the next element */
401         szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
402
403         /* build the full pathname to the element */
404         /* lstrcpyW(szPath, This->sPathTarget); */
405         MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, szPath, MAX_PATH);
406         PathAddBackslashW(szPath);
407         len = lstrlenW(szPath);
408         lstrcpynW(szPath + len, szElement, MAX_PATH - len);
409
410         /* get the pidl */
411         hr = _ILCreateFromPathW(szPath, &pidlTemp);
412
413         if (SUCCEEDED(hr)) {
414             if (szNext && *szNext) {
415                 /* try to analyse the next element */
416                 hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc,
417                  &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
418             } else {
419                 /* it's the last element */
420                 if (pdwAttributes && *pdwAttributes) {
421                     hr = SHELL32_GetItemAttributes (_IShellFolder_ (This),
422                      pidlTemp, pdwAttributes);
423                 }
424             }
425         }
426     }
427
428     if (SUCCEEDED(hr))
429         *ppidl = pidlTemp;
430     else
431         *ppidl = NULL;
432
433     TRACE ("(%p)->(-- pidl=%p ret=0x%08lx)\n", This, ppidl ? *ppidl : 0, hr);
434
435     return hr;
436 }
437
438 /**************************************************************************
439 * IShellFolder_fnEnumObjects
440 * PARAMETERS
441 *  HWND          hwndOwner,    //[in ] Parent Window
442 *  DWORD         grfFlags,     //[in ] SHCONTF enumeration mask
443 *  LPENUMIDLIST* ppenumIDList  //[out] IEnumIDList interface
444 */
445 static HRESULT WINAPI
446 IShellFolder_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner,
447                             DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
448 {
449     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
450
451     TRACE ("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner,
452      dwFlags, ppEnumIDList);
453
454     *ppEnumIDList = IEnumIDList_Constructor();
455     if (*ppEnumIDList)
456     {
457         WCHAR path[MAX_PATH];
458         MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, path, MAX_PATH);
459         CreateFolderEnumList(*ppEnumIDList, path, dwFlags);
460     }
461
462     TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
463
464     return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
465 }
466
467 /**************************************************************************
468 * IShellFolder_fnBindToObject
469 * PARAMETERS
470 *  LPCITEMIDLIST pidl,       //[in ] relative pidl to open
471 *  LPBC          pbc,        //[in ] optional FileSystemBindData context
472 *  REFIID        riid,       //[in ] Initial Interface
473 *  LPVOID*       ppvObject   //[out] Interface*
474 */
475 static HRESULT WINAPI
476 IShellFolder_fnBindToObject (IShellFolder2 * iface, LPCITEMIDLIST pidl,
477                              LPBC pbc, REFIID riid, LPVOID * ppvOut)
478 {
479     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
480
481     TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbc,
482      shdebugstr_guid (riid), ppvOut);
483
484     return SHELL32_BindToChild (This->pidlRoot, This->sPathTarget, pidl, riid,
485      ppvOut);
486 }
487
488 /**************************************************************************
489 *  IShellFolder_fnBindToStorage
490 * PARAMETERS
491 *  LPCITEMIDLIST pidl,       //[in ] complex pidl to store
492 *  LPBC          pbc,        //[in ] reserved
493 *  REFIID        riid,       //[in ] Initial storage interface
494 *  LPVOID*       ppvObject   //[out] Interface* returned
495 */
496 static HRESULT WINAPI
497 IShellFolder_fnBindToStorage (IShellFolder2 * iface, LPCITEMIDLIST pidl,
498                               LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
499 {
500     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
501
502     FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved,
503      shdebugstr_guid (riid), ppvOut);
504
505     *ppvOut = NULL;
506     return E_NOTIMPL;
507 }
508
509 /**************************************************************************
510 *  IShellFolder_fnCompareIDs
511 */
512
513 static HRESULT WINAPI
514 IShellFolder_fnCompareIDs (IShellFolder2 * iface, LPARAM lParam,
515                            LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
516 {
517     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
518
519     int nReturn;
520
521     TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
522     nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
523     TRACE ("-- %i\n", nReturn);
524     return nReturn;
525 }
526
527 /**************************************************************************
528 * IShellFolder_fnCreateViewObject
529 */
530 static HRESULT WINAPI
531 IShellFolder_fnCreateViewObject (IShellFolder2 * iface, HWND hwndOwner,
532                                  REFIID riid, LPVOID * ppvOut)
533 {
534     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
535
536     LPSHELLVIEW pShellView;
537     HRESULT hr = E_INVALIDARG;
538
539     TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid),
540      ppvOut);
541
542     if (ppvOut) {
543         *ppvOut = NULL;
544
545         if (IsEqualIID (riid, &IID_IDropTarget)) {
546             hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, ppvOut);
547         } else if (IsEqualIID (riid, &IID_IContextMenu)) {
548             FIXME ("IContextMenu not implemented\n");
549             hr = E_NOTIMPL;
550         } else if (IsEqualIID (riid, &IID_IShellView)) {
551             pShellView = IShellView_Constructor ((IShellFolder *) iface);
552             if (pShellView) {
553                 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
554                 IShellView_Release (pShellView);
555             }
556         }
557     }
558     TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
559     return hr;
560 }
561
562 /**************************************************************************
563 *  IShellFolder_fnGetAttributesOf
564 *
565 * PARAMETERS
566 *  UINT            cidl,     //[in ] num elements in pidl array
567 *  LPCITEMIDLIST*  apidl,    //[in ] simple pidl array
568 *  ULONG*          rgfInOut) //[out] result array
569 *
570 */
571 static HRESULT WINAPI
572 IShellFolder_fnGetAttributesOf (IShellFolder2 * iface, UINT cidl,
573                                 LPCITEMIDLIST * apidl, DWORD * rgfInOut)
574 {
575     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
576
577     HRESULT hr = S_OK;
578
579     TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\n", This, cidl, apidl,
580      rgfInOut, rgfInOut ? *rgfInOut : 0);
581
582     if (!rgfInOut)
583         return E_INVALIDARG;
584     if (cidl && !apidl)
585         return E_INVALIDARG;
586
587     if (*rgfInOut == 0)
588         *rgfInOut = ~0;
589
590     while (cidl > 0 && *apidl) {
591         pdump (*apidl);
592         SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
593         apidl++;
594         cidl--;
595     }
596     /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
597     *rgfInOut &= ~SFGAO_VALIDATE;
598
599     TRACE ("-- result=0x%08lx\n", *rgfInOut);
600
601     return hr;
602 }
603
604 /**************************************************************************
605 *  IShellFolder_fnGetUIObjectOf
606 *
607 * PARAMETERS
608 *  HWND           hwndOwner, //[in ] Parent window for any output
609 *  UINT           cidl,      //[in ] array size
610 *  LPCITEMIDLIST* apidl,     //[in ] simple pidl array
611 *  REFIID         riid,      //[in ] Requested Interface
612 *  UINT*          prgfInOut, //[   ] reserved
613 *  LPVOID*        ppvObject) //[out] Resulting Interface
614 *
615 * NOTES
616 *  This function gets asked to return "view objects" for one or more (multiple
617 *  select) items:
618 *  The viewobject typically is an COM object with one of the following
619 *  interfaces:
620 *  IExtractIcon,IDataObject,IContextMenu
621 *  In order to support icon positions in the default Listview your DataObject
622 *  must implement the SetData method (in addition to GetData :) - the shell
623 *  passes a barely documented "Icon positions" structure to SetData when the
624 *  drag starts, and GetData's it if the drop is in another explorer window that
625 *  needs the positions.
626 */
627 static HRESULT WINAPI
628 IShellFolder_fnGetUIObjectOf (IShellFolder2 * iface,
629                               HWND hwndOwner,
630                               UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
631                               UINT * prgfInOut, LPVOID * ppvOut)
632 {
633     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
634
635     LPITEMIDLIST pidl;
636     IUnknown *pObj = NULL;
637     HRESULT hr = E_INVALIDARG;
638
639     TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
640      This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
641
642     if (ppvOut) {
643         *ppvOut = NULL;
644
645         if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
646             pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface,
647              This->pidlRoot, apidl, cidl);
648             hr = S_OK;
649         } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
650             pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner,
651              This->pidlRoot, apidl, cidl);
652             hr = S_OK;
653         } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
654             pidl = ILCombine (This->pidlRoot, apidl[0]);
655             pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
656             SHFree (pidl);
657             hr = S_OK;
658         } else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1)) {
659             pidl = ILCombine (This->pidlRoot, apidl[0]);
660             pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
661             SHFree (pidl);
662             hr = S_OK;
663         } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
664             hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget,
665              (LPVOID *) & pObj);
666         } else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
667          IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1)) {
668             pidl = ILCombine (This->pidlRoot, apidl[0]);
669             hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
670             SHFree (pidl);
671         } else {
672             hr = E_NOINTERFACE;
673         }
674
675         if (SUCCEEDED(hr) && !pObj)
676             hr = E_OUTOFMEMORY;
677
678         *ppvOut = pObj;
679     }
680     TRACE ("(%p)->hr=0x%08lx\n", This, hr);
681     return hr;
682 }
683
684 static const WCHAR AdvancedW[] = { 'S','O','F','T','W','A','R','E',
685  '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
686  'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
687  'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
688 static const WCHAR HideFileExtW[] = { 'H','i','d','e','F','i','l','e','E','x',
689  't',0 };
690 static const WCHAR NeverShowExtW[] = { 'N','e','v','e','r','S','h','o','w','E',
691  'x','t',0 };
692
693 static BOOL hide_extension(LPWSTR szPath)
694 {
695     HKEY hKey;
696     DWORD dwData;
697     DWORD dwDataSize = sizeof (DWORD);
698     BOOL doHide = FALSE; /* The default value is FALSE (win98 at least) */
699     
700     if (!RegCreateKeyExW(HKEY_CURRENT_USER, AdvancedW, 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0)) {
701         if (!RegQueryValueExW(hKey, HideFileExtW, 0, 0, (LPBYTE) &dwData, &dwDataSize))
702             doHide = dwData;
703         RegCloseKey (hKey);
704     }
705
706     if (!doHide) {
707         LPWSTR ext = PathFindExtensionW(szPath);
708
709         if (*ext != '\0') {
710             WCHAR classname[MAX_PATH];
711             LONG classlen = sizeof(classname);
712
713             if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, classname, &classlen))
714                 if (!RegOpenKeyW(HKEY_CLASSES_ROOT, classname, &hKey)) {
715                     if (!RegQueryValueExW(hKey, NeverShowExtW, 0, NULL, NULL, NULL))
716                         doHide = TRUE;
717                     RegCloseKey(hKey);
718                 }
719         }
720     }
721     return doHide;
722 }
723     
724 void SHELL_FS_ProcessDisplayFilename(LPSTR szPath, DWORD dwFlags)
725 {
726     WCHAR pathW[MAX_PATH];
727
728     /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
729     if (!(dwFlags & SHGDN_FORPARSING) &&
730         ((dwFlags & SHGDN_INFOLDER) || (dwFlags == SHGDN_NORMAL))) {
731         MultiByteToWideChar(CP_ACP, 0, szPath, -1, pathW, MAX_PATH);
732         if (hide_extension(pathW) && szPath[0] != '.')
733             PathRemoveExtensionA (szPath);
734     }
735 }
736
737 /**************************************************************************
738 *  IShellFolder_fnGetDisplayNameOf
739 *  Retrieves the display name for the specified file object or subfolder
740 *
741 * PARAMETERS
742 *  LPCITEMIDLIST pidl,    //[in ] complex pidl to item
743 *  DWORD         dwFlags, //[in ] SHGNO formatting flags
744 *  LPSTRRET      lpName)  //[out] Returned display name
745 *
746 * FIXME
747 *  if the name is in the pidl the ret value should be a STRRET_OFFSET
748 */
749
750 static HRESULT WINAPI
751 IShellFolder_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
752                                  DWORD dwFlags, LPSTRRET strRet)
753 {
754     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
755
756     HRESULT hr = S_OK;
757     int len = 0;
758
759     TRACE ("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
760     pdump (pidl);
761
762     if (!pidl || !strRet)
763         return E_INVALIDARG;
764     
765     strRet->uType = STRRET_CSTR;
766     if (_ILIsDesktop(pidl)) { /* empty pidl */
767         if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
768             (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER)) 
769         {
770             if (This->sPathTarget)
771                 lstrcpynA(strRet->u.cStr, This->sPathTarget, MAX_PATH);
772         } else {
773             /* pidl has to contain exactly one non null SHITEMID */
774             hr = E_INVALIDARG;
775         }
776     } else if (_ILIsPidlSimple(pidl)) {
777         if ((GET_SHGDN_FOR(dwFlags) == SHGDN_FORPARSING) &&
778             (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER) && 
779             This->sPathTarget) 
780         {
781             lstrcpynA(strRet->u.cStr, This->sPathTarget, MAX_PATH);
782             PathAddBackslashA(strRet->u.cStr);
783             len = lstrlenA(strRet->u.cStr);
784         }
785         _ILSimpleGetText(pidl, strRet->u.cStr + len, MAX_PATH - len);
786         if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(strRet->u.cStr, dwFlags);
787     } else {
788         hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, strRet->u.cStr, MAX_PATH);
789     }
790
791     TRACE ("-- (%p)->(%s)\n", This, strRet->u.cStr);
792     return hr;
793 }
794
795 /**************************************************************************
796 *  IShellFolder_fnSetNameOf
797 *  Changes the name of a file object or subfolder, possibly changing its item
798 *  identifier in the process.
799 *
800 * PARAMETERS
801 *  HWND          hwndOwner,  //[in ] Owner window for output
802 *  LPCITEMIDLIST pidl,       //[in ] simple pidl of item to change
803 *  LPCOLESTR     lpszName,   //[in ] the items new display name
804 *  DWORD         dwFlags,    //[in ] SHGNO formatting flags
805 *  LPITEMIDLIST* ppidlOut)   //[out] simple pidl returned
806 */
807 static HRESULT WINAPI IShellFolder_fnSetNameOf (IShellFolder2 * iface,
808                                                 HWND hwndOwner,
809                                                 LPCITEMIDLIST pidl,
810                                                 LPCOLESTR lpName,
811                                                 DWORD dwFlags,
812                                                 LPITEMIDLIST * pPidlOut)
813 {
814     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
815     WCHAR szSrc[MAX_PATH], szDest[MAX_PATH];
816     LPWSTR ptr;
817     BOOL bIsFolder = _ILIsFolder (ILFindLastID (pidl));
818
819     TRACE ("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl,
820      debugstr_w (lpName), dwFlags, pPidlOut);
821
822     /* build source path */
823     MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, szSrc, MAX_PATH);
824     ptr = PathAddBackslashW (szSrc);
825     if (ptr)
826         _ILSimpleGetTextW (pidl, ptr, MAX_PATH - (ptr - szSrc));
827
828     /* build destination path */
829     if (dwFlags == SHGDN_NORMAL || dwFlags & SHGDN_INFOLDER) {
830         MultiByteToWideChar(CP_ACP, 0, This->sPathTarget, -1, szDest, MAX_PATH);
831         ptr = PathAddBackslashW (szDest);
832         if (ptr)
833             lstrcpynW(ptr, lpName, MAX_PATH - (ptr - szDest));
834     } else
835         lstrcpynW(szDest, lpName, MAX_PATH);
836
837     if(!(dwFlags & SHGDN_FORPARSING) && hide_extension(szSrc)) {
838         WCHAR *ext = PathFindExtensionW(szSrc);
839         if(*ext != '\0') {
840             INT len = strlenW(szDest);
841             lstrcpynW(szDest + len, ext, MAX_PATH - len);
842         }
843     }
844     
845     TRACE ("src=%s dest=%s\n", debugstr_w(szSrc), debugstr_w(szDest));
846
847     if (MoveFileW (szSrc, szDest)) {
848         HRESULT hr = S_OK;
849
850         if (pPidlOut)
851             hr = _ILCreateFromPathW(szDest, pPidlOut);
852
853         SHChangeNotify (bIsFolder ? SHCNE_RENAMEFOLDER : SHCNE_RENAMEITEM,
854          SHCNF_PATHW, szSrc, szDest);
855
856         return hr;
857     }
858
859     return E_FAIL;
860 }
861
862 static HRESULT WINAPI IShellFolder_fnGetDefaultSearchGUID (IShellFolder2 *iface,
863                                                            GUID * pguid)
864 {
865     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
866     FIXME ("(%p)\n", This);
867     return E_NOTIMPL;
868 }
869 static HRESULT WINAPI IShellFolder_fnEnumSearches (IShellFolder2 * iface,
870                                                    IEnumExtraSearch ** ppenum)
871 {
872     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
873     FIXME ("(%p)\n", This);
874     return E_NOTIMPL;
875 }
876
877 static HRESULT WINAPI
878 IShellFolder_fnGetDefaultColumn (IShellFolder2 * iface, DWORD dwRes,
879                                  ULONG * pSort, ULONG * pDisplay)
880 {
881     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
882
883     TRACE ("(%p)\n", This);
884
885     if (pSort)
886         *pSort = 0;
887     if (pDisplay)
888         *pDisplay = 0;
889
890     return S_OK;
891 }
892
893 static HRESULT WINAPI
894 IShellFolder_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn,
895                                       DWORD * pcsFlags)
896 {
897     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
898
899     TRACE ("(%p)\n", This);
900
901     if (!pcsFlags || iColumn >= GENERICSHELLVIEWCOLUMNS)
902         return E_INVALIDARG;
903
904     *pcsFlags = GenericSFHeader[iColumn].pcsFlags;
905
906     return S_OK;
907 }
908
909 static HRESULT WINAPI
910 IShellFolder_fnGetDetailsEx (IShellFolder2 * iface, LPCITEMIDLIST pidl,
911                              const SHCOLUMNID * pscid, VARIANT * pv)
912 {
913     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
914     FIXME ("(%p)\n", This);
915
916     return E_NOTIMPL;
917 }
918
919 static HRESULT WINAPI
920 IShellFolder_fnGetDetailsOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
921                              UINT iColumn, SHELLDETAILS * psd)
922 {
923     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
924     HRESULT hr = E_FAIL;
925
926     TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
927
928     if (!psd || iColumn >= GENERICSHELLVIEWCOLUMNS)
929         return E_INVALIDARG;
930
931     if (!pidl) {
932         /* the header titles */
933         psd->fmt = GenericSFHeader[iColumn].fmt;
934         psd->cxChar = GenericSFHeader[iColumn].cxChar;
935         psd->str.uType = STRRET_CSTR;
936         LoadStringA (shell32_hInstance, GenericSFHeader[iColumn].colnameid,
937          psd->str.u.cStr, MAX_PATH);
938         return S_OK;
939     } else {
940         /* the data from the pidl */
941         switch (iColumn) {
942         case 0:                /* name */
943             hr = IShellFolder_GetDisplayNameOf (iface, pidl,
944              SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
945             break;
946         case 1:                /* size */
947             _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
948             break;
949         case 2:                /* type */
950             _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
951             break;
952         case 3:                /* date */
953             _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
954             break;
955         case 4:                /* attributes */
956             _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
957             break;
958         }
959         hr = S_OK;
960         psd->str.uType = STRRET_CSTR;
961     }
962
963     return hr;
964 }
965
966 static HRESULT WINAPI
967 IShellFolder_fnMapColumnToSCID (IShellFolder2 * iface, UINT column,
968                                 SHCOLUMNID * pscid)
969 {
970     _ICOM_THIS_From_IShellFolder2 (IGenericSFImpl, iface)
971     FIXME ("(%p)\n", This);
972     return E_NOTIMPL;
973 }
974
975 static IShellFolder2Vtbl sfvt =
976 {
977     IShellFolder_fnQueryInterface,
978     IShellFolder_fnAddRef,
979     IShellFolder_fnRelease,
980     IShellFolder_fnParseDisplayName,
981     IShellFolder_fnEnumObjects,
982     IShellFolder_fnBindToObject,
983     IShellFolder_fnBindToStorage,
984     IShellFolder_fnCompareIDs,
985     IShellFolder_fnCreateViewObject,
986     IShellFolder_fnGetAttributesOf,
987     IShellFolder_fnGetUIObjectOf,
988     IShellFolder_fnGetDisplayNameOf,
989     IShellFolder_fnSetNameOf,
990     /* ShellFolder2 */
991     IShellFolder_fnGetDefaultSearchGUID,
992     IShellFolder_fnEnumSearches,
993     IShellFolder_fnGetDefaultColumn,
994     IShellFolder_fnGetDefaultColumnState,
995     IShellFolder_fnGetDetailsEx,
996     IShellFolder_fnGetDetailsOf,
997     IShellFolder_fnMapColumnToSCID
998 };
999
1000 /****************************************************************************
1001  * ISFHelper for IShellFolder implementation
1002  */
1003
1004 static HRESULT WINAPI
1005 ISFHelper_fnQueryInterface (ISFHelper * iface, REFIID riid, LPVOID * ppvObj)
1006 {
1007     _ICOM_THIS_From_ISFHelper (IGenericSFImpl, iface);
1008
1009     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
1010
1011     return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
1012 }
1013
1014 static ULONG WINAPI ISFHelper_fnAddRef (ISFHelper * iface)
1015 {
1016     _ICOM_THIS_From_ISFHelper (IGenericSFImpl, iface);
1017
1018     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
1019
1020     return IUnknown_AddRef (This->pUnkOuter);
1021 }
1022
1023 static ULONG WINAPI ISFHelper_fnRelease (ISFHelper * iface)
1024 {
1025     _ICOM_THIS_From_ISFHelper (IGenericSFImpl, iface);
1026
1027     TRACE ("(%p)\n", This);
1028
1029     return IUnknown_Release (This->pUnkOuter);
1030 }
1031
1032 /****************************************************************************
1033  * ISFHelper_fnAddFolder
1034  *
1035  * creates a unique folder name
1036  */
1037
1038 static HRESULT WINAPI
1039 ISFHelper_fnGetUniqueName (ISFHelper * iface, LPSTR lpName, UINT uLen)
1040 {
1041     _ICOM_THIS_From_ISFHelper (IGenericSFImpl, iface)
1042     IEnumIDList *penum;
1043     HRESULT hr;
1044     char szText[MAX_PATH];
1045     char *szNewFolder = "New Folder";
1046
1047     TRACE ("(%p)(%s %u)\n", This, lpName, uLen);
1048
1049     if (uLen < strlen (szNewFolder) + 4)
1050         return E_POINTER;
1051
1052     strcpy (lpName, szNewFolder);
1053
1054     hr = IShellFolder_fnEnumObjects (_IShellFolder2_ (This), 0,
1055      SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &penum);
1056     if (penum) {
1057         LPITEMIDLIST pidl;
1058         DWORD dwFetched;
1059         int i = 1;
1060
1061 next:
1062         IEnumIDList_Reset (penum);
1063         while (S_OK == IEnumIDList_Next (penum, 1, &pidl, &dwFetched) &&
1064          dwFetched) {
1065             _ILSimpleGetText (pidl, szText, MAX_PATH);
1066             if (0 == strcasecmp (szText, lpName)) {
1067                 sprintf (lpName, "%s %d", szNewFolder, i++);
1068                 if (i > 99) {
1069                     hr = E_FAIL;
1070                     break;
1071                 }
1072                 goto next;
1073             }
1074         }
1075
1076         IEnumIDList_Release (penum);
1077     }
1078     return hr;
1079 }
1080
1081 /****************************************************************************
1082  * ISFHelper_fnAddFolder
1083  *
1084  * adds a new folder.
1085  */
1086
1087 static HRESULT WINAPI
1088 ISFHelper_fnAddFolder (ISFHelper * iface, HWND hwnd, LPCSTR lpName,
1089                        LPITEMIDLIST * ppidlOut)
1090 {
1091     _ICOM_THIS_From_ISFHelper (IGenericSFImpl, iface)
1092     char lpstrNewDir[MAX_PATH];
1093     DWORD bRes;
1094     HRESULT hres = E_FAIL;
1095
1096     TRACE ("(%p)(%s %p)\n", This, lpName, ppidlOut);
1097
1098     strcpy (lpstrNewDir, This->sPathTarget);
1099     PathAppendA(lpstrNewDir, lpName);
1100
1101     bRes = CreateDirectoryA (lpstrNewDir, NULL);
1102     if (bRes) {
1103         SHChangeNotify (SHCNE_MKDIR, SHCNF_PATHA, lpstrNewDir, NULL);
1104
1105         hres = S_OK;
1106
1107         if (ppidlOut)
1108                 hres = _ILCreateFromPathA(lpstrNewDir, ppidlOut);
1109     } else {
1110         char lpstrText[128 + MAX_PATH];
1111         char lpstrTempText[128];
1112         char lpstrCaption[256];
1113
1114         /* Cannot Create folder because of permissions */
1115         LoadStringA (shell32_hInstance, IDS_CREATEFOLDER_DENIED, lpstrTempText,
1116          sizeof (lpstrTempText));
1117         LoadStringA (shell32_hInstance, IDS_CREATEFOLDER_CAPTION, lpstrCaption,
1118          sizeof (lpstrCaption));
1119         sprintf (lpstrText, lpstrTempText, lpstrNewDir);
1120         MessageBoxA (hwnd, lpstrText, lpstrCaption, MB_OK | MB_ICONEXCLAMATION);
1121     }
1122
1123     return hres;
1124 }
1125
1126 /****************************************************************************
1127  * ISFHelper_fnDeleteItems
1128  *
1129  * deletes items in folder
1130  */
1131 static HRESULT WINAPI
1132 ISFHelper_fnDeleteItems (ISFHelper * iface, UINT cidl, LPCITEMIDLIST * apidl)
1133 {
1134     _ICOM_THIS_From_ISFHelper (IGenericSFImpl, iface)
1135     UINT i;
1136     char szPath[MAX_PATH];
1137     BOOL bConfirm = TRUE;
1138
1139     TRACE ("(%p)(%u %p)\n", This, cidl, apidl);
1140
1141     /* deleting multiple items so give a slightly different warning */
1142     if (cidl != 1) {
1143         char tmp[8];
1144
1145         snprintf (tmp, sizeof (tmp), "%d", cidl);
1146         if (!SHELL_ConfirmDialog(ASK_DELETE_MULTIPLE_ITEM, tmp))
1147             return E_FAIL;
1148         bConfirm = FALSE;
1149     }
1150
1151     for (i = 0; i < cidl; i++) {
1152         strcpy (szPath, This->sPathTarget);
1153         PathAddBackslashA (szPath);
1154         _ILSimpleGetText (apidl[i], szPath + strlen (szPath), MAX_PATH);
1155
1156         if (_ILIsFolder (apidl[i])) {
1157             LPITEMIDLIST pidl;
1158
1159             TRACE ("delete %s\n", szPath);
1160             if (!SHELL_DeleteDirectoryA (szPath, bConfirm)) {
1161                 TRACE ("delete %s failed, bConfirm=%d\n", szPath, bConfirm);
1162                 return E_FAIL;
1163             }
1164             pidl = ILCombine (This->pidlRoot, apidl[i]);
1165             SHChangeNotify (SHCNE_RMDIR, SHCNF_IDLIST, pidl, NULL);
1166             SHFree (pidl);
1167         } else if (_ILIsValue (apidl[i])) {
1168             LPITEMIDLIST pidl;
1169
1170             TRACE ("delete %s\n", szPath);
1171             if (!SHELL_DeleteFileA (szPath, bConfirm)) {
1172                 TRACE ("delete %s failed, bConfirm=%d\n", szPath, bConfirm);
1173                 return E_FAIL;
1174             }
1175             pidl = ILCombine (This->pidlRoot, apidl[i]);
1176             SHChangeNotify (SHCNE_DELETE, SHCNF_IDLIST, pidl, NULL);
1177             SHFree (pidl);
1178         }
1179
1180     }
1181     return S_OK;
1182 }
1183
1184 /****************************************************************************
1185  * ISFHelper_fnCopyItems
1186  *
1187  * copies items to this folder
1188  */
1189 static HRESULT WINAPI
1190 ISFHelper_fnCopyItems (ISFHelper * iface, IShellFolder * pSFFrom, UINT cidl,
1191                        LPCITEMIDLIST * apidl)
1192 {
1193     UINT i;
1194     IPersistFolder2 *ppf2 = NULL;
1195     char szSrcPath[MAX_PATH],
1196       szDstPath[MAX_PATH];
1197
1198     _ICOM_THIS_From_ISFHelper (IGenericSFImpl, iface);
1199
1200     TRACE ("(%p)->(%p,%u,%p)\n", This, pSFFrom, cidl, apidl);
1201
1202     IShellFolder_QueryInterface (pSFFrom, &IID_IPersistFolder2,
1203      (LPVOID *) & ppf2);
1204     if (ppf2) {
1205         LPITEMIDLIST pidl;
1206
1207         if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2, &pidl))) {
1208             for (i = 0; i < cidl; i++) {
1209                 SHGetPathFromIDListA (pidl, szSrcPath);
1210                 PathAddBackslashA (szSrcPath);
1211                 _ILSimpleGetText (apidl[i], szSrcPath + strlen (szSrcPath),
1212                  MAX_PATH);
1213
1214                 strcpy (szDstPath, This->sPathTarget);
1215                 PathAddBackslashA (szDstPath);
1216                 _ILSimpleGetText (apidl[i], szDstPath + strlen (szDstPath),
1217                  MAX_PATH);
1218                 MESSAGE ("would copy %s to %s\n", szSrcPath, szDstPath);
1219             }
1220             SHFree (pidl);
1221         }
1222         IPersistFolder2_Release (ppf2);
1223     }
1224     return S_OK;
1225 }
1226
1227 static ISFHelperVtbl shvt =
1228 {
1229     ISFHelper_fnQueryInterface,
1230     ISFHelper_fnAddRef,
1231     ISFHelper_fnRelease,
1232     ISFHelper_fnGetUniqueName,
1233     ISFHelper_fnAddFolder,
1234     ISFHelper_fnDeleteItems,
1235     ISFHelper_fnCopyItems
1236 };
1237
1238 /************************************************************************
1239  * IFSFldr_PersistFolder3_QueryInterface
1240  *
1241  */
1242 static HRESULT WINAPI
1243 IFSFldr_PersistFolder3_QueryInterface (IPersistFolder3 * iface, REFIID iid,
1244                                        LPVOID * ppvObj)
1245 {
1246     _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl, iface);
1247
1248     TRACE ("(%p)\n", This);
1249
1250     return IUnknown_QueryInterface (This->pUnkOuter, iid, ppvObj);
1251 }
1252
1253 /************************************************************************
1254  * IFSFldr_PersistFolder3_AddRef
1255  *
1256  */
1257 static ULONG WINAPI
1258 IFSFldr_PersistFolder3_AddRef (IPersistFolder3 * iface)
1259 {
1260     _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl, iface);
1261
1262     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
1263
1264     return IUnknown_AddRef (This->pUnkOuter);
1265 }
1266
1267 /************************************************************************
1268  * IFSFldr_PersistFolder3_Release
1269  *
1270  */
1271 static ULONG WINAPI
1272 IFSFldr_PersistFolder3_Release (IPersistFolder3 * iface)
1273 {
1274     _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl, iface);
1275
1276     TRACE ("(%p)->(count=%lu)\n", This, This->ref);
1277
1278     return IUnknown_Release (This->pUnkOuter);
1279 }
1280
1281 /************************************************************************
1282  * IFSFldr_PersistFolder3_GetClassID
1283  */
1284 static HRESULT WINAPI
1285 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3 * iface, CLSID * lpClassId)
1286 {
1287     _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl, iface);
1288
1289     TRACE ("(%p)\n", This);
1290
1291     if (!lpClassId)
1292         return E_POINTER;
1293     *lpClassId = *This->pclsid;
1294
1295     return S_OK;
1296 }
1297
1298 /************************************************************************
1299  * IFSFldr_PersistFolder3_Initialize
1300  *
1301  * NOTES
1302  *  sPathTarget is not set. Don't know how to handle in a non rooted environment.
1303  */
1304 static HRESULT WINAPI
1305 IFSFldr_PersistFolder3_Initialize (IPersistFolder3 * iface, LPCITEMIDLIST pidl)
1306 {
1307     char sTemp[MAX_PATH];
1308
1309     _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl, iface);
1310
1311     TRACE ("(%p)->(%p)\n", This, pidl);
1312
1313     if (This->pidlRoot)
1314         SHFree (This->pidlRoot);     /* free the old pidl */
1315     This->pidlRoot = ILClone (pidl); /* set my pidl */
1316
1317     if (This->sPathTarget)
1318         SHFree (This->sPathTarget);
1319
1320     /* set my path */
1321     if (SHGetPathFromIDListA (pidl, sTemp)) {
1322         This->sPathTarget = SHAlloc (strlen (sTemp) + 1);
1323         strcpy (This->sPathTarget, sTemp);
1324     }
1325
1326     TRACE ("--(%p)->(%s)\n", This, This->sPathTarget);
1327     return S_OK;
1328 }
1329
1330 /**************************************************************************
1331  * IFSFldr_PersistFolder3_GetCurFolder
1332  */
1333 static HRESULT WINAPI
1334 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3 * iface,
1335                                        LPITEMIDLIST * pidl)
1336 {
1337     _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl, iface);
1338
1339     TRACE ("(%p)->(%p)\n", This, pidl);
1340
1341     if (!pidl) return E_POINTER;
1342     *pidl = ILClone (This->pidlRoot);
1343     return S_OK;
1344 }
1345
1346 /**************************************************************************
1347  * IFSFldr_PersistFolder3_InitializeEx
1348  *
1349  * FIXME: error handling
1350  */
1351 static HRESULT WINAPI
1352 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3 * iface,
1353                                      IBindCtx * pbc, LPCITEMIDLIST pidlRoot,
1354                                      const PERSIST_FOLDER_TARGET_INFO * ppfti)
1355 {
1356     char sTemp[MAX_PATH];
1357
1358     _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl, iface);
1359
1360     TRACE ("(%p)->(%p,%p,%p)\n", This, pbc, pidlRoot, ppfti);
1361     if (ppfti)
1362         TRACE ("--%p %s %s 0x%08lx 0x%08x\n",
1363          ppfti->pidlTargetFolder, debugstr_w (ppfti->szTargetParsingName),
1364          debugstr_w (ppfti->szNetworkProvider), ppfti->dwAttributes,
1365          ppfti->csidl);
1366
1367     pdump (pidlRoot);
1368     if (ppfti && ppfti->pidlTargetFolder)
1369         pdump (ppfti->pidlTargetFolder);
1370
1371     if (This->pidlRoot)
1372         __SHFreeAndNil (&This->pidlRoot);    /* free the old */
1373     if (This->sPathTarget)
1374         __SHFreeAndNil (&This->sPathTarget);
1375
1376     /*
1377      * Root path and pidl
1378      */
1379     This->pidlRoot = ILClone (pidlRoot);
1380
1381     /*
1382      *  the target folder is spezified in csidl OR pidlTargetFolder OR
1383      *  szTargetParsingName
1384      */
1385     if (ppfti) {
1386         if (ppfti->csidl != -1) {
1387             if (SHGetSpecialFolderPathA (0, sTemp, ppfti->csidl,
1388              ppfti->csidl & CSIDL_FLAG_CREATE)) {
1389                 __SHCloneStrA (&This->sPathTarget, sTemp);
1390             }
1391         } else if (ppfti->szTargetParsingName[0]) {
1392             __SHCloneStrWtoA (&This->sPathTarget, ppfti->szTargetParsingName);
1393         } else if (ppfti->pidlTargetFolder) {
1394             if (SHGetPathFromIDListA (ppfti->pidlTargetFolder, sTemp)) {
1395                 __SHCloneStrA (&This->sPathTarget, sTemp);
1396             }
1397         }
1398     }
1399
1400     TRACE ("--(%p)->(target=%s)\n", This, debugstr_a (This->sPathTarget));
1401     pdump (This->pidlRoot);
1402     return (This->sPathTarget) ? S_OK : E_FAIL;
1403 }
1404
1405 static HRESULT WINAPI
1406 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3 * iface,
1407                                             PERSIST_FOLDER_TARGET_INFO * ppfti)
1408 {
1409     _ICOM_THIS_From_IPersistFolder3 (IGenericSFImpl, iface);
1410     FIXME ("(%p)->(%p)\n", This, ppfti);
1411     ZeroMemory (ppfti, sizeof (ppfti));
1412     return E_NOTIMPL;
1413 }
1414
1415 static IPersistFolder3Vtbl vt_FSFldr_PersistFolder3 =
1416 {
1417     IFSFldr_PersistFolder3_QueryInterface,
1418     IFSFldr_PersistFolder3_AddRef,
1419     IFSFldr_PersistFolder3_Release,
1420     IFSFldr_PersistFolder3_GetClassID,
1421     IFSFldr_PersistFolder3_Initialize,
1422     IFSFldr_PersistFolder3_fnGetCurFolder,
1423     IFSFldr_PersistFolder3_InitializeEx,
1424     IFSFldr_PersistFolder3_GetFolderTargetInfo
1425 };
1426
1427 /****************************************************************************
1428  * ISFDropTarget implementation
1429  */
1430 static BOOL
1431 ISFDropTarget_QueryDrop (IDropTarget * iface, DWORD dwKeyState,
1432                          LPDWORD pdwEffect)
1433 {
1434     DWORD dwEffect = *pdwEffect;
1435
1436     _ICOM_THIS_From_IDropTarget (IGenericSFImpl, iface);
1437
1438     *pdwEffect = DROPEFFECT_NONE;
1439
1440     if (This->fAcceptFmt) { /* Does our interpretation of the keystate ... */
1441         *pdwEffect = KeyStateToDropEffect (dwKeyState);
1442
1443         /* ... matches the desired effect ? */
1444         if (dwEffect & *pdwEffect) {
1445             return TRUE;
1446         }
1447     }
1448     return FALSE;
1449 }
1450
1451 static HRESULT WINAPI
1452 ISFDropTarget_QueryInterface (IDropTarget * iface, REFIID riid, LPVOID * ppvObj)
1453 {
1454     _ICOM_THIS_From_IDropTarget (IGenericSFImpl, iface);
1455
1456     TRACE ("(%p)\n", This);
1457
1458     return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
1459 }
1460
1461 static ULONG WINAPI ISFDropTarget_AddRef (IDropTarget * iface)
1462 {
1463     _ICOM_THIS_From_IDropTarget (IGenericSFImpl, iface);
1464
1465     TRACE ("(%p)\n", This);
1466
1467     return IUnknown_AddRef (This->pUnkOuter);
1468 }
1469
1470 static ULONG WINAPI ISFDropTarget_Release (IDropTarget * iface)
1471 {
1472     _ICOM_THIS_From_IDropTarget (IGenericSFImpl, iface);
1473
1474     TRACE ("(%p)\n", This);
1475
1476     return IUnknown_Release (This->pUnkOuter);
1477 }
1478
1479 static HRESULT WINAPI
1480 ISFDropTarget_DragEnter (IDropTarget * iface, IDataObject * pDataObject,
1481                          DWORD dwKeyState, POINTL pt, DWORD * pdwEffect)
1482 {
1483     FORMATETC fmt;
1484
1485     _ICOM_THIS_From_IDropTarget (IGenericSFImpl, iface);
1486
1487     TRACE ("(%p)->(DataObject=%p)\n", This, pDataObject);
1488
1489     InitFormatEtc (fmt, This->cfShellIDList, TYMED_HGLOBAL);
1490
1491     This->fAcceptFmt = (S_OK == IDataObject_QueryGetData (pDataObject, &fmt)) ?
1492      TRUE : FALSE;
1493
1494     ISFDropTarget_QueryDrop (iface, dwKeyState, pdwEffect);
1495
1496     return S_OK;
1497 }
1498
1499 static HRESULT WINAPI
1500 ISFDropTarget_DragOver (IDropTarget * iface, DWORD dwKeyState, POINTL pt,
1501                         DWORD * pdwEffect)
1502 {
1503     _ICOM_THIS_From_IDropTarget (IGenericSFImpl, iface);
1504
1505     TRACE ("(%p)\n", This);
1506
1507     if (!pdwEffect)
1508         return E_INVALIDARG;
1509
1510     ISFDropTarget_QueryDrop (iface, dwKeyState, pdwEffect);
1511
1512     return S_OK;
1513 }
1514
1515 static HRESULT WINAPI ISFDropTarget_DragLeave (IDropTarget * iface)
1516 {
1517     _ICOM_THIS_From_IDropTarget (IGenericSFImpl, iface);
1518
1519     TRACE ("(%p)\n", This);
1520
1521     This->fAcceptFmt = FALSE;
1522
1523     return S_OK;
1524 }
1525
1526 static HRESULT WINAPI
1527 ISFDropTarget_Drop (IDropTarget * iface, IDataObject * pDataObject,
1528                     DWORD dwKeyState, POINTL pt, DWORD * pdwEffect)
1529 {
1530     _ICOM_THIS_From_IDropTarget (IGenericSFImpl, iface);
1531
1532     FIXME ("(%p) object dropped\n", This);
1533
1534     return E_NOTIMPL;
1535 }
1536
1537 static struct IDropTargetVtbl dtvt = {
1538     ISFDropTarget_QueryInterface,
1539     ISFDropTarget_AddRef,
1540     ISFDropTarget_Release,
1541     ISFDropTarget_DragEnter,
1542     ISFDropTarget_DragOver,
1543     ISFDropTarget_DragLeave,
1544     ISFDropTarget_Drop
1545 };