From a5a9057b995bbcebd5bcf7e9967788b8f443ebc5 Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Wed, 28 Apr 1999 00:31:07 +0000 Subject: [PATCH] brought modal dialog code into line with latest from ToolkitCore, from which it was clearly originally adapted, anyway. --- xpfe/AppCores/src/nsPrefsCore.cpp | 96 +++++++++++++++++++------------ 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/xpfe/AppCores/src/nsPrefsCore.cpp b/xpfe/AppCores/src/nsPrefsCore.cpp index ef3d9b750061..22a40fe31650 100644 --- a/xpfe/AppCores/src/nsPrefsCore.cpp +++ b/xpfe/AppCores/src/nsPrefsCore.cpp @@ -73,6 +73,8 @@ static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID); static PRBool firstTime = PR_TRUE; #endif +void DOMWindowToWebShellWindow(nsIDOMWindow *DOMWindow, nsCOMPtr *webWindow); + //---------------------------------------------------------------------------------------- nsPrefsCore::nsPrefsCore() //---------------------------------------------------------------------------------------- @@ -611,23 +613,24 @@ NS_IMETHODIMP nsPrefsCore::Init(const nsString& aId) } // nsPrefsCore::Init //---------------------------------------------------------------------------------------- -NS_IMETHODIMP nsPrefsCore::ShowWindow(nsIDOMWindow* /*aCurrentFrontWin*/) +NS_IMETHODIMP nsPrefsCore::ShowWindow(nsIDOMWindow* aCurrentFrontWin) //---------------------------------------------------------------------------------------- { - // Get app shell service. + // (code adapted from nsToolkitCore::ShowModal. yeesh.) + nsresult rv; + nsString controllerCID; nsIAppShellService *appShell; - nsresult rv = nsServiceManager::GetService( - kAppShellServiceCID, - kIAppShellServiceIID, - (nsISupports**)&appShell); + nsIWebShellWindow *window; + window = nsnull; + + nsCOMPtr urlObj; + rv = NS_NewURL(getter_AddRefs(urlObj), "resource://res/samples/PrefsWindow.html"); if (NS_FAILED(rv)) return rv; - nsString controllerCID = "43147b80-8a39-11d2-9938-0080c7cb1081"; - - nsCOMPtr url; - rv = NS_NewURL(getter_AddRefs(url), "resource:/res/samples/PrefsWindow.html"); + rv = nsServiceManager::GetService(kAppShellServiceCID, kIAppShellServiceIID, + (nsISupports**) &appShell); if (NS_FAILED(rv)) return rv; @@ -635,17 +638,29 @@ NS_IMETHODIMP nsPrefsCore::ShowWindow(nsIDOMWindow* /*aCurrentFrontWin*/) //nsIXULWindowCallbacks *cb = new nsFindDialogCallbacks( aURL, aContentType ); nsIXULWindowCallbacks *cb = nsnull; - nsIWebShellWindow* newWindow; - rv = appShell->CreateDialogWindow( - nsnull, - url, - controllerCID, - newWindow, - nsnull, - cb, - 504, 436 ); - if (newWindow != nsnull) - newWindow->ShowModal(); + // hardwired temporary hack. See nsAppRunner.cpp at main() + controllerCID = "43147b80-8a39-11d2-9938-0080c7cb1081"; + + nsCOMPtr parent; + DOMWindowToWebShellWindow(aCurrentFrontWin, &parent); + appShell->CreateDialogWindow(parent, urlObj, controllerCID, window, + nsnull, cb, 504, 436); + nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); + + if (window != nsnull) { + nsCOMPtr parentWindowWidgetThing; + nsresult gotParent; + gotParent = parent ? parent->GetWidget(*getter_AddRefs(parentWindowWidgetThing)) : + NS_ERROR_FAILURE; + // Windows OS is the only one that needs the parent disabled, or cares + // arguably this should be done by the new window, within ShowModal... + if (NS_SUCCEEDED(gotParent)) + parentWindowWidgetThing->Enable(PR_FALSE); + window->ShowModal(); + if (NS_SUCCEEDED(gotParent)) + parentWindowWidgetThing->Enable(PR_TRUE); + } + return rv; } // nsPrefsCore::ShowWindow @@ -698,26 +713,30 @@ NS_IMETHODIMP nsPrefsCore::PanelLoaded(nsIDOMWindow* aWin) return NS_OK; } -//---------------------------------------------------------------------------------------- -static nsCOMPtr - DOMWindowToWebShellWindow(nsIDOMWindow *DOMWindow) -// horribly complicated routine simply to convert from one to the other + +//---------------------------------------------------------------------------------------- +static void DOMWindowToWebShellWindow( + nsIDOMWindow *DOMWindow, + nsCOMPtr *webWindow) //---------------------------------------------------------------------------------------- { - nsCOMPtr webWindow; - nsCOMPtr globalScript(do_QueryInterface(DOMWindow)); - nsCOMPtr webshell; - if (globalScript) - globalScript->GetWebShell(getter_AddRefs(webshell)); - if (webshell) - { - nsCOMPtr webshellContainer; - webshell->GetContainer(*getter_AddRefs(webshellContainer)); - webWindow = do_QueryInterface(webshellContainer); - } - return webWindow; + if (!DOMWindow) + return; // with webWindow unchanged -- its constructor gives it a null ptr + + nsCOMPtr globalScript(do_QueryInterface(DOMWindow)); + nsCOMPtr webshell, rootWebshell; + if (globalScript) + globalScript->GetWebShell(getter_AddRefs(webshell)); + if (webshell) + webshell->GetRootWebShellEvenIfChrome(*getter_AddRefs(rootWebshell)); + if (rootWebshell) { + nsCOMPtr webshellContainer; + rootWebshell->GetContainer(*getter_AddRefs(webshellContainer)); + *webWindow = do_QueryInterface(webshellContainer); + } } + //---------------------------------------------------------------------------------------- static nsresult Close(nsIDOMWindow*& dw) //---------------------------------------------------------------------------------------- @@ -728,7 +747,8 @@ static nsresult Close(nsIDOMWindow*& dw) dw->GetTop(&top); if (!top) return NS_ERROR_FAILURE; - nsCOMPtr parent = DOMWindowToWebShellWindow(top); + nsCOMPtr parent; + DOMWindowToWebShellWindow(top, &parent); if (parent) parent->Close(); NS_IF_RELEASE(dw);