Stubs for IQueryAssociations.
[wine] / dlls / shell32 / classes.c
1 /*
2  *      file type mapping 
3  *      (HKEY_CLASSES_ROOT - Stuff)
4  *
5  *
6  */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <stdio.h>
10 #include "debugtools.h"
11 #include "winerror.h"
12 #include "winreg.h"
13
14 #include "wine/obj_queryassociations.h"
15 #include "shlobj.h"
16 #include "shell32_main.h"
17 #include "shlguid.h"
18 #include "shresdef.h"
19
20 DEFAULT_DEBUG_CHANNEL(shell);
21
22 #define MAX_EXTENSION_LENGTH 20
23
24 BOOL HCR_MapTypeToValue ( LPCSTR szExtension, LPSTR szFileType, DWORD len, BOOL bPrependDot)
25 {       HKEY    hkey;
26         char    szTemp[MAX_EXTENSION_LENGTH + 2];
27
28         TRACE("%s %p\n",szExtension, szFileType );
29
30         if (bPrependDot)
31           strcpy(szTemp, ".");
32
33         lstrcpynA(szTemp+((bPrependDot)?1:0), szExtension, MAX_EXTENSION_LENGTH);
34         
35         if (RegOpenKeyExA(HKEY_CLASSES_ROOT,szTemp,0,0x02000000,&hkey))
36         { return FALSE;
37         }
38
39         if (RegQueryValueA(hkey,NULL,szFileType,&len))
40         { RegCloseKey(hkey);
41           return FALSE;
42         }       
43
44         RegCloseKey(hkey);
45
46         TRACE("-- %s\n", szFileType );
47
48         return TRUE;
49 }
50 BOOL HCR_GetExecuteCommand ( LPCSTR szClass, LPCSTR szVerb, LPSTR szDest, DWORD len )
51 {       HKEY    hkey;
52         char    sTemp[256];
53         
54         TRACE("%s %s\n",szClass, szVerb );
55
56         sprintf(sTemp, "%s\\shell\\%s\\command",szClass, szVerb);
57
58         if (RegOpenKeyExA(HKEY_CLASSES_ROOT,sTemp,0,0x02000000,&hkey))
59         { return FALSE;
60         }
61
62         if (RegQueryValueA(hkey,NULL,szDest,&len))
63         { RegCloseKey(hkey);
64           return FALSE;
65         }       
66         RegCloseKey(hkey);
67
68         TRACE("-- %s\n", szDest );
69
70         return TRUE;
71
72 }
73 /***************************************************************************************
74 *       HCR_GetDefaultIcon      [internal]
75 *
76 * Gets the icon for a filetype
77 */
78 BOOL HCR_GetDefaultIcon (LPCSTR szClass, LPSTR szDest, DWORD len, LPDWORD dwNr)
79 {       HKEY    hkey;
80         char    sTemp[256];
81         char    sNum[5];
82
83         TRACE("%s\n",szClass );
84
85         sprintf(sTemp, "%s\\DefaultIcon",szClass);
86
87         if (RegOpenKeyExA(HKEY_CLASSES_ROOT,sTemp,0,0x02000000,&hkey))
88         { return FALSE;
89         }
90
91         if (RegQueryValueA(hkey,NULL,szDest,&len))
92         { RegCloseKey(hkey);
93           return FALSE;
94         }       
95
96         RegCloseKey(hkey);
97
98         if (ParseFieldA (szDest, 2, sNum, 5))
99         { *dwNr=atoi(sNum);
100         }
101         
102         ParseFieldA (szDest, 1, szDest, len);
103         
104         TRACE("-- %s %li\n", szDest, *dwNr );
105
106         return TRUE;
107 }
108
109 /***************************************************************************************
110 *       HCR_GetClassName        [internal]
111 *
112 * Gets the name of a registred class
113 */
114 BOOL HCR_GetClassName (REFIID riid, LPSTR szDest, DWORD len)
115 {       HKEY    hkey;
116         char    xriid[50];
117         BOOL ret = FALSE;
118         DWORD buflen = len;
119
120         strcpy(xriid,"CLSID\\");
121         WINE_StringFromCLSID(riid,&xriid[strlen(xriid)]);
122
123         TRACE("%s\n",xriid );
124
125         szDest[0] = 0;
126         if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,xriid,0,KEY_READ,&hkey))
127         {
128           if (!RegQueryValueExA(hkey,"",0,NULL,szDest,&len))
129           {
130             ret = TRUE;
131           }
132           RegCloseKey(hkey);
133         }
134
135         if (!ret || !szDest[0])
136         { 
137           if(IsEqualIID(riid, &CLSID_ShellDesktop))
138           {
139             if (LoadStringA(shell32_hInstance, IDS_DESKTOP, szDest, buflen))
140               ret = TRUE;
141           }
142           else if (IsEqualIID(riid, &CLSID_MyComputer))
143           {
144             if(LoadStringA(shell32_hInstance, IDS_MYCOMPUTER, szDest, buflen))
145               ret = TRUE;
146           }     
147         }
148
149         TRACE("-- %s\n", szDest);
150
151         return ret;
152 }
153
154 /***************************************************************************************
155 *       HCR_GetFolderAttributes [internal]
156 *
157 * gets the folder attributes of a class
158 *
159 * FIXME
160 *       verify the defaultvalue for *szDest
161 */
162 BOOL HCR_GetFolderAttributes (REFIID riid, LPDWORD szDest)
163 {       HKEY    hkey;
164         char    xriid[60];
165         DWORD   attributes;
166         DWORD   len = 4;
167
168         strcpy(xriid,"CLSID\\");
169         WINE_StringFromCLSID(riid,&xriid[strlen(xriid)]);
170         TRACE("%s\n",xriid );
171
172         if (!szDest) return FALSE;
173         *szDest = SFGAO_FOLDER|SFGAO_FILESYSTEM;
174         
175         strcat (xriid, "\\ShellFolder");
176
177         if (RegOpenKeyExA(HKEY_CLASSES_ROOT,xriid,0,KEY_READ,&hkey))
178         {
179           return FALSE;
180         }
181
182         if (RegQueryValueExA(hkey,"Attributes",0,NULL,(LPBYTE)&attributes,&len))
183         {
184           RegCloseKey(hkey);
185           return FALSE;
186         }
187
188         RegCloseKey(hkey);
189
190         TRACE("-- 0x%08lx\n", attributes);
191
192         *szDest = attributes;
193
194         return TRUE;
195 }
196
197 typedef struct 
198 {       ICOM_VFIELD(IQueryAssociations);
199         DWORD   ref;
200 } IQueryAssociationsImpl;
201
202 static struct ICOM_VTABLE(IQueryAssociations) qavt;
203
204 /**************************************************************************
205 *  IQueryAssociations_Constructor
206 */
207 IQueryAssociations* IQueryAssociations_Constructor(void)
208 {
209         IQueryAssociationsImpl* ei;
210
211         ei=(IQueryAssociationsImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IQueryAssociationsImpl));
212         ei->ref=1;
213         ICOM_VTBL(ei) = &qavt;
214
215         TRACE("(%p)\n",ei);
216         shell32_ObjCount++;
217         return (IQueryAssociations *)ei;
218 }
219 /**************************************************************************
220  *  IQueryAssociations_QueryInterface
221  */
222 static HRESULT WINAPI IQueryAssociations_fnQueryInterface(
223         IQueryAssociations * iface,
224         REFIID riid,
225         LPVOID *ppvObj)
226 {
227         ICOM_THIS(IQueryAssociationsImpl,iface);
228
229          TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
230
231         *ppvObj = NULL;
232
233         if(IsEqualIID(riid, &IID_IUnknown))             /*IUnknown*/
234         {
235           *ppvObj = This; 
236         }
237         else if(IsEqualIID(riid, &IID_IQueryAssociations))      /*IExtractIcon*/
238         {
239           *ppvObj = (IQueryAssociations*)This;
240         }
241
242         if(*ppvObj)
243         {
244           IQueryAssociations_AddRef((IQueryAssociations*) *ppvObj);     
245           TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
246           return S_OK;
247         }
248         TRACE("-- Interface: E_NOINTERFACE\n");
249         return E_NOINTERFACE;
250 }
251
252 /**************************************************************************
253 *  IQueryAssociations_AddRef
254 */
255 static ULONG WINAPI IQueryAssociations_fnAddRef(IQueryAssociations * iface)
256 {
257         ICOM_THIS(IQueryAssociationsImpl,iface);
258
259         TRACE("(%p)->(count=%lu)\n",This, This->ref );
260
261         shell32_ObjCount++;
262
263         return ++(This->ref);
264 }
265 /**************************************************************************
266 *  IQueryAssociations_Release
267 */
268 static ULONG WINAPI IQueryAssociations_fnRelease(IQueryAssociations * iface)
269 {
270         ICOM_THIS(IQueryAssociationsImpl,iface);
271
272         TRACE("(%p)->()\n",This);
273
274         shell32_ObjCount--;
275
276         if (!--(This->ref)) 
277         {
278           TRACE(" destroying IExtractIcon(%p)\n",This);
279           HeapFree(GetProcessHeap(),0,This);
280           return 0;
281         }
282         return This->ref;
283 }
284
285 static HRESULT WINAPI IQueryAssociations_fnInit(
286         IQueryAssociations * iface,
287         ASSOCF flags,
288         LPCWSTR pszAssoc,
289         HKEY hkProgid,
290         HWND hwnd)
291 {
292         return E_NOTIMPL;
293 }
294
295 static HRESULT WINAPI IQueryAssociations_fnGetString(
296         IQueryAssociations * iface,
297         ASSOCF flags,
298         ASSOCSTR str,
299         LPCWSTR pszExtra,
300         LPWSTR pszOut,
301         DWORD *pcchOut)
302 {
303         return E_NOTIMPL;
304 }
305
306 static HRESULT WINAPI IQueryAssociations_fnGetKey(
307         IQueryAssociations * iface,
308         ASSOCF flags,
309         ASSOCKEY key,
310         LPCWSTR pszExtra,
311         HKEY *phkeyOut)
312 {
313         return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI IQueryAssociations_fnGetData(
317         IQueryAssociations * iface,
318         ASSOCF flags,
319         ASSOCDATA data,
320         LPCWSTR pszExtra,
321         LPVOID pvOut,
322         DWORD *pcbOut)
323 {
324         return E_NOTIMPL;
325 }
326 static HRESULT WINAPI IQueryAssociations_fnGetEnum(
327         IQueryAssociations * iface,
328         ASSOCF flags,
329         ASSOCENUM assocenum,
330         LPCWSTR pszExtra,
331         REFIID riid,
332         LPVOID *ppvOut)
333 {
334         return E_NOTIMPL;
335 }
336
337 static struct ICOM_VTABLE(IQueryAssociations) qavt = 
338 {       
339         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
340         IQueryAssociations_fnQueryInterface,
341         IQueryAssociations_fnAddRef,
342         IQueryAssociations_fnRelease,
343         IQueryAssociations_fnInit,
344         IQueryAssociations_fnGetString, 
345         IQueryAssociations_fnGetKey,
346         IQueryAssociations_fnGetData,
347         IQueryAssociations_fnGetEnum
348 };