X11DRV_SetFocus: really don't mess with focus for managed windows.
[wine/multimedia.git] / dlls / shell32 / enumidlist.c
bloba75d15be5228726734d9fd28bd62f10af5df5497
1 /*
2 * IEnumIDList
4 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include "debugtools.h"
10 #include "winreg.h"
11 #include "wine/obj_base.h"
12 #include "wine/obj_enumidlist.h"
13 #include "wine/undocshell.h"
14 #include "winerror.h"
16 #include "pidl.h"
17 #include "shlguid.h"
18 #include "shell32_main.h"
20 DEFAULT_DEBUG_CHANNEL(shell)
22 typedef struct tagENUMLIST
24 struct tagENUMLIST *pNext;
25 LPITEMIDLIST pidl;
27 } ENUMLIST, *LPENUMLIST;
29 typedef struct
31 ICOM_VFIELD(IEnumIDList);
32 DWORD ref;
33 LPENUMLIST mpFirst;
34 LPENUMLIST mpLast;
35 LPENUMLIST mpCurrent;
37 } IEnumIDListImpl;
39 static struct ICOM_VTABLE(IEnumIDList) eidlvt;
41 /**************************************************************************
42 * AddToEnumList()
44 static BOOL AddToEnumList(
45 IEnumIDList * iface,
46 LPITEMIDLIST pidl)
48 ICOM_THIS(IEnumIDListImpl,iface);
50 LPENUMLIST pNew;
52 TRACE("(%p)->(pidl=%p)\n",This,pidl);
53 pNew = (LPENUMLIST)SHAlloc(sizeof(ENUMLIST));
54 if(pNew)
56 /*set the next pointer */
57 pNew->pNext = NULL;
58 pNew->pidl = pidl;
60 /*is This the first item in the list? */
61 if(!This->mpFirst)
63 This->mpFirst = pNew;
64 This->mpCurrent = pNew;
67 if(This->mpLast)
69 /*add the new item to the end of the list */
70 This->mpLast->pNext = pNew;
73 /*update the last item pointer */
74 This->mpLast = pNew;
75 TRACE("-- (%p)->(first=%p, last=%p)\n",This,This->mpFirst,This->mpLast);
76 return TRUE;
78 return FALSE;
81 /**************************************************************************
82 * CreateFolderEnumList()
84 static BOOL CreateFolderEnumList(
85 IEnumIDList * iface,
86 LPCSTR lpszPath,
87 DWORD dwFlags)
89 ICOM_THIS(IEnumIDListImpl,iface);
91 LPITEMIDLIST pidl=NULL;
92 WIN32_FIND_DATAA stffile;
93 HANDLE hFile;
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))
118 continue;
120 return FALSE;
122 } while( FindNextFileA(hFile,&stffile));
123 FindClose (hFile);
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))
141 continue;
143 return FALSE;
145 } while( FindNextFileA(hFile,&stffile));
146 FindClose (hFile);
149 return TRUE;
152 /**************************************************************************
153 * CreateDesktopEnumList()
155 static BOOL CreateDesktopEnumList(
156 IEnumIDList * iface,
157 DWORD dwFlags)
159 ICOM_THIS(IEnumIDListImpl,iface);
161 LPITEMIDLIST pidl=NULL;
162 HKEY hkey;
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();
172 if(pidl)
174 if(!AddToEnumList((IEnumIDList*)This, pidl))
175 return FALSE;
178 if (! RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\desktop\\NameSpace", 0, KEY_READ, &hkey))
180 char iid[50];
181 int i=0;
183 while (1)
185 DWORD size = sizeof (iid);
187 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
188 break;
190 pidl = _ILCreateSpecial(iid);
192 if(pidl)
193 AddToEnumList((IEnumIDList*)This, pidl);
195 i++;
197 RegCloseKey(hkey);
201 /*enumerate the elements in %windir%\desktop */
202 SHGetSpecialFolderPathA(0, szPath, CSIDL_DESKTOPDIRECTORY, FALSE);
203 CreateFolderEnumList( (IEnumIDList*)This, szPath, dwFlags);
205 return TRUE;
208 /**************************************************************************
209 * CreateMyCompEnumList()
211 static BOOL CreateMyCompEnumList(
212 IEnumIDList * iface,
213 DWORD dwFlags)
215 ICOM_THIS(IEnumIDListImpl,iface);
217 LPITEMIDLIST pidl=NULL;
218 DWORD dwDrivemap;
219 CHAR szDriveName[4];
220 HKEY hkey;
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);
234 if(pidl)
236 if(!AddToEnumList((IEnumIDList*)This, pidl))
237 return FALSE;
240 szDriveName[0]++;
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))
247 char iid[50];
248 int i=0;
250 while (1)
252 DWORD size = sizeof (iid);
254 if (ERROR_SUCCESS!=RegEnumKeyExA(hkey, i, iid, &size, 0, NULL, NULL, NULL))
255 break;
257 pidl = _ILCreateSpecial(iid);
259 if(pidl)
260 AddToEnumList((IEnumIDList*)This, pidl);
262 i++;
264 RegCloseKey(hkey);
267 return TRUE;
270 /**************************************************************************
271 * DeleteList()
273 static BOOL DeleteList(
274 IEnumIDList * iface)
276 ICOM_THIS(IEnumIDListImpl,iface);
278 LPENUMLIST pDelete;
280 TRACE("(%p)->()\n",This);
282 while(This->mpFirst)
283 { pDelete = This->mpFirst;
284 This->mpFirst = pDelete->pNext;
285 SHFree(pDelete->pidl);
286 SHFree(pDelete);
288 This->mpFirst = This->mpLast = This->mpCurrent = NULL;
289 return TRUE;
292 /**************************************************************************
293 * IEnumIDList_Folder_Constructor
297 IEnumIDList * IEnumIDList_Constructor(
298 LPCSTR lpszPath,
299 DWORD dwFlags,
300 DWORD dwKind)
302 IEnumIDListImpl* lpeidl;
303 BOOL ret = FALSE;
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);
309 if (lpeidl)
311 lpeidl->ref = 1;
312 ICOM_VTBL(lpeidl) = &eidlvt;
314 switch (dwKind)
316 case EIDL_DESK:
317 ret = CreateDesktopEnumList((IEnumIDList*)lpeidl, dwFlags);
318 break;
320 case EIDL_MYCOMP:
321 ret = CreateMyCompEnumList((IEnumIDList*)lpeidl, dwFlags);
322 break;
324 case EIDL_FILE:
325 ret = CreateFolderEnumList((IEnumIDList*)lpeidl, lpszPath, dwFlags);
326 break;
329 if(ret)
331 shell32_ObjCount++;
333 else
335 if (lpeidl)
337 HeapFree(GetProcessHeap(),0,lpeidl);
342 TRACE("-- (%p)->()\n",lpeidl);
344 return (IEnumIDList*)lpeidl;
347 /**************************************************************************
348 * EnumIDList_QueryInterface
350 static HRESULT WINAPI IEnumIDList_fnQueryInterface(
351 IEnumIDList * iface,
352 REFIID riid,
353 LPVOID *ppvObj)
355 ICOM_THIS(IEnumIDListImpl,iface);
357 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
359 *ppvObj = NULL;
361 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
362 { *ppvObj = This;
364 else if(IsEqualIID(riid, &IID_IEnumIDList)) /*IEnumIDList*/
365 { *ppvObj = (IEnumIDList*)This;
368 if(*ppvObj)
369 { IEnumIDList_AddRef((IEnumIDList*)*ppvObj);
370 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
371 return S_OK;
374 TRACE("-- Interface: E_NOINTERFACE\n");
375 return E_NOINTERFACE;
378 /******************************************************************************
379 * IEnumIDList_fnAddRef
381 static ULONG WINAPI IEnumIDList_fnAddRef(
382 IEnumIDList * iface)
384 ICOM_THIS(IEnumIDListImpl,iface);
386 TRACE("(%p)->(%lu)\n",This,This->ref);
388 shell32_ObjCount++;
389 return ++(This->ref);
391 /******************************************************************************
392 * IEnumIDList_fnRelease
394 static ULONG WINAPI IEnumIDList_fnRelease(
395 IEnumIDList * iface)
397 ICOM_THIS(IEnumIDListImpl,iface);
399 TRACE("(%p)->(%lu)\n",This,This->ref);
401 shell32_ObjCount--;
403 if (!--(This->ref))
404 { TRACE(" destroying IEnumIDList(%p)\n",This);
405 DeleteList((IEnumIDList*)This);
406 HeapFree(GetProcessHeap(),0,This);
407 return 0;
409 return This->ref;
412 /**************************************************************************
413 * IEnumIDList_fnNext
416 static HRESULT WINAPI IEnumIDList_fnNext(
417 IEnumIDList * iface,
418 ULONG celt,
419 LPITEMIDLIST * rgelt,
420 ULONG *pceltFetched)
422 ICOM_THIS(IEnumIDListImpl,iface);
424 ULONG i;
425 HRESULT hr = S_OK;
426 LPITEMIDLIST temp;
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)
433 if(pceltFetched)
434 *pceltFetched = 0;
436 *rgelt=0;
438 if(celt > 1 && !pceltFetched)
439 { return E_INVALIDARG;
442 for(i = 0; i < celt; i++)
443 { if(!(This->mpCurrent))
444 { hr = S_FALSE;
445 break;
447 temp = ILClone(This->mpCurrent->pidl);
448 rgelt[i] = temp;
449 This->mpCurrent = This->mpCurrent->pNext;
451 if(pceltFetched)
452 { *pceltFetched = i;
455 return hr;
458 /**************************************************************************
459 * IEnumIDList_fnSkip
461 static HRESULT WINAPI IEnumIDList_fnSkip(
462 IEnumIDList * iface,ULONG celt)
464 ICOM_THIS(IEnumIDListImpl,iface);
466 DWORD dwIndex;
467 HRESULT hr = S_OK;
469 TRACE("(%p)->(%lu)\n",This,celt);
471 for(dwIndex = 0; dwIndex < celt; dwIndex++)
472 { if(!This->mpCurrent)
473 { hr = S_FALSE;
474 break;
476 This->mpCurrent = This->mpCurrent->pNext;
478 return hr;
480 /**************************************************************************
481 * IEnumIDList_fnReset
483 static HRESULT WINAPI IEnumIDList_fnReset(
484 IEnumIDList * iface)
486 ICOM_THIS(IEnumIDListImpl,iface);
488 TRACE("(%p)\n",This);
489 This->mpCurrent = This->mpFirst;
490 return S_OK;
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);
501 return E_NOTIMPL;
504 /**************************************************************************
505 * IEnumIDList_fnVTable
507 static ICOM_VTABLE (IEnumIDList) eidlvt =
509 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
510 IEnumIDList_fnQueryInterface,
511 IEnumIDList_fnAddRef,
512 IEnumIDList_fnRelease,
513 IEnumIDList_fnNext,
514 IEnumIDList_fnSkip,
515 IEnumIDList_fnReset,
516 IEnumIDList_fnClone,