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
);
39 /**************************************************************************
42 BOOL
AddToEnumList(IEnumIDListImpl
*This
, LPITEMIDLIST pidl
)
44 struct enumlist
*pNew
;
46 TRACE("(%p)->(pidl=%p)\n",This
,pidl
);
51 pNew
= SHAlloc(sizeof(*pNew
));
54 /*set the next pointer */
58 /*is This the first item in the list? */
62 This
->mpCurrent
= pNew
;
67 /*add the new item to the end of the list */
68 This
->mpLast
->pNext
= pNew
;
71 /*update the last item pointer */
73 TRACE("-- (%p)->(first=%p, last=%p)\n",This
,This
->mpFirst
,This
->mpLast
);
79 /**************************************************************************
80 * CreateFolderEnumList()
82 BOOL
CreateFolderEnumList(IEnumIDListImpl
*list
, LPCWSTR lpszPath
, DWORD dwFlags
)
84 LPITEMIDLIST pidl
=NULL
;
85 WIN32_FIND_DATAW stffile
;
87 WCHAR szPath
[MAX_PATH
];
88 BOOL succeeded
= TRUE
;
89 static const WCHAR stars
[] = { '*','.','*',0 };
90 static const WCHAR dot
[] = { '.',0 };
91 static const WCHAR dotdot
[] = { '.','.',0 };
93 TRACE("(%p)->(path=%s flags=0x%08x)\n", list
, debugstr_w(lpszPath
), dwFlags
);
95 if(!lpszPath
|| !lpszPath
[0]) return FALSE
;
97 strcpyW(szPath
, lpszPath
);
98 PathAddBackslashW(szPath
);
99 strcatW(szPath
,stars
);
101 hFile
= FindFirstFileW(szPath
,&stffile
);
102 if ( hFile
!= INVALID_HANDLE_VALUE
)
104 BOOL findFinished
= FALSE
;
108 if ( !(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
)
109 || (dwFlags
& SHCONTF_INCLUDEHIDDEN
) )
111 if ( (stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
112 dwFlags
& SHCONTF_FOLDERS
&&
113 strcmpW(stffile
.cFileName
, dot
) && strcmpW(stffile
.cFileName
, dotdot
))
115 pidl
= _ILCreateFromFindDataW(&stffile
);
116 succeeded
= succeeded
&& AddToEnumList(list
, pidl
);
118 else if (!(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
119 && dwFlags
& SHCONTF_NONFOLDERS
)
121 pidl
= _ILCreateFromFindDataW(&stffile
);
122 succeeded
= succeeded
&& AddToEnumList(list
, pidl
);
127 if (!FindNextFileW(hFile
, &stffile
))
129 if (GetLastError() == ERROR_NO_MORE_FILES
)
135 } while (succeeded
&& !findFinished
);
141 static BOOL
DeleteList(IEnumIDListImpl
*This
)
143 struct enumlist
*pDelete
;
145 TRACE("(%p)->()\n",This
);
148 { pDelete
= This
->mpFirst
;
149 This
->mpFirst
= pDelete
->pNext
;
150 SHFree(pDelete
->pidl
);
153 This
->mpFirst
= This
->mpLast
= This
->mpCurrent
= NULL
;
157 static inline IEnumIDListImpl
*impl_from_IEnumIDList(IEnumIDList
*iface
)
159 return CONTAINING_RECORD(iface
, IEnumIDListImpl
, IEnumIDList_iface
);
162 /**************************************************************************
163 * IEnumIDList::QueryInterface
165 static HRESULT WINAPI
IEnumIDList_fnQueryInterface(IEnumIDList
*iface
, REFIID riid
, void **ppvObj
)
167 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
169 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
173 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
176 else if(IsEqualIID(riid
, &IID_IEnumIDList
)) /*IEnumIDList*/
181 { IEnumIDList_AddRef((IEnumIDList
*)*ppvObj
);
182 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
186 TRACE("-- Interface: E_NOINTERFACE\n");
187 return E_NOINTERFACE
;
190 /******************************************************************************
191 * IEnumIDList::AddRef
193 static ULONG WINAPI
IEnumIDList_fnAddRef(IEnumIDList
*iface
)
195 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
196 ULONG refCount
= InterlockedIncrement(&This
->ref
);
198 TRACE("(%p)->(%u)\n", This
, refCount
- 1);
202 /******************************************************************************
203 * IEnumIDList::Release
205 static ULONG WINAPI
IEnumIDList_fnRelease(IEnumIDList
*iface
)
207 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
208 ULONG refCount
= InterlockedDecrement(&This
->ref
);
210 TRACE("(%p)->(%u)\n", This
, refCount
+ 1);
213 TRACE(" destroying IEnumIDList(%p)\n",This
);
215 HeapFree(GetProcessHeap(),0,This
);
220 /**************************************************************************
224 static HRESULT WINAPI
IEnumIDList_fnNext(IEnumIDList
*iface
, ULONG celt
, LPITEMIDLIST
*rgelt
,
227 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
233 TRACE("(%p)->(%d,%p, %p)\n",This
,celt
,rgelt
,pceltFetched
);
235 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
236 * subsystems actually use it (and so may a third party browser)
243 if(celt
> 1 && !pceltFetched
)
244 { return E_INVALIDARG
;
247 if(celt
> 0 && !This
->mpCurrent
)
251 for(i
= 0; i
< celt
; i
++)
252 { if(!(This
->mpCurrent
))
255 temp
= ILClone(This
->mpCurrent
->pidl
);
257 This
->mpCurrent
= This
->mpCurrent
->pNext
;
266 /**************************************************************************
269 static HRESULT WINAPI
IEnumIDList_fnSkip(IEnumIDList
*iface
, ULONG celt
)
271 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
276 TRACE("(%p)->(%u)\n",This
,celt
);
278 for(dwIndex
= 0; dwIndex
< celt
; dwIndex
++)
279 { if(!This
->mpCurrent
)
283 This
->mpCurrent
= This
->mpCurrent
->pNext
;
287 /**************************************************************************
290 static HRESULT WINAPI
IEnumIDList_fnReset(IEnumIDList
*iface
)
292 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
294 TRACE("(%p)\n",This
);
295 This
->mpCurrent
= This
->mpFirst
;
298 /**************************************************************************
301 static HRESULT WINAPI
IEnumIDList_fnClone(IEnumIDList
*iface
, IEnumIDList
**ppenum
)
303 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
305 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This
,ppenum
);
309 static const IEnumIDListVtbl eidlvt
=
311 IEnumIDList_fnQueryInterface
,
312 IEnumIDList_fnAddRef
,
313 IEnumIDList_fnRelease
,
320 IEnumIDListImpl
*IEnumIDList_Constructor(void)
322 IEnumIDListImpl
*lpeidl
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*lpeidl
));
327 lpeidl
->IEnumIDList_iface
.lpVtbl
= &eidlvt
;
330 TRACE("-- (%p)->()\n",lpeidl
);