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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/debug.h"
34 #include "enumidlist.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(shell);
38 typedef struct tagENUMLIST
40 struct tagENUMLIST *pNext;
43 } ENUMLIST, *LPENUMLIST;
47 IEnumIDListVtbl *lpVtbl;
55 static struct IEnumIDListVtbl eidlvt;
57 /**************************************************************************
64 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
68 TRACE("(%p)->(pidl=%p)\n",This,pidl);
73 pNew = (LPENUMLIST)SHAlloc(sizeof(ENUMLIST));
76 /*set the next pointer */
80 /*is This the first item in the list? */
84 This->mpCurrent = pNew;
89 /*add the new item to the end of the list */
90 This->mpLast->pNext = pNew;
93 /*update the last item pointer */
95 TRACE("-- (%p)->(first=%p, last=%p)\n",This,This->mpFirst,This->mpLast);
101 /**************************************************************************
102 * CreateFolderEnumList()
104 BOOL CreateFolderEnumList(
109 LPITEMIDLIST pidl=NULL;
110 WIN32_FIND_DATAA stffile;
112 CHAR szPath[MAX_PATH];
113 BOOL succeeded = TRUE;
115 TRACE("(%p)->(path=%s flags=0x%08lx) \n",list,debugstr_a(lpszPath),dwFlags);
117 if(!lpszPath || !lpszPath[0]) return FALSE;
119 strcpy(szPath, lpszPath);
120 PathAddBackslashA(szPath);
121 strcat(szPath,"*.*");
123 hFile = FindFirstFileA(szPath,&stffile);
124 if ( hFile != INVALID_HANDLE_VALUE )
126 BOOL findFinished = FALSE;
130 if ( !(stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
131 || (dwFlags & SHCONTF_INCLUDEHIDDEN) )
133 if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
134 dwFlags & SHCONTF_FOLDERS &&
135 strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, ".."))
137 pidl = _ILCreateFromFindDataA(&stffile);
138 succeeded = succeeded && AddToEnumList(list, pidl);
140 else if (!(stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
141 && dwFlags & SHCONTF_NONFOLDERS)
143 pidl = _ILCreateFromFindDataA(&stffile);
144 succeeded = succeeded && AddToEnumList(list, pidl);
149 if (!FindNextFileA(hFile, &stffile))
151 if (GetLastError() == ERROR_NO_MORE_FILES)
157 } while (succeeded && !findFinished);
163 /**************************************************************************
166 static BOOL DeleteList(
169 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
173 TRACE("(%p)->()\n",This);
176 { pDelete = This->mpFirst;
177 This->mpFirst = pDelete->pNext;
178 SHFree(pDelete->pidl);
181 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
185 /**************************************************************************
186 * IEnumIDList_Folder_Constructor
190 IEnumIDList * IEnumIDList_Constructor(void)
192 IEnumIDListImpl *lpeidl = (IEnumIDListImpl*)HeapAlloc(GetProcessHeap(),
193 HEAP_ZERO_MEMORY, sizeof(IEnumIDListImpl));
198 lpeidl->lpVtbl = &eidlvt;
200 TRACE("-- (%p)->()\n",lpeidl);
202 return (IEnumIDList*)lpeidl;
205 /**************************************************************************
206 * EnumIDList_QueryInterface
208 static HRESULT WINAPI IEnumIDList_fnQueryInterface(
213 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
215 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
219 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
222 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
223 { *ppvObj = (IEnumIDList*)This;
227 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
228 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
232 TRACE("-- Interface: E_NOINTERFACE\n");
233 return E_NOINTERFACE;
236 /******************************************************************************
237 * IEnumIDList_fnAddRef
239 static ULONG WINAPI IEnumIDList_fnAddRef(
242 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
243 TRACE("(%p)->(%lu)\n",This,This->ref);
244 return ++(This->ref);
246 /******************************************************************************
247 * IEnumIDList_fnRelease
249 static ULONG WINAPI IEnumIDList_fnRelease(
252 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
254 TRACE("(%p)->(%lu)\n",This,This->ref);
256 if (!--(This->ref)) {
257 TRACE(" destroying IEnumIDList(%p)\n",This);
258 DeleteList((IEnumIDList*)This);
259 HeapFree(GetProcessHeap(),0,This);
265 /**************************************************************************
269 static HRESULT WINAPI IEnumIDList_fnNext(
272 LPITEMIDLIST * rgelt,
275 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
281 TRACE("(%p)->(%ld,%p, %p)\n",This,celt,rgelt,pceltFetched);
283 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
284 * subsystems actually use it (and so may a third party browser)
291 if(celt > 1 && !pceltFetched)
292 { return E_INVALIDARG;
295 if(celt > 0 && !This->mpCurrent)
299 for(i = 0; i < celt; i++)
300 { if(!(This->mpCurrent))
303 temp = ILClone(This->mpCurrent->pidl);
305 This->mpCurrent = This->mpCurrent->pNext;
314 /**************************************************************************
317 static HRESULT WINAPI IEnumIDList_fnSkip(
318 IEnumIDList * iface,ULONG celt)
320 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
325 TRACE("(%p)->(%lu)\n",This,celt);
327 for(dwIndex = 0; dwIndex < celt; dwIndex++)
328 { if(!This->mpCurrent)
332 This->mpCurrent = This->mpCurrent->pNext;
336 /**************************************************************************
337 * IEnumIDList_fnReset
339 static HRESULT WINAPI IEnumIDList_fnReset(
342 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
344 TRACE("(%p)\n",This);
345 This->mpCurrent = This->mpFirst;
348 /**************************************************************************
349 * IEnumIDList_fnClone
351 static HRESULT WINAPI IEnumIDList_fnClone(
352 IEnumIDList * iface,LPENUMIDLIST * ppenum)
354 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
356 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
360 /**************************************************************************
361 * IEnumIDList_fnVTable
363 static IEnumIDListVtbl eidlvt =
365 IEnumIDList_fnQueryInterface,
366 IEnumIDList_fnAddRef,
367 IEnumIDList_fnRelease,