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
29 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
36 #include "shell32_main.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(shell);
41 typedef struct _ShellItem {
42 IShellItem2 IShellItem2_iface;
45 IPersistIDList IPersistIDList_iface;
48 static inline ShellItem *impl_from_IShellItem2(IShellItem2 *iface)
50 return CONTAINING_RECORD(iface, ShellItem, IShellItem2_iface);
54 static inline ShellItem *impl_from_IPersistIDList( IPersistIDList *iface )
56 return CONTAINING_RECORD(iface, ShellItem, IPersistIDList_iface);
60 static HRESULT WINAPI ShellItem_QueryInterface(IShellItem2 *iface, REFIID riid,
63 ShellItem *This = impl_from_IShellItem2(iface);
65 TRACE("(%p,%p,%p)\n", iface, riid, ppv);
67 if (!ppv) return E_INVALIDARG;
69 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellItem, riid) ||
70 IsEqualIID(&IID_IShellItem2, riid))
74 else if (IsEqualIID(&IID_IPersist, riid) || IsEqualIID(&IID_IPersistIDList, riid))
76 *ppv = &This->IPersistIDList_iface;
79 FIXME("not implemented for %s\n", shdebugstr_guid(riid));
84 IUnknown_AddRef((IUnknown*)*ppv);
88 static ULONG WINAPI ShellItem_AddRef(IShellItem2 *iface)
90 ShellItem *This = impl_from_IShellItem2(iface);
91 ULONG ref = InterlockedIncrement(&This->ref);
93 TRACE("(%p), new refcount=%i\n", iface, ref);
98 static ULONG WINAPI ShellItem_Release(IShellItem2 *iface)
100 ShellItem *This = impl_from_IShellItem2(iface);
101 ULONG ref = InterlockedDecrement(&This->ref);
103 TRACE("(%p), new refcount=%i\n", iface, ref);
108 HeapFree(GetProcessHeap(), 0, This);
114 static HRESULT ShellItem_get_parent_pidl(ShellItem *This, LPITEMIDLIST *parent_pidl)
116 *parent_pidl = ILClone(This->pidl);
119 if (ILRemoveLastID(*parent_pidl))
123 ILFree(*parent_pidl);
131 return E_OUTOFMEMORY;
135 static HRESULT ShellItem_get_parent_shellfolder(ShellItem *This, IShellFolder **ppsf)
137 LPITEMIDLIST parent_pidl;
138 IShellFolder *desktop;
141 ret = ShellItem_get_parent_pidl(This, &parent_pidl);
144 ret = SHGetDesktopFolder(&desktop);
147 ret = IShellFolder_BindToObject(desktop, parent_pidl, NULL, &IID_IShellFolder, (void**)ppsf);
148 IShellFolder_Release(desktop);
156 static HRESULT ShellItem_get_shellfolder(ShellItem *This, IBindCtx *pbc, IShellFolder **ppsf)
158 IShellFolder *desktop;
161 ret = SHGetDesktopFolder(&desktop);
164 if (_ILIsDesktop(This->pidl))
167 IShellFolder_AddRef(*ppsf);
171 ret = IShellFolder_BindToObject(desktop, This->pidl, pbc, &IID_IShellFolder, (void**)ppsf);
174 IShellFolder_Release(desktop);
180 static HRESULT WINAPI ShellItem_BindToHandler(IShellItem2 *iface, IBindCtx *pbc,
181 REFGUID rbhid, REFIID riid, void **ppvOut)
183 ShellItem *This = impl_from_IShellItem2(iface);
185 TRACE("(%p,%p,%s,%p,%p)\n", iface, pbc, shdebugstr_guid(rbhid), riid, ppvOut);
188 if (IsEqualGUID(rbhid, &BHID_SFObject))
191 ret = ShellItem_get_shellfolder(This, pbc, &psf);
194 ret = IShellFolder_QueryInterface(psf, riid, ppvOut);
195 IShellFolder_Release(psf);
199 else if (IsEqualGUID(rbhid, &BHID_SFUIObject))
201 IShellFolder *psf_parent;
202 if (_ILIsDesktop(This->pidl))
203 ret = SHGetDesktopFolder(&psf_parent);
205 ret = ShellItem_get_parent_shellfolder(This, &psf_parent);
209 LPCITEMIDLIST pidl = ILFindLastID(This->pidl);
210 ret = IShellFolder_GetUIObjectOf(psf_parent, NULL, 1, &pidl, riid, NULL, ppvOut);
211 IShellFolder_Release(psf_parent);
215 else if (IsEqualGUID(rbhid, &BHID_DataObject))
217 return ShellItem_BindToHandler(&This->IShellItem2_iface, pbc, &BHID_SFUIObject,
218 &IID_IDataObject, ppvOut);
221 FIXME("Unsupported BHID %s.\n", debugstr_guid(rbhid));
223 return MK_E_NOOBJECT;
226 static HRESULT WINAPI ShellItem_GetParent(IShellItem2 *iface, IShellItem **ppsi)
228 ShellItem *This = impl_from_IShellItem2(iface);
229 LPITEMIDLIST parent_pidl;
232 TRACE("(%p,%p)\n", iface, ppsi);
234 ret = ShellItem_get_parent_pidl(This, &parent_pidl);
237 ret = SHCreateShellItem(NULL, NULL, parent_pidl, ppsi);
244 static HRESULT WINAPI ShellItem_GetDisplayName(IShellItem2 *iface, SIGDN sigdnName,
247 ShellItem *This = impl_from_IShellItem2(iface);
248 TRACE("(%p,%x,%p)\n", iface, sigdnName, ppszName);
250 return SHGetNameFromIDList(This->pidl, sigdnName, ppszName);
253 static HRESULT WINAPI ShellItem_GetAttributes(IShellItem2 *iface, SFGAOF sfgaoMask,
254 SFGAOF *psfgaoAttribs)
256 ShellItem *This = impl_from_IShellItem2(iface);
257 IShellFolder *parent_folder;
258 LPITEMIDLIST child_pidl;
261 TRACE("(%p,%x,%p)\n", iface, sfgaoMask, psfgaoAttribs);
263 if (_ILIsDesktop(This->pidl))
264 ret = SHGetDesktopFolder(&parent_folder);
266 ret = ShellItem_get_parent_shellfolder(This, &parent_folder);
269 child_pidl = ILFindLastID(This->pidl);
270 *psfgaoAttribs = sfgaoMask;
271 ret = IShellFolder_GetAttributesOf(parent_folder, 1, (LPCITEMIDLIST*)&child_pidl, psfgaoAttribs);
272 IShellFolder_Release(parent_folder);
278 static HRESULT WINAPI ShellItem_Compare(IShellItem2 *iface, IShellItem *oth,
279 SICHINTF hint, int *piOrder)
281 LPWSTR dispname, dispname_oth;
283 TRACE("(%p,%p,%x,%p)\n", iface, oth, hint, piOrder);
285 if(hint & (SICHINT_CANONICAL | SICHINT_ALLFIELDS))
286 FIXME("Unsupported flags 0x%08x\n", hint);
288 ret = IShellItem_GetDisplayName(iface, SIGDN_DESKTOPABSOLUTEEDITING, &dispname);
291 ret = IShellItem_GetDisplayName(oth, SIGDN_DESKTOPABSOLUTEEDITING, &dispname_oth);
294 *piOrder = lstrcmpiW(dispname, dispname_oth);
295 CoTaskMemFree(dispname_oth);
297 CoTaskMemFree(dispname);
300 if(SUCCEEDED(ret) && *piOrder &&
301 (hint & SICHINT_TEST_FILESYSPATH_IF_NOT_EQUAL))
303 LPWSTR dispname, dispname_oth;
305 TRACE("Testing filesystem path.\n");
306 ret = IShellItem_GetDisplayName(iface, SIGDN_FILESYSPATH, &dispname);
309 ret = IShellItem_GetDisplayName(oth, SIGDN_FILESYSPATH, &dispname_oth);
312 *piOrder = lstrcmpiW(dispname, dispname_oth);
313 CoTaskMemFree(dispname_oth);
315 CoTaskMemFree(dispname);
328 static HRESULT WINAPI ShellItem2_GetPropertyStore(IShellItem2 *iface, GETPROPERTYSTOREFLAGS flags,
329 REFIID riid, void **ppv)
331 ShellItem *This = impl_from_IShellItem2(iface);
332 FIXME("Stub: %p (%d, %s, %p)\n", This, flags, shdebugstr_guid(riid), ppv);
336 static HRESULT WINAPI ShellItem2_GetPropertyStoreWithCreateObject(IShellItem2 *iface,
337 GETPROPERTYSTOREFLAGS flags, IUnknown *punkCreateObject, REFIID riid, void **ppv)
339 ShellItem *This = impl_from_IShellItem2(iface);
340 FIXME("Stub: %p (%08x, %p, %s, %p)\n",
341 This, flags, punkCreateObject, shdebugstr_guid(riid), ppv);
345 static HRESULT WINAPI ShellItem2_GetPropertyStoreForKeys(IShellItem2 *iface, const PROPERTYKEY *rgKeys,
346 UINT cKeys, GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv)
348 ShellItem *This = impl_from_IShellItem2(iface);
349 FIXME("Stub: %p (%p, %d, %08x, %s, %p)\n",
350 This, rgKeys, cKeys, flags, shdebugstr_guid(riid), ppv);
354 static HRESULT WINAPI ShellItem2_GetPropertyDescriptionList(IShellItem2 *iface,
355 REFPROPERTYKEY keyType, REFIID riid, void **ppv)
357 ShellItem *This = impl_from_IShellItem2(iface);
358 FIXME("Stub: %p (%p, %s, %p)\n", This, keyType, debugstr_guid(riid), ppv);
362 static HRESULT WINAPI ShellItem2_Update(IShellItem2 *iface, IBindCtx *pbc)
364 ShellItem *This = impl_from_IShellItem2(iface);
365 FIXME("Stub: %p (%p)\n", This, pbc);
369 static HRESULT WINAPI ShellItem2_GetProperty(IShellItem2 *iface, REFPROPERTYKEY key, PROPVARIANT *ppropvar)
371 ShellItem *This = impl_from_IShellItem2(iface);
372 FIXME("Stub: %p (%p, %p)\n", This, key, ppropvar);
376 static HRESULT WINAPI ShellItem2_GetCLSID(IShellItem2 *iface, REFPROPERTYKEY key, CLSID *pclsid)
378 ShellItem *This = impl_from_IShellItem2(iface);
379 FIXME("Stub: %p (%p, %p)\n", This, key, pclsid);
383 static HRESULT WINAPI ShellItem2_GetFileTime(IShellItem2 *iface, REFPROPERTYKEY key, FILETIME *pft)
385 ShellItem *This = impl_from_IShellItem2(iface);
386 FIXME("Stub: %p (%p, %p)\n", This, key, pft);
390 static HRESULT WINAPI ShellItem2_GetInt32(IShellItem2 *iface, REFPROPERTYKEY key, int *pi)
392 ShellItem *This = impl_from_IShellItem2(iface);
393 FIXME("Stub: %p (%p, %p)\n", This, key, pi);
397 static HRESULT WINAPI ShellItem2_GetString(IShellItem2 *iface, REFPROPERTYKEY key, LPWSTR *ppsz)
399 ShellItem *This = impl_from_IShellItem2(iface);
400 FIXME("Stub: %p (%p, %p)\n", This, key, ppsz);
404 static HRESULT WINAPI ShellItem2_GetUInt32(IShellItem2 *iface, REFPROPERTYKEY key, ULONG *pui)
406 ShellItem *This = impl_from_IShellItem2(iface);
407 FIXME("Stub: %p (%p, %p)\n", This, key, pui);
411 static HRESULT WINAPI ShellItem2_GetUInt64(IShellItem2 *iface, REFPROPERTYKEY key, ULONGLONG *pull)
413 ShellItem *This = impl_from_IShellItem2(iface);
414 FIXME("Stub: %p (%p, %p)\n", This, key, pull);
418 static HRESULT WINAPI ShellItem2_GetBool(IShellItem2 *iface, REFPROPERTYKEY key, BOOL *pf)
420 ShellItem *This = impl_from_IShellItem2(iface);
421 FIXME("Stub: %p (%p, %p)\n", This, key, pf);
426 static const IShellItem2Vtbl ShellItem2_Vtbl = {
427 ShellItem_QueryInterface,
430 ShellItem_BindToHandler,
432 ShellItem_GetDisplayName,
433 ShellItem_GetAttributes,
435 ShellItem2_GetPropertyStore,
436 ShellItem2_GetPropertyStoreWithCreateObject,
437 ShellItem2_GetPropertyStoreForKeys,
438 ShellItem2_GetPropertyDescriptionList,
440 ShellItem2_GetProperty,
442 ShellItem2_GetFileTime,
444 ShellItem2_GetString,
445 ShellItem2_GetUInt32,
446 ShellItem2_GetUInt64,
451 static HRESULT ShellItem_GetClassID(ShellItem* This, CLSID *pClassID)
453 TRACE("(%p,%p)\n", This, pClassID);
455 *pClassID = CLSID_ShellItem;
460 static HRESULT WINAPI ShellItem_IPersistIDList_QueryInterface(IPersistIDList *iface,
461 REFIID riid, void **ppv)
463 ShellItem *This = impl_from_IPersistIDList(iface);
464 return ShellItem_QueryInterface(&This->IShellItem2_iface, riid, ppv);
467 static ULONG WINAPI ShellItem_IPersistIDList_AddRef(IPersistIDList *iface)
469 ShellItem *This = impl_from_IPersistIDList(iface);
470 return ShellItem_AddRef(&This->IShellItem2_iface);
473 static ULONG WINAPI ShellItem_IPersistIDList_Release(IPersistIDList *iface)
475 ShellItem *This = impl_from_IPersistIDList(iface);
476 return ShellItem_Release(&This->IShellItem2_iface);
479 static HRESULT WINAPI ShellItem_IPersistIDList_GetClassID(IPersistIDList* iface,
482 ShellItem *This = impl_from_IPersistIDList(iface);
484 return ShellItem_GetClassID(This, pClassID);
487 static HRESULT WINAPI ShellItem_IPersistIDList_SetIDList(IPersistIDList* iface,
490 ShellItem *This = impl_from_IPersistIDList(iface);
491 LPITEMIDLIST new_pidl;
493 TRACE("(%p,%p)\n", This, pidl);
495 new_pidl = ILClone(pidl);
500 This->pidl = new_pidl;
504 return E_OUTOFMEMORY;
507 static HRESULT WINAPI ShellItem_IPersistIDList_GetIDList(IPersistIDList* iface,
510 ShellItem *This = impl_from_IPersistIDList(iface);
512 TRACE("(%p,%p)\n", This, ppidl);
514 *ppidl = ILClone(This->pidl);
518 return E_OUTOFMEMORY;
521 static const IPersistIDListVtbl ShellItem_IPersistIDList_Vtbl = {
522 ShellItem_IPersistIDList_QueryInterface,
523 ShellItem_IPersistIDList_AddRef,
524 ShellItem_IPersistIDList_Release,
525 ShellItem_IPersistIDList_GetClassID,
526 ShellItem_IPersistIDList_SetIDList,
527 ShellItem_IPersistIDList_GetIDList
531 HRESULT WINAPI IShellItem_Constructor(IUnknown *pUnkOuter, REFIID riid, void **ppv)
536 TRACE("(%p,%s)\n",pUnkOuter, debugstr_guid(riid));
540 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
542 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ShellItem));
543 This->IShellItem2_iface.lpVtbl = &ShellItem2_Vtbl;
546 This->IPersistIDList_iface.lpVtbl = &ShellItem_IPersistIDList_Vtbl;
548 ret = ShellItem_QueryInterface(&This->IShellItem2_iface, riid, ppv);
549 ShellItem_Release(&This->IShellItem2_iface);
554 HRESULT WINAPI SHCreateShellItem(LPCITEMIDLIST pidlParent,
555 IShellFolder *psfParent, LPCITEMIDLIST pidl, IShellItem **ppsi)
558 LPITEMIDLIST new_pidl;
561 TRACE("(%p,%p,%p,%p)\n", pidlParent, psfParent, pidl, ppsi);
567 else if (pidlParent || psfParent)
569 LPITEMIDLIST temp_parent=NULL;
572 IPersistFolder2* ppf2Parent;
574 if (FAILED(IPersistFolder2_QueryInterface(psfParent, &IID_IPersistFolder2, (void**)&ppf2Parent)))
576 FIXME("couldn't get IPersistFolder2 interface of parent\n");
577 return E_NOINTERFACE;
580 if (FAILED(IPersistFolder2_GetCurFolder(ppf2Parent, &temp_parent)))
582 FIXME("couldn't get parent PIDL\n");
583 IPersistFolder2_Release(ppf2Parent);
584 return E_NOINTERFACE;
587 pidlParent = temp_parent;
588 IPersistFolder2_Release(ppf2Parent);
591 new_pidl = ILCombine(pidlParent, pidl);
595 return E_OUTOFMEMORY;
599 new_pidl = ILClone(pidl);
601 return E_OUTOFMEMORY;
604 ret = IShellItem_Constructor(NULL, &IID_IShellItem, (void**)&This);
607 *ppsi = (IShellItem*)&This->IShellItem2_iface;
608 This->pidl = new_pidl;
618 HRESULT WINAPI SHCreateItemFromParsingName(PCWSTR pszPath,
619 IBindCtx *pbc, REFIID riid, void **ppv)
626 ret = SHParseDisplayName(pszPath, pbc, &pidl, 0, NULL);
630 ret = IShellItem_Constructor(NULL, riid, (void**)&This);
645 HRESULT WINAPI SHCreateItemFromIDList(PCIDLIST_ABSOLUTE pidl, REFIID riid, void **ppv)
653 ret = IShellItem_Constructor(NULL, riid, ppv);
656 psiimpl = (ShellItem*)*ppv;
657 psiimpl->pidl = ILClone(pidl);
663 HRESULT WINAPI SHGetItemFromDataObject(IDataObject *pdtobj,
664 DATAOBJ_GET_ITEM_FLAGS dwFlags, REFIID riid, void **ppv)
670 TRACE("%p, %x, %s, %p\n", pdtobj, dwFlags, debugstr_guid(riid), ppv);
675 fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
677 fmt.dwAspect = DVASPECT_CONTENT;
679 fmt.tymed = TYMED_HGLOBAL;
681 ret = IDataObject_GetData(pdtobj, &fmt, &medium);
684 LPIDA pida = GlobalLock(medium.u.hGlobal);
686 if((pida->cidl > 1 && !(dwFlags & DOGIF_ONLY_IF_ONE)) ||
691 /* Get the first pidl (parent + child1) */
692 pidl = ILCombine((LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]),
693 (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[1]));
695 ret = SHCreateItemFromIDList(pidl, riid, ppv);
703 GlobalUnlock(medium.u.hGlobal);
704 GlobalFree(medium.u.hGlobal);
707 if(FAILED(ret) && !(dwFlags & DOGIF_NO_HDROP))
709 TRACE("Attempting to fall back on CF_HDROP.\n");
711 fmt.cfFormat = CF_HDROP;
713 fmt.dwAspect = DVASPECT_CONTENT;
715 fmt.tymed = TYMED_HGLOBAL;
717 ret = IDataObject_GetData(pdtobj, &fmt, &medium);
720 DROPFILES *df = GlobalLock(medium.u.hGlobal);
721 LPBYTE files = (LPBYTE)df + df->pFiles;
722 BOOL multiple_files = FALSE;
727 WCHAR filename[MAX_PATH];
728 PCSTR first_file = (PCSTR)files;
729 if(*(files + lstrlenA(first_file) + 1) != 0)
730 multiple_files = TRUE;
732 if( !(multiple_files && (dwFlags & DOGIF_ONLY_IF_ONE)) )
734 MultiByteToWideChar(CP_ACP, 0, first_file, -1, filename, MAX_PATH);
735 ret = SHCreateItemFromParsingName(filename, NULL, riid, ppv);
740 PCWSTR first_file = (PCWSTR)files;
741 if(*((PCWSTR)files + lstrlenW(first_file) + 1) != 0)
742 multiple_files = TRUE;
744 if( !(multiple_files && (dwFlags & DOGIF_ONLY_IF_ONE)) )
745 ret = SHCreateItemFromParsingName(first_file, NULL, riid, ppv);
748 GlobalUnlock(medium.u.hGlobal);
749 GlobalFree(medium.u.hGlobal);
753 if(FAILED(ret) && !(dwFlags & DOGIF_NO_URL))
755 FIXME("Failed to create item, should try CF_URL.\n");
761 HRESULT WINAPI SHGetItemFromObject(IUnknown *punk, REFIID riid, void **ppv)
766 ret = SHGetIDListFromObject(punk, &pidl);
769 ret = SHCreateItemFromIDList(pidl, riid, ppv);
776 /*************************************************************************
777 * IShellItemArray implementation
780 IShellItemArray IShellItemArray_iface;
785 } IShellItemArrayImpl;
787 static inline IShellItemArrayImpl *impl_from_IShellItemArray(IShellItemArray *iface)
789 return CONTAINING_RECORD(iface, IShellItemArrayImpl, IShellItemArray_iface);
792 static HRESULT WINAPI IShellItemArray_fnQueryInterface(IShellItemArray *iface,
796 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
797 TRACE("%p (%s, %p)\n", This, shdebugstr_guid(riid), ppvObject);
800 if(IsEqualIID(riid, &IID_IShellItemArray) ||
801 IsEqualIID(riid, &IID_IUnknown))
808 IUnknown_AddRef((IUnknown*)*ppvObject);
812 return E_NOINTERFACE;
815 static ULONG WINAPI IShellItemArray_fnAddRef(IShellItemArray *iface)
817 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
818 LONG ref = InterlockedIncrement(&This->ref);
819 TRACE("%p - ref %d\n", This, ref);
824 static ULONG WINAPI IShellItemArray_fnRelease(IShellItemArray *iface)
826 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
827 LONG ref = InterlockedDecrement(&This->ref);
828 TRACE("%p - ref %d\n", This, ref);
835 for(i = 0; i < This->item_count; i++)
836 IShellItem_Release(This->array[i]);
838 HeapFree(GetProcessHeap(), 0, This->array);
839 HeapFree(GetProcessHeap(), 0, This);
846 static HRESULT WINAPI IShellItemArray_fnBindToHandler(IShellItemArray *iface,
852 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
853 FIXME("Stub: %p (%p, %s, %s, %p)\n",
854 This, pbc, shdebugstr_guid(bhid), shdebugstr_guid(riid), ppvOut);
859 static HRESULT WINAPI IShellItemArray_fnGetPropertyStore(IShellItemArray *iface,
860 GETPROPERTYSTOREFLAGS flags,
864 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
865 FIXME("Stub: %p (%x, %s, %p)\n", This, flags, shdebugstr_guid(riid), ppv);
870 static HRESULT WINAPI IShellItemArray_fnGetPropertyDescriptionList(IShellItemArray *iface,
871 REFPROPERTYKEY keyType,
875 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
876 FIXME("Stub: %p (%p, %s, %p)\n",
877 This, keyType, shdebugstr_guid(riid), ppv);
882 static HRESULT WINAPI IShellItemArray_fnGetAttributes(IShellItemArray *iface,
883 SIATTRIBFLAGS AttribFlags,
885 SFGAOF *psfgaoAttribs)
887 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
888 FIXME("Stub: %p (%x, %x, %p)\n", This, AttribFlags, sfgaoMask, psfgaoAttribs);
893 static HRESULT WINAPI IShellItemArray_fnGetCount(IShellItemArray *iface,
896 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
897 TRACE("%p (%p)\n", This, pdwNumItems);
899 *pdwNumItems = This->item_count;
904 static HRESULT WINAPI IShellItemArray_fnGetItemAt(IShellItemArray *iface,
908 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
909 TRACE("%p (%x, %p)\n", This, dwIndex, ppsi);
912 if(dwIndex + 1 > This->item_count)
915 *ppsi = This->array[dwIndex];
916 IShellItem_AddRef(*ppsi);
921 static HRESULT WINAPI IShellItemArray_fnEnumItems(IShellItemArray *iface,
922 IEnumShellItems **ppenumShellItems)
924 IShellItemArrayImpl *This = impl_from_IShellItemArray(iface);
925 FIXME("Stub: %p (%p)\n", This, ppenumShellItems);
930 static const IShellItemArrayVtbl vt_IShellItemArray = {
931 IShellItemArray_fnQueryInterface,
932 IShellItemArray_fnAddRef,
933 IShellItemArray_fnRelease,
934 IShellItemArray_fnBindToHandler,
935 IShellItemArray_fnGetPropertyStore,
936 IShellItemArray_fnGetPropertyDescriptionList,
937 IShellItemArray_fnGetAttributes,
938 IShellItemArray_fnGetCount,
939 IShellItemArray_fnGetItemAt,
940 IShellItemArray_fnEnumItems
943 static HRESULT IShellItemArray_Constructor(IUnknown *pUnkOuter, REFIID riid, void **ppv)
945 IShellItemArrayImpl *This;
948 TRACE("(%p, %s, %p)\n",pUnkOuter, debugstr_guid(riid), ppv);
951 return CLASS_E_NOAGGREGATION;
953 This = HeapAlloc(GetProcessHeap(), 0, sizeof(IShellItemArrayImpl));
955 return E_OUTOFMEMORY;
958 This->IShellItemArray_iface.lpVtbl = &vt_IShellItemArray;
960 This->item_count = 0;
962 ret = IShellItemArray_QueryInterface(&This->IShellItemArray_iface, riid, ppv);
963 IShellItemArray_Release(&This->IShellItemArray_iface);
968 HRESULT WINAPI SHCreateShellItemArray(PCIDLIST_ABSOLUTE pidlParent,
971 PCUITEMID_CHILD_ARRAY ppidl,
972 IShellItemArray **ppsiItemArray)
974 IShellItemArrayImpl *This;
976 HRESULT ret = E_FAIL;
979 TRACE("%p, %p, %d, %p, %p\n", pidlParent, psf, cidl, ppidl, ppsiItemArray);
981 if(!pidlParent && !psf)
987 array = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cidl*sizeof(IShellItem*));
989 return E_OUTOFMEMORY;
991 for(i = 0; i < cidl; i++)
993 ret = SHCreateShellItem(pidlParent, psf, ppidl[i], &array[i]);
994 if(FAILED(ret)) break;
999 ret = IShellItemArray_Constructor(NULL, &IID_IShellItemArray, (void**)&This);
1002 This->array = array;
1003 This->item_count = cidl;
1004 *ppsiItemArray = &This->IShellItemArray_iface;
1010 /* Something failed, clean up. */
1011 for(i = 0; i < cidl; i++)
1012 if(array[i]) IShellItem_Release(array[i]);
1013 HeapFree(GetProcessHeap(), 0, array);
1014 *ppsiItemArray = NULL;
1018 HRESULT WINAPI SHCreateShellItemArrayFromShellItem(IShellItem *psi, REFIID riid, void **ppv)
1020 IShellItemArrayImpl *This;
1024 TRACE("%p, %s, %p\n", psi, shdebugstr_guid(riid), ppv);
1026 array = HeapAlloc(GetProcessHeap(), 0, sizeof(IShellItem*));
1028 return E_OUTOFMEMORY;
1030 ret = IShellItemArray_Constructor(NULL, riid, (void**)&This);
1034 IShellItem_AddRef(psi);
1035 This->array = array;
1036 This->item_count = 1;
1041 HeapFree(GetProcessHeap(), 0, array);
1048 HRESULT WINAPI SHCreateShellItemArrayFromDataObject(IDataObject *pdo, REFIID riid, void **ppv)
1050 IShellItemArray *psia;
1055 TRACE("%p, %s, %p\n", pdo, shdebugstr_guid(riid), ppv);
1058 return E_INVALIDARG;
1062 fmt.cfFormat = RegisterClipboardFormatW(CFSTR_SHELLIDLISTW);
1064 fmt.dwAspect = DVASPECT_CONTENT;
1066 fmt.tymed = TYMED_HGLOBAL;
1068 ret = IDataObject_GetData(pdo, &fmt, &medium);
1071 LPIDA pida = GlobalLock(medium.u.hGlobal);
1072 LPCITEMIDLIST parent_pidl;
1073 LPCITEMIDLIST *children;
1075 TRACE("Converting %d objects.\n", pida->cidl);
1077 parent_pidl = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[0]);
1079 children = HeapAlloc(GetProcessHeap(), 0, sizeof(LPCITEMIDLIST)*pida->cidl);
1080 for(i = 0; i < pida->cidl; i++)
1081 children[i] = (LPCITEMIDLIST) ((LPBYTE)pida+pida->aoffset[i+1]);
1083 ret = SHCreateShellItemArray(parent_pidl, NULL, pida->cidl, children, (IShellItemArray**)&psia);
1085 HeapFree(GetProcessHeap(), 0, children);
1087 GlobalUnlock(medium.u.hGlobal);
1088 GlobalFree(medium.u.hGlobal);
1093 ret = IShellItemArray_QueryInterface(psia, riid, ppv);
1094 IShellItemArray_Release(psia);