mciqtz32: Remove all remaining tabs.
[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
36 #include "browseui.h"
37
38 #include "initguid.h"
39 DEFINE_GUID(CLSID_CompCatCacheDaemon, 0x8C7461EF, 0x2b13, 0x11d2, 0xbe, 0x35, 0x30, 0x78, 0x30, 0x2c, 0x20, 0x30);
40
41 WINE_DEFAULT_DEBUG_CHANNEL(browseui);
42
43 LONG BROWSEUI_refCount = 0;
44
45 HINSTANCE BROWSEUI_hinstance = 0;
46
47 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
48
49 static const struct {
50     REFCLSID clsid;
51     LPFNCONSTRUCTOR ctor;
52 } ClassesTable[] = {
53     {&CLSID_ACLMulti, ACLMulti_Constructor},
54     {&CLSID_ProgressDialog, ProgressDialog_Constructor},
55     {&CLSID_CompCatCacheDaemon, CompCatCacheDaemon_Constructor},
56     {&CLSID_ACListISF, ACLShellSource_Constructor},
57     {NULL, NULL}
58 };
59
60 typedef struct tagClassFactory
61 {
62     const IClassFactoryVtbl *vtbl;
63     LONG   ref;
64     LPFNCONSTRUCTOR ctor;
65 } ClassFactory;
66
67 static void ClassFactory_Destructor(ClassFactory *This)
68 {
69     TRACE("Destroying class factory %p\n", This);
70     heap_free(This);
71     BROWSEUI_refCount--;
72 }
73
74 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
75 {
76     *ppvOut = NULL;
77     if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown)) {
78         IClassFactory_AddRef(iface);
79         *ppvOut = iface;
80         return S_OK;
81     }
82
83     WARN("Unknown interface %s\n", debugstr_guid(riid));
84     return E_NOINTERFACE;
85 }
86
87 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
88 {
89     ClassFactory *This = (ClassFactory *)iface;
90     return InterlockedIncrement(&This->ref);
91 }
92
93 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
94 {
95     ClassFactory *This = (ClassFactory *)iface;
96     ULONG ret = InterlockedDecrement(&This->ref);
97
98     if (ret == 0)
99         ClassFactory_Destructor(This);
100     return ret;
101 }
102
103 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
104 {
105     ClassFactory *This = (ClassFactory *)iface;
106     HRESULT ret;
107     IUnknown *obj;
108
109     TRACE("(%p, %p, %s, %p)\n", iface, punkOuter, debugstr_guid(iid), ppvOut);
110     ret = This->ctor(punkOuter, &obj);
111     if (FAILED(ret))
112         return ret;
113     ret = IUnknown_QueryInterface(obj, iid, ppvOut);
114     IUnknown_Release(obj);
115     return ret;
116 }
117
118 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
119 {
120     ClassFactory *This = (ClassFactory *)iface;
121
122     TRACE("(%p)->(%x)\n", This, fLock);
123
124     if(fLock)
125         InterlockedIncrement(&BROWSEUI_refCount);
126     else
127         InterlockedDecrement(&BROWSEUI_refCount);
128
129     return S_OK;
130 }
131
132 static const IClassFactoryVtbl ClassFactoryVtbl = {
133     /* IUnknown */
134     ClassFactory_QueryInterface,
135     ClassFactory_AddRef,
136     ClassFactory_Release,
137
138     /* IClassFactory*/
139     ClassFactory_CreateInstance,
140     ClassFactory_LockServer
141 };
142
143 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
144 {
145     ClassFactory *This = heap_alloc(sizeof(ClassFactory));
146     This->vtbl = &ClassFactoryVtbl;
147     This->ref = 1;
148     This->ctor = ctor;
149     *ppvOut = This;
150     TRACE("Created class factory %p\n", This);
151     BROWSEUI_refCount++;
152     return S_OK;
153 }
154
155 /*************************************************************************
156  * BROWSEUI DllMain
157  */
158 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
159 {
160     TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
161     switch (fdwReason)
162     {
163         case DLL_WINE_PREATTACH:
164             return FALSE;   /* prefer native version */
165         case DLL_PROCESS_ATTACH:
166             DisableThreadLibraryCalls(hinst);
167             BROWSEUI_hinstance = hinst;
168             break;
169     }
170     return TRUE;
171 }
172
173 /*************************************************************************
174  *              DllCanUnloadNow (BROWSEUI.@)
175  */
176 HRESULT WINAPI DllCanUnloadNow(void)
177 {
178     return BROWSEUI_refCount ? S_FALSE : S_OK;
179 }
180
181 /***********************************************************************
182  *              DllGetVersion (BROWSEUI.@)
183  */
184 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
185 {
186     if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
187
188     /* this is what IE6 on Windows 98 reports */
189     info->dwMajorVersion = 6;
190     info->dwMinorVersion = 0;
191     info->dwBuildNumber = 2600;
192     info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
193
194     return NOERROR;
195 }
196
197 /***********************************************************************
198  *              DllGetClassObject (BROWSEUI.@)
199  */
200 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *ppvOut)
201 {
202     int i;
203
204     *ppvOut = NULL;
205     if (!IsEqualIID(iid, &IID_IUnknown) && !IsEqualIID(iid, &IID_IClassFactory))
206         return E_NOINTERFACE;
207
208     for (i = 0; ClassesTable[i].clsid != NULL; i++)
209         if (IsEqualCLSID(ClassesTable[i].clsid, clsid)) {
210             return ClassFactory_Constructor(ClassesTable[i].ctor, ppvOut);
211         }
212     FIXME("CLSID %s not supported\n", debugstr_guid(clsid));
213     return CLASS_E_CLASSNOTAVAILABLE;
214 }