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 TRACE("()->(%s flags=0x%08lx kind=0x%08lx)\n",debugstr_a(lpszPath),dwFlags, dwKind);
322 lpeidl = (IEnumIDListImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumIDListImpl));
327 ICOM_VTBL(lpeidl) = &eidlvt;
332 ret = CreateDesktopEnumList((IEnumIDList*)lpeidl, dwFlags);
336 ret = CreateMyCompEnumList((IEnumIDList*)lpeidl, dwFlags);
340 ret = CreateFolderEnumList((IEnumIDList*)lpeidl, lpszPath, dwFlags);
345 HeapFree(GetProcessHeap(),0,lpeidl);
350 TRACE("-- (%p)->()\n",lpeidl);
352 return (IEnumIDList*)lpeidl;
355 /**************************************************************************
356 * EnumIDList_QueryInterface
358 static HRESULT WINAPI IEnumIDList_fnQueryInterface(
363 ICOM_THIS(IEnumIDListImpl,iface);
365 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
369 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
372 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
373 { *ppvObj = (IEnumIDList*)This;
377 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
378 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
382 TRACE("-- Interface: E_NOINTERFACE\n");
383 return E_NOINTERFACE;
386 /******************************************************************************
387 * IEnumIDList_fnAddRef
389 static ULONG WINAPI IEnumIDList_fnAddRef(
392 ICOM_THIS(IEnumIDListImpl,iface);
393 TRACE("(%p)->(%lu)\n",This,This->ref);
394 return ++(This->ref);
396 /******************************************************************************
397 * IEnumIDList_fnRelease
399 static ULONG WINAPI IEnumIDList_fnRelease(
402 ICOM_THIS(IEnumIDListImpl,iface);
404 TRACE("(%p)->(%lu)\n",This,This->ref);
406 if (!--(This->ref)) {
407 TRACE(" destroying IEnumIDList(%p)\n",This);
408 DeleteList((IEnumIDList*)This);
409 HeapFree(GetProcessHeap(),0,This);
415 /**************************************************************************
419 static HRESULT WINAPI IEnumIDList_fnNext(
422 LPITEMIDLIST * rgelt,
425 ICOM_THIS(IEnumIDListImpl,iface);
431 TRACE("(%p)->(%ld,%p, %p)\n",This,celt,rgelt,pceltFetched);
433 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
434 * subsystems actually use it (and so may a third party browser)
441 if(celt > 1 && !pceltFetched)
442 { return E_INVALIDARG;
445 for(i = 0; i < celt; i++)
446 { if(!(This->mpCurrent))
450 temp = ILClone(This->mpCurrent->pidl);
452 This->mpCurrent = This->mpCurrent->pNext;
461 /**************************************************************************
464 static HRESULT WINAPI IEnumIDList_fnSkip(
465 IEnumIDList * iface,ULONG celt)
467 ICOM_THIS(IEnumIDListImpl,iface);
472 TRACE("(%p)->(%lu)\n",This,celt);
474 for(dwIndex = 0; dwIndex < celt; dwIndex++)
475 { if(!This->mpCurrent)
479 This->mpCurrent = This->mpCurrent->pNext;
483 /**************************************************************************
484 * IEnumIDList_fnReset
486 static HRESULT WINAPI IEnumIDList_fnReset(
489 ICOM_THIS(IEnumIDListImpl,iface);
491 TRACE("(%p)\n",This);
492 This->mpCurrent = This->mpFirst;
495 /**************************************************************************
496 * IEnumIDList_fnClone
498 static HRESULT WINAPI IEnumIDList_fnClone(
499 IEnumIDList * iface,LPENUMIDLIST * ppenum)
501 ICOM_THIS(IEnumIDListImpl,iface);
503 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
507 /**************************************************************************
508 * IEnumIDList_fnVTable
510 static ICOM_VTABLE (IEnumIDList) eidlvt =
512 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
513 IEnumIDList_fnQueryInterface,
514 IEnumIDList_fnAddRef,
515 IEnumIDList_fnRelease,