wined3d: Print lastpixel state fixme only once.
[wine/hacks.git] / dlls / shell32 / shfldr_fs.c
blob5fda4af321d0fcaf07e51981cfa51c1bda115ef9
2 /*
3 * file system folder
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998, 1999, 2002 Juergen Schmied
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdio.h>
31 #define COBJMACROS
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
35 #include "winerror.h"
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winreg.h"
39 #include "wingdi.h"
40 #include "winuser.h"
42 #include "ole2.h"
43 #include "shlguid.h"
45 #include "enumidlist.h"
46 #include "pidl.h"
47 #include "undocshell.h"
48 #include "shell32_main.h"
49 #include "shresdef.h"
50 #include "shlwapi.h"
51 #include "shellfolder.h"
52 #include "wine/debug.h"
53 #include "debughlp.h"
54 #include "shfldr.h"
56 WINE_DEFAULT_DEBUG_CHANNEL (shell);
58 /***********************************************************************
59 * IShellFolder implementation
62 typedef struct {
63 const IUnknownVtbl *lpVtbl;
64 LONG ref;
65 const IShellFolder2Vtbl *lpvtblShellFolder;
66 const IPersistFolder3Vtbl *lpvtblPersistFolder3;
67 const IDropTargetVtbl *lpvtblDropTarget;
68 const ISFHelperVtbl *lpvtblSFHelper;
70 IUnknown *pUnkOuter; /* used for aggregation */
72 CLSID *pclsid;
74 /* both paths are parsible from the desktop */
75 LPWSTR sPathTarget; /* complete path to target used for enumeration and ChangeNotify */
77 LPITEMIDLIST pidlRoot; /* absolute pidl */
79 UINT cfShellIDList; /* clipboardformat for IDropTarget */
80 BOOL fAcceptFmt; /* flag for pending Drop */
81 } IGenericSFImpl;
83 static const IUnknownVtbl unkvt;
84 static const IShellFolder2Vtbl sfvt;
85 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3; /* IPersistFolder3 for a FS_Folder */
86 static const IDropTargetVtbl dtvt;
87 static const ISFHelperVtbl shvt;
89 static inline IGenericSFImpl *impl_from_IShellFolder2( IShellFolder2 *iface )
91 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblShellFolder));
94 static inline IGenericSFImpl *impl_from_IPersistFolder3( IPersistFolder3 *iface )
96 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblPersistFolder3));
99 static inline IGenericSFImpl *impl_from_IDropTarget( IDropTarget *iface )
101 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblDropTarget));
104 static inline IGenericSFImpl *impl_from_ISFHelper( ISFHelper *iface )
106 return (IGenericSFImpl *)((char*)iface - FIELD_OFFSET(IGenericSFImpl, lpvtblSFHelper));
111 converts This to an interface pointer
113 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
114 #define _IShellFolder_(This) (IShellFolder*)&(This->lpvtblShellFolder)
115 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpvtblShellFolder)
116 #define _IPersist_(This) (IPersist*)&(This->lpvtblPersistFolder3)
117 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpvtblPersistFolder3)
118 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpvtblPersistFolder3)
119 #define _IPersistFolder3_(This) (IPersistFolder3*)&(This->lpvtblPersistFolder3)
120 #define _IDropTarget_(This) (IDropTarget*)&(This->lpvtblDropTarget)
121 #define _ISFHelper_(This) (ISFHelper*)&(This->lpvtblSFHelper)
123 /**************************************************************************
124 * registers clipboardformat once
126 static void SF_RegisterClipFmt (IGenericSFImpl * This)
128 TRACE ("(%p)\n", This);
130 if (!This->cfShellIDList) {
131 This->cfShellIDList = RegisterClipboardFormatA (CFSTR_SHELLIDLIST);
135 /**************************************************************************
136 * we need a separate IUnknown to handle aggregation
137 * (inner IUnknown)
139 static HRESULT WINAPI IUnknown_fnQueryInterface (IUnknown * iface, REFIID riid, LPVOID * ppvObj)
141 IGenericSFImpl *This = (IGenericSFImpl *)iface;
143 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
145 *ppvObj = NULL;
147 if (IsEqualIID (riid, &IID_IUnknown))
148 *ppvObj = _IUnknown_ (This);
149 else if (IsEqualIID (riid, &IID_IShellFolder))
150 *ppvObj = _IShellFolder_ (This);
151 else if (IsEqualIID (riid, &IID_IShellFolder2))
152 *ppvObj = _IShellFolder_ (This);
153 else if (IsEqualIID (riid, &IID_IPersist))
154 *ppvObj = _IPersist_ (This);
155 else if (IsEqualIID (riid, &IID_IPersistFolder))
156 *ppvObj = _IPersistFolder_ (This);
157 else if (IsEqualIID (riid, &IID_IPersistFolder2))
158 *ppvObj = _IPersistFolder2_ (This);
159 else if (IsEqualIID (riid, &IID_IPersistFolder3))
160 *ppvObj = _IPersistFolder3_ (This);
161 else if (IsEqualIID (riid, &IID_ISFHelper))
162 *ppvObj = _ISFHelper_ (This);
163 else if (IsEqualIID (riid, &IID_IDropTarget)) {
164 *ppvObj = _IDropTarget_ (This);
165 SF_RegisterClipFmt (This);
168 if (*ppvObj) {
169 IUnknown_AddRef ((IUnknown *) (*ppvObj));
170 TRACE ("-- Interface = %p\n", *ppvObj);
171 return S_OK;
173 TRACE ("-- Interface: E_NOINTERFACE\n");
174 return E_NOINTERFACE;
177 static ULONG WINAPI IUnknown_fnAddRef (IUnknown * iface)
179 IGenericSFImpl *This = (IGenericSFImpl *)iface;
180 ULONG refCount = InterlockedIncrement(&This->ref);
182 TRACE ("(%p)->(count=%u)\n", This, refCount - 1);
184 return refCount;
187 static ULONG WINAPI IUnknown_fnRelease (IUnknown * iface)
189 IGenericSFImpl *This = (IGenericSFImpl *)iface;
190 ULONG refCount = InterlockedDecrement(&This->ref);
192 TRACE ("(%p)->(count=%u)\n", This, refCount + 1);
194 if (!refCount) {
195 TRACE ("-- destroying IShellFolder(%p)\n", This);
197 SHFree (This->pidlRoot);
198 SHFree (This->sPathTarget);
199 LocalFree ((HLOCAL) This);
201 return refCount;
204 static const IUnknownVtbl unkvt =
206 IUnknown_fnQueryInterface,
207 IUnknown_fnAddRef,
208 IUnknown_fnRelease,
211 static const shvheader GenericSFHeader[] = {
212 {IDS_SHV_COLUMN1, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},
213 {IDS_SHV_COLUMN2, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
214 {IDS_SHV_COLUMN3, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 10},
215 {IDS_SHV_COLUMN4, SHCOLSTATE_TYPE_DATE | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 12},
216 {IDS_SHV_COLUMN5, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 5}
219 #define GENERICSHELLVIEWCOLUMNS 5
221 /**************************************************************************
222 * IFSFolder_Constructor
224 * NOTES
225 * creating undocumented ShellFS_Folder as part of an aggregation
226 * {F3364BA0-65B9-11CE-A9BA-00AA004AE837}
229 HRESULT WINAPI
230 IFSFolder_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
232 IGenericSFImpl *sf;
234 TRACE ("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid (riid));
236 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
237 return CLASS_E_NOAGGREGATION;
238 sf = (IGenericSFImpl *) LocalAlloc (LMEM_ZEROINIT, sizeof (IGenericSFImpl));
239 if (!sf)
240 return E_OUTOFMEMORY;
242 sf->ref = 0;
243 sf->lpVtbl = &unkvt;
244 sf->lpvtblShellFolder = &sfvt;
245 sf->lpvtblPersistFolder3 = &vt_FSFldr_PersistFolder3;
246 sf->lpvtblDropTarget = &dtvt;
247 sf->lpvtblSFHelper = &shvt;
248 sf->pclsid = (CLSID *) & CLSID_ShellFSFolder;
249 sf->pUnkOuter = pUnkOuter ? pUnkOuter : _IUnknown_ (sf);
251 if (!SUCCEEDED (IUnknown_QueryInterface (_IUnknown_ (sf), riid, ppv))) {
252 IUnknown_Release (_IUnknown_ (sf));
253 return E_NOINTERFACE;
256 TRACE ("--%p\n", *ppv);
257 return S_OK;
260 /**************************************************************************
261 * IShellFolder_fnQueryInterface
263 * PARAMETERS
264 * REFIID riid [in ] Requested InterfaceID
265 * LPVOID* ppvObject [out] Interface* to hold the result
267 static HRESULT WINAPI
268 IShellFolder_fnQueryInterface (IShellFolder2 * iface, REFIID riid,
269 LPVOID * ppvObj)
271 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
273 TRACE ("(%p)->(%s,%p)\n", This, shdebugstr_guid (riid), ppvObj);
275 return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
278 /**************************************************************************
279 * IShellFolder_AddRef
282 static ULONG WINAPI IShellFolder_fnAddRef (IShellFolder2 * iface)
284 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
286 TRACE ("(%p)->(count=%u)\n", This, This->ref);
288 return IUnknown_AddRef (This->pUnkOuter);
291 /**************************************************************************
292 * IShellFolder_fnRelease
294 static ULONG WINAPI IShellFolder_fnRelease (IShellFolder2 * iface)
296 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
298 TRACE ("(%p)->(count=%u)\n", This, This->ref);
300 return IUnknown_Release (This->pUnkOuter);
303 /**************************************************************************
304 * SHELL32_CreatePidlFromBindCtx [internal]
306 * If the caller bound File System Bind Data, assume it is the
307 * find data for the path.
308 * This allows binding of paths that don't exist.
310 LPITEMIDLIST SHELL32_CreatePidlFromBindCtx(IBindCtx *pbc, LPCWSTR path)
312 static WCHAR szfsbc[] = {
313 'F','i','l','e',' ','S','y','s','t','e','m',' ',
314 'B','i','n','d',' ','D','a','t','a',0 };
315 IFileSystemBindData *fsbd = NULL;
316 LPITEMIDLIST pidl = NULL;
317 IUnknown *param = NULL;
318 WIN32_FIND_DATAW wfd;
319 HRESULT r;
321 TRACE("%p %s\n", pbc, debugstr_w(path));
323 if (!pbc)
324 return NULL;
326 /* see if the caller bound File System Bind Data */
327 r = IBindCtx_GetObjectParam( pbc, (LPOLESTR) szfsbc, &param );
328 if (FAILED(r))
329 return NULL;
331 r = IUnknown_QueryInterface( param, &IID_IFileSystemBindData,
332 (LPVOID*) &fsbd );
333 if (SUCCEEDED(r))
335 r = IFileSystemBindData_GetFindData( fsbd, &wfd );
336 if (SUCCEEDED(r))
338 lstrcpynW( &wfd.cFileName[0], path, MAX_PATH );
339 pidl = _ILCreateFromFindDataW( &wfd );
341 IFileSystemBindData_Release( fsbd );
344 return pidl;
347 /**************************************************************************
348 * IShellFolder_ParseDisplayName {SHELL32}
350 * Parse a display name.
352 * PARAMS
353 * hwndOwner [in] Parent window for any message's
354 * pbc [in] optional FileSystemBindData context
355 * lpszDisplayName [in] Unicode displayname.
356 * pchEaten [out] (unicode) characters processed
357 * ppidl [out] complex pidl to item
358 * pdwAttributes [out] items attributes
360 * NOTES
361 * Every folder tries to parse only its own (the leftmost) pidl and creates a
362 * subfolder to evaluate the remaining parts.
363 * Now we can parse into namespaces implemented by shell extensions
365 * Behaviour on win98: lpszDisplayName=NULL -> crash
366 * lpszDisplayName="" -> returns mycoputer-pidl
368 * FIXME
369 * pdwAttributes is not set
370 * pchEaten is not set like in windows
372 static HRESULT WINAPI
373 IShellFolder_fnParseDisplayName (IShellFolder2 * iface,
374 HWND hwndOwner,
375 LPBC pbc,
376 LPOLESTR lpszDisplayName,
377 DWORD * pchEaten, LPITEMIDLIST * ppidl,
378 DWORD * pdwAttributes)
380 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
382 HRESULT hr = E_INVALIDARG;
383 LPCWSTR szNext = NULL;
384 WCHAR szElement[MAX_PATH];
385 WCHAR szPath[MAX_PATH];
386 LPITEMIDLIST pidlTemp = NULL;
387 DWORD len;
389 TRACE ("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
390 This, hwndOwner, pbc, lpszDisplayName, debugstr_w (lpszDisplayName),
391 pchEaten, ppidl, pdwAttributes);
393 if (!lpszDisplayName || !ppidl)
394 return E_INVALIDARG;
396 if (pchEaten)
397 *pchEaten = 0; /* strange but like the original */
399 pidlTemp = SHELL32_CreatePidlFromBindCtx(pbc, lpszDisplayName);
400 if (!pidlTemp && *lpszDisplayName)
402 /* get the next element */
403 szNext = GetNextElementW (lpszDisplayName, szElement, MAX_PATH);
405 /* build the full pathname to the element */
406 lstrcpynW(szPath, This->sPathTarget, MAX_PATH - 1);
407 PathAddBackslashW(szPath);
408 len = lstrlenW(szPath);
409 lstrcpynW(szPath + len, szElement, MAX_PATH - len);
411 /* get the pidl */
412 hr = _ILCreateFromPathW(szPath, &pidlTemp);
414 if (SUCCEEDED(hr)) {
415 if (szNext && *szNext) {
416 /* try to analyse the next element */
417 hr = SHELL32_ParseNextElement (iface, hwndOwner, pbc,
418 &pidlTemp, (LPOLESTR) szNext, pchEaten, pdwAttributes);
419 } else {
420 /* it's the last element */
421 if (pdwAttributes && *pdwAttributes) {
422 hr = SHELL32_GetItemAttributes (_IShellFolder_ (This),
423 pidlTemp, pdwAttributes);
429 if (SUCCEEDED(hr))
430 *ppidl = pidlTemp;
431 else
432 *ppidl = NULL;
434 TRACE ("(%p)->(-- pidl=%p ret=0x%08x)\n", This, ppidl ? *ppidl : 0, hr);
436 return hr;
439 /**************************************************************************
440 * IShellFolder_fnEnumObjects
441 * PARAMETERS
442 * HWND hwndOwner, //[in ] Parent Window
443 * DWORD grfFlags, //[in ] SHCONTF enumeration mask
444 * LPENUMIDLIST* ppenumIDList //[out] IEnumIDList interface
446 static HRESULT WINAPI
447 IShellFolder_fnEnumObjects (IShellFolder2 * iface, HWND hwndOwner,
448 DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
450 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
452 TRACE ("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This, hwndOwner,
453 dwFlags, ppEnumIDList);
455 *ppEnumIDList = IEnumIDList_Constructor();
456 if (*ppEnumIDList)
457 CreateFolderEnumList(*ppEnumIDList, This->sPathTarget, dwFlags);
459 TRACE ("-- (%p)->(new ID List: %p)\n", This, *ppEnumIDList);
461 return *ppEnumIDList ? S_OK : E_OUTOFMEMORY;
464 /**************************************************************************
465 * IShellFolder_fnBindToObject
466 * PARAMETERS
467 * LPCITEMIDLIST pidl, //[in ] relative pidl to open
468 * LPBC pbc, //[in ] optional FileSystemBindData context
469 * REFIID riid, //[in ] Initial Interface
470 * LPVOID* ppvObject //[out] Interface*
472 static HRESULT WINAPI
473 IShellFolder_fnBindToObject (IShellFolder2 * iface, LPCITEMIDLIST pidl,
474 LPBC pbc, REFIID riid, LPVOID * ppvOut)
476 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
478 TRACE ("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbc,
479 shdebugstr_guid (riid), ppvOut);
481 return SHELL32_BindToChild (This->pidlRoot, This->sPathTarget, pidl, riid,
482 ppvOut);
485 /**************************************************************************
486 * IShellFolder_fnBindToStorage
487 * PARAMETERS
488 * LPCITEMIDLIST pidl, //[in ] complex pidl to store
489 * LPBC pbc, //[in ] reserved
490 * REFIID riid, //[in ] Initial storage interface
491 * LPVOID* ppvObject //[out] Interface* returned
493 static HRESULT WINAPI
494 IShellFolder_fnBindToStorage (IShellFolder2 * iface, LPCITEMIDLIST pidl,
495 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
497 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
499 FIXME ("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved,
500 shdebugstr_guid (riid), ppvOut);
502 *ppvOut = NULL;
503 return E_NOTIMPL;
506 /**************************************************************************
507 * IShellFolder_fnCompareIDs
510 static HRESULT WINAPI
511 IShellFolder_fnCompareIDs (IShellFolder2 * iface, LPARAM lParam,
512 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
514 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
516 int nReturn;
518 TRACE ("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
519 nReturn = SHELL32_CompareIDs (_IShellFolder_ (This), lParam, pidl1, pidl2);
520 TRACE ("-- %i\n", nReturn);
521 return nReturn;
524 /**************************************************************************
525 * IShellFolder_fnCreateViewObject
527 static HRESULT WINAPI
528 IShellFolder_fnCreateViewObject (IShellFolder2 * iface, HWND hwndOwner,
529 REFIID riid, LPVOID * ppvOut)
531 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
533 LPSHELLVIEW pShellView;
534 HRESULT hr = E_INVALIDARG;
536 TRACE ("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid (riid),
537 ppvOut);
539 if (ppvOut) {
540 *ppvOut = NULL;
542 if (IsEqualIID (riid, &IID_IDropTarget)) {
543 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget, ppvOut);
544 } else if (IsEqualIID (riid, &IID_IContextMenu)) {
545 FIXME ("IContextMenu not implemented\n");
546 hr = E_NOTIMPL;
547 } else if (IsEqualIID (riid, &IID_IShellView)) {
548 pShellView = IShellView_Constructor ((IShellFolder *) iface);
549 if (pShellView) {
550 hr = IShellView_QueryInterface (pShellView, riid, ppvOut);
551 IShellView_Release (pShellView);
555 TRACE ("-- (%p)->(interface=%p)\n", This, ppvOut);
556 return hr;
559 /**************************************************************************
560 * IShellFolder_fnGetAttributesOf
562 * PARAMETERS
563 * UINT cidl, //[in ] num elements in pidl array
564 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
565 * ULONG* rgfInOut) //[out] result array
568 static HRESULT WINAPI
569 IShellFolder_fnGetAttributesOf (IShellFolder2 * iface, UINT cidl,
570 LPCITEMIDLIST * apidl, DWORD * rgfInOut)
572 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
574 HRESULT hr = S_OK;
576 TRACE ("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", This, cidl, apidl,
577 rgfInOut, rgfInOut ? *rgfInOut : 0);
579 if (!rgfInOut)
580 return E_INVALIDARG;
581 if (cidl && !apidl)
582 return E_INVALIDARG;
584 if (*rgfInOut == 0)
585 *rgfInOut = ~0;
587 if(cidl == 0){
588 IShellFolder *psfParent = NULL;
589 LPCITEMIDLIST rpidl = NULL;
591 hr = SHBindToParent(This->pidlRoot, &IID_IShellFolder, (LPVOID*)&psfParent, (LPCITEMIDLIST*)&rpidl);
592 if(SUCCEEDED(hr)) {
593 SHELL32_GetItemAttributes (psfParent, rpidl, rgfInOut);
594 IShellFolder_Release(psfParent);
597 else {
598 while (cidl > 0 && *apidl) {
599 pdump (*apidl);
600 SHELL32_GetItemAttributes (_IShellFolder_ (This), *apidl, rgfInOut);
601 apidl++;
602 cidl--;
605 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
606 *rgfInOut &= ~SFGAO_VALIDATE;
608 TRACE ("-- result=0x%08x\n", *rgfInOut);
610 return hr;
613 /**************************************************************************
614 * IShellFolder_fnGetUIObjectOf
616 * PARAMETERS
617 * HWND hwndOwner, //[in ] Parent window for any output
618 * UINT cidl, //[in ] array size
619 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
620 * REFIID riid, //[in ] Requested Interface
621 * UINT* prgfInOut, //[ ] reserved
622 * LPVOID* ppvObject) //[out] Resulting Interface
624 * NOTES
625 * This function gets asked to return "view objects" for one or more (multiple
626 * select) items:
627 * The viewobject typically is an COM object with one of the following
628 * interfaces:
629 * IExtractIcon,IDataObject,IContextMenu
630 * In order to support icon positions in the default Listview your DataObject
631 * must implement the SetData method (in addition to GetData :) - the shell
632 * passes a barely documented "Icon positions" structure to SetData when the
633 * drag starts, and GetData's it if the drop is in another explorer window that
634 * needs the positions.
636 static HRESULT WINAPI
637 IShellFolder_fnGetUIObjectOf (IShellFolder2 * iface,
638 HWND hwndOwner,
639 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid,
640 UINT * prgfInOut, LPVOID * ppvOut)
642 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
644 LPITEMIDLIST pidl;
645 IUnknown *pObj = NULL;
646 HRESULT hr = E_INVALIDARG;
648 TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
649 This, hwndOwner, cidl, apidl, shdebugstr_guid (riid), prgfInOut, ppvOut);
651 if (ppvOut) {
652 *ppvOut = NULL;
654 if (IsEqualIID (riid, &IID_IContextMenu) && (cidl >= 1)) {
655 pObj = (LPUNKNOWN) ISvItemCm_Constructor ((IShellFolder *) iface,
656 This->pidlRoot, apidl, cidl);
657 hr = S_OK;
658 } else if (IsEqualIID (riid, &IID_IDataObject) && (cidl >= 1)) {
659 pObj = (LPUNKNOWN) IDataObject_Constructor (hwndOwner,
660 This->pidlRoot, apidl, cidl);
661 hr = S_OK;
662 } else if (IsEqualIID (riid, &IID_IExtractIconA) && (cidl == 1)) {
663 pidl = ILCombine (This->pidlRoot, apidl[0]);
664 pObj = (LPUNKNOWN) IExtractIconA_Constructor (pidl);
665 SHFree (pidl);
666 hr = S_OK;
667 } else if (IsEqualIID (riid, &IID_IExtractIconW) && (cidl == 1)) {
668 pidl = ILCombine (This->pidlRoot, apidl[0]);
669 pObj = (LPUNKNOWN) IExtractIconW_Constructor (pidl);
670 SHFree (pidl);
671 hr = S_OK;
672 } else if (IsEqualIID (riid, &IID_IDropTarget) && (cidl >= 1)) {
673 hr = IShellFolder_QueryInterface (iface, &IID_IDropTarget,
674 (LPVOID *) & pObj);
675 } else if ((IsEqualIID(riid,&IID_IShellLinkW) ||
676 IsEqualIID(riid,&IID_IShellLinkA)) && (cidl == 1)) {
677 pidl = ILCombine (This->pidlRoot, apidl[0]);
678 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, (LPVOID*)&pObj);
679 SHFree (pidl);
680 } else {
681 hr = E_NOINTERFACE;
684 if (SUCCEEDED(hr) && !pObj)
685 hr = E_OUTOFMEMORY;
687 *ppvOut = pObj;
689 TRACE ("(%p)->hr=0x%08x\n", This, hr);
690 return hr;
693 static const WCHAR AdvancedW[] = { 'S','O','F','T','W','A','R','E',
694 '\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
695 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l',
696 'o','r','e','r','\\','A','d','v','a','n','c','e','d',0 };
697 static const WCHAR HideFileExtW[] = { 'H','i','d','e','F','i','l','e','E','x',
698 't',0 };
699 static const WCHAR NeverShowExtW[] = { 'N','e','v','e','r','S','h','o','w','E',
700 'x','t',0 };
702 /******************************************************************************
703 * SHELL_FS_HideExtension [Internal]
705 * Query the registry if the filename extension of a given path should be
706 * hidden.
708 * PARAMS
709 * szPath [I] Relative or absolute path of a file
711 * RETURNS
712 * TRUE, if the filename's extension should be hidden
713 * FALSE, otherwise.
715 BOOL SHELL_FS_HideExtension(LPWSTR szPath)
717 HKEY hKey;
718 DWORD dwData;
719 DWORD dwDataSize = sizeof (DWORD);
720 BOOL doHide = FALSE; /* The default value is FALSE (win98 at least) */
722 if (!RegCreateKeyExW(HKEY_CURRENT_USER, AdvancedW, 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0)) {
723 if (!RegQueryValueExW(hKey, HideFileExtW, 0, 0, (LPBYTE) &dwData, &dwDataSize))
724 doHide = dwData;
725 RegCloseKey (hKey);
728 if (!doHide) {
729 LPWSTR ext = PathFindExtensionW(szPath);
731 if (*ext != '\0') {
732 WCHAR classname[MAX_PATH];
733 LONG classlen = sizeof(classname);
735 if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, classname, &classlen))
736 if (!RegOpenKeyW(HKEY_CLASSES_ROOT, classname, &hKey)) {
737 if (!RegQueryValueExW(hKey, NeverShowExtW, 0, NULL, NULL, NULL))
738 doHide = TRUE;
739 RegCloseKey(hKey);
743 return doHide;
746 void SHELL_FS_ProcessDisplayFilename(LPWSTR szPath, DWORD dwFlags)
748 /*FIXME: MSDN also mentions SHGDN_FOREDITING which is not yet handled. */
749 if (!(dwFlags & SHGDN_FORPARSING) &&
750 ((dwFlags & SHGDN_INFOLDER) || (dwFlags == SHGDN_NORMAL))) {
751 if (SHELL_FS_HideExtension(szPath) && szPath[0] != '.')
752 PathRemoveExtensionW(szPath);
756 /**************************************************************************
757 * IShellFolder_fnGetDisplayNameOf
758 * Retrieves the display name for the specified file object or subfolder
760 * PARAMETERS
761 * LPCITEMIDLIST pidl, //[in ] complex pidl to item
762 * DWORD dwFlags, //[in ] SHGNO formatting flags
763 * LPSTRRET lpName) //[out] Returned display name
765 * FIXME
766 * if the name is in the pidl the ret value should be a STRRET_OFFSET
769 static HRESULT WINAPI
770 IShellFolder_fnGetDisplayNameOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
771 DWORD dwFlags, LPSTRRET strRet)
773 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
774 WCHAR wszPath[MAX_PATH+1];
776 HRESULT hr = S_OK;
777 int len = 0;
779 TRACE ("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
780 pdump (pidl);
782 if (!pidl || !strRet)
783 return E_INVALIDARG;
785 if (_ILIsDesktop(pidl)) { /* empty pidl */
786 if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) &&
787 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER))
789 if (This->sPathTarget)
790 lstrcpynW(wszPath, This->sPathTarget, MAX_PATH);
791 } else {
792 /* pidl has to contain exactly one non null SHITEMID */
793 hr = E_INVALIDARG;
795 } else if (_ILIsPidlSimple(pidl)) {
796 if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) &&
797 (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER) &&
798 This->sPathTarget)
800 lstrcpynW(wszPath, This->sPathTarget, MAX_PATH);
801 PathAddBackslashW(wszPath);
802 len = lstrlenW(wszPath);
804 _ILSimpleGetTextW(pidl, wszPath + len, MAX_PATH + 1 - len);
805 if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(wszPath, dwFlags);
806 } else {
807 hr = SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, wszPath, MAX_PATH);
810 if (SUCCEEDED(hr)) {
811 strRet->uType = STRRET_CSTR;
812 if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, strRet->u.cStr, MAX_PATH,
813 NULL, NULL))
814 strRet->u.cStr[0] = '\0';
817 TRACE ("-- (%p)->(%s)\n", This, strRet->u.cStr);
818 return hr;
821 /**************************************************************************
822 * IShellFolder_fnSetNameOf
823 * Changes the name of a file object or subfolder, possibly changing its item
824 * identifier in the process.
826 * PARAMETERS
827 * HWND hwndOwner, //[in ] Owner window for output
828 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
829 * LPCOLESTR lpszName, //[in ] the items new display name
830 * DWORD dwFlags, //[in ] SHGNO formatting flags
831 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
833 static HRESULT WINAPI IShellFolder_fnSetNameOf (IShellFolder2 * iface,
834 HWND hwndOwner,
835 LPCITEMIDLIST pidl,
836 LPCOLESTR lpName,
837 DWORD dwFlags,
838 LPITEMIDLIST * pPidlOut)
840 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
841 WCHAR szSrc[MAX_PATH + 1], szDest[MAX_PATH + 1];
842 LPWSTR ptr;
843 BOOL bIsFolder = _ILIsFolder (ILFindLastID (pidl));
845 TRACE ("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl,
846 debugstr_w (lpName), dwFlags, pPidlOut);
848 /* build source path */
849 lstrcpynW(szSrc, This->sPathTarget, MAX_PATH);
850 ptr = PathAddBackslashW (szSrc);
851 if (ptr)
852 _ILSimpleGetTextW (pidl, ptr, MAX_PATH + 1 - (ptr - szSrc));
854 /* build destination path */
855 if (dwFlags == SHGDN_NORMAL || dwFlags & SHGDN_INFOLDER) {
856 lstrcpynW(szDest, This->sPathTarget, MAX_PATH);
857 ptr = PathAddBackslashW (szDest);
858 if (ptr)
859 lstrcpynW(ptr, lpName, MAX_PATH + 1 - (ptr - szDest));
860 } else
861 lstrcpynW(szDest, lpName, MAX_PATH);
863 if(!(dwFlags & SHGDN_FORPARSING) && SHELL_FS_HideExtension(szSrc)) {
864 WCHAR *ext = PathFindExtensionW(szSrc);
865 if(*ext != '\0') {
866 INT len = strlenW(szDest);
867 lstrcpynW(szDest + len, ext, MAX_PATH - len);
871 TRACE ("src=%s dest=%s\n", debugstr_w(szSrc), debugstr_w(szDest));
873 if (MoveFileW (szSrc, szDest)) {
874 HRESULT hr = S_OK;
876 if (pPidlOut)
877 hr = _ILCreateFromPathW(szDest, pPidlOut);
879 SHChangeNotify (bIsFolder ? SHCNE_RENAMEFOLDER : SHCNE_RENAMEITEM,
880 SHCNF_PATHW, szSrc, szDest);
882 return hr;
885 return E_FAIL;
888 static HRESULT WINAPI IShellFolder_fnGetDefaultSearchGUID (IShellFolder2 *iface,
889 GUID * pguid)
891 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
892 FIXME ("(%p)\n", This);
893 return E_NOTIMPL;
895 static HRESULT WINAPI IShellFolder_fnEnumSearches (IShellFolder2 * iface,
896 IEnumExtraSearch ** ppenum)
898 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
899 FIXME ("(%p)\n", This);
900 return E_NOTIMPL;
903 static HRESULT WINAPI
904 IShellFolder_fnGetDefaultColumn (IShellFolder2 * iface, DWORD dwRes,
905 ULONG * pSort, ULONG * pDisplay)
907 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
909 TRACE ("(%p)\n", This);
911 if (pSort)
912 *pSort = 0;
913 if (pDisplay)
914 *pDisplay = 0;
916 return S_OK;
919 static HRESULT WINAPI
920 IShellFolder_fnGetDefaultColumnState (IShellFolder2 * iface, UINT iColumn,
921 DWORD * pcsFlags)
923 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
925 TRACE ("(%p)\n", This);
927 if (!pcsFlags || iColumn >= GENERICSHELLVIEWCOLUMNS)
928 return E_INVALIDARG;
930 *pcsFlags = GenericSFHeader[iColumn].pcsFlags;
932 return S_OK;
935 static HRESULT WINAPI
936 IShellFolder_fnGetDetailsEx (IShellFolder2 * iface, LPCITEMIDLIST pidl,
937 const SHCOLUMNID * pscid, VARIANT * pv)
939 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
940 FIXME ("(%p)\n", This);
942 return E_NOTIMPL;
945 static HRESULT WINAPI
946 IShellFolder_fnGetDetailsOf (IShellFolder2 * iface, LPCITEMIDLIST pidl,
947 UINT iColumn, SHELLDETAILS * psd)
949 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
950 HRESULT hr = E_FAIL;
952 TRACE ("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
954 if (!psd || iColumn >= GENERICSHELLVIEWCOLUMNS)
955 return E_INVALIDARG;
957 if (!pidl) {
958 /* the header titles */
959 psd->fmt = GenericSFHeader[iColumn].fmt;
960 psd->cxChar = GenericSFHeader[iColumn].cxChar;
961 psd->str.uType = STRRET_CSTR;
962 LoadStringA (shell32_hInstance, GenericSFHeader[iColumn].colnameid,
963 psd->str.u.cStr, MAX_PATH);
964 return S_OK;
965 } else {
966 hr = S_OK;
967 psd->str.uType = STRRET_CSTR;
968 /* the data from the pidl */
969 switch (iColumn) {
970 case 0: /* name */
971 hr = IShellFolder_GetDisplayNameOf (iface, pidl,
972 SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
973 break;
974 case 1: /* size */
975 _ILGetFileSize (pidl, psd->str.u.cStr, MAX_PATH);
976 break;
977 case 2: /* type */
978 _ILGetFileType (pidl, psd->str.u.cStr, MAX_PATH);
979 break;
980 case 3: /* date */
981 _ILGetFileDate (pidl, psd->str.u.cStr, MAX_PATH);
982 break;
983 case 4: /* attributes */
984 _ILGetFileAttributes (pidl, psd->str.u.cStr, MAX_PATH);
985 break;
989 return hr;
992 static HRESULT WINAPI
993 IShellFolder_fnMapColumnToSCID (IShellFolder2 * iface, UINT column,
994 SHCOLUMNID * pscid)
996 IGenericSFImpl *This = impl_from_IShellFolder2(iface);
997 FIXME ("(%p)\n", This);
998 return E_NOTIMPL;
1001 static const IShellFolder2Vtbl sfvt =
1003 IShellFolder_fnQueryInterface,
1004 IShellFolder_fnAddRef,
1005 IShellFolder_fnRelease,
1006 IShellFolder_fnParseDisplayName,
1007 IShellFolder_fnEnumObjects,
1008 IShellFolder_fnBindToObject,
1009 IShellFolder_fnBindToStorage,
1010 IShellFolder_fnCompareIDs,
1011 IShellFolder_fnCreateViewObject,
1012 IShellFolder_fnGetAttributesOf,
1013 IShellFolder_fnGetUIObjectOf,
1014 IShellFolder_fnGetDisplayNameOf,
1015 IShellFolder_fnSetNameOf,
1016 /* ShellFolder2 */
1017 IShellFolder_fnGetDefaultSearchGUID,
1018 IShellFolder_fnEnumSearches,
1019 IShellFolder_fnGetDefaultColumn,
1020 IShellFolder_fnGetDefaultColumnState,
1021 IShellFolder_fnGetDetailsEx,
1022 IShellFolder_fnGetDetailsOf,
1023 IShellFolder_fnMapColumnToSCID
1026 /****************************************************************************
1027 * ISFHelper for IShellFolder implementation
1030 static HRESULT WINAPI
1031 ISFHelper_fnQueryInterface (ISFHelper * iface, REFIID riid, LPVOID * ppvObj)
1033 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1035 TRACE ("(%p)->(count=%u)\n", This, This->ref);
1037 return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
1040 static ULONG WINAPI ISFHelper_fnAddRef (ISFHelper * iface)
1042 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1044 TRACE ("(%p)->(count=%u)\n", This, This->ref);
1046 return IUnknown_AddRef (This->pUnkOuter);
1049 static ULONG WINAPI ISFHelper_fnRelease (ISFHelper * iface)
1051 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1053 TRACE ("(%p)\n", This);
1055 return IUnknown_Release (This->pUnkOuter);
1058 /****************************************************************************
1059 * ISFHelper_fnAddFolder
1061 * creates a unique folder name
1064 static HRESULT WINAPI
1065 ISFHelper_fnGetUniqueName (ISFHelper * iface, LPWSTR pwszName, UINT uLen)
1067 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1068 IEnumIDList *penum;
1069 HRESULT hr;
1070 WCHAR wszText[MAX_PATH];
1071 const WCHAR wszNewFolder[] = {'N','e','w',' ','F','o','l','d','e','r',0 };
1072 const WCHAR wszFormat[] = {'%','s',' ','%','d',0 };
1074 TRACE ("(%p)(%p %u)\n", This, pwszName, uLen);
1076 if (uLen < sizeof(wszNewFolder)/sizeof(WCHAR) + 3)
1077 return E_POINTER;
1079 lstrcpynW (pwszName, wszNewFolder, uLen);
1081 hr = IShellFolder_fnEnumObjects (_IShellFolder2_ (This), 0,
1082 SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &penum);
1083 if (penum) {
1084 LPITEMIDLIST pidl;
1085 DWORD dwFetched;
1086 int i = 1;
1088 next:
1089 IEnumIDList_Reset (penum);
1090 while (S_OK == IEnumIDList_Next (penum, 1, &pidl, &dwFetched) &&
1091 dwFetched) {
1092 _ILSimpleGetTextW (pidl, wszText, MAX_PATH);
1093 if (0 == lstrcmpiW (wszText, pwszName)) {
1094 snprintfW (pwszName, uLen, wszFormat, wszNewFolder, i++);
1095 if (i > 99) {
1096 hr = E_FAIL;
1097 break;
1099 goto next;
1103 IEnumIDList_Release (penum);
1105 return hr;
1108 /****************************************************************************
1109 * ISFHelper_fnAddFolder
1111 * adds a new folder.
1114 static HRESULT WINAPI
1115 ISFHelper_fnAddFolder (ISFHelper * iface, HWND hwnd, LPCWSTR pwszName,
1116 LPITEMIDLIST * ppidlOut)
1118 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1119 WCHAR wszNewDir[MAX_PATH];
1120 DWORD bRes;
1121 HRESULT hres = E_FAIL;
1123 TRACE ("(%p)(%s %p)\n", This, debugstr_w(pwszName), ppidlOut);
1125 wszNewDir[0] = 0;
1126 if (This->sPathTarget)
1127 lstrcpynW(wszNewDir, This->sPathTarget, MAX_PATH);
1128 PathAppendW(wszNewDir, pwszName);
1130 bRes = CreateDirectoryW (wszNewDir, NULL);
1131 if (bRes) {
1132 SHChangeNotify (SHCNE_MKDIR, SHCNF_PATHW, wszNewDir, NULL);
1134 hres = S_OK;
1136 if (ppidlOut)
1137 hres = _ILCreateFromPathW(wszNewDir, ppidlOut);
1138 } else {
1139 WCHAR wszText[128 + MAX_PATH];
1140 WCHAR wszTempText[128];
1141 WCHAR wszCaption[256];
1143 /* Cannot Create folder because of permissions */
1144 LoadStringW (shell32_hInstance, IDS_CREATEFOLDER_DENIED, wszTempText,
1145 sizeof (wszTempText));
1146 LoadStringW (shell32_hInstance, IDS_CREATEFOLDER_CAPTION, wszCaption,
1147 sizeof (wszCaption));
1148 sprintfW (wszText, wszTempText, wszNewDir);
1149 MessageBoxW (hwnd, wszText, wszCaption, MB_OK | MB_ICONEXCLAMATION);
1152 return hres;
1155 /****************************************************************************
1156 * build_paths_list
1158 * Builds a list of paths like the one used in SHFileOperation from a table of
1159 * PIDLs relative to the given base folder
1161 static WCHAR *build_paths_list(LPCWSTR wszBasePath, int cidl, LPCITEMIDLIST *pidls)
1163 WCHAR *wszPathsList;
1164 WCHAR *wszListPos;
1165 int iPathLen;
1166 int i;
1168 iPathLen = lstrlenW(wszBasePath);
1169 wszPathsList = HeapAlloc(GetProcessHeap(), 0, MAX_PATH*sizeof(WCHAR)*cidl+1);
1170 wszListPos = wszPathsList;
1172 for (i = 0; i < cidl; i++) {
1173 if (!_ILIsFolder(pidls[i]) && !_ILIsValue(pidls[i]))
1174 continue;
1176 lstrcpynW(wszListPos, wszBasePath, MAX_PATH);
1177 /* FIXME: abort if path too long */
1178 _ILSimpleGetTextW(pidls[i], wszListPos+iPathLen, MAX_PATH-iPathLen);
1179 wszListPos += lstrlenW(wszListPos)+1;
1181 *wszListPos=0;
1182 return wszPathsList;
1185 /****************************************************************************
1186 * ISFHelper_fnDeleteItems
1188 * deletes items in folder
1190 static HRESULT WINAPI
1191 ISFHelper_fnDeleteItems (ISFHelper * iface, UINT cidl, LPCITEMIDLIST * apidl)
1193 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1194 UINT i;
1195 SHFILEOPSTRUCTW op;
1196 WCHAR wszPath[MAX_PATH];
1197 WCHAR *wszPathsList;
1198 HRESULT ret;
1199 WCHAR *wszCurrentPath;
1201 TRACE ("(%p)(%u %p)\n", This, cidl, apidl);
1202 if (cidl==0) return S_OK;
1204 if (This->sPathTarget)
1205 lstrcpynW(wszPath, This->sPathTarget, MAX_PATH);
1206 else
1207 wszPath[0] = '\0';
1208 PathAddBackslashW(wszPath);
1209 wszPathsList = build_paths_list(wszPath, cidl, apidl);
1211 ZeroMemory(&op, sizeof(op));
1212 op.hwnd = GetActiveWindow();
1213 op.wFunc = FO_DELETE;
1214 op.pFrom = wszPathsList;
1215 op.fFlags = FOF_ALLOWUNDO;
1216 if (SHFileOperationW(&op))
1218 WARN("SHFileOperation failed\n");
1219 ret = E_FAIL;
1221 else
1222 ret = S_OK;
1224 /* we currently need to manually send the notifies */
1225 wszCurrentPath = wszPathsList;
1226 for (i = 0; i < cidl; i++)
1228 LONG wEventId;
1230 if (_ILIsFolder(apidl[i]))
1231 wEventId = SHCNE_RMDIR;
1232 else if (_ILIsValue(apidl[i]))
1233 wEventId = SHCNE_DELETE;
1234 else
1235 continue;
1237 /* check if file exists */
1238 if (GetFileAttributesW(wszCurrentPath) == INVALID_FILE_ATTRIBUTES)
1240 LPITEMIDLIST pidl = ILCombine(This->pidlRoot, apidl[i]);
1241 SHChangeNotify(wEventId, SHCNF_IDLIST, pidl, NULL);
1242 SHFree(pidl);
1245 wszCurrentPath += lstrlenW(wszCurrentPath)+1;
1247 HeapFree(GetProcessHeap(), 0, wszPathsList);
1248 return ret;
1251 /****************************************************************************
1252 * ISFHelper_fnCopyItems
1254 * copies items to this folder
1256 static HRESULT WINAPI
1257 ISFHelper_fnCopyItems (ISFHelper * iface, IShellFolder * pSFFrom, UINT cidl,
1258 LPCITEMIDLIST * apidl)
1260 UINT i;
1261 IPersistFolder2 *ppf2 = NULL;
1262 char szSrcPath[MAX_PATH],
1263 szDstPath[MAX_PATH];
1265 IGenericSFImpl *This = impl_from_ISFHelper(iface);
1267 TRACE ("(%p)->(%p,%u,%p)\n", This, pSFFrom, cidl, apidl);
1269 IShellFolder_QueryInterface (pSFFrom, &IID_IPersistFolder2,
1270 (LPVOID *) & ppf2);
1271 if (ppf2) {
1272 LPITEMIDLIST pidl;
1274 if (SUCCEEDED (IPersistFolder2_GetCurFolder (ppf2, &pidl))) {
1275 for (i = 0; i < cidl; i++) {
1276 SHGetPathFromIDListA (pidl, szSrcPath);
1277 PathAddBackslashA (szSrcPath);
1278 _ILSimpleGetText (apidl[i], szSrcPath + strlen (szSrcPath),
1279 MAX_PATH);
1281 if (!WideCharToMultiByte(CP_ACP, 0, This->sPathTarget, -1, szDstPath, MAX_PATH, NULL, NULL))
1282 szDstPath[0] = '\0';
1283 PathAddBackslashA (szDstPath);
1284 _ILSimpleGetText (apidl[i], szDstPath + strlen (szDstPath),
1285 MAX_PATH);
1286 MESSAGE ("would copy %s to %s\n", szSrcPath, szDstPath);
1288 SHFree (pidl);
1290 IPersistFolder2_Release (ppf2);
1292 return S_OK;
1295 static const ISFHelperVtbl shvt =
1297 ISFHelper_fnQueryInterface,
1298 ISFHelper_fnAddRef,
1299 ISFHelper_fnRelease,
1300 ISFHelper_fnGetUniqueName,
1301 ISFHelper_fnAddFolder,
1302 ISFHelper_fnDeleteItems,
1303 ISFHelper_fnCopyItems
1306 /************************************************************************
1307 * IFSFldr_PersistFolder3_QueryInterface
1310 static HRESULT WINAPI
1311 IFSFldr_PersistFolder3_QueryInterface (IPersistFolder3 * iface, REFIID iid,
1312 LPVOID * ppvObj)
1314 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1316 TRACE ("(%p)\n", This);
1318 return IUnknown_QueryInterface (This->pUnkOuter, iid, ppvObj);
1321 /************************************************************************
1322 * IFSFldr_PersistFolder3_AddRef
1325 static ULONG WINAPI
1326 IFSFldr_PersistFolder3_AddRef (IPersistFolder3 * iface)
1328 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1330 TRACE ("(%p)->(count=%u)\n", This, This->ref);
1332 return IUnknown_AddRef (This->pUnkOuter);
1335 /************************************************************************
1336 * IFSFldr_PersistFolder3_Release
1339 static ULONG WINAPI
1340 IFSFldr_PersistFolder3_Release (IPersistFolder3 * iface)
1342 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1344 TRACE ("(%p)->(count=%u)\n", This, This->ref);
1346 return IUnknown_Release (This->pUnkOuter);
1349 /************************************************************************
1350 * IFSFldr_PersistFolder3_GetClassID
1352 static HRESULT WINAPI
1353 IFSFldr_PersistFolder3_GetClassID (IPersistFolder3 * iface, CLSID * lpClassId)
1355 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1357 TRACE ("(%p)\n", This);
1359 if (!lpClassId)
1360 return E_POINTER;
1361 *lpClassId = *This->pclsid;
1363 return S_OK;
1366 /************************************************************************
1367 * IFSFldr_PersistFolder3_Initialize
1369 * NOTES
1370 * sPathTarget is not set. Don't know how to handle in a non rooted environment.
1372 static HRESULT WINAPI
1373 IFSFldr_PersistFolder3_Initialize (IPersistFolder3 * iface, LPCITEMIDLIST pidl)
1375 WCHAR wszTemp[MAX_PATH];
1377 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1379 TRACE ("(%p)->(%p)\n", This, pidl);
1381 SHFree (This->pidlRoot); /* free the old pidl */
1382 This->pidlRoot = ILClone (pidl); /* set my pidl */
1384 SHFree (This->sPathTarget);
1385 This->sPathTarget = NULL;
1387 /* set my path */
1388 if (SHGetPathFromIDListW (pidl, wszTemp)) {
1389 int len = strlenW(wszTemp);
1390 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1391 if (!This->sPathTarget)
1392 return E_OUTOFMEMORY;
1393 memcpy(This->sPathTarget, wszTemp, (len + 1) * sizeof(WCHAR));
1396 TRACE ("--(%p)->(%s)\n", This, debugstr_w(This->sPathTarget));
1397 return S_OK;
1400 /**************************************************************************
1401 * IFSFldr_PersistFolder3_GetCurFolder
1403 static HRESULT WINAPI
1404 IFSFldr_PersistFolder3_fnGetCurFolder (IPersistFolder3 * iface,
1405 LPITEMIDLIST * pidl)
1407 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1409 TRACE ("(%p)->(%p)\n", This, pidl);
1411 if (!pidl) return E_POINTER;
1412 *pidl = ILClone (This->pidlRoot);
1413 return S_OK;
1416 /**************************************************************************
1417 * IFSFldr_PersistFolder3_InitializeEx
1419 * FIXME: error handling
1421 static HRESULT WINAPI
1422 IFSFldr_PersistFolder3_InitializeEx (IPersistFolder3 * iface,
1423 IBindCtx * pbc, LPCITEMIDLIST pidlRoot,
1424 const PERSIST_FOLDER_TARGET_INFO * ppfti)
1426 WCHAR wszTemp[MAX_PATH];
1428 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1430 TRACE ("(%p)->(%p,%p,%p)\n", This, pbc, pidlRoot, ppfti);
1431 if (ppfti)
1432 TRACE ("--%p %s %s 0x%08x 0x%08x\n",
1433 ppfti->pidlTargetFolder, debugstr_w (ppfti->szTargetParsingName),
1434 debugstr_w (ppfti->szNetworkProvider), ppfti->dwAttributes,
1435 ppfti->csidl);
1437 pdump (pidlRoot);
1438 if (ppfti && ppfti->pidlTargetFolder)
1439 pdump (ppfti->pidlTargetFolder);
1441 if (This->pidlRoot)
1442 __SHFreeAndNil (&This->pidlRoot); /* free the old */
1443 if (This->sPathTarget)
1444 __SHFreeAndNil (&This->sPathTarget);
1447 * Root path and pidl
1449 This->pidlRoot = ILClone (pidlRoot);
1452 * the target folder is spezified in csidl OR pidlTargetFolder OR
1453 * szTargetParsingName
1455 if (ppfti) {
1456 if (ppfti->csidl != -1) {
1457 if (SHGetSpecialFolderPathW (0, wszTemp, ppfti->csidl,
1458 ppfti->csidl & CSIDL_FLAG_CREATE)) {
1459 int len = strlenW(wszTemp);
1460 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1461 if (!This->sPathTarget)
1462 return E_OUTOFMEMORY;
1463 memcpy(This->sPathTarget, wszTemp, (len + 1) * sizeof(WCHAR));
1465 } else if (ppfti->szTargetParsingName[0]) {
1466 int len = strlenW(ppfti->szTargetParsingName);
1467 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1468 if (!This->sPathTarget)
1469 return E_OUTOFMEMORY;
1470 memcpy(This->sPathTarget, ppfti->szTargetParsingName,
1471 (len + 1) * sizeof(WCHAR));
1472 } else if (ppfti->pidlTargetFolder) {
1473 if (SHGetPathFromIDListW(ppfti->pidlTargetFolder, wszTemp)) {
1474 int len = strlenW(wszTemp);
1475 This->sPathTarget = SHAlloc((len + 1) * sizeof(WCHAR));
1476 if (!This->sPathTarget)
1477 return E_OUTOFMEMORY;
1478 memcpy(This->sPathTarget, wszTemp, (len + 1) * sizeof(WCHAR));
1483 TRACE ("--(%p)->(target=%s)\n", This, debugstr_w(This->sPathTarget));
1484 pdump (This->pidlRoot);
1485 return (This->sPathTarget) ? S_OK : E_FAIL;
1488 static HRESULT WINAPI
1489 IFSFldr_PersistFolder3_GetFolderTargetInfo (IPersistFolder3 * iface,
1490 PERSIST_FOLDER_TARGET_INFO * ppfti)
1492 IGenericSFImpl *This = impl_from_IPersistFolder3(iface);
1493 FIXME ("(%p)->(%p)\n", This, ppfti);
1494 ZeroMemory (ppfti, sizeof (ppfti));
1495 return E_NOTIMPL;
1498 static const IPersistFolder3Vtbl vt_FSFldr_PersistFolder3 =
1500 IFSFldr_PersistFolder3_QueryInterface,
1501 IFSFldr_PersistFolder3_AddRef,
1502 IFSFldr_PersistFolder3_Release,
1503 IFSFldr_PersistFolder3_GetClassID,
1504 IFSFldr_PersistFolder3_Initialize,
1505 IFSFldr_PersistFolder3_fnGetCurFolder,
1506 IFSFldr_PersistFolder3_InitializeEx,
1507 IFSFldr_PersistFolder3_GetFolderTargetInfo
1510 /****************************************************************************
1511 * ISFDropTarget implementation
1513 static BOOL
1514 ISFDropTarget_QueryDrop (IDropTarget * iface, DWORD dwKeyState,
1515 LPDWORD pdwEffect)
1517 DWORD dwEffect = *pdwEffect;
1519 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1521 *pdwEffect = DROPEFFECT_NONE;
1523 if (This->fAcceptFmt) { /* Does our interpretation of the keystate ... */
1524 *pdwEffect = KeyStateToDropEffect (dwKeyState);
1526 /* ... matches the desired effect ? */
1527 if (dwEffect & *pdwEffect) {
1528 return TRUE;
1531 return FALSE;
1534 static HRESULT WINAPI
1535 ISFDropTarget_QueryInterface (IDropTarget * iface, REFIID riid, LPVOID * ppvObj)
1537 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1539 TRACE ("(%p)\n", This);
1541 return IUnknown_QueryInterface (This->pUnkOuter, riid, ppvObj);
1544 static ULONG WINAPI ISFDropTarget_AddRef (IDropTarget * iface)
1546 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1548 TRACE ("(%p)\n", This);
1550 return IUnknown_AddRef (This->pUnkOuter);
1553 static ULONG WINAPI ISFDropTarget_Release (IDropTarget * iface)
1555 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1557 TRACE ("(%p)\n", This);
1559 return IUnknown_Release (This->pUnkOuter);
1562 static HRESULT WINAPI
1563 ISFDropTarget_DragEnter (IDropTarget * iface, IDataObject * pDataObject,
1564 DWORD dwKeyState, POINTL pt, DWORD * pdwEffect)
1566 FORMATETC fmt;
1568 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1570 TRACE ("(%p)->(DataObject=%p)\n", This, pDataObject);
1572 InitFormatEtc (fmt, This->cfShellIDList, TYMED_HGLOBAL);
1574 This->fAcceptFmt = (S_OK == IDataObject_QueryGetData (pDataObject, &fmt)) ?
1575 TRUE : FALSE;
1577 ISFDropTarget_QueryDrop (iface, dwKeyState, pdwEffect);
1579 return S_OK;
1582 static HRESULT WINAPI
1583 ISFDropTarget_DragOver (IDropTarget * iface, DWORD dwKeyState, POINTL pt,
1584 DWORD * pdwEffect)
1586 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1588 TRACE ("(%p)\n", This);
1590 if (!pdwEffect)
1591 return E_INVALIDARG;
1593 ISFDropTarget_QueryDrop (iface, dwKeyState, pdwEffect);
1595 return S_OK;
1598 static HRESULT WINAPI ISFDropTarget_DragLeave (IDropTarget * iface)
1600 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1602 TRACE ("(%p)\n", This);
1604 This->fAcceptFmt = FALSE;
1606 return S_OK;
1609 static HRESULT WINAPI
1610 ISFDropTarget_Drop (IDropTarget * iface, IDataObject * pDataObject,
1611 DWORD dwKeyState, POINTL pt, DWORD * pdwEffect)
1613 IGenericSFImpl *This = impl_from_IDropTarget(iface);
1615 FIXME ("(%p) object dropped\n", This);
1617 return E_NOTIMPL;
1620 static const IDropTargetVtbl dtvt = {
1621 ISFDropTarget_QueryInterface,
1622 ISFDropTarget_AddRef,
1623 ISFDropTarget_Release,
1624 ISFDropTarget_DragEnter,
1625 ISFDropTarget_DragOver,
1626 ISFDropTarget_DragLeave,
1627 ISFDropTarget_Drop