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