push 8724397e7ede0f147b6e05994a72142d44d4fecc
[wine/hacks.git] / dlls / shell32 / shellitem.c
blob643f1b571ffa2f57d73d313c6d69ffc16853c18a
1 /*
2 * IShellItem implementation
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdio.h>
25 #include <stdarg.h>
27 #define COBJMACROS
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wine/debug.h"
35 #include "pidl.h"
36 #include "shell32_main.h"
37 #include "debughlp.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(shell);
41 typedef struct _ShellItem {
42 const IShellItemVtbl *lpIShellItemVtbl;
43 LONG ref;
44 LPITEMIDLIST pidl;
45 const IPersistIDListVtbl *lpIPersistIDListVtbl;
46 } ShellItem;
49 static inline ShellItem *impl_from_IPersistIDList( IPersistIDList *iface )
51 return (ShellItem*)((char*)iface - FIELD_OFFSET(ShellItem, lpIPersistIDListVtbl));
55 static HRESULT WINAPI ShellItem_QueryInterface(IShellItem *iface, REFIID riid,
56 void **ppv)
58 ShellItem *This = (ShellItem*)iface;
60 TRACE("(%p,%p,%p)\n", iface, riid, ppv);
62 if (!ppv) return E_INVALIDARG;
64 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IShellItem, riid))
66 *ppv = This;
68 else if (IsEqualIID(&IID_IPersist, riid) || IsEqualIID(&IID_IPersistIDList, riid))
70 *ppv = &(This->lpIPersistIDListVtbl);
72 else {
73 FIXME("not implemented for %s\n", shdebugstr_guid(riid));
74 *ppv = NULL;
75 return E_NOINTERFACE;
78 IUnknown_AddRef((IUnknown*)*ppv);
79 return S_OK;
82 static ULONG WINAPI ShellItem_AddRef(IShellItem *iface)
84 ShellItem *This = (ShellItem*)iface;
85 ULONG ref = InterlockedIncrement(&This->ref);
87 TRACE("(%p), new refcount=%i\n", iface, ref);
89 return ref;
92 static ULONG WINAPI ShellItem_Release(IShellItem *iface)
94 ShellItem *This = (ShellItem*)iface;
95 ULONG ref = InterlockedDecrement(&This->ref);
97 TRACE("(%p), new refcount=%i\n", iface, ref);
99 if (ref == 0)
101 ILFree(This->pidl);
102 HeapFree(GetProcessHeap(), 0, This);
105 return ref;
108 static HRESULT WINAPI ShellItem_BindToHandler(IShellItem *iface, IBindCtx *pbc,
109 REFGUID rbhid, REFIID riid, void **ppvOut)
111 FIXME("(%p,%p,%s,%p,%p)\n", iface, pbc, shdebugstr_guid(rbhid), riid, ppvOut);
113 *ppvOut = NULL;
115 return E_NOTIMPL;
118 static HRESULT WINAPI ShellItem_GetParent(IShellItem *iface, IShellItem **ppsi)
120 FIXME("(%p,%p)\n", iface, ppsi);
122 *ppsi = NULL;
124 return E_NOTIMPL;
127 static HRESULT WINAPI ShellItem_GetDisplayName(IShellItem *iface, SIGDN sigdnName,
128 LPWSTR *ppszName)
130 FIXME("(%p,%x,%p)\n", iface, sigdnName, ppszName);
132 *ppszName = NULL;
134 return E_NOTIMPL;
137 static HRESULT WINAPI ShellItem_GetAttributes(IShellItem *iface, SFGAOF sfgaoMask,
138 SFGAOF *psfgaoAttribs)
140 FIXME("(%p,%x,%p)\n", iface, sfgaoMask, psfgaoAttribs);
142 *psfgaoAttribs = 0;
144 return E_NOTIMPL;
147 static HRESULT WINAPI ShellItem_Compare(IShellItem *iface, IShellItem *oth,
148 SICHINTF hint, int *piOrder)
150 FIXME("(%p,%p,%x,%p)\n", iface, oth, hint, piOrder);
152 return E_NOTIMPL;
155 static const IShellItemVtbl ShellItem_Vtbl = {
156 ShellItem_QueryInterface,
157 ShellItem_AddRef,
158 ShellItem_Release,
159 ShellItem_BindToHandler,
160 ShellItem_GetParent,
161 ShellItem_GetDisplayName,
162 ShellItem_GetAttributes,
163 ShellItem_Compare
167 static HRESULT ShellItem_GetClassID(ShellItem* This, CLSID *pClassID)
169 TRACE("(%p,%p)\n", This, pClassID);
171 *pClassID = CLSID_ShellItem;
172 return S_OK;
176 static HRESULT WINAPI ShellItem_IPersistIDList_QueryInterface(IPersistIDList *iface,
177 REFIID riid, void **ppv)
179 ShellItem *This = impl_from_IPersistIDList(iface);
180 return ShellItem_QueryInterface((IShellItem*)This, riid, ppv);
183 static ULONG WINAPI ShellItem_IPersistIDList_AddRef(IPersistIDList *iface)
185 ShellItem *This = impl_from_IPersistIDList(iface);
186 return ShellItem_AddRef((IShellItem*)This);
189 static ULONG WINAPI ShellItem_IPersistIDList_Release(IPersistIDList *iface)
191 ShellItem *This = impl_from_IPersistIDList(iface);
192 return ShellItem_Release((IShellItem*)This);
195 static HRESULT WINAPI ShellItem_IPersistIDList_GetClassID(IPersistIDList* iface,
196 CLSID *pClassID)
198 ShellItem *This = impl_from_IPersistIDList(iface);
200 return ShellItem_GetClassID(This, pClassID);
203 static HRESULT WINAPI ShellItem_IPersistIDList_SetIDList(IPersistIDList* iface,
204 LPCITEMIDLIST pidl)
206 ShellItem *This = impl_from_IPersistIDList(iface);
207 LPITEMIDLIST new_pidl;
209 TRACE("(%p,%p)\n", This, pidl);
211 new_pidl = ILClone(pidl);
213 if (new_pidl)
215 ILFree(This->pidl);
216 This->pidl = new_pidl;
217 return S_OK;
219 else
220 return E_OUTOFMEMORY;
223 static HRESULT WINAPI ShellItem_IPersistIDList_GetIDList(IPersistIDList* iface,
224 LPITEMIDLIST *ppidl)
226 ShellItem *This = impl_from_IPersistIDList(iface);
228 TRACE("(%p,%p)\n", This, ppidl);
230 *ppidl = ILClone(This->pidl);
231 if (*ppidl)
232 return S_OK;
233 else
234 return E_OUTOFMEMORY;
237 static const IPersistIDListVtbl ShellItem_IPersistIDList_Vtbl = {
238 ShellItem_IPersistIDList_QueryInterface,
239 ShellItem_IPersistIDList_AddRef,
240 ShellItem_IPersistIDList_Release,
241 ShellItem_IPersistIDList_GetClassID,
242 ShellItem_IPersistIDList_SetIDList,
243 ShellItem_IPersistIDList_GetIDList
247 HRESULT WINAPI IShellItem_Constructor(IUnknown *pUnkOuter, REFIID riid, void **ppv)
249 ShellItem *This;
250 HRESULT ret;
252 TRACE("(%p,%s)\n",pUnkOuter, debugstr_guid(riid));
254 *ppv = NULL;
256 if (pUnkOuter) return CLASS_E_NOAGGREGATION;
258 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ShellItem));
259 This->lpIShellItemVtbl = &ShellItem_Vtbl;
260 This->ref = 1;
261 This->pidl = NULL;
262 This->lpIPersistIDListVtbl = &ShellItem_IPersistIDList_Vtbl;
264 ret = ShellItem_QueryInterface((IShellItem*)This, riid, ppv);
265 ShellItem_Release((IShellItem*)This);
267 return ret;
270 HRESULT WINAPI SHCreateShellItem(LPCITEMIDLIST pidlParent,
271 IShellFolder *psfParent, LPCITEMIDLIST pidl, IShellItem **ppsi)
273 ShellItem *This;
274 LPITEMIDLIST new_pidl;
275 HRESULT ret;
277 TRACE("(%p,%p,%p,%p)\n", pidlParent, psfParent, pidl, ppsi);
279 if (!pidlParent && !psfParent && pidl)
281 new_pidl = ILClone(pidl);
282 if (!new_pidl)
283 return E_OUTOFMEMORY;
285 else
287 FIXME("(%p,%p,%p) not implemented\n", pidlParent, psfParent, pidl);
288 return E_NOINTERFACE;
291 ret = IShellItem_Constructor(NULL, &IID_IShellItem, (void**)&This);
292 if (This)
294 *ppsi = (IShellItem*)This;
295 This->pidl = new_pidl;
297 else
299 *ppsi = NULL;
300 ILFree(new_pidl);
302 return ret;