source: trunk/src/shell32/folders.c@ 4696

Last change on this file since 4696 was 4696, checked in by sandervl, 25 years ago

icon index fixes

File size: 16.5 KB
Line 
1/* $Id: folders.c,v 1.5 2000-11-24 22:52:26 sandervl Exp $ */
2/*
3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
5 *
6 */
7#ifdef __WIN32OS2__
8#define ICOM_CINTERFACE 1
9#include <odin.h>
10#include "shellicon.h"
11#endif
12
13#include <stdlib.h>
14#include <stdio.h>
15#include <string.h>
16
17#include "wine/obj_base.h"
18#include "wine/obj_extracticon.h"
19#include "wine/undocshell.h"
20#include "shlguid.h"
21
22#include "debugtools.h"
23#include "winerror.h"
24
25#include "pidl.h"
26#include "shell32_main.h"
27
28DEFAULT_DEBUG_CHANNEL(shell)
29
30
31/***********************************************************************
32* IExtractIconA implementation
33*/
34
35typedef struct
36{ ICOM_VFIELD(IExtractIconA);
37 DWORD ref;
38 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
39 LPITEMIDLIST pidl;
40} IExtractIconAImpl;
41
42static struct ICOM_VTABLE(IExtractIconA) eivt;
43static struct ICOM_VTABLE(IPersistFile) pfvt;
44
45#define _IPersistFile_Offset ((int)(&(((IExtractIconAImpl*)0)->lpvtblPersistFile)))
46#define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
47
48/**************************************************************************
49* IExtractIconA_Constructor
50*/
51IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
52{
53 IExtractIconAImpl* ei;
54
55 ei=(IExtractIconAImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconAImpl));
56 ei->ref=1;
57 ICOM_VTBL(ei) = &eivt;
58 ei->lpvtblPersistFile = &pfvt;
59 ei->pidl=ILClone(pidl);
60
61 pdump(pidl);
62
63 TRACE("(%p)\n",ei);
64 shell32_ObjCount++;
65 return (IExtractIconA *)ei;
66}
67/**************************************************************************
68 * IExtractIconA_QueryInterface
69 */
70static HRESULT WINAPI IExtractIconA_fnQueryInterface( IExtractIconA * iface, REFIID riid, LPVOID *ppvObj)
71{
72 ICOM_THIS(IExtractIconAImpl,iface);
73
74 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
75
76 *ppvObj = NULL;
77
78 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
79 { *ppvObj = This;
80 }
81 else if(IsEqualIID(riid, &IID_IPersistFile)) /*IExtractIcon*/
82 { *ppvObj = (IPersistFile*)&(This->lpvtblPersistFile);
83 }
84 else if(IsEqualIID(riid, &IID_IExtractIconA)) /*IExtractIcon*/
85 { *ppvObj = (IExtractIconA*)This;
86 }
87
88 if(*ppvObj)
89 { IExtractIconA_AddRef((IExtractIconA*) *ppvObj);
90 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
91 return S_OK;
92 }
93 TRACE("-- Interface: E_NOINTERFACE\n");
94 return E_NOINTERFACE;
95}
96
97/**************************************************************************
98* IExtractIconA_AddRef
99*/
100static ULONG WINAPI IExtractIconA_fnAddRef(IExtractIconA * iface)
101{
102 ICOM_THIS(IExtractIconAImpl,iface);
103
104 TRACE("(%p)->(count=%lu)\n",This, This->ref );
105
106 shell32_ObjCount++;
107
108 return ++(This->ref);
109}
110/**************************************************************************
111* IExtractIconA_Release
112*/
113static ULONG WINAPI IExtractIconA_fnRelease(IExtractIconA * iface)
114{
115 ICOM_THIS(IExtractIconAImpl,iface);
116
117 TRACE("(%p)->()\n",This);
118
119 shell32_ObjCount--;
120
121 if (!--(This->ref))
122 { TRACE(" destroying IExtractIcon(%p)\n",This);
123 SHFree(This->pidl);
124 HeapFree(GetProcessHeap(),0,This);
125 return 0;
126 }
127 return This->ref;
128}
129/**************************************************************************
130* IExtractIconA_GetIconLocation
131*
132* mapping filetype to icon
133*/
134static HRESULT WINAPI IExtractIconA_fnGetIconLocation(
135 IExtractIconA * iface,
136 UINT uFlags,
137 LPSTR szIconFile,
138 UINT cchMax,
139 int * piIndex,
140 UINT * pwFlags)
141{
142 ICOM_THIS(IExtractIconAImpl,iface);
143
144 char sTemp[MAX_PATH];
145 DWORD dwNr;
146 GUID const * riid;
147 LPITEMIDLIST pSimplePidl = ILFindLastID(This->pidl);
148
149 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
150
151 if (pwFlags)
152 *pwFlags = 0;
153
154 if (_ILIsDesktop(pSimplePidl))
155 {
156 lstrcpynA(szIconFile, "shell32.dll", cchMax);
157#ifdef __WIN32OS2__
158 *piIndex = -SHLICON_DESKTOP;
159#else
160 *piIndex = 34;
161#endif
162 }
163
164 /* my computer and other shell extensions */
165 else if ( (riid = _ILGetGUIDPointer(pSimplePidl)) )
166 {
167 char xriid[50];
168 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
169 riid->Data1, riid->Data2, riid->Data3,
170 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
171 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
172
173 if (HCR_GetDefaultIcon(xriid, sTemp, MAX_PATH, &dwNr))
174 {
175 lstrcpynA(szIconFile, sTemp, cchMax);
176 *piIndex = dwNr;
177 }
178 else
179 {
180#ifdef __WIN32OS2__
181 /* Not correct. Originally location is explorer.exe, index 1 */
182 lstrcpynA(szIconFile, "shell32.dll", cchMax);
183 *piIndex = -SHLICON_MYCOMPUTER;
184
185 /* 15 is absolutely wrong! ( Another computer in the network ) */
186#else
187 lstrcpynA(szIconFile, "shell32.dll", cchMax);
188 *piIndex = 15;
189#endif
190 }
191 }
192 else if (_ILIsDrive (pSimplePidl))
193 {
194#ifdef __WIN32OS2__
195 lstrcpynA(szIconFile, "shell32.dll", cchMax);
196 *piIndex = -SHLICON_HARDDISK; /* hard disk */
197
198 if ( _ILGetDrive( pSimplePidl, sTemp, cchMax ) )
199 {
200 if ( ( sTemp[ 0 ] == 'A' ) || ( sTemp[ 0 ] == 'a' ) ||
201 ( sTemp[ 0 ] == 'B' ) || ( sTemp[ 0 ] == 'b' ) )
202 {
203 /* FIXME determine 5.25 Floppy */
204 *piIndex = -SHLICON_FLOPPY35;
205 }
206 else
207 {
208 UINT nType = GetDriveTypeA( sTemp );
209 switch ( nType )
210 {
211 case DRIVE_REMOVABLE:
212 *piIndex = -SHLICON_REMOVABLE_DISK;
213 break;
214
215 case DRIVE_FIXED:
216 *piIndex = -SHLICON_HARDDISK;
217 break;
218
219 case DRIVE_REMOTE:
220 {
221 /* FIXME: connected (9) / disconnected (10)state */
222 BOOL connected = TRUE;
223 if ( connected )
224 *piIndex = -SHLICON_NETDRIVE_CONN;
225 else
226 *piIndex = -SHLICON_NETDRIVE_DISCON;
227 break;
228 }
229 case DRIVE_CDROM:
230 *piIndex = -SHLICON_CDROM_DRIVE;
231 break;
232
233 case DRIVE_RAMDISK:
234 *piIndex = -SHLICON_RAMDRIVE;
235 break;
236
237 case DRIVE_UNKNOWN:
238 case DRIVE_NO_ROOT_DIR:
239 default:
240 *piIndex = -SHLICON_HARDDISK;
241 break;
242 }
243 }
244 }
245
246 if ( ( *piIndex == 8 ) &&
247 HCR_GetDefaultIcon( "Drive", sTemp, MAX_PATH, &dwNr ) )
248 {
249 /* kso: Are there special registry keys for particular drives? */
250 lstrcpynA(szIconFile, sTemp, cchMax);
251 *piIndex = dwNr;
252 }
253#else
254 if (HCR_GetDefaultIcon("Drive", sTemp, MAX_PATH, &dwNr))
255 {
256 lstrcpynA(szIconFile, sTemp, cchMax);
257 *piIndex = dwNr;
258 }
259 else
260 {
261 lstrcpynA(szIconFile, "shell32.dll", cchMax);
262 *piIndex = 8;
263 }
264#endif
265 }
266 else if (_ILIsFolder (pSimplePidl))
267 {
268 if (HCR_GetDefaultIcon("Folder", sTemp, MAX_PATH, &dwNr))
269 {
270 lstrcpynA(szIconFile, sTemp, cchMax);
271 *piIndex = dwNr;
272 }
273 else
274 {
275 lstrcpynA(szIconFile, "shell32.dll", cchMax);
276#ifdef __WIN32OS2__
277 *piIndex = (uFlags & GIL_OPENICON)? -SHLICON_FOLDER_OPEN : -SHLICON_FOLDER_CLOSED;
278#else
279 *piIndex = (uFlags & GIL_OPENICON)? 4 : 3;
280#endif
281 }
282 }
283 else /* object is file */
284 {
285#ifdef __WIN32OS2__
286 if (_ILGetExtension (pSimplePidl, sTemp, MAX_PATH))
287 {
288 if (HCR_MapTypeToValue(sTemp, sTemp, MAX_PATH, TRUE)
289 && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
290 {
291 if (!strcmp("%1",sTemp)) /* icon is in the file */
292 {
293 SHGetPathFromIDListA(This->pidl, sTemp);
294 dwNr = 0;
295 }
296 lstrcpynA(szIconFile, sTemp, cchMax);
297 *piIndex = dwNr;
298 } else
299 {
300 //icon is in the file/file is icon
301 if ((stricmp(sTemp,"EXE") == 0) ||
302 (stricmp(sTemp,"ICO") == 0))
303 {
304 SHGetPathFromIDListA(This->pidl, sTemp);
305 lstrcpynA(szIconFile, sTemp, cchMax);
306 *piIndex = 0;
307 }
308 else if (stricmp(sTemp,"FND") == 0)
309 {
310 SHGetPathFromIDListA(This->pidl, sTemp);
311 lstrcpynA(szIconFile, "shell32.dll", cchMax);
312#ifdef __WIN32OS2__
313 *piIndex = -SHLICON_COMPUTERS;
314#else
315 *piIndex = 42;
316#endif
317 }
318 else if (stricmp(sTemp,"COM") == 0)
319 {
320 SHGetPathFromIDListA(This->pidl, sTemp);
321 lstrcpynA(szIconFile, "shell32.dll", cchMax);
322#ifdef __WIN32OS2__
323 *piIndex = -SHLICON_APPLICATION;
324#else
325 *piIndex = 2;
326#endif
327 }
328#if 0
329 // icons not yet in resources
330
331 else if ((stricmp(sTemp,"INI") == 0) ||
332 (stricmp(sTemp,"INF") == 0))
333 {
334 SHGetPathFromIDListA(This->pidl, sTemp);
335 lstrcpynA(szIconFile, "shell32.dll", cchMax);
336 *piIndex = -151;
337 }
338 else if (stricmp(sTemp,"TXT") == 0)
339 {
340 SHGetPathFromIDListA(This->pidl, sTemp);
341 lstrcpynA(szIconFile, "shell32.dll", cchMax);
342 *piIndex = -152;
343 }
344 else if ((stricmp(sTemp,"BAT") == 0) ||
345 (stricmp(sTemp,"CMD") == 0))
346 {
347 SHGetPathFromIDListA(This->pidl, sTemp);
348 lstrcpynA(szIconFile, "shell32.dll", cchMax);
349 *piIndex = -153;
350 }
351 else if ((stricmp(sTemp,"DLL") == 0) ||
352 (stricmp(sTemp,"SYS") == 0) ||
353 (stricmp(sTemp,"VXD") == 0) ||
354 (stricmp(sTemp,"DRV") == 0) ||
355 (stricmp(sTemp,"CPL") == 0))
356 {
357 SHGetPathFromIDListA(This->pidl, sTemp);
358 lstrcpynA(szIconFile, "shell32.dll", cchMax);
359 *piIndex = -154;
360 }
361 else if (stricmp(sTemp,"FON") == 0)
362 {
363 SHGetPathFromIDListA(This->pidl, sTemp);
364 lstrcpynA(szIconFile, "shell32.dll", cchMax);
365 *piIndex = -155;
366 }
367 else if (stricmp(sTemp,"TTF") == 0)
368 {
369 SHGetPathFromIDListA(This->pidl, sTemp);
370 lstrcpynA(szIconFile,"shell32.dll", cchMax);
371 *piIndex = -156;
372 }
373#endif
374 else //default icon
375 {
376 lstrcpynA(szIconFile, "shell32.dll", cchMax);
377 *piIndex = 0;
378 }
379 }
380 } else /* default icon */
381 {
382 lstrcpynA(szIconFile, "shell32.dll", cchMax);
383 *piIndex = 0;
384 }
385 }
386#else
387 if (_ILGetExtension (pSimplePidl, sTemp, MAX_PATH)
388 && HCR_MapTypeToValue(sTemp, sTemp, MAX_PATH, TRUE)
389 && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
390 {
391 if (!strcmp("%1",sTemp)) /* icon is in the file */
392 {
393 SHGetPathFromIDListA(This->pidl, sTemp);
394 dwNr = 0;
395 }
396 lstrcpynA(szIconFile, sTemp, cchMax);
397 *piIndex = dwNr;
398 }
399 else /* default icon */
400 {
401 lstrcpynA(szIconFile, "shell32.dll", cchMax);
402 *piIndex = 0;
403 }
404 }
405#endif
406 TRACE("-- %s %x\n", szIconFile, *piIndex);
407 return NOERROR;
408}
409/**************************************************************************
410* IExtractIconA_Extract
411*/
412static HRESULT WINAPI IExtractIconA_fnExtract(IExtractIconA * iface, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
413{
414 ICOM_THIS(IExtractIconAImpl,iface);
415
416 FIXME("(%p) (file=%p index=%u %p %p size=%u) semi-stub\n", This, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
417
418 if (phiconLarge)
419 *phiconLarge = pImageList_GetIcon(ShellBigIconList, nIconIndex, ILD_TRANSPARENT);
420
421 if (phiconSmall)
422 *phiconSmall = pImageList_GetIcon(ShellSmallIconList, nIconIndex, ILD_TRANSPARENT);
423
424 return S_OK;
425}
426
427static struct ICOM_VTABLE(IExtractIconA) eivt =
428{
429 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
430 IExtractIconA_fnQueryInterface,
431 IExtractIconA_fnAddRef,
432 IExtractIconA_fnRelease,
433 IExtractIconA_fnGetIconLocation,
434 IExtractIconA_fnExtract
435};
436
437/************************************************************************
438 * IEIPersistFile_QueryInterface (IUnknown)
439 */
440static HRESULT WINAPI IEIPersistFile_fnQueryInterface(
441 IPersistFile *iface,
442 REFIID iid,
443 LPVOID *ppvObj)
444{
445 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
446
447 return IShellFolder_QueryInterface((IExtractIconA*)This, iid, ppvObj);
448}
449
450/************************************************************************
451 * IEIPersistFile_AddRef (IUnknown)
452 */
453static ULONG WINAPI IEIPersistFile_fnAddRef(
454 IPersistFile *iface)
455{
456 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
457
458 return IExtractIconA_AddRef((IExtractIconA*)This);
459}
460
461/************************************************************************
462 * IEIPersistFile_Release (IUnknown)
463 */
464static ULONG WINAPI IEIPersistFile_fnRelease(
465 IPersistFile *iface)
466{
467 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
468
469 return IExtractIconA_Release((IExtractIconA*)This);
470}
471
472/************************************************************************
473 * IEIPersistFile_GetClassID (IPersist)
474 */
475static HRESULT WINAPI IEIPersistFile_fnGetClassID(
476 IPersistFile *iface,
477 LPCLSID lpClassId)
478{
479 CLSID StdFolderID = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
480
481 if (lpClassId==NULL)
482 return E_POINTER;
483
484 memcpy(lpClassId, &StdFolderID, sizeof(StdFolderID));
485
486 return S_OK;
487}
488
489/************************************************************************
490 * IEIPersistFile_Load (IPersistFile)
491 */
492static HRESULT WINAPI IEIPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
493{
494 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
495 FIXME("%p\n", This);
496 return E_NOTIMPL;
497
498}
499
500#ifdef __WIN32OS2__
501/************************************************************************
502 * IEIPersistFile_IsDirty (IPersistFile)
503 */
504static HRESULT WINAPI IEIPersistFile_fnIsDirty(IPersistFile* iface)
505{
506 dprintf(("SHELL32: Folders: IEIPersistFile_fnIsDirty not implemented.\n"));
507 return E_NOTIMPL;
508}
509
510/************************************************************************
511 * IEIPersistFile_Save (IPersistFile)
512 */
513static HRESULT WINAPI IEIPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
514{
515 dprintf(("SHELL32: Folders: IEIPersistFile_fnSave not implemented.\n"));
516 return E_NOTIMPL;
517}
518
519
520/************************************************************************
521 * IEIPersistFile_SaveCompleted (IPersistFile)
522 */
523static HRESULT WINAPI IEIPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
524{
525 dprintf(("SHELL32: Folders: IEIPersistFile_fnSaveCompleted not implemented.\n"));
526 return E_NOTIMPL;
527}
528
529
530/************************************************************************
531 * IEIPersistFile_GetCurFile (IPersistFile)
532 */
533static HRESULT WINAPI IEIPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR* pszFileName)
534{
535 dprintf(("SHELL32: Folders: IEIPersistFile_fnGetCurFile not implemented.\n"));
536 return E_NOTIMPL;
537}
538#endif
539
540static struct ICOM_VTABLE(IPersistFile) pfvt =
541{
542 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
543 IEIPersistFile_fnQueryInterface,
544 IEIPersistFile_fnAddRef,
545 IEIPersistFile_fnRelease,
546 IEIPersistFile_fnGetClassID,
547#ifdef __WIN32OS2__
548 IEIPersistFile_fnIsDirty, /* IEIPersistFile_fnIsDirty */
549#else
550 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
551#endif
552 IEIPersistFile_fnLoad,
553#ifdef __WIN32OS2__
554 IEIPersistFile_fnSave, /* IEIPersistFile_fnSave */
555 IEIPersistFile_fnSaveCompleted, /* IEIPersistFile_fnSaveCompleted */
556 IEIPersistFile_fnGetCurFile /* IEIPersistFile_fnGetCurFile */
557#else
558 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
559 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
560 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */
561#endif
562};
563
Note: See TracBrowser for help on using the repository browser.