gdi32: Construct the EGA palette from the default palette.
[wine.git] / dlls / shdocvw / shdocvw_main.c
blob9bf2fa788fcfdfa0e6c72431030bb7c20f3ce4e7
1 /*
2 * SHDOCVW - Internet Explorer Web Control
4 * Copyright 2001 John R. Sheets (for CodeWeavers)
5 * Copyright 2004 Mike McCormack (for CodeWeavers)
6 * Copyright 2008 Detlef Riekenberg
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
25 #include <stdarg.h>
26 #include <stdio.h>
28 #include "wine/unicode.h"
29 #include "wine/debug.h"
31 #include "shdocvw.h"
33 #include "winreg.h"
34 #include "shlwapi.h"
35 #include "wininet.h"
37 #include "initguid.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
41 LONG SHDOCVW_refCount = 0;
43 HINSTANCE shdocvw_hinstance = 0;
44 static HMODULE SHDOCVW_hshell32 = 0;
45 static ITypeInfo *wb_typeinfo = NULL;
47 HRESULT get_typeinfo(ITypeInfo **typeinfo)
49 ITypeLib *typelib;
50 HRESULT hres;
52 if(wb_typeinfo) {
53 *typeinfo = wb_typeinfo;
54 return S_OK;
57 hres = LoadRegTypeLib(&LIBID_SHDocVw, 1, 1, LOCALE_SYSTEM_DEFAULT, &typelib);
58 if(FAILED(hres)) {
59 ERR("LoadRegTypeLib failed: %08x\n", hres);
60 return hres;
63 hres = ITypeLib_GetTypeInfoOfGuid(typelib, &IID_IWebBrowser2, &wb_typeinfo);
64 ITypeLib_Release(typelib);
66 *typeinfo = wb_typeinfo;
67 return hres;
70 const char *debugstr_variant(const VARIANT *v)
72 if(!v)
73 return "(null)";
75 switch(V_VT(v)) {
76 case VT_EMPTY:
77 return "{VT_EMPTY}";
78 case VT_NULL:
79 return "{VT_NULL}";
80 case VT_I4:
81 return wine_dbg_sprintf("{VT_I4: %d}", V_I4(v));
82 case VT_R8:
83 return wine_dbg_sprintf("{VT_R8: %lf}", V_R8(v));
84 case VT_BSTR:
85 return wine_dbg_sprintf("{VT_BSTR: %s}", debugstr_w(V_BSTR(v)));
86 case VT_DISPATCH:
87 return wine_dbg_sprintf("{VT_DISPATCH: %p}", V_DISPATCH(v));
88 case VT_BOOL:
89 return wine_dbg_sprintf("{VT_BOOL: %x}", V_BOOL(v));
90 default:
91 return wine_dbg_sprintf("{vt %d}", V_VT(v));
95 /*************************************************************************
96 * SHDOCVW DllMain
98 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID fImpLoad)
100 TRACE("%p 0x%x %p\n", hinst, fdwReason, fImpLoad);
101 switch (fdwReason)
103 case DLL_PROCESS_ATTACH:
104 shdocvw_hinstance = hinst;
105 register_iewindow_class();
106 break;
107 case DLL_PROCESS_DETACH:
108 if (SHDOCVW_hshell32) FreeLibrary(SHDOCVW_hshell32);
109 unregister_iewindow_class();
110 if(wb_typeinfo)
111 ITypeInfo_Release(wb_typeinfo);
112 break;
114 return TRUE;
117 /*************************************************************************
118 * DllCanUnloadNow (SHDOCVW.@)
120 HRESULT WINAPI DllCanUnloadNow(void)
122 return SHDOCVW_refCount ? S_FALSE : S_OK;
125 /***********************************************************************
126 * DllGetVersion (SHDOCVW.@)
128 HRESULT WINAPI DllGetVersion(DLLVERSIONINFO *info)
130 if (info->cbSize != sizeof(DLLVERSIONINFO)) FIXME("support DLLVERSIONINFO2\n");
132 /* this is what IE6 on Windows 98 reports */
133 info->dwMajorVersion = 6;
134 info->dwMinorVersion = 0;
135 info->dwBuildNumber = 2600;
136 info->dwPlatformID = DLLVER_PLATFORM_WINDOWS;
138 return NOERROR;
141 /*************************************************************************
142 * DllInstall (SHDOCVW.@)
144 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
146 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
148 return S_OK;
151 /*************************************************************************
152 * SHDOCVW_LoadShell32
154 * makes sure the handle to shell32 is valid
156 static BOOL SHDOCVW_LoadShell32(void)
158 if (SHDOCVW_hshell32)
159 return TRUE;
160 return ((SHDOCVW_hshell32 = LoadLibraryA("shell32.dll")) != NULL);
163 /***********************************************************************
164 * @ (SHDOCVW.110)
166 * Called by Win98 explorer.exe main binary, definitely has 0
167 * parameters.
169 DWORD WINAPI WinList_Init(void)
171 FIXME("(), stub!\n");
172 return 0x0deadfeed;
175 /***********************************************************************
176 * @ (SHDOCVW.118)
178 * Called by Win98 explorer.exe main binary, definitely has only one
179 * parameter.
181 static BOOL (WINAPI *pShellDDEInit)(BOOL start) = NULL;
183 BOOL WINAPI ShellDDEInit(BOOL start)
185 TRACE("(%d)\n", start);
187 if (!pShellDDEInit)
189 if (!SHDOCVW_LoadShell32())
190 return FALSE;
191 pShellDDEInit = (void *)GetProcAddress(SHDOCVW_hshell32, (LPCSTR)188);
194 if (pShellDDEInit)
195 return pShellDDEInit(start);
196 else
197 return FALSE;
200 /***********************************************************************
201 * @ (SHDOCVW.125)
203 * Called by Win98 explorer.exe main binary, definitely has 0
204 * parameters.
206 DWORD WINAPI RunInstallUninstallStubs(void)
208 FIXME("(), stub!\n");
209 return 0x0deadbee;
212 /***********************************************************************
213 * @ (SHDOCVW.130)
215 * Called by Emerge Desktop (alternative Windows Shell).
217 DWORD WINAPI RunInstallUninstallStubs2(void)
219 FIXME("(), stub!\n");
220 return 0x0deadbee;
223 /***********************************************************************
224 * SetQueryNetSessionCount (SHDOCVW.@)
226 DWORD WINAPI SetQueryNetSessionCount(DWORD arg)
228 FIXME("(%u), stub!\n", arg);
229 return 0;
232 /**********************************************************************
233 * Some forwards (by ordinal) to SHLWAPI
236 static void* fetch_shlwapi_ordinal(UINT_PTR ord)
238 static const WCHAR shlwapiW[] = {'s','h','l','w','a','p','i','.','d','l','l','\0'};
239 static HANDLE h;
241 if (!h && !(h = GetModuleHandleW(shlwapiW))) return NULL;
242 return (void*)GetProcAddress(h, (const char*)ord);
245 /******************************************************************
246 * WhichPlatformFORWARD (SHDOCVW.@)
248 DWORD WINAPI WhichPlatformFORWARD(void)
250 static DWORD (WINAPI *p)(void);
252 if (p || (p = fetch_shlwapi_ordinal(276))) return p();
253 return 1; /* not integrated, see shlwapi.WhichPlatform */
256 /******************************************************************
257 * StopWatchModeFORWARD (SHDOCVW.@)
259 void WINAPI StopWatchModeFORWARD(void)
261 static void (WINAPI *p)(void);
263 if (p || (p = fetch_shlwapi_ordinal(241))) p();
266 /******************************************************************
267 * StopWatchFlushFORWARD (SHDOCVW.@)
269 void WINAPI StopWatchFlushFORWARD(void)
271 static void (WINAPI *p)(void);
273 if (p || (p = fetch_shlwapi_ordinal(242))) p();
276 /******************************************************************
277 * StopWatchWFORWARD (SHDOCVW.@)
279 DWORD WINAPI StopWatchWFORWARD(DWORD dwClass, LPCWSTR lpszStr, DWORD dwUnknown,
280 DWORD dwMode, DWORD dwTimeStamp)
282 static DWORD (WINAPI *p)(DWORD, LPCWSTR, DWORD, DWORD, DWORD);
284 if (p || (p = fetch_shlwapi_ordinal(243)))
285 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
286 return ERROR_CALL_NOT_IMPLEMENTED;
289 /******************************************************************
290 * StopWatchAFORWARD (SHDOCVW.@)
292 DWORD WINAPI StopWatchAFORWARD(DWORD dwClass, LPCSTR lpszStr, DWORD dwUnknown,
293 DWORD dwMode, DWORD dwTimeStamp)
295 static DWORD (WINAPI *p)(DWORD, LPCSTR, DWORD, DWORD, DWORD);
297 if (p || (p = fetch_shlwapi_ordinal(244)))
298 return p(dwClass, lpszStr, dwUnknown, dwMode, dwTimeStamp);
299 return ERROR_CALL_NOT_IMPLEMENTED;
302 /******************************************************************
303 * URLSubRegQueryA (SHDOCVW.151)
305 HRESULT WINAPI URLSubRegQueryA(LPCSTR regpath, LPCSTR name, DWORD type,
306 LPSTR out, DWORD outlen, DWORD unknown)
308 CHAR buffer[INTERNET_MAX_URL_LENGTH];
309 DWORD len;
310 LONG res;
312 TRACE("(%s, %s, %d, %p, %d, %d)\n", debugstr_a(regpath), debugstr_a(name),
313 type, out, outlen, unknown);
315 if (!out) return S_OK;
317 len = sizeof(buffer);
318 res = SHRegGetUSValueA(regpath, name, NULL, buffer, &len, FALSE, NULL, 0);
319 if (!res) {
320 lstrcpynA(out, buffer, outlen);
321 return S_OK;
324 return E_FAIL;
327 /******************************************************************
328 * ParseURLFromOutsideSourceW (SHDOCVW.170)
330 DWORD WINAPI ParseURLFromOutsideSourceW(LPCWSTR url, LPWSTR out, LPDWORD plen, LPDWORD unknown)
332 WCHAR buffer_in[INTERNET_MAX_URL_LENGTH];
333 WCHAR buffer_out[INTERNET_MAX_URL_LENGTH];
334 LPCWSTR ptr = url;
335 HRESULT hr;
336 DWORD needed;
337 DWORD len;
338 DWORD res = 0;
341 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_w(url), out, plen, unknown,
342 plen ? *plen : 0, unknown ? *unknown : 0);
344 if (!PathIsURLW(ptr)) {
345 len = sizeof(buffer_in) / sizeof(buffer_in[0]);
346 buffer_in[0] = 0;
347 hr = UrlApplySchemeW(ptr, buffer_in, &len, URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT);
348 TRACE("got 0x%x with %s\n", hr, debugstr_w(buffer_in));
349 if (hr == S_OK) {
350 /* we parsed the url to buffer_in */
351 ptr = buffer_in;
353 else
355 FIXME("call search hook for %s\n", debugstr_w(ptr));
359 len = sizeof(buffer_out) / sizeof(buffer_out[0]);
360 buffer_out[0] = '\0';
361 hr = UrlCanonicalizeW(ptr, buffer_out, &len, URL_ESCAPE_SPACES_ONLY);
362 needed = lstrlenW(buffer_out)+1;
363 TRACE("got 0x%x with %s (need %d)\n", hr, debugstr_w(buffer_out), needed);
365 if (*plen >= needed) {
366 if (out != NULL) {
367 lstrcpyW(out, buffer_out);
368 res++;
370 needed--;
373 *plen = needed;
375 TRACE("=> %d\n", res);
376 return res;
379 /******************************************************************
380 * ParseURLFromOutsideSourceA (SHDOCVW.169)
382 * See ParseURLFromOutsideSourceW
384 DWORD WINAPI ParseURLFromOutsideSourceA(LPCSTR url, LPSTR out, LPDWORD plen, LPDWORD unknown)
386 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
387 LPWSTR urlW = NULL;
388 DWORD needed;
389 DWORD res;
390 DWORD len;
392 TRACE("(%s, %p, %p, %p) len: %d, unknown: 0x%x\n", debugstr_a(url), out, plen, unknown,
393 plen ? *plen : 0, unknown ? *unknown : 0);
395 if (url) {
396 len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
397 urlW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
398 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
401 len = sizeof(buffer) / sizeof(buffer[0]);
402 res = ParseURLFromOutsideSourceW(urlW, buffer, &len, unknown);
403 HeapFree(GetProcessHeap(), 0, urlW);
405 needed = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
407 res = 0;
408 if (*plen >= needed) {
409 if (out != NULL) {
410 WideCharToMultiByte(CP_ACP, 0, buffer, -1, out, *plen, NULL, NULL);
411 res = needed;
413 needed--;
416 *plen = needed;
418 TRACE("=> %d\n", res);
419 return res;
422 /******************************************************************
423 * IEParseDisplayNameWithBCW (SHDOCVW.218)
425 HRESULT WINAPI IEParseDisplayNameWithBCW(DWORD codepage, LPCWSTR lpszDisplayName, LPBC pbc, LPITEMIDLIST *ppidl)
427 /* Guessing at parameter 3 based on IShellFolder's ParseDisplayName */
428 FIXME("stub: 0x%x %s %p %p\n",codepage,debugstr_w(lpszDisplayName),pbc,ppidl);
429 return E_FAIL;
432 /******************************************************************
433 * SHRestricted2W (SHDOCVW.159)
435 DWORD WINAPI SHRestricted2W(DWORD res, LPCWSTR url, DWORD reserved)
437 FIXME("(%d %s %d) stub\n", res, debugstr_w(url), reserved);
438 return 0;
441 /******************************************************************
442 * SHRestricted2A (SHDOCVW.158)
444 * See SHRestricted2W
446 DWORD WINAPI SHRestricted2A(DWORD restriction, LPCSTR url, DWORD reserved)
448 LPWSTR urlW = NULL;
449 DWORD res;
451 TRACE("(%d, %s, %d)\n", restriction, debugstr_a(url), reserved);
452 if (url) {
453 DWORD len = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
454 urlW = heap_alloc(len * sizeof(WCHAR));
455 MultiByteToWideChar(CP_ACP, 0, url, -1, urlW, len);
457 res = SHRestricted2W(restriction, urlW, reserved);
458 heap_free(urlW);
459 return res;
462 /******************************************************************
463 * ImportPrivacySettings (SHDOCVW.@)
465 * Import global and/or per site privacy preferences from an xml file
467 * PARAMS
468 * filename [I] XML file to use
469 * pGlobalPrefs [IO] PTR to a usage flag for the global privacy preferences
470 * pPerSitePrefs [IO] PTR to a usage flag for the per site privacy preferences
472 * RETURNS
473 * Success: TRUE (the privacy preferences where updated)
474 * Failure: FALSE (the privacy preferences are unchanged)
476 * NOTES
477 * Set the flag to TRUE, when the related privacy preferences in the xml file
478 * should be used (parsed and overwrite the current settings).
479 * On return, the flag is TRUE, when the related privacy settings where used
482 BOOL WINAPI ImportPrivacySettings(LPCWSTR filename, BOOL *pGlobalPrefs, BOOL * pPerSitePrefs)
484 FIXME("(%s, %p->%d, %p->%d): stub\n", debugstr_w(filename),
485 pGlobalPrefs, pGlobalPrefs ? *pGlobalPrefs : 0,
486 pPerSitePrefs, pPerSitePrefs ? *pPerSitePrefs : 0);
488 if (pGlobalPrefs) *pGlobalPrefs = FALSE;
489 if (pPerSitePrefs) *pPerSitePrefs = FALSE;
491 return TRUE;