ReactOS 0.4.15-dev-8222-g9164419
CShellItem.cpp
Go to the documentation of this file.
1/*
2 * IShellItem implementation
3 *
4 * Copyright 2008 Vincent Povirk for CodeWeavers
5 * Copyright 2009 Andrew Hill
6 * Copyright 2013 Katayama Hirofumi MZ
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23#include "precomp.h"
24
26
28 IShellFolder *psfParent, PCUITEMID_CHILD pidl, IShellItem **ppsi);
29
31 m_pidl(NULL)
32{
33}
34
36{
38}
39
41{
42 *parent_pidl = ILClone(m_pidl);
43 if (*parent_pidl)
44 {
45 if (ILRemoveLastID(*parent_pidl))
46 return S_OK;
47 else
48 {
49 ILFree(*parent_pidl);
50 *parent_pidl = NULL;
51 return E_INVALIDARG;
52 }
53 }
54 else
55 {
56 *parent_pidl = NULL;
57 return E_OUTOFMEMORY;
58 }
59}
60
62{
63 HRESULT hr;
64 LPITEMIDLIST parent_pidl;
66
67 hr = get_parent_pidl(&parent_pidl);
68 if (SUCCEEDED(hr))
69 {
70 hr = SHGetDesktopFolder(&desktop);
71 if (SUCCEEDED(hr))
72 hr = desktop->BindToObject(parent_pidl, NULL, IID_PPV_ARG(IShellFolder, ppsf));
73 ILFree(parent_pidl);
74 }
75
76 return hr;
77}
78
80{
82 CComPtr<IShellFolder> psfDesktop;
84
85 ret = SHGetDesktopFolder(&psfDesktop);
87 return ret;
88
90 psf = psfDesktop;
91 else
92 {
93 ret = psfDesktop->BindToObject(m_pidl, pbc, IID_PPV_ARG(IShellFolder, &psf));
95 return ret;
96 }
97
98 return psf->QueryInterface(riid, ppvOut);
99}
100
102{
103 HRESULT ret;
104 TRACE("(%p, %p,%s,%p,%p)\n", this, pbc, shdebugstr_guid(&rbhid), riid, ppvOut);
105
106 *ppvOut = NULL;
107 if (IsEqualGUID(rbhid, BHID_SFObject))
108 {
109 return get_shellfolder(pbc, riid, ppvOut);
110 }
111 else if (IsEqualGUID(rbhid, BHID_SFUIObject))
112 {
113 CComPtr<IShellFolder> psf_parent;
114 if (_ILIsDesktop(m_pidl))
115 ret = SHGetDesktopFolder(&psf_parent);
116 else
117 ret = get_parent_shellfolder(&psf_parent);
119 return ret;
120
122 return psf_parent->GetUIObjectOf(NULL, 1, &pidl, riid, NULL, ppvOut);
123 }
124 else if (IsEqualGUID(rbhid, BHID_DataObject))
125 {
126 return BindToHandler(pbc, BHID_SFUIObject, IID_IDataObject, ppvOut);
127 }
128 else if (IsEqualGUID(rbhid, BHID_SFViewObject))
129 {
133 return ret;
134
135 return psf->CreateViewObject(NULL, riid, ppvOut);
136 }
137
138 FIXME("Unsupported BHID %s.\n", debugstr_guid(&rbhid));
139
140 return MK_E_NOOBJECT;
141}
142
144{
145 HRESULT hr;
146 LPITEMIDLIST parent_pidl;
147
148 TRACE("(%p,%p)\n", this, ppsi);
149
150 hr = get_parent_pidl(&parent_pidl);
151 if (SUCCEEDED(hr))
152 {
153 hr = SHCreateShellItem(NULL, NULL, parent_pidl, ppsi);
154 ILFree(parent_pidl);
155 }
156
157 return hr;
158}
159
161{
163}
164
166{
167 CComPtr<IShellFolder> parent_folder;
168 LPCITEMIDLIST child_pidl;
169 HRESULT hr;
170
171 TRACE("(%p,%x,%p)\n", this, sfgaoMask, psfgaoAttribs);
172
173 if (_ILIsDesktop(m_pidl))
174 hr = SHGetDesktopFolder(&parent_folder);
175 else
176 hr = get_parent_shellfolder(&parent_folder);
178 return hr;
179
180 child_pidl = ILFindLastID(m_pidl);
181 *psfgaoAttribs = sfgaoMask;
182 hr = parent_folder->GetAttributesOf(1, &child_pidl, psfgaoAttribs);
183 *psfgaoAttribs &= sfgaoMask;
184
186 return hr;
187
188 return (sfgaoMask == *psfgaoAttribs) ? S_OK : S_FALSE;
189}
190
192{
193 HRESULT hr;
195 CComPtr<IShellFolder> psfDesktop;
196 LPITEMIDLIST pidl;
197
198 TRACE("(%p,%p,%x,%p)\n", this, oth, hint, piOrder);
199
200 if (piOrder == NULL || oth == NULL)
201 return E_POINTER;
202
203 hr = oth->QueryInterface(IID_PPV_ARG(IPersistIDList, &pIDList));
204 if (SUCCEEDED(hr))
205 {
206 hr = pIDList->GetIDList(&pidl);
207 if (SUCCEEDED(hr))
208 {
209 hr = SHGetDesktopFolder(&psfDesktop);
210 if (SUCCEEDED(hr))
211 {
212 hr = psfDesktop->CompareIDs(hint, m_pidl, pidl);
213 *piOrder = (int)(short)SCODE_CODE(hr);
214 }
215 ILFree(pidl);
216 }
217 }
218
219 if(FAILED(hr))
220 return hr;
221
222 if(*piOrder)
223 return S_FALSE;
224 else
225 return S_OK;
226}
227
229{
230 TRACE("(%p,%p)\n", this, pClassID);
231
232 *pClassID = CLSID_ShellItem;
233 return S_OK;
234}
235
237{
238 LPITEMIDLIST new_pidl;
239
240 TRACE("(%p,%p)\n", this, pidlx);
241
242 new_pidl = ILClone(pidlx);
243 if (new_pidl)
244 {
245 ILFree(m_pidl);
246 m_pidl = new_pidl;
247 return S_OK;
248 }
249 else
250 return E_OUTOFMEMORY;
251}
252
254{
255 TRACE("(%p,%p)\n", this, ppidl);
256
257 *ppidl = ILClone(m_pidl);
258 if (*ppidl)
259 return S_OK;
260 else
261 return E_OUTOFMEMORY;
262}
263
265 IShellFolder *psfParent, PCUITEMID_CHILD pidl, IShellItem **ppsi)
266{
267 HRESULT hr;
268 CComPtr<IShellItem> newShellItem;
269 LPITEMIDLIST new_pidl;
270 CComPtr<IPersistIDList> newPersistIDList;
271
272 TRACE("(%p,%p,%p,%p)\n", pidlParent, psfParent, pidl, ppsi);
273
274 *ppsi = NULL;
275
276 if (!pidl)
277 return E_INVALIDARG;
278
279 if (pidlParent || psfParent)
280 {
281 LPITEMIDLIST temp_parent = NULL;
282 if (!pidlParent)
283 {
284 CComPtr<IPersistFolder2> ppf2Parent;
285
286 if (FAILED(psfParent->QueryInterface(IID_PPV_ARG(IPersistFolder2, &ppf2Parent))))
287 {
288 FIXME("couldn't get IPersistFolder2 interface of parent\n");
289 return E_NOINTERFACE;
290 }
291
292 if (FAILED(ppf2Parent->GetCurFolder(&temp_parent)))
293 {
294 FIXME("couldn't get parent PIDL\n");
295 return E_NOINTERFACE;
296 }
297
298 pidlParent = temp_parent;
299 }
300
301 new_pidl = ILCombine(pidlParent, pidl);
302 ILFree(temp_parent);
303
304 if (!new_pidl)
305 return E_OUTOFMEMORY;
306 }
307 else
308 {
309 new_pidl = ILClone(pidl);
310 if (!new_pidl)
311 return E_OUTOFMEMORY;
312 }
313
314 hr = CShellItem::_CreatorClass::CreateInstance(NULL, IID_PPV_ARG(IShellItem, &newShellItem));
315 if (FAILED(hr))
316 {
317 ILFree(new_pidl);
318 return hr;
319 }
320 hr = newShellItem->QueryInterface(IID_PPV_ARG(IPersistIDList, &newPersistIDList));
321 if (FAILED(hr))
322 {
323 ILFree(new_pidl);
324 return hr;
325 }
326 hr = newPersistIDList->SetIDList(new_pidl);
327 if (FAILED(hr))
328 {
329 ILFree(new_pidl);
330 return hr;
331 }
332 ILFree(new_pidl);
333
334 *ppsi = newShellItem.Detach();
335
336 return hr;
337}
338
340 public CComCoClass<CShellItemArray, &CLSID_NULL>,
341 public CComObjectRootEx<CComMultiThreadModelNoCS>,
342 public IShellItemArray
343{
345 STGMEDIUM m_Medium;
346
347public:
349 {
350 m_Medium.tymed = TYMED_NULL;
351 }
352
354 {
355 CDataObjectHIDA::DestroyCIDA(m_pCIDA, m_Medium);
356 }
357
359 {
360 return CDataObjectHIDA::CreateCIDA(pdo, &m_pCIDA, m_Medium);
361 }
362
363 inline UINT GetCount() const { return m_pCIDA->cidl; }
364
365 // IShellItemArray
366 STDMETHODIMP BindToHandler(IBindCtx *pbc, REFGUID rbhid, REFIID riid, void **ppv) override
367 {
369 *ppv = NULL;
370 return E_NOTIMPL;
371 }
372
373 STDMETHODIMP GetPropertyStore(GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv) override
374 {
376 *ppv = NULL;
377 return E_NOTIMPL;
378 }
379
381 {
383 *ppv = NULL;
384 return E_NOTIMPL;
385 }
386
387 STDMETHODIMP GetAttributes(SIATTRIBFLAGS dwAttribFlags, SFGAOF sfgaoMask, SFGAOF *psfgaoAttribs) override
388 {
390 *psfgaoAttribs = 0;
391 return E_NOTIMPL;
392 }
393
394 STDMETHODIMP GetCount(DWORD*pCount) override
395 {
396 *pCount = m_pCIDA ? GetCount() : 0;
397 return S_OK;
398 }
399
400 STDMETHODIMP GetItemAt(DWORD nIndex, IShellItem **ppItem) override
401 {
402 if (!ppItem)
403 return E_INVALIDARG;
404 *ppItem = NULL;
405 if (!m_pCIDA)
406 return E_UNEXPECTED;
407 if (nIndex >= GetCount())
408 return E_FAIL;
410 HIDA_GetPIDLItem(m_pCIDA, nIndex), ppItem);
411 }
412
414 {
416 *ppESI = NULL;
417 return E_NOTIMPL;
418 }
419
422
424 COM_INTERFACE_ENTRY_IID(IID_IShellItemArray, IShellItemArray)
426};
427
430{
431 return ShellObjectCreatorInit<CShellItemArray>(pdo, riid, ppv);
432}
BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
Definition: CBandSite.h:24
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
EXTERN_C HRESULT WINAPI SHCreateShellItemArrayFromDataObject(_In_ IDataObject *pdo, _In_ REFIID riid, _Out_ void **ppv)
Definition: CShellItem.cpp:429
EXTERN_C HRESULT WINAPI SHCreateShellItem(PCIDLIST_ABSOLUTE pidlParent, IShellFolder *psfParent, PCUITEMID_CHILD pidl, IShellItem **ppsi)
Definition: CShellItem.cpp:264
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
#define EXTERN_C
Definition: basetyps.h:12
#define STDMETHODIMP
Definition: basetyps.h:43
#define FIXME(fmt,...)
Definition: debug.h:114
#define UNIMPLEMENTED
Definition: debug.h:118
T * Detach()
Definition: atlcomcli.h:186
STDMETHODIMP EnumItems(IEnumShellItems **ppESI) override
Definition: CShellItem.cpp:413
UINT GetCount() const
Definition: CShellItem.cpp:363
STDMETHODIMP GetItemAt(DWORD nIndex, IShellItem **ppItem) override
Definition: CShellItem.cpp:400
STDMETHODIMP BindToHandler(IBindCtx *pbc, REFGUID rbhid, REFIID riid, void **ppv) override
Definition: CShellItem.cpp:366
STDMETHODIMP GetPropertyDescriptionList(REFPROPERTYKEY keyType, REFIID riid, void **ppv) override
Definition: CShellItem.cpp:380
STDMETHODIMP GetAttributes(SIATTRIBFLAGS dwAttribFlags, SFGAOF sfgaoMask, SFGAOF *psfgaoAttribs) override
Definition: CShellItem.cpp:387
STDMETHODIMP GetPropertyStore(GETPROPERTYSTOREFLAGS flags, REFIID riid, void **ppv) override
Definition: CShellItem.cpp:373
HRESULT Initialize(IDataObject *pdo)
Definition: CShellItem.cpp:358
STDMETHODIMP GetCount(DWORD *pCount) override
Definition: CShellItem.cpp:394
virtual ~CShellItemArray()
Definition: CShellItem.cpp:353
STGMEDIUM m_Medium
Definition: CShellItem.cpp:345
STDMETHOD() BindToHandler(IBindCtx *pbc, REFGUID rbhid, REFIID riid, void **ppvOut) override
Definition: CShellItem.cpp:101
STDMETHOD() Compare(IShellItem *oth, SICHINTF hint, int *piOrder) override
Definition: CShellItem.cpp:191
STDMETHOD() GetAttributes(SFGAOF sfgaoMask, SFGAOF *psfgaoAttribs) override
Definition: CShellItem.cpp:165
STDMETHOD() GetClassID(CLSID *pClassID) override
Definition: CShellItem.cpp:228
LPITEMIDLIST m_pidl
Definition: CShellItem.h:32
STDMETHOD() GetDisplayName(SIGDN sigdnName, LPWSTR *ppszName) override
Definition: CShellItem.cpp:160
HRESULT get_parent_shellfolder(IShellFolder **ppsf)
Definition: CShellItem.cpp:61
HRESULT get_shellfolder(IBindCtx *pbc, REFIID riid, void **ppvOut)
Definition: CShellItem.cpp:79
STDMETHOD() SetIDList(PCIDLIST_ABSOLUTE pidl) override
Definition: CShellItem.cpp:236
STDMETHOD() GetIDList(PIDLIST_ABSOLUTE *ppidl) override
Definition: CShellItem.cpp:253
STDMETHOD() GetParent(IShellItem **ppsi) override
Definition: CShellItem.cpp:143
HRESULT get_parent_pidl(LPITEMIDLIST *parent_pidl)
Definition: CShellItem.cpp:40
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
const char * shdebugstr_guid(const struct _GUID *id)
Definition: debughlp.cpp:428
#define NULL
Definition: types.h:112
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
static IShellFolder IShellItem **static IBindCtx LPITEMIDLIST SFGAOF
Definition: ebrowser.c:83
unsigned long DWORD
Definition: ntddk_ex.h:95
GLbitfield flags
Definition: glext.h:7161
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
DWORD SICHINTF
Definition: shobjidl.idl:390
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:651
#define END_COM_MAP()
Definition: atlcom.h:592
#define DECLARE_NO_REGISTRY()
Definition: atlcom.h:639
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
unsigned int UINT
Definition: ndis.h:50
const GUID IID_IDataObject
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:237
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:940
LPITEMIDLIST WINAPI ILFindLastID(LPCITEMIDLIST pidl)
Definition: pidl.c:198
HRESULT WINAPI SHGetNameFromIDList(PCIDLIST_ABSOLUTE pidl, SIGDN sigdnName, PWSTR *ppszName)
Definition: pidl.c:1456
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:712
BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
Definition: pidl.c:221
PROPERTYKEY * REFPROPERTYKEY
Definition: propsys.idl:34
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
static PCUIDLIST_RELATIVE HIDA_GetPIDLItem(CIDA const *pida, SIZE_T i)
Definition: shellutils.h:619
static PCUIDLIST_ABSOLUTE HIDA_GetPIDLFolder(CIDA const *pida)
Definition: shellutils.h:614
HRESULT hr
Definition: shlfolder.c:183
SIGDN PWSTR * ppszName
Definition: shobjidl.idl:605
SIGDN sigdnName
Definition: shobjidl.idl:605
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
const ITEMID_CHILD UNALIGNED * PCUITEMID_CHILD
Definition: shtypes.idl:70
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define TRACE(s)
Definition: solgame.cpp:4
Definition: shlobj.h:572
UINT cidl
Definition: shlobj.h:572
Definition: scsiwmi.h:51
DWORD hint
Definition: vfdcmd.c:88
int ret
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:2357
#define MK_E_NOOBJECT
Definition: winerror.h:2786
#define E_NOINTERFACE
Definition: winerror.h:2364
#define E_UNEXPECTED
Definition: winerror.h:2456
#define E_POINTER
Definition: winerror.h:2365
#define SCODE_CODE(sc)
Definition: winerror.h:77
#define IID_PPV_ARG(Itype, ppType)
WCHAR * LPWSTR
Definition: xmlstorage.h:184