2 * IShellItem and IShellItemArray implementations
4 * Copyright 2008 Vincent Povirk for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
28 #define NONAMELESSUNION
32 #include "wine/debug.h"
35 #include "shell32_main.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
40 typedef struct _ShellItem
{
41 IShellItem2 IShellItem2_iface
;
44 IPersistIDList IPersistIDList_iface
;
47 typedef struct _CustomDestinationList
{
48 ICustomDestinationList ICustomDestinationList_iface
;
50 } CustomDestinationList
;
52 static inline ShellItem
*impl_from_IShellItem2(IShellItem2
*iface
)
54 return CONTAINING_RECORD(iface
, ShellItem
, IShellItem2_iface
);
57 static inline ShellItem
*impl_from_IPersistIDList( IPersistIDList
*iface
)
59 return CONTAINING_RECORD(iface
, ShellItem
, IPersistIDList_iface
);
62 static inline CustomDestinationList
*impl_from_ICustomDestinationList( ICustomDestinationList
*iface
)
64 return CONTAINING_RECORD(iface
, CustomDestinationList
, ICustomDestinationList_iface
);
67 static HRESULT WINAPI
ShellItem_QueryInterface(IShellItem2
*iface
, REFIID riid
,
70 ShellItem
*This
= impl_from_IShellItem2(iface
);
72 TRACE("(%p, %s, %p)\n", iface
, debugstr_guid(riid
), ppv
);
74 if (!ppv
) return E_INVALIDARG
;
76 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IShellItem
, riid
) ||
77 IsEqualIID(&IID_IShellItem2
, riid
))
79 *ppv
= &This
->IShellItem2_iface
;
81 else if (IsEqualIID(&IID_IPersist
, riid
) || IsEqualIID(&IID_IPersistIDList
, riid
))
83 *ppv
= &This
->IPersistIDList_iface
;
86 FIXME("not implemented for %s\n", shdebugstr_guid(riid
));
91 IUnknown_AddRef((IUnknown
*)*ppv
);
95 static ULONG WINAPI
ShellItem_AddRef(IShellItem2
*iface
)
97 ShellItem
*This
= impl_from_IShellItem2(iface
);
98 ULONG ref
= InterlockedIncrement(&This
->ref
);
100 TRACE("(%p), new refcount=%i\n", iface
, ref
);
105 static ULONG WINAPI
ShellItem_Release(IShellItem2
*iface
)
107 ShellItem
*This
= impl_from_IShellItem2(iface
);
108 ULONG ref
= InterlockedDecrement(&This
->ref
);
110 TRACE("(%p), new refcount=%i\n", iface
, ref
);
121 static HRESULT
ShellItem_get_parent_pidl(ShellItem
*This
, LPITEMIDLIST
*parent_pidl
)
123 *parent_pidl
= ILClone(This
->pidl
);
126 if (ILRemoveLastID(*parent_pidl
))
130 ILFree(*parent_pidl
);
138 return E_OUTOFMEMORY
;
142 static HRESULT
ShellItem_get_parent_shellfolder(ShellItem
*This
, IShellFolder
**ppsf
)
144 LPITEMIDLIST parent_pidl
;
145 IShellFolder
*desktop
;
148 ret
= ShellItem_get_parent_pidl(This
, &parent_pidl
);
151 ret
= SHGetDesktopFolder(&desktop
);
154 if (_ILIsDesktop(parent_pidl
))
160 ret
= IShellFolder_BindToObject(desktop
, parent_pidl
, NULL
, &IID_IShellFolder
, (void**)ppsf
);
161 IShellFolder_Release(desktop
);
170 static HRESULT
ShellItem_get_shellfolder(ShellItem
*This
, IBindCtx
*pbc
, IShellFolder
**ppsf
)
172 IShellFolder
*desktop
;
175 ret
= SHGetDesktopFolder(&desktop
);
178 if (_ILIsDesktop(This
->pidl
))
181 IShellFolder_AddRef(*ppsf
);
185 ret
= IShellFolder_BindToObject(desktop
, This
->pidl
, pbc
, &IID_IShellFolder
, (void**)ppsf
);
188 IShellFolder_Release(desktop
);
194 static HRESULT WINAPI
ShellItem_BindToHandler(IShellItem2
*iface
, IBindCtx
*pbc
,
195 REFGUID rbhid
, REFIID riid
, void **ppvOut
)
197 ShellItem
*This
= impl_from_IShellItem2(iface
);
199 TRACE("(%p,%p,%s,%p,%p)\n", iface
, pbc
, shdebugstr_guid(rbhid
), riid
, ppvOut
);
202 if (IsEqualGUID(rbhid
, &BHID_SFObject
))
205 ret
= ShellItem_get_shellfolder(This
, pbc
, &psf
);
208 ret
= IShellFolder_QueryInterface(psf
, riid
, ppvOut
);
209 IShellFolder_Release(psf
);
213 else if (IsEqualGUID(rbhid
, &BHID_SFUIObject
))
215 IShellFolder
*psf_parent
;
216 if (_ILIsDesktop(This
->pidl
))
217 ret
= SHGetDesktopFolder(&psf_parent
);
219 ret
= ShellItem_get_parent_shellfolder(This
, &psf_parent
);
223 LPCITEMIDLIST pidl
= ILFindLastID(This
->pidl
);
224 ret
= IShellFolder_GetUIObjectOf(psf_parent
, NULL
, 1, &pidl
, riid
, NULL
, ppvOut
);
225 IShellFolder_Release(psf_parent
);
229 else if (IsEqualGUID(rbhid
, &BHID_DataObject
))
231 return ShellItem_BindToHandler(&This
->IShellItem2_iface
, pbc
, &BHID_SFUIObject
,
232 &IID_IDataObject
, ppvOut
);
235 FIXME("Unsupported BHID %s.\n", debugstr_guid(rbhid
));
237 return MK_E_NOOBJECT
;
240 static HRESULT WINAPI
ShellItem_GetParent(IShellItem2
*iface
, IShellItem
**ppsi
)
242 ShellItem
*This
= impl_from_IShellItem2(iface
);
243 LPITEMIDLIST parent_pidl
;
246 TRACE("(%p,%p)\n", iface
, ppsi
);
248 ret
= ShellItem_get_parent_pidl(This
, &parent_pidl
);
251 ret
= SHCreateShellItem(NULL
, NULL
, parent_pidl
, ppsi
);
258 static HRESULT WINAPI
ShellItem_GetDisplayName(IShellItem2
*iface
, SIGDN sigdnName
,
261 ShellItem
*This
= impl_from_IShellItem2(iface
);
262 TRACE("(%p,%x,%p)\n", iface
, sigdnName
, ppszName
);
264 return SHGetNameFromIDList(This
->pidl
, sigdnName
, ppszName
);
267 static HRESULT WINAPI
ShellItem_GetAttributes(IShellItem2
*iface
, SFGAOF sfgaoMask
,
268 SFGAOF
*psfgaoAttribs
)
270 ShellItem
*This
= impl_from_IShellItem2(iface
);
271 IShellFolder
*parent_folder
;
272 LPITEMIDLIST child_pidl
;
275 TRACE("(%p,%x,%p)\n", iface
, sfgaoMask
, psfgaoAttribs
);
277 if (_ILIsDesktop(This
->pidl
))
278 ret
= SHGetDesktopFolder(&parent_folder
);
280 ret
= ShellItem_get_parent_shellfolder(This
, &parent_folder
);
283 child_pidl
= ILFindLastID(This
->pidl
);
284 *psfgaoAttribs
= sfgaoMask
;
285 ret
= IShellFolder_GetAttributesOf(parent_folder
, 1, (LPCITEMIDLIST
*)&child_pidl
, psfgaoAttribs
);
286 *psfgaoAttribs
&= sfgaoMask
;
287 IShellFolder_Release(parent_folder
);
291 if(sfgaoMask
== *psfgaoAttribs
)
301 static HRESULT WINAPI
ShellItem_Compare(IShellItem2
*iface
, IShellItem
*oth
,
302 SICHINTF hint
, int *piOrder
)
304 LPWSTR dispname
, dispname_oth
;
306 TRACE("(%p,%p,%x,%p)\n", iface
, oth
, hint
, piOrder
);
308 if(hint
& (SICHINT_CANONICAL
| SICHINT_ALLFIELDS
))
309 FIXME("Unsupported flags 0x%08x\n", hint
);
311 ret
= IShellItem2_GetDisplayName(iface
, SIGDN_DESKTOPABSOLUTEEDITING
, &dispname
);
314 ret
= IShellItem_GetDisplayName(oth
, SIGDN_DESKTOPABSOLUTEEDITING
, &dispname_oth
);
317 *piOrder
= lstrcmpiW(dispname
, dispname_oth
);
318 CoTaskMemFree(dispname_oth
);
320 CoTaskMemFree(dispname
);
323 if(SUCCEEDED(ret
) && *piOrder
&&
324 (hint
& SICHINT_TEST_FILESYSPATH_IF_NOT_EQUAL
))
326 LPWSTR dispname
, dispname_oth
;
328 TRACE("Testing filesystem path.\n");
329 ret
= IShellItem2_GetDisplayName(iface
, SIGDN_FILESYSPATH
, &dispname
);
332 ret
= IShellItem_GetDisplayName(oth
, SIGDN_FILESYSPATH
, &dispname_oth
);
335 *piOrder
= lstrcmpiW(dispname
, dispname_oth
);
336 CoTaskMemFree(dispname_oth
);
338 CoTaskMemFree(dispname
);
351 static HRESULT WINAPI
ShellItem2_GetPropertyStore(IShellItem2
*iface
, GETPROPERTYSTOREFLAGS flags
,
352 REFIID riid
, void **ppv
)
354 ShellItem
*This
= impl_from_IShellItem2(iface
);
355 FIXME("Stub: %p (%d, %s, %p)\n", This
, flags
, shdebugstr_guid(riid
), ppv
);
359 static HRESULT WINAPI
ShellItem2_GetPropertyStoreWithCreateObject(IShellItem2
*iface
,
360 GETPROPERTYSTOREFLAGS flags
, IUnknown
*punkCreateObject
, REFIID riid
, void **ppv
)
362 ShellItem
*This
= impl_from_IShellItem2(iface
);
363 FIXME("Stub: %p (%08x, %p, %s, %p)\n",
364 This
, flags
, punkCreateObject
, shdebugstr_guid(riid
), ppv
);
368 static HRESULT WINAPI
ShellItem2_GetPropertyStoreForKeys(IShellItem2
*iface
, const PROPERTYKEY
*rgKeys
,
369 UINT cKeys
, GETPROPERTYSTOREFLAGS flags
, REFIID riid
, void **ppv
)
371 ShellItem
*This
= impl_from_IShellItem2(iface
);
372 FIXME("Stub: %p (%p, %d, %08x, %s, %p)\n",
373 This
, rgKeys
, cKeys
, flags
, shdebugstr_guid(riid
), ppv
);
377 static HRESULT WINAPI
ShellItem2_GetPropertyDescriptionList(IShellItem2
*iface
,
378 REFPROPERTYKEY keyType
, REFIID riid
, void **ppv
)
380 ShellItem
*This
= impl_from_IShellItem2(iface
);
381 FIXME("Stub: %p (%p, %s, %p)\n", This
, keyType
, debugstr_guid(riid
), ppv
);
385 static HRESULT WINAPI
ShellItem2_Update(IShellItem2
*iface
, IBindCtx
*pbc
)
387 ShellItem
*This
= impl_from_IShellItem2(iface
);
388 FIXME("Stub: %p (%p)\n", This
, pbc
);
392 static HRESULT WINAPI
ShellItem2_GetProperty(IShellItem2
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*ppropvar
)
394 ShellItem
*This
= impl_from_IShellItem2(iface
);
395 FIXME("Stub: %p (%p, %p)\n", This
, key
, ppropvar
);
399 static HRESULT WINAPI
ShellItem2_GetCLSID(IShellItem2
*iface
, REFPROPERTYKEY key
, CLSID
*pclsid
)
401 ShellItem
*This
= impl_from_IShellItem2(iface
);
402 FIXME("Stub: %p (%p, %p)\n", This
, key
, pclsid
);
406 static HRESULT WINAPI
ShellItem2_GetFileTime(IShellItem2
*iface
, REFPROPERTYKEY key
, FILETIME
*pft
)
408 ShellItem
*This
= impl_from_IShellItem2(iface
);
409 FIXME("Stub: %p (%p, %p)\n", This
, key
, pft
);
413 static HRESULT WINAPI
ShellItem2_GetInt32(IShellItem2
*iface
, REFPROPERTYKEY key
, int *pi
)
415 ShellItem
*This
= impl_from_IShellItem2(iface
);
416 FIXME("Stub: %p (%p, %p)\n", This
, key
, pi
);
420 static HRESULT WINAPI
ShellItem2_GetString(IShellItem2
*iface
, REFPROPERTYKEY key
, LPWSTR
*ppsz
)
422 ShellItem
*This
= impl_from_IShellItem2(iface
);
423 FIXME("Stub: %p (%p, %p)\n", This
, key
, ppsz
);
427 static HRESULT WINAPI
ShellItem2_GetUInt32(IShellItem2
*iface
, REFPROPERTYKEY key
, ULONG
*pui
)
429 ShellItem
*This
= impl_from_IShellItem2(iface
);
430 FIXME("Stub: %p (%p, %p)\n", This
, key
, pui
);
434 static HRESULT WINAPI
ShellItem2_GetUInt64(IShellItem2
*iface
, REFPROPERTYKEY key
, ULONGLONG
*pull
)
436 ShellItem
*This
= impl_from_IShellItem2(iface
);
437 FIXME("Stub: %p (%p, %p)\n", This
, key
, pull
);
441 static HRESULT WINAPI
ShellItem2_GetBool(IShellItem2
*iface
, REFPROPERTYKEY key
, BOOL
*pf
)
443 ShellItem
*This
= impl_from_IShellItem2(iface
);
444 FIXME("Stub: %p (%p, %p)\n", This
, key
, pf
);
449 static const IShellItem2Vtbl ShellItem2_Vtbl
= {
450 ShellItem_QueryInterface
,
453 ShellItem_BindToHandler
,
455 ShellItem_GetDisplayName
,
456 ShellItem_GetAttributes
,
458 ShellItem2_GetPropertyStore
,
459 ShellItem2_GetPropertyStoreWithCreateObject
,
460 ShellItem2_GetPropertyStoreForKeys
,
461 ShellItem2_GetPropertyDescriptionList
,
463 ShellItem2_GetProperty
,
465 ShellItem2_GetFileTime
,
467 ShellItem2_GetString
,
468 ShellItem2_GetUInt32
,
469 ShellItem2_GetUInt64
,
473 static HRESULT WINAPI
ShellItem_IPersistIDList_QueryInterface(IPersistIDList
*iface
,
474 REFIID riid
, void **ppv
)
476 ShellItem
*This
= impl_from_IPersistIDList(iface
);
477 return IShellItem2_QueryInterface(&This
->IShellItem2_iface
, riid
, ppv
);
480 static ULONG WINAPI
ShellItem_IPersistIDList_AddRef(IPersistIDList
*iface
)
482 ShellItem
*This
= impl_from_IPersistIDList(iface
);
483 return IShellItem2_AddRef(&This
->IShellItem2_iface
);
486 static ULONG WINAPI
ShellItem_IPersistIDList_Release(IPersistIDList
*iface
)
488 ShellItem
*This
= impl_from_IPersistIDList(iface
);
489 return IShellItem2_Release(&This
->IShellItem2_iface
);
492 static HRESULT WINAPI
ShellItem_IPersistIDList_GetClassID(IPersistIDList
* iface
,
495 *pClassID
= CLSID_ShellItem
;
499 static HRESULT WINAPI
ShellItem_IPersistIDList_SetIDList(IPersistIDList
* iface
,
502 ShellItem
*This
= impl_from_IPersistIDList(iface
);
503 LPITEMIDLIST new_pidl
;
505 TRACE("(%p,%p)\n", This
, pidl
);
507 new_pidl
= ILClone(pidl
);
512 This
->pidl
= new_pidl
;
516 return E_OUTOFMEMORY
;
519 static HRESULT WINAPI
ShellItem_IPersistIDList_GetIDList(IPersistIDList
* iface
,
522 ShellItem
*This
= impl_from_IPersistIDList(iface
);
524 TRACE("(%p,%p)\n", This
, ppidl
);
526 *ppidl
= ILClone(This
->pidl
);
530 return E_OUTOFMEMORY
;
533 static const IPersistIDListVtbl ShellItem_IPersistIDList_Vtbl
= {
534 ShellItem_IPersistIDList_QueryInterface
,
535 ShellItem_IPersistIDList_AddRef
,
536 ShellItem_IPersistIDList_Release
,
537 ShellItem_IPersistIDList_GetClassID
,
538 ShellItem_IPersistIDList_SetIDList
,
539 ShellItem_IPersistIDList_GetIDList
543 HRESULT WINAPI
IShellItem_Constructor(IUnknown
*pUnkOuter
, REFIID riid
, void **ppv
)
548 TRACE("(%p,%s)\n",pUnkOuter
, debugstr_guid(riid
));
552 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
554 This
= heap_alloc(sizeof(*This
));
555 This
->IShellItem2_iface
.lpVtbl
= &ShellItem2_Vtbl
;
558 This
->IPersistIDList_iface
.lpVtbl
= &ShellItem_IPersistIDList_Vtbl
;
560 ret
= IShellItem2_QueryInterface(&This
->IShellItem2_iface
, riid
, ppv
);
561 IShellItem2_Release(&This
->IShellItem2_iface
);
566 HRESULT WINAPI
SHCreateShellItem(LPCITEMIDLIST pidlParent
,
567 IShellFolder
*psfParent
, LPCITEMIDLIST pidl
, IShellItem
**ppsi
)
569 LPITEMIDLIST new_pidl
;
572 TRACE("(%p,%p,%p,%p)\n", pidlParent
, psfParent
, pidl
, ppsi
);
580 else if (pidlParent
|| psfParent
)
582 LPITEMIDLIST temp_parent
=NULL
;
585 IPersistFolder2
* ppf2Parent
;
587 if (FAILED(IShellFolder_QueryInterface(psfParent
, &IID_IPersistFolder2
, (void**)&ppf2Parent
)))
589 FIXME("couldn't get IPersistFolder2 interface of parent\n");
590 return E_NOINTERFACE
;
593 if (FAILED(IPersistFolder2_GetCurFolder(ppf2Parent
, &temp_parent
)))
595 FIXME("couldn't get parent PIDL\n");
596 IPersistFolder2_Release(ppf2Parent
);
597 return E_NOINTERFACE
;
600 pidlParent
= temp_parent
;
601 IPersistFolder2_Release(ppf2Parent
);
604 new_pidl
= ILCombine(pidlParent
, pidl
);
608 return E_OUTOFMEMORY
;
612 new_pidl
= ILClone(pidl
);
614 return E_OUTOFMEMORY
;
617 ret
= SHCreateItemFromIDList(new_pidl
, &IID_IShellItem
, (void**)ppsi
);
623 HRESULT WINAPI
SHCreateItemFromParsingName(PCWSTR pszPath
,
624 IBindCtx
*pbc
, REFIID riid
, void **ppv
)
631 ret
= SHParseDisplayName(pszPath
, pbc
, &pidl
, 0, NULL
);
634 ret
= SHCreateItemFromIDList(pidl
, riid
, ppv
);
640 HRESULT WINAPI
SHCreateItemFromRelativeName(IShellItem
*parent
, PCWSTR name
, IBindCtx
*pbc
,
641 REFIID riid
, void **ppv
)
643 LPITEMIDLIST pidl_folder
= NULL
, pidl
= NULL
;
644 IShellFolder
*desktop
= NULL
, *folder
= NULL
;
647 TRACE("(%p, %s, %p, %s, %p)\n", parent
, wine_dbgstr_w(name
), pbc
, debugstr_guid(riid
), ppv
);
655 hr
= SHGetIDListFromObject((IUnknown
*)parent
, &pidl_folder
);
659 hr
= SHGetDesktopFolder(&desktop
);
663 if(!_ILIsDesktop(pidl_folder
))
665 hr
= IShellFolder_BindToObject(desktop
, pidl_folder
, NULL
, &IID_IShellFolder
,
671 hr
= IShellFolder_ParseDisplayName(folder
? folder
: desktop
, NULL
, pbc
, (LPWSTR
)name
,
675 hr
= SHCreateItemFromIDList(pidl
, riid
, ppv
);
683 IShellFolder_Release(desktop
);
685 IShellFolder_Release(folder
);
689 HRESULT WINAPI
SHCreateItemFromIDList(PCIDLIST_ABSOLUTE pidl
, REFIID riid
, void **ppv
)
691 IPersistIDList
*persist
;
698 ret
= IShellItem_Constructor(NULL
, &IID_IPersistIDList
, (void**)&persist
);
702 ret
= IPersistIDList_SetIDList(persist
, pidl
);
705 IPersistIDList_Release(persist
);
709 ret
= IPersistIDList_QueryInterface(persist
, riid
, ppv
);
710 IPersistIDList_Release(persist
);
714 HRESULT WINAPI
SHCreateItemInKnownFolder(REFKNOWNFOLDERID rfid
, DWORD flags
,
715 PCWSTR filename
, REFIID riid
, void **ppv
)
718 IShellItem
*parent
= NULL
;
719 LPITEMIDLIST pidl
= NULL
;
721 TRACE("(%p, %x, %s, %s, %p)\n", rfid
, flags
, wine_dbgstr_w(filename
),
722 debugstr_guid(riid
), ppv
);
728 hr
= SHGetKnownFolderIDList(rfid
, flags
, NULL
, &pidl
);
732 hr
= SHCreateItemFromIDList(pidl
, &IID_IShellItem
, (void**)&parent
);
740 hr
= SHCreateItemFromRelativeName(parent
, filename
, NULL
, riid
, ppv
);
742 hr
= IShellItem_QueryInterface(parent
, riid
, ppv
);
745 IShellItem_Release(parent
);
749 HRESULT WINAPI
SHGetItemFromDataObject(IDataObject
*pdtobj
,
750 DATAOBJ_GET_ITEM_FLAGS dwFlags
, REFIID riid
, void **ppv
)
756 TRACE("%p, %x, %s, %p\n", pdtobj
, dwFlags
, debugstr_guid(riid
), ppv
);
761 fmt
.cfFormat
= RegisterClipboardFormatW(CFSTR_SHELLIDLISTW
);
763 fmt
.dwAspect
= DVASPECT_CONTENT
;
765 fmt
.tymed
= TYMED_HGLOBAL
;
767 ret
= IDataObject_GetData(pdtobj
, &fmt
, &medium
);
770 LPIDA pida
= GlobalLock(medium
.u
.hGlobal
);
772 if((pida
->cidl
> 1 && !(dwFlags
& DOGIF_ONLY_IF_ONE
)) ||
777 /* Get the first pidl (parent + child1) */
778 pidl
= ILCombine((LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]),
779 (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[1]));
781 ret
= SHCreateItemFromIDList(pidl
, riid
, ppv
);
789 GlobalUnlock(medium
.u
.hGlobal
);
790 GlobalFree(medium
.u
.hGlobal
);
793 if(FAILED(ret
) && !(dwFlags
& DOGIF_NO_HDROP
))
795 TRACE("Attempting to fall back on CF_HDROP.\n");
797 fmt
.cfFormat
= CF_HDROP
;
799 fmt
.dwAspect
= DVASPECT_CONTENT
;
801 fmt
.tymed
= TYMED_HGLOBAL
;
803 ret
= IDataObject_GetData(pdtobj
, &fmt
, &medium
);
806 DROPFILES
*df
= GlobalLock(medium
.u
.hGlobal
);
807 LPBYTE files
= (LPBYTE
)df
+ df
->pFiles
;
808 BOOL multiple_files
= FALSE
;
813 WCHAR filename
[MAX_PATH
];
814 PCSTR first_file
= (PCSTR
)files
;
815 if(*(files
+ lstrlenA(first_file
) + 1) != 0)
816 multiple_files
= TRUE
;
818 if( !(multiple_files
&& (dwFlags
& DOGIF_ONLY_IF_ONE
)) )
820 MultiByteToWideChar(CP_ACP
, 0, first_file
, -1, filename
, MAX_PATH
);
821 ret
= SHCreateItemFromParsingName(filename
, NULL
, riid
, ppv
);
826 PCWSTR first_file
= (PCWSTR
)files
;
827 if(*((PCWSTR
)files
+ lstrlenW(first_file
) + 1) != 0)
828 multiple_files
= TRUE
;
830 if( !(multiple_files
&& (dwFlags
& DOGIF_ONLY_IF_ONE
)) )
831 ret
= SHCreateItemFromParsingName(first_file
, NULL
, riid
, ppv
);
834 GlobalUnlock(medium
.u
.hGlobal
);
835 GlobalFree(medium
.u
.hGlobal
);
839 if(FAILED(ret
) && !(dwFlags
& DOGIF_NO_URL
))
841 FIXME("Failed to create item, should try CF_URL.\n");
847 HRESULT WINAPI
SHGetItemFromObject(IUnknown
*punk
, REFIID riid
, void **ppv
)
852 ret
= SHGetIDListFromObject(punk
, &pidl
);
855 ret
= SHCreateItemFromIDList(pidl
, riid
, ppv
);
862 /*************************************************************************
863 * IEnumShellItems implementation
866 IEnumShellItems IEnumShellItems_iface
;
869 IShellItemArray
*array
;
872 } IEnumShellItemsImpl
;
874 static inline IEnumShellItemsImpl
*impl_from_IEnumShellItems(IEnumShellItems
*iface
)
876 return CONTAINING_RECORD(iface
, IEnumShellItemsImpl
, IEnumShellItems_iface
);
879 static HRESULT WINAPI
IEnumShellItems_fnQueryInterface(IEnumShellItems
*iface
,
883 IEnumShellItemsImpl
*This
= impl_from_IEnumShellItems(iface
);
884 TRACE("%p (%s, %p)\n", This
, shdebugstr_guid(riid
), ppvObject
);
887 if(IsEqualIID(riid
, &IID_IEnumShellItems
) ||
888 IsEqualIID(riid
, &IID_IUnknown
))
890 *ppvObject
= &This
->IEnumShellItems_iface
;
895 IUnknown_AddRef((IUnknown
*)*ppvObject
);
899 return E_NOINTERFACE
;
902 static ULONG WINAPI
IEnumShellItems_fnAddRef(IEnumShellItems
*iface
)
904 IEnumShellItemsImpl
*This
= impl_from_IEnumShellItems(iface
);
905 LONG ref
= InterlockedIncrement(&This
->ref
);
906 TRACE("%p - ref %d\n", This
, ref
);
911 static ULONG WINAPI
IEnumShellItems_fnRelease(IEnumShellItems
*iface
)
913 IEnumShellItemsImpl
*This
= impl_from_IEnumShellItems(iface
);
914 LONG ref
= InterlockedDecrement(&This
->ref
);
915 TRACE("%p - ref %d\n", This
, ref
);
920 IShellItemArray_Release(This
->array
);
928 static HRESULT WINAPI
IEnumShellItems_fnNext(IEnumShellItems
* iface
,
933 IEnumShellItemsImpl
*This
= impl_from_IEnumShellItems(iface
);
934 HRESULT hr
= S_FALSE
;
937 TRACE("%p (%d %p %p)\n", This
, celt
, rgelt
, pceltFetched
);
939 if(pceltFetched
== NULL
&& celt
!= 1)
942 for(i
= This
->position
; fetched
< celt
&& i
< This
->count
; i
++) {
943 hr
= IShellItemArray_GetItemAt(This
->array
, i
, &rgelt
[fetched
]);
952 if(pceltFetched
!= NULL
)
953 *pceltFetched
= fetched
;
964 static HRESULT WINAPI
IEnumShellItems_fnSkip(IEnumShellItems
* iface
, ULONG celt
)
966 IEnumShellItemsImpl
*This
= impl_from_IEnumShellItems(iface
);
967 TRACE("%p (%d)\n", This
, celt
);
969 This
->position
= min(This
->position
+ celt
, This
->count
-1);
974 static HRESULT WINAPI
IEnumShellItems_fnReset(IEnumShellItems
* iface
)
976 IEnumShellItemsImpl
*This
= impl_from_IEnumShellItems(iface
);
984 static HRESULT WINAPI
IEnumShellItems_fnClone(IEnumShellItems
* iface
, IEnumShellItems
**ppenum
)
986 IEnumShellItemsImpl
*This
= impl_from_IEnumShellItems(iface
);
987 TRACE("%p (%p)\n", This
, ppenum
);
989 /* Not implemented anywhere */
995 static const IEnumShellItemsVtbl vt_IEnumShellItems
= {
996 IEnumShellItems_fnQueryInterface
,
997 IEnumShellItems_fnAddRef
,
998 IEnumShellItems_fnRelease
,
999 IEnumShellItems_fnNext
,
1000 IEnumShellItems_fnSkip
,
1001 IEnumShellItems_fnReset
,
1002 IEnumShellItems_fnClone
1005 static HRESULT
IEnumShellItems_Constructor(IShellItemArray
*array
, IEnumShellItems
**ppesi
)
1007 IEnumShellItemsImpl
*This
;
1010 This
= heap_alloc(sizeof(*This
));
1012 return E_OUTOFMEMORY
;
1015 This
->IEnumShellItems_iface
.lpVtbl
= &vt_IEnumShellItems
;
1016 This
->array
= array
;
1019 IShellItemArray_AddRef(This
->array
);
1020 IShellItemArray_GetCount(This
->array
, &This
->count
);
1022 ret
= IEnumShellItems_QueryInterface(&This
->IEnumShellItems_iface
, &IID_IEnumShellItems
, (void**)ppesi
);
1023 IEnumShellItems_Release(&This
->IEnumShellItems_iface
);
1029 /*************************************************************************
1030 * IShellItemArray implementation
1033 IShellItemArray IShellItemArray_iface
;
1038 } IShellItemArrayImpl
;
1040 static inline IShellItemArrayImpl
*impl_from_IShellItemArray(IShellItemArray
*iface
)
1042 return CONTAINING_RECORD(iface
, IShellItemArrayImpl
, IShellItemArray_iface
);
1045 static HRESULT WINAPI
IShellItemArray_fnQueryInterface(IShellItemArray
*iface
,
1049 IShellItemArrayImpl
*This
= impl_from_IShellItemArray(iface
);
1050 TRACE("%p (%s, %p)\n", This
, shdebugstr_guid(riid
), ppvObject
);
1053 if(IsEqualIID(riid
, &IID_IShellItemArray
) ||
1054 IsEqualIID(riid
, &IID_IUnknown
))
1056 *ppvObject
= &This
->IShellItemArray_iface
;
1061 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1065 return E_NOINTERFACE
;
1068 static ULONG WINAPI
IShellItemArray_fnAddRef(IShellItemArray
*iface
)
1070 IShellItemArrayImpl
*This
= impl_from_IShellItemArray(iface
);
1071 LONG ref
= InterlockedIncrement(&This
->ref
);
1072 TRACE("%p - ref %d\n", This
, ref
);
1077 static ULONG WINAPI
IShellItemArray_fnRelease(IShellItemArray
*iface
)
1079 IShellItemArrayImpl
*This
= impl_from_IShellItemArray(iface
);
1080 LONG ref
= InterlockedDecrement(&This
->ref
);
1081 TRACE("%p - ref %d\n", This
, ref
);
1086 TRACE("Freeing.\n");
1088 for(i
= 0; i
< This
->item_count
; i
++)
1089 IShellItem_Release(This
->array
[i
]);
1091 heap_free(This
->array
);
1099 static HRESULT WINAPI
IShellItemArray_fnBindToHandler(IShellItemArray
*iface
,
1105 IShellItemArrayImpl
*This
= impl_from_IShellItemArray(iface
);
1106 FIXME("Stub: %p (%p, %s, %s, %p)\n",
1107 This
, pbc
, shdebugstr_guid(bhid
), shdebugstr_guid(riid
), ppvOut
);
1112 static HRESULT WINAPI
IShellItemArray_fnGetPropertyStore(IShellItemArray
*iface
,
1113 GETPROPERTYSTOREFLAGS flags
,
1117 IShellItemArrayImpl
*This
= impl_from_IShellItemArray(iface
);
1118 FIXME("Stub: %p (%x, %s, %p)\n", This
, flags
, shdebugstr_guid(riid
), ppv
);
1123 static HRESULT WINAPI
IShellItemArray_fnGetPropertyDescriptionList(IShellItemArray
*iface
,
1124 REFPROPERTYKEY keyType
,
1128 IShellItemArrayImpl
*This
= impl_from_IShellItemArray(iface
);
1129 FIXME("Stub: %p (%p, %s, %p)\n",
1130 This
, keyType
, shdebugstr_guid(riid
), ppv
);
1135 static HRESULT WINAPI
IShellItemArray_fnGetAttributes(IShellItemArray
*iface
,
1136 SIATTRIBFLAGS AttribFlags
,
1138 SFGAOF
*psfgaoAttribs
)
1140 IShellItemArrayImpl
*This
= impl_from_IShellItemArray(iface
);
1144 TRACE("%p (%x, %x, %p)\n", This
, AttribFlags
, sfgaoMask
, psfgaoAttribs
);
1146 if(AttribFlags
& ~(SIATTRIBFLAGS_AND
|SIATTRIBFLAGS_OR
))
1147 FIXME("%08x contains unsupported attribution flags\n", AttribFlags
);
1149 for(i
= 0; i
< This
->item_count
; i
++)
1151 hr
= IShellItem_GetAttributes(This
->array
[i
], sfgaoMask
, &attr
);
1157 *psfgaoAttribs
= attr
;
1161 switch(AttribFlags
& SIATTRIBFLAGS_MASK
)
1163 case SIATTRIBFLAGS_AND
:
1164 *psfgaoAttribs
&= attr
;
1166 case SIATTRIBFLAGS_OR
:
1167 *psfgaoAttribs
|= attr
;
1174 if(*psfgaoAttribs
== sfgaoMask
)
1183 static HRESULT WINAPI
IShellItemArray_fnGetCount(IShellItemArray
*iface
,
1186 IShellItemArrayImpl
*This
= impl_from_IShellItemArray(iface
);
1187 TRACE("%p (%p)\n", This
, pdwNumItems
);
1189 *pdwNumItems
= This
->item_count
;
1194 static HRESULT WINAPI
IShellItemArray_fnGetItemAt(IShellItemArray
*iface
,
1198 IShellItemArrayImpl
*This
= impl_from_IShellItemArray(iface
);
1199 TRACE("%p (%x, %p)\n", This
, dwIndex
, ppsi
);
1202 if(dwIndex
+ 1 > This
->item_count
)
1205 *ppsi
= This
->array
[dwIndex
];
1206 IShellItem_AddRef(*ppsi
);
1211 static HRESULT WINAPI
IShellItemArray_fnEnumItems(IShellItemArray
*iface
,
1212 IEnumShellItems
**ppenumShellItems
)
1214 IShellItemArrayImpl
*This
= impl_from_IShellItemArray(iface
);
1215 TRACE("%p (%p)\n", This
, ppenumShellItems
);
1216 return IEnumShellItems_Constructor(iface
, ppenumShellItems
);
1219 static const IShellItemArrayVtbl vt_IShellItemArray
= {
1220 IShellItemArray_fnQueryInterface
,
1221 IShellItemArray_fnAddRef
,
1222 IShellItemArray_fnRelease
,
1223 IShellItemArray_fnBindToHandler
,
1224 IShellItemArray_fnGetPropertyStore
,
1225 IShellItemArray_fnGetPropertyDescriptionList
,
1226 IShellItemArray_fnGetAttributes
,
1227 IShellItemArray_fnGetCount
,
1228 IShellItemArray_fnGetItemAt
,
1229 IShellItemArray_fnEnumItems
1232 /* Caller is responsible to AddRef all items */
1233 static HRESULT
create_shellitemarray(IShellItem
**items
, DWORD count
, IShellItemArray
**ret
)
1235 IShellItemArrayImpl
*This
;
1237 TRACE("(%p, %d, %p)\n", items
, count
, ret
);
1239 This
= heap_alloc(sizeof(*This
));
1241 return E_OUTOFMEMORY
;
1243 This
->IShellItemArray_iface
.lpVtbl
= &vt_IShellItemArray
;
1246 This
->array
= heap_alloc(count
*sizeof(IShellItem
*));
1250 return E_OUTOFMEMORY
;
1252 memcpy(This
->array
, items
, count
*sizeof(IShellItem
*));
1253 This
->item_count
= count
;
1255 *ret
= &This
->IShellItemArray_iface
;
1259 HRESULT WINAPI
SHCreateShellItemArray(PCIDLIST_ABSOLUTE pidlParent
,
1262 PCUITEMID_CHILD_ARRAY ppidl
,
1263 IShellItemArray
**ppsiItemArray
)
1266 HRESULT ret
= E_FAIL
;
1269 TRACE("%p, %p, %d, %p, %p\n", pidlParent
, psf
, cidl
, ppidl
, ppsiItemArray
);
1271 *ppsiItemArray
= NULL
;
1273 if(!pidlParent
&& !psf
)
1277 return E_INVALIDARG
;
1279 array
= heap_alloc_zero(cidl
*sizeof(IShellItem
*));
1281 return E_OUTOFMEMORY
;
1283 for(i
= 0; i
< cidl
; i
++)
1285 ret
= SHCreateShellItem(pidlParent
, psf
, ppidl
[i
], &array
[i
]);
1286 if(FAILED(ret
)) break;
1291 ret
= create_shellitemarray(array
, cidl
, ppsiItemArray
);
1297 /* Something failed, clean up. */
1298 for(i
= 0; i
< cidl
; i
++)
1299 if(array
[i
]) IShellItem_Release(array
[i
]);
1304 HRESULT WINAPI
SHCreateShellItemArrayFromShellItem(IShellItem
*item
, REFIID riid
, void **ppv
)
1306 IShellItemArray
*array
;
1309 TRACE("%p, %s, %p\n", item
, shdebugstr_guid(riid
), ppv
);
1313 IShellItem_AddRef(item
);
1314 ret
= create_shellitemarray(&item
, 1, &array
);
1317 IShellItem_Release(item
);
1321 ret
= IShellItemArray_QueryInterface(array
, riid
, ppv
);
1322 IShellItemArray_Release(array
);
1326 HRESULT WINAPI
SHCreateShellItemArrayFromDataObject(IDataObject
*pdo
, REFIID riid
, void **ppv
)
1328 IShellItemArray
*psia
;
1333 TRACE("%p, %s, %p\n", pdo
, shdebugstr_guid(riid
), ppv
);
1336 return E_INVALIDARG
;
1340 fmt
.cfFormat
= RegisterClipboardFormatW(CFSTR_SHELLIDLISTW
);
1342 fmt
.dwAspect
= DVASPECT_CONTENT
;
1344 fmt
.tymed
= TYMED_HGLOBAL
;
1346 ret
= IDataObject_GetData(pdo
, &fmt
, &medium
);
1349 LPIDA pida
= GlobalLock(medium
.u
.hGlobal
);
1350 LPCITEMIDLIST parent_pidl
;
1351 LPCITEMIDLIST
*children
;
1353 TRACE("Converting %d objects.\n", pida
->cidl
);
1355 parent_pidl
= (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[0]);
1357 children
= heap_alloc(sizeof(LPCITEMIDLIST
)*pida
->cidl
);
1358 for(i
= 0; i
< pida
->cidl
; i
++)
1359 children
[i
] = (LPCITEMIDLIST
) ((LPBYTE
)pida
+pida
->aoffset
[i
+1]);
1361 ret
= SHCreateShellItemArray(parent_pidl
, NULL
, pida
->cidl
, children
, &psia
);
1363 heap_free(children
);
1365 GlobalUnlock(medium
.u
.hGlobal
);
1366 GlobalFree(medium
.u
.hGlobal
);
1371 ret
= IShellItemArray_QueryInterface(psia
, riid
, ppv
);
1372 IShellItemArray_Release(psia
);
1378 HRESULT WINAPI
SHCreateShellItemArrayFromIDLists(UINT cidl
,
1379 PCIDLIST_ABSOLUTE_ARRAY pidl_array
,
1380 IShellItemArray
**psia
)
1385 TRACE("%d, %p, %p\n", cidl
, pidl_array
, psia
);
1390 return E_INVALIDARG
;
1392 array
= heap_alloc_zero(cidl
*sizeof(IShellItem
*));
1394 return E_OUTOFMEMORY
;
1396 for(i
= 0; i
< cidl
; i
++)
1398 ret
= SHCreateShellItem(NULL
, NULL
, pidl_array
[i
], &array
[i
]);
1405 ret
= create_shellitemarray(array
, cidl
, psia
);
1411 for(i
= 0; i
< cidl
; i
++)
1412 if(array
[i
]) IShellItem_Release(array
[i
]);
1418 HRESULT WINAPI
SHGetPropertyStoreFromParsingName(const WCHAR
*path
, IBindCtx
*pbc
, GETPROPERTYSTOREFLAGS flags
,
1419 REFIID riid
, void **ppv
)
1424 TRACE("(%s %p %#x %p %p)\n", debugstr_w(path
), pbc
, flags
, riid
, ppv
);
1426 hr
= SHCreateItemFromParsingName(path
, pbc
, &IID_IShellItem2
, (void **)&item
);
1429 hr
= IShellItem2_GetPropertyStore(item
, flags
, riid
, ppv
);
1430 IShellItem2_Release(item
);
1436 static HRESULT WINAPI
CustomDestinationList_QueryInterface(ICustomDestinationList
*iface
, REFIID riid
, void **obj
)
1438 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1440 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), obj
);
1442 if (IsEqualIID(&IID_ICustomDestinationList
, riid
) || IsEqualIID(&IID_IUnknown
, riid
))
1444 *obj
= &This
->ICustomDestinationList_iface
;
1447 FIXME("not implemented for %s\n", shdebugstr_guid(riid
));
1449 return E_NOINTERFACE
;
1452 IUnknown_AddRef((IUnknown
*)*obj
);
1456 static ULONG WINAPI
CustomDestinationList_AddRef(ICustomDestinationList
*iface
)
1458 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1459 ULONG ref
= InterlockedIncrement(&This
->ref
);
1461 TRACE("(%p), new refcount=%i\n", This
, ref
);
1466 static ULONG WINAPI
CustomDestinationList_Release(ICustomDestinationList
*iface
)
1468 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1469 ULONG ref
= InterlockedDecrement(&This
->ref
);
1471 TRACE("(%p), new refcount=%i\n", This
, ref
);
1479 static HRESULT WINAPI
CustomDestinationList_SetAppID(ICustomDestinationList
*iface
, const WCHAR
*appid
)
1481 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1483 FIXME("%p (%s): stub\n", This
, debugstr_w(appid
));
1488 static HRESULT WINAPI
CustomDestinationList_BeginList(ICustomDestinationList
*iface
, UINT
*min_slots
, REFIID riid
, void **obj
)
1490 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1492 FIXME("%p (%p %s %p): stub\n", This
, min_slots
, debugstr_guid(riid
), obj
);
1497 static HRESULT WINAPI
CustomDestinationList_AppendCategory(ICustomDestinationList
*iface
, const WCHAR
*category
, IObjectArray
*array
)
1499 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1501 FIXME("%p (%s %p): stub\n", This
, debugstr_w(category
), array
);
1506 static HRESULT WINAPI
CustomDestinationList_AppendKnownCategory(ICustomDestinationList
*iface
, KNOWNDESTCATEGORY category
)
1508 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1510 FIXME("%p (%d): stub\n", This
, category
);
1515 static HRESULT WINAPI
CustomDestinationList_AddUserTasks(ICustomDestinationList
*iface
, IObjectArray
*tasks
)
1517 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1519 FIXME("%p (%p): stub\n", This
, tasks
);
1524 static HRESULT WINAPI
CustomDestinationList_CommitList(ICustomDestinationList
*iface
)
1526 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1528 FIXME("%p: stub\n", This
);
1533 static HRESULT WINAPI
CustomDestinationList_GetRemovedDestinations(ICustomDestinationList
*iface
, REFIID riid
, void **obj
)
1535 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1537 FIXME("%p (%s %p): stub\n", This
, debugstr_guid(riid
), obj
);
1542 static HRESULT WINAPI
CustomDestinationList_DeleteList(ICustomDestinationList
*iface
, const WCHAR
*appid
)
1544 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1546 FIXME("%p (%s): stub\n", This
, debugstr_w(appid
));
1551 static HRESULT WINAPI
CustomDestinationList_AbortList(ICustomDestinationList
*iface
)
1553 CustomDestinationList
*This
= impl_from_ICustomDestinationList(iface
);
1555 FIXME("%p: stub\n", This
);
1560 static const ICustomDestinationListVtbl CustomDestinationListVtbl
=
1562 CustomDestinationList_QueryInterface
,
1563 CustomDestinationList_AddRef
,
1564 CustomDestinationList_Release
,
1565 CustomDestinationList_SetAppID
,
1566 CustomDestinationList_BeginList
,
1567 CustomDestinationList_AppendCategory
,
1568 CustomDestinationList_AppendKnownCategory
,
1569 CustomDestinationList_AddUserTasks
,
1570 CustomDestinationList_CommitList
,
1571 CustomDestinationList_GetRemovedDestinations
,
1572 CustomDestinationList_DeleteList
,
1573 CustomDestinationList_AbortList
1576 HRESULT WINAPI
CustomDestinationList_Constructor(IUnknown
*outer
, REFIID riid
, void **obj
)
1578 CustomDestinationList
*list
;
1581 TRACE("%p %s %p\n", outer
, debugstr_guid(riid
), obj
);
1584 return CLASS_E_NOAGGREGATION
;
1586 if(!(list
= heap_alloc(sizeof(*list
))))
1587 return E_OUTOFMEMORY
;
1589 list
->ICustomDestinationList_iface
.lpVtbl
= &CustomDestinationListVtbl
;
1592 hr
= ICustomDestinationList_QueryInterface(&list
->ICustomDestinationList_iface
, riid
, obj
);
1593 ICustomDestinationList_Release(&list
->ICustomDestinationList_iface
);