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
23 #include "wine/debug.h"
25 #include "undocshell.h"
32 #include "shell32_main.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(shell);
36 typedef struct tagENUMLIST
38 struct tagENUMLIST *pNext;
41 } ENUMLIST, *LPENUMLIST;
45 ICOM_VFIELD(IEnumIDList);
53 static struct ICOM_VTABLE(IEnumIDList) eidlvt;
55 /**************************************************************************
58 static BOOL AddToEnumList(
62 ICOM_THIS(IEnumIDListImpl,iface);
66 TRACE("(%p)->(pidl=%p)\n",This,pidl);
67 pNew = (LPENUMLIST)SHAlloc(sizeof(ENUMLIST));
70 /*set the next pointer */
74 /*is This the first item in the list? */
78 This->mpCurrent = pNew;
83 /*add the new item to the end of the list */
84 This->mpLast->pNext = pNew;
87 /*update the last item pointer */
89 TRACE("-- (%p)->(first=%p, last=%p)\n",This,This->mpFirst,This->mpLast);
95 /**************************************************************************
96 * CreateFolderEnumList()
98 static BOOL CreateFolderEnumList(
103 ICOM_THIS(IEnumIDListImpl,iface);
105 LPITEMIDLIST pidl=NULL;
106 WIN32_FIND_DATAA stffile;
108 CHAR szPath[MAX_PATH];
110 TRACE("(%p)->(path=%s flags=0x%08lx) \n",This,debugstr_a(lpszPath),dwFlags);
112 if(!lpszPath || !lpszPath[0]) return FALSE;
114 strcpy(szPath, lpszPath);
115 PathAddBackslashA(szPath);
116 strcat(szPath,"*.*");
118 /*enumerate the folders*/
119 if(dwFlags & SHCONTF_FOLDERS)
121 TRACE("-- (%p)-> enumerate SHCONTF_FOLDERS of %s\n",This,debugstr_a(szPath));
122 hFile = FindFirstFileA(szPath,&stffile);
123 if ( hFile != INVALID_HANDLE_VALUE )
127 if ( !(dwFlags & SHCONTF_INCLUDEHIDDEN) && (stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) continue;
128 if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, ".."))
130 pidl = _ILCreateFolder (&stffile);
131 if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
137 } while( FindNextFileA(hFile,&stffile));
142 /*enumerate the non-folder items (values) */
143 if(dwFlags & SHCONTF_NONFOLDERS)
145 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",This,debugstr_a(szPath));
146 hFile = FindFirstFileA(szPath,&stffile);
147 if ( hFile != INVALID_HANDLE_VALUE )
151 if ( !(dwFlags & SHCONTF_INCLUDEHIDDEN) && (stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) continue;
152 if (! (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
154 pidl = _ILCreateValue(&stffile);
155 if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
161 } while( FindNextFileA(hFile,&stffile));
168 /**************************************************************************
169 * CreateDesktopEnumList()
171 static BOOL CreateDesktopEnumList(
175 ICOM_THIS(IEnumIDListImpl,iface);
177 LPITEMIDLIST pidl=NULL;
179 char szPath[MAX_PATH];
181 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
183 /*enumerate the root folders */
184 if(dwFlags & SHCONTF_FOLDERS)
186 /*create the pidl for This item */
187 pidl = _ILCreateMyComputer();
190 if(!AddToEnumList((IEnumIDList*)This, pidl))
194 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\desktop\\NameSpace", 0, KEY_READ, &hkey))
201 DWORD size = sizeof (iid);
203 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
206 pidl = _ILCreateSpecial(iid);
209 AddToEnumList((IEnumIDList*)This, pidl);
217 /*enumerate the elements in %windir%\desktop */
218 SHGetSpecialFolderPathA(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
219 CreateFolderEnumList( (IEnumIDList*)This, szPath, dwFlags);
224 /**************************************************************************
225 * CreateMyCompEnumList()
227 static BOOL CreateMyCompEnumList(
231 ICOM_THIS(IEnumIDListImpl,iface);
233 LPITEMIDLIST pidl=NULL;
238 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
240 /*enumerate the folders*/
241 if(dwFlags & SHCONTF_FOLDERS)
243 dwDrivemap = GetLogicalDrives();
244 strcpy (szDriveName,"A:\\");
245 while (szDriveName[0]<='Z')
247 if(dwDrivemap & 0x00000001L)
249 pidl = _ILCreateDrive(szDriveName);
252 if(!AddToEnumList((IEnumIDList*)This, pidl))
257 dwDrivemap = dwDrivemap >> 1;
260 TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",This);
261 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\mycomputer\\NameSpace", 0, KEY_READ, &hkey))
268 DWORD size = sizeof (iid);
270 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
273 pidl = _ILCreateSpecial(iid);
276 AddToEnumList((IEnumIDList*)This, pidl);
286 /**************************************************************************
289 static BOOL DeleteList(
292 ICOM_THIS(IEnumIDListImpl,iface);
296 TRACE("(%p)->()\n",This);
299 { pDelete = This->mpFirst;
300 This->mpFirst = pDelete->pNext;
301 SHFree(pDelete->pidl);
304 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
308 /**************************************************************************
309 * IEnumIDList_Folder_Constructor
313 IEnumIDList * IEnumIDList_Constructor(
318 IEnumIDListImpl* lpeidl;
321 TRACE("()->(%s flags=0x%08lx kind=0x%08lx)\n",debugstr_a(lpszPath),dwFlags, dwKind);
323 lpeidl = (IEnumIDListImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumIDListImpl));
328 lpeidl->lpVtbl = &eidlvt;
333 ret = CreateDesktopEnumList((IEnumIDList*)lpeidl, dwFlags);
337 ret = CreateMyCompEnumList((IEnumIDList*)lpeidl, dwFlags);
341 ret = CreateFolderEnumList((IEnumIDList*)lpeidl, lpszPath, dwFlags);
346 HeapFree(GetProcessHeap(),0,lpeidl);
351 TRACE("-- (%p)->()\n",lpeidl);
353 return (IEnumIDList*)lpeidl;
356 /**************************************************************************
357 * EnumIDList_QueryInterface
359 static HRESULT WINAPI IEnumIDList_fnQueryInterface(
364 ICOM_THIS(IEnumIDListImpl,iface);
366 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
370 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
373 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
374 { *ppvObj = (IEnumIDList*)This;
378 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
379 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
383 TRACE("-- Interface: E_NOINTERFACE\n");
384 return E_NOINTERFACE;
387 /******************************************************************************
388 * IEnumIDList_fnAddRef
390 static ULONG WINAPI IEnumIDList_fnAddRef(
393 ICOM_THIS(IEnumIDListImpl,iface);
394 TRACE("(%p)->(%lu)\n",This,This->ref);
395 return ++(This->ref);
397 /******************************************************************************
398 * IEnumIDList_fnRelease
400 static ULONG WINAPI IEnumIDList_fnRelease(
403 ICOM_THIS(IEnumIDListImpl,iface);
405 TRACE("(%p)->(%lu)\n",This,This->ref);
407 if (!--(This->ref)) {
408 TRACE(" destroying IEnumIDList(%p)\n",This);
409 DeleteList((IEnumIDList*)This);
410 HeapFree(GetProcessHeap(),0,This);
416 /**************************************************************************
420 static HRESULT WINAPI IEnumIDList_fnNext(
423 LPITEMIDLIST * rgelt,
426 ICOM_THIS(IEnumIDListImpl,iface);
432 TRACE("(%p)->(%ld,%p, %p)\n",This,celt,rgelt,pceltFetched);
434 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
435 * subsystems actually use it (and so may a third party browser)
442 if(celt > 1 && !pceltFetched)
443 { return E_INVALIDARG;
446 if(celt > 0 && !This->mpCurrent)
450 for(i = 0; i < celt; i++)
451 { if(!(This->mpCurrent))
454 temp = ILClone(This->mpCurrent->pidl);
456 This->mpCurrent = This->mpCurrent->pNext;
465 /**************************************************************************
468 static HRESULT WINAPI IEnumIDList_fnSkip(
469 IEnumIDList * iface,ULONG celt)
471 ICOM_THIS(IEnumIDListImpl,iface);
476 TRACE("(%p)->(%lu)\n",This,celt);
478 for(dwIndex = 0; dwIndex < celt; dwIndex++)
479 { if(!This->mpCurrent)
483 This->mpCurrent = This->mpCurrent->pNext;
487 /**************************************************************************
488 * IEnumIDList_fnReset
490 static HRESULT WINAPI IEnumIDList_fnReset(
493 ICOM_THIS(IEnumIDListImpl,iface);
495 TRACE("(%p)\n",This);
496 This->mpCurrent = This->mpFirst;
499 /**************************************************************************
500 * IEnumIDList_fnClone
502 static HRESULT WINAPI IEnumIDList_fnClone(
503 IEnumIDList * iface,LPENUMIDLIST * ppenum)
505 ICOM_THIS(IEnumIDListImpl,iface);
507 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
511 /**************************************************************************
512 * IEnumIDList_fnVTable
514 static ICOM_VTABLE (IEnumIDList) eidlvt =
516 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
517 IEnumIDList_fnQueryInterface,
518 IEnumIDList_fnAddRef,
519 IEnumIDList_fnRelease,