-Wpointer-sign fixes.
[wine/multimedia.git] / dlls / shell32 / folders.c
blob443262a774cd8fb38c15235afa55d2e5cd047fc5
1 /*
2 * Copyright 1997 Marcus Meissner
3 * Copyright 1998 Juergen Schmied
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
28 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winerror.h"
33 #include "objbase.h"
34 #include "undocshell.h"
35 #include "shlguid.h"
36 #include "winreg.h"
38 #include "wine/debug.h"
40 #include "pidl.h"
41 #include "shell32_main.h"
42 #include "shfldr.h"
43 #include "shresdef.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(shell);
47 /***********************************************************************
48 * IExtractIconW implementation
50 typedef struct
52 const IExtractIconWVtbl *lpVtbl;
53 LONG ref;
54 const IPersistFileVtbl *lpvtblPersistFile;
55 const IExtractIconAVtbl *lpvtblExtractIconA;
56 LPITEMIDLIST pidl;
57 } IExtractIconWImpl;
59 static const IExtractIconAVtbl eiavt;
60 static const IExtractIconWVtbl eivt;
61 static const IPersistFileVtbl pfvt;
63 #define _IPersistFile_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblPersistFile)))
64 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
66 #define _IExtractIconA_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblExtractIconA)))
67 #define _ICOM_THIS_From_IExtractIconA(class, name) class* This = (class*)(((char*)name)-_IExtractIconA_Offset);
69 /**************************************************************************
70 * IExtractIconW_Constructor
72 IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl)
74 IExtractIconWImpl* ei;
76 TRACE("%p\n", pidl);
78 ei = HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconWImpl));
79 ei->ref=1;
80 ei->lpVtbl = &eivt;
81 ei->lpvtblPersistFile = &pfvt;
82 ei->lpvtblExtractIconA = &eiavt;
83 ei->pidl=ILClone(pidl);
85 pdump(pidl);
87 TRACE("(%p)\n", ei);
88 return (IExtractIconW *)ei;
90 /**************************************************************************
91 * IExtractIconW_QueryInterface
93 static HRESULT WINAPI IExtractIconW_fnQueryInterface(IExtractIconW *iface, REFIID riid, LPVOID *ppvObj)
95 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
97 TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This, debugstr_guid(riid), ppvObj);
99 *ppvObj = NULL;
101 if (IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
103 *ppvObj = This;
105 else if (IsEqualIID(riid, &IID_IPersistFile)) /*IExtractIcon*/
107 *ppvObj = (IPersistFile*)&(This->lpvtblPersistFile);
109 else if (IsEqualIID(riid, &IID_IExtractIconA)) /*IExtractIcon*/
111 *ppvObj = (IExtractIconA*)&(This->lpvtblExtractIconA);
113 else if (IsEqualIID(riid, &IID_IExtractIconW)) /*IExtractIcon*/
115 *ppvObj = (IExtractIconW*)This;
118 if(*ppvObj)
120 IExtractIconW_AddRef((IExtractIconW*) *ppvObj);
121 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
122 return S_OK;
124 TRACE("-- Interface: E_NOINTERFACE\n");
125 return E_NOINTERFACE;
128 /**************************************************************************
129 * IExtractIconW_AddRef
131 static ULONG WINAPI IExtractIconW_fnAddRef(IExtractIconW * iface)
133 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
134 ULONG refCount = InterlockedIncrement(&This->ref);
136 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
138 return refCount;
140 /**************************************************************************
141 * IExtractIconW_Release
143 static ULONG WINAPI IExtractIconW_fnRelease(IExtractIconW * iface)
145 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
146 ULONG refCount = InterlockedDecrement(&This->ref);
148 TRACE("(%p)->(count=%lu)\n", This, refCount + 1);
150 if (!refCount)
152 TRACE(" destroying IExtractIcon(%p)\n",This);
153 SHFree(This->pidl);
154 HeapFree(GetProcessHeap(),0,This);
155 return 0;
157 return refCount;
160 static HRESULT getIconLocationForFolder(IExtractIconW *iface, UINT uFlags,
161 LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
163 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
164 DWORD dwNr;
165 WCHAR wszPath[MAX_PATH];
166 WCHAR wszCLSIDValue[CHARS_IN_GUID];
167 static const WCHAR shellClassInfo[] = { '.','S','h','e','l','l','C','l','a','s','s','I','n','f','o',0 };
168 static const WCHAR iconFile[] = { 'I','c','o','n','F','i','l','e',0 };
169 static const WCHAR clsid[] = { 'C','L','S','I','D',0 };
170 static const WCHAR clsid2[] = { 'C','L','S','I','D','2',0 };
171 static const WCHAR iconIndex[] = { 'I','c','o','n','I','n','d','e','x',0 };
173 if (SHELL32_GetCustomFolderAttribute(This->pidl, shellClassInfo, iconFile,
174 wszPath, MAX_PATH))
176 WCHAR wszIconIndex[10];
177 SHELL32_GetCustomFolderAttribute(This->pidl, shellClassInfo, iconIndex,
178 wszIconIndex, 10);
179 *piIndex = atoiW(wszIconIndex);
181 else if (SHELL32_GetCustomFolderAttribute(This->pidl, shellClassInfo, clsid,
182 wszCLSIDValue, CHARS_IN_GUID) &&
183 HCR_GetDefaultIconW(wszCLSIDValue, szIconFile, cchMax, &dwNr))
185 *piIndex = dwNr;
187 else if (SHELL32_GetCustomFolderAttribute(This->pidl, shellClassInfo, clsid2,
188 wszCLSIDValue, CHARS_IN_GUID) &&
189 HCR_GetDefaultIconW(wszCLSIDValue, szIconFile, cchMax, &dwNr))
191 *piIndex = dwNr;
193 else
195 static const WCHAR folder[] = { 'F','o','l','d','e','r',0 };
197 if (!HCR_GetDefaultIconW(folder, szIconFile, cchMax, &dwNr))
199 lstrcpynW(szIconFile, swShell32Name, cchMax);
200 dwNr = IDI_SHELL_FOLDER;
202 *piIndex = -((uFlags & GIL_OPENICON) ? dwNr + 1 : dwNr);
204 return S_OK;
207 WCHAR swShell32Name[MAX_PATH];
209 /**************************************************************************
210 * IExtractIconW_GetIconLocation
212 * mapping filetype to icon
214 static HRESULT WINAPI IExtractIconW_fnGetIconLocation(
215 IExtractIconW * iface,
216 UINT uFlags, /* GIL_ flags */
217 LPWSTR szIconFile,
218 UINT cchMax,
219 int * piIndex,
220 UINT * pwFlags) /* returned GIL_ flags */
222 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
224 char sTemp[MAX_PATH];
225 DWORD dwNr;
226 GUID const * riid;
227 LPITEMIDLIST pSimplePidl = ILFindLastID(This->pidl);
229 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
231 if (pwFlags)
232 *pwFlags = 0;
234 if (_ILIsDesktop(pSimplePidl))
236 lstrcpynW(szIconFile, swShell32Name, cchMax);
237 *piIndex = -IDI_SHELL_DESKTOP;
240 /* my computer and other shell extensions */
241 else if ((riid = _ILGetGUIDPointer(pSimplePidl)))
243 static const WCHAR fmt[] = { 'C','L','S','I','D','\\',
244 '{','%','0','8','l','x','-','%','0','4','x','-','%','0','4','x','-',
245 '%','0','2','x','%','0','2','x','-','%','0','2','x', '%','0','2','x',
246 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0 };
247 WCHAR xriid[50];
249 sprintfW(xriid, fmt,
250 riid->Data1, riid->Data2, riid->Data3,
251 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
252 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]);
254 if (HCR_GetDefaultIconW(xriid, szIconFile, cchMax, &dwNr))
256 *piIndex = dwNr;
258 else
260 lstrcpynW(szIconFile, swShell32Name, cchMax);
261 if(IsEqualGUID(riid, &CLSID_MyComputer))
262 *piIndex = -IDI_SHELL_MY_COMPUTER;
263 else if(IsEqualGUID(riid, &CLSID_MyDocuments))
264 *piIndex = -IDI_SHELL_FOLDER;
265 else if(IsEqualGUID(riid, &CLSID_NetworkPlaces))
266 *piIndex = -IDI_SHELL_MY_NETWORK_PLACES;
267 else if(IsEqualGUID(riid, &CLSID_UnixFolder) ||
268 IsEqualGUID(riid, &CLSID_UnixDosFolder))
269 *piIndex = -IDI_SHELL_DRIVE;
270 else
271 *piIndex = -IDI_SHELL_FOLDER;
275 else if (_ILIsDrive (pSimplePidl))
277 static const WCHAR drive[] = { 'D','r','i','v','e',0 };
279 int icon_idx = -1;
281 if (_ILGetDrive(pSimplePidl, sTemp, MAX_PATH))
283 switch(GetDriveTypeA(sTemp))
285 case DRIVE_REMOVABLE: icon_idx = IDI_SHELL_FLOPPY; break;
286 case DRIVE_CDROM: icon_idx = IDI_SHELL_CDROM; break;
287 case DRIVE_REMOTE: icon_idx = IDI_SHELL_NETDRIVE; break;
288 case DRIVE_RAMDISK: icon_idx = IDI_SHELL_RAMDISK; break;
292 if (icon_idx != -1)
294 lstrcpynW(szIconFile, swShell32Name, cchMax);
295 *piIndex = -icon_idx;
297 else
299 if (HCR_GetDefaultIconW(drive, szIconFile, cchMax, &dwNr))
301 *piIndex = dwNr;
303 else
305 lstrcpynW(szIconFile, swShell32Name, cchMax);
306 *piIndex = -IDI_SHELL_DRIVE;
310 else if (_ILIsFolder (pSimplePidl))
312 getIconLocationForFolder(iface, uFlags, szIconFile, cchMax, piIndex,
313 pwFlags);
315 else
317 BOOL found = FALSE;
319 if (_ILIsCPanelStruct(pSimplePidl))
321 if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl, szIconFile, cchMax, piIndex)))
322 found = TRUE;
324 else if (_ILGetExtension(pSimplePidl, sTemp, MAX_PATH))
326 if (HCR_MapTypeToValueA(sTemp, sTemp, MAX_PATH, TRUE)
327 && HCR_GetDefaultIconA(sTemp, sTemp, MAX_PATH, &dwNr))
329 if (!lstrcmpA("%1", sTemp)) /* icon is in the file */
331 SHGetPathFromIDListW(This->pidl, szIconFile);
332 *piIndex = 0;
334 else
336 MultiByteToWideChar(CP_ACP, 0, sTemp, -1, szIconFile, cchMax);
337 *piIndex = dwNr;
340 found = TRUE;
342 else if (!lstrcmpiA(sTemp, "lnkfile"))
344 /* extract icon from shell shortcut */
345 IShellFolder* dsf;
346 IShellLinkW* psl;
348 if (SUCCEEDED(SHGetDesktopFolder(&dsf)))
350 HRESULT hr = IShellFolder_GetUIObjectOf(dsf, NULL, 1, (LPCITEMIDLIST*)&This->pidl, &IID_IShellLinkW, NULL, (LPVOID*)&psl);
352 if (SUCCEEDED(hr))
354 hr = IShellLinkW_GetIconLocation(psl, szIconFile, MAX_PATH, piIndex);
356 if (SUCCEEDED(hr) && *szIconFile)
357 found = TRUE;
359 IShellLinkW_Release(psl);
362 IShellFolder_Release(dsf);
367 if (!found) /* default icon */
369 lstrcpynW(szIconFile, swShell32Name, cchMax);
370 *piIndex = 0;
374 TRACE("-- %s %x\n", debugstr_w(szIconFile), *piIndex);
375 return NOERROR;
378 /**************************************************************************
379 * IExtractIconW_Extract
381 static HRESULT WINAPI IExtractIconW_fnExtract(IExtractIconW * iface, LPCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
383 IExtractIconWImpl *This = (IExtractIconWImpl *)iface;
384 int index;
386 FIXME("(%p) (file=%p index=%d %p %p size=%08x) semi-stub\n", This, debugstr_w(pszFile), (signed)nIconIndex,
387 phiconLarge, phiconSmall, nIconSize);
389 index = SIC_GetIconIndex(pszFile, nIconIndex, 0);
391 if (phiconLarge)
392 *phiconLarge = ImageList_GetIcon(ShellBigIconList, index, ILD_TRANSPARENT);
394 if (phiconSmall)
395 *phiconSmall = ImageList_GetIcon(ShellSmallIconList, index, ILD_TRANSPARENT);
397 return S_OK;
400 static const IExtractIconWVtbl eivt =
402 IExtractIconW_fnQueryInterface,
403 IExtractIconW_fnAddRef,
404 IExtractIconW_fnRelease,
405 IExtractIconW_fnGetIconLocation,
406 IExtractIconW_fnExtract
409 /**************************************************************************
410 * IExtractIconA_Constructor
412 IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
414 IExtractIconWImpl *This = (IExtractIconWImpl *)IExtractIconW_Constructor(pidl);
415 IExtractIconA *eia = (IExtractIconA *)&This->lpvtblExtractIconA;
417 TRACE("(%p)->(%p)\n", This, eia);
418 return eia;
420 /**************************************************************************
421 * IExtractIconA_QueryInterface
423 static HRESULT WINAPI IExtractIconA_fnQueryInterface(IExtractIconA * iface, REFIID riid, LPVOID *ppvObj)
425 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
427 return IExtractIconW_QueryInterface(This, riid, ppvObj);
430 /**************************************************************************
431 * IExtractIconA_AddRef
433 static ULONG WINAPI IExtractIconA_fnAddRef(IExtractIconA * iface)
435 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
437 return IExtractIconW_AddRef(This);
439 /**************************************************************************
440 * IExtractIconA_Release
442 static ULONG WINAPI IExtractIconA_fnRelease(IExtractIconA * iface)
444 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
446 return IExtractIconW_AddRef(This);
448 /**************************************************************************
449 * IExtractIconA_GetIconLocation
451 * mapping filetype to icon
453 static HRESULT WINAPI IExtractIconA_fnGetIconLocation(
454 IExtractIconA * iface,
455 UINT uFlags,
456 LPSTR szIconFile,
457 UINT cchMax,
458 int * piIndex,
459 UINT * pwFlags)
461 HRESULT ret;
462 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, cchMax * sizeof(WCHAR));
463 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
465 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
467 ret = IExtractIconW_GetIconLocation(This, uFlags, lpwstrFile, cchMax, piIndex, pwFlags);
468 WideCharToMultiByte(CP_ACP, 0, lpwstrFile, -1, szIconFile, cchMax, NULL, NULL);
469 HeapFree(GetProcessHeap(), 0, lpwstrFile);
471 TRACE("-- %s %x\n", szIconFile, *piIndex);
472 return ret;
474 /**************************************************************************
475 * IExtractIconA_Extract
477 static HRESULT WINAPI IExtractIconA_fnExtract(IExtractIconA * iface, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
479 HRESULT ret;
480 INT len = MultiByteToWideChar(CP_ACP, 0, pszFile, -1, NULL, 0);
481 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
482 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
484 TRACE("(%p) (file=%p index=%u %p %p size=%u)\n", This, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
486 MultiByteToWideChar(CP_ACP, 0, pszFile, -1, lpwstrFile, len);
487 ret = IExtractIconW_Extract(This, lpwstrFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
488 HeapFree(GetProcessHeap(), 0, lpwstrFile);
489 return ret;
492 static const IExtractIconAVtbl eiavt =
494 IExtractIconA_fnQueryInterface,
495 IExtractIconA_fnAddRef,
496 IExtractIconA_fnRelease,
497 IExtractIconA_fnGetIconLocation,
498 IExtractIconA_fnExtract
501 /************************************************************************
502 * IEIPersistFile_QueryInterface (IUnknown)
504 static HRESULT WINAPI IEIPersistFile_fnQueryInterface(
505 IPersistFile *iface,
506 REFIID iid,
507 LPVOID *ppvObj)
509 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
511 return IExtractIconW_QueryInterface(This, iid, ppvObj);
514 /************************************************************************
515 * IEIPersistFile_AddRef (IUnknown)
517 static ULONG WINAPI IEIPersistFile_fnAddRef(
518 IPersistFile *iface)
520 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
522 return IExtractIconW_AddRef(This);
525 /************************************************************************
526 * IEIPersistFile_Release (IUnknown)
528 static ULONG WINAPI IEIPersistFile_fnRelease(
529 IPersistFile *iface)
531 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
533 return IExtractIconW_Release(This);
536 /************************************************************************
537 * IEIPersistFile_GetClassID (IPersist)
539 static HRESULT WINAPI IEIPersistFile_fnGetClassID(
540 IPersistFile *iface,
541 LPCLSID lpClassId)
543 CLSID StdFolderID = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
545 if (lpClassId==NULL)
546 return E_POINTER;
548 memcpy(lpClassId, &StdFolderID, sizeof(StdFolderID));
550 return S_OK;
553 /************************************************************************
554 * IEIPersistFile_Load (IPersistFile)
556 static HRESULT WINAPI IEIPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
558 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
559 FIXME("%p\n", This);
560 return E_NOTIMPL;
564 static const IPersistFileVtbl pfvt =
566 IEIPersistFile_fnQueryInterface,
567 IEIPersistFile_fnAddRef,
568 IEIPersistFile_fnRelease,
569 IEIPersistFile_fnGetClassID,
570 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
571 IEIPersistFile_fnLoad,
572 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
573 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
574 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */