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 "shell32_main.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shell);
41 struct enumlist *pNext;
47 IEnumIDList IEnumIDList_iface;
49 struct enumlist *mpFirst;
50 struct enumlist *mpLast;
51 struct enumlist *mpCurrent;
55 /**************************************************************************
62 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
64 struct enumlist *pNew;
66 TRACE("(%p)->(pidl=%p)\n",This,pidl);
71 pNew = SHAlloc(sizeof(*pNew));
74 /*set the next pointer */
78 /*is This the first item in the list? */
82 This->mpCurrent = pNew;
87 /*add the new item to the end of the list */
88 This->mpLast->pNext = pNew;
91 /*update the last item pointer */
93 TRACE("-- (%p)->(first=%p, last=%p)\n",This,This->mpFirst,This->mpLast);
99 /**************************************************************************
100 * CreateFolderEnumList()
102 BOOL CreateFolderEnumList(
107 LPITEMIDLIST pidl=NULL;
108 WIN32_FIND_DATAW stffile;
110 WCHAR szPath[MAX_PATH];
111 BOOL succeeded = TRUE;
112 static const WCHAR stars[] = { '*','.','*',0 };
113 static const WCHAR dot[] = { '.',0 };
114 static const WCHAR dotdot[] = { '.','.',0 };
116 TRACE("(%p)->(path=%s flags=0x%08x)\n", list, debugstr_w(lpszPath), dwFlags);
118 if(!lpszPath || !lpszPath[0]) return FALSE;
120 strcpyW(szPath, lpszPath);
121 PathAddBackslashW(szPath);
122 strcatW(szPath,stars);
124 hFile = FindFirstFileW(szPath,&stffile);
125 if ( hFile != INVALID_HANDLE_VALUE )
127 BOOL findFinished = FALSE;
131 if ( !(stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
132 || (dwFlags & SHCONTF_INCLUDEHIDDEN) )
134 if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
135 dwFlags & SHCONTF_FOLDERS &&
136 strcmpW(stffile.cFileName, dot) && strcmpW(stffile.cFileName, dotdot))
138 pidl = _ILCreateFromFindDataW(&stffile);
139 succeeded = succeeded && AddToEnumList(list, pidl);
141 else if (!(stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
142 && dwFlags & SHCONTF_NONFOLDERS)
144 pidl = _ILCreateFromFindDataW(&stffile);
145 succeeded = succeeded && AddToEnumList(list, pidl);
150 if (!FindNextFileW(hFile, &stffile))
152 if (GetLastError() == ERROR_NO_MORE_FILES)
158 } while (succeeded && !findFinished);
164 static BOOL DeleteList(IEnumIDListImpl *This)
166 struct enumlist *pDelete;
168 TRACE("(%p)->()\n",This);
171 { pDelete = This->mpFirst;
172 This->mpFirst = pDelete->pNext;
173 SHFree(pDelete->pidl);
176 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
180 static inline IEnumIDListImpl *impl_from_IEnumIDList(IEnumIDList *iface)
182 return CONTAINING_RECORD(iface, IEnumIDListImpl, IEnumIDList_iface);
185 /**************************************************************************
186 * IEnumIDList::QueryInterface
188 static HRESULT WINAPI IEnumIDList_fnQueryInterface(IEnumIDList *iface, REFIID riid, void **ppvObj)
190 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
192 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
196 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
199 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
204 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
205 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
209 TRACE("-- Interface: E_NOINTERFACE\n");
210 return E_NOINTERFACE;
213 /******************************************************************************
214 * IEnumIDList::AddRef
216 static ULONG WINAPI IEnumIDList_fnAddRef(IEnumIDList *iface)
218 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
219 ULONG refCount = InterlockedIncrement(&This->ref);
221 TRACE("(%p)->(%u)\n", This, refCount - 1);
225 /******************************************************************************
226 * IEnumIDList::Release
228 static ULONG WINAPI IEnumIDList_fnRelease(IEnumIDList *iface)
230 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
231 ULONG refCount = InterlockedDecrement(&This->ref);
233 TRACE("(%p)->(%u)\n", This, refCount + 1);
236 TRACE(" destroying IEnumIDList(%p)\n",This);
238 HeapFree(GetProcessHeap(),0,This);
243 /**************************************************************************
247 static HRESULT WINAPI IEnumIDList_fnNext(IEnumIDList *iface, ULONG celt, LPITEMIDLIST *rgelt,
250 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
256 TRACE("(%p)->(%d,%p, %p)\n",This,celt,rgelt,pceltFetched);
258 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
259 * subsystems actually use it (and so may a third party browser)
266 if(celt > 1 && !pceltFetched)
267 { return E_INVALIDARG;
270 if(celt > 0 && !This->mpCurrent)
274 for(i = 0; i < celt; i++)
275 { if(!(This->mpCurrent))
278 temp = ILClone(This->mpCurrent->pidl);
280 This->mpCurrent = This->mpCurrent->pNext;
289 /**************************************************************************
292 static HRESULT WINAPI IEnumIDList_fnSkip(IEnumIDList *iface, ULONG celt)
294 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
299 TRACE("(%p)->(%u)\n",This,celt);
301 for(dwIndex = 0; dwIndex < celt; dwIndex++)
302 { if(!This->mpCurrent)
306 This->mpCurrent = This->mpCurrent->pNext;
310 /**************************************************************************
313 static HRESULT WINAPI IEnumIDList_fnReset(IEnumIDList *iface)
315 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
317 TRACE("(%p)\n",This);
318 This->mpCurrent = This->mpFirst;
321 /**************************************************************************
324 static HRESULT WINAPI IEnumIDList_fnClone(IEnumIDList *iface, IEnumIDList **ppenum)
326 IEnumIDListImpl *This = impl_from_IEnumIDList(iface);
328 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
332 static const IEnumIDListVtbl eidlvt =
334 IEnumIDList_fnQueryInterface,
335 IEnumIDList_fnAddRef,
336 IEnumIDList_fnRelease,
343 IEnumIDList *IEnumIDList_Constructor(void)
345 IEnumIDListImpl *lpeidl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*lpeidl));
350 lpeidl->IEnumIDList_iface.lpVtbl = &eidlvt;
355 TRACE("-- (%p)->()\n",lpeidl);
357 return &lpeidl->IEnumIDList_iface;