Moved mode setting out of .spec file into Makefile.
[wine/gsoc_dplay.git] / dlls / shell32 / folders.c
blob43c87731fe4e6a2916658b03313024a9a3cd65d9
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 <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
24 #include "windef.h"
25 #include "wine/obj_base.h"
26 #include "wine/obj_extracticon.h"
27 #include "undocshell.h"
28 #include "shlguid.h"
30 #include "wine/debug.h"
31 #include "winerror.h"
33 #include "pidl.h"
34 #include "shell32_main.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(shell);
39 /***********************************************************************
40 * IExtractIconA implementation
43 typedef struct
44 { ICOM_VFIELD(IExtractIconA);
45 DWORD ref;
46 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
47 LPITEMIDLIST pidl;
48 } IExtractIconAImpl;
50 static struct ICOM_VTABLE(IExtractIconA) eivt;
51 static struct ICOM_VTABLE(IPersistFile) pfvt;
53 #define _IPersistFile_Offset ((int)(&(((IExtractIconAImpl*)0)->lpvtblPersistFile)))
54 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
56 /**************************************************************************
57 * IExtractIconA_Constructor
59 IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
61 IExtractIconAImpl* ei;
63 ei=(IExtractIconAImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IExtractIconAImpl));
64 ei->ref=1;
65 ICOM_VTBL(ei) = &eivt;
66 ei->lpvtblPersistFile = &pfvt;
67 ei->pidl=ILClone(pidl);
69 pdump(pidl);
71 TRACE("(%p)\n",ei);
72 return (IExtractIconA *)ei;
74 /**************************************************************************
75 * IExtractIconA_QueryInterface
77 static HRESULT WINAPI IExtractIconA_fnQueryInterface( IExtractIconA * iface, REFIID riid, LPVOID *ppvObj)
79 ICOM_THIS(IExtractIconAImpl,iface);
81 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
83 *ppvObj = NULL;
85 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
86 { *ppvObj = This;
88 else if(IsEqualIID(riid, &IID_IPersistFile)) /*IExtractIcon*/
89 { *ppvObj = (IPersistFile*)&(This->lpvtblPersistFile);
91 else if(IsEqualIID(riid, &IID_IExtractIconA)) /*IExtractIcon*/
92 { *ppvObj = (IExtractIconA*)This;
95 if(*ppvObj)
96 { IExtractIconA_AddRef((IExtractIconA*) *ppvObj);
97 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
98 return S_OK;
100 TRACE("-- Interface: E_NOINTERFACE\n");
101 return E_NOINTERFACE;
104 /**************************************************************************
105 * IExtractIconA_AddRef
107 static ULONG WINAPI IExtractIconA_fnAddRef(IExtractIconA * iface)
109 ICOM_THIS(IExtractIconAImpl,iface);
111 TRACE("(%p)->(count=%lu)\n",This, This->ref );
113 return ++(This->ref);
115 /**************************************************************************
116 * IExtractIconA_Release
118 static ULONG WINAPI IExtractIconA_fnRelease(IExtractIconA * iface)
120 ICOM_THIS(IExtractIconAImpl,iface);
122 TRACE("(%p)->()\n",This);
124 if (!--(This->ref))
125 { TRACE(" destroying IExtractIcon(%p)\n",This);
126 SHFree(This->pidl);
127 HeapFree(GetProcessHeap(),0,This);
128 return 0;
130 return This->ref;
132 /**************************************************************************
133 * IExtractIconA_GetIconLocation
135 * mapping filetype to icon
137 static HRESULT WINAPI IExtractIconA_fnGetIconLocation(
138 IExtractIconA * iface,
139 UINT uFlags,
140 LPSTR szIconFile,
141 UINT cchMax,
142 int * piIndex,
143 UINT * pwFlags)
145 ICOM_THIS(IExtractIconAImpl,iface);
147 char sTemp[MAX_PATH];
148 DWORD dwNr;
149 GUID const * riid;
150 LPITEMIDLIST pSimplePidl = ILFindLastID(This->pidl);
152 TRACE("(%p) (flags=%u %p %u %p %p)\n", This, uFlags, szIconFile, cchMax, piIndex, pwFlags);
154 if (pwFlags)
155 *pwFlags = 0;
157 if (_ILIsDesktop(pSimplePidl))
159 lstrcpynA(szIconFile, "shell32.dll", cchMax);
160 *piIndex = 34;
163 /* my computer and other shell extensions */
164 else if ( (riid = _ILGetGUIDPointer(pSimplePidl)) )
166 char xriid[50];
167 sprintf( xriid, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
168 riid->Data1, riid->Data2, riid->Data3,
169 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
170 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
172 if (HCR_GetDefaultIcon(xriid, sTemp, MAX_PATH, &dwNr))
174 lstrcpynA(szIconFile, sTemp, cchMax);
175 *piIndex = dwNr;
177 else
179 lstrcpynA(szIconFile, "shell32.dll", cchMax);
180 *piIndex = 15;
184 else if (_ILIsDrive (pSimplePidl))
186 if (HCR_GetDefaultIcon("Drive", sTemp, MAX_PATH, &dwNr))
188 lstrcpynA(szIconFile, sTemp, cchMax);
189 *piIndex = dwNr;
191 else
193 lstrcpynA(szIconFile, "shell32.dll", cchMax);
194 *piIndex = 8;
197 else if (_ILIsFolder (pSimplePidl))
199 if (HCR_GetDefaultIcon("Folder", sTemp, MAX_PATH, &dwNr))
201 lstrcpynA(szIconFile, sTemp, cchMax);
202 *piIndex = dwNr;
204 else
206 lstrcpynA(szIconFile, "shell32.dll", cchMax);
207 *piIndex = (uFlags & GIL_OPENICON)? 4 : 3;
210 else /* object is file */
212 if (_ILGetExtension (pSimplePidl, sTemp, MAX_PATH)
213 && HCR_MapTypeToValue(sTemp, sTemp, MAX_PATH, TRUE)
214 && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
216 if (!strcmp("%1",sTemp)) /* icon is in the file */
218 SHGetPathFromIDListA(This->pidl, sTemp);
219 dwNr = 0;
221 lstrcpynA(szIconFile, sTemp, cchMax);
222 *piIndex = dwNr;
224 else /* default icon */
226 lstrcpynA(szIconFile, "shell32.dll", cchMax);
227 *piIndex = 0;
231 TRACE("-- %s %x\n", szIconFile, *piIndex);
232 return NOERROR;
234 /**************************************************************************
235 * IExtractIconA_Extract
237 static HRESULT WINAPI IExtractIconA_fnExtract(IExtractIconA * iface, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
239 ICOM_THIS(IExtractIconAImpl,iface);
241 FIXME("(%p) (file=%p index=%u %p %p size=%u) semi-stub\n", This, pszFile, nIconIndex, phiconLarge, phiconSmall, nIconSize);
243 if (phiconLarge)
244 *phiconLarge = ImageList_GetIcon(ShellBigIconList, nIconIndex, ILD_TRANSPARENT);
246 if (phiconSmall)
247 *phiconSmall = ImageList_GetIcon(ShellSmallIconList, nIconIndex, ILD_TRANSPARENT);
249 return S_OK;
252 static struct ICOM_VTABLE(IExtractIconA) eivt =
254 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
255 IExtractIconA_fnQueryInterface,
256 IExtractIconA_fnAddRef,
257 IExtractIconA_fnRelease,
258 IExtractIconA_fnGetIconLocation,
259 IExtractIconA_fnExtract
262 /************************************************************************
263 * IEIPersistFile_QueryInterface (IUnknown)
265 static HRESULT WINAPI IEIPersistFile_fnQueryInterface(
266 IPersistFile *iface,
267 REFIID iid,
268 LPVOID *ppvObj)
270 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
272 return IShellFolder_QueryInterface((IExtractIconA*)This, iid, ppvObj);
275 /************************************************************************
276 * IEIPersistFile_AddRef (IUnknown)
278 static ULONG WINAPI IEIPersistFile_fnAddRef(
279 IPersistFile *iface)
281 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
283 return IExtractIconA_AddRef((IExtractIconA*)This);
286 /************************************************************************
287 * IEIPersistFile_Release (IUnknown)
289 static ULONG WINAPI IEIPersistFile_fnRelease(
290 IPersistFile *iface)
292 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
294 return IExtractIconA_Release((IExtractIconA*)This);
297 /************************************************************************
298 * IEIPersistFile_GetClassID (IPersist)
300 static HRESULT WINAPI IEIPersistFile_fnGetClassID(
301 IPersistFile *iface,
302 LPCLSID lpClassId)
304 CLSID StdFolderID = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
306 if (lpClassId==NULL)
307 return E_POINTER;
309 memcpy(lpClassId, &StdFolderID, sizeof(StdFolderID));
311 return S_OK;
314 /************************************************************************
315 * IEIPersistFile_Load (IPersistFile)
317 static HRESULT WINAPI IEIPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
319 _ICOM_THIS_From_IPersistFile(IExtractIconA, iface);
320 FIXME("%p\n", This);
321 return E_NOTIMPL;
325 static struct ICOM_VTABLE(IPersistFile) pfvt =
327 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
328 IEIPersistFile_fnQueryInterface,
329 IEIPersistFile_fnAddRef,
330 IEIPersistFile_fnRelease,
331 IEIPersistFile_fnGetClassID,
332 (void *) 0xdeadbeef /* IEIPersistFile_fnIsDirty */,
333 IEIPersistFile_fnLoad,
334 (void *) 0xdeadbeef /* IEIPersistFile_fnSave */,
335 (void *) 0xdeadbeef /* IEIPersistFile_fnSaveCompleted */,
336 (void *) 0xdeadbeef /* IEIPersistFile_fnGetCurFile */