Make sure PostScript floats are printed with LC_NUMERIC="C".
[wine] / dlls / itss / itss.c
1 /*
2  *    ITSS Class Factory
3  *
4  * Copyright 2002 Lionel Ulmer
5  * Copyright 2004 Mike McCormack
6  *
7  *  see http://bonedaddy.net/pabs3/hhm/#chmspec
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "config.h"
25
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winnls.h"
33 #include "winreg.h"
34 #include "ole2.h"
35
36 #include "itss.h"
37 #include "uuids.h"
38
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
41
42 #include "itsstor.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(itss);
45
46 #include "initguid.h"
47
48 DEFINE_GUID(CLSID_ITStorage,0x5d02926a,0x212e,0x11d0,0x9d,0xf9,0x00,0xa0,0xc9,0x22,0xe6,0xec );
49 DEFINE_GUID(CLSID_ITSProtocol,0x9d148290,0xb9c8,0x11d0,0xa4,0xcc,0x00,0x00,0xf8,0x01,0x49,0xf6);
50 DEFINE_GUID(IID_IITStorage, 0x88cc31de, 0x27ab, 0x11d0, 0x9d, 0xf9, 0x0, 0xa0, 0xc9, 0x22, 0xe6, 0xec);
51
52 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj);
53
54 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
55 {
56     switch(fdwReason) {
57     case DLL_PROCESS_ATTACH:
58         DisableThreadLibraryCalls(hInstDLL);
59         break;
60     case DLL_PROCESS_DETACH:
61         break;
62     }
63     return TRUE;
64 }
65
66 /******************************************************************************
67  * ITSS ClassFactory
68  */
69 typedef struct {
70     IClassFactory ITF_IClassFactory;
71
72     DWORD ref;
73     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
74 } IClassFactoryImpl;
75
76 struct object_creation_info
77 {
78     const CLSID *clsid;
79     LPCSTR szClassName;
80     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
81 };
82
83 static const struct object_creation_info object_creation[] =
84 {
85     { &CLSID_ITStorage, "ITStorage", ITSS_create },
86     { &CLSID_ITSProtocol, "ITSProtocol", ITS_IParseDisplayName_create },
87 };
88
89 static HRESULT WINAPI
90 ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
91 {
92     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
93
94     if (IsEqualGUID(riid, &IID_IUnknown)
95         || IsEqualGUID(riid, &IID_IClassFactory))
96     {
97         IClassFactory_AddRef(iface);
98         *ppobj = This;
99         return S_OK;
100     }
101
102     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
103     return E_NOINTERFACE;
104 }
105
106 static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
107 {
108     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
109     return InterlockedIncrement(&This->ref);
110 }
111
112 static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
113 {
114     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
115
116     ULONG ref = InterlockedDecrement(&This->ref);
117
118     if (ref == 0)
119         HeapFree(GetProcessHeap(), 0, This);
120
121     return ref;
122 }
123
124
125 static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
126                                           REFIID riid, LPVOID *ppobj)
127 {
128     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
129     HRESULT hres;
130     LPUNKNOWN punk;
131     
132     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
133
134     *ppobj = NULL;
135     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
136     if (SUCCEEDED(hres)) {
137         hres = IUnknown_QueryInterface(punk, riid, ppobj);
138         IUnknown_Release(punk);
139     }
140     return hres;
141 }
142
143 static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
144 {
145     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
146     FIXME("(%p)->(%d),stub!\n",This,dolock);
147     return S_OK;
148 }
149
150 static IClassFactoryVtbl ITSSCF_Vtbl =
151 {
152     ITSSCF_QueryInterface,
153     ITSSCF_AddRef,
154     ITSSCF_Release,
155     ITSSCF_CreateInstance,
156     ITSSCF_LockServer
157 };
158
159
160 HRESULT WINAPI ITSS_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
161 {
162     int i;
163     IClassFactoryImpl *factory;
164
165     TRACE("%s %s %p\n",debugstr_guid(rclsid), debugstr_guid(iid), ppv);
166     
167     if ( !IsEqualGUID( &IID_IClassFactory, iid )
168          && ! IsEqualGUID( &IID_IUnknown, iid) )
169         return E_NOINTERFACE;
170
171     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
172     {
173         if (IsEqualGUID(object_creation[i].clsid, rclsid))
174             break;
175     }
176
177     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
178     {
179         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
180         return CLASS_E_CLASSNOTAVAILABLE;
181     }
182
183     TRACE("Creating a class factory for %s\n",object_creation[i].szClassName);
184
185     factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
186     if (factory == NULL) return E_OUTOFMEMORY;
187
188     factory->ITF_IClassFactory.lpVtbl = &ITSSCF_Vtbl;
189     factory->ref = 1;
190
191     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
192
193     *ppv = &(factory->ITF_IClassFactory);
194
195     TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
196
197     return S_OK;
198 }
199
200 /*****************************************************************************/
201
202 typedef struct {
203     IITStorageVtbl *vtbl_IITStorage;
204     DWORD ref;
205 } ITStorageImpl;
206
207
208 HRESULT WINAPI ITStorageImpl_QueryInterface(
209     IITStorage* iface,
210     REFIID riid,
211     void** ppvObject)
212 {
213     ITStorageImpl *This = (ITStorageImpl *)iface;
214     if (IsEqualGUID(riid, &IID_IUnknown)
215         || IsEqualGUID(riid, &IID_IITStorage))
216     {
217         IClassFactory_AddRef(iface);
218         *ppvObject = This;
219         return S_OK;
220     }
221
222     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppvObject);
223     return E_NOINTERFACE;
224 }
225
226 ULONG WINAPI ITStorageImpl_AddRef(
227     IITStorage* iface)
228 {
229     ITStorageImpl *This = (ITStorageImpl *)iface;
230     TRACE("%p\n", This);
231     return ++(This->ref);
232 }
233
234 ULONG WINAPI ITStorageImpl_Release(
235     IITStorage* iface)
236 {
237     ITStorageImpl *This = (ITStorageImpl *)iface;
238     ULONG ref = --This->ref;
239
240     if (ref == 0)
241         HeapFree(GetProcessHeap(), 0, This);
242
243     return ref;
244 }
245
246 HRESULT WINAPI ITStorageImpl_StgCreateDocfile(
247     IITStorage* iface,
248     const WCHAR* pwcsName,
249     DWORD grfMode,
250     DWORD reserved,
251     IStorage** ppstgOpen)
252 {
253     ITStorageImpl *This = (ITStorageImpl *)iface;
254
255     TRACE("%p %s %lu %lu %p\n", This,
256           debugstr_w(pwcsName), grfMode, reserved, ppstgOpen );
257
258     return ITSS_StgOpenStorage( pwcsName, NULL, grfMode,
259                                 0, reserved, ppstgOpen);
260 }
261
262 HRESULT WINAPI ITStorageImpl_StgCreateDocfileOnILockBytes(
263     IITStorage* iface,
264     ILockBytes* plkbyt,
265     DWORD grfMode,
266     DWORD reserved,
267     IStorage** ppstgOpen)
268 {
269     ITStorageImpl *This = (ITStorageImpl *)iface;
270     FIXME("%p\n", This);
271     return E_NOTIMPL;
272 }
273
274 HRESULT WINAPI ITStorageImpl_StgIsStorageFile(
275     IITStorage* iface,
276     const WCHAR* pwcsName)
277 {
278     ITStorageImpl *This = (ITStorageImpl *)iface;
279     FIXME("%p\n", This);
280     return E_NOTIMPL;
281 }
282
283 HRESULT WINAPI ITStorageImpl_StgIsStorageILockBytes(
284     IITStorage* iface,
285     ILockBytes* plkbyt)
286 {
287     ITStorageImpl *This = (ITStorageImpl *)iface;
288     FIXME("%p\n", This);
289     return E_NOTIMPL;
290 }
291
292 HRESULT WINAPI ITStorageImpl_StgOpenStorage(
293     IITStorage* iface,
294     const WCHAR* pwcsName,
295     IStorage* pstgPriority,
296     DWORD grfMode,
297     SNB snbExclude,
298     DWORD reserved,
299     IStorage** ppstgOpen)
300 {
301     ITStorageImpl *This = (ITStorageImpl *)iface;
302
303     TRACE("%p %s %p %ld %p\n", This, debugstr_w( pwcsName ),
304            pstgPriority, grfMode, snbExclude );
305
306     return ITSS_StgOpenStorage( pwcsName, pstgPriority, grfMode,
307                                 snbExclude, reserved, ppstgOpen);
308 }
309
310 HRESULT WINAPI ITStorageImpl_StgOpenStorageOnILockBytes(
311     IITStorage* iface,
312     ILockBytes* plkbyt,
313     IStorage* pStgPriority,
314     DWORD grfMode,
315     SNB snbExclude,
316     DWORD reserved,
317     IStorage** ppstgOpen)
318 {
319     ITStorageImpl *This = (ITStorageImpl *)iface;
320     FIXME("%p\n", This);
321     return E_NOTIMPL;
322 }
323
324 HRESULT WINAPI ITStorageImpl_StgSetTimes(
325     IITStorage* iface,
326     WCHAR* lpszName,
327     FILETIME* pctime,
328     FILETIME* patime,
329     FILETIME* pmtime)
330 {
331     ITStorageImpl *This = (ITStorageImpl *)iface;
332     FIXME("%p\n", This);
333     return E_NOTIMPL;
334 }
335
336 HRESULT WINAPI ITStorageImpl_SetControlData(
337     IITStorage* iface,
338     PITS_Control_Data pControlData)
339 {
340     ITStorageImpl *This = (ITStorageImpl *)iface;
341     FIXME("%p\n", This);
342     return E_NOTIMPL;
343 }
344
345 HRESULT WINAPI ITStorageImpl_DefaultControlData(
346     IITStorage* iface,
347     PITS_Control_Data* ppControlData)
348 {
349     ITStorageImpl *This = (ITStorageImpl *)iface;
350     FIXME("%p\n", This);
351     return E_NOTIMPL;
352 }
353
354 HRESULT WINAPI ITStorageImpl_Compact(
355     IITStorage* iface,
356     const WCHAR* pwcsName,
357     ECompactionLev iLev)
358 {
359     ITStorageImpl *This = (ITStorageImpl *)iface;
360     FIXME("%p\n", This);
361     return E_NOTIMPL;
362 }
363
364 static IITStorageVtbl ITStorageImpl_Vtbl =
365 {
366     ITStorageImpl_QueryInterface,
367     ITStorageImpl_AddRef,
368     ITStorageImpl_Release,
369     ITStorageImpl_StgCreateDocfile,
370     ITStorageImpl_StgCreateDocfileOnILockBytes,
371     ITStorageImpl_StgIsStorageFile,
372     ITStorageImpl_StgIsStorageILockBytes,
373     ITStorageImpl_StgOpenStorage,
374     ITStorageImpl_StgOpenStorageOnILockBytes,
375     ITStorageImpl_StgSetTimes,
376     ITStorageImpl_SetControlData,
377     ITStorageImpl_DefaultControlData,
378     ITStorageImpl_Compact,
379 };
380
381 static HRESULT ITSS_create(IUnknown *pUnkOuter, LPVOID *ppObj)
382 {
383     ITStorageImpl *its;
384
385     its = HeapAlloc( GetProcessHeap(), 0, sizeof(ITStorageImpl) );
386     its->vtbl_IITStorage = &ITStorageImpl_Vtbl;
387     its->ref = 1;
388
389     TRACE("-> %p\n", its);
390     *ppObj = (LPVOID) its;
391
392     return S_OK;
393 }
394
395 /*****************************************************************************/
396
397 HRESULT WINAPI ITSS_DllRegisterServer(void)
398 {
399     FIXME("\n");
400     return S_OK;
401 }
402
403 BOOL WINAPI ITSS_DllCanUnloadNow(void)
404 {
405     FIXME("\n");
406
407     return FALSE;
408 }