gdi32/tests: Fixed broken bitmap font metrics test on CJK locales.
[wine] / dlls / browseui / browseui_main.c
1 /*
2  * browseui - Internet Explorer / Windows Explorer standard UI
3  *
4  * Copyright 2001 John R. Sheets (for CodeWeavers)
5  * Copyright 2004 Mike McCormack (for CodeWeavers)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #define COBJMACROS
28
29 #include "wine/debug.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winreg.h"
33 #include "shlwapi.h"
34 #include "shlguid.h"
35 #include "rpcproxy.h"
36
37 #include "browseui.h"
38
39 #include "initguid.h"
40 DEFINE_GUID(CLSID_CompCatCacheDaemon, 0x8C7461EF, 0x2b13, 0x11d2, 0xbe, 0x35, 0x30, 0x78, 0x30, 0x2c, 0x20, 0x30);
41
42 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
43
44 LONG BROWSEUI_refCount = 0;
45
46 HINSTANCE BROWSEUI_hinstance = 0;
47
48 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
49
50 static const struct {
51     REFCLSID clsid;
52     LPFNCONSTRUCTOR ctor;
53 } ClassesTable[] = {
54     {&CLSID_ACLMulti, ACLMulti_Constructor},
55     {&CLSID_ProgressDialog, ProgressDialog_Constructor},
56     {&CLSID_CompCatCacheDaemon, CompCatCacheDaemon_Constructor},
57     {&CLSID_ACListISF, ACLShellSource_Constructor},
58     {NULL, NULL}
59 };
60
61 typedef struct tagClassFactory
62 {
63     IClassFactory IClassFactory_iface;
64     LONG   ref;
65     LPFNCONSTRUCTOR ctor;
66 } ClassFactory;
67
68 static inline ClassFactory *impl_from_IClassFactory(IClassFactory *iface)
69 {
70     return CONTAINING_RECORD(iface, ClassFactory, IClassFactory_iface);
71 }
72
73 static void ClassFactory_Destructor(ClassFactory *This)
74 {
75     TRACE("Destroying class factory %p\n", This);
76     heap_free(This);
77     BROWSEUI_refCount--;
78 }
79
80 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
81 {
82     *ppvOut = NULL;
83     if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown)) {
84         IClassFactory_AddRef(iface);
85         *ppvOut = iface;
86         return S_OK;
87     }
88
89     WARN("Unknown interface %s\n", debugstr_guid(riid));
90     return E_NOINTERFACE;
91 }
92
93 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
94 {
95     ClassFactory *This = impl_from_IClassFactory(iface);
96     return InterlockedIncrement(&This->ref);
97 }
98
99 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
100 {
101     ClassFactory *This = impl_from_IClassFactory(iface);
102     ULONG ret = InterlockedDecrement(&This->ref);
103
104     if (ret == 0)
105         ClassFactory_Destructor(This);
106     return ret;
107 }
108
109 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
110 {
111     ClassFactory *This = impl_from_IClassFactory(iface);
112     HRESULT ret;
113     IUnknown *obj;
114
115     TRACE("(%p, %p, %s, %p)\n", iface, punkOuter, debugstr_guid(iid), ppvOut);
116     ret = This->ctor(punkOuter, &obj);
117     if (FAILED(ret))
118         return ret;
119     ret = IUnknown_QueryInterface(obj, iid, ppvOut);
120     IUnknown_Release(obj);
121     return ret;
122 }
123
124 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
125 {
126     ClassFactory *This = impl_from_IClassFactory(iface);
127
128     TRACE("(%p)->(%x)\n", This, fLock);
129
130     if(fLock)
131         InterlockedIncrement(&BROWSEUI_refCount);
132     else
133         InterlockedDecrement(&BROWSEUI_refCount);
134
135     return S_OK;
136 }
137
138 static const IClassFactoryVtbl ClassFactoryVtbl = {
139     /* IUnknown */
140     ClassFactory_QueryInterface,
141     ClassFactory_AddRef,
142     ClassFactory_Release,
143
144     /* IClassFactory*/
145     ClassFactory_CreateInstance,
146     ClassFactory_LockServer
147 };
148
149 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
150 {
151     ClassFactory *This = heap_alloc(sizeof(ClassFactory));
152     This->IClassFactory_iface.lpVtbl = &ClassFactoryVtbl;
153     This->ref = 1;
154     This->ctor = ctor;
155     *ppvOut = This;
156     TRACE("Created class factory %p\n", This);
157     BROWSEUI_refCount++;
158     return S_OK;
159 }
160
161 /*************************************************************************
162  * BROWSEUI DllMain
163  */
164 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
165 {
166     TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
167     switch (fdwReason)
168     {
169         case DLL_WINE_PREATTACH:
170             return FALSE;   /* prefer native version */
171         case DLL_PROCESS_ATTACH:
172             DisableThreadLibraryCalls(hinst);
173             BROWSEUI_hinstance = hinst;
174             break;
175     }
176     return TRUE;
177 }
178
179 /*************************************************************************
180  *              DllCanUnloadNow (BROWSEUI.@)
181  */
182 HRESULT WINAPI DllCanUnloadNow(void)
183 {
184     return BROWSEUI_refCount ? S_FALSE : S_OK;
185 }
186
187 /***********************************************************************
188  *              DllGetVersion (BROWSEUI.@)
189  */
190 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
191 {
192     if(info->cbSize == sizeof(DLLVERSIONINFO) ||
193        info->cbSize == sizeof(DLLVERSIONINFO2))
194     {
195         /* this is what IE6 on Windows 98 reports */
196         info->dwMajorVersion = 6;
197         info->dwMinorVersion = 0;
198         info->dwBuildNumber = 2600;
199         info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
200         if(info->cbSize == sizeof(DLLVERSIONINFO2))
201         {
202             DLLVERSIONINFO2 *info2 = (DLLVERSIONINFO2*) info;
203             info2->dwFlags = 0;
204             info2->ullVersion = MAKEDLLVERULL(info->dwMajorVersion,
205                                               info->dwMinorVersion,
206                                               info->dwBuildNumber,
207                                               0); /* FIXME: correct hotfix number */
208         }
209         return S_OK;
210     }
211
212     WARN("wrong DLLVERSIONINFO size from app.\n");
213     return E_INVALIDARG;
214 }
215
216 /***********************************************************************
217  *              DllGetClassObject (BROWSEUI.@)
218  */
219 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *ppvOut)
220 {
221     int i;
222
223     *ppvOut = NULL;
224     if (!IsEqualIID(iid, &IID_IUnknown) && !IsEqualIID(iid, &IID_IClassFactory))
225         return E_NOINTERFACE;
226
227     for (i = 0; ClassesTable[i].clsid != NULL; i++)
228         if (IsEqualCLSID(ClassesTable[i].clsid, clsid)) {
229             return ClassFactory_Constructor(ClassesTable[i].ctor, ppvOut);
230         }
231     FIXME("CLSID %s not supported\n", debugstr_guid(clsid));
232     return CLASS_E_CLASSNOTAVAILABLE;
233 }
234
235 /***********************************************************************
236  *  DllInstall (BROWSEUI.@)
237  */
238 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
239 {
240     FIXME("(%s, %s): stub\n", bInstall ? "TRUE" : "FALSE", debugstr_w(cmdline));
241     return S_OK;
242 }
243
244 /***********************************************************************
245  *              DllRegisterServer (BROWSEUI.@)
246  */
247 HRESULT WINAPI DllRegisterServer(void)
248 {
249     return __wine_register_resources( BROWSEUI_hinstance );
250 }
251
252 /***********************************************************************
253  *              DllUnregisterServer (BROWSEUI.@)
254  */
255 HRESULT WINAPI DllUnregisterServer(void)
256 {
257     return __wine_unregister_resources( BROWSEUI_hinstance );
258 }