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"
28 #include "wine/obj_base.h"
29 #include "wine/obj_enumidlist.h"
33 #include "shell32_main.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(shell);
37 typedef struct tagENUMLIST
39 struct tagENUMLIST *pNext;
42 } ENUMLIST, *LPENUMLIST;
46 ICOM_VFIELD(IEnumIDList);
54 static struct ICOM_VTABLE(IEnumIDList) eidlvt;
56 /**************************************************************************
59 static BOOL AddToEnumList(
63 ICOM_THIS(IEnumIDListImpl,iface);
67 TRACE("(%p)->(pidl=%p)\n",This,pidl);
68 pNew = (LPENUMLIST)SHAlloc(sizeof(ENUMLIST));
71 /*set the next pointer */
75 /*is This the first item in the list? */
79 This->mpCurrent = pNew;
84 /*add the new item to the end of the list */
85 This->mpLast->pNext = pNew;
88 /*update the last item pointer */
90 TRACE("-- (%p)->(first=%p, last=%p)\n",This,This->mpFirst,This->mpLast);
96 /**************************************************************************
97 * CreateFolderEnumList()
99 static BOOL CreateFolderEnumList(
104 ICOM_THIS(IEnumIDListImpl,iface);
106 LPITEMIDLIST pidl=NULL;
107 WIN32_FIND_DATAA stffile;
109 CHAR szPath[MAX_PATH];
111 TRACE("(%p)->(path=%s flags=0x%08lx) \n",This,debugstr_a(lpszPath),dwFlags);
113 if(!lpszPath || !lpszPath[0]) return FALSE;
115 strcpy(szPath, lpszPath);
116 PathAddBackslashA(szPath);
117 strcat(szPath,"*.*");
119 /*enumerate the folders*/
120 if(dwFlags & SHCONTF_FOLDERS)
122 TRACE("-- (%p)-> enumerate SHCONTF_FOLDERS of %s\n",This,debugstr_a(szPath));
123 hFile = FindFirstFileA(szPath,&stffile);
124 if ( hFile != INVALID_HANDLE_VALUE )
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 (! (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
153 pidl = _ILCreateValue(&stffile);
154 if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
160 } while( FindNextFileA(hFile,&stffile));
167 /**************************************************************************
168 * CreateDesktopEnumList()
170 static BOOL CreateDesktopEnumList(
174 ICOM_THIS(IEnumIDListImpl,iface);
176 LPITEMIDLIST pidl=NULL;
178 char szPath[MAX_PATH];
180 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
182 /*enumerate the root folders */
183 if(dwFlags & SHCONTF_FOLDERS)
185 /*create the pidl for This item */
186 pidl = _ILCreateMyComputer();
189 if(!AddToEnumList((IEnumIDList*)This, pidl))
193 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\desktop\\NameSpace", 0, KEY_READ, &hkey))
200 DWORD size = sizeof (iid);
202 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
205 pidl = _ILCreateSpecial(iid);
208 AddToEnumList((IEnumIDList*)This, pidl);
216 /*enumerate the elements in %windir%\desktop */
217 SHGetSpecialFolderPathA(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
218 CreateFolderEnumList( (IEnumIDList*)This, szPath, dwFlags);
223 /**************************************************************************
224 * CreateMyCompEnumList()
226 static BOOL CreateMyCompEnumList(
230 ICOM_THIS(IEnumIDListImpl,iface);
232 LPITEMIDLIST pidl=NULL;
237 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
239 /*enumerate the folders*/
240 if(dwFlags & SHCONTF_FOLDERS)
242 dwDrivemap = GetLogicalDrives();
243 strcpy (szDriveName,"A:\\");
244 while (szDriveName[0]<='Z')
246 if(dwDrivemap & 0x00000001L)
248 pidl = _ILCreateDrive(szDriveName);
251 if(!AddToEnumList((IEnumIDList*)This, pidl))
256 dwDrivemap = dwDrivemap >> 1;
259 TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",This);
260 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\mycomputer\\NameSpace", 0, KEY_READ, &hkey))
267 DWORD size = sizeof (iid);
269 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
272 pidl = _ILCreateSpecial(iid);
275 AddToEnumList((IEnumIDList*)This, pidl);
285 /**************************************************************************
288 static BOOL DeleteList(
291 ICOM_THIS(IEnumIDListImpl,iface);
295 TRACE("(%p)->()\n",This);
298 { pDelete = This->mpFirst;
299 This->mpFirst = pDelete->pNext;
300 SHFree(pDelete->pidl);
303 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
307 /**************************************************************************
308 * IEnumIDList_Folder_Constructor
312 IEnumIDList * IEnumIDList_Constructor(
317 IEnumIDListImpl* lpeidl;
320 lpeidl = (IEnumIDListImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumIDListImpl));
322 TRACE("(%p)->(%s flags=0x%08lx kind=0x%08lx)\n",lpeidl,debugstr_a(lpszPath),dwFlags, dwKind);
327 ICOM_VTBL(lpeidl) = &eidlvt;
332 ret = CreateDesktopEnumList((IEnumIDList*)lpeidl, dwFlags);
336 ret = CreateMyCompEnumList((IEnumIDList*)lpeidl, dwFlags);
340 ret = CreateFolderEnumList((IEnumIDList*)lpeidl, lpszPath, dwFlags);
352 HeapFree(GetProcessHeap(),0,lpeidl);
357 TRACE("-- (%p)->()\n",lpeidl);
359 return (IEnumIDList*)lpeidl;
362 /**************************************************************************
363 * EnumIDList_QueryInterface
365 static HRESULT WINAPI IEnumIDList_fnQueryInterface(
370 ICOM_THIS(IEnumIDListImpl,iface);
372 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
376 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
379 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
380 { *ppvObj = (IEnumIDList*)This;
384 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
385 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
389 TRACE("-- Interface: E_NOINTERFACE\n");
390 return E_NOINTERFACE;
393 /******************************************************************************
394 * IEnumIDList_fnAddRef
396 static ULONG WINAPI IEnumIDList_fnAddRef(
399 ICOM_THIS(IEnumIDListImpl,iface);
401 TRACE("(%p)->(%lu)\n",This,This->ref);
404 return ++(This->ref);
406 /******************************************************************************
407 * IEnumIDList_fnRelease
409 static ULONG WINAPI IEnumIDList_fnRelease(
412 ICOM_THIS(IEnumIDListImpl,iface);
414 TRACE("(%p)->(%lu)\n",This,This->ref);
419 { TRACE(" destroying IEnumIDList(%p)\n",This);
420 DeleteList((IEnumIDList*)This);
421 HeapFree(GetProcessHeap(),0,This);
427 /**************************************************************************
431 static HRESULT WINAPI IEnumIDList_fnNext(
434 LPITEMIDLIST * rgelt,
437 ICOM_THIS(IEnumIDListImpl,iface);
443 TRACE("(%p)->(%ld,%p, %p)\n",This,celt,rgelt,pceltFetched);
445 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
446 * subsystems actually use it (and so may a third party browser)
453 if(celt > 1 && !pceltFetched)
454 { return E_INVALIDARG;
457 for(i = 0; i < celt; i++)
458 { if(!(This->mpCurrent))
462 temp = ILClone(This->mpCurrent->pidl);
464 This->mpCurrent = This->mpCurrent->pNext;
473 /**************************************************************************
476 static HRESULT WINAPI IEnumIDList_fnSkip(
477 IEnumIDList * iface,ULONG celt)
479 ICOM_THIS(IEnumIDListImpl,iface);
484 TRACE("(%p)->(%lu)\n",This,celt);
486 for(dwIndex = 0; dwIndex < celt; dwIndex++)
487 { if(!This->mpCurrent)
491 This->mpCurrent = This->mpCurrent->pNext;
495 /**************************************************************************
496 * IEnumIDList_fnReset
498 static HRESULT WINAPI IEnumIDList_fnReset(
501 ICOM_THIS(IEnumIDListImpl,iface);
503 TRACE("(%p)\n",This);
504 This->mpCurrent = This->mpFirst;
507 /**************************************************************************
508 * IEnumIDList_fnClone
510 static HRESULT WINAPI IEnumIDList_fnClone(
511 IEnumIDList * iface,LPENUMIDLIST * ppenum)
513 ICOM_THIS(IEnumIDListImpl,iface);
515 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
519 /**************************************************************************
520 * IEnumIDList_fnVTable
522 static ICOM_VTABLE (IEnumIDList) eidlvt =
524 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
525 IEnumIDList_fnQueryInterface,
526 IEnumIDList_fnAddRef,
527 IEnumIDList_fnRelease,