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
31 #include "undocshell.h"
34 #include "wine/debug.h"
37 #include "shell32_main.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
43 /***********************************************************************
44 * IExtractIconW implementation
48 IExtractIconW IExtractIconW_iface
;
49 IExtractIconA IExtractIconA_iface
;
50 IPersistFile IPersistFile_iface
;
55 static inline IExtractIconWImpl
*impl_from_IExtractIconW(IExtractIconW
*iface
)
57 return CONTAINING_RECORD(iface
, IExtractIconWImpl
, IExtractIconW_iface
);
60 static inline IExtractIconWImpl
*impl_from_IExtractIconA(IExtractIconA
*iface
)
62 return CONTAINING_RECORD(iface
, IExtractIconWImpl
, IExtractIconA_iface
);
65 static inline IExtractIconWImpl
*impl_from_IPersistFile(IPersistFile
*iface
)
67 return CONTAINING_RECORD(iface
, IExtractIconWImpl
, IPersistFile_iface
);
71 /**************************************************************************
72 * IExtractIconW::QueryInterface
74 static HRESULT WINAPI
IExtractIconW_fnQueryInterface(IExtractIconW
*iface
, REFIID riid
,
77 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
79 TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This
, debugstr_guid(riid
), ppv
);
82 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IExtractIconW
))
84 else if (IsEqualIID(riid
, &IID_IPersistFile
))
85 *ppv
= &This
->IPersistFile_iface
;
86 else if (IsEqualIID(riid
, &IID_IExtractIconA
))
87 *ppv
= &This
->IExtractIconA_iface
;
91 IUnknown_AddRef((IUnknown
*)*ppv
);
92 TRACE("-- Interface: (%p)->(%p)\n", ppv
, *ppv
);
95 TRACE("-- Interface: E_NOINTERFACE\n");
99 /**************************************************************************
100 * IExtractIconW::AddRef
102 static ULONG WINAPI
IExtractIconW_fnAddRef(IExtractIconW
* iface
)
104 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
105 ULONG refCount
= InterlockedIncrement(&This
->ref
);
107 TRACE("(%p)->(count=%u)\n", This
, refCount
- 1);
111 /**************************************************************************
112 * IExtractIconW::Release
114 static ULONG WINAPI
IExtractIconW_fnRelease(IExtractIconW
* iface
)
116 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
117 ULONG refCount
= InterlockedDecrement(&This
->ref
);
119 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
123 TRACE(" destroying IExtractIcon(%p)\n",This
);
130 static HRESULT
getIconLocationForFolder(IExtractIconWImpl
*This
, UINT uFlags
, LPWSTR szIconFile
,
131 UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
134 WCHAR wszPath
[MAX_PATH
];
135 WCHAR wszCLSIDValue
[CHARS_IN_GUID
];
137 if (SHELL32_GetCustomFolderAttribute(This
->pidl
, L
".ShellClassInfo", L
"IconFile",
140 WCHAR wszIconIndex
[10];
141 SHELL32_GetCustomFolderAttribute(This
->pidl
, L
".ShellClassInfo", L
"IconIndex",
143 *piIndex
= wcstol(wszIconIndex
, NULL
, 10);
145 else if (SHELL32_GetCustomFolderAttribute(This
->pidl
, L
".ShellClassInfo", L
"CLSID",
146 wszCLSIDValue
, CHARS_IN_GUID
) &&
147 HCR_GetDefaultIconW(wszCLSIDValue
, szIconFile
, cchMax
, &icon_idx
))
151 else if (SHELL32_GetCustomFolderAttribute(This
->pidl
, L
".ShellClassInfo", L
"CLSID2",
152 wszCLSIDValue
, CHARS_IN_GUID
) &&
153 HCR_GetDefaultIconW(wszCLSIDValue
, szIconFile
, cchMax
, &icon_idx
))
159 if (!HCR_GetDefaultIconW(L
"Folder", szIconFile
, cchMax
, &icon_idx
))
161 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
162 icon_idx
= -IDI_SHELL_FOLDER
;
165 if (uFlags
& GIL_OPENICON
)
166 *piIndex
= icon_idx
<0? icon_idx
-1: icon_idx
+1;
174 WCHAR swShell32Name
[MAX_PATH
];
176 /**************************************************************************
177 * IExtractIconW::GetIconLocation
179 * mapping filetype to icon
181 static HRESULT WINAPI
IExtractIconW_fnGetIconLocation(IExtractIconW
* iface
, UINT uFlags
,
182 LPWSTR szIconFile
, UINT cchMax
, int * piIndex
, UINT
* pwFlags
)
184 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
185 char sTemp
[MAX_PATH
];
188 LPITEMIDLIST pSimplePidl
= ILFindLastID(This
->pidl
);
190 TRACE("(%p) (flags=%u, %p, %u, %p, %p)\n", This
, uFlags
, szIconFile
,
191 cchMax
, piIndex
, pwFlags
);
196 if (_ILIsDesktop(pSimplePidl
))
198 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
199 *piIndex
= -IDI_SHELL_DESKTOP
;
202 /* my computer and other shell extensions */
203 else if ((riid
= _ILGetGUIDPointer(pSimplePidl
)))
207 swprintf(xriid
, ARRAY_SIZE(xriid
), L
"CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
208 riid
->Data1
, riid
->Data2
, riid
->Data3
,
209 riid
->Data4
[0], riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3],
210 riid
->Data4
[4], riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
212 if (HCR_GetDefaultIconW(xriid
, szIconFile
, cchMax
, &icon_idx
))
218 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
219 if(IsEqualGUID(riid
, &CLSID_MyComputer
))
220 *piIndex
= -IDI_SHELL_MY_COMPUTER
;
221 else if(IsEqualGUID(riid
, &CLSID_MyDocuments
))
222 *piIndex
= -IDI_SHELL_MY_DOCUMENTS
;
223 else if(IsEqualGUID(riid
, &CLSID_NetworkPlaces
))
224 *piIndex
= -IDI_SHELL_MY_NETWORK_PLACES
;
225 else if(IsEqualGUID(riid
, &CLSID_UnixFolder
) ||
226 IsEqualGUID(riid
, &CLSID_UnixDosFolder
))
227 *piIndex
= -IDI_SHELL_DRIVE
;
229 *piIndex
= -IDI_SHELL_FOLDER
;
233 else if (_ILIsDrive (pSimplePidl
))
237 if (_ILGetDrive(pSimplePidl
, sTemp
, MAX_PATH
))
239 switch(GetDriveTypeA(sTemp
))
241 case DRIVE_REMOVABLE
: icon_idx
= IDI_SHELL_FLOPPY
; break;
242 case DRIVE_CDROM
: icon_idx
= IDI_SHELL_OPTICAL_DRIVE
; break;
243 case DRIVE_REMOTE
: icon_idx
= IDI_SHELL_NETDRIVE
; break;
244 case DRIVE_RAMDISK
: icon_idx
= IDI_SHELL_RAMDISK
; break;
250 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
251 *piIndex
= -icon_idx
;
255 if (HCR_GetDefaultIconW(L
"Drive", szIconFile
, cchMax
, &icon_idx
))
261 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
262 *piIndex
= -IDI_SHELL_DRIVE
;
266 else if (_ILIsFolder (pSimplePidl
))
268 getIconLocationForFolder(This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
274 if (_ILIsCPanelStruct(pSimplePidl
))
276 if (SUCCEEDED(CPanel_GetIconLocationW(pSimplePidl
, szIconFile
, cchMax
, piIndex
)))
279 else if (_ILGetExtension(pSimplePidl
, sTemp
, MAX_PATH
))
281 if (HCR_MapTypeToValueA(sTemp
, sTemp
, MAX_PATH
, TRUE
)
282 && HCR_GetDefaultIconA(sTemp
, sTemp
, MAX_PATH
, &icon_idx
))
284 if (!lstrcmpA("%1", sTemp
)) /* icon is in the file */
286 SHGetPathFromIDListW(This
->pidl
, szIconFile
);
291 MultiByteToWideChar(CP_ACP
, 0, sTemp
, -1, szIconFile
, cchMax
);
297 else if (!lstrcmpiA(sTemp
, "lnkfile"))
299 /* extract icon from shell shortcut */
303 if (SUCCEEDED(SHGetDesktopFolder(&dsf
)))
305 HRESULT hr
= IShellFolder_GetUIObjectOf(dsf
, NULL
, 1, (LPCITEMIDLIST
*)&This
->pidl
, &IID_IShellLinkW
, NULL
, (LPVOID
*)&psl
);
309 hr
= IShellLinkW_GetIconLocation(psl
, szIconFile
, cchMax
, piIndex
);
311 if (SUCCEEDED(hr
) && *szIconFile
)
314 IShellLinkW_Release(psl
);
317 IShellFolder_Release(dsf
);
322 if (!found
) /* default icon */
324 lstrcpynW(szIconFile
, swShell32Name
, cchMax
);
329 TRACE("-- %s %x\n", debugstr_w(szIconFile
), *piIndex
);
333 /**************************************************************************
334 * IExtractIconW::Extract
336 static HRESULT WINAPI
IExtractIconW_fnExtract(IExtractIconW
* iface
, LPCWSTR pszFile
,
337 UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
339 IExtractIconWImpl
*This
= impl_from_IExtractIconW(iface
);
341 HIMAGELIST big_icons
, small_icons
;
343 FIXME("(%p) (file=%s index=%d %p %p size=%08x) semi-stub\n", This
, debugstr_w(pszFile
),
344 (signed)nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
346 index
= SIC_GetIconIndex(pszFile
, nIconIndex
, 0);
347 Shell_GetImageLists( &big_icons
, &small_icons
);
349 *phiconLarge
= ImageList_GetIcon(big_icons
, index
, ILD_TRANSPARENT
);
352 *phiconSmall
= ImageList_GetIcon(small_icons
, index
, ILD_TRANSPARENT
);
357 static const IExtractIconWVtbl eivt
=
359 IExtractIconW_fnQueryInterface
,
360 IExtractIconW_fnAddRef
,
361 IExtractIconW_fnRelease
,
362 IExtractIconW_fnGetIconLocation
,
363 IExtractIconW_fnExtract
366 /**************************************************************************
367 * IExtractIconA::QueryInterface
369 static HRESULT WINAPI
IExtractIconA_fnQueryInterface(IExtractIconA
* iface
, REFIID riid
,
372 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
374 return IExtractIconW_QueryInterface(&This
->IExtractIconW_iface
, riid
, ppv
);
377 /**************************************************************************
378 * IExtractIconA::AddRef
380 static ULONG WINAPI
IExtractIconA_fnAddRef(IExtractIconA
* iface
)
382 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
384 return IExtractIconW_AddRef(&This
->IExtractIconW_iface
);
386 /**************************************************************************
387 * IExtractIconA::Release
389 static ULONG WINAPI
IExtractIconA_fnRelease(IExtractIconA
* iface
)
391 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
393 return IExtractIconW_Release(&This
->IExtractIconW_iface
);
395 /**************************************************************************
396 * IExtractIconA::GetIconLocation
398 * mapping filetype to icon
400 static HRESULT WINAPI
IExtractIconA_fnGetIconLocation(IExtractIconA
* iface
, UINT uFlags
,
401 LPSTR szIconFile
, UINT cchMax
, int * piIndex
, UINT
* pwFlags
)
403 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
405 LPWSTR lpwstrFile
= heap_alloc(cchMax
* sizeof(WCHAR
));
407 TRACE("(%p) (flags=%u %p %u %p %p)\n", This
, uFlags
, szIconFile
, cchMax
, piIndex
, pwFlags
);
409 ret
= IExtractIconW_GetIconLocation(&This
->IExtractIconW_iface
, uFlags
, lpwstrFile
, cchMax
,
411 WideCharToMultiByte(CP_ACP
, 0, lpwstrFile
, -1, szIconFile
, cchMax
, NULL
, NULL
);
412 heap_free(lpwstrFile
);
414 TRACE("-- %s %x\n", szIconFile
, *piIndex
);
417 /**************************************************************************
418 * IExtractIconA::Extract
420 static HRESULT WINAPI
IExtractIconA_fnExtract(IExtractIconA
* iface
, LPCSTR pszFile
,
421 UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
423 IExtractIconWImpl
*This
= impl_from_IExtractIconA(iface
);
425 INT len
= MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, NULL
, 0);
426 LPWSTR lpwstrFile
= heap_alloc(len
* sizeof(WCHAR
));
428 TRACE("(%p) (file=%p index=%u %p %p size=%u)\n", This
, pszFile
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
430 MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, lpwstrFile
, len
);
431 ret
= IExtractIconW_Extract(&This
->IExtractIconW_iface
, lpwstrFile
, nIconIndex
, phiconLarge
,
432 phiconSmall
, nIconSize
);
433 heap_free(lpwstrFile
);
437 static const IExtractIconAVtbl eiavt
=
439 IExtractIconA_fnQueryInterface
,
440 IExtractIconA_fnAddRef
,
441 IExtractIconA_fnRelease
,
442 IExtractIconA_fnGetIconLocation
,
443 IExtractIconA_fnExtract
446 /************************************************************************
447 * IEIPersistFile::QueryInterface
449 static HRESULT WINAPI
IEIPersistFile_fnQueryInterface(IPersistFile
*iface
, REFIID iid
,
452 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
454 return IExtractIconW_QueryInterface(&This
->IExtractIconW_iface
, iid
, ppv
);
457 /************************************************************************
458 * IEIPersistFile::AddRef
460 static ULONG WINAPI
IEIPersistFile_fnAddRef(IPersistFile
*iface
)
462 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
464 return IExtractIconW_AddRef(&This
->IExtractIconW_iface
);
467 /************************************************************************
468 * IEIPersistFile::Release
470 static ULONG WINAPI
IEIPersistFile_fnRelease(IPersistFile
*iface
)
472 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
474 return IExtractIconW_Release(&This
->IExtractIconW_iface
);
477 /************************************************************************
478 * IEIPersistFile::GetClassID
480 static HRESULT WINAPI
IEIPersistFile_fnGetClassID(IPersistFile
*iface
, LPCLSID lpClassId
)
482 CLSID StdFolderID
= { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
487 *lpClassId
= StdFolderID
;
492 /************************************************************************
493 * IEIPersistFile_Load
495 static HRESULT WINAPI
IEIPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
,
498 IExtractIconWImpl
*This
= impl_from_IPersistFile(iface
);
504 static const IPersistFileVtbl pfvt
=
506 IEIPersistFile_fnQueryInterface
,
507 IEIPersistFile_fnAddRef
,
508 IEIPersistFile_fnRelease
,
509 IEIPersistFile_fnGetClassID
,
510 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
511 IEIPersistFile_fnLoad
,
512 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
513 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
514 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */
517 static IExtractIconWImpl
*extracticon_create(LPCITEMIDLIST pidl
)
519 IExtractIconWImpl
*ei
;
523 ei
= heap_alloc(sizeof(*ei
));
525 ei
->IExtractIconW_iface
.lpVtbl
= &eivt
;
526 ei
->IExtractIconA_iface
.lpVtbl
= &eiavt
;
527 ei
->IPersistFile_iface
.lpVtbl
= &pfvt
;
528 ei
->pidl
=ILClone(pidl
);
536 IExtractIconW
*IExtractIconW_Constructor(LPCITEMIDLIST pidl
)
538 IExtractIconWImpl
*ei
= extracticon_create(pidl
);
540 return &ei
->IExtractIconW_iface
;
543 IExtractIconA
*IExtractIconA_Constructor(LPCITEMIDLIST pidl
)
545 IExtractIconWImpl
*ei
= extracticon_create(pidl
);
547 return &ei
->IExtractIconA_iface
;