4 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
9 #include "debugtools.h"
11 #include "wine/undocshell.h"
14 #include "wine/obj_base.h"
15 #include "wine/obj_enumidlist.h"
19 #include "shell32_main.h"
21 DEFAULT_DEBUG_CHANNEL(shell);
23 typedef struct tagENUMLIST
25 struct tagENUMLIST *pNext;
28 } ENUMLIST, *LPENUMLIST;
32 ICOM_VFIELD(IEnumIDList);
40 static struct ICOM_VTABLE(IEnumIDList) eidlvt;
42 /**************************************************************************
45 static BOOL AddToEnumList(
49 ICOM_THIS(IEnumIDListImpl,iface);
53 TRACE("(%p)->(pidl=%p)\n",This,pidl);
54 pNew = (LPENUMLIST)SHAlloc(sizeof(ENUMLIST));
57 /*set the next pointer */
61 /*is This the first item in the list? */
65 This->mpCurrent = pNew;
70 /*add the new item to the end of the list */
71 This->mpLast->pNext = pNew;
74 /*update the last item pointer */
76 TRACE("-- (%p)->(first=%p, last=%p)\n",This,This->mpFirst,This->mpLast);
82 /**************************************************************************
83 * CreateFolderEnumList()
85 static BOOL CreateFolderEnumList(
90 ICOM_THIS(IEnumIDListImpl,iface);
92 LPITEMIDLIST pidl=NULL;
93 WIN32_FIND_DATAA stffile;
95 CHAR szPath[MAX_PATH];
97 TRACE("(%p)->(path=%s flags=0x%08lx) \n",This,debugstr_a(lpszPath),dwFlags);
99 if(!lpszPath || !lpszPath[0]) return FALSE;
101 strcpy(szPath, lpszPath);
102 PathAddBackslashA(szPath);
103 strcat(szPath,"*.*");
105 /*enumerate the folders*/
106 if(dwFlags & SHCONTF_FOLDERS)
108 TRACE("-- (%p)-> enumerate SHCONTF_FOLDERS of %s\n",This,debugstr_a(szPath));
109 hFile = FindFirstFileA(szPath,&stffile);
110 if ( hFile != INVALID_HANDLE_VALUE )
114 if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, ".."))
116 pidl = _ILCreateFolder (&stffile);
117 if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
123 } while( FindNextFileA(hFile,&stffile));
128 /*enumerate the non-folder items (values) */
129 if(dwFlags & SHCONTF_NONFOLDERS)
131 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",This,debugstr_a(szPath));
132 hFile = FindFirstFileA(szPath,&stffile);
133 if ( hFile != INVALID_HANDLE_VALUE )
137 if (! (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
139 pidl = _ILCreateValue(&stffile);
140 if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
146 } while( FindNextFileA(hFile,&stffile));
153 /**************************************************************************
154 * CreateDesktopEnumList()
156 static BOOL CreateDesktopEnumList(
160 ICOM_THIS(IEnumIDListImpl,iface);
162 LPITEMIDLIST pidl=NULL;
164 char szPath[MAX_PATH];
166 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
168 /*enumerate the root folders */
169 if(dwFlags & SHCONTF_FOLDERS)
171 /*create the pidl for This item */
172 pidl = _ILCreateMyComputer();
175 if(!AddToEnumList((IEnumIDList*)This, pidl))
179 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\desktop\\NameSpace", 0, KEY_READ, &hkey))
186 DWORD size = sizeof (iid);
188 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
191 pidl = _ILCreateSpecial(iid);
194 AddToEnumList((IEnumIDList*)This, pidl);
202 /*enumerate the elements in %windir%\desktop */
203 SHGetSpecialFolderPathA(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
204 CreateFolderEnumList( (IEnumIDList*)This, szPath, dwFlags);
209 /**************************************************************************
210 * CreateMyCompEnumList()
212 static BOOL CreateMyCompEnumList(
216 ICOM_THIS(IEnumIDListImpl,iface);
218 LPITEMIDLIST pidl=NULL;
223 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
225 /*enumerate the folders*/
226 if(dwFlags & SHCONTF_FOLDERS)
228 dwDrivemap = GetLogicalDrives();
229 strcpy (szDriveName,"A:\\");
230 while (szDriveName[0]<='Z')
232 if(dwDrivemap & 0x00000001L)
234 pidl = _ILCreateDrive(szDriveName);
237 if(!AddToEnumList((IEnumIDList*)This, pidl))
242 dwDrivemap = dwDrivemap >> 1;
245 TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",This);
246 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\mycomputer\\NameSpace", 0, KEY_READ, &hkey))
253 DWORD size = sizeof (iid);
255 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
258 pidl = _ILCreateSpecial(iid);
261 AddToEnumList((IEnumIDList*)This, pidl);
271 /**************************************************************************
274 static BOOL DeleteList(
277 ICOM_THIS(IEnumIDListImpl,iface);
281 TRACE("(%p)->()\n",This);
284 { pDelete = This->mpFirst;
285 This->mpFirst = pDelete->pNext;
286 SHFree(pDelete->pidl);
289 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
293 /**************************************************************************
294 * IEnumIDList_Folder_Constructor
298 IEnumIDList * IEnumIDList_Constructor(
303 IEnumIDListImpl* lpeidl;
306 lpeidl = (IEnumIDListImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumIDListImpl));
308 TRACE("(%p)->(%s flags=0x%08lx kind=0x%08lx)\n",lpeidl,debugstr_a(lpszPath),dwFlags, dwKind);
313 ICOM_VTBL(lpeidl) = &eidlvt;
318 ret = CreateDesktopEnumList((IEnumIDList*)lpeidl, dwFlags);
322 ret = CreateMyCompEnumList((IEnumIDList*)lpeidl, dwFlags);
326 ret = CreateFolderEnumList((IEnumIDList*)lpeidl, lpszPath, dwFlags);
338 HeapFree(GetProcessHeap(),0,lpeidl);
343 TRACE("-- (%p)->()\n",lpeidl);
345 return (IEnumIDList*)lpeidl;
348 /**************************************************************************
349 * EnumIDList_QueryInterface
351 static HRESULT WINAPI IEnumIDList_fnQueryInterface(
356 ICOM_THIS(IEnumIDListImpl,iface);
358 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
362 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
365 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
366 { *ppvObj = (IEnumIDList*)This;
370 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
371 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
375 TRACE("-- Interface: E_NOINTERFACE\n");
376 return E_NOINTERFACE;
379 /******************************************************************************
380 * IEnumIDList_fnAddRef
382 static ULONG WINAPI IEnumIDList_fnAddRef(
385 ICOM_THIS(IEnumIDListImpl,iface);
387 TRACE("(%p)->(%lu)\n",This,This->ref);
390 return ++(This->ref);
392 /******************************************************************************
393 * IEnumIDList_fnRelease
395 static ULONG WINAPI IEnumIDList_fnRelease(
398 ICOM_THIS(IEnumIDListImpl,iface);
400 TRACE("(%p)->(%lu)\n",This,This->ref);
405 { TRACE(" destroying IEnumIDList(%p)\n",This);
406 DeleteList((IEnumIDList*)This);
407 HeapFree(GetProcessHeap(),0,This);
413 /**************************************************************************
417 static HRESULT WINAPI IEnumIDList_fnNext(
420 LPITEMIDLIST * rgelt,
423 ICOM_THIS(IEnumIDListImpl,iface);
429 TRACE("(%p)->(%ld,%p, %p)\n",This,celt,rgelt,pceltFetched);
431 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
432 * subsystems actually use it (and so may a third party browser)
439 if(celt > 1 && !pceltFetched)
440 { return E_INVALIDARG;
443 for(i = 0; i < celt; i++)
444 { if(!(This->mpCurrent))
448 temp = ILClone(This->mpCurrent->pidl);
450 This->mpCurrent = This->mpCurrent->pNext;
459 /**************************************************************************
462 static HRESULT WINAPI IEnumIDList_fnSkip(
463 IEnumIDList * iface,ULONG celt)
465 ICOM_THIS(IEnumIDListImpl,iface);
470 TRACE("(%p)->(%lu)\n",This,celt);
472 for(dwIndex = 0; dwIndex < celt; dwIndex++)
473 { if(!This->mpCurrent)
477 This->mpCurrent = This->mpCurrent->pNext;
481 /**************************************************************************
482 * IEnumIDList_fnReset
484 static HRESULT WINAPI IEnumIDList_fnReset(
487 ICOM_THIS(IEnumIDListImpl,iface);
489 TRACE("(%p)\n",This);
490 This->mpCurrent = This->mpFirst;
493 /**************************************************************************
494 * IEnumIDList_fnClone
496 static HRESULT WINAPI IEnumIDList_fnClone(
497 IEnumIDList * iface,LPENUMIDLIST * ppenum)
499 ICOM_THIS(IEnumIDListImpl,iface);
501 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
505 /**************************************************************************
506 * IEnumIDList_fnVTable
508 static ICOM_VTABLE (IEnumIDList) eidlvt =
510 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
511 IEnumIDList_fnQueryInterface,
512 IEnumIDList_fnAddRef,
513 IEnumIDList_fnRelease,