mpr: Tweak a label so it matches the one in wininet.
[wine/multimedia.git] / dlls / shell32 / enumidlist.c
blob8ee789bec2afc223250dfe91b4551210628aaafe
1 /*
2 * IEnumIDList
4 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
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 <stdarg.h>
22 #include <stdlib.h>
23 #include <string.h>
25 #define COBJMACROS
27 #include "wine/debug.h"
28 #include "wine/unicode.h"
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winreg.h"
32 #include "shlwapi.h"
34 #include "pidl.h"
35 #include "shell32_main.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shell);
39 /**************************************************************************
40 * AddToEnumList()
42 BOOL AddToEnumList(IEnumIDListImpl *This, LPITEMIDLIST pidl)
44 struct enumlist *pNew;
46 TRACE("(%p)->(pidl=%p)\n",This,pidl);
48 if (!This || !pidl)
49 return FALSE;
51 pNew = SHAlloc(sizeof(*pNew));
52 if(pNew)
54 /*set the next pointer */
55 pNew->pNext = NULL;
56 pNew->pidl = pidl;
58 /*is This the first item in the list? */
59 if(!This->mpFirst)
61 This->mpFirst = pNew;
62 This->mpCurrent = pNew;
65 if(This->mpLast)
67 /*add the new item to the end of the list */
68 This->mpLast->pNext = pNew;
71 /*update the last item pointer */
72 This->mpLast = pNew;
73 TRACE("-- (%p)->(first=%p, last=%p)\n",This,This->mpFirst,This->mpLast);
74 return TRUE;
76 return FALSE;
79 /**************************************************************************
80 * CreateFolderEnumList()
82 BOOL CreateFolderEnumList(IEnumIDListImpl *list, LPCWSTR lpszPath, DWORD dwFlags)
84 LPITEMIDLIST pidl=NULL;
85 WIN32_FIND_DATAW stffile;
86 HANDLE hFile;
87 WCHAR szPath[MAX_PATH];
88 BOOL succeeded = TRUE;
89 static const WCHAR stars[] = { '*','.','*',0 };
90 static const WCHAR dot[] = { '.',0 };
91 static const WCHAR dotdot[] = { '.','.',0 };
93 TRACE("(%p)->(path=%s flags=0x%08x)\n", list, debugstr_w(lpszPath), dwFlags);
95 if(!lpszPath || !lpszPath[0]) return FALSE;
97 strcpyW(szPath, lpszPath);
98 PathAddBackslashW(szPath);
99 strcatW(szPath,stars);
101 hFile = FindFirstFileW(szPath,&stffile);
102 if ( hFile != INVALID_HANDLE_VALUE )
104 BOOL findFinished = FALSE;
108 if ( !(stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
109 || (dwFlags & SHCONTF_INCLUDEHIDDEN) )
111 if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
112 dwFlags & SHCONTF_FOLDERS &&
113 strcmpW(stffile.cFileName, dot) && strcmpW(stffile.cFileName, dotdot))
115 pidl = _ILCreateFromFindDataW(&stffile);
116 succeeded = succeeded && AddToEnumList(list, pidl);
118 else if (!(stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
119 && dwFlags & SHCONTF_NONFOLDERS)
121 pidl = _ILCreateFromFindDataW(&stffile);
122 succeeded = succeeded && AddToEnumList(list, pidl);
125 if (succeeded)
127 if (!FindNextFileW(hFile, &stffile))
129 if (GetLastError() == ERROR_NO_MORE_FILES)
130 findFinished = TRUE;
131 else
132 succeeded = FALSE;
135 } while (succeeded && !findFinished);
136 FindClose(hFile);
138 return succeeded;
141 static BOOL DeleteList(IEnumIDListImpl *This)
143 struct enumlist *pDelete;
145 TRACE("(%p)->()\n",This);
147 while(This->mpFirst)
148 { pDelete = This->mpFirst;
149 This->mpFirst = pDelete->pNext;
150 SHFree(pDelete->pidl);
151 SHFree(pDelete);
153 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
154 return TRUE;
157 static inline IEnumIDListImpl *impl_from_IEnumIDList(IEnumIDList *iface)
159 return CONTAINING_RECORD(iface, IEnumIDListImpl, IEnumIDList_iface);
162 /**************************************************************************
163 * IEnumIDList::QueryInterface
165 static HRESULT WINAPI IEnumIDList_fnQueryInterface(IEnumIDList *iface, REFIID riid, void **ppvObj)
167 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
169 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
171 *ppvObj = NULL;
173 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
174 { *ppvObj = This;
176 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
177 { *ppvObj = This;
180 if(*ppvObj)
181 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
182 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
183 return S_OK;
186 TRACE("-- Interface: E_NOINTERFACE\n");
187 return E_NOINTERFACE;
190 /******************************************************************************
191 * IEnumIDList::AddRef
193 static ULONG WINAPI IEnumIDList_fnAddRef(IEnumIDList *iface)
195 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
196 ULONG refCount = InterlockedIncrement(&This->ref);
198 TRACE("(%p)->(%u)\n", This, refCount - 1);
200 return refCount;
202 /******************************************************************************
203 * IEnumIDList::Release
205 static ULONG WINAPI IEnumIDList_fnRelease(IEnumIDList *iface)
207 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
208 ULONG refCount = InterlockedDecrement(&This->ref);
210 TRACE("(%p)->(%u)\n", This, refCount + 1);
212 if (!refCount) {
213 TRACE(" destroying IEnumIDList(%p)\n",This);
214 DeleteList(This);
215 HeapFree(GetProcessHeap(),0,This);
217 return refCount;
220 /**************************************************************************
221 * IEnumIDList::Next
224 static HRESULT WINAPI IEnumIDList_fnNext(IEnumIDList *iface, ULONG celt, LPITEMIDLIST *rgelt,
225 ULONG *pceltFetched)
227 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
229 ULONG i;
230 HRESULT hr = S_OK;
231 LPITEMIDLIST temp;
233 TRACE("(%p)->(%d,%p, %p)\n",This,celt,rgelt,pceltFetched);
235 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
236 * subsystems actually use it (and so may a third party browser)
238 if(pceltFetched)
239 *pceltFetched = 0;
241 *rgelt=0;
243 if(celt > 1 && !pceltFetched)
244 { return E_INVALIDARG;
247 if(celt > 0 && !This->mpCurrent)
248 { return S_FALSE;
251 for(i = 0; i < celt; i++)
252 { if(!(This->mpCurrent))
253 break;
255 temp = ILClone(This->mpCurrent->pidl);
256 rgelt[i] = temp;
257 This->mpCurrent = This->mpCurrent->pNext;
259 if(pceltFetched)
260 { *pceltFetched = i;
263 return hr;
266 /**************************************************************************
267 * IEnumIDList::Skip
269 static HRESULT WINAPI IEnumIDList_fnSkip(IEnumIDList *iface, ULONG celt)
271 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
273 DWORD dwIndex;
274 HRESULT hr = S_OK;
276 TRACE("(%p)->(%u)\n",This,celt);
278 for(dwIndex = 0; dwIndex < celt; dwIndex++)
279 { if(!This->mpCurrent)
280 { hr = S_FALSE;
281 break;
283 This->mpCurrent = This->mpCurrent->pNext;
285 return hr;
287 /**************************************************************************
288 * IEnumIDList::Reset
290 static HRESULT WINAPI IEnumIDList_fnReset(IEnumIDList *iface)
292 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
294 TRACE("(%p)\n",This);
295 This->mpCurrent = This->mpFirst;
296 return S_OK;
298 /**************************************************************************
299 * IEnumIDList::Clone
301 static HRESULT WINAPI IEnumIDList_fnClone(IEnumIDList *iface, IEnumIDList **ppenum)
303 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
305 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
306 return E_NOTIMPL;
309 static const IEnumIDListVtbl eidlvt =
311 IEnumIDList_fnQueryInterface,
312 IEnumIDList_fnAddRef,
313 IEnumIDList_fnRelease,
314 IEnumIDList_fnNext,
315 IEnumIDList_fnSkip,
316 IEnumIDList_fnReset,
317 IEnumIDList_fnClone,
320 IEnumIDListImpl *IEnumIDList_Constructor(void)
322 IEnumIDListImpl *lpeidl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*lpeidl));
324 if (lpeidl)
326 lpeidl->ref = 1;
327 lpeidl->IEnumIDList_iface.lpVtbl = &eidlvt;
330 TRACE("-- (%p)->()\n",lpeidl);
332 return lpeidl;