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
27 #include "wine/debug.h"
28 #include "wine/unicode.h"
35 #include "enumidlist.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shell);
39 typedef struct tagENUMLIST
41 struct tagENUMLIST *pNext;
44 } ENUMLIST, *LPENUMLIST;
48 const IEnumIDListVtbl *lpVtbl;
56 static const IEnumIDListVtbl eidlvt;
58 /**************************************************************************
65 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
69 TRACE("(%p)->(pidl=%p)\n",This,pidl);
74 pNew = SHAlloc(sizeof(ENUMLIST));
77 /*set the next pointer */
81 /*is This the first item in the list? */
85 This->mpCurrent = pNew;
90 /*add the new item to the end of the list */
91 This->mpLast->pNext = pNew;
94 /*update the last item pointer */
96 TRACE("-- (%p)->(first=%p, last=%p)\n",This,This->mpFirst,This->mpLast);
102 /**************************************************************************
103 * CreateFolderEnumList()
105 BOOL CreateFolderEnumList(
110 LPITEMIDLIST pidl=NULL;
111 WIN32_FIND_DATAW stffile;
113 WCHAR szPath[MAX_PATH];
114 BOOL succeeded = TRUE;
115 static const WCHAR stars[] = { '*','.','*',0 };
116 static const WCHAR dot[] = { '.',0 };
117 static const WCHAR dotdot[] = { '.','.',0 };
119 TRACE("(%p)->(path=%s flags=0x%08x)\n", list, debugstr_w(lpszPath), dwFlags);
121 if(!lpszPath || !lpszPath[0]) return FALSE;
123 strcpyW(szPath, lpszPath);
124 PathAddBackslashW(szPath);
125 strcatW(szPath,stars);
127 hFile = FindFirstFileW(szPath,&stffile);
128 if ( hFile != INVALID_HANDLE_VALUE )
130 BOOL findFinished = FALSE;
134 if ( !(stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
135 || (dwFlags & SHCONTF_INCLUDEHIDDEN) )
137 if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
138 dwFlags & SHCONTF_FOLDERS &&
139 strcmpW(stffile.cFileName, dot) && strcmpW(stffile.cFileName, dotdot))
141 pidl = _ILCreateFromFindDataW(&stffile);
142 succeeded = succeeded && AddToEnumList(list, pidl);
144 else if (!(stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
145 && dwFlags & SHCONTF_NONFOLDERS)
147 pidl = _ILCreateFromFindDataW(&stffile);
148 succeeded = succeeded && AddToEnumList(list, pidl);
153 if (!FindNextFileW(hFile, &stffile))
155 if (GetLastError() == ERROR_NO_MORE_FILES)
161 } while (succeeded && !findFinished);
167 /**************************************************************************
170 static BOOL DeleteList(
173 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
177 TRACE("(%p)->()\n",This);
180 { pDelete = This->mpFirst;
181 This->mpFirst = pDelete->pNext;
182 SHFree(pDelete->pidl);
185 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
189 /**************************************************************************
190 * IEnumIDList_Folder_Constructor
194 IEnumIDList * IEnumIDList_Constructor(void)
196 IEnumIDListImpl *lpeidl = HeapAlloc(GetProcessHeap(),
197 HEAP_ZERO_MEMORY, sizeof(IEnumIDListImpl));
202 lpeidl->lpVtbl = &eidlvt;
204 TRACE("-- (%p)->()\n",lpeidl);
206 return (IEnumIDList*)lpeidl;
209 /**************************************************************************
210 * EnumIDList_QueryInterface
212 static HRESULT WINAPI IEnumIDList_fnQueryInterface(
217 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
219 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
223 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
226 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
231 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
232 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
236 TRACE("-- Interface: E_NOINTERFACE\n");
237 return E_NOINTERFACE;
240 /******************************************************************************
241 * IEnumIDList_fnAddRef
243 static ULONG WINAPI IEnumIDList_fnAddRef(
246 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
247 ULONG refCount = InterlockedIncrement(&This->ref);
249 TRACE("(%p)->(%u)\n", This, refCount - 1);
253 /******************************************************************************
254 * IEnumIDList_fnRelease
256 static ULONG WINAPI IEnumIDList_fnRelease(
259 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
260 ULONG refCount = InterlockedDecrement(&This->ref);
262 TRACE("(%p)->(%u)\n", This, refCount + 1);
265 TRACE(" destroying IEnumIDList(%p)\n",This);
266 DeleteList((IEnumIDList*)This);
267 HeapFree(GetProcessHeap(),0,This);
272 /**************************************************************************
276 static HRESULT WINAPI IEnumIDList_fnNext(
279 LPITEMIDLIST * rgelt,
282 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
288 TRACE("(%p)->(%d,%p, %p)\n",This,celt,rgelt,pceltFetched);
290 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
291 * subsystems actually use it (and so may a third party browser)
298 if(celt > 1 && !pceltFetched)
299 { return E_INVALIDARG;
302 if(celt > 0 && !This->mpCurrent)
306 for(i = 0; i < celt; i++)
307 { if(!(This->mpCurrent))
310 temp = ILClone(This->mpCurrent->pidl);
312 This->mpCurrent = This->mpCurrent->pNext;
321 /**************************************************************************
324 static HRESULT WINAPI IEnumIDList_fnSkip(
325 IEnumIDList * iface,ULONG celt)
327 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
332 TRACE("(%p)->(%u)\n",This,celt);
334 for(dwIndex = 0; dwIndex < celt; dwIndex++)
335 { if(!This->mpCurrent)
339 This->mpCurrent = This->mpCurrent->pNext;
343 /**************************************************************************
344 * IEnumIDList_fnReset
346 static HRESULT WINAPI IEnumIDList_fnReset(
349 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
351 TRACE("(%p)\n",This);
352 This->mpCurrent = This->mpFirst;
355 /**************************************************************************
356 * IEnumIDList_fnClone
358 static HRESULT WINAPI IEnumIDList_fnClone(
359 IEnumIDList * iface,LPENUMIDLIST * ppenum)
361 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
363 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
367 /**************************************************************************
368 * IEnumIDList_fnVTable
370 static const IEnumIDListVtbl eidlvt =
372 IEnumIDList_fnQueryInterface,
373 IEnumIDList_fnAddRef,
374 IEnumIDList_fnRelease,