Init nsWebBrowser window while creating nscontainer.

This commit is contained in:
Jacek Caban 2005-08-10 09:54:02 +00:00 committed by Alexandre Julliard
parent 21e3ba8cd1
commit 2255e6fedb
4 changed files with 86 additions and 62 deletions

View File

@ -67,8 +67,6 @@ struct NSContainer {
nsIBaseWindow *window;
HWND hwnd;
LPWSTR url; /* hack! */
};

View File

@ -67,6 +67,52 @@ static HINSTANCE hXPCOM = NULL;
static nsIServiceManager *pServMgr = NULL;
static nsIComponentManager *pCompMgr = NULL;
static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
static ATOM nscontainer_class;
static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HTMLDocument *This;
nsresult nsres;
static const WCHAR wszTHIS[] = {'T','H','I','S',0};
if(msg == WM_CREATE) {
This = *(HTMLDocument**)lParam;
SetPropW(hwnd, wszTHIS, This);
}else {
This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
}
switch(msg) {
case WM_SIZE:
TRACE("(%p)->(WM_SIZE)\n", This);
nsres = nsIBaseWindow_SetSize(This->nscontainer->window,
LOWORD(lParam), HIWORD(lParam), TRUE);
if(NS_FAILED(nsres))
WARN("SetSize failed: %08lx\n", nsres);
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
static void register_nscontainer_class(void)
{
static WNDCLASSEXW wndclass = {
sizeof(WNDCLASSEXW),
CS_DBLCLKS,
nsembed_proc,
0, 0, NULL, NULL, NULL, NULL, NULL,
wszNsContainer,
NULL,
};
wndclass.hInstance = hInst;
nscontainer_class = RegisterClassExW(&wndclass);
}
static BOOL get_mozilla_path(PRUnichar *gre_path)
{
DWORD res, type, i, size = MAX_PATH;
@ -124,8 +170,6 @@ static BOOL get_mozctl_path(PRUnichar *gre_path)
return TRUE;
}
static BOOL load_gecko()
{
nsresult nsres;
@ -143,7 +187,7 @@ static BOOL load_gecko()
return pCompMgr != NULL;
tried_load = TRUE;
if(!(get_mozctl_path(gre_path) || get_mozilla_path(gre_path))) {
if(!get_mozctl_path(gre_path) && !get_mozilla_path(gre_path)) {
MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
return FALSE;
}
@ -157,8 +201,6 @@ static BOOL load_gecko()
static WCHAR wszPATH[] = {'P','A','T','H',0};
int len;
TRACE("here\n");
GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
len = strlenW(path_env);
path_env[len++] = ';';
@ -238,7 +280,6 @@ void close_gecko()
void HTMLDocument_NSContainer_Init(HTMLDocument *This)
{
NSContainer *ret;
nsIWebBrowserSetup *wbsetup;
nsresult nsres;
@ -247,20 +288,19 @@ void HTMLDocument_NSContainer_Init(HTMLDocument *This)
if(!load_gecko())
return;
ret = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
ret->url = NULL;
This->nscontainer = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
NS_WEBBROWSER_CONTRACTID, NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
NULL, &IID_nsIWebBrowser, (void**)&This->nscontainer->webbrowser);
if(NS_FAILED(nsres))
ERR("Creating WebBrowser failed: %08lx\n", nsres);
nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
(void**)&ret->window);
nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIBaseWindow,
(void**)&This->nscontainer->window);
if(NS_FAILED(nsres))
ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
nsres = nsIWebBrowser_QueryInterface(ret->webbrowser,
nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser,
&IID_nsIWebBrowserSetup, (void**)&wbsetup);
if(NS_SUCCEEDED(nsres)) {
nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
@ -271,12 +311,30 @@ void HTMLDocument_NSContainer_Init(HTMLDocument *This)
ERR("Could not get nsIWebBrowserSetup interface\n");
}
nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
(void**)&ret->navigation);
nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebNavigation,
(void**)&This->nscontainer->navigation);
if(NS_FAILED(nsres))
ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
This->nscontainer = ret;
if(!nscontainer_class)
register_nscontainer_class();
This->nscontainer->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
GetDesktopWindow(), NULL, hInst, This);
nsres = nsIBaseWindow_InitWindow(This->nscontainer->window, This->nscontainer->hwnd, NULL,
0, 0, 100, 100);
if(NS_SUCCEEDED(nsres)) {
nsres = nsIBaseWindow_Create(This->nscontainer->window);
if(NS_FAILED(nsres))
WARN("Creating window failed: %08lx\n", nsres);
nsIBaseWindow_SetVisibility(This->nscontainer->window, FALSE);
nsIBaseWindow_SetEnabled(This->nscontainer->window, FALSE);
}else {
ERR("InitWindow failed: %08lx\n", nsres);
}
}
void HTMLDocument_NSContainer_Destroy(HTMLDocument *This)

View File

@ -265,17 +265,12 @@ static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAva
}
TRACE("got url: %s\n", debugstr_w(url));
if(This->hwnd) {
nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url,
LOAD_FLAGS_NONE, NULL, NULL, NULL);
if(NS_SUCCEEDED(nsres))
return S_OK;
else
WARN("LoadURI failed: %08lx\n", nsres);
}else {
This->nscontainer->url = url;
return S_OK;
}
}
/* FIXME: Use grfMode */

View File

@ -71,35 +71,13 @@ static void paint_disabled(HWND hwnd) {
static void activate_gecko(HTMLDocument *This)
{
RECT rect;
nsresult nsres;
TRACE("(%p) %p\n", This, This->nscontainer->window);
GetClientRect(This->hwnd, &rect);
nsres = nsIBaseWindow_InitWindow(This->nscontainer->window, This->hwnd, NULL,
0, 0, rect.right, rect.bottom);
if(nsres == NS_OK) {
nsres = nsIBaseWindow_Create(This->nscontainer->window);
if(NS_FAILED(nsres))
WARN("Creating window failed: %08lx\n", nsres);
SetParent(This->nscontainer->hwnd, This->hwnd);
ShowWindow(This->nscontainer->hwnd, SW_SHOW);
nsIBaseWindow_SetVisibility(This->nscontainer->window, TRUE);
nsIBaseWindow_SetEnabled(This->nscontainer->window, TRUE);
}else {
ERR("Initializing window failed: %08lx\n", nsres);
}
if(This->nscontainer->url) {
TRACE("Loading url: %s\n", debugstr_w(This->nscontainer->url));
nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, This->nscontainer->url,
LOAD_FLAGS_NONE, NULL, NULL, NULL);
if(NS_FAILED(nsres))
ERR("LoadURI failed: %08lx\n", nsres);
This->nscontainer->url = NULL;
}
}
static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
@ -127,14 +105,9 @@ static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
break;
case WM_SIZE:
TRACE("(%p)->(WM_SIZE)\n", This);
if(This->nscontainer) {
nsresult nsres;
nsres = nsIBaseWindow_SetSize(This->nscontainer->window,
LOWORD(lParam), HIWORD(lParam), TRUE);
if(NS_FAILED(nsres))
WARN("SetSize failed: %08lx\n", nsres);
}
if(This->nscontainer)
SetWindowPos(This->nscontainer->hwnd, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam),
SWP_NOZORDER | SWP_NOACTIVATE);
}
return DefWindowProcW(hwnd, msg, wParam, lParam);