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 IExtractIconW IExtractIconW_iface
;
52 IExtractIconA IExtractIconA_iface
;
53 IPersistFile IPersistFile_iface
;
58 static inline IExtractIconWImpl
*impl_from_IExtractIconW(IExtractIconW
*iface
)
60 return CONTAINING_RECORD(iface
, IExtractIconWImpl
, IExtractIconW_iface
);
63 static inline IExtractIconWImpl
*impl_from_IExtractIconA(IExtractIconA
*iface
)
65 return CONTAINING_RECORD(iface
, IExtractIconWImpl
, IExtractIconA_iface
);
68 static inline IExtractIconWImpl
*impl_from_IPersistFile(IPersistFile
*iface
)
70 return CONTAINING_RECORD(iface
, IExtractIconWImpl
, IPersistFile_iface
);
74 /**************************************************************************
75 * IExtractIconW::QueryInterface
77 static HRESULT WINAPI
IExtractIconW_fnQueryInterface(IExtractIconW
*iface
, REFIID riid
,
80 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
82 TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This
, debugstr_guid(riid
), ppv
);
85 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IExtractIconW
))
87 else if (IsEqualIID(riid
, &IID_IPersistFile
))
88 *ppv
= &This
->IPersistFile_iface
;
89 else if (IsEqualIID(riid
, &IID_IExtractIconA
))
90 *ppv
= &This
->IExtractIconA_iface
;
94 IUnknown_AddRef((IUnknown
*)*ppv
);
95 TRACE("-- Interface: (%p)->(%p)\n", ppv
, *ppv
);
98 TRACE("-- Interface: E_NOINTERFACE\n");
102 /**************************************************************************
103 * IExtractIconW::AddRef
105 static ULONG WINAPI
IExtractIconW_fnAddRef(IExtractIconW
* iface
)
107 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
108 ULONG refCount
= InterlockedIncrement(&This
->ref
);
110 TRACE("(%p)->(count=%u)\n", This
, refCount
- 1);
114 /**************************************************************************
115 * IExtractIconW::Release
117 static ULONG WINAPI
IExtractIconW_fnRelease(IExtractIconW
* iface
)
119 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
120 ULONG refCount
= InterlockedDecrement(&This
->ref
);
122 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
126 TRACE(" destroying IExtractIcon(%p)\n",This
);
133 static HRESULT
getIconLocationForFolder(IExtractIconWImpl
*This
, UINT uFlags
, LPWSTR szIconFile
,
134 UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
137 WCHAR wszPath
[MAX_PATH
];
138 WCHAR wszCLSIDValue
[CHARS_IN_GUID
];
139 static const WCHAR shellClassInfo
[] = { '.','S','h','e','l','l','C','l','a','s','s','I','n','f','o',0 };
140 static const WCHAR iconFile
[] = { 'I','c','o','n','F','i','l','e',0 };
141 static const WCHAR clsid
[] = { 'C','L','S','I','D',0 };
142 static const WCHAR clsid2
[] = { 'C','L','S','I','D','2',0 };
143 static const WCHAR iconIndex
[] = { 'I','c','o','n','I','n','d','e','x',0 };
145 if (SHELL32_GetCustomFolderAttribute(This
->pidl
, shellClassInfo
, iconFile
,
148 WCHAR wszIconIndex
[10];
149 SHELL32_GetCustomFolderAttribute(This
->pidl
, shellClassInfo
, iconIndex
,
151 *piIndex
= atoiW(wszIconIndex
);
153 else if (SHELL32_GetCustomFolderAttribute(This
->pidl
, shellClassInfo
, clsid
,
154 wszCLSIDValue
, CHARS_IN_GUID
) &&
155 HCR_GetDefaultIconW(wszCLSIDValue
, szIconFile
, cchMax
, &icon_idx
))
159 else if (SHELL32_GetCustomFolderAttribute(This
->pidl
, shellClassInfo
, clsid2
,
160 wszCLSIDValue
, CHARS_IN_GUID
) &&
161 HCR_GetDefaultIconW(wszCLSIDValue
, szIconFile
, cchMax
, &icon_idx
))
167 static const WCHAR folder
[] = { 'F','o','l','d','e','r',0 };
169 if (!HCR_GetDefaultIconW(folder
, szIconFile
, cchMax
, &icon_idx
))
171 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
172 icon_idx
= -IDI_SHELL_FOLDER
;
175 if (uFlags
& GIL_OPENICON
)
176 *piIndex
= icon_idx
<0? icon_idx
-1: icon_idx
+1;
184 WCHAR swShell32Name
[MAX_PATH
];
186 /**************************************************************************
187 * IExtractIconW::GetIconLocation
189 * mapping filetype to icon
191 static HRESULT WINAPI
IExtractIconW_fnGetIconLocation(IExtractIconW
* iface
, UINT uFlags
,
192 LPWSTR szIconFile
, UINT cchMax
, int * piIndex
, UINT
* pwFlags
)
194 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
195 char sTemp
[MAX_PATH
];
198 LPITEMIDLIST pSimplePidl
= ILFindLastID(This
->pidl
);
200 TRACE("(%p) (flags=%u, %p, %u, %p, %p)\n", This
, uFlags
, szIconFile
,
201 cchMax
, piIndex
, pwFlags
);
206 if (_ILIsDesktop(pSimplePidl
))
208 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
209 *piIndex
= -IDI_SHELL_DESKTOP
;
212 /* my computer and other shell extensions */
213 else if ((riid
= _ILGetGUIDPointer(pSimplePidl
)))
215 static const WCHAR fmt
[] = { 'C','L','S','I','D','\\',
216 '{','%','0','8','l','x','-','%','0','4','x','-','%','0','4','x','-',
217 '%','0','2','x','%','0','2','x','-','%','0','2','x', '%','0','2','x',
218 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','}',0 };
222 riid
->Data1
, riid
->Data2
, riid
->Data3
,
223 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
224 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
226 if (HCR_GetDefaultIconW(xriid
, szIconFile
, cchMax
, &icon_idx
))
232 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
233 if(IsEqualGUID(riid
, &CLSID_MyComputer
))
234 *piIndex
= -IDI_SHELL_MY_COMPUTER
;
235 else if(IsEqualGUID(riid
, &CLSID_MyDocuments
))
236 *piIndex
= -IDI_SHELL_MY_DOCUMENTS
;
237 else if(IsEqualGUID(riid
, &CLSID_NetworkPlaces
))
238 *piIndex
= -IDI_SHELL_MY_NETWORK_PLACES
;
239 else if(IsEqualGUID(riid
, &CLSID_UnixFolder
) ||
240 IsEqualGUID(riid
, &CLSID_UnixDosFolder
))
241 *piIndex
= -IDI_SHELL_DRIVE
;
243 *piIndex
= -IDI_SHELL_FOLDER
;
247 else if (_ILIsDrive (pSimplePidl
))
249 static const WCHAR drive
[] = { 'D','r','i','v','e',0 };
253 if (_ILGetDrive(pSimplePidl
, sTemp
, MAX_PATH
))
255 switch(GetDriveTypeA(sTemp
))
257 case DRIVE_REMOVABLE
: icon_idx
= IDI_SHELL_FLOPPY
; break;
258 case DRIVE_CDROM
: icon_idx
= IDI_SHELL_CDROM
; break;
259 case DRIVE_REMOTE
: icon_idx
= IDI_SHELL_NETDRIVE
; break;
260 case DRIVE_RAMDISK
: icon_idx
= IDI_SHELL_RAMDISK
; break;
266 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
267 *piIndex
= -icon_idx
;
271 if (HCR_GetDefaultIconW(drive
, szIconFile
, cchMax
, &icon_idx
))
277 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
278 *piIndex
= -IDI_SHELL_DRIVE
;
282 else if (_ILIsFolder (pSimplePidl
))
284 getIconLocationForFolder(This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
290 if (_ILIsCPanelStruct(pSimplePidl
))
292 if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl
, szIconFile
, cchMax
, piIndex
)))
295 else if (_ILGetExtension(pSimplePidl
, sTemp
, MAX_PATH
))
297 if (HCR_MapTypeToValueA(sTemp
, sTemp
, MAX_PATH
, TRUE
)
298 && HCR_GetDefaultIconA(sTemp
, sTemp
, MAX_PATH
, &icon_idx
))
300 if (!lstrcmpA("%1", sTemp
)) /* icon is in the file */
302 SHGetPathFromIDListW(This
->pidl
, szIconFile
);
307 MultiByteToWideChar(CP_ACP
, 0, sTemp
, -1, szIconFile
, cchMax
);
313 else if (!lstrcmpiA(sTemp
, "lnkfile"))
315 /* extract icon from shell shortcut */
319 if (SUCCEEDED(SHGetDesktopFolder(&dsf
)))
321 HRESULT hr
= IShellFolder_GetUIObjectOf(dsf
, NULL
, 1, (LPCITEMIDLIST
*)&This
->pidl
, &IID_IShellLinkW
, NULL
, (LPVOID
*)&psl
);
325 hr
= IShellLinkW_GetIconLocation(psl
, szIconFile
, cchMax
, piIndex
);
327 if (SUCCEEDED(hr
) && *szIconFile
)
330 IShellLinkW_Release(psl
);
333 IShellFolder_Release(dsf
);
338 if (!found
) /* default icon */
340 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
345 TRACE("-- %s %x\n", debugstr_w(szIconFile
), *piIndex
);
349 /**************************************************************************
350 * IExtractIconW::Extract
352 static HRESULT WINAPI
IExtractIconW_fnExtract(IExtractIconW
* iface
, LPCWSTR pszFile
,
353 UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
355 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
357 HIMAGELIST big_icons
, small_icons
;
359 FIXME("(%p) (file=%s index=%d %p %p size=%08x) semi-stub\n", This
, debugstr_w(pszFile
),
360 (signed)nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
362 index
= SIC_GetIconIndex(pszFile
, nIconIndex
, 0);
363 Shell_GetImageLists( &big_icons
, &small_icons
);
365 *phiconLarge
= ImageList_GetIcon(big_icons
, index
, ILD_TRANSPARENT
);
368 *phiconSmall
= ImageList_GetIcon(small_icons
, index
, ILD_TRANSPARENT
);
373 static const IExtractIconWVtbl eivt
=
375 IExtractIconW_fnQueryInterface
,
376 IExtractIconW_fnAddRef
,
377 IExtractIconW_fnRelease
,
378 IExtractIconW_fnGetIconLocation
,
379 IExtractIconW_fnExtract
382 /**************************************************************************
383 * IExtractIconA::QueryInterface
385 static HRESULT WINAPI
IExtractIconA_fnQueryInterface(IExtractIconA
* iface
, REFIID riid
,
388 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
390 return IExtractIconW_QueryInterface(&This
->IExtractIconW_iface
, riid
, ppv
);
393 /**************************************************************************
394 * IExtractIconA::AddRef
396 static ULONG WINAPI
IExtractIconA_fnAddRef(IExtractIconA
* iface
)
398 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
400 return IExtractIconW_AddRef(&This
->IExtractIconW_iface
);
402 /**************************************************************************
403 * IExtractIconA::Release
405 static ULONG WINAPI
IExtractIconA_fnRelease(IExtractIconA
* iface
)
407 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
409 return IExtractIconW_Release(&This
->IExtractIconW_iface
);
411 /**************************************************************************
412 * IExtractIconA::GetIconLocation
414 * mapping filetype to icon
416 static HRESULT WINAPI
IExtractIconA_fnGetIconLocation(IExtractIconA
* iface
, UINT uFlags
,
417 LPSTR szIconFile
, UINT cchMax
, int * piIndex
, UINT
* pwFlags
)
419 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
421 LPWSTR lpwstrFile
= heap_alloc(cchMax
* sizeof(WCHAR
));
423 TRACE("(%p) (flags=%u %p %u %p %p)\n", This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
425 ret
= IExtractIconW_GetIconLocation(&This
->IExtractIconW_iface
, uFlags
, lpwstrFile
, cchMax
,
427 WideCharToMultiByte(CP_ACP
, 0, lpwstrFile
, -1, szIconFile
, cchMax
, NULL
, NULL
);
428 heap_free(lpwstrFile
);
430 TRACE("-- %s %x\n", szIconFile
, *piIndex
);
433 /**************************************************************************
434 * IExtractIconA::Extract
436 static HRESULT WINAPI
IExtractIconA_fnExtract(IExtractIconA
* iface
, LPCSTR pszFile
,
437 UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
439 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
441 INT len
= MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, NULL
, 0);
442 LPWSTR lpwstrFile
= heap_alloc(len
* sizeof(WCHAR
));
444 TRACE("(%p) (file=%p index=%u %p %p size=%u)\n", This
, pszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
446 MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, lpwstrFile
, len
);
447 ret
= IExtractIconW_Extract(&This
->IExtractIconW_iface
, lpwstrFile
, nIconIndex
, phiconLarge
,
448 phiconSmall
, nIconSize
);
449 heap_free(lpwstrFile
);
453 static const IExtractIconAVtbl eiavt
=
455 IExtractIconA_fnQueryInterface
,
456 IExtractIconA_fnAddRef
,
457 IExtractIconA_fnRelease
,
458 IExtractIconA_fnGetIconLocation
,
459 IExtractIconA_fnExtract
462 /************************************************************************
463 * IEIPersistFile::QueryInterface
465 static HRESULT WINAPI
IEIPersistFile_fnQueryInterface(IPersistFile
*iface
, REFIID iid
,
468 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
470 return IExtractIconW_QueryInterface(&This
->IExtractIconW_iface
, iid
, ppv
);
473 /************************************************************************
474 * IEIPersistFile::AddRef
476 static ULONG WINAPI
IEIPersistFile_fnAddRef(IPersistFile
*iface
)
478 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
480 return IExtractIconW_AddRef(&This
->IExtractIconW_iface
);
483 /************************************************************************
484 * IEIPersistFile::Release
486 static ULONG WINAPI
IEIPersistFile_fnRelease(IPersistFile
*iface
)
488 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
490 return IExtractIconW_Release(&This
->IExtractIconW_iface
);
493 /************************************************************************
494 * IEIPersistFile::GetClassID
496 static HRESULT WINAPI
IEIPersistFile_fnGetClassID(IPersistFile
*iface
, LPCLSID lpClassId
)
498 CLSID StdFolderID
= { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
503 *lpClassId
= StdFolderID
;
508 /************************************************************************
509 * IEIPersistFile_Load
511 static HRESULT WINAPI
IEIPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
,
514 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
520 static const IPersistFileVtbl pfvt
=
522 IEIPersistFile_fnQueryInterface
,
523 IEIPersistFile_fnAddRef
,
524 IEIPersistFile_fnRelease
,
525 IEIPersistFile_fnGetClassID
,
526 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
527 IEIPersistFile_fnLoad
,
528 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
529 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
530 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */
533 static IExtractIconWImpl
*extracticon_create(LPCITEMIDLIST pidl
)
535 IExtractIconWImpl
*ei
;
539 ei
= heap_alloc(sizeof(*ei
));
541 ei
->IExtractIconW_iface
.lpVtbl
= &eivt
;
542 ei
->IExtractIconA_iface
.lpVtbl
= &eiavt
;
543 ei
->IPersistFile_iface
.lpVtbl
= &pfvt
;
544 ei
->pidl
=ILClone(pidl
);
552 IExtractIconW
*IExtractIconW_Constructor(LPCITEMIDLIST pidl
)
554 IExtractIconWImpl
*ei
= extracticon_create(pidl
);
556 return &ei
->IExtractIconW_iface
;
559 IExtractIconA
*IExtractIconA_Constructor(LPCITEMIDLIST pidl
)
561 IExtractIconWImpl
*ei
= extracticon_create(pidl
);
563 return &ei
->IExtractIconA_iface
;