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 /**************************************************************************
46 IEnumIDListImpl
*This
= (IEnumIDListImpl
*)iface
;
48 struct enumlist
*pNew
;
50 TRACE("(%p)->(pidl=%p)\n",This
,pidl
);
55 pNew
= SHAlloc(sizeof(*pNew
));
58 /*set the next pointer */
62 /*is This the first item in the list? */
66 This
->mpCurrent
= pNew
;
71 /*add the new item to the end of the list */
72 This
->mpLast
->pNext
= pNew
;
75 /*update the last item pointer */
77 TRACE("-- (%p)->(first=%p, last=%p)\n",This
,This
->mpFirst
,This
->mpLast
);
83 /**************************************************************************
84 * CreateFolderEnumList()
86 BOOL
CreateFolderEnumList(
91 LPITEMIDLIST pidl
=NULL
;
92 WIN32_FIND_DATAW stffile
;
94 WCHAR szPath
[MAX_PATH
];
95 BOOL succeeded
= TRUE
;
96 static const WCHAR stars
[] = { '*','.','*',0 };
97 static const WCHAR dot
[] = { '.',0 };
98 static const WCHAR dotdot
[] = { '.','.',0 };
100 TRACE("(%p)->(path=%s flags=0x%08x)\n", list
, debugstr_w(lpszPath
), dwFlags
);
102 if(!lpszPath
|| !lpszPath
[0]) return FALSE
;
104 strcpyW(szPath
, lpszPath
);
105 PathAddBackslashW(szPath
);
106 strcatW(szPath
,stars
);
108 hFile
= FindFirstFileW(szPath
,&stffile
);
109 if ( hFile
!= INVALID_HANDLE_VALUE
)
111 BOOL findFinished
= FALSE
;
115 if ( !(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
)
116 || (dwFlags
& SHCONTF_INCLUDEHIDDEN
) )
118 if ( (stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
119 dwFlags
& SHCONTF_FOLDERS
&&
120 strcmpW(stffile
.cFileName
, dot
) && strcmpW(stffile
.cFileName
, dotdot
))
122 pidl
= _ILCreateFromFindDataW(&stffile
);
123 succeeded
= succeeded
&& AddToEnumList(list
, pidl
);
125 else if (!(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
126 && dwFlags
& SHCONTF_NONFOLDERS
)
128 pidl
= _ILCreateFromFindDataW(&stffile
);
129 succeeded
= succeeded
&& AddToEnumList(list
, pidl
);
134 if (!FindNextFileW(hFile
, &stffile
))
136 if (GetLastError() == ERROR_NO_MORE_FILES
)
142 } while (succeeded
&& !findFinished
);
148 static BOOL
DeleteList(IEnumIDListImpl
*This
)
150 struct enumlist
*pDelete
;
152 TRACE("(%p)->()\n",This
);
155 { pDelete
= This
->mpFirst
;
156 This
->mpFirst
= pDelete
->pNext
;
157 SHFree(pDelete
->pidl
);
160 This
->mpFirst
= This
->mpLast
= This
->mpCurrent
= NULL
;
164 static inline IEnumIDListImpl
*impl_from_IEnumIDList(IEnumIDList
*iface
)
166 return CONTAINING_RECORD(iface
, IEnumIDListImpl
, IEnumIDList_iface
);
169 /**************************************************************************
170 * IEnumIDList::QueryInterface
172 static HRESULT WINAPI
IEnumIDList_fnQueryInterface(IEnumIDList
*iface
, REFIID riid
, void **ppvObj
)
174 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
176 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
180 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
183 else if(IsEqualIID(riid
, &IID_IEnumIDList
)) /*IEnumIDList*/
188 { IEnumIDList_AddRef((IEnumIDList
*)*ppvObj
);
189 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
193 TRACE("-- Interface: E_NOINTERFACE\n");
194 return E_NOINTERFACE
;
197 /******************************************************************************
198 * IEnumIDList::AddRef
200 static ULONG WINAPI
IEnumIDList_fnAddRef(IEnumIDList
*iface
)
202 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
203 ULONG refCount
= InterlockedIncrement(&This
->ref
);
205 TRACE("(%p)->(%u)\n", This
, refCount
- 1);
209 /******************************************************************************
210 * IEnumIDList::Release
212 static ULONG WINAPI
IEnumIDList_fnRelease(IEnumIDList
*iface
)
214 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
215 ULONG refCount
= InterlockedDecrement(&This
->ref
);
217 TRACE("(%p)->(%u)\n", This
, refCount
+ 1);
220 TRACE(" destroying IEnumIDList(%p)\n",This
);
222 HeapFree(GetProcessHeap(),0,This
);
227 /**************************************************************************
231 static HRESULT WINAPI
IEnumIDList_fnNext(IEnumIDList
*iface
, ULONG celt
, LPITEMIDLIST
*rgelt
,
234 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
240 TRACE("(%p)->(%d,%p, %p)\n",This
,celt
,rgelt
,pceltFetched
);
242 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
243 * subsystems actually use it (and so may a third party browser)
250 if(celt
> 1 && !pceltFetched
)
251 { return E_INVALIDARG
;
254 if(celt
> 0 && !This
->mpCurrent
)
258 for(i
= 0; i
< celt
; i
++)
259 { if(!(This
->mpCurrent
))
262 temp
= ILClone(This
->mpCurrent
->pidl
);
264 This
->mpCurrent
= This
->mpCurrent
->pNext
;
273 /**************************************************************************
276 static HRESULT WINAPI
IEnumIDList_fnSkip(IEnumIDList
*iface
, ULONG celt
)
278 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
283 TRACE("(%p)->(%u)\n",This
,celt
);
285 for(dwIndex
= 0; dwIndex
< celt
; dwIndex
++)
286 { if(!This
->mpCurrent
)
290 This
->mpCurrent
= This
->mpCurrent
->pNext
;
294 /**************************************************************************
297 static HRESULT WINAPI
IEnumIDList_fnReset(IEnumIDList
*iface
)
299 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
301 TRACE("(%p)\n",This
);
302 This
->mpCurrent
= This
->mpFirst
;
305 /**************************************************************************
308 static HRESULT WINAPI
IEnumIDList_fnClone(IEnumIDList
*iface
, IEnumIDList
**ppenum
)
310 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
312 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This
,ppenum
);
316 static const IEnumIDListVtbl eidlvt
=
318 IEnumIDList_fnQueryInterface
,
319 IEnumIDList_fnAddRef
,
320 IEnumIDList_fnRelease
,
327 IEnumIDListImpl
*IEnumIDList_Constructor(void)
329 IEnumIDListImpl
*lpeidl
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*lpeidl
));
334 lpeidl
->IEnumIDList_iface
.lpVtbl
= &eidlvt
;
337 TRACE("-- (%p)->()\n",lpeidl
);