webservices: Add a stub implementation of WS_TYPE_ATTRIBUTE_FIELD_MAPPING in the...
[wine.git] / dlls / shell32 / enumidlist.c
blob182686c54c5a7c4745007c023fec01473acd5ea8
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) ||
174 IsEqualIID(riid, &IID_IEnumIDList))
176 *ppvObj = &This->IEnumIDList_iface;
179 if(*ppvObj)
180 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
181 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
182 return S_OK;
185 TRACE("-- Interface: E_NOINTERFACE\n");
186 return E_NOINTERFACE;
189 /******************************************************************************
190 * IEnumIDList::AddRef
192 static ULONG WINAPI IEnumIDList_fnAddRef(IEnumIDList *iface)
194 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
195 ULONG refCount = InterlockedIncrement(&This->ref);
197 TRACE("(%p)->(%u)\n", This, refCount - 1);
199 return refCount;
201 /******************************************************************************
202 * IEnumIDList::Release
204 static ULONG WINAPI IEnumIDList_fnRelease(IEnumIDList *iface)
206 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
207 ULONG refCount = InterlockedDecrement(&This->ref);
209 TRACE("(%p)->(%u)\n", This, refCount + 1);
211 if (!refCount) {
212 TRACE(" destroying IEnumIDList(%p)\n",This);
213 DeleteList(This);
214 HeapFree(GetProcessHeap(),0,This);
216 return refCount;
219 /**************************************************************************
220 * IEnumIDList::Next
223 static HRESULT WINAPI IEnumIDList_fnNext(IEnumIDList *iface, ULONG celt, LPITEMIDLIST *rgelt,
224 ULONG *pceltFetched)
226 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
228 ULONG i;
229 HRESULT hr = S_OK;
230 LPITEMIDLIST temp;
232 TRACE("(%p)->(%d,%p, %p)\n",This,celt,rgelt,pceltFetched);
234 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
235 * subsystems actually use it (and so may a third party browser)
237 if(pceltFetched)
238 *pceltFetched = 0;
240 *rgelt=0;
242 if(celt > 1 && !pceltFetched)
243 { return E_INVALIDARG;
246 if(celt > 0 && !This->mpCurrent)
247 { return S_FALSE;
250 for(i = 0; i < celt; i++)
251 { if(!(This->mpCurrent))
252 break;
254 temp = ILClone(This->mpCurrent->pidl);
255 rgelt[i] = temp;
256 This->mpCurrent = This->mpCurrent->pNext;
258 if(pceltFetched)
259 { *pceltFetched = i;
262 return hr;
265 /**************************************************************************
266 * IEnumIDList::Skip
268 static HRESULT WINAPI IEnumIDList_fnSkip(IEnumIDList *iface, ULONG celt)
270 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
272 DWORD dwIndex;
273 HRESULT hr = S_OK;
275 TRACE("(%p)->(%u)\n",This,celt);
277 for(dwIndex = 0; dwIndex < celt; dwIndex++)
278 { if(!This->mpCurrent)
279 { hr = S_FALSE;
280 break;
282 This->mpCurrent = This->mpCurrent->pNext;
284 return hr;
286 /**************************************************************************
287 * IEnumIDList::Reset
289 static HRESULT WINAPI IEnumIDList_fnReset(IEnumIDList *iface)
291 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
293 TRACE("(%p)\n",This);
294 This->mpCurrent = This->mpFirst;
295 return S_OK;
297 /**************************************************************************
298 * IEnumIDList::Clone
300 static HRESULT WINAPI IEnumIDList_fnClone(IEnumIDList *iface, IEnumIDList **ppenum)
302 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
304 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
305 return E_NOTIMPL;
308 static const IEnumIDListVtbl eidlvt =
310 IEnumIDList_fnQueryInterface,
311 IEnumIDList_fnAddRef,
312 IEnumIDList_fnRelease,
313 IEnumIDList_fnNext,
314 IEnumIDList_fnSkip,
315 IEnumIDList_fnReset,
316 IEnumIDList_fnClone,
319 IEnumIDListImpl *IEnumIDList_Constructor(void)
321 IEnumIDListImpl *lpeidl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*lpeidl));
323 if (lpeidl)
325 lpeidl->ref = 1;
326 lpeidl->IEnumIDList_iface.lpVtbl = &eidlvt;
329 TRACE("-- (%p)->()\n",lpeidl);
331 return lpeidl;