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