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
*list
, LPITEMIDLIST pidl
)
44 struct pidl_enum_entry
*pidl_entry
;
46 TRACE("(%p)->(pidl=%p)\n", list
, pidl
);
51 if (!(pidl_entry
= SHAlloc(sizeof(*pidl_entry
))))
54 pidl_entry
->pidl
= pidl
;
55 list_add_tail(&list
->pidls
, &pidl_entry
->entry
);
57 list
->current
= list_head(&list
->pidls
);
62 /**************************************************************************
63 * CreateFolderEnumList()
65 BOOL
CreateFolderEnumList(IEnumIDListImpl
*list
, LPCWSTR lpszPath
, DWORD dwFlags
)
67 LPITEMIDLIST pidl
=NULL
;
68 WIN32_FIND_DATAW stffile
;
70 WCHAR szPath
[MAX_PATH
];
71 BOOL succeeded
= TRUE
;
72 static const WCHAR stars
[] = { '*','.','*',0 };
73 static const WCHAR dot
[] = { '.',0 };
74 static const WCHAR dotdot
[] = { '.','.',0 };
76 TRACE("(%p)->(path=%s flags=0x%08x)\n", list
, debugstr_w(lpszPath
), dwFlags
);
78 if(!lpszPath
|| !lpszPath
[0]) return FALSE
;
80 strcpyW(szPath
, lpszPath
);
81 PathAddBackslashW(szPath
);
82 strcatW(szPath
,stars
);
84 hFile
= FindFirstFileW(szPath
,&stffile
);
85 if ( hFile
!= INVALID_HANDLE_VALUE
)
87 BOOL findFinished
= FALSE
;
91 if ( !(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
)
92 || (dwFlags
& SHCONTF_INCLUDEHIDDEN
) )
94 if ( (stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) &&
95 dwFlags
& SHCONTF_FOLDERS
&&
96 strcmpW(stffile
.cFileName
, dot
) && strcmpW(stffile
.cFileName
, dotdot
))
98 pidl
= _ILCreateFromFindDataW(&stffile
);
99 succeeded
= succeeded
&& AddToEnumList(list
, pidl
);
101 else if (!(stffile
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
102 && dwFlags
& SHCONTF_NONFOLDERS
)
104 pidl
= _ILCreateFromFindDataW(&stffile
);
105 succeeded
= succeeded
&& AddToEnumList(list
, pidl
);
110 if (!FindNextFileW(hFile
, &stffile
))
112 if (GetLastError() == ERROR_NO_MORE_FILES
)
118 } while (succeeded
&& !findFinished
);
124 static inline IEnumIDListImpl
*impl_from_IEnumIDList(IEnumIDList
*iface
)
126 return CONTAINING_RECORD(iface
, IEnumIDListImpl
, IEnumIDList_iface
);
129 /**************************************************************************
130 * IEnumIDList::QueryInterface
132 static HRESULT WINAPI
IEnumIDList_fnQueryInterface(IEnumIDList
*iface
, REFIID riid
, void **ppvObj
)
134 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
136 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppvObj
);
140 if (IsEqualIID(riid
, &IID_IUnknown
) ||
141 IsEqualIID(riid
, &IID_IEnumIDList
))
143 *ppvObj
= &This
->IEnumIDList_iface
;
148 IUnknown_AddRef((IUnknown
*)*ppvObj
);
152 WARN("interface %s is not supported\n", debugstr_guid(riid
));
153 return E_NOINTERFACE
;
156 /******************************************************************************
157 * IEnumIDList::AddRef
159 static ULONG WINAPI
IEnumIDList_fnAddRef(IEnumIDList
*iface
)
161 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
162 ULONG refCount
= InterlockedIncrement(&This
->ref
);
164 TRACE("(%p)->(%u)\n", This
, refCount
- 1);
169 /******************************************************************************
170 * IEnumIDList::Release
172 static ULONG WINAPI
IEnumIDList_fnRelease(IEnumIDList
*iface
)
174 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
175 ULONG refCount
= InterlockedDecrement(&This
->ref
);
177 TRACE("(%p)->(%u)\n", This
, refCount
+ 1);
181 struct pidl_enum_entry
*cur
, *cur2
;
183 LIST_FOR_EACH_ENTRY_SAFE(cur
, cur2
, &This
->pidls
, struct pidl_enum_entry
, entry
)
185 list_remove(&cur
->entry
);
195 /**************************************************************************
199 static HRESULT WINAPI
IEnumIDList_fnNext(IEnumIDList
*iface
, ULONG celt
, LPITEMIDLIST
*rgelt
,
202 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
206 TRACE("(%p)->(%d, %p, %p)\n", This
, celt
, rgelt
, fetched
);
208 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
209 * subsystems actually use it (and so may a third party browser)
216 if (celt
> 1 && !fetched
)
219 if (celt
> 0 && !This
->current
)
222 for (i
= 0; i
< celt
; i
++)
227 rgelt
[i
] = ILClone(LIST_ENTRY(This
->current
, struct pidl_enum_entry
, entry
)->pidl
);
228 This
->current
= list_next(&This
->pidls
, This
->current
);
237 /**************************************************************************
240 static HRESULT WINAPI
IEnumIDList_fnSkip(IEnumIDList
*iface
, ULONG celt
)
242 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
246 TRACE("(%p)->(%u)\n", This
, celt
);
248 for (i
= 0; i
< celt
; i
++)
255 This
->current
= list_next(&This
->pidls
, This
->current
);
261 /**************************************************************************
264 static HRESULT WINAPI
IEnumIDList_fnReset(IEnumIDList
*iface
)
266 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
268 TRACE("(%p)\n",This
);
269 This
->current
= list_head(&This
->pidls
);
273 /**************************************************************************
276 static HRESULT WINAPI
IEnumIDList_fnClone(IEnumIDList
*iface
, IEnumIDList
**ppenum
)
278 IEnumIDListImpl
*This
= impl_from_IEnumIDList(iface
);
280 FIXME("(%p)->(%p): stub\n",This
, ppenum
);
285 static const IEnumIDListVtbl eidlvt
=
287 IEnumIDList_fnQueryInterface
,
288 IEnumIDList_fnAddRef
,
289 IEnumIDList_fnRelease
,
296 IEnumIDListImpl
*IEnumIDList_Constructor(void)
298 IEnumIDListImpl
*lpeidl
= heap_alloc(sizeof(*lpeidl
));
302 lpeidl
->IEnumIDList_iface
.lpVtbl
= &eidlvt
;
304 list_init(&lpeidl
->pidls
);
305 lpeidl
->current
= NULL
;
308 TRACE("-- (%p)->()\n",lpeidl
);