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