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_VFIELD(IEnumIDList
);
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 ICOM_VTBL(lpeidl
) = &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
);
357 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
361 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
364 else if(IsEqualIID(riid
, &IID_IEnumIDList
)) /*IEnumIDList*/
365 { *ppvObj
= (IEnumIDList
*)This
;
369 { IEnumIDList_AddRef((IEnumIDList
*)*ppvObj
);
370 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
374 TRACE("-- Interface: E_NOINTERFACE\n");
375 return E_NOINTERFACE
;
378 /******************************************************************************
379 * IEnumIDList_fnAddRef
381 static ULONG WINAPI
IEnumIDList_fnAddRef(
384 ICOM_THIS(IEnumIDListImpl
,iface
);
386 TRACE("(%p)->(%lu)\n",This
,This
->ref
);
389 return ++(This
->ref
);
391 /******************************************************************************
392 * IEnumIDList_fnRelease
394 static ULONG WINAPI
IEnumIDList_fnRelease(
397 ICOM_THIS(IEnumIDListImpl
,iface
);
399 TRACE("(%p)->(%lu)\n",This
,This
->ref
);
404 { TRACE(" destroying IEnumIDList(%p)\n",This
);
405 DeleteList((IEnumIDList
*)This
);
406 HeapFree(GetProcessHeap(),0,This
);
412 /**************************************************************************
416 static HRESULT WINAPI
IEnumIDList_fnNext(
419 LPITEMIDLIST
* rgelt
,
422 ICOM_THIS(IEnumIDListImpl
,iface
);
428 TRACE("(%p)->(%ld,%p, %p)\n",This
,celt
,rgelt
,pceltFetched
);
430 /* It is valid to leave pceltFetched NULL when celt is 1. Some of explorer's
431 * subsystems actually use it (and so may a third party browser)
438 if(celt
> 1 && !pceltFetched
)
439 { return E_INVALIDARG
;
442 for(i
= 0; i
< celt
; i
++)
443 { if(!(This
->mpCurrent
))
447 temp
= ILClone(This
->mpCurrent
->pidl
);
449 This
->mpCurrent
= This
->mpCurrent
->pNext
;
458 /**************************************************************************
461 static HRESULT WINAPI
IEnumIDList_fnSkip(
462 IEnumIDList
* iface
,ULONG celt
)
464 ICOM_THIS(IEnumIDListImpl
,iface
);
469 TRACE("(%p)->(%lu)\n",This
,celt
);
471 for(dwIndex
= 0; dwIndex
< celt
; dwIndex
++)
472 { if(!This
->mpCurrent
)
476 This
->mpCurrent
= This
->mpCurrent
->pNext
;
480 /**************************************************************************
481 * IEnumIDList_fnReset
483 static HRESULT WINAPI
IEnumIDList_fnReset(
486 ICOM_THIS(IEnumIDListImpl
,iface
);
488 TRACE("(%p)\n",This
);
489 This
->mpCurrent
= This
->mpFirst
;
492 /**************************************************************************
493 * IEnumIDList_fnClone
495 static HRESULT WINAPI
IEnumIDList_fnClone(
496 IEnumIDList
* iface
,LPENUMIDLIST
* ppenum
)
498 ICOM_THIS(IEnumIDListImpl
,iface
);
500 TRACE("(%p)->() to (%p)->() E_NOTIMPL\n",This
,ppenum
);
504 /**************************************************************************
505 * IEnumIDList_fnVTable
507 static ICOM_VTABLE (IEnumIDList
) eidlvt
=
509 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
510 IEnumIDList_fnQueryInterface
,
511 IEnumIDList_fnAddRef
,
512 IEnumIDList_fnRelease
,