Implemented InternetGetConnectedStateExA.
[wine/wine64.git] / dlls / shell32 / enumidlist.c
blob4c9fcc4c131003b491247aa2853d4eefd3f84172
1 /*
2 * IEnumIDList
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
21 #include <stdarg.h>
22 #include <stdlib.h>
23 #include <string.h>
25 #define COBJMACROS
27 #include "wine/debug.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "undocshell.h"
32 #include "shlwapi.h"
33 #include "winerror.h"
34 #include "objbase.h"
36 #include "pidl.h"
37 #include "shlguid.h"
38 #include "enumidlist.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shell);
42 typedef struct tagENUMLIST
44 struct tagENUMLIST *pNext;
45 LPITEMIDLIST pidl;
47 } ENUMLIST, *LPENUMLIST;
49 typedef struct
51 IEnumIDListVtbl *lpVtbl;
52 DWORD ref;
53 LPENUMLIST mpFirst;
54 LPENUMLIST mpLast;
55 LPENUMLIST mpCurrent;
57 } IEnumIDListImpl;
59 static struct IEnumIDListVtbl eidlvt;
61 /**************************************************************************
62 * AddToEnumList()
64 BOOL AddToEnumList(
65 IEnumIDList * iface,
66 LPITEMIDLIST pidl)
68 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
70 LPENUMLIST pNew;
72 TRACE("(%p)->(pidl=%p)\n",This,pidl);
74 if (!iface || !pidl)
75 return FALSE;
77 pNew = (LPENUMLIST)SHAlloc(sizeof(ENUMLIST));
78 if(pNew)
80 /*set the next pointer */
81 pNew->pNext = NULL;
82 pNew->pidl = pidl;
84 /*is This the first item in the list? */
85 if(!This->mpFirst)
87 This->mpFirst = pNew;
88 This->mpCurrent = pNew;
91 if(This->mpLast)
93 /*add the new item to the end of the list */
94 This->mpLast->pNext = pNew;
97 /*update the last item pointer */
98 This->mpLast = pNew;
99 TRACE("-- (%p)->(first=%p, last=%p)\n",This,This->mpFirst,This->mpLast);
100 return TRUE;
102 return FALSE;
105 /**************************************************************************
106 * CreateFolderEnumList()
108 BOOL CreateFolderEnumList(
109 IEnumIDList *list,
110 LPCSTR lpszPath,
111 DWORD dwFlags)
113 LPITEMIDLIST pidl=NULL;
114 WIN32_FIND_DATAA stffile;
115 HANDLE hFile;
116 CHAR szPath[MAX_PATH];
117 BOOL succeeded = TRUE;
119 TRACE("(%p)->(path=%s flags=0x%08lx) \n",list,debugstr_a(lpszPath),dwFlags);
121 if(!lpszPath || !lpszPath[0]) return FALSE;
123 strcpy(szPath, lpszPath);
124 PathAddBackslashA(szPath);
125 strcat(szPath,"*.*");
127 hFile = FindFirstFileA(szPath,&stffile);
128 if ( hFile != INVALID_HANDLE_VALUE )
130 BOOL findFinished = FALSE;
134 if ( !(stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
135 || (dwFlags & SHCONTF_INCLUDEHIDDEN) )
137 if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
138 dwFlags & SHCONTF_FOLDERS &&
139 strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, ".."))
141 pidl = _ILCreateFromFindDataA(&stffile);
142 succeeded = succeeded && AddToEnumList(list, pidl);
144 else if (!(stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
145 && dwFlags & SHCONTF_NONFOLDERS)
147 pidl = _ILCreateFromFindDataA(&stffile);
148 succeeded = succeeded && AddToEnumList(list, pidl);
151 if (succeeded)
153 if (!FindNextFileA(hFile, &stffile))
155 if (GetLastError() == ERROR_NO_MORE_FILES)
156 findFinished = TRUE;
157 else
158 succeeded = FALSE;
161 } while (succeeded && !findFinished);
162 FindClose(hFile);
164 return succeeded;
167 /**************************************************************************
168 * DeleteList()
170 static BOOL DeleteList(
171 IEnumIDList * iface)
173 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
175 LPENUMLIST pDelete;
177 TRACE("(%p)->()\n",This);
179 while(This->mpFirst)
180 { pDelete = This->mpFirst;
181 This->mpFirst = pDelete->pNext;
182 SHFree(pDelete->pidl);
183 SHFree(pDelete);
185 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
186 return TRUE;
189 /**************************************************************************
190 * IEnumIDList_Folder_Constructor
194 IEnumIDList * IEnumIDList_Constructor(void)
196 IEnumIDListImpl *lpeidl = (IEnumIDListImpl*)HeapAlloc(GetProcessHeap(),
197 HEAP_ZERO_MEMORY, sizeof(IEnumIDListImpl));
199 if (lpeidl)
201 lpeidl->ref = 1;
202 lpeidl->lpVtbl = &eidlvt;
204 TRACE("-- (%p)->()\n",lpeidl);
206 return (IEnumIDList*)lpeidl;
209 /**************************************************************************
210 * EnumIDList_QueryInterface
212 static HRESULT WINAPI IEnumIDList_fnQueryInterface(
213 IEnumIDList * iface,
214 REFIID riid,
215 LPVOID *ppvObj)
217 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
219 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
221 *ppvObj = NULL;
223 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
224 { *ppvObj = This;
226 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
227 { *ppvObj = (IEnumIDList*)This;
230 if(*ppvObj)
231 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
232 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
233 return S_OK;
236 TRACE("-- Interface: E_NOINTERFACE\n");
237 return E_NOINTERFACE;
240 /******************************************************************************
241 * IEnumIDList_fnAddRef
243 static ULONG WINAPI IEnumIDList_fnAddRef(
244 IEnumIDList * iface)
246 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
247 TRACE("(%p)->(%lu)\n",This,This->ref);
248 return ++(This->ref);
250 /******************************************************************************
251 * IEnumIDList_fnRelease
253 static ULONG WINAPI IEnumIDList_fnRelease(
254 IEnumIDList * iface)
256 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
258 TRACE("(%p)->(%lu)\n",This,This->ref);
260 if (!--(This->ref)) {
261 TRACE(" destroying IEnumIDList(%p)\n",This);
262 DeleteList((IEnumIDList*)This);
263 HeapFree(GetProcessHeap(),0,This);
264 return 0;
266 return This->ref;
269 /**************************************************************************
270 * IEnumIDList_fnNext
273 static HRESULT WINAPI IEnumIDList_fnNext(
274 IEnumIDList * iface,
275 ULONG celt,
276 LPITEMIDLIST * rgelt,
277 ULONG *pceltFetched)
279 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
281 ULONG i;
282 HRESULT hr = S_OK;
283 LPITEMIDLIST temp;
285 TRACE("(%p)->(%ld,%p, %p)\n",This,celt,rgelt,pceltFetched);
287 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
288 * subsystems actually use it (and so may a third party browser)
290 if(pceltFetched)
291 *pceltFetched = 0;
293 *rgelt=0;
295 if(celt > 1 && !pceltFetched)
296 { return E_INVALIDARG;
299 if(celt > 0 && !This->mpCurrent)
300 { return S_FALSE;
303 for(i = 0; i < celt; i++)
304 { if(!(This->mpCurrent))
305 break;
307 temp = ILClone(This->mpCurrent->pidl);
308 rgelt[i] = temp;
309 This->mpCurrent = This->mpCurrent->pNext;
311 if(pceltFetched)
312 { *pceltFetched = i;
315 return hr;
318 /**************************************************************************
319 * IEnumIDList_fnSkip
321 static HRESULT WINAPI IEnumIDList_fnSkip(
322 IEnumIDList * iface,ULONG celt)
324 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
326 DWORD dwIndex;
327 HRESULT hr = S_OK;
329 TRACE("(%p)->(%lu)\n",This,celt);
331 for(dwIndex = 0; dwIndex < celt; dwIndex++)
332 { if(!This->mpCurrent)
333 { hr = S_FALSE;
334 break;
336 This->mpCurrent = This->mpCurrent->pNext;
338 return hr;
340 /**************************************************************************
341 * IEnumIDList_fnReset
343 static HRESULT WINAPI IEnumIDList_fnReset(
344 IEnumIDList * iface)
346 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
348 TRACE("(%p)\n",This);
349 This->mpCurrent = This->mpFirst;
350 return S_OK;
352 /**************************************************************************
353 * IEnumIDList_fnClone
355 static HRESULT WINAPI IEnumIDList_fnClone(
356 IEnumIDList * iface,LPENUMIDLIST * ppenum)
358 IEnumIDListImpl *This = (IEnumIDListImpl *)iface;
360 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
361 return E_NOTIMPL;
364 /**************************************************************************
365 * IEnumIDList_fnVTable
367 static IEnumIDListVtbl eidlvt =
369 IEnumIDList_fnQueryInterface,
370 IEnumIDList_fnAddRef,
371 IEnumIDList_fnRelease,
372 IEnumIDList_fnNext,
373 IEnumIDList_fnSkip,
374 IEnumIDList_fnReset,
375 IEnumIDList_fnClone,