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
23 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
25 typedef struct tagENUMLIST
27 struct tagENUMLIST
*pNext
;
30 } ENUMLIST
, *LPENUMLIST
;
34 const IEnumIDListVtbl
*lpVtbl
;
42 static const IEnumIDListVtbl eidlvt
;
44 /**************************************************************************
51 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
55 TRACE("(%p)->(pidl=%p)\n",This
,pidl
);
60 pNew
= (LPENUMLIST
)SHAlloc(sizeof(ENUMLIST
));
63 /*set the next pointer */
67 /*is This the first item in the list? */
71 This
->mpCurrent
= pNew
;
76 /*add the new item to the end of the list */
77 This
->mpLast
->pNext
= pNew
;
80 /*update the last item pointer */
82 TRACE("-- (%p)->(first=%p, last=%p)\n",This
,This
->mpFirst
,This
->mpLast
);
87 /**************************************************************************
90 BOOL
HasItemWithCLSID(IEnumIDList
*iface
, LPITEMIDLIST pidl
)
92 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
94 REFIID refid
= _ILGetGUIDPointer(pidl
);
100 LPGUID curid
= _ILGetGUIDPointer(pCur
->pidl
);
101 if (curid
&& IsEqualGUID(curid
, refid
))
111 /**************************************************************************
112 * CreateFolderEnumList()
114 BOOL
CreateFolderEnumList(
119 LPITEMIDLIST pidl
=NULL
;
120 WIN32_FIND_DATAW stffile
;
122 WCHAR szPath
[MAX_PATH
];
123 BOOL succeeded
= TRUE
;
124 static const WCHAR stars
[] = { '*','.','*',0 };
125 static const WCHAR dot
[] = { '.',0 };
126 static const WCHAR dotdot
[] = { '.','.',0 };
128 TRACE("(%p)->(path=%s flags=0x%08x)\n", list
, debugstr_w(lpszPath
), dwFlags
);
130 if(!lpszPath
|| !lpszPath
[0]) return FALSE
;
132 wcscpy(szPath
, lpszPath
);
133 PathAddBackslashW(szPath
);
134 wcscat(szPath
,stars
);
136 hFile
= FindFirstFileW(szPath
,&stffile
);
137 if ( hFile
!= INVALID_HANDLE_VALUE
)
139 BOOL findFinished
= FALSE
;
143 if ( !(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
)
144 || (dwFlags
& SHCONTF_INCLUDEHIDDEN
) )
146 if ( (stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
147 dwFlags
& SHCONTF_FOLDERS
&&
148 strcmpW(stffile
.cFileName
, dot
) && strcmpW(stffile
.cFileName
, dotdot
))
150 pidl
= _ILCreateFromFindDataW(&stffile
);
151 succeeded
= succeeded
&& AddToEnumList(list
, pidl
);
153 else if (!(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
154 && dwFlags
& SHCONTF_NONFOLDERS
)
156 pidl
= _ILCreateFromFindDataW(&stffile
);
157 succeeded
= succeeded
&& AddToEnumList(list
, pidl
);
162 if (!FindNextFileW(hFile
, &stffile
))
164 if (GetLastError() == ERROR_NO_MORE_FILES
)
170 } while (succeeded
&& !findFinished
);
176 /**************************************************************************
179 static BOOL
DeleteList(
182 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
186 TRACE("(%p)->()\n",This
);
189 { pDelete
= This
->mpFirst
;
190 This
->mpFirst
= pDelete
->pNext
;
191 SHFree(pDelete
->pidl
);
194 This
->mpFirst
= This
->mpLast
= This
->mpCurrent
= NULL
;
198 /**************************************************************************
199 * IEnumIDList_Folder_Constructor
203 IEnumIDList
* IEnumIDList_Constructor(void)
205 IEnumIDListImpl
*lpeidl
= HeapAlloc(GetProcessHeap(),
206 HEAP_ZERO_MEMORY
, sizeof(IEnumIDListImpl
));
211 lpeidl
->lpVtbl
= &eidlvt
;
213 TRACE("-- (%p)->()\n",lpeidl
);
215 return (IEnumIDList
*)lpeidl
;
218 /**************************************************************************
219 * EnumIDList_QueryInterface
221 static HRESULT WINAPI
IEnumIDList_fnQueryInterface(
226 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
228 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
232 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
235 else if(IsEqualIID(riid
, &IID_IEnumIDList
)) /*IEnumIDList*/
236 { *ppvObj
= (IEnumIDList
*)This
;
240 { IEnumIDList_AddRef((IEnumIDList
*)*ppvObj
);
241 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
245 TRACE("-- Interface: E_NOINTERFACE\n");
246 return E_NOINTERFACE
;
249 /******************************************************************************
250 * IEnumIDList_fnAddRef
252 static ULONG WINAPI
IEnumIDList_fnAddRef(
255 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
256 ULONG refCount
= InterlockedIncrement(&This
->ref
);
258 TRACE("(%p)->(%u)\n", This
, refCount
- 1);
262 /******************************************************************************
263 * IEnumIDList_fnRelease
265 static ULONG WINAPI
IEnumIDList_fnRelease(
268 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
269 ULONG refCount
= InterlockedDecrement(&This
->ref
);
271 TRACE("(%p)->(%u)\n", This
, refCount
+ 1);
274 TRACE(" destroying IEnumIDList(%p)\n",This
);
275 DeleteList((IEnumIDList
*)This
);
276 HeapFree(GetProcessHeap(),0,This
);
281 /**************************************************************************
285 static HRESULT WINAPI
IEnumIDList_fnNext(
288 LPITEMIDLIST
* rgelt
,
291 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
297 TRACE("(%p)->(%d,%p, %p)\n",This
,celt
,rgelt
,pceltFetched
);
299 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
300 * subsystems actually use it (and so may a third party browser)
307 if(celt
> 1 && !pceltFetched
)
308 { return E_INVALIDARG
;
311 if(celt
> 0 && !This
->mpCurrent
)
315 for(i
= 0; i
< celt
; i
++)
316 { if(!(This
->mpCurrent
))
319 temp
= ILClone(This
->mpCurrent
->pidl
);
321 This
->mpCurrent
= This
->mpCurrent
->pNext
;
330 /**************************************************************************
333 static HRESULT WINAPI
IEnumIDList_fnSkip(
334 IEnumIDList
* iface
,ULONG celt
)
336 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
341 TRACE("(%p)->(%u)\n",This
,celt
);
343 for(dwIndex
= 0; dwIndex
< celt
; dwIndex
++)
344 { if(!This
->mpCurrent
)
348 This
->mpCurrent
= This
->mpCurrent
->pNext
;
352 /**************************************************************************
353 * IEnumIDList_fnReset
355 static HRESULT WINAPI
IEnumIDList_fnReset(
358 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
360 TRACE("(%p)\n",This
);
361 This
->mpCurrent
= This
->mpFirst
;
364 /**************************************************************************
365 * IEnumIDList_fnClone
367 static HRESULT WINAPI
IEnumIDList_fnClone(
368 IEnumIDList
* iface
,LPENUMIDLIST
* ppenum
)
370 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
372 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This
,ppenum
);
376 /**************************************************************************
377 * IEnumIDList_fnVTable
379 static const IEnumIDListVtbl eidlvt
=
381 IEnumIDList_fnQueryInterface
,
382 IEnumIDList_fnAddRef
,
383 IEnumIDList_fnRelease
,