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