Get rid of the no longer used ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
[wine/multimedia.git] / dlls / shell32 / folders.c
blob84e4eebed79f5f2ba5258c441fada7d43f41d113
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 #include "windef.h"
29 #include "winbase.h"
30 #include "objbase.h"
31 #include "undocshell.h"
32 #include "shlguid.h"
33 #include "winreg.h"
34 #include "shlwapi.h"
36 #include "wine/debug.h"
37 #include "winerror.h"
39 #include "pidl.h"
40 #include "shell32_main.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(shell);
44 /***********************************************************************
45 * IExtractIconW implementation
47 typedef struct
49 IExtractIconWVtbl *lpVtbl;
50 DWORD ref;
51 IPersistFileVtbl *lpvtblPersistFile;
52 IExtractIconAVtbl *lpvtblExtractIconA;
53 LPITEMIDLIST pidl;
54 } IExtractIconWImpl;
56 static struct IExtractIconAVtbl eiavt;
57 static struct IExtractIconWVtbl eivt;
58 static struct IPersistFileVtbl pfvt;
60 #define _IPersistFile_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblPersistFile)))
61 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
63 #define _IExtractIconA_Offset ((int)(&(((IExtractIconWImpl*)0)->lpvtblExtractIconA)))
64 #define _ICOM_THIS_From_IExtractIconA(class, name) class* This = (class*)(((char*)name)-_IExtractIconA_Offset);
66 /**************************************************************************
67 * IExtractIconW_Constructor
69 IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl)
71 IExtractIconWImpl* ei;
73 TRACE("%p\n", pidl);
75 ei = (IExtractIconWImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconWImpl));
76 ei->ref=1;
77 ei->lpVtbl = &eivt;
78 ei->lpvtblPersistFile = &pfvt;
79 ei->lpvtblExtractIconA = &eiavt;
80 ei->pidl=ILClone(pidl);
82 pdump(pidl);
84 TRACE("(%p)\n", ei);
85 return (IExtractIconW *)ei;
87 /**************************************************************************
88 * IExtractIconW_QueryInterface
90 static HRESULT WINAPI IExtractIconW_fnQueryInterface(IExtractIconW *iface, REFIID riid, LPVOID *ppvObj)
92 ICOM_THIS(IExtractIconWImpl, iface);
94 TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This, debugstr_guid(riid), ppvObj);
96 *ppvObj = NULL;
98 if (IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
100 *ppvObj = This;
102 else if (IsEqualIID(riid, &IID_IPersistFile)) /*IExtractIcon*/
104 *ppvObj = (IPersistFile*)&(This->lpvtblPersistFile);
106 else if (IsEqualIID(riid, &IID_IExtractIconA)) /*IExtractIcon*/
108 *ppvObj = (IExtractIconA*)&(This->lpvtblExtractIconA);
110 else if (IsEqualIID(riid, &IID_IExtractIconW)) /*IExtractIcon*/
112 *ppvObj = (IExtractIconW*)This;
115 if(*ppvObj)
117 IExtractIconW_AddRef((IExtractIconW*) *ppvObj);
118 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
119 return S_OK;
121 TRACE("-- Interface: E_NOINTERFACE\n");
122 return E_NOINTERFACE;
125 /**************************************************************************
126 * IExtractIconW_AddRef
128 static ULONG WINAPI IExtractIconW_fnAddRef(IExtractIconW * iface)
130 ICOM_THIS(IExtractIconWImpl, iface);
132 TRACE("(%p)->(count=%lu)\n",This, This->ref );
134 return ++(This->ref);
136 /**************************************************************************
137 * IExtractIconW_Release
139 static ULONG WINAPI IExtractIconW_fnRelease(IExtractIconW * iface)
141 ICOM_THIS(IExtractIconWImpl, iface);
143 TRACE("(%p)->()\n",This);
145 if (!--(This->ref))
147 TRACE(" destroying IExtractIcon(%p)\n",This);
148 SHFree(This->pidl);
149 HeapFree(GetProcessHeap(),0,This);
150 return 0;
152 return This->ref;
155 static HRESULT getIconLocationForFolder(IExtractIconW *iface, UINT uFlags,
156 LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
158 ICOM_THIS(IExtractIconWImpl, iface);
160 WCHAR path[MAX_PATH];
161 BOOL found = FALSE;
162 DWORD dwNr;
164 if (SUCCEEDED(SHGetPathFromIDListW(This->pidl, path)))
166 static const WCHAR desktopIni[] = { 'D','e','s','k','t','o','p','.',
167 'i','n','i',0 };
168 HANDLE hFile;
170 PathAppendW(path, desktopIni);
171 if ((hFile = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL,
172 OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE)
174 static const WCHAR shellClassInfo[] = { '.','S','h','e','l','l',
175 'C','l','a','s','s','I','n','f','o',0 };
176 static const WCHAR iconFile[] =
177 { 'I','c','o','n','F','i','l','e',0 };
178 static const WCHAR clsid[] = { 'C','L','S','I','D',0 };
179 static const WCHAR clsid2[] = { 'C','L','S','I','D','2',0 };
180 static const WCHAR defStr[] = { 0 };
181 WCHAR clsidStr[39];
183 CloseHandle(hFile);
184 if (GetPrivateProfileStringW(shellClassInfo, iconFile, defStr,
185 szIconFile, cchMax, path) && strlenW(szIconFile))
187 static const WCHAR iconIndex[] = { 'I','c','o','n',
188 'I','n','d','e','x',0 };
190 found = TRUE;
191 *piIndex = (int)GetPrivateProfileIntW(shellClassInfo, iconIndex,
192 0, path);
194 else if (GetPrivateProfileStringW(shellClassInfo, clsid, defStr,
195 clsidStr, sizeof(clsidStr) / sizeof(WCHAR), path) &&
196 strlenW(clsidStr))
198 if (HCR_GetDefaultIconW(clsidStr, szIconFile, cchMax, &dwNr))
200 *piIndex = dwNr;
201 found = TRUE;
204 else if (GetPrivateProfileStringW(shellClassInfo, clsid2, defStr,
205 clsidStr, sizeof(clsidStr) / sizeof(WCHAR), path) &&
206 strlenW(clsidStr))
208 if (HCR_GetDefaultIconW(clsidStr, szIconFile, cchMax, &dwNr))
210 *piIndex = dwNr;
211 found = TRUE;
216 if (!found)
218 static const WCHAR folder[] = { 'F','o','l','d','e','r',0 };
220 if (!HCR_GetDefaultIconW(folder, szIconFile, cchMax, &dwNr))
222 lstrcpynW(szIconFile, swShell32Name, cchMax);
223 dwNr = 3;
225 *piIndex = (uFlags & GIL_OPENICON) ? dwNr + 1 : dwNr;
227 return S_OK;
230 WCHAR swShell32Name[MAX_PATH];
232 /**************************************************************************
233 * IExtractIconW_GetIconLocation
235 * mapping filetype to icon
237 static HRESULT WINAPI IExtractIconW_fnGetIconLocation(
238 IExtractIconW * iface,
239 UINT uFlags, /* GIL_ flags */
240 LPWSTR szIconFile,
241 UINT cchMax,
242 int * piIndex,
243 UINT * pwFlags) /* returned GIL_ flags */
245 ICOM_THIS(IExtractIconWImpl, iface);
247 char sTemp[MAX_PATH];
248 DWORD dwNr;
249 GUID const * riid;
250 LPITEMIDLIST pSimplePidl = ILFindLastID(This->pidl);
252 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
254 if (pwFlags)
255 *pwFlags = 0;
257 if (_ILIsDesktop(pSimplePidl))
259 lstrcpynW(szIconFile, swShell32Name, cchMax);
260 *piIndex = 34;
263 /* my computer and other shell extensions */
264 else if ((riid = _ILGetGUIDPointer(pSimplePidl)))
266 static const WCHAR fmt[] = { 'C','L','S','I','D','\\',
267 '{','%','0','8','l','x','-','%','0','4','x','-','%','0','4','x','-',
268 '%','0','2','x','%','0','2','x','-','%','0','2','x', '%','0','2','x',
269 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0 };
270 WCHAR xriid[50];
272 sprintfW(xriid, fmt,
273 riid->Data1, riid->Data2, riid->Data3,
274 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
275 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]);
277 if (HCR_GetDefaultIconW(xriid, szIconFile, cchMax, &dwNr))
279 *piIndex = dwNr;
281 else
283 lstrcpynW(szIconFile, swShell32Name, cchMax);
284 *piIndex = 15;
288 else if (_ILIsDrive (pSimplePidl))
290 static const WCHAR drive[] = { 'D','r','i','v','e',0 };
292 if (HCR_GetDefaultIconW(drive, szIconFile, cchMax, &dwNr))
294 *piIndex = dwNr;
296 else
298 lstrcpynW(szIconFile, swShell32Name, cchMax);
299 *piIndex = 8;
302 else if (_ILIsFolder (pSimplePidl))
304 getIconLocationForFolder(iface, uFlags, szIconFile, cchMax, piIndex,
305 pwFlags);
307 else
309 BOOL found = FALSE;
311 if (_ILIsCPanelStruct(pSimplePidl))
313 if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl, szIconFile, cchMax, piIndex)))
314 found = TRUE;
316 else if (_ILGetExtension(pSimplePidl, sTemp, MAX_PATH))
318 if (HCR_MapTypeToValueA(sTemp, sTemp, MAX_PATH, TRUE)
319 && HCR_GetDefaultIconA(sTemp, sTemp, MAX_PATH, &dwNr))
321 if (!lstrcmpA("%1", sTemp)) /* icon is in the file */
323 SHGetPathFromIDListW(This->pidl, szIconFile);
324 *piIndex = 0;
326 else
328 MultiByteToWideChar(CP_ACP, 0, sTemp, -1, szIconFile, cchMax);
329 *piIndex = dwNr;
332 found = TRUE;
334 else if (!strcasecmp(sTemp, "lnkfile"))
336 /* extract icon from shell shortcut */
337 IShellFolder* dsf;
338 IShellLinkW* psl;
340 if (SUCCEEDED(SHGetDesktopFolder(&dsf)))
342 HRESULT hr = IShellFolder_GetUIObjectOf(dsf, NULL, 1, (LPCITEMIDLIST*)&This->pidl, &IID_IShellLinkW, NULL, (LPVOID*)&psl);
344 if (SUCCEEDED(hr))
346 hr = IShellLinkW_GetIconLocation(psl, szIconFile, MAX_PATH, piIndex);
348 if (SUCCEEDED(hr) && *szIconFile)
349 found = TRUE;
351 IShellLinkW_Release(psl);
354 IShellFolder_Release(dsf);
359 if (!found) /* default icon */
361 lstrcpynW(szIconFile, swShell32Name, cchMax);
362 *piIndex = 0;
366 TRACE("-- %s %x\n", debugstr_w(szIconFile), *piIndex);
367 return NOERROR;
370 /**************************************************************************
371 * IExtractIconW_Extract
373 static HRESULT WINAPI IExtractIconW_fnExtract(IExtractIconW * iface, LPCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
375 ICOM_THIS(IExtractIconWImpl, iface);
377 FIXME("(%p) (file=%p index=%u %p %p size=%u) semi-stub\n", This, debugstr_w(pszFile), nIconIndex, phiconLarge, phiconSmall, nIconSize);
379 if (phiconLarge)
380 *phiconLarge = ImageList_GetIcon(ShellBigIconList, nIconIndex, ILD_TRANSPARENT);
382 if (phiconSmall)
383 *phiconSmall = ImageList_GetIcon(ShellSmallIconList, nIconIndex, ILD_TRANSPARENT);
385 return S_OK;
388 static struct IExtractIconWVtbl eivt =
390 IExtractIconW_fnQueryInterface,
391 IExtractIconW_fnAddRef,
392 IExtractIconW_fnRelease,
393 IExtractIconW_fnGetIconLocation,
394 IExtractIconW_fnExtract
397 /**************************************************************************
398 * IExtractIconA_Constructor
400 IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
402 ICOM_THIS(IExtractIconWImpl, IExtractIconW_Constructor(pidl));
403 IExtractIconA *eia = (IExtractIconA *)&This->lpvtblExtractIconA;
405 TRACE("(%p)->(%p)\n", This, eia);
406 return eia;
408 /**************************************************************************
409 * IExtractIconA_QueryInterface
411 static HRESULT WINAPI IExtractIconA_fnQueryInterface(IExtractIconA * iface, REFIID riid, LPVOID *ppvObj)
413 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
415 return IExtractIconW_QueryInterface(This, riid, ppvObj);
418 /**************************************************************************
419 * IExtractIconA_AddRef
421 static ULONG WINAPI IExtractIconA_fnAddRef(IExtractIconA * iface)
423 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
425 return IExtractIconW_AddRef(This);
427 /**************************************************************************
428 * IExtractIconA_Release
430 static ULONG WINAPI IExtractIconA_fnRelease(IExtractIconA * iface)
432 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
434 return IExtractIconW_AddRef(This);
436 /**************************************************************************
437 * IExtractIconA_GetIconLocation
439 * mapping filetype to icon
441 static HRESULT WINAPI IExtractIconA_fnGetIconLocation(
442 IExtractIconA * iface,
443 UINT uFlags,
444 LPSTR szIconFile,
445 UINT cchMax,
446 int * piIndex,
447 UINT * pwFlags)
449 HRESULT ret;
450 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, cchMax * sizeof(WCHAR));
451 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
453 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
455 ret = IExtractIconW_GetIconLocation(This, uFlags, lpwstrFile, cchMax, piIndex, pwFlags);
456 WideCharToMultiByte(CP_ACP, 0, lpwstrFile, -1, szIconFile, cchMax, NULL, NULL);
457 HeapFree(GetProcessHeap(), 0, lpwstrFile);
459 TRACE("-- %s %x\n", szIconFile, *piIndex);
460 return ret;
462 /**************************************************************************
463 * IExtractIconA_Extract
465 static HRESULT WINAPI IExtractIconA_fnExtract(IExtractIconA * iface, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
467 HRESULT ret;
468 INT len = MultiByteToWideChar(CP_ACP, 0, pszFile, -1, NULL, 0);
469 LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
470 _ICOM_THIS_From_IExtractIconA(IExtractIconW, iface);
472 TRACE("(%p) (file=%p index=%u %p %p size=%u)\n", This, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
474 MultiByteToWideChar(CP_ACP, 0, pszFile, -1, lpwstrFile, len);
475 ret = IExtractIconW_Extract(This, lpwstrFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
476 HeapFree(GetProcessHeap(), 0, lpwstrFile);
477 return ret;
480 static struct IExtractIconAVtbl eiavt =
482 IExtractIconA_fnQueryInterface,
483 IExtractIconA_fnAddRef,
484 IExtractIconA_fnRelease,
485 IExtractIconA_fnGetIconLocation,
486 IExtractIconA_fnExtract
489 /************************************************************************
490 * IEIPersistFile_QueryInterface (IUnknown)
492 static HRESULT WINAPI IEIPersistFile_fnQueryInterface(
493 IPersistFile *iface,
494 REFIID iid,
495 LPVOID *ppvObj)
497 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
499 return IExtractIconW_QueryInterface(This, iid, ppvObj);
502 /************************************************************************
503 * IEIPersistFile_AddRef (IUnknown)
505 static ULONG WINAPI IEIPersistFile_fnAddRef(
506 IPersistFile *iface)
508 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
510 return IExtractIconW_AddRef(This);
513 /************************************************************************
514 * IEIPersistFile_Release (IUnknown)
516 static ULONG WINAPI IEIPersistFile_fnRelease(
517 IPersistFile *iface)
519 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
521 return IExtractIconW_Release(This);
524 /************************************************************************
525 * IEIPersistFile_GetClassID (IPersist)
527 static HRESULT WINAPI IEIPersistFile_fnGetClassID(
528 IPersistFile *iface,
529 LPCLSID lpClassId)
531 CLSID StdFolderID = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
533 if (lpClassId==NULL)
534 return E_POINTER;
536 memcpy(lpClassId, &StdFolderID, sizeof(StdFolderID));
538 return S_OK;
541 /************************************************************************
542 * IEIPersistFile_Load (IPersistFile)
544 static HRESULT WINAPI IEIPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
546 _ICOM_THIS_From_IPersistFile(IExtractIconW, iface);
547 FIXME("%p\n", This);
548 return E_NOTIMPL;
552 static struct IPersistFileVtbl pfvt =
554 IEIPersistFile_fnQueryInterface,
555 IEIPersistFile_fnAddRef,
556 IEIPersistFile_fnRelease,
557 IEIPersistFile_fnGetClassID,
558 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
559 IEIPersistFile_fnLoad,
560 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
561 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
562 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */