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
24 #include "wine/debug.h"
28 #include "undocshell.h"
35 #include "enumidlist.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shell);
39 typedef struct tagENUMLIST
41 struct tagENUMLIST *pNext;
44 } ENUMLIST, *LPENUMLIST;
48 ICOM_VFIELD(IEnumIDList);
56 static struct ICOM_VTABLE(IEnumIDList) eidlvt;
58 /**************************************************************************
65 ICOM_THIS(IEnumIDListImpl,iface);
69 TRACE("(%p)->(pidl=%p)\n",This,pidl);
74 pNew = (LPENUMLIST)SHAlloc(sizeof(ENUMLIST));
77 /*set the next pointer */
81 /*is This the first item in the list? */
85 This->mpCurrent = pNew;
90 /*add the new item to the end of the list */
91 This->mpLast->pNext = pNew;
94 /*update the last item pointer */
96 TRACE("-- (%p)->(first=%p, last=%p)\n",This,This->mpFirst,This->mpLast);
102 /**************************************************************************
103 * CreateFolderEnumList()
105 static BOOL CreateFolderEnumList(
110 ICOM_THIS(IEnumIDListImpl,iface);
112 LPITEMIDLIST pidl=NULL;
113 WIN32_FIND_DATAA stffile;
115 CHAR szPath[MAX_PATH];
117 TRACE("(%p)->(path=%s flags=0x%08lx) \n",This,debugstr_a(lpszPath),dwFlags);
119 if(!lpszPath || !lpszPath[0]) return FALSE;
121 strcpy(szPath, lpszPath);
122 PathAddBackslashA(szPath);
123 strcat(szPath,"*.*");
125 /*enumerate the folders*/
126 if(dwFlags & SHCONTF_FOLDERS)
128 TRACE("-- (%p)-> enumerate SHCONTF_FOLDERS of %s\n",This,debugstr_a(szPath));
129 hFile = FindFirstFileA(szPath,&stffile);
130 if ( hFile != INVALID_HANDLE_VALUE )
134 if ( !(dwFlags & SHCONTF_INCLUDEHIDDEN) && (stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) continue;
135 if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, ".."))
137 pidl = _ILCreateFromFindDataA (&stffile);
138 if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
144 } while( FindNextFileA(hFile,&stffile));
149 /*enumerate the non-folder items (values) */
150 if(dwFlags & SHCONTF_NONFOLDERS)
152 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",This,debugstr_a(szPath));
153 hFile = FindFirstFileA(szPath,&stffile);
154 if ( hFile != INVALID_HANDLE_VALUE )
158 if ( !(dwFlags & SHCONTF_INCLUDEHIDDEN) && (stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) continue;
159 if (! (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
161 pidl = _ILCreateFromFindDataA(&stffile);
162 if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
168 } while( FindNextFileA(hFile,&stffile));
175 /**************************************************************************
176 * CreateDesktopEnumList()
178 static BOOL CreateDesktopEnumList(
182 ICOM_THIS(IEnumIDListImpl,iface);
184 LPITEMIDLIST pidl=NULL;
186 char szPath[MAX_PATH];
188 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
190 /*enumerate the root folders */
191 if(dwFlags & SHCONTF_FOLDERS)
193 /*create the pidl for This item */
194 pidl = _ILCreateMyComputer();
197 if(!AddToEnumList((IEnumIDList*)This, pidl))
201 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\desktop\\NameSpace", 0, KEY_READ, &hkey))
208 DWORD size = sizeof (iid);
210 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
213 pidl = _ILCreateGuidFromStrA(iid);
216 AddToEnumList((IEnumIDList*)This, pidl);
224 /*enumerate the elements in %windir%\desktop */
225 SHGetSpecialFolderPathA(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
226 CreateFolderEnumList( (IEnumIDList*)This, szPath, dwFlags);
231 /**************************************************************************
232 * CreateMyCompEnumList()
234 static BOOL CreateMyCompEnumList(
238 ICOM_THIS(IEnumIDListImpl,iface);
240 LPITEMIDLIST pidl=NULL;
245 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
247 /*enumerate the folders*/
248 if(dwFlags & SHCONTF_FOLDERS)
250 dwDrivemap = GetLogicalDrives();
251 strcpy (szDriveName,"A:\\");
252 while (szDriveName[0]<='Z')
254 if(dwDrivemap & 0x00000001L)
256 pidl = _ILCreateDrive(szDriveName);
259 if(!AddToEnumList((IEnumIDList*)This, pidl))
264 dwDrivemap = dwDrivemap >> 1;
267 TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",This);
268 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\mycomputer\\NameSpace", 0, KEY_READ, &hkey))
275 DWORD size = sizeof (iid);
277 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
280 pidl = _ILCreateGuidFromStrA(iid);
283 AddToEnumList((IEnumIDList*)This, pidl);
293 /**************************************************************************
296 static BOOL DeleteList(
299 ICOM_THIS(IEnumIDListImpl,iface);
303 TRACE("(%p)->()\n",This);
306 { pDelete = This->mpFirst;
307 This->mpFirst = pDelete->pNext;
308 SHFree(pDelete->pidl);
311 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
315 /**************************************************************************
316 * IEnumIDList_Folder_Constructor
320 IEnumIDList * IEnumIDList_Constructor(void)
322 IEnumIDListImpl *lpeidl = (IEnumIDListImpl*)HeapAlloc(GetProcessHeap(),
323 HEAP_ZERO_MEMORY, sizeof(IEnumIDListImpl));
328 lpeidl->lpVtbl = &eidlvt;
330 TRACE("-- (%p)->()\n",lpeidl);
332 return (IEnumIDList*)lpeidl;
335 IEnumIDList * IEnumIDList_BadConstructor(
340 IEnumIDListImpl* lpeidl;
343 TRACE("()->(%s flags=0x%08lx kind=0x%08lx)\n",debugstr_a(lpszPath),dwFlags, dwKind);
345 lpeidl = (IEnumIDListImpl *)IEnumIDList_Constructor();
352 ret = CreateDesktopEnumList((IEnumIDList*)lpeidl, dwFlags);
356 ret = CreateMyCompEnumList((IEnumIDList*)lpeidl, dwFlags);
360 ret = CreateFolderEnumList((IEnumIDList*)lpeidl, lpszPath, dwFlags);
365 HeapFree(GetProcessHeap(),0,lpeidl);
370 TRACE("-- (%p)->()\n",lpeidl);
372 return (IEnumIDList*)lpeidl;
375 /**************************************************************************
376 * EnumIDList_QueryInterface
378 static HRESULT WINAPI IEnumIDList_fnQueryInterface(
383 ICOM_THIS(IEnumIDListImpl,iface);
385 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
389 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
392 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
393 { *ppvObj = (IEnumIDList*)This;
397 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
398 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
402 TRACE("-- Interface: E_NOINTERFACE\n");
403 return E_NOINTERFACE;
406 /******************************************************************************
407 * IEnumIDList_fnAddRef
409 static ULONG WINAPI IEnumIDList_fnAddRef(
412 ICOM_THIS(IEnumIDListImpl,iface);
413 TRACE("(%p)->(%lu)\n",This,This->ref);
414 return ++(This->ref);
416 /******************************************************************************
417 * IEnumIDList_fnRelease
419 static ULONG WINAPI IEnumIDList_fnRelease(
422 ICOM_THIS(IEnumIDListImpl,iface);
424 TRACE("(%p)->(%lu)\n",This,This->ref);
426 if (!--(This->ref)) {
427 TRACE(" destroying IEnumIDList(%p)\n",This);
428 DeleteList((IEnumIDList*)This);
429 HeapFree(GetProcessHeap(),0,This);
435 /**************************************************************************
439 static HRESULT WINAPI IEnumIDList_fnNext(
442 LPITEMIDLIST * rgelt,
445 ICOM_THIS(IEnumIDListImpl,iface);
451 TRACE("(%p)->(%ld,%p, %p)\n",This,celt,rgelt,pceltFetched);
453 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
454 * subsystems actually use it (and so may a third party browser)
461 if(celt > 1 && !pceltFetched)
462 { return E_INVALIDARG;
465 if(celt > 0 && !This->mpCurrent)
469 for(i = 0; i < celt; i++)
470 { if(!(This->mpCurrent))
473 temp = ILClone(This->mpCurrent->pidl);
475 This->mpCurrent = This->mpCurrent->pNext;
484 /**************************************************************************
487 static HRESULT WINAPI IEnumIDList_fnSkip(
488 IEnumIDList * iface,ULONG celt)
490 ICOM_THIS(IEnumIDListImpl,iface);
495 TRACE("(%p)->(%lu)\n",This,celt);
497 for(dwIndex = 0; dwIndex < celt; dwIndex++)
498 { if(!This->mpCurrent)
502 This->mpCurrent = This->mpCurrent->pNext;
506 /**************************************************************************
507 * IEnumIDList_fnReset
509 static HRESULT WINAPI IEnumIDList_fnReset(
512 ICOM_THIS(IEnumIDListImpl,iface);
514 TRACE("(%p)\n",This);
515 This->mpCurrent = This->mpFirst;
518 /**************************************************************************
519 * IEnumIDList_fnClone
521 static HRESULT WINAPI IEnumIDList_fnClone(
522 IEnumIDList * iface,LPENUMIDLIST * ppenum)
524 ICOM_THIS(IEnumIDListImpl,iface);
526 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
530 /**************************************************************************
531 * IEnumIDList_fnVTable
533 static ICOM_VTABLE (IEnumIDList) eidlvt =
535 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
536 IEnumIDList_fnQueryInterface,
537 IEnumIDList_fnAddRef,
538 IEnumIDList_fnRelease,