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 ( !(dwFlags & SHCONTF_INCLUDEHIDDEN) && (stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) continue;
129 if ( (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp (stffile.cFileName, ".") && strcmp (stffile.cFileName, ".."))
131 pidl = _ILCreateFolder (&stffile);
132 if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
138 } while( FindNextFileA(hFile,&stffile));
143 /*enumerate the non-folder items (values) */
144 if(dwFlags & SHCONTF_NONFOLDERS)
146 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",This,debugstr_a(szPath));
147 hFile = FindFirstFileA(szPath,&stffile);
148 if ( hFile != INVALID_HANDLE_VALUE )
152 if ( !(dwFlags & SHCONTF_INCLUDEHIDDEN) && (stffile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ) continue;
153 if (! (stffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
155 pidl = _ILCreateValue(&stffile);
156 if(pidl && AddToEnumList((IEnumIDList*)This, pidl))
162 } while( FindNextFileA(hFile,&stffile));
169 /**************************************************************************
170 * CreateDesktopEnumList()
172 static BOOL CreateDesktopEnumList(
176 ICOM_THIS(IEnumIDListImpl,iface);
178 LPITEMIDLIST pidl=NULL;
180 char szPath[MAX_PATH];
182 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
184 /*enumerate the root folders */
185 if(dwFlags & SHCONTF_FOLDERS)
187 /*create the pidl for This item */
188 pidl = _ILCreateMyComputer();
191 if(!AddToEnumList((IEnumIDList*)This, pidl))
195 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\desktop\\NameSpace", 0, KEY_READ, &hkey))
202 DWORD size = sizeof (iid);
204 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
207 pidl = _ILCreateSpecial(iid);
210 AddToEnumList((IEnumIDList*)This, pidl);
218 /*enumerate the elements in %windir%\desktop */
219 SHGetSpecialFolderPathA(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
220 CreateFolderEnumList( (IEnumIDList*)This, szPath, dwFlags);
225 /**************************************************************************
226 * CreateMyCompEnumList()
228 static BOOL CreateMyCompEnumList(
232 ICOM_THIS(IEnumIDListImpl,iface);
234 LPITEMIDLIST pidl=NULL;
239 TRACE("(%p)->(flags=0x%08lx) \n",This,dwFlags);
241 /*enumerate the folders*/
242 if(dwFlags & SHCONTF_FOLDERS)
244 dwDrivemap = GetLogicalDrives();
245 strcpy (szDriveName,"A:\\");
246 while (szDriveName[0]<='Z')
248 if(dwDrivemap & 0x00000001L)
250 pidl = _ILCreateDrive(szDriveName);
253 if(!AddToEnumList((IEnumIDList*)This, pidl))
258 dwDrivemap = dwDrivemap >> 1;
261 TRACE("-- (%p)-> enumerate (mycomputer shell extensions)\n",This);
262 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\mycomputer\\NameSpace", 0, KEY_READ, &hkey))
269 DWORD size = sizeof (iid);
271 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
274 pidl = _ILCreateSpecial(iid);
277 AddToEnumList((IEnumIDList*)This, pidl);
287 /**************************************************************************
290 static BOOL DeleteList(
293 ICOM_THIS(IEnumIDListImpl,iface);
297 TRACE("(%p)->()\n",This);
300 { pDelete = This->mpFirst;
301 This->mpFirst = pDelete->pNext;
302 SHFree(pDelete->pidl);
305 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
309 /**************************************************************************
310 * IEnumIDList_Folder_Constructor
314 IEnumIDList * IEnumIDList_Constructor(
319 IEnumIDListImpl* lpeidl;
322 TRACE("()->(%s flags=0x%08lx kind=0x%08lx)\n",debugstr_a(lpszPath),dwFlags, dwKind);
324 lpeidl = (IEnumIDListImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumIDListImpl));
329 ICOM_VTBL(lpeidl) = &eidlvt;
334 ret = CreateDesktopEnumList((IEnumIDList*)lpeidl, dwFlags);
338 ret = CreateMyCompEnumList((IEnumIDList*)lpeidl, dwFlags);
342 ret = CreateFolderEnumList((IEnumIDList*)lpeidl, lpszPath, dwFlags);
347 HeapFree(GetProcessHeap(),0,lpeidl);
352 TRACE("-- (%p)->()\n",lpeidl);
354 return (IEnumIDList*)lpeidl;
357 /**************************************************************************
358 * EnumIDList_QueryInterface
360 static HRESULT WINAPI IEnumIDList_fnQueryInterface(
365 ICOM_THIS(IEnumIDListImpl,iface);
367 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
371 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
374 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
375 { *ppvObj = (IEnumIDList*)This;
379 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
380 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
384 TRACE("-- Interface: E_NOINTERFACE\n");
385 return E_NOINTERFACE;
388 /******************************************************************************
389 * IEnumIDList_fnAddRef
391 static ULONG WINAPI IEnumIDList_fnAddRef(
394 ICOM_THIS(IEnumIDListImpl,iface);
395 TRACE("(%p)->(%lu)\n",This,This->ref);
396 return ++(This->ref);
398 /******************************************************************************
399 * IEnumIDList_fnRelease
401 static ULONG WINAPI IEnumIDList_fnRelease(
404 ICOM_THIS(IEnumIDListImpl,iface);
406 TRACE("(%p)->(%lu)\n",This,This->ref);
408 if (!--(This->ref)) {
409 TRACE(" destroying IEnumIDList(%p)\n",This);
410 DeleteList((IEnumIDList*)This);
411 HeapFree(GetProcessHeap(),0,This);
417 /**************************************************************************
421 static HRESULT WINAPI IEnumIDList_fnNext(
424 LPITEMIDLIST * rgelt,
427 ICOM_THIS(IEnumIDListImpl,iface);
433 TRACE("(%p)->(%ld,%p, %p)\n",This,celt,rgelt,pceltFetched);
435 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
436 * subsystems actually use it (and so may a third party browser)
443 if(celt > 1 && !pceltFetched)
444 { return E_INVALIDARG;
447 for(i = 0; i < celt; i++)
448 { if(!(This->mpCurrent))
452 temp = ILClone(This->mpCurrent->pidl);
454 This->mpCurrent = This->mpCurrent->pNext;
463 /**************************************************************************
466 static HRESULT WINAPI IEnumIDList_fnSkip(
467 IEnumIDList * iface,ULONG celt)
469 ICOM_THIS(IEnumIDListImpl,iface);
474 TRACE("(%p)->(%lu)\n",This,celt);
476 for(dwIndex = 0; dwIndex < celt; dwIndex++)
477 { if(!This->mpCurrent)
481 This->mpCurrent = This->mpCurrent->pNext;
485 /**************************************************************************
486 * IEnumIDList_fnReset
488 static HRESULT WINAPI IEnumIDList_fnReset(
491 ICOM_THIS(IEnumIDListImpl,iface);
493 TRACE("(%p)\n",This);
494 This->mpCurrent = This->mpFirst;
497 /**************************************************************************
498 * IEnumIDList_fnClone
500 static HRESULT WINAPI IEnumIDList_fnClone(
501 IEnumIDList * iface,LPENUMIDLIST * ppenum)
503 ICOM_THIS(IEnumIDListImpl,iface);
505 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This,ppenum);
509 /**************************************************************************
510 * IEnumIDList_fnVTable
512 static ICOM_VTABLE (IEnumIDList) eidlvt =
514 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
515 IEnumIDList_fnQueryInterface,
516 IEnumIDList_fnAddRef,
517 IEnumIDList_fnRelease,