gdi32: Don't remove leading '@' from face name.
[wine] / dlls / ieframe / ieframe_main.c
1 /*
2  * Copyright 2011 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "ieframe.h"
20
21 #include "rpcproxy.h"
22 #include "shlguid.h"
23 #include "isguids.h"
24
25 #include "wine/debug.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
28
29 LONG module_ref = 0;
30 HINSTANCE ieframe_instance;
31
32 const char *debugstr_variant(const VARIANT *v)
33 {
34     if(!v)
35         return "(null)";
36
37     switch(V_VT(v)) {
38     case VT_EMPTY:
39         return "{VT_EMPTY}";
40     case VT_NULL:
41         return "{VT_NULL}";
42     case VT_I4:
43         return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
44     case VT_R8:
45         return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
46     case VT_BSTR:
47         return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
48     case VT_DISPATCH:
49         return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
50     case VT_BOOL:
51         return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
52     default:
53         return wine_dbg_sprintf("{vt %d}", V_VT(v));
54     }
55 }
56
57 static ITypeInfo *wb_typeinfo = NULL;
58
59 HRESULT get_typeinfo(ITypeInfo **typeinfo)
60 {
61     ITypeLib *typelib;
62     HRESULT hres;
63
64     if(wb_typeinfo) {
65         *typeinfo = wb_typeinfo;
66         return S_OK;
67     }
68
69     hres = LoadRegTypeLib(&LIBID_SHDocVw, 1, 1, LOCALE_SYSTEM_DEFAULT, &typelib);
70     if(FAILED(hres)) {
71         ERR("LoadRegTypeLib failed: %08x\n", hres);
72         return hres;
73     }
74
75     hres = ITypeLib_GetTypeInfoOfGuid(typelib, &IID_IWebBrowser2, &wb_typeinfo);
76     ITypeLib_Release(typelib);
77
78     *typeinfo = wb_typeinfo;
79     return hres;
80 }
81
82 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
83 {
84     *ppv = NULL;
85
86     if(IsEqualGUID(&IID_IUnknown, riid)) {
87         TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
88         *ppv = iface;
89     }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
90         TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
91         *ppv = iface;
92     }
93
94     if(*ppv) {
95         IUnknown_AddRef((IUnknown*)*ppv);
96         return S_OK;
97     }
98
99     FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
100     return E_NOINTERFACE;
101 }
102
103 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
104 {
105     TRACE("(%p)\n", iface);
106     return 2;
107 }
108
109 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
110 {
111     TRACE("(%p)\n", iface);
112     return 1;
113 }
114
115 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
116 {
117     TRACE("(%p)->(%x)\n", iface, fLock);
118     return S_OK;
119 }
120
121 static const IClassFactoryVtbl WebBrowserFactoryVtbl = {
122     ClassFactory_QueryInterface,
123     ClassFactory_AddRef,
124     ClassFactory_Release,
125     WebBrowser_Create,
126     ClassFactory_LockServer
127 };
128
129 static IClassFactory WebBrowserFactory = { &WebBrowserFactoryVtbl };
130
131 static const IClassFactoryVtbl WebBrowserV1FactoryVtbl = {
132     ClassFactory_QueryInterface,
133     ClassFactory_AddRef,
134     ClassFactory_Release,
135     WebBrowserV1_Create,
136     ClassFactory_LockServer
137 };
138
139 static IClassFactory WebBrowserV1Factory = { &WebBrowserV1FactoryVtbl };
140
141 static const IClassFactoryVtbl InternetShortcutFactoryVtbl = {
142     ClassFactory_QueryInterface,
143     ClassFactory_AddRef,
144     ClassFactory_Release,
145     InternetShortcut_Create,
146     ClassFactory_LockServer
147 };
148
149 static IClassFactory InternetShortcutFactory = { &InternetShortcutFactoryVtbl };
150
151 static const IClassFactoryVtbl CUrlHistoryFactoryVtbl = {
152     ClassFactory_QueryInterface,
153     ClassFactory_AddRef,
154     ClassFactory_Release,
155     CUrlHistory_Create,
156     ClassFactory_LockServer
157 };
158
159 static IClassFactory CUrlHistoryFactory = { &CUrlHistoryFactoryVtbl };
160
161 static const IClassFactoryVtbl TaskbarListFactoryVtbl = {
162     ClassFactory_QueryInterface,
163     ClassFactory_AddRef,
164     ClassFactory_Release,
165     TaskbarList_Create,
166     ClassFactory_LockServer
167 };
168
169 static IClassFactory TaskbarListFactory = { &TaskbarListFactoryVtbl };
170
171 /******************************************************************
172  *              DllMain (ieframe.@)
173  */
174 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
175 {
176     TRACE("(%p %d %p)\n", hInstDLL, fdwReason, lpv);
177
178     switch(fdwReason)
179     {
180     case DLL_WINE_PREATTACH:
181         return FALSE;  /* prefer native version */
182     case DLL_PROCESS_ATTACH:
183         ieframe_instance = hInstDLL;
184         register_iewindow_class();
185         DisableThreadLibraryCalls(ieframe_instance);
186         break;
187     case DLL_PROCESS_DETACH:
188         unregister_iewindow_class();
189         if(wb_typeinfo)
190             ITypeInfo_Release(wb_typeinfo);
191     }
192
193     return TRUE;
194 }
195
196 /***********************************************************************
197  *              DllGetClassObject       (ieframe.@)
198  */
199 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
200 {
201     if(IsEqualGUID(&CLSID_WebBrowser, rclsid)) {
202         TRACE("(CLSID_WebBrowser %s %p)\n", debugstr_guid(riid), ppv);
203         return IClassFactory_QueryInterface(&WebBrowserFactory, riid, ppv);
204     }
205
206     if(IsEqualGUID(&CLSID_WebBrowser_V1, rclsid)) {
207         TRACE("(CLSID_WebBrowser_V1 %s %p)\n", debugstr_guid(riid), ppv);
208         return IClassFactory_QueryInterface(&WebBrowserV1Factory, riid, ppv);
209     }
210
211
212     if(IsEqualGUID(rclsid, &CLSID_InternetShortcut)) {
213         TRACE("(CLSID_InternetShortcut %s %p)\n", debugstr_guid(riid), ppv);
214         return IClassFactory_QueryInterface(&InternetShortcutFactory, riid, ppv);
215     }
216
217     if(IsEqualGUID(&CLSID_CUrlHistory, rclsid)) {
218         TRACE("(CLSID_CUrlHistory %s %p)\n", debugstr_guid(riid), ppv);
219         return IClassFactory_QueryInterface(&CUrlHistoryFactory, riid, ppv);
220     }
221
222     if(IsEqualGUID(&CLSID_TaskbarList, rclsid)) {
223         TRACE("(CLSID_TaskbarList %s %p)\n", debugstr_guid(riid), ppv);
224         return IClassFactory_QueryInterface(&TaskbarListFactory, riid, ppv);
225     }
226
227
228     FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
229     return CLASS_E_CLASSNOTAVAILABLE;
230 }
231
232 static const IClassFactoryVtbl InternetExplorerFactoryVtbl = {
233     ClassFactory_QueryInterface,
234     ClassFactory_AddRef,
235     ClassFactory_Release,
236     InternetExplorer_Create,
237     ClassFactory_LockServer
238 };
239
240 static IClassFactory InternetExplorerFactory = { &InternetExplorerFactoryVtbl };
241
242 HRESULT register_class_object(BOOL do_reg)
243 {
244     HRESULT hres;
245
246     static DWORD cookie;
247
248     if(do_reg) {
249         hres = CoRegisterClassObject(&CLSID_InternetExplorer,
250                 (IUnknown*)&InternetExplorerFactory, CLSCTX_SERVER,
251                 REGCLS_MULTIPLEUSE|REGCLS_SUSPENDED, &cookie);
252         if (FAILED(hres)) {
253             ERR("failed to register object %08x\n", hres);
254             return hres;
255         }
256
257         hres = CoResumeClassObjects();
258         if(SUCCEEDED(hres))
259             return hres;
260
261         ERR("failed to resume object %08x\n", hres);
262     }
263
264     return CoRevokeClassObject(cookie);
265 }
266
267 /***********************************************************************
268  *          DllCanUnloadNow (ieframe.@)
269  */
270 HRESULT WINAPI DllCanUnloadNow(void)
271 {
272     TRACE("()\n");
273     return module_ref ? S_FALSE : S_OK;
274 }
275
276 /***********************************************************************
277  *          DllRegisterServer (ieframe.@)
278  */
279 HRESULT WINAPI DllRegisterServer(void)
280 {
281     TRACE("()\n");
282     return __wine_register_resources(ieframe_instance);
283 }
284
285 /***********************************************************************
286  *          DllUnregisterServer (ieframe.@)
287  */
288 HRESULT WINAPI DllUnregisterServer(void)
289 {
290     TRACE("()\n");
291     return __wine_unregister_resources(ieframe_instance);
292 }
293
294 /***********************************************************************
295  *          IEGetWriteableHKCU (ieframe.@)
296  */
297 HRESULT WINAPI IEGetWriteableHKCU(HKEY *pkey)
298 {
299     FIXME("(%p) stub\n", pkey);
300     return E_NOTIMPL;
301 }