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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/port.h"
34 #include "undocshell.h"
37 #include "wine/debug.h"
40 #include "shell32_main.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
46 /***********************************************************************
47 * IExtractIconW implementation
51 const IExtractIconWVtbl
*lpVtbl
;
53 const IPersistFileVtbl
*lpvtblPersistFile
;
54 const IExtractIconAVtbl
*lpvtblExtractIconA
;
58 static const IExtractIconAVtbl eiavt
;
59 static const IExtractIconWVtbl eivt
;
60 static const IPersistFileVtbl pfvt
;
62 static inline IExtractIconW
*impl_from_IPersistFile( IPersistFile
*iface
)
64 return (IExtractIconW
*)((char*)iface
- FIELD_OFFSET(IExtractIconWImpl
, lpvtblPersistFile
));
67 static inline IExtractIconW
*impl_from_IExtractIconA( IExtractIconA
*iface
)
69 return (IExtractIconW
*)((char*)iface
- FIELD_OFFSET(IExtractIconWImpl
, lpvtblExtractIconA
));
73 /**************************************************************************
74 * IExtractIconW_Constructor
76 IExtractIconW
* IExtractIconW_Constructor(LPCITEMIDLIST pidl
)
78 IExtractIconWImpl
* ei
;
82 ei
= HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconWImpl
));
85 ei
->lpvtblPersistFile
= &pfvt
;
86 ei
->lpvtblExtractIconA
= &eiavt
;
87 ei
->pidl
=ILClone(pidl
);
92 return (IExtractIconW
*)ei
;
94 /**************************************************************************
95 * IExtractIconW_QueryInterface
97 static HRESULT WINAPI
IExtractIconW_fnQueryInterface(IExtractIconW
*iface
, REFIID riid
, LPVOID
*ppvObj
)
99 IExtractIconWImpl
*This
= (IExtractIconWImpl
*)iface
;
101 TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This
, debugstr_guid(riid
), ppvObj
);
105 if (IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
109 else if (IsEqualIID(riid
, &IID_IPersistFile
)) /*IExtractIcon*/
111 *ppvObj
= &This
->lpvtblPersistFile
;
113 else if (IsEqualIID(riid
, &IID_IExtractIconA
)) /*IExtractIcon*/
115 *ppvObj
= &This
->lpvtblExtractIconA
;
117 else if (IsEqualIID(riid
, &IID_IExtractIconW
)) /*IExtractIcon*/
124 IExtractIconW_AddRef((IExtractIconW
*) *ppvObj
);
125 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
128 TRACE("-- Interface: E_NOINTERFACE\n");
129 return E_NOINTERFACE
;
132 /**************************************************************************
133 * IExtractIconW_AddRef
135 static ULONG WINAPI
IExtractIconW_fnAddRef(IExtractIconW
* iface
)
137 IExtractIconWImpl
*This
= (IExtractIconWImpl
*)iface
;
138 ULONG refCount
= InterlockedIncrement(&This
->ref
);
140 TRACE("(%p)->(count=%u)\n", This
, refCount
- 1);
144 /**************************************************************************
145 * IExtractIconW_Release
147 static ULONG WINAPI
IExtractIconW_fnRelease(IExtractIconW
* iface
)
149 IExtractIconWImpl
*This
= (IExtractIconWImpl
*)iface
;
150 ULONG refCount
= InterlockedDecrement(&This
->ref
);
152 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
156 TRACE(" destroying IExtractIcon(%p)\n",This
);
158 HeapFree(GetProcessHeap(),0,This
);
164 static HRESULT
getIconLocationForFolder(IExtractIconW
*iface
, UINT uFlags
,
165 LPWSTR szIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
167 IExtractIconWImpl
*This
= (IExtractIconWImpl
*)iface
;
169 WCHAR wszPath
[MAX_PATH
];
170 WCHAR wszCLSIDValue
[CHARS_IN_GUID
];
171 static const WCHAR shellClassInfo
[] = { '.','S','h','e','l','l','C','l','a','s','s','I','n','f','o',0 };
172 static const WCHAR iconFile
[] = { 'I','c','o','n','F','i','l','e',0 };
173 static const WCHAR clsid
[] = { 'C','L','S','I','D',0 };
174 static const WCHAR clsid2
[] = { 'C','L','S','I','D','2',0 };
175 static const WCHAR iconIndex
[] = { 'I','c','o','n','I','n','d','e','x',0 };
177 if (SHELL32_GetCustomFolderAttribute(This
->pidl
, shellClassInfo
, iconFile
,
180 WCHAR wszIconIndex
[10];
181 SHELL32_GetCustomFolderAttribute(This
->pidl
, shellClassInfo
, iconIndex
,
183 *piIndex
= atoiW(wszIconIndex
);
185 else if (SHELL32_GetCustomFolderAttribute(This
->pidl
, shellClassInfo
, clsid
,
186 wszCLSIDValue
, CHARS_IN_GUID
) &&
187 HCR_GetDefaultIconW(wszCLSIDValue
, szIconFile
, cchMax
, &icon_idx
))
191 else if (SHELL32_GetCustomFolderAttribute(This
->pidl
, shellClassInfo
, clsid2
,
192 wszCLSIDValue
, CHARS_IN_GUID
) &&
193 HCR_GetDefaultIconW(wszCLSIDValue
, szIconFile
, cchMax
, &icon_idx
))
199 static const WCHAR folder
[] = { 'F','o','l','d','e','r',0 };
201 if (!HCR_GetDefaultIconW(folder
, szIconFile
, cchMax
, &icon_idx
))
203 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
204 icon_idx
= -IDI_SHELL_FOLDER
;
207 if (uFlags
& GIL_OPENICON
)
208 *piIndex
= icon_idx
<0? icon_idx
-1: icon_idx
+1;
216 WCHAR swShell32Name
[MAX_PATH
];
218 /**************************************************************************
219 * IExtractIconW_GetIconLocation
221 * mapping filetype to icon
223 static HRESULT WINAPI
IExtractIconW_fnGetIconLocation(
224 IExtractIconW
* iface
,
225 UINT uFlags
, /* GIL_ flags */
229 UINT
* pwFlags
) /* returned GIL_ flags */
231 IExtractIconWImpl
*This
= (IExtractIconWImpl
*)iface
;
233 char sTemp
[MAX_PATH
];
236 LPITEMIDLIST pSimplePidl
= ILFindLastID(This
->pidl
);
238 TRACE("(%p) (flags=%u %p %u %p %p)\n", This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
243 if (_ILIsDesktop(pSimplePidl
))
245 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
246 *piIndex
= -IDI_SHELL_DESKTOP
;
249 /* my computer and other shell extensions */
250 else if ((riid
= _ILGetGUIDPointer(pSimplePidl
)))
252 static const WCHAR fmt
[] = { 'C','L','S','I','D','\\',
253 '{','%','0','8','l','x','-','%','0','4','x','-','%','0','4','x','-',
254 '%','0','2','x','%','0','2','x','-','%','0','2','x', '%','0','2','x',
255 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0 };
259 riid
->Data1
, riid
->Data2
, riid
->Data3
,
260 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
261 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
263 if (HCR_GetDefaultIconW(xriid
, szIconFile
, cchMax
, &icon_idx
))
269 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
270 if(IsEqualGUID(riid
, &CLSID_MyComputer
))
271 *piIndex
= -IDI_SHELL_MY_COMPUTER
;
272 else if(IsEqualGUID(riid
, &CLSID_MyDocuments
))
273 *piIndex
= -IDI_SHELL_MY_DOCUMENTS
;
274 else if(IsEqualGUID(riid
, &CLSID_NetworkPlaces
))
275 *piIndex
= -IDI_SHELL_MY_NETWORK_PLACES
;
276 else if(IsEqualGUID(riid
, &CLSID_UnixFolder
) ||
277 IsEqualGUID(riid
, &CLSID_UnixDosFolder
))
278 *piIndex
= -IDI_SHELL_DRIVE
;
280 *piIndex
= -IDI_SHELL_FOLDER
;
284 else if (_ILIsDrive (pSimplePidl
))
286 static const WCHAR drive
[] = { 'D','r','i','v','e',0 };
290 if (_ILGetDrive(pSimplePidl
, sTemp
, MAX_PATH
))
292 switch(GetDriveTypeA(sTemp
))
294 case DRIVE_REMOVABLE
: icon_idx
= IDI_SHELL_FLOPPY
; break;
295 case DRIVE_CDROM
: icon_idx
= IDI_SHELL_CDROM
; break;
296 case DRIVE_REMOTE
: icon_idx
= IDI_SHELL_NETDRIVE
; break;
297 case DRIVE_RAMDISK
: icon_idx
= IDI_SHELL_RAMDISK
; break;
303 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
304 *piIndex
= -icon_idx
;
308 if (HCR_GetDefaultIconW(drive
, szIconFile
, cchMax
, &icon_idx
))
314 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
315 *piIndex
= -IDI_SHELL_DRIVE
;
319 else if (_ILIsFolder (pSimplePidl
))
321 getIconLocationForFolder(iface
, uFlags
, szIconFile
, cchMax
, piIndex
,
328 if (_ILIsCPanelStruct(pSimplePidl
))
330 if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl
, szIconFile
, cchMax
, piIndex
)))
333 else if (_ILGetExtension(pSimplePidl
, sTemp
, MAX_PATH
))
335 if (HCR_MapTypeToValueA(sTemp
, sTemp
, MAX_PATH
, TRUE
)
336 && HCR_GetDefaultIconA(sTemp
, sTemp
, MAX_PATH
, &icon_idx
))
338 if (!lstrcmpA("%1", sTemp
)) /* icon is in the file */
340 SHGetPathFromIDListW(This
->pidl
, szIconFile
);
345 MultiByteToWideChar(CP_ACP
, 0, sTemp
, -1, szIconFile
, cchMax
);
351 else if (!lstrcmpiA(sTemp
, "lnkfile"))
353 /* extract icon from shell shortcut */
357 if (SUCCEEDED(SHGetDesktopFolder(&dsf
)))
359 HRESULT hr
= IShellFolder_GetUIObjectOf(dsf
, NULL
, 1, (LPCITEMIDLIST
*)&This
->pidl
, &IID_IShellLinkW
, NULL
, (LPVOID
*)&psl
);
363 hr
= IShellLinkW_GetIconLocation(psl
, szIconFile
, MAX_PATH
, piIndex
);
365 if (SUCCEEDED(hr
) && *szIconFile
)
368 IShellLinkW_Release(psl
);
371 IShellFolder_Release(dsf
);
376 if (!found
) /* default icon */
378 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
383 TRACE("-- %s %x\n", debugstr_w(szIconFile
), *piIndex
);
387 /**************************************************************************
388 * IExtractIconW_Extract
390 static HRESULT WINAPI
IExtractIconW_fnExtract(IExtractIconW
* iface
, LPCWSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
392 IExtractIconWImpl
*This
= (IExtractIconWImpl
*)iface
;
395 FIXME("(%p) (file=%p index=%d %p %p size=%08x) semi-stub\n", This
, debugstr_w(pszFile
), (signed)nIconIndex
,
396 phiconLarge
, phiconSmall
, nIconSize
);
398 index
= SIC_GetIconIndex(pszFile
, nIconIndex
, 0);
401 *phiconLarge
= ImageList_GetIcon(ShellBigIconList
, index
, ILD_TRANSPARENT
);
404 *phiconSmall
= ImageList_GetIcon(ShellSmallIconList
, index
, ILD_TRANSPARENT
);
409 static const IExtractIconWVtbl eivt
=
411 IExtractIconW_fnQueryInterface
,
412 IExtractIconW_fnAddRef
,
413 IExtractIconW_fnRelease
,
414 IExtractIconW_fnGetIconLocation
,
415 IExtractIconW_fnExtract
418 /**************************************************************************
419 * IExtractIconA_Constructor
421 IExtractIconA
* IExtractIconA_Constructor(LPCITEMIDLIST pidl
)
423 IExtractIconWImpl
*This
= (IExtractIconWImpl
*)IExtractIconW_Constructor(pidl
);
424 IExtractIconA
*eia
= (IExtractIconA
*)&This
->lpvtblExtractIconA
;
426 TRACE("(%p)->(%p)\n", This
, eia
);
429 /**************************************************************************
430 * IExtractIconA_QueryInterface
432 static HRESULT WINAPI
IExtractIconA_fnQueryInterface(IExtractIconA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
434 IExtractIconW
*This
= impl_from_IExtractIconA(iface
);
436 return IExtractIconW_QueryInterface(This
, riid
, ppvObj
);
439 /**************************************************************************
440 * IExtractIconA_AddRef
442 static ULONG WINAPI
IExtractIconA_fnAddRef(IExtractIconA
* iface
)
444 IExtractIconW
*This
= impl_from_IExtractIconA(iface
);
446 return IExtractIconW_AddRef(This
);
448 /**************************************************************************
449 * IExtractIconA_Release
451 static ULONG WINAPI
IExtractIconA_fnRelease(IExtractIconA
* iface
)
453 IExtractIconW
*This
= impl_from_IExtractIconA(iface
);
455 return IExtractIconW_AddRef(This
);
457 /**************************************************************************
458 * IExtractIconA_GetIconLocation
460 * mapping filetype to icon
462 static HRESULT WINAPI
IExtractIconA_fnGetIconLocation(
463 IExtractIconA
* iface
,
471 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, cchMax
* sizeof(WCHAR
));
472 IExtractIconW
*This
= impl_from_IExtractIconA(iface
);
474 TRACE("(%p) (flags=%u %p %u %p %p)\n", This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
476 ret
= IExtractIconW_GetIconLocation(This
, uFlags
, lpwstrFile
, cchMax
, piIndex
, pwFlags
);
477 WideCharToMultiByte(CP_ACP
, 0, lpwstrFile
, -1, szIconFile
, cchMax
, NULL
, NULL
);
478 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
480 TRACE("-- %s %x\n", szIconFile
, *piIndex
);
483 /**************************************************************************
484 * IExtractIconA_Extract
486 static HRESULT WINAPI
IExtractIconA_fnExtract(IExtractIconA
* iface
, LPCSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
489 INT len
= MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, NULL
, 0);
490 LPWSTR lpwstrFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
491 IExtractIconW
*This
= impl_from_IExtractIconA(iface
);
493 TRACE("(%p) (file=%p index=%u %p %p size=%u)\n", This
, pszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
495 MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, lpwstrFile
, len
);
496 ret
= IExtractIconW_Extract(This
, lpwstrFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
497 HeapFree(GetProcessHeap(), 0, lpwstrFile
);
501 static const IExtractIconAVtbl eiavt
=
503 IExtractIconA_fnQueryInterface
,
504 IExtractIconA_fnAddRef
,
505 IExtractIconA_fnRelease
,
506 IExtractIconA_fnGetIconLocation
,
507 IExtractIconA_fnExtract
510 /************************************************************************
511 * IEIPersistFile_QueryInterface (IUnknown)
513 static HRESULT WINAPI
IEIPersistFile_fnQueryInterface(
518 IExtractIconW
*This
= impl_from_IPersistFile(iface
);
520 return IExtractIconW_QueryInterface(This
, iid
, ppvObj
);
523 /************************************************************************
524 * IEIPersistFile_AddRef (IUnknown)
526 static ULONG WINAPI
IEIPersistFile_fnAddRef(
529 IExtractIconW
*This
= impl_from_IPersistFile(iface
);
531 return IExtractIconW_AddRef(This
);
534 /************************************************************************
535 * IEIPersistFile_Release (IUnknown)
537 static ULONG WINAPI
IEIPersistFile_fnRelease(
540 IExtractIconW
*This
= impl_from_IPersistFile(iface
);
542 return IExtractIconW_Release(This
);
545 /************************************************************************
546 * IEIPersistFile_GetClassID (IPersist)
548 static HRESULT WINAPI
IEIPersistFile_fnGetClassID(
552 CLSID StdFolderID
= { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
557 *lpClassId
= StdFolderID
;
562 /************************************************************************
563 * IEIPersistFile_Load (IPersistFile)
565 static HRESULT WINAPI
IEIPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
567 IExtractIconW
*This
= impl_from_IPersistFile(iface
);
573 static const IPersistFileVtbl pfvt
=
575 IEIPersistFile_fnQueryInterface
,
576 IEIPersistFile_fnAddRef
,
577 IEIPersistFile_fnRelease
,
578 IEIPersistFile_fnGetClassID
,
579 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
580 IEIPersistFile_fnLoad
,
581 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
582 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
583 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */