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
= (LPENUMLIST
)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
);
101 /**************************************************************************
104 BOOL
HasItemWithCLSID(IEnumIDList
*iface
, LPITEMIDLIST pidl
)
106 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
108 REFIID refid
= _ILGetGUIDPointer(pidl
);
110 pCur
= This
->mpFirst
;
114 REFIID curid
= _ILGetGUIDPointer(pCur
->pidl
);
115 if (IsEqualIID(curid
, refid
))
125 /**************************************************************************
126 * CreateFolderEnumList()
128 BOOL
CreateFolderEnumList(
133 LPITEMIDLIST pidl
=NULL
;
134 WIN32_FIND_DATAW stffile
;
136 WCHAR szPath
[MAX_PATH
];
137 BOOL succeeded
= TRUE
;
138 static const WCHAR stars
[] = { '*','.','*',0 };
139 static const WCHAR dot
[] = { '.',0 };
140 static const WCHAR dotdot
[] = { '.','.',0 };
142 TRACE("(%p)->(path=%s flags=0x%08x)\n", list
, debugstr_w(lpszPath
), dwFlags
);
144 if(!lpszPath
|| !lpszPath
[0]) return FALSE
;
146 strcpyW(szPath
, lpszPath
);
147 PathAddBackslashW(szPath
);
148 strcatW(szPath
,stars
);
150 hFile
= FindFirstFileW(szPath
,&stffile
);
151 if ( hFile
!= INVALID_HANDLE_VALUE
)
153 BOOL findFinished
= FALSE
;
157 if ( !(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
)
158 || (dwFlags
& SHCONTF_INCLUDEHIDDEN
) )
160 if ( (stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
161 dwFlags
& SHCONTF_FOLDERS
&&
162 strcmpW(stffile
.cFileName
, dot
) && strcmpW(stffile
.cFileName
, dotdot
))
164 pidl
= _ILCreateFromFindDataW(&stffile
);
165 succeeded
= succeeded
&& AddToEnumList(list
, pidl
);
167 else if (!(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
168 && dwFlags
& SHCONTF_NONFOLDERS
)
170 pidl
= _ILCreateFromFindDataW(&stffile
);
171 succeeded
= succeeded
&& AddToEnumList(list
, pidl
);
176 if (!FindNextFileW(hFile
, &stffile
))
178 if (GetLastError() == ERROR_NO_MORE_FILES
)
184 } while (succeeded
&& !findFinished
);
190 /**************************************************************************
193 static BOOL
DeleteList(
196 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
200 TRACE("(%p)->()\n",This
);
203 { pDelete
= This
->mpFirst
;
204 This
->mpFirst
= pDelete
->pNext
;
205 SHFree(pDelete
->pidl
);
208 This
->mpFirst
= This
->mpLast
= This
->mpCurrent
= NULL
;
212 /**************************************************************************
213 * IEnumIDList_Folder_Constructor
217 IEnumIDList
* IEnumIDList_Constructor(void)
219 IEnumIDListImpl
*lpeidl
= HeapAlloc(GetProcessHeap(),
220 HEAP_ZERO_MEMORY
, sizeof(IEnumIDListImpl
));
225 lpeidl
->lpVtbl
= &eidlvt
;
227 TRACE("-- (%p)->()\n",lpeidl
);
229 return (IEnumIDList
*)lpeidl
;
232 /**************************************************************************
233 * EnumIDList_QueryInterface
235 static HRESULT WINAPI
IEnumIDList_fnQueryInterface(
240 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
242 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
246 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
249 else if(IsEqualIID(riid
, &IID_IEnumIDList
)) /*IEnumIDList*/
250 { *ppvObj
= (IEnumIDList
*)This
;
254 { IEnumIDList_AddRef((IEnumIDList
*)*ppvObj
);
255 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
259 TRACE("-- Interface: E_NOINTERFACE\n");
260 return E_NOINTERFACE
;
263 /******************************************************************************
264 * IEnumIDList_fnAddRef
266 static ULONG WINAPI
IEnumIDList_fnAddRef(
269 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
270 ULONG refCount
= InterlockedIncrement(&This
->ref
);
272 TRACE("(%p)->(%u)\n", This
, refCount
- 1);
276 /******************************************************************************
277 * IEnumIDList_fnRelease
279 static ULONG WINAPI
IEnumIDList_fnRelease(
282 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
283 ULONG refCount
= InterlockedDecrement(&This
->ref
);
285 TRACE("(%p)->(%u)\n", This
, refCount
+ 1);
288 TRACE(" destroying IEnumIDList(%p)\n",This
);
289 DeleteList((IEnumIDList
*)This
);
290 HeapFree(GetProcessHeap(),0,This
);
295 /**************************************************************************
299 static HRESULT WINAPI
IEnumIDList_fnNext(
302 LPITEMIDLIST
* rgelt
,
305 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
311 TRACE("(%p)->(%d,%p, %p)\n",This
,celt
,rgelt
,pceltFetched
);
313 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
314 * subsystems actually use it (and so may a third party browser)
321 if(celt
> 1 && !pceltFetched
)
322 { return E_INVALIDARG
;
325 if(celt
> 0 && !This
->mpCurrent
)
329 for(i
= 0; i
< celt
; i
++)
330 { if(!(This
->mpCurrent
))
333 temp
= ILClone(This
->mpCurrent
->pidl
);
335 This
->mpCurrent
= This
->mpCurrent
->pNext
;
344 /**************************************************************************
347 static HRESULT WINAPI
IEnumIDList_fnSkip(
348 IEnumIDList
* iface
,ULONG celt
)
350 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
355 TRACE("(%p)->(%u)\n",This
,celt
);
357 for(dwIndex
= 0; dwIndex
< celt
; dwIndex
++)
358 { if(!This
->mpCurrent
)
362 This
->mpCurrent
= This
->mpCurrent
->pNext
;
366 /**************************************************************************
367 * IEnumIDList_fnReset
369 static HRESULT WINAPI
IEnumIDList_fnReset(
372 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
374 TRACE("(%p)\n",This
);
375 This
->mpCurrent
= This
->mpFirst
;
378 /**************************************************************************
379 * IEnumIDList_fnClone
381 static HRESULT WINAPI
IEnumIDList_fnClone(
382 IEnumIDList
* iface
,LPENUMIDLIST
* ppenum
)
384 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
386 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This
,ppenum
);
390 /**************************************************************************
391 * IEnumIDList_fnVTable
393 static const IEnumIDListVtbl eidlvt
=
395 IEnumIDList_fnQueryInterface
,
396 IEnumIDList_fnAddRef
,
397 IEnumIDList_fnRelease
,