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 ULONG refCount
= InterlockedIncrement(&This
->ref
);
245 TRACE("(%p)->(%lu)\n", This
, refCount
- 1);
249 /******************************************************************************
250 * IEnumIDList_fnRelease
252 static ULONG WINAPI
IEnumIDList_fnRelease(
255 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
256 ULONG refCount
= InterlockedDecrement(&This
->ref
);
258 TRACE("(%p)->(%lu)\n", This
, refCount
+ 1);
261 TRACE(" destroying IEnumIDList(%p)\n",This
);
262 DeleteList((IEnumIDList
*)This
);
263 HeapFree(GetProcessHeap(),0,This
);
268 /**************************************************************************
272 static HRESULT WINAPI
IEnumIDList_fnNext(
275 LPITEMIDLIST
* rgelt
,
278 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
284 TRACE("(%p)->(%ld,%p, %p)\n",This
,celt
,rgelt
,pceltFetched
);
286 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
287 * subsystems actually use it (and so may a third party browser)
294 if(celt
> 1 && !pceltFetched
)
295 { return E_INVALIDARG
;
298 if(celt
> 0 && !This
->mpCurrent
)
302 for(i
= 0; i
< celt
; i
++)
303 { if(!(This
->mpCurrent
))
306 temp
= ILClone(This
->mpCurrent
->pidl
);
308 This
->mpCurrent
= This
->mpCurrent
->pNext
;
317 /**************************************************************************
320 static HRESULT WINAPI
IEnumIDList_fnSkip(
321 IEnumIDList
* iface
,ULONG celt
)
323 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
328 TRACE("(%p)->(%lu)\n",This
,celt
);
330 for(dwIndex
= 0; dwIndex
< celt
; dwIndex
++)
331 { if(!This
->mpCurrent
)
335 This
->mpCurrent
= This
->mpCurrent
->pNext
;
339 /**************************************************************************
340 * IEnumIDList_fnReset
342 static HRESULT WINAPI
IEnumIDList_fnReset(
345 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
347 TRACE("(%p)\n",This
);
348 This
->mpCurrent
= This
->mpFirst
;
351 /**************************************************************************
352 * IEnumIDList_fnClone
354 static HRESULT WINAPI
IEnumIDList_fnClone(
355 IEnumIDList
* iface
,LPENUMIDLIST
* ppenum
)
357 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
359 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This
,ppenum
);
363 /**************************************************************************
364 * IEnumIDList_fnVTable
366 static IEnumIDListVtbl eidlvt
=
368 IEnumIDList_fnQueryInterface
,
369 IEnumIDList_fnAddRef
,
370 IEnumIDList_fnRelease
,