4 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
9 #include "debugtools.h"
11 #include "wine/obj_base.h"
12 #include "wine/obj_enumidlist.h"
13 #include "wine/undocshell.h"
18 #include "shell32_main.h"
20 DEFAULT_DEBUG_CHANNEL(shell)
22 typedef struct tagENUMLIST
24 struct tagENUMLIST *pNext;
27 } ENUMLIST, *LPENUMLIST;
31 ICOM_VTABLE(IEnumIDList)* lpvtbl;
39 static struct ICOM_VTABLE(IEnumIDList) eidlvt;
41 /**************************************************************************
44 static BOOL AddToEnumList(
48 ICOM_THIS(IEnumIDListImpl,iface);
52 TRACE("(%p)->(pidl=%p)\n",This,pidl);
53 pNew = (LPENUMLIST)SHAlloc(sizeof(ENUMLIST));
56 /*set the next pointer */
60 /*is This the first item in the list? */
64 This->mpCurrent = pNew;
69 /*add the new item to the end of the list */
70 This->mpLast->pNext = pNew;
73 /*update the last item pointer */
75 TRACE("-- (%p)->(first=%p, last=%p)\n",This,This->mpFirst,This->mpLast);
81 /**************************************************************************
82 * CreateFolderEnumList()
84 static BOOL CreateFolderEnumList(
89 ICOM_THIS(IEnumIDListImpl,iface);
91 LPITEMIDLIST pidl=NULL;
92 WIN32_FIND_DATAA stffile;
94 CHAR szPath[MAX_PATH];
96 TRACE("(%p)->(path=%s flags=0x%08lx) \n",This,debugstr_a(lpszPath),dwFlags);
98 if(!lpszPath || !lpszPath[0]) return FALSE;
100 strcpy(szPath, lpszPath);
101 PathAddBackslashA(szPath);
102 strcat(szPath,"*.*");
104 /*enumerate the folders*/
105 if(dwFlags & SHCONTF_FOLDERS)
107 TRACE("-- (%p)-> enumerate SHCONTF_FOLDERS of %s\n",This,debugstr_a(szPath));
108 hFile = FindFirstFileA(szPath,&stffile);
109 if ( hFile != INVALID_HANDLE_VALUE )
113 if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, ".."))
115 pidl = _ILCreateFolder (&stffile);
116 if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
122 } while( FindNextFileA(hFile,&stffile));
127 /*enumerate the non-folder items (values) */
128 if(dwFlags & SHCONTF_NONFOLDERS)
130 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",This,debugstr_a(szPath));
131 hFile = FindFirstFileA(szPath,&stffile);
132 if ( hFile != INVALID_HANDLE_VALUE )
136 if (! (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
138 pidl = _ILCreateValue(&stffile);
139 if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
145 } while( FindNextFileA(hFile,&stffile));
152 /**************************************************************************
153 * CreateDesktopEnumList()
155 static BOOL CreateDesktopEnumList(
159 ICOM_THIS(IEnumIDListImpl,iface);
161 LPITEMIDLIST pidl=NULL;
163 char szPath[MAX_PATH];
165 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
167 /*enumerate the root folders */
168 if(dwFlags & SHCONTF_FOLDERS)
170 /*create the pidl for This item */
171 pidl = _ILCreateMyComputer();
174 if(!AddToEnumList((IEnumIDList*)This, pidl))
178 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\desktop\\NameSpace", 0, KEY_READ, &hkey))
185 DWORD size = sizeof (iid);
187 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
190 pidl = _ILCreateSpecial(iid);
193 AddToEnumList((IEnumIDList*)This, pidl);
201 /*enumerate the elements in %windir%\desktop */
202 SHGetSpecialFolderPathA(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
203 CreateFolderEnumList( (IEnumIDList*)This, szPath, dwFlags);
208 /**************************************************************************
209 * CreateMyCompEnumList()
211 static BOOL CreateMyCompEnumList(
215 ICOM_THIS(IEnumIDListImpl,iface);
217 LPITEMIDLIST pidl=NULL;
222 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
224 /*enumerate the folders*/
225 if(dwFlags & SHCONTF_FOLDERS)
227 dwDrivemap = GetLogicalDrives();
228 strcpy (szDriveName,"A:\\");
229 while (szDriveName[0]<='Z')
231 if(dwDrivemap & 0x00000001L)
233 pidl = _ILCreateDrive(szDriveName);
236 if(!AddToEnumList((IEnumIDList*)This, pidl))
241 dwDrivemap = dwDrivemap >> 1;
244 TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",This);
245 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\mycomputer\\NameSpace", 0, KEY_READ, &hkey))
252 DWORD size = sizeof (iid);
254 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
257 pidl = _ILCreateSpecial(iid);
260 AddToEnumList((IEnumIDList*)This, pidl);
270 /**************************************************************************
273 static BOOL DeleteList(
276 ICOM_THIS(IEnumIDListImpl,iface);
280 TRACE("(%p)->()\n",This);
283 { pDelete = This->mpFirst;
284 This->mpFirst = pDelete->pNext;
285 SHFree(pDelete->pidl);
288 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
292 /**************************************************************************
293 * IEnumIDList_Folder_Constructor
297 IEnumIDList * IEnumIDList_Constructor(
302 IEnumIDListImpl* lpeidl;
305 lpeidl = (IEnumIDListImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumIDListImpl));
307 TRACE("(%p)->(%s flags=0x%08lx kind=0x%08lx)\n",lpeidl,debugstr_a(lpszPath),dwFlags, dwKind);
312 lpeidl->lpvtbl = &eidlvt;
317 ret = CreateDesktopEnumList((IEnumIDList*)lpeidl, dwFlags);
321 ret = CreateMyCompEnumList((IEnumIDList*)lpeidl, dwFlags);
325 ret = CreateFolderEnumList((IEnumIDList*)lpeidl, lpszPath, dwFlags);
337 HeapFree(GetProcessHeap(),0,lpeidl);
342 TRACE("-- (%p)->()\n",lpeidl);
344 return (IEnumIDList*)lpeidl;
347 /**************************************************************************
348 * EnumIDList_QueryInterface
350 static HRESULT WINAPI IEnumIDList_fnQueryInterface(
355 ICOM_THIS(IEnumIDListImpl,iface);
358 WINE_StringFromCLSID((LPCLSID)riid,xriid);
359 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
363 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
366 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
367 { *ppvObj = (IEnumIDList*)This;
371 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
372 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
376 TRACE("-- Interface: E_NOINTERFACE\n");
377 return E_NOINTERFACE;
380 /******************************************************************************
381 * IEnumIDList_fnAddRef
383 static ULONG WINAPI IEnumIDList_fnAddRef(
386 ICOM_THIS(IEnumIDListImpl,iface);
388 TRACE("(%p)->(%lu)\n",This,This->ref);
391 return ++(This->ref);
393 /******************************************************************************
394 * IEnumIDList_fnRelease
396 static ULONG WINAPI IEnumIDList_fnRelease(
399 ICOM_THIS(IEnumIDListImpl,iface);
401 TRACE("(%p)->(%lu)\n",This,This->ref);
406 { TRACE(" destroying IEnumIDList(%p)\n",This);
407 DeleteList((IEnumIDList*)This);
408 HeapFree(GetProcessHeap(),0,This);
414 /**************************************************************************
418 static HRESULT WINAPI IEnumIDList_fnNext(
421 LPITEMIDLIST * rgelt,
424 ICOM_THIS(IEnumIDListImpl,iface);
430 TRACE("(%p)->(%ld,%p, %p)\n",This,celt,rgelt,pceltFetched);
432 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
433 * subsystems actually use it (and so may a third party browser)
440 if(celt > 1 && !pceltFetched)
441 { return E_INVALIDARG;
444 for(i = 0; i < celt; i++)
445 { if(!(This->mpCurrent))
449 temp = ILClone(This->mpCurrent->pidl);
451 This->mpCurrent = This->mpCurrent->pNext;
460 /**************************************************************************
463 static HRESULT WINAPI IEnumIDList_fnSkip(
464 IEnumIDList * iface,ULONG celt)
466 ICOM_THIS(IEnumIDListImpl,iface);
471 TRACE("(%p)->(%lu)\n",This,celt);
473 for(dwIndex = 0; dwIndex < celt; dwIndex++)
474 { if(!This->mpCurrent)
478 This->mpCurrent = This->mpCurrent->pNext;
482 /**************************************************************************
483 * IEnumIDList_fnReset
485 static HRESULT WINAPI IEnumIDList_fnReset(
488 ICOM_THIS(IEnumIDListImpl,iface);
490 TRACE("(%p)\n",This);
491 This->mpCurrent = This->mpFirst;
494 /**************************************************************************
495 * IEnumIDList_fnClone
497 static HRESULT WINAPI IEnumIDList_fnClone(
498 IEnumIDList * iface,LPENUMIDLIST * ppenum)
500 ICOM_THIS(IEnumIDListImpl,iface);
502 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
506 /**************************************************************************
507 * IEnumIDList_fnVTable
509 static ICOM_VTABLE (IEnumIDList) eidlvt =
511 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
512 IEnumIDList_fnQueryInterface,
513 IEnumIDList_fnAddRef,
514 IEnumIDList_fnRelease,